refactor(compiler-sfc): always parse explicit script setup signature
This commit is contained in:
parent
941b645d58
commit
ed2eb81317
@ -366,10 +366,8 @@ export function compileScript(
|
||||
// record declared types for runtime props type generation
|
||||
const declaredTypes: Record<string, string[]> = {}
|
||||
|
||||
if (isTS && hasExplicitSignature) {
|
||||
// <script setup="xxx" lang="ts">
|
||||
// parse the signature to extract the props/emit variables the user wants
|
||||
// we need them to find corresponding type declarations.
|
||||
// <script setup="xxx">
|
||||
if (hasExplicitSignature) {
|
||||
let signatureAST
|
||||
try {
|
||||
signatureAST = _parse(`(${setupValue})=>{}`, { plugins }).program.body[0]
|
||||
@ -382,6 +380,11 @@ export function compileScript(
|
||||
)}`
|
||||
)
|
||||
}
|
||||
|
||||
if (isTS) {
|
||||
// <script setup="xxx" lang="ts">
|
||||
// parse the signature to extract the props/emit variables the user wants
|
||||
// we need them to find corresponding type declarations.
|
||||
const params = ((signatureAST as ExpressionStatement)
|
||||
.expression as ArrowFunctionExpression).params
|
||||
if (params[0] && params[0].type === 'Identifier') {
|
||||
@ -407,6 +410,7 @@ export function compileScript(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. parse <script setup> and walk over top level statements
|
||||
const scriptSetupAst = parse(
|
||||
|
Loading…
x
Reference in New Issue
Block a user