From ca614f466b315e9faea889ea6ccb00d94a19f564 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 12 Oct 2020 19:20:56 +0900 Subject: [PATCH] Fixed wrong location calculation when including CRLF. (#74) * Fixed wrong location calculation when including CRLF. * Fixed error --- src/common/location-calculator.ts | 43 +- src/script/index.ts | 30 +- test/ast.js | 19 + test/fixtures/ast/end-of-line01/ast.json | 2803 +++++++++++++++++ test/fixtures/ast/end-of-line01/source.vue | 17 + .../ast/end-of-line01/token-ranges.json | 80 + test/fixtures/ast/end-of-line01/tree.json | 311 ++ test/fixtures/ast/end-of-line02/ast.json | 2803 +++++++++++++++++ test/fixtures/ast/end-of-line02/source.vue | 17 + .../ast/end-of-line02/token-ranges.json | 80 + test/fixtures/ast/end-of-line02/tree.json | 311 ++ 11 files changed, 6494 insertions(+), 20 deletions(-) create mode 100644 test/fixtures/ast/end-of-line01/ast.json create mode 100644 test/fixtures/ast/end-of-line01/source.vue create mode 100644 test/fixtures/ast/end-of-line01/token-ranges.json create mode 100644 test/fixtures/ast/end-of-line01/tree.json create mode 100644 test/fixtures/ast/end-of-line02/ast.json create mode 100644 test/fixtures/ast/end-of-line02/source.vue create mode 100644 test/fixtures/ast/end-of-line02/token-ranges.json create mode 100644 test/fixtures/ast/end-of-line02/tree.json diff --git a/src/common/location-calculator.ts b/src/common/location-calculator.ts index fb33bef0..980e0174 100644 --- a/src/common/location-calculator.ts +++ b/src/common/location-calculator.ts @@ -23,17 +23,20 @@ export class LocationCalculator { private ltOffsets: number[] private baseOffset: number private baseIndexOfGap: number + private shiftOffset: number /** * Initialize this calculator. * @param gapOffsets The list of the offset of removed characters in tokenization phase. * @param ltOffsets The list of the offset of line terminators. * @param baseOffset The base offset to calculate locations. + * @param shiftOffset The shift offset to calculate locations. */ public constructor( gapOffsets: number[], ltOffsets: number[], baseOffset?: number, + shiftOffset: number = 0, ) { this.gapOffsets = gapOffsets this.ltOffsets = ltOffsets @@ -42,6 +45,7 @@ export class LocationCalculator { this.baseOffset === 0 ? 0 : sortedLastIndex(gapOffsets, this.baseOffset) + this.shiftOffset = shiftOffset } /** @@ -54,6 +58,21 @@ export class LocationCalculator { this.gapOffsets, this.ltOffsets, this.baseOffset + offset, + this.shiftOffset, + ) + } + + /** + * Get sub calculator that shifts the given offset. + * @param offset The shift of new sub calculator. + * @returns Sub calculator. + */ + public getSubCalculatorShift(offset: number): LocationCalculator { + return new LocationCalculator( + this.gapOffsets, + this.ltOffsets, + this.baseOffset, + this.shiftOffset + offset, ) } @@ -91,7 +110,7 @@ export class LocationCalculator { * @returns The location of the index. */ public getLocation(index: number): Location { - return this._getLocation(this.baseOffset + index) + return this._getLocation(this.baseOffset + index + this.shiftOffset) } /** @@ -100,7 +119,13 @@ export class LocationCalculator { * @returns The offset of the index. */ public getOffsetWithGap(index: number): number { - return this.baseOffset + index + this._getGap(index) + const shiftOffset = this.shiftOffset + return ( + this.baseOffset + + index + + shiftOffset + + this._getGap(index + shiftOffset) + ) } /** @@ -108,12 +133,13 @@ export class LocationCalculator { * @param node The node to modify their location. */ public fixLocation(node: T): T { + const shiftOffset = this.shiftOffset const range = node.range const loc = node.loc - const gap0 = this._getGap(range[0]) - const gap1 = this._getGap(range[1]) - const d0 = this.baseOffset + Math.max(0, gap0) - const d1 = this.baseOffset + Math.max(0, gap1) + const gap0 = this._getGap(range[0] + shiftOffset) + const gap1 = this._getGap(range[1] + shiftOffset) + const d0 = this.baseOffset + Math.max(0, gap0) + shiftOffset + const d1 = this.baseOffset + Math.max(0, gap1) + shiftOffset if (d0 !== 0) { range[0] += d0 @@ -138,8 +164,9 @@ export class LocationCalculator { * @param error The error to modify their location. */ public fixErrorLocation(error: ParseError) { - const gap = this._getGap(error.index) - const diff = this.baseOffset + Math.max(0, gap) + const shiftOffset = this.shiftOffset + const gap = this._getGap(error.index + shiftOffset) + const diff = this.baseOffset + Math.max(0, gap) + shiftOffset error.index += diff diff --git a/src/script/index.ts b/src/script/index.ts index bfa9100f..f073acd5 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -361,7 +361,7 @@ function parseExpressionBody( try { const ast = parseScriptFragment( `0(${code})`, - locationCalculator.getSubCalculatorAfter(-2), + locationCalculator.getSubCalculatorShift(-2), parserOptions, ).ast const tokens = ast.tokens || [] @@ -431,9 +431,12 @@ function parseFilter( // Parse the callee. if (calleeCode.trim()) { const spaces = /^\s*/u.exec(calleeCode)![0] + const subCalculator = locationCalculator.getSubCalculatorShift( + spaces.length, + ) const { ast } = parseScriptFragment( - `${spaces}"${calleeCode.trim()}"`, - locationCalculator, + `"${calleeCode.trim()}"`, + subCalculator, parserOptions, ) const statement = ast.body[0] as ESLintExpressionStatement @@ -455,12 +458,13 @@ function parseFilter( expression.callee = { type: "Identifier", parent: expression, - range: [callee.range[0], callee.range[1] - 2], + range: [ + callee.range[0], + subCalculator.getOffsetWithGap(calleeCode.trim().length), + ], loc: { start: callee.loc.start, - end: locationCalculator.getLocation( - callee.range[1] - callee.range[0] - 1, - ), + end: subCalculator.getLocation(calleeCode.trim().length), }, name: String(callee.value), } @@ -478,7 +482,9 @@ function parseFilter( if (argsCode != null) { const { ast } = parseScriptFragment( `0${argsCode}`, - locationCalculator.getSubCalculatorAfter(paren - 1), + locationCalculator + .getSubCalculatorAfter(paren) + .getSubCalculatorShift(-1), parserOptions, ) const statement = ast.body[0] as ESLintExpressionStatement @@ -684,7 +690,7 @@ export function parseExpression( // Parse a filter const retF = parseFilter( filterCode, - locationCalculator.getSubCalculatorAfter(prevLoc + 1), + locationCalculator.getSubCalculatorShift(prevLoc + 1), parserOptions, ) if (retF) { @@ -731,7 +737,7 @@ export function parseVForExpression( const replaced = processedCode !== code const ast = parseScriptFragment( `for(let ${processedCode});`, - locationCalculator.getSubCalculatorAfter(-8), + locationCalculator.getSubCalculatorShift(-8), parserOptions, ).ast const tokens = ast.tokens || [] @@ -829,7 +835,7 @@ function parseVOnExpressionBody( try { const ast = parseScriptFragment( `void function($event){${code}}`, - locationCalculator.getSubCalculatorAfter(-22), + locationCalculator.getSubCalculatorShift(-22), parserOptions, ).ast const references = analyzeExternalReferences(ast, parserOptions) @@ -905,7 +911,7 @@ export function parseSlotScopeExpression( try { const ast = parseScriptFragment( `void function(${code}) {}`, - locationCalculator.getSubCalculatorAfter(-14), + locationCalculator.getSubCalculatorShift(-14), parserOptions, ).ast const statement = ast.body[0] as ESLintExpressionStatement diff --git a/test/ast.js b/test/ast.js index 34900a9b..3f2d15a6 100644 --- a/test/ast.js +++ b/test/ast.js @@ -198,6 +198,25 @@ describe("Template AST", () => { assert.strictEqual(actualText, expectedText) }) + it("should have correct range on windows(CRLF).", () => { + const sourceForWin = source.replace(/\r?\n/gu, "\r\n") + const actualForWin = parser.parseForESLint( + sourceForWin, + Object.assign({ filePath: sourcePath }, PARSER_OPTIONS) + ) + + const resultPath = path.join(ROOT, `${name}/token-ranges.json`) + const expectedText = fs.readFileSync(resultPath, "utf8") + const tokens = getAllTokens(actualForWin.ast).map(t => + sourceForWin + .slice(t.range[0], t.range[1]) + .replace(/\r?\n/gu, "\n") + ) + const actualText = JSON.stringify(tokens, null, 4) + + assert.strictEqual(actualText, expectedText) + }) + it("should have correct location.", () => { const lines = source.match(/[^\r\n]*(?:\r?\n|$)/gu) || [] lines.push(String.fromCodePoint(0)) diff --git a/test/fixtures/ast/end-of-line01/ast.json b/test/fixtures/ast/end-of-line01/ast.json new file mode 100644 index 00000000..94e76dd0 --- /dev/null +++ b/test/fixtures/ast/end-of-line01/ast.json @@ -0,0 +1,2803 @@ +{ + "type": "Program", + "start": 191, + "end": 204, + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "range": [ + 192, + 203 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 192, + "end": 203, + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "range": [ + 192, + 203 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 196, + "end": 203, + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "range": [ + 196, + 203 + ], + "id": { + "type": "Identifier", + "start": 196, + "end": 197, + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 5 + } + }, + "range": [ + 196, + 197 + ], + "name": "a" + }, + "init": { + "type": "Identifier", + "start": 200, + "end": 203, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "range": [ + 200, + 203 + ], + "name": "foo" + } + } + ], + "kind": "var" + } + ], + "sourceType": "script", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 183, + 191 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 182 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "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, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 13, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 13, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 22, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 22, + 28 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "column": 4, + "line": 3 + }, + "end": { + "column": 5, + "line": 3 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 23, + 28 + ], + "loc": { + "start": { + "column": 5, + "line": 3 + }, + "end": { + "column": 10, + "line": 3 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 29, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "expression": { + "type": "VOnExpression", + "range": [ + 30, + 33 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "range": [ + 30, + 33 + ], + "expression": { + "type": "AssignmentExpression", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "range": [ + 30, + 33 + ], + "operator": "=", + "left": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 30, + 31 + ], + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "range": [ + 32, + 33 + ], + "name": "b" + } + } + } + ] + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 30, + 31 + ], + "name": "a" + }, + "mode": "w" + }, + { + "id": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "range": [ + 32, + 33 + ], + "name": "b" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 38, + 44 + ], + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 44, + 47 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 47, + 83 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 47, + 77 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 56, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 56, + 67 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "column": 4, + "line": 6 + }, + "end": { + "column": 5, + "line": 6 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 57, + 67 + ], + "loc": { + "start": { + "column": 5, + "line": 6 + }, + "end": { + "column": 15, + "line": 6 + } + }, + "name": "data-click", + "rawName": "data-click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 68, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 69, + "end": 72, + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "range": [ + 69, + 72 + ], + "operator": "=", + "left": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "range": [ + 69, + 70 + ], + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 71, + "end": 72, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "range": [ + 71, + 72 + ], + "name": "b" + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "range": [ + 69, + 70 + ], + "name": "a" + }, + "mode": "w" + }, + { + "id": { + "type": "Identifier", + "start": 71, + "end": 72, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "range": [ + 71, + 72 + ], + "name": "b" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 83, + 86 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 86, + 129 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 86, + 123 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 95, + 119 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 95, + 104 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 95, + 96 + ], + "loc": { + "start": { + "column": 4, + "line": 9 + }, + "end": { + "column": 5, + "line": 9 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 96, + 104 + ], + "loc": { + "start": { + "column": 5, + "line": 9 + }, + "end": { + "column": 13, + "line": 9 + } + }, + "name": "data-foo", + "rawName": "data-foo" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 105, + 119 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "expression": { + "type": "LogicalExpression", + "start": 106, + "end": 110, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 106, + 118 + ], + "left": { + "type": "Identifier", + "start": 106, + "end": 107, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "range": [ + 106, + 107 + ], + "name": "c" + }, + "operator": "&&", + "right": { + "type": "Identifier", + "start": 117, + "end": 118, + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 117, + 118 + ], + "name": "d" + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 106, + "end": 107, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "range": [ + 106, + 107 + ], + "name": "c" + }, + "mode": "r" + }, + { + "id": { + "type": "Identifier", + "start": 117, + "end": 118, + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 117, + 118 + ], + "name": "d" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 123, + 129 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 129, + 132 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 132, + 170 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 132, + 164 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 141, + 160 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 23 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 141, + 145 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 8 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 141, + 142 + ], + "loc": { + "start": { + "column": 4, + "line": 12 + }, + "end": { + "column": 5, + "line": 12 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 142, + 145 + ], + "loc": { + "start": { + "column": 5, + "line": 12 + }, + "end": { + "column": 8, + "line": 12 + } + }, + "name": "foo", + "rawName": "foo" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 146, + 160 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 23 + } + }, + "expression": { + "type": "VOnExpression", + "range": [ + 147, + 159 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 147, + "end": 151, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "range": [ + 147, + 159 + ], + "expression": { + "type": "LogicalExpression", + "start": 147, + "end": 151, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "range": [ + 147, + 159 + ], + "left": { + "type": "Identifier", + "start": 147, + "end": 148, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "range": [ + 147, + 148 + ], + "name": "c" + }, + "operator": "&&", + "right": { + "type": "Identifier", + "start": 158, + "end": 159, + "loc": { + "start": { + "line": 12, + "column": 21 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "range": [ + 158, + 159 + ], + "name": "d" + } + } + } + ] + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 147, + "end": 148, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "range": [ + 147, + 148 + ], + "name": "c" + }, + "mode": "r" + }, + { + "id": { + "type": "Identifier", + "start": 158, + "end": 159, + "loc": { + "start": { + "line": 12, + "column": 21 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "range": [ + 158, + 159 + ], + "name": "d" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 164, + 170 + ], + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 171, + 182 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "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, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 13, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "Punctuator", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "column": 4, + "line": 3 + }, + "end": { + "column": 5, + "line": 3 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 23, + 28 + ], + "loc": { + "start": { + "column": 5, + "line": 3 + }, + "end": { + "column": 10, + "line": 3 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "a", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 30, + 31 + ] + }, + { + "type": "Punctuator", + "value": "=", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "range": [ + 31, + 32 + ] + }, + { + "type": "Identifier", + "value": "b", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "range": [ + 32, + 33 + ] + }, + { + "type": "Punctuator", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 38, + 43 + ], + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 44, + 47 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 47, + 51 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "Punctuator", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "column": 4, + "line": 6 + }, + "end": { + "column": 5, + "line": 6 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 57, + 67 + ], + "loc": { + "start": { + "column": 5, + "line": 6 + }, + "end": { + "column": 15, + "line": 6 + } + }, + "value": "data-click" + }, + { + "type": "HTMLAssociation", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "a", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "range": [ + 69, + 70 + ] + }, + { + "type": "Punctuator", + "value": "=", + "start": 70, + "end": 71, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "range": [ + 70, + 71 + ] + }, + { + "type": "Identifier", + "value": "b", + "start": 71, + "end": 72, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "range": [ + 71, + 72 + ] + }, + { + "type": "Punctuator", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 77, + 82 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 83, + 86 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 86, + 90 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "Punctuator", + "range": [ + 95, + 96 + ], + "loc": { + "start": { + "column": 4, + "line": 9 + }, + "end": { + "column": 5, + "line": 9 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 96, + 104 + ], + "loc": { + "start": { + "column": 5, + "line": 9 + }, + "end": { + "column": 13, + "line": 9 + } + }, + "value": "data-foo" + }, + { + "type": "HTMLAssociation", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "c", + "start": 106, + "end": 107, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "range": [ + 106, + 107 + ] + }, + { + "type": "Punctuator", + "value": "&&", + "start": 107, + "end": 109, + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "range": [ + 107, + 117 + ] + }, + { + "type": "Identifier", + "value": "d", + "start": 117, + "end": 118, + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 117, + 118 + ] + }, + { + "type": "Punctuator", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 9, + "column": 27 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 122, + 123 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 123, + 128 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 129, + 132 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 132, + 136 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "Punctuator", + "range": [ + 141, + 142 + ], + "loc": { + "start": { + "column": 4, + "line": 12 + }, + "end": { + "column": 5, + "line": 12 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 142, + 145 + ], + "loc": { + "start": { + "column": 5, + "line": 12 + }, + "end": { + "column": 8, + "line": 12 + } + }, + "value": "foo" + }, + { + "type": "HTMLAssociation", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "c", + "start": 147, + "end": 148, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "range": [ + 147, + 148 + ] + }, + { + "type": "Punctuator", + "value": "&&", + "start": 148, + "end": 150, + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 21 + } + }, + "range": [ + 148, + 158 + ] + }, + { + "type": "Identifier", + "value": "d", + "start": 158, + "end": 159, + "loc": { + "start": { + "line": 12, + "column": 21 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "range": [ + 158, + 159 + ] + }, + { + "type": "Punctuator", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 23 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 163, + 164 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 164, + 169 + ], + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 171, + 181 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 181, + 182 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 183, + 190 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 190, + 191 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 191, + 192 + ], + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 192, + 195 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 3 + } + }, + "value": "var" + }, + { + "type": "HTMLWhitespace", + "range": [ + 195, + 196 + ], + "loc": { + "start": { + "line": 16, + "column": 3 + }, + "end": { + "line": 16, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 5 + } + }, + "value": "a" + }, + { + "type": "HTMLWhitespace", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 198, + 199 + ], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 7 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 199, + 200 + ], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 200, + 203 + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 203, + 204 + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 204, + 212 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 212, + 213 + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/end-of-line01/source.vue b/test/fixtures/ast/end-of-line01/source.vue new file mode 100644 index 00000000..4f0ac53a --- /dev/null +++ b/test/fixtures/ast/end-of-line01/source.vue @@ -0,0 +1,17 @@ + + diff --git a/test/fixtures/ast/end-of-line01/token-ranges.json b/test/fixtures/ast/end-of-line01/token-ranges.json new file mode 100644 index 00000000..6b841cd8 --- /dev/null +++ b/test/fixtures/ast/end-of-line01/token-ranges.json @@ -0,0 +1,80 @@ +[ + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n", + "", + "\n", + "", + "\n", + "var", + " ", + "a", + " ", + "=", + " ", + "foo", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/end-of-line01/tree.json b/test/fixtures/ast/end-of-line01/tree.json new file mode 100644 index 00000000..a68b9b28 --- /dev/null +++ b/test/fixtures/ast/end-of-line01/tree.json @@ -0,0 +1,311 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/end-of-line02/ast.json b/test/fixtures/ast/end-of-line02/ast.json new file mode 100644 index 00000000..86473657 --- /dev/null +++ b/test/fixtures/ast/end-of-line02/ast.json @@ -0,0 +1,2803 @@ +{ + "type": "Program", + "start": 8, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 9, + 20 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 9, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 9, + 20 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 13, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 13, + 20 + ], + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "range": [ + 13, + 14 + ], + "name": "a" + }, + "init": { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 17, + 20 + ], + "name": "foo" + } + } + ], + "kind": "var" + } + ], + "sourceType": "script", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 31, + 213 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 17, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 31, + 41 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 41, + 44 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 44, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 44, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 53, + 65 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 53, + 59 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "column": 4, + "line": 6 + }, + "end": { + "column": 5, + "line": 6 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 54, + 59 + ], + "loc": { + "start": { + "column": 5, + "line": 6 + }, + "end": { + "column": 10, + "line": 6 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "expression": { + "type": "VOnExpression", + "range": [ + 61, + 64 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 61, + "end": 64, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "range": [ + 61, + 64 + ], + "expression": { + "type": "AssignmentExpression", + "start": 61, + "end": 64, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "range": [ + 61, + 64 + ], + "operator": "=", + "left": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "range": [ + 61, + 62 + ], + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "range": [ + 63, + 64 + ], + "name": "b" + } + } + } + ] + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "range": [ + 61, + 62 + ], + "name": "a" + }, + "mode": "w" + }, + { + "id": { + "type": "Identifier", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "range": [ + 63, + 64 + ], + "name": "b" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 75, + 78 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 78, + 121 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 78, + 115 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 87, + 111 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 87, + 96 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "column": 4, + "line": 9 + }, + "end": { + "column": 5, + "line": 9 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 88, + 96 + ], + "loc": { + "start": { + "column": 5, + "line": 9 + }, + "end": { + "column": 13, + "line": 9 + } + }, + "name": "data-foo", + "rawName": "data-foo" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 97, + 111 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "expression": { + "type": "LogicalExpression", + "start": 98, + "end": 102, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 98, + 110 + ], + "left": { + "type": "Identifier", + "start": 98, + "end": 99, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "range": [ + 98, + 99 + ], + "name": "c" + }, + "operator": "&&", + "right": { + "type": "Identifier", + "start": 109, + "end": 110, + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 109, + 110 + ], + "name": "d" + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 98, + "end": 99, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "range": [ + 98, + 99 + ], + "name": "c" + }, + "mode": "r" + }, + { + "id": { + "type": "Identifier", + "start": 109, + "end": 110, + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 109, + 110 + ], + "name": "d" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 115, + 121 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 121, + 124 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 124, + 160 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 124, + 154 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 133, + 150 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 21 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 133, + 144 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 15 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "column": 4, + "line": 12 + }, + "end": { + "column": 5, + "line": 12 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 134, + 144 + ], + "loc": { + "start": { + "column": 5, + "line": 12 + }, + "end": { + "column": 15, + "line": 12 + } + }, + "name": "data-click", + "rawName": "data-click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 145, + 150 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 21 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 146, + "end": 149, + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 20 + } + }, + "range": [ + 146, + 149 + ], + "operator": "=", + "left": { + "type": "Identifier", + "start": 146, + "end": 147, + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 18 + } + }, + "range": [ + 146, + 147 + ], + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 148, + "end": 149, + "loc": { + "start": { + "line": 12, + "column": 19 + }, + "end": { + "line": 12, + "column": 20 + } + }, + "range": [ + 148, + 149 + ], + "name": "b" + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 146, + "end": 147, + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 18 + } + }, + "range": [ + 146, + 147 + ], + "name": "a" + }, + "mode": "w" + }, + { + "id": { + "type": "Identifier", + "start": 148, + "end": 149, + "loc": { + "start": { + "line": 12, + "column": 19 + }, + "end": { + "line": 12, + "column": 20 + } + }, + "range": [ + 148, + 149 + ], + "name": "b" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 154, + 160 + ], + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 160, + 163 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 163, + 201 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 16, + "column": 9 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 163, + 195 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 16, + "column": 3 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 172, + 191 + ], + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 23 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 172, + 176 + ], + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "column": 4, + "line": 15 + }, + "end": { + "column": 5, + "line": 15 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 173, + 176 + ], + "loc": { + "start": { + "column": 5, + "line": 15 + }, + "end": { + "column": 8, + "line": 15 + } + }, + "name": "foo", + "rawName": "foo" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 177, + 191 + ], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 23 + } + }, + "expression": { + "type": "VOnExpression", + "range": [ + 178, + 190 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 22 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 178, + "end": 182, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 22 + } + }, + "range": [ + 178, + 190 + ], + "expression": { + "type": "LogicalExpression", + "start": 178, + "end": 182, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 22 + } + }, + "range": [ + 178, + 190 + ], + "left": { + "type": "Identifier", + "start": 178, + "end": 179, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "range": [ + 178, + 179 + ], + "name": "c" + }, + "operator": "&&", + "right": { + "type": "Identifier", + "start": 189, + "end": 190, + "loc": { + "start": { + "line": 15, + "column": 21 + }, + "end": { + "line": 15, + "column": 22 + } + }, + "range": [ + 189, + 190 + ], + "name": "d" + } + } + } + ] + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 178, + "end": 179, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "range": [ + 178, + 179 + ], + "name": "c" + }, + "mode": "r" + }, + { + "id": { + "type": "Identifier", + "start": 189, + "end": 190, + "loc": { + "start": { + "line": 15, + "column": 21 + }, + "end": { + "line": 15, + "column": 22 + } + }, + "range": [ + 189, + 190 + ], + "name": "d" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 195, + 201 + ], + "loc": { + "start": { + "line": 16, + "column": 3 + }, + "end": { + "line": 16, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 201, + 202 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 202, + 213 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 12 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "value": "var" + }, + { + "type": "HTMLWhitespace", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "a" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 21, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 31, + 40 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 41, + 44 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 44, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "Punctuator", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "column": 4, + "line": 6 + }, + "end": { + "column": 5, + "line": 6 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 54, + 59 + ], + "loc": { + "start": { + "column": 5, + "line": 6 + }, + "end": { + "column": 10, + "line": 6 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "a", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "range": [ + 61, + 62 + ] + }, + { + "type": "Punctuator", + "value": "=", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "range": [ + 62, + 63 + ] + }, + { + "type": "Identifier", + "value": "b", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "range": [ + 63, + 64 + ] + }, + { + "type": "Punctuator", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 69, + 74 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 75, + 78 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 78, + 82 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "Punctuator", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "column": 4, + "line": 9 + }, + "end": { + "column": 5, + "line": 9 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 88, + 96 + ], + "loc": { + "start": { + "column": 5, + "line": 9 + }, + "end": { + "column": 13, + "line": 9 + } + }, + "value": "data-foo" + }, + { + "type": "HTMLAssociation", + "range": [ + 96, + 97 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "c", + "start": 98, + "end": 99, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "range": [ + 98, + 99 + ] + }, + { + "type": "Punctuator", + "value": "&&", + "start": 99, + "end": 101, + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "range": [ + 99, + 109 + ] + }, + { + "type": "Identifier", + "value": "d", + "start": 109, + "end": 110, + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 109, + 110 + ] + }, + { + "type": "Punctuator", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 9, + "column": 27 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 115, + 120 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 121, + 124 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 124, + 128 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "Punctuator", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "column": 4, + "line": 12 + }, + "end": { + "column": 5, + "line": 12 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 134, + 144 + ], + "loc": { + "start": { + "column": 5, + "line": 12 + }, + "end": { + "column": 15, + "line": 12 + } + }, + "value": "data-click" + }, + { + "type": "HTMLAssociation", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 12, + "column": 15 + }, + "end": { + "line": 12, + "column": 16 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 17 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "a", + "start": 146, + "end": 147, + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 18 + } + }, + "range": [ + 146, + 147 + ] + }, + { + "type": "Punctuator", + "value": "=", + "start": 147, + "end": 148, + "loc": { + "start": { + "line": 12, + "column": 18 + }, + "end": { + "line": 12, + "column": 19 + } + }, + "range": [ + 147, + 148 + ] + }, + { + "type": "Identifier", + "value": "b", + "start": 148, + "end": 149, + "loc": { + "start": { + "line": 12, + "column": 19 + }, + "end": { + "line": 12, + "column": 20 + } + }, + "range": [ + 148, + 149 + ] + }, + { + "type": "Punctuator", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 12, + "column": 20 + }, + "end": { + "line": 12, + "column": 21 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 154, + 159 + ], + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 160, + 163 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 163, + 167 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "Punctuator", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "column": 4, + "line": 15 + }, + "end": { + "column": 5, + "line": 15 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 173, + 176 + ], + "loc": { + "start": { + "column": 5, + "line": 15 + }, + "end": { + "column": 8, + "line": 15 + } + }, + "value": "foo" + }, + { + "type": "HTMLAssociation", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 10 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "c", + "start": 178, + "end": 179, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "range": [ + 178, + 179 + ] + }, + { + "type": "Punctuator", + "value": "&&", + "start": 179, + "end": 181, + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 21 + } + }, + "range": [ + 179, + 189 + ] + }, + { + "type": "Identifier", + "value": "d", + "start": 189, + "end": 190, + "loc": { + "start": { + "line": 15, + "column": 21 + }, + "end": { + "line": 15, + "column": 22 + } + }, + "range": [ + 189, + 190 + ] + }, + { + "type": "Punctuator", + "range": [ + 190, + 191 + ], + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 23 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 194, + 195 + ], + "loc": { + "start": { + "line": 16, + "column": 2 + }, + "end": { + "line": 16, + "column": 3 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 195, + 200 + ], + "loc": { + "start": { + "line": 16, + "column": 3 + }, + "end": { + "line": 16, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 200, + 201 + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 201, + 202 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 202, + 212 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 212, + 213 + ], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/end-of-line02/source.vue b/test/fixtures/ast/end-of-line02/source.vue new file mode 100644 index 00000000..6c27e7dd --- /dev/null +++ b/test/fixtures/ast/end-of-line02/source.vue @@ -0,0 +1,17 @@ + + diff --git a/test/fixtures/ast/end-of-line02/token-ranges.json b/test/fixtures/ast/end-of-line02/token-ranges.json new file mode 100644 index 00000000..be779652 --- /dev/null +++ b/test/fixtures/ast/end-of-line02/token-ranges.json @@ -0,0 +1,80 @@ +[ + "", + "", + "\n", + "var", + " ", + "a", + " ", + "=", + " ", + "foo", + "\n", + "", + "\n", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/end-of-line02/tree.json b/test/fixtures/ast/end-of-line02/tree.json new file mode 100644 index 00000000..d1a52306 --- /dev/null +++ b/test/fixtures/ast/end-of-line02/tree.json @@ -0,0 +1,311 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file