fix(compiler): improve auto prefixing cases

This commit is contained in:
Evan You
2019-09-27 23:20:26 -04:00
parent 262be6733c
commit 6377af483b
2 changed files with 86 additions and 22 deletions

View File

@@ -308,6 +308,59 @@ describe('compiler: expression transform', () => {
})
})
test('should prefix default value of a function expression param', () => {
const node = parseWithExpressionTransform(
`{{ (foo = baz) => foo + bar }}`
) as InterpolationNode
expect(node.content).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`(`,
{ content: `foo` },
` = `,
{ content: `_ctx.baz` },
`) => `,
{ content: `foo` },
` + `,
{ content: `_ctx.bar` }
]
})
})
test('should not prefix function param destructuring', () => {
const node = parseWithExpressionTransform(
`{{ ({ foo }) => foo + bar }}`
) as InterpolationNode
expect(node.content).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`({ foo }) => `,
{ content: `foo` },
` + `,
{ content: `_ctx.bar` }
]
})
})
test('should prefix default value of function param destructuring', () => {
const node = parseWithExpressionTransform(
`{{ ({ foo = bar }) => foo + bar }}`
) as InterpolationNode
expect(node.content).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`({ `,
{ content: `foo` },
` = `,
{ content: `_ctx.bar` },
` }) => `,
{ content: `foo` },
` + `,
{ content: `_ctx.bar` }
]
})
})
test('should not prefix an object property key', () => {
const node = parseWithExpressionTransform(
`{{ { foo: bar } }}`