Skip to content

Commit b3cca26

Browse files
authored
fix(compiler-core): fix v-bind shorthand handling for in-DOM templates (#13933)
close #13930
1 parent 8ec7cb1 commit b3cca26

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ describe('compiler: transform v-bind', () => {
112112
})
113113
})
114114

115+
test('no expression (shorthand) in-DOM templates', () => {
116+
try {
117+
__BROWSER__ = true
118+
// :id in in-DOM templates will be parsed into :id="" by browser
119+
const node = parseWithVBind(`<div :id="" />`)
120+
const props = (node.codegenNode as VNodeCall).props as ObjectExpression
121+
expect(props.properties[0]).toMatchObject({
122+
key: {
123+
content: `id`,
124+
isStatic: true,
125+
},
126+
value: {
127+
content: `id`,
128+
isStatic: false,
129+
},
130+
})
131+
} finally {
132+
__BROWSER__ = false
133+
}
134+
})
135+
115136
test('dynamic arg', () => {
116137
const node = parseWithVBind(`<div v-bind:[id]="id"/>`)
117138
const props = (node.codegenNode as VNodeCall).props as CallExpression

packages/compiler-core/src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
10541054
`[@vue/compiler-core] decodeEntities option is passed but will be ` +
10551055
`ignored in non-browser builds.`,
10561056
)
1057-
} else if (__BROWSER__ && !currentOptions.decodeEntities) {
1057+
} else if (__BROWSER__ && !__TEST__ && !currentOptions.decodeEntities) {
10581058
throw new Error(
10591059
`[@vue/compiler-core] decodeEntities option is required in browser builds.`,
10601060
)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export const transformVBindShorthand: NodeTransform = (node, context) => {
1515
if (
1616
prop.type === NodeTypes.DIRECTIVE &&
1717
prop.name === 'bind' &&
18-
!prop.exp
18+
(!prop.exp ||
19+
// #13930 :foo in in-DOM templates will be parsed into :foo="" by browser
20+
(__BROWSER__ &&
21+
prop.exp.type === NodeTypes.SIMPLE_EXPRESSION &&
22+
!prop.exp.content.trim()))
1923
) {
2024
const arg = prop.arg!
2125
if (arg.type !== NodeTypes.SIMPLE_EXPRESSION || !arg.isStatic) {

0 commit comments

Comments
 (0)