wip: optimize binding access to known imported components

This commit is contained in:
Evan You
2020-11-10 18:06:38 -05:00
parent 4977526a2b
commit 4e8ef55237
4 changed files with 49 additions and 21 deletions

View File

@@ -736,7 +736,7 @@ export function compileScript(
`\nexport ${hasAwait ? `async ` : ``}function setup(${args}) {\n`
)
const exposedBindings = { ...userImports, ...setupBindings }
const allBindings = { ...userImports, ...setupBindings }
// 9. inject `useCssVars` calls
if (hasCssVars) {
@@ -746,7 +746,7 @@ export function compileScript(
if (typeof vars === 'string') {
s.prependRight(
endOffset,
`\n${genCssVarsCode(vars, !!style.scoped, exposedBindings)}`
`\n${genCssVarsCode(vars, !!style.scoped, allBindings)}`
)
}
}
@@ -756,12 +756,23 @@ export function compileScript(
if (scriptAst) {
Object.assign(bindingMetadata, analyzeScriptBindings(scriptAst))
}
Object.keys(exposedBindings).forEach(key => {
bindingMetadata[key] = 'setup'
})
Object.keys(typeDeclaredProps).forEach(key => {
if (options.inlineTemplate) {
for (const [key, value] of Object.entries(userImports)) {
bindingMetadata[key] = value.endsWith('.vue')
? 'component-import'
: 'setup'
}
for (const key in setupBindings) {
bindingMetadata[key] = 'setup'
}
} else {
for (const key in allBindings) {
bindingMetadata[key] = 'setup'
}
}
for (const key in typeDeclaredProps) {
bindingMetadata[key] = 'props'
})
}
Object.assign(bindingMetadata, analyzeScriptBindings(scriptSetupAst))
// 11. generate return statement
@@ -799,7 +810,7 @@ export function compileScript(
}
} else {
// return bindings from setup
returned = `{ ${Object.keys(exposedBindings).join(', ')} }`
returned = `{ ${Object.keys(allBindings).join(', ')} }`
}
s.appendRight(endOffset, `\nreturn ${returned}\n}\n\n`)