Skip to content

Commit

Permalink
fix(compiler-core): fix bail constant for globals
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 29, 2024
1 parent 638a79f commit fefce06
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion packages/compiler-core/src/transforms/transformExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fefce06

Please sign in to comment.