Skip to content

Commit 9326fa0

Browse files
committed
✨ add parsing error about invalid dynamic argument (refs vuejs#39)
1 parent b57cd06 commit 9326fa0

File tree

9 files changed

+1539
-0
lines changed

9 files changed

+1539
-0
lines changed

src/template/index.ts

+20
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636

3737
const shorthandSign = /^[.:@#]/u
3838
const shorthandNameMap = { ":": "bind", ".": "bind", "@": "on", "#": "slot" }
39+
const invalidDynamicArgumentNextChar = /^[\s\r\n=/>]$/u
3940

4041
/**
4142
* Get the belonging document of the given node.
@@ -649,6 +650,25 @@ export function convertToDirective(
649650
locationCalculator,
650651
)
651652

653+
const { argument } = directive.key
654+
if (
655+
argument &&
656+
argument.type === "VIdentifier" &&
657+
argument.name.startsWith("[") &&
658+
invalidDynamicArgumentNextChar.test(code[argument.range[1]])
659+
) {
660+
insertError(
661+
document,
662+
new ParseError(
663+
"Dynamic argument cannot contain spaces, '=', '/', or '>'.",
664+
undefined,
665+
argument.range[1],
666+
argument.loc.end.line,
667+
argument.loc.end.column,
668+
),
669+
)
670+
}
671+
652672
if (node.value == null) {
653673
return
654674
}

0 commit comments

Comments
 (0)