Skip to content

Commit

Permalink
Fix: false positive syntax error (vuejs/eslint-plugin-vue#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Feb 17, 2018
1 parent 6111437 commit f115c26
Show file tree
Hide file tree
Showing 10 changed files with 2,468 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function parseScriptFragment(code: string, locationCalculator: LocationCalculato
* The result of parsing expressions.
*/
export interface ExpressionParseResult {
expression: ESLintExpression | VForExpression | VOnExpression
expression: ESLintExpression | VForExpression | VOnExpression | null
tokens: Token[]
comments: Token[]
references: Reference[]
Expand Down
9 changes: 7 additions & 2 deletions src/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ function parseAttributeValue(code: string, parserOptions: any, globalLocationCal
const quoted = (firstChar === "\"" || firstChar === "'")
const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(node.range[0] + (quoted ? 1 : 0))
const result = (
quoted && node.value === "" ? { expression: null, tokens: [], comments: [], variables: [], references: [] } :
directiveName === "for" ? parseVForExpression(node.value, locationCalculator, parserOptions) :
directiveName === "on" ? parseVOnExpression(node.value, locationCalculator, parserOptions) :
/* otherwise */ parseExpression(node.value, locationCalculator, parserOptions)
Expand Down Expand Up @@ -323,7 +324,9 @@ export function convertToDirective(code: string, parserOptions: any, locationCal
expression: ret.expression,
references: ret.references,
}
ret.expression.parent = directive.value
if (ret.expression != null) {
ret.expression.parent = directive.value
}

for (const variable of ret.variables) {
node.parent.parent.variables.push(variable)
Expand Down Expand Up @@ -398,7 +401,9 @@ export function processMustache(parserOptions: any, globalLocationCalculator: Lo

node.expression = ret.expression
node.references = ret.references
ret.expression.parent = node
if (ret.expression != null) {
ret.expression.parent = node
}

replaceTokens(document, { range }, ret.tokens)
insertComments(document, ret.comments)
Expand Down

0 comments on commit f115c26

Please sign in to comment.