Skip to content

Commit 555e626

Browse files
committed
feat: support false prop shorthand
1 parent 3942dbe commit 555e626

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ describe('compiler: transform v-bind', () => {
133133
}
134134
})
135135

136+
test('no expression (false shorthand)', () => {
137+
const node = parseWithVBind(`<div !id />`)
138+
const props = (node.codegenNode as VNodeCall).props as ObjectExpression
139+
expect(props.properties[0]).toMatchObject({
140+
key: {
141+
content: `id`,
142+
isStatic: true,
143+
},
144+
value: {
145+
content: `false`,
146+
isStatic: false,
147+
},
148+
})
149+
})
150+
136151
test('dynamic arg', () => {
137152
const node = parseWithVBind(`<div v-bind:[id]="id"/>`)
138153
const props = (node.codegenNode as VNodeCall).props as CallExpression

packages/compiler-core/src/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const tokenizer = new Tokenizer(stack, {
200200
ondirname(start, end) {
201201
const raw = getSlice(start, end)
202202
const name =
203-
raw === '.' || raw === ':'
203+
raw === '!' || raw === '.' || raw === ':'
204204
? 'bind'
205205
: raw === '@'
206206
? 'on'
@@ -225,7 +225,7 @@ const tokenizer = new Tokenizer(stack, {
225225
type: NodeTypes.DIRECTIVE,
226226
name,
227227
rawName: raw,
228-
exp: undefined,
228+
exp: raw === '!' ? createSimpleExpression('false') : undefined,
229229
arg: undefined,
230230
modifiers: raw === '.' ? [createSimpleExpression('prop')] : [],
231231
loc: getLoc(start),

packages/compiler-core/src/tokenizer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ export default class Tokenizer {
665665
this.state = State.InDirName
666666
this.sectionStart = this.index
667667
} else if (
668+
c === CharCodes.ExclamationMark ||
668669
c === CharCodes.Dot ||
669670
c === CharCodes.Colon ||
670671
c === CharCodes.At ||

0 commit comments

Comments
 (0)