Skip to content

Commit

Permalink
fix(compiler-sfc): async transformer doesn't correctly detect need fo…
Browse files Browse the repository at this point in the history
…r semicolon in block #5808
  • Loading branch information
liulinboyi authored and yyx990803 committed May 13, 2022
1 parent de7a879 commit 6c3b681
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ export function compileScript(

// walk statements & named exports / variable declarations for top level
// await
let body = scriptSetupAst.body
if (
(node.type === 'VariableDeclaration' && !node.declare) ||
node.type.endsWith('Statement')
Expand All @@ -1135,11 +1136,32 @@ export function compileScript(
if (isFunctionType(child)) {
this.skip()
}
if (child.type === 'ExpressionStatement') {
if (
child.expression.type === 'AwaitExpression' ||
child.expression.type === 'BinaryExpression'
) {
// set the parent of the AwaitExpression's body to the variable body
if (parent && parent.type === 'BlockStatement') {
body = parent.body
} else {
body = scriptSetupAst.body
}
}
}
if (child.type === 'AwaitExpression') {
hasAwait = true
const needsSemi = scriptSetupAst.body.some(n => {
// set the AwaitExpression's index in the parent of the AwaitExpression's body to the variable AwaitIndex
let AwaitIndex = 0
let needsSemi = body.some((n, index) => {
AwaitIndex = index
return n.type === 'ExpressionStatement' && n.start === child.start
})
// if the variable body is not equal scriptSetupAst.body
if (body !== scriptSetupAst.body) {
// judge the AwaitExpression is not in the first of the parent of the AwaitExpression's body
needsSemi = needsSemi && AwaitIndex > 0
}
processAwait(
child,
needsSemi,
Expand Down

0 comments on commit 6c3b681

Please sign in to comment.