Skip to content

Commit b92c25f

Browse files
committedApr 22, 2024··
fix(compiler-core): properly parse await expressions in edge cases
close #10754
1 parent 173ec65 commit b92c25f

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed
 

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

+28
Original file line numberDiff line numberDiff line change
@@ -598,5 +598,33 @@ describe('compiler: expression transform', () => {
598598
`${PatchFlags.TEXT} /* ${PatchFlagNames[PatchFlags.TEXT]} */`,
599599
)
600600
})
601+
602+
// #10754
603+
test('await expression in right hand of assignment, inline mode', () => {
604+
const node = parseWithExpressionTransform(
605+
`{{ (async () => { x = await bar })() }}`,
606+
{
607+
inline: true,
608+
bindingMetadata: {
609+
x: BindingTypes.SETUP_LET,
610+
bar: BindingTypes.SETUP_CONST,
611+
},
612+
},
613+
) as InterpolationNode
614+
expect(node.content).toMatchObject({
615+
type: NodeTypes.COMPOUND_EXPRESSION,
616+
children: [
617+
`(async () => { `,
618+
{
619+
content: `_isRef(x) ? x.value = await bar : x`,
620+
},
621+
` = await `,
622+
{
623+
content: `bar`,
624+
},
625+
` })()`,
626+
],
627+
})
628+
})
601629
})
602630
})

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import type {
4040
UpdateExpression,
4141
} from '@babel/types'
4242
import { validateBrowserExpression } from '../validateExpression'
43-
import { parse } from '@babel/parser'
43+
import { parseExpression } from '@babel/parser'
4444
import { IS_REF, UNREF } from '../runtimeHelpers'
4545
import { BindingTypes } from '../options'
4646

@@ -272,9 +272,10 @@ export function processExpression(
272272
? ` ${rawExp} `
273273
: `(${rawExp})${asParams ? `=>{}` : ``}`
274274
try {
275-
ast = parse(source, {
275+
ast = parseExpression(source, {
276+
sourceType: 'module',
276277
plugins: context.expressionPlugins,
277-
}).program
278+
})
278279
} catch (e: any) {
279280
context.onError(
280281
createCompilerError(

0 commit comments

Comments
 (0)
Please sign in to comment.