]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-vapor): remove createTextNode argument
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Wed, 31 Jan 2024 05:16:03 +0000 (13:16 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Wed, 31 Jan 2024 05:16:03 +0000 (13:16 +0800)
packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap
packages/compiler-vapor/__tests__/transforms/__snapshots__/vOnce.spec.ts.snap
packages/compiler-vapor/__tests__/transforms/vOnce.spec.ts
packages/compiler-vapor/src/generators/text.ts
packages/compiler-vapor/src/ir.ts
packages/compiler-vapor/src/transforms/transformInterpolation.ts
packages/runtime-vapor/src/dom.ts
packages/runtime-vapor/src/for.ts
packages/runtime-vapor/src/if.ts

index 7b66d766a7becbbfb647975c81d6903ae2b66244..b804903c92044654041a235fc81bc768ef15d09d 100644 (file)
@@ -7,7 +7,7 @@ export function render(_ctx) {
   const t0 = _template("<div>count is <!>.</div>")
   const n0 = t0()
   const { 0: [n3, { 1: [n2],}],} = _children(n0)
-  const n1 = _createTextNode(_ctx.count)
+  const n1 = _createTextNode()
   _insert(n1, n3, n2)
   _renderEffect(() => {
     _setText(n1, _ctx.count)
@@ -139,7 +139,7 @@ export function render(_ctx) {
   const t0 = _template("<div></div><div><Comp></Comp></div>")
   const n0 = t0()
   const { 1: [n2],} = _children(n0)
-  const n1 = _createTextNode(_ctx.bar)
+  const n1 = _createTextNode()
   _append(n2, n1)
   _renderEffect(() => {
     _setText(n1, _ctx.bar)
@@ -158,7 +158,7 @@ export function render(_ctx) {
   const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div><div><Comp></Comp></div>")
   const n0 = t0()
   const { 1: [n2],} = _children(n0)
-  const n1 = _createTextNode(_ctx.bar)
+  const n1 = _createTextNode()
   _append(n2, n1)
   _renderEffect(() => {
     _setText(n1, _ctx.bar)
@@ -176,8 +176,8 @@ exports[`compile > dynamic root 1`] = `
 export function render(_ctx) {
   const t0 = _fragment()
   const n0 = t0()
-  const n1 = _createTextNode(1)
-  const n2 = _createTextNode(2)
+  const n1 = _createTextNode()
+  const n2 = _createTextNode()
   _append(n0, n1, n2)
   _renderEffect(() => {
     _setText(n1, 1)
@@ -196,9 +196,9 @@ export function render(_ctx) {
   const t0 = _template("<button>foo<!>foo</button>")
   const n0 = t0()
   const { 0: [n4, { 1: [n5],}],} = _children(n0)
-  const n1 = _createTextNode(_ctx.count)
-  const n2 = _createTextNode(_ctx.count)
-  const n3 = _createTextNode(_ctx.count)
+  const n1 = _createTextNode()
+  const n2 = _createTextNode()
+  const n3 = _createTextNode()
   _prepend(n4, n1)
   _insert(n2, n4, n5)
   _append(n4, n3)
@@ -217,7 +217,7 @@ exports[`compile > expression parsing > interpolation 1`] = `
 "(() => {
   const t0 = _fragment()
   const n0 = t0()
-  const n1 = _createTextNode(a + b.value)
+  const n1 = _createTextNode()
   _append(n0, n1)
   _renderEffect(() => {
     _setText(n1, a + b.value)
@@ -255,14 +255,14 @@ export function render(_ctx) {
   const t0 = _template("3<!>6<!>9")
   const n0 = t0()
   const { 1: [n9], 3: [n10],} = _children(n0)
-  const n1 = _createTextNode(1)
-  const n2 = _createTextNode(2)
-  const n3 = _createTextNode(4)
-  const n4 = _createTextNode(5)
-  const n5 = _createTextNode(7)
-  const n6 = _createTextNode(8)
-  const n7 = _createTextNode('A')
-  const n8 = _createTextNode('B')
+  const n1 = _createTextNode()
+  const n2 = _createTextNode()
+  const n3 = _createTextNode()
+  const n4 = _createTextNode()
+  const n5 = _createTextNode()
+  const n6 = _createTextNode()
+  const n7 = _createTextNode()
+  const n8 = _createTextNode()
   _prepend(n0, n1, n2)
   _insert([n3, n4], n0, n9)
   _insert([n5, n6], n0, n10)
index e85387cd74826e2fe3c8aec43aad16e77da2ce47..99a9974426349c62441be3df0239fbae4bd2cf17 100644 (file)
@@ -19,7 +19,7 @@ export function render(_ctx) {
   const t0 = _template("<div> <span></span></div>")
   const n0 = t0()
   const { 0: [n3, { 1: [n2],}],} = _children(n0)
-  const n1 = _createTextNode(_ctx.msg)
+  const n1 = _createTextNode()
   _setText(n1, _ctx.msg)
   _setClass(n2, _ctx.clz)
   _prepend(n3, n1)
index 12aa08af65ae766c56772a6991d676ea48f68515..ff05e122a809e90fdca4c073a611a4f61a7ba0ad 100644 (file)
@@ -31,11 +31,6 @@ describe('compiler: v-once', () => {
       {
         id: 1,
         type: IRNodeTypes.CREATE_TEXT_NODE,
-        value: {
-          type: NodeTypes.SIMPLE_EXPRESSION,
-          content: 'msg',
-          isStatic: false,
-        },
       },
       {
         element: 1,
index 1947498621b7232fc860cebd494bf33e3b887666..a5bc02c7b4cabbcdceb89f7213aa962e76f42719 100644 (file)
@@ -25,6 +25,6 @@ export function genCreateTextNode(
   return [
     newline(),
     `const n${oper.id} = `,
-    ...call(vaporHelper('createTextNode'), genExpression(oper.value, context)),
+    ...call(vaporHelper('createTextNode')),
   ]
 }
index ac44a553892b41bb2e6b3bc2c7e140defbec714f..1c8f101564ea213df9068eec7400d89ca310a158 100644 (file)
@@ -130,7 +130,6 @@ export interface SetModelValueIRNode extends BaseIRNode {
 export interface CreateTextNodeIRNode extends BaseIRNode {
   type: IRNodeTypes.CREATE_TEXT_NODE
   id: number
-  value: IRExpression
 }
 
 export interface InsertNodeIRNode extends BaseIRNode {
index 5c15633f2de459e811652d09b1a6b65eb6c7df15..56a870ac1f5356754debdd923d87186191b575ce 100644 (file)
@@ -32,7 +32,6 @@ export const transformInterpolation: NodeTransform = (node, ctx) => {
       type: IRNodeTypes.CREATE_TEXT_NODE,
       loc: node.loc,
       id,
-      value: expr,
     })
     ctx.registerEffect(
       [expr],
index c8bb7f42f4eb0fc6ab6bfb90d6d6c5407e739e63..e8fe75b3c337ff5d4ab3fcd8db4f0486bd73c51a 100644 (file)
@@ -73,9 +73,9 @@ export function children(nodes: ChildNode[]): Children {
   return result
 }
 
-export function createTextNode(val: unknown): Text {
+export function createTextNode(val?: unknown): Text {
   // eslint-disable-next-line no-restricted-globals
-  return document.createTextNode(toDisplayString(val))
+  return document.createTextNode(val === undefined ? '' : toDisplayString(val))
 }
 
 export function createComment(data: string): Comment {
index d0093088116429a675da94edb2916e4cc7450ead..ed68491ead9bdeb2464d542baf15a5a7ed1903ed 100644 (file)
@@ -24,7 +24,7 @@ export const createFor = (
   let oldBlocks: ForBlock[] = []
   let newBlocks: ForBlock[]
   let parent: ParentNode | undefined | null
-  const parentAnchor = __DEV__ ? createComment('for') : createTextNode('')
+  const parentAnchor = __DEV__ ? createComment('for') : createTextNode()
   const ref: Fragment = {
     nodes: oldBlocks,
     [fragmentKey]: true,
index e2b50f26642eb41859406e45904c3a0e94ce0aa3..542f955a31b289ec69adfdb74dc5f929702c9a0d 100644 (file)
@@ -15,7 +15,7 @@ export const createIf = (
   let parent: ParentNode | undefined | null
   let block: Block | undefined
   let scope: EffectScope | undefined
-  const anchor = __DEV__ ? createComment('if') : createTextNode('')
+  const anchor = __DEV__ ? createComment('if') : createTextNode()
   const fragment: Fragment = {
     nodes: [],
     anchor,