@@ -11,6 +11,7 @@ import type { AwaitExpression, Node } from '@babel/types'
11
11
import {
12
12
CSS_VARS_HELPER ,
13
13
DEFINE_COMPONENT_HELPER ,
14
+ EXPECTED_ERROR ,
14
15
TO_REFS_HELPER ,
15
16
UN_REF_HELPER ,
16
17
USE_DEFAULTS_HELPER ,
@@ -43,21 +44,27 @@ function wrapWithAsyncContext(
43
44
44
45
function mayContainAwaitExpr ( targetNode : Node ) {
45
46
let awaitExpr : AwaitExpression | undefined
46
- let isMayCotainAwaitExpr = (
47
+ if ( ! (
47
48
isVariableDeclaration ( targetNode )
48
49
|| isAssignmentExpression ( targetNode )
49
50
|| isExpressionStatement ( targetNode )
50
- )
51
- if ( ! isMayCotainAwaitExpr ) {
51
+ ) ) {
52
52
return false
53
53
}
54
- traverse ( targetNode , ( descendant ) => {
55
- if ( isAwaitExpression ( descendant ) ) {
56
- isMayCotainAwaitExpr = true
57
- awaitExpr = descendant
54
+ try {
55
+ traverse ( targetNode , ( descendant ) => {
56
+ if ( isAwaitExpression ( descendant ) ) {
57
+ awaitExpr = descendant
58
+ throw new Error ( EXPECTED_ERROR )
59
+ }
60
+ } )
61
+ }
62
+ catch ( error ) {
63
+ if ( error === EXPECTED_ERROR ) {
64
+ return awaitExpr
58
65
}
59
- } )
60
- return isMayCotainAwaitExpr && awaitExpr
66
+ throw error
67
+ }
61
68
}
62
69
63
70
function registerImport (
@@ -89,7 +96,7 @@ function registerImport(
89
96
* We need to remove all imports from the original code, one by one, and then prepend the
90
97
* merged imports to the code, based on our analysis result.
91
98
*
92
- * 2. - Transform every Vine comonent function to be an IIFE.
99
+ * 2. - Transform every Vine component function to be an IIFE.
93
100
* it's for creating a independent scope, so we can put those statements can be hosted.
94
101
*/
95
102
export function transformFile (
@@ -169,7 +176,7 @@ export function transformFile(
169
176
170
177
// Replace the original function delcaration start to its body's first statement's start,
171
178
// and the last statement's end to the function declaration end.
172
- // Wrap all body statemnts into a `setup(...) { ... }`
179
+ // Wrap all body statements into a `setup(...) { ... }`
173
180
ms . remove ( vineCompFnStart , firstStmt . start ! )
174
181
ms . remove ( lastStmt . end ! , vineCompFnEnd )
175
182
0 commit comments