Skip to content

Commit

Permalink
fix(compiler-core): properly parse await expressions in edge cases
Browse files Browse the repository at this point in the history
close #10754
  • Loading branch information
yyx990803 committed Apr 22, 2024
1 parent 173ec65 commit b92c25f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Expand Up @@ -598,5 +598,33 @@ describe('compiler: expression transform', () => {
`${PatchFlags.TEXT} /* ${PatchFlagNames[PatchFlags.TEXT]} */`,
)
})

// #10754
test('await expression in right hand of assignment, inline mode', () => {
const node = parseWithExpressionTransform(
`{{ (async () => { x = await bar })() }}`,
{
inline: true,
bindingMetadata: {
x: BindingTypes.SETUP_LET,
bar: BindingTypes.SETUP_CONST,
},
},
) as InterpolationNode
expect(node.content).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`(async () => { `,
{
content: `_isRef(x) ? x.value = await bar : x`,
},
` = await `,
{
content: `bar`,
},
` })()`,
],
})
})
})
})
7 changes: 4 additions & 3 deletions packages/compiler-core/src/transforms/transformExpression.ts
Expand Up @@ -40,7 +40,7 @@ import type {
UpdateExpression,
} from '@babel/types'
import { validateBrowserExpression } from '../validateExpression'
import { parse } from '@babel/parser'
import { parseExpression } from '@babel/parser'
import { IS_REF, UNREF } from '../runtimeHelpers'
import { BindingTypes } from '../options'

Expand Down Expand Up @@ -272,9 +272,10 @@ export function processExpression(
? ` ${rawExp} `
: `(${rawExp})${asParams ? `=>{}` : ``}`
try {
ast = parse(source, {
ast = parseExpression(source, {
sourceType: 'module',
plugins: context.expressionPlugins,
}).program
})
} catch (e: any) {
context.onError(
createCompilerError(
Expand Down

0 comments on commit b92c25f

Please sign in to comment.