]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix v-bind shorthand handling for in-DOM templates (#13933)
authoredison <daiwei521@126.com>
Wed, 5 Nov 2025 08:51:29 +0000 (16:51 +0800)
committerGitHub <noreply@github.com>
Wed, 5 Nov 2025 08:51:29 +0000 (16:51 +0800)
close #13930

packages/compiler-core/__tests__/transforms/vBind.spec.ts
packages/compiler-core/src/parser.ts
packages/compiler-core/src/transforms/transformVBindShorthand.ts

index 2221d926e52f5784c9e3fcdd92f043d9806d6abe..ff21351d05da42fabdd3a6af11cfa38437d67538 100644 (file)
@@ -112,6 +112,27 @@ describe('compiler: transform v-bind', () => {
     })
   })
 
+  test('no expression (shorthand) in-DOM templates', () => {
+    try {
+      __BROWSER__ = true
+      // :id in in-DOM templates will be parsed into :id="" by browser
+      const node = parseWithVBind(`<div :id="" />`)
+      const props = (node.codegenNode as VNodeCall).props as ObjectExpression
+      expect(props.properties[0]).toMatchObject({
+        key: {
+          content: `id`,
+          isStatic: true,
+        },
+        value: {
+          content: `id`,
+          isStatic: false,
+        },
+      })
+    } finally {
+      __BROWSER__ = false
+    }
+  })
+
   test('dynamic arg', () => {
     const node = parseWithVBind(`<div v-bind:[id]="id"/>`)
     const props = (node.codegenNode as VNodeCall).props as CallExpression
index a6e25681d75ba8e668b82bd248aeb82fcef39bbc..2d85289fc6842afe6c9cfaa97b194e86eb3416a6 100644 (file)
@@ -1054,7 +1054,7 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
         `[@vue/compiler-core] decodeEntities option is passed but will be ` +
           `ignored in non-browser builds.`,
       )
-    } else if (__BROWSER__ && !currentOptions.decodeEntities) {
+    } else if (__BROWSER__ && !__TEST__ && !currentOptions.decodeEntities) {
       throw new Error(
         `[@vue/compiler-core] decodeEntities option is required in browser builds.`,
       )
index ff5b51047a3691da3fd2f579f3ae26d902fd12e8..a6b989e734ac988f5c9b5c7a678a708d49d87558 100644 (file)
@@ -15,7 +15,11 @@ export const transformVBindShorthand: NodeTransform = (node, context) => {
       if (
         prop.type === NodeTypes.DIRECTIVE &&
         prop.name === 'bind' &&
-        !prop.exp
+        (!prop.exp ||
+          // #13930 :foo in in-DOM templates will be parsed into :foo="" by browser
+          (__BROWSER__ &&
+            prop.exp.type === NodeTypes.SIMPLE_EXPRESSION &&
+            !prop.exp.content.trim()))
       ) {
         const arg = prop.arg!
         if (arg.type !== NodeTypes.SIMPLE_EXPRESSION || !arg.isStatic) {