File tree 1 file changed +23
-1
lines changed
packages/compiler-sfc/src
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1126,6 +1126,7 @@ export function compileScript(
1126
1126
1127
1127
// walk statements & named exports / variable declarations for top level
1128
1128
// await
1129
+ let body = scriptSetupAst . body
1129
1130
if (
1130
1131
( node . type === 'VariableDeclaration' && ! node . declare ) ||
1131
1132
node . type . endsWith ( 'Statement' )
@@ -1135,11 +1136,32 @@ export function compileScript(
1135
1136
if ( isFunctionType ( child ) ) {
1136
1137
this . skip ( )
1137
1138
}
1139
+ if ( child . type === 'ExpressionStatement' ) {
1140
+ if (
1141
+ child . expression . type === 'AwaitExpression' ||
1142
+ child . expression . type === 'BinaryExpression'
1143
+ ) {
1144
+ // set the parent of the AwaitExpression's body to the variable body
1145
+ if ( parent && parent . type === 'BlockStatement' ) {
1146
+ body = parent . body
1147
+ } else {
1148
+ body = scriptSetupAst . body
1149
+ }
1150
+ }
1151
+ }
1138
1152
if ( child . type === 'AwaitExpression' ) {
1139
1153
hasAwait = true
1140
- const needsSemi = scriptSetupAst . body . some ( n => {
1154
+ // set the AwaitExpression's index in the parent of the AwaitExpression's body to the variable AwaitIndex
1155
+ let AwaitIndex = 0
1156
+ let needsSemi = body . some ( ( n , index ) => {
1157
+ AwaitIndex = index
1141
1158
return n . type === 'ExpressionStatement' && n . start === child . start
1142
1159
} )
1160
+ // if the variable body is not equal scriptSetupAst.body
1161
+ if ( body !== scriptSetupAst . body ) {
1162
+ // judge the AwaitExpression is not in the first of the parent of the AwaitExpression's body
1163
+ needsSemi = needsSemi && AwaitIndex > 0
1164
+ }
1143
1165
processAwait (
1144
1166
child ,
1145
1167
needsSemi ,
You can’t perform that action at this time.
0 commit comments