Skip to content

Commit 0ca9137

Browse files
committed
wip: tests for defineContext()
1 parent 128621d commit 0ca9137

File tree

5 files changed

+593
-351
lines changed

5 files changed

+593
-351
lines changed

packages/compiler-core/src/transforms/transformElement.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,10 @@ export function resolveComponentType(
272272
}
273273
const tagFromConst = checkType(BindingTypes.CONST)
274274
if (tagFromConst) {
275-
// constant setup bindings (e.g. imports) can be used as-is
276-
return tagFromConst
275+
return context.inline
276+
? // in inline mode, const setup bindings (e.g. imports) can be used as-is
277+
tagFromConst
278+
: `$setup[${JSON.stringify(tagFromConst)}]`
277279
}
278280
}
279281

packages/compiler-core/src/transforms/transformExpression.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,35 @@ export function processExpression(
102102
const { inline, bindingMetadata } = context
103103

104104
// const bindings exposed from setup - we know they never change
105-
if (inline && bindingMetadata[node.content] === BindingTypes.CONST) {
105+
if (bindingMetadata[node.content] === BindingTypes.CONST) {
106106
node.isRuntimeConstant = true
107107
return node
108108
}
109109

110110
const prefix = (raw: string) => {
111111
const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw]
112-
if (type === BindingTypes.CONST) {
113-
return raw
114-
}
115112
if (inline) {
116113
// setup inline mode
117-
if (type === BindingTypes.SETUP) {
114+
if (type === BindingTypes.CONST) {
115+
return raw
116+
} else if (type === BindingTypes.SETUP) {
118117
return `${context.helperString(UNREF)}(${raw})`
119118
} else if (type === BindingTypes.PROPS) {
120119
// use __props which is generated by compileScript so in ts mode
121120
// it gets correct type
122121
return `__props.${raw}`
123122
}
124123
}
125-
// fallback to normal
126-
return `${type ? `$${type}` : `_ctx`}.${raw}`
124+
125+
if (type === BindingTypes.CONST) {
126+
// setup const binding in non-inline mode
127+
return `$setup.${raw}`
128+
} else if (type) {
129+
return `$${type}.${raw}`
130+
} else {
131+
// fallback to ctx
132+
return `_ctx.${raw}`
133+
}
127134
}
128135

129136
// fast path if expression is a simple identifier.

0 commit comments

Comments
 (0)