Skip to content

Commit e49dffc

Browse files
committed
fix(parser): directive arg should be undefined on shorthands with no arg
1 parent ebaeb2e commit e49dffc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/compiler-core/__tests__/parse.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,17 @@ describe('compiler: parse', () => {
19411941
})
19421942
})
19431943

1944+
test('arg should be undefined on shorthand dirs with no arg', () => {
1945+
const ast = baseParse(`<template #></template>`)
1946+
const el = ast.children[0] as ElementNode
1947+
expect(el.props[0]).toMatchObject({
1948+
type: NodeTypes.DIRECTIVE,
1949+
name: 'slot',
1950+
exp: undefined,
1951+
arg: undefined
1952+
})
1953+
})
1954+
19441955
describe('decodeEntities option', () => {
19451956
test('use decode by default', () => {
19461957
const ast: any = baseParse('&gt;&lt;&amp;&apos;&quot;&foo;')

packages/compiler-core/src/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ const tokenizer = new Tokenizer(stack, {
238238
},
239239

240240
ondirarg(start, end) {
241+
if (start === end) return
241242
const arg = getSlice(start, end)
242243
if (inVPre) {
243244
;(currentProp as AttributeNode).name += arg

0 commit comments

Comments
 (0)