fix(compiler): report invalid directive name error (#4494) (#4495)

This commit is contained in:
Herrington Darkholme
2021-09-02 21:42:20 +08:00
committed by GitHub
parent d7f1b771f8
commit c00925ed5c
3 changed files with 29 additions and 1 deletions

View File

@@ -1244,6 +1244,27 @@ describe('compiler: parse', () => {
}
})
})
test('directive with no name', () => {
let errorCode = -1
const ast = baseParse('<div v-/>', {
onError: err => {
errorCode = err.code as number
}
})
const directive = (ast.children[0] as ElementNode).props[0]
expect(errorCode).toBe(ErrorCodes.X_MISSING_DIRECTIVE_NAME)
expect(directive).toStrictEqual({
type: NodeTypes.ATTRIBUTE,
name: 'v-',
value: undefined,
loc: {
start: { offset: 5, line: 1, column: 6 },
end: { offset: 7, line: 1, column: 8 },
source: 'v-'
}
})
})
test('v-bind shorthand', () => {
const ast = baseParse('<div :a=b />')