fix(compiler-sfc): fix props codegen w/ leading import

fix #4764
This commit is contained in:
Evan You
2021-10-08 12:52:48 -04:00
parent 9e3d7731c7
commit d4c04e9799
4 changed files with 51 additions and 14 deletions

View File

@@ -1205,25 +1205,25 @@ export function compileScript(
// we use a default __props so that template expressions referencing props
// can use it directly
if (propsIdentifier) {
s.prependRight(
s.prependLeft(
startOffset,
`\nconst ${propsIdentifier} = __props${
propsTypeDecl ? ` as ${genSetupPropsType(propsTypeDecl)}` : ``
}`
}\n`
)
}
if (propsDestructureRestId) {
s.prependRight(
s.prependLeft(
startOffset,
`\nconst ${propsDestructureRestId} = ${helper(
`createPropsRestProxy`
)}(__props, ${JSON.stringify(Object.keys(propsDestructuredBindings))})`
)}(__props, ${JSON.stringify(Object.keys(propsDestructuredBindings))})\n`
)
}
// inject temp variables for async context preservation
if (hasAwait) {
const any = isTS ? `: any` : ``
s.prependRight(startOffset, `\nlet __temp${any}, __restore${any}\n`)
s.prependLeft(startOffset, `\nlet __temp${any}, __restore${any}\n`)
}
const destructureElements =