Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/compiler-core/__tests__/transforms/vBind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ describe('compiler: transform v-bind', () => {
})
})

test('no expression (shorthand) in-DOM template', () => {
try {
__BROWSER__ = true
// in-DOM templates will be parsed by the browser into :id=""
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
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export const transformVBindShorthand: NodeTransform = (node, context) => {
if (
prop.type === NodeTypes.DIRECTIVE &&
prop.name === 'bind' &&
!prop.exp
(!prop.exp ||
// #13930 :foo will be processed as :foo="" in in-DOM template
(__BROWSER__ &&
prop.exp.type === NodeTypes.SIMPLE_EXPRESSION &&
!prop.exp.isStatic &&
!prop.exp.content))
) {
const arg = prop.arg!
if (arg.type !== NodeTypes.SIMPLE_EXPRESSION || !arg.isStatic) {
Expand Down
Loading