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

@@ -775,7 +775,7 @@ function parseAttribute(
}
const loc = getSelection(context, start)
if (!context.inVPre && /^(v-|:|\.|@|#)/.test(name)) {
if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
const match =
/(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
name
@@ -888,6 +888,11 @@ function parseAttribute(
}
}
// missing directive name or illegal directive name
if (!context.inVPre && startsWith(name, 'v-')) {
emitError(context, ErrorCodes.X_MISSING_DIRECTIVE_NAME)
}
return {
type: NodeTypes.ATTRIBUTE,
name,