Skip to content

Commit 6bda4b6

Browse files
committed
fix(compiler-core): fix codegen for literal const in non-inline mode
1 parent ba4cec3 commit 6bda4b6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,16 @@ describe('compiler: expression transform', () => {
540540
const { code } = compileWithBindingMetadata(`<div>{{ literal }}</div>`, {
541541
inline: true
542542
})
543+
expect(code).toMatch(`toDisplayString(literal)`)
544+
// #7973 should skip patch for literal const
545+
expect(code).not.toMatch(
546+
`${PatchFlags.TEXT} /* ${PatchFlagNames[PatchFlags.TEXT]} */`
547+
)
548+
})
549+
550+
test('literal const handling, non-inline mode', () => {
551+
const { code } = compileWithBindingMetadata(`<div>{{ literal }}</div>`)
552+
expect(code).toMatch(`toDisplayString(literal)`)
543553
// #7973 should skip patch for literal const
544554
expect(code).not.toMatch(
545555
`${PatchFlags.TEXT} /* ${PatchFlagNames[PatchFlags.TEXT]} */`

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

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ export function processExpression(
202202
return `$setup.${raw}`
203203
} else if (type === BindingTypes.PROPS_ALIASED) {
204204
return `$props['${bindingMetadata.__propsAliases![raw]}']`
205+
} else if (type === BindingTypes.LITERAL_CONST) {
206+
return raw
205207
} else if (type) {
206208
return `$${type}.${raw}`
207209
}

0 commit comments

Comments
 (0)