Skip to content

Commit 080f58a

Browse files
committed
Hoist async component declarations
1 parent 949c6cf commit 080f58a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/core/transformScriptSetup.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@ import { ParsedSFC, ScriptSetupTransformOptions } from '../types'
77
import { applyMacros } from './macros'
88
import { getIdentifierDeclarations } from './identifiers'
99

10+
function isAsyncImport(node: any) {
11+
if (node.type === 'VariableDeclaration') {
12+
const declaration = node.declarations[0]
13+
14+
return declaration.init.callee != null
15+
&& declaration.init.callee.name === 'defineAsyncComponent'
16+
}
17+
18+
return false
19+
}
20+
1021
export function transformScriptSetup(sfc: ParsedSFC, options?: ScriptSetupTransformOptions) {
1122
const { scriptSetup, script, template } = sfc
1223

1324
const { nodes: body, props, expose } = applyMacros(scriptSetup.ast.body)
1425

1526
const [hoisted, setupBody] = partition(
1627
body,
17-
n => n.type === 'ImportDeclaration'
28+
n =>
29+
isAsyncImport(n)
30+
|| n.type === 'ImportDeclaration'
1831
|| n.type === 'ExportNamedDeclaration'
1932
|| n.type.startsWith('TS'),
2033
)

0 commit comments

Comments
 (0)