Skip to content

Commit 3dea80b

Browse files
authored
Merge branch 'main' into fix/vuejs#10827
2 parents 9f619d2 + 09b4df8 commit 3dea80b

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,16 @@ describe('compiler: expression transform', () => {
421421
})
422422
})
423423

424+
// #10807
425+
test('should not bail constant on strings w/ ()', () => {
426+
const node = parseWithExpressionTransform(
427+
`{{ { foo: 'ok()' } }}`,
428+
) as InterpolationNode
429+
expect(node.content).toMatchObject({
430+
constType: ConstantTypes.CAN_STRINGIFY,
431+
})
432+
})
433+
424434
describe('ES Proposals support', () => {
425435
test('bigInt', () => {
426436
const node = parseWithExpressionTransform(

packages/compiler-core/src/babelUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import type {
1010
} from '@babel/types'
1111
import { walk } from 'estree-walker'
1212

13+
/**
14+
* Return value indicates whether the AST walked can be a constant
15+
*/
1316
export function walkIdentifiers(
1417
root: Node,
1518
onIdentifier: (

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ import { BindingTypes } from '../options'
4646

4747
const isLiteralWhitelisted = /*#__PURE__*/ makeMap('true,false,null,this')
4848

49-
// a heuristic safeguard to bail constant expressions on presence of
50-
// likely function invocation and member access
51-
const constantBailRE = /\w\s*\(|\.[^\d]/
52-
5349
export const transformExpression: NodeTransform = (node, context) => {
5450
if (node.type === NodeTypes.INTERPOLATION) {
5551
node.content = processExpression(
@@ -226,8 +222,6 @@ export function processExpression(
226222

227223
// fast path if expression is a simple identifier.
228224
const rawExp = node.content
229-
// bail constant on parens (function invocation) and dot (member access)
230-
const bailConstant = constantBailRE.test(rawExp)
231225

232226
let ast = node.ast
233227

@@ -317,7 +311,7 @@ export function processExpression(
317311
} else {
318312
// The identifier is considered constant unless it's pointing to a
319313
// local scope variable (a v-for alias, or a v-slot prop)
320-
if (!(needPrefix && isLocal) && !bailConstant) {
314+
if (!(needPrefix && isLocal)) {
321315
;(node as QualifiedId).isConstant = true
322316
}
323317
// also generate sub-expressions for other identifiers for better
@@ -371,9 +365,7 @@ export function processExpression(
371365
ret.ast = ast
372366
} else {
373367
ret = node
374-
ret.constType = bailConstant
375-
? ConstantTypes.NOT_CONSTANT
376-
: ConstantTypes.CAN_STRINGIFY
368+
ret.constType = ConstantTypes.CAN_STRINGIFY
377369
}
378370
ret.identifiers = Object.keys(knownIds)
379371
return ret

packages/runtime-core/src/componentSlots.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const initSlots = (
171171
if (type) {
172172
extend(slots, children as InternalSlots)
173173
// make compiler marker non-enumerable
174-
def(slots, '_', type)
174+
def(slots, '_', type, true)
175175
} else {
176176
normalizeObjectSlots(children as RawSlots, slots, instance)
177177
}

packages/shared/src/general.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,16 @@ export const invokeArrayFns = (fns: Function[], arg?: any) => {
139139
}
140140
}
141141

142-
export const def = (obj: object, key: string | symbol, value: any) => {
142+
export const def = (
143+
obj: object,
144+
key: string | symbol,
145+
value: any,
146+
writable = false,
147+
) => {
143148
Object.defineProperty(obj, key, {
144149
configurable: true,
145150
enumerable: false,
151+
writable,
146152
value,
147153
})
148154
}

0 commit comments

Comments
 (0)