From f115c263200479f617de7c311712972c33173a58 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sat, 17 Feb 2018 18:49:14 +0900 Subject: [PATCH] Fix: false positive syntax error (vuejs/eslint-plugin-vue#388) --- src/script/index.ts | 2 +- src/template/index.ts | 9 +- .../ast/directive-empty-value/ast.json | 2024 +++++++++++++++++ .../ast/directive-empty-value/source.vue | 8 + .../directive-empty-value/token-ranges.json | 62 + .../ast/directive-empty-value/tree.json | 251 ++ test/fixtures/ast/directives/ast.json | 60 +- .../fixtures/ast/directives/token-ranges.json | 6 +- .../fixtures/ast/error-message-empty/ast.json | 90 +- .../ast/error-message-empty/token-ranges.json | 9 +- 10 files changed, 2468 insertions(+), 53 deletions(-) create mode 100644 test/fixtures/ast/directive-empty-value/ast.json create mode 100644 test/fixtures/ast/directive-empty-value/source.vue create mode 100644 test/fixtures/ast/directive-empty-value/token-ranges.json create mode 100644 test/fixtures/ast/directive-empty-value/tree.json diff --git a/src/script/index.ts b/src/script/index.ts index 3f53b913..8c001394 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -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[] diff --git a/src/template/index.ts b/src/template/index.ts index f5aa9460..24a14806 100644 --- a/src/template/index.ts +++ b/src/template/index.ts @@ -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) @@ -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) @@ -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) diff --git a/test/fixtures/ast/directive-empty-value/ast.json b/test/fixtures/ast/directive-empty-value/ast.json new file mode 100644 index 00000000..eb98e370 --- /dev/null +++ b/test/fixtures/ast/directive-empty-value/ast.json @@ -0,0 +1,2024 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 180 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 20, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 20, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "name": "on", + "argument": "a", + "modifiers": [], + "shorthand": false, + "raw": { + "name": "on", + "argument": "a", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 27, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "expression": null, + "references": [] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 30, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 36, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 41, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 41, + 56 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 46, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 46, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "name": "on", + "argument": "a", + "modifiers": [], + "shorthand": false, + "raw": { + "name": "on", + "argument": "a", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 53, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "expression": null, + "references": [] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 56, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 67, + 90 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 67, + 84 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 21 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 72, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 72, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "name": "bind", + "argument": "a", + "modifiers": [], + "shorthand": false, + "raw": { + "name": "bind", + "argument": "a", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 81, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "expression": null, + "references": [] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 84, + 90 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 27 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 90, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 95, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 27 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 95, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 100, + 111 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 100, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "name": "bind", + "argument": "a", + "modifiers": [], + "shorthand": false, + "raw": { + "name": "bind", + "argument": "a", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 109, + 111 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "expression": null, + "references": [] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 112, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 27 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 118, + 123 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 123, + 143 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 123, + 137 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 128, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 128, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "name": "for", + "argument": null, + "modifiers": [], + "shorthand": false, + "raw": { + "name": "for", + "argument": null, + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 134, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "expression": null, + "references": [] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 137, + 143 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 24 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 143, + 148 + ], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 148, + 168 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 24 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 148, + 162 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 153, + 161 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 153, + 158 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "name": "for", + "argument": null, + "modifiers": [], + "shorthand": false, + "raw": { + "name": "for", + "argument": null, + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 159, + 161 + ], + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "expression": null, + "references": [] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 162, + 168 + ], + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 169, + 180 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 20, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": "v-on:a" + }, + { + "type": "HTMLAssociation", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 36, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 41, + 45 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 46, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "value": "v-on:a" + }, + { + "type": "HTMLAssociation", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": "'" + }, + { + "type": "Punctuator", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "'" + }, + { + "type": "HTMLTagClose", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 67, + 71 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 72, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "value": "v-bind:a" + }, + { + "type": "HTMLAssociation", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 84, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 90, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 95, + 99 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 100, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "value": "v-bind:a" + }, + { + "type": "HTMLAssociation", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "'" + }, + { + "type": "Punctuator", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "value": "'" + }, + { + "type": "HTMLTagClose", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 112, + 117 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 27 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 118, + 123 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 123, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 128, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "value": "v-for" + }, + { + "type": "HTMLAssociation", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 137, + 142 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 142, + 143 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 143, + 148 + ], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 148, + 152 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 153, + 158 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "v-for" + }, + { + "type": "HTMLAssociation", + "range": [ + 158, + 159 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 15 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "value": "'" + }, + { + "type": "Punctuator", + "range": [ + 160, + 161 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "value": "'" + }, + { + "type": "HTMLTagClose", + "range": [ + 161, + 162 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 162, + 167 + ], + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 24 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 169, + 179 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 179, + 180 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 180, + 181 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/directive-empty-value/source.vue b/test/fixtures/ast/directive-empty-value/source.vue new file mode 100644 index 00000000..50131df8 --- /dev/null +++ b/test/fixtures/ast/directive-empty-value/source.vue @@ -0,0 +1,8 @@ + diff --git a/test/fixtures/ast/directive-empty-value/token-ranges.json b/test/fixtures/ast/directive-empty-value/token-ranges.json new file mode 100644 index 00000000..b557f5c2 --- /dev/null +++ b/test/fixtures/ast/directive-empty-value/token-ranges.json @@ -0,0 +1,62 @@ +[ + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/directive-empty-value/tree.json b/test/fixtures/ast/directive-empty-value/tree.json new file mode 100644 index 00000000..4690a720 --- /dev/null +++ b/test/fixtures/ast/directive-empty-value/tree.json @@ -0,0 +1,251 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/directives/ast.json b/test/fixtures/ast/directives/ast.json index 8035268f..bb7ac14e 100644 --- a/test/fixtures/ast/directives/ast.json +++ b/test/fixtures/ast/directives/ast.json @@ -2023,22 +2023,40 @@ "value": "" }, { - "type": "HTMLLiteral", + "type": "Punctuator", "range": [ 135, - 137 + 136 ], "loc": { "start": { "line": 7, "column": 13 }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, "end": { "line": 7, "column": 15 } }, - "value": "" + "value": "\"" }, { "type": "HTMLTagClose", @@ -2167,22 +2185,40 @@ "value": "" }, { - "type": "HTMLLiteral", + "type": "Punctuator", "range": [ 158, - 160 + 159 ], "loc": { "start": { "line": 8, "column": 13 }, + "end": { + "line": 8, + "column": 14 + } + }, + "value": "'" + }, + { + "type": "Punctuator", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, "end": { "line": 8, "column": 15 } }, - "value": "" + "value": "'" }, { "type": "HTMLTagClose", @@ -2318,18 +2354,6 @@ "index": 44, "lineNumber": 3, "column": 13 - }, - { - "message": "Expected to be an expression, but got empty.", - "index": 136, - "lineNumber": 7, - "column": 14 - }, - { - "message": "Expected to be an expression, but got empty.", - "index": 159, - "lineNumber": 8, - "column": 14 } ] } diff --git a/test/fixtures/ast/directives/token-ranges.json b/test/fixtures/ast/directives/token-ranges.json index 3276e9be..a6fce592 100644 --- a/test/fixtures/ast/directives/token-ranges.json +++ b/test/fixtures/ast/directives/token-ranges.json @@ -46,7 +46,8 @@ "", "", @@ -54,7 +55,8 @@ "", "", diff --git a/test/fixtures/ast/error-message-empty/ast.json b/test/fixtures/ast/error-message-empty/ast.json index 55da8234..03a5b384 100644 --- a/test/fixtures/ast/error-message-empty/ast.json +++ b/test/fixtures/ast/error-message-empty/ast.json @@ -1246,22 +1246,40 @@ "value": "" }, { - "type": "HTMLLiteral", + "type": "Punctuator", "range": [ 42, - 44 + 43 ], "loc": { "start": { "line": 4, "column": 12 }, + "end": { + "line": 4, + "column": 13 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, "end": { "line": 4, "column": 14 } }, - "value": "" + "value": "\"" }, { "type": "HTMLTagClose", @@ -1534,22 +1552,40 @@ "value": "" }, { - "type": "HTMLLiteral", + "type": "Punctuator", "range": [ 87, - 89 + 88 ], "loc": { "start": { "line": 6, "column": 12 }, + "end": { + "line": 6, + "column": 13 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, "end": { "line": 6, "column": 14 } }, - "value": "" + "value": "\"" }, { "type": "HTMLTagClose", @@ -1822,22 +1858,40 @@ "value": "" }, { - "type": "HTMLLiteral", + "type": "Punctuator", "range": [ 135, - 137 + 136 ], "loc": { "start": { "line": 8, "column": 15 }, + "end": { + "line": 8, + "column": 16 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, "end": { "line": 8, "column": 17 } }, - "value": "" + "value": "\"" }, { "type": "HTMLTagClose", @@ -2124,36 +2178,18 @@ "lineNumber": 3, "column": 6 }, - { - "message": "Expected to be an expression, but got empty.", - "index": 43, - "lineNumber": 4, - "column": 13 - }, { "message": "Expected to be an expression, but got empty.", "index": 65, "lineNumber": 5, "column": 13 }, - { - "message": "Expected to be statements, but got empty.", - "index": 88, - "lineNumber": 6, - "column": 13 - }, { "message": "Expected to be statements, but got empty.", "index": 110, "lineNumber": 7, "column": 13 }, - { - "message": "Expected to be ' in ', but got empty.", - "index": 136, - "lineNumber": 8, - "column": 16 - }, { "message": "Expected to be ' in ', but got empty.", "index": 161, diff --git a/test/fixtures/ast/error-message-empty/token-ranges.json b/test/fixtures/ast/error-message-empty/token-ranges.json index 5c9cc814..0f647014 100644 --- a/test/fixtures/ast/error-message-empty/token-ranges.json +++ b/test/fixtures/ast/error-message-empty/token-ranges.json @@ -12,7 +12,8 @@ "", "", @@ -28,7 +29,8 @@ "", "", @@ -44,7 +46,8 @@ "", "",