Skip to content

Commit

Permalink
fix(compiler-core): fix codegen for literal const in non-inline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 30, 2023
1 parent ba4cec3 commit 6bda4b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,16 @@ describe('compiler: expression transform', () => {
const { code } = compileWithBindingMetadata(`<div>{{ literal }}</div>`, {
inline: true
})
expect(code).toMatch(`toDisplayString(literal)`)
// #7973 should skip patch for literal const
expect(code).not.toMatch(
`${PatchFlags.TEXT} /* ${PatchFlagNames[PatchFlags.TEXT]} */`
)
})

test('literal const handling, non-inline mode', () => {
const { code } = compileWithBindingMetadata(`<div>{{ literal }}</div>`)
expect(code).toMatch(`toDisplayString(literal)`)
// #7973 should skip patch for literal const
expect(code).not.toMatch(
`${PatchFlags.TEXT} /* ${PatchFlagNames[PatchFlags.TEXT]} */`
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler-core/src/transforms/transformExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ export function processExpression(
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}`
}
Expand Down

0 comments on commit 6bda4b6

Please sign in to comment.