]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix codegen for literal const in non-inline mode
authorEvan You <yyx990803@gmail.com>
Thu, 30 Mar 2023 07:19:27 +0000 (15:19 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 30 Mar 2023 07:19:27 +0000 (15:19 +0800)
packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
packages/compiler-core/src/transforms/transformExpression.ts

index 40070778b2af26dd674145099697b72138e9ba76..66f988d3474f6612635ecd06083c889039399b2b 100644 (file)
@@ -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]} */`
index 080d61d739f4981c6285366b189eab04fbe550d1..466027682b13d3525b1ff06883099222e96c378d 100644 (file)
@@ -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}`
       }