test('literal const handling, non-inline mode', () => {
const { code } = compileWithBindingMetadata(`<div>{{ literal }}</div>`)
- expect(code).toMatch(`toDisplayString(literal)`)
+ expect(code).toMatch(`toDisplayString($setup.literal)`)
// #7973 should skip patch for literal const
expect(code).not.toMatch(
`${PatchFlags.TEXT} /* ${PatchFlagNames[PatchFlags.TEXT]} */`
return genPropsAccessExp(bindingMetadata.__propsAliases![raw])
}
} else {
- if (type && type.startsWith('setup')) {
+ if (
+ (type && type.startsWith('setup')) ||
+ type === BindingTypes.LITERAL_CONST
+ ) {
// setup bindings in non-inline mode
return `$setup.${raw}`
} else if (type === BindingTypes.PROPS_ALIASED) {
return `$props['${bindingMetadata.__propsAliases![raw]}']`
- } else if (type === BindingTypes.LITERAL_CONST) {
- return raw
} else if (type) {
return `$${type}.${raw}`
}
})
assertCode(content)
})
+
+ test('template binding access in inline mode', () => {
+ const { content } = compile(
+ `
+ <script setup>
+ const foo = 'bar'
+ </script>
+ <template>{{ foo }}</template>
+ `
+ )
+ expect(content).toMatch('_toDisplayString(foo)')
+ })
})