Skip to content

Commit

Permalink
✨ add parsing error about invalid dynamic argument (refs #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Feb 7, 2019
1 parent b57cd06 commit 9326fa0
Show file tree
Hide file tree
Showing 9 changed files with 1,539 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {

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

/**
* Get the belonging document of the given node.
Expand Down Expand Up @@ -649,6 +650,25 @@ export function convertToDirective(
locationCalculator,
)

const { argument } = directive.key
if (
argument &&
argument.type === "VIdentifier" &&
argument.name.startsWith("[") &&
invalidDynamicArgumentNextChar.test(code[argument.range[1]])
) {
insertError(
document,
new ParseError(
"Dynamic argument cannot contain spaces, '=', '/', or '>'.",
undefined,
argument.range[1],
argument.loc.end.line,
argument.loc.end.column,
),
)
}

if (node.value == null) {
return
}
Expand Down
Loading

0 comments on commit 9326fa0

Please sign in to comment.