wip: tests for defineContext()

This commit is contained in:
Evan You
2020-11-12 18:11:25 -05:00
parent 128621d6a0
commit 0ca9137188
5 changed files with 592 additions and 350 deletions

View File

@@ -272,8 +272,10 @@ export function resolveComponentType(
}
const tagFromConst = checkType(BindingTypes.CONST)
if (tagFromConst) {
// constant setup bindings (e.g. imports) can be used as-is
return tagFromConst
return context.inline
? // in inline mode, const setup bindings (e.g. imports) can be used as-is
tagFromConst
: `$setup[${JSON.stringify(tagFromConst)}]`
}
}

View File

@@ -102,19 +102,18 @@ export function processExpression(
const { inline, bindingMetadata } = context
// const bindings exposed from setup - we know they never change
if (inline && bindingMetadata[node.content] === BindingTypes.CONST) {
if (bindingMetadata[node.content] === BindingTypes.CONST) {
node.isRuntimeConstant = true
return node
}
const prefix = (raw: string) => {
const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw]
if (type === BindingTypes.CONST) {
return raw
}
if (inline) {
// setup inline mode
if (type === BindingTypes.SETUP) {
if (type === BindingTypes.CONST) {
return raw
} else if (type === BindingTypes.SETUP) {
return `${context.helperString(UNREF)}(${raw})`
} else if (type === BindingTypes.PROPS) {
// use __props which is generated by compileScript so in ts mode
@@ -122,8 +121,16 @@ export function processExpression(
return `__props.${raw}`
}
}
// fallback to normal
return `${type ? `$${type}` : `_ctx`}.${raw}`
if (type === BindingTypes.CONST) {
// setup const binding in non-inline mode
return `$setup.${raw}`
} else if (type) {
return `$${type}.${raw}`
} else {
// fallback to ctx
return `_ctx.${raw}`
}
}
// fast path if expression is a simple identifier.