Skip to content

Commit fefce06

Browse files
committed
fix(compiler-core): fix bail constant for globals
1 parent 638a79f commit fefce06

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,21 @@ describe('compiler: expression transform', () => {
431431
})
432432
})
433433

434+
test('should not bail constant on strings w/ ()', () => {
435+
const node = parseWithExpressionTransform(
436+
`{{ new Date().getFullYear() }}`,
437+
) as InterpolationNode
438+
expect(node.content).toMatchObject({
439+
children: [
440+
'new ',
441+
{ constType: ConstantTypes.NOT_CONSTANT },
442+
'().',
443+
{ constType: ConstantTypes.NOT_CONSTANT },
444+
'()',
445+
],
446+
})
447+
})
448+
434449
describe('ES Proposals support', () => {
435450
test('bigInt', () => {
436451
const node = parseWithExpressionTransform(

packages/compiler-core/src/transforms/transformExpression.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,12 @@ export function processExpression(
311311
} else {
312312
// The identifier is considered constant unless it's pointing to a
313313
// local scope variable (a v-for alias, or a v-slot prop)
314-
if (!(needPrefix && isLocal)) {
314+
if (
315+
!(needPrefix && isLocal) &&
316+
parent.type !== 'CallExpression' &&
317+
parent.type !== 'NewExpression' &&
318+
parent.type !== 'MemberExpression'
319+
) {
315320
;(node as QualifiedId).isConstant = true
316321
}
317322
// also generate sub-expressions for other identifiers for better

0 commit comments

Comments
 (0)