]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: v-pre (#14)
authorRizumu Ayaka <rizumu@ayaka.moe>
Wed, 29 Nov 2023 21:31:26 +0000 (05:31 +0800)
committerGitHub <noreply@github.com>
Wed, 29 Nov 2023 21:31:26 +0000 (05:31 +0800)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap
packages/compiler-vapor/__tests__/compile.test.ts

index 4f9dbf8d29c123e743cbeda1e5d9060389f88781..bc7dc37728e9204a445cf138a647334416f3d467 100644 (file)
@@ -141,6 +141,58 @@ export function render() {
 "
 `;
 
+exports[`compile > directives > v-pre > basic 1`] = `
+"import { template } from 'vue/vapor';
+const t0 = template('<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div>');
+export function render() {
+  const n0 = t0();
+  return n0;
+}
+"
+`;
+
+exports[`compile > directives > v-pre > self-closing v-pre 1`] = `
+"import { template, children, createTextNode, append, effect, setAttr, setText } from 'vue/vapor';
+const t0 = template('<div></div><div><Comp></Comp></div>');
+export function render() {
+  const n0 = t0();
+  const {
+    1: [n1],
+  } = children(n0);
+  const n2 = createTextNode(bar);
+  append(n1, n2);
+  effect(() => {
+    setAttr(n1, 'id', undefined, foo);
+  });
+  effect(() => {
+    setText(n2, undefined, bar);
+  });
+  return n0;
+}
+"
+`;
+
+exports[`compile > directives > v-pre > should not affect siblings after it 1`] = `
+"import { template, children, createTextNode, append, effect, setAttr, setText } from 'vue/vapor';
+const t0 = template('<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div><div><Comp></Comp></div>');
+export function render() {
+  const n0 = t0();
+  const {
+    1: [n1],
+  } = children(n0);
+  const n2 = createTextNode(bar.value);
+  append(n1, n2);
+  effect(() => {
+    setAttr(n1, 'id', undefined, foo.value);
+  });
+  effect(() => {
+    setText(n2, undefined, bar.value);
+  });
+  return n0;
+}
+"
+`;
+
 exports[`compile > directives > v-text > no expression 1`] = `
 "import { template, children, effect, setText } from 'vue/vapor';
 const t0 = template('<div></div>');
index 8fa34b5ed303997939c18d07bde0be893fe91d89..b73270c38949cb3870f085b9a03a707d3aa714a9 100644 (file)
@@ -189,5 +189,51 @@ describe('compile', () => {
         expect(code).not.contains('effect')
       })
     })
+
+    describe('v-pre', () => {
+      test('basic', async () => {
+        const code = await compile(
+          `<div v-pre :id="foo"><Comp/>{{ bar }}</div>\n`,
+          {
+            bindingMetadata: {
+              foo: BindingTypes.SETUP_REF,
+              bar: BindingTypes.SETUP_REF,
+            },
+          },
+        )
+
+        expect(code).toMatchSnapshot()
+        expect(code).contains('<div :id="foo"><Comp></Comp>{{ bar }}</div>')
+        expect(code).not.contains('effect')
+      })
+
+      // TODO: support multiple root nodes and components
+      test('should not affect siblings after it', async () => {
+        const code = await compile(
+          `<div v-pre :id="foo"><Comp/>{{ bar }}</div>\n` +
+            `<div :id="foo"><Comp/>{{ bar }}</div>`,
+          {
+            bindingMetadata: {
+              foo: BindingTypes.SETUP_REF,
+              bar: BindingTypes.SETUP_REF,
+            },
+          },
+        )
+
+        expect(code).toMatchSnapshot()
+        // Waiting for TODO, There should be more here.
+      })
+
+      // TODO: support multiple root nodes and components
+      test('self-closing v-pre', async () => {
+        const code = await compile(
+          `<div v-pre/>\n<div :id="foo"><Comp/>{{ bar }}</div>`,
+        )
+
+        expect(code).toMatchSnapshot()
+        expect(code).contains('<div></div><div><Comp></Comp></div>')
+        // Waiting for TODO, There should be more here.
+      })
+    })
   })
 })