Преглед изворни кода

fix(parser): directive arg should be undefined on shorthands with no arg

Evan You пре 2 година
родитељ
комит
e49dffc9ec
2 измењених фајлова са 12 додато и 0 уклоњено
  1. 11 0
      packages/compiler-core/__tests__/parse.spec.ts
  2. 1 0
      packages/compiler-core/src/parser.ts

+ 11 - 0
packages/compiler-core/__tests__/parse.spec.ts

@@ -1941,6 +1941,17 @@ describe('compiler: parse', () => {
     })
   })
 
+  test('arg should be undefined on shorthand dirs with no arg', () => {
+    const ast = baseParse(`<template #></template>`)
+    const el = ast.children[0] as ElementNode
+    expect(el.props[0]).toMatchObject({
+      type: NodeTypes.DIRECTIVE,
+      name: 'slot',
+      exp: undefined,
+      arg: undefined
+    })
+  })
+
   describe('decodeEntities option', () => {
     test('use decode by default', () => {
       const ast: any = baseParse('&gt;&lt;&amp;&apos;&quot;&foo;')

+ 1 - 0
packages/compiler-core/src/parser.ts

@@ -238,6 +238,7 @@ const tokenizer = new Tokenizer(stack, {
   },
 
   ondirarg(start, end) {
+    if (start === end) return
     const arg = getSlice(start, end)
     if (inVPre) {
       ;(currentProp as AttributeNode).name += arg