]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: fix v-bind no-exp shorthand for new parser
authorEvan You <yyx990803@gmail.com>
Tue, 21 Nov 2023 10:37:47 +0000 (18:37 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 25 Nov 2023 08:18:29 +0000 (16:18 +0800)
packages/compiler-core/__tests__/transforms/vBind.spec.ts
packages/compiler-core/src/transforms/vBind.ts

index 2e94dc1f7de2a07c482afe8c220d06548cc9e567..0ae247c2f5012806be6b1ada88f6de69623f14bf 100644 (file)
@@ -80,32 +80,16 @@ describe('compiler: transform v-bind', () => {
         content: `id`,
         isStatic: true,
         loc: {
-          start: {
-            line: 1,
-            column: 13,
-            offset: 12
-          },
-          end: {
-            line: 1,
-            column: 15,
-            offset: 14
-          }
+          start: { line: 1, column: 13, offset: 12 },
+          end: { line: 1, column: 15, offset: 14 }
         }
       },
       value: {
         content: `id`,
         isStatic: false,
         loc: {
-          start: {
-            line: 1,
-            column: 1,
-            offset: 0
-          },
-          end: {
-            line: 1,
-            column: 1,
-            offset: 0
-          }
+          start: { line: 1, column: 13, offset: 12 },
+          end: { line: 1, column: 15, offset: 14 }
         }
       }
     })
index 9f85d6b3d635ec8aebb694ea7f3764d51cc00edc..eba95727bd5f573fa48369393c76bed79a296954 100644 (file)
@@ -3,7 +3,6 @@ import {
   createObjectProperty,
   createSimpleExpression,
   ExpressionNode,
-  locStub,
   NodeTypes
 } from '../ast'
 import { createCompilerError, ErrorCodes } from '../errors'
@@ -18,6 +17,16 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
   const { modifiers, loc } = dir
   const arg = dir.arg!
 
+  // :arg is replaced by :arg="arg"
+  let { exp } = dir
+  if (!exp && arg.type === NodeTypes.SIMPLE_EXPRESSION) {
+    const propName = camelize(arg.content)
+    exp = dir.exp = createSimpleExpression(propName, false, arg.loc)
+    if (!__BROWSER__) {
+      exp = dir.exp = processExpression(exp, context)
+    }
+  }
+
   if (arg.type !== NodeTypes.SIMPLE_EXPRESSION) {
     arg.children.unshift(`(`)
     arg.children.push(`) || ""`)
@@ -48,18 +57,6 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
     }
   }
 
-  // :arg is replaced by :arg="arg"
-  let { exp } = dir
-  if (!exp && arg.type === NodeTypes.SIMPLE_EXPRESSION) {
-    const propName = camelize(arg.loc.source)
-    const simpleExpression = createSimpleExpression(propName, false, {
-      ...locStub,
-      source: propName
-    })
-
-    exp = dir.exp = processExpression(simpleExpression, context)
-  }
-
   if (
     !exp ||
     (exp.type === NodeTypes.SIMPLE_EXPRESSION && !exp.content.trim())