]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix bail constant for globals
authorEvan You <yyx990803@gmail.com>
Mon, 29 Apr 2024 08:21:25 +0000 (16:21 +0800)
committerEvan You <yyx990803@gmail.com>
Mon, 29 Apr 2024 08:21:25 +0000 (16:21 +0800)
packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
packages/compiler-core/src/transforms/transformExpression.ts

index 8ecc2fb0fb87da8ac9d3f3edcbe098b865038e6b..273634dd57b8dfbbf2a32eabe2d3fe222a6167e6 100644 (file)
@@ -431,6 +431,21 @@ describe('compiler: expression transform', () => {
     })
   })
 
+  test('should not bail constant on strings w/ ()', () => {
+    const node = parseWithExpressionTransform(
+      `{{ new Date().getFullYear() }}`,
+    ) as InterpolationNode
+    expect(node.content).toMatchObject({
+      children: [
+        'new ',
+        { constType: ConstantTypes.NOT_CONSTANT },
+        '().',
+        { constType: ConstantTypes.NOT_CONSTANT },
+        '()',
+      ],
+    })
+  })
+
   describe('ES Proposals support', () => {
     test('bigInt', () => {
       const node = parseWithExpressionTransform(
index 2d8dc8bc8502663552e3732d3df634ae40a5037e..35aa9a373a4298f5a5f4bbd9a5e6b396b3c3c271 100644 (file)
@@ -311,7 +311,12 @@ export function processExpression(
       } else {
         // The identifier is considered constant unless it's pointing to a
         // local scope variable (a v-for alias, or a v-slot prop)
-        if (!(needPrefix && isLocal)) {
+        if (
+          !(needPrefix && isLocal) &&
+          parent.type !== 'CallExpression' &&
+          parent.type !== 'NewExpression' &&
+          parent.type !== 'MemberExpression'
+        ) {
           ;(node as QualifiedId).isConstant = true
         }
         // also generate sub-expressions for other identifiers for better