diff --git a/src/script-setup/index.ts b/src/script-setup/index.ts index ec00b5a1..afb1fa2f 100644 --- a/src/script-setup/index.ts +++ b/src/script-setup/index.ts @@ -289,6 +289,28 @@ export function parseScriptSetupElements( } result.ast.body.sort((a, b) => a.range[0] - b.range[0]) + const programStartOffset = result.ast.body.reduce( + (start, node) => Math.min(start, node.range[0]), + result.ast.range[0], + ) + result.ast.range[0] = programStartOffset + result.ast.loc.start = + locationCalculator.getLocFromIndex(programStartOffset) + if (result.ast.start != null) { + result.ast.start = [scriptSetupElement, scriptElement].reduce( + (start, node) => { + const textNode = node.children[0] + return Math.min( + start, + textNode != null && textNode.type === "VText" + ? textNode.range[0] + : node.startTag.range[1], + ) + }, + result.ast.start, + ) + } + const programEndOffset = result.ast.body.reduce( (end, node) => Math.max(end, node.range[1]), 0, @@ -303,7 +325,7 @@ export function parseScriptSetupElements( end, textNode != null && textNode.type === "VText" ? textNode.range[1] - : node.endTag?.range[1] ?? node.range[1], + : node.endTag?.range[0] ?? node.range[1], ) }, 0, diff --git a/test/fixtures/ast/multiple-scripts-10/ast.json b/test/fixtures/ast/multiple-scripts-10/ast.json index d885cac3..dcf27584 100644 --- a/test/fixtures/ast/multiple-scripts-10/ast.json +++ b/test/fixtures/ast/multiple-scripts-10/ast.json @@ -1,7 +1,7 @@ { "type": "Program", - "start": 9, - "end": 57, + "start": 8, + "end": 48, "loc": { "start": { "line": 2, diff --git a/test/fixtures/ast/multiple-scripts-11/ast.json b/test/fixtures/ast/multiple-scripts-11/ast.json new file mode 100644 index 00000000..87bdc971 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-11/ast.json @@ -0,0 +1,3338 @@ +{ + "type": "Program", + "start": 152, + "end": 383, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "range": [ + 153, + 382 + ], + "body": [ + { + "type": "ImportDeclaration", + "start": 153, + "end": 188, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 35 + } + }, + "range": [ + 153, + 188 + ], + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 162, + "end": 165, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "range": [ + 162, + 165 + ], + "imported": { + "type": "Identifier", + "start": 162, + "end": 165, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "range": [ + 162, + 165 + ], + "name": "ref" + }, + "local": { + "type": "Identifier", + "start": 162, + "end": 165, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "range": [ + 162, + 165 + ], + "name": "ref" + } + }, + { + "type": "ImportSpecifier", + "start": 167, + "end": 175, + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "range": [ + 167, + 175 + ], + "imported": { + "type": "Identifier", + "start": 167, + "end": 175, + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "range": [ + 167, + 175 + ], + "name": "computed" + }, + "local": { + "type": "Identifier", + "start": 167, + "end": 175, + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "range": [ + 167, + 175 + ], + "name": "computed" + } + } + ], + "source": { + "type": "Literal", + "start": 183, + "end": 188, + "loc": { + "start": { + "line": 7, + "column": 30 + }, + "end": { + "line": 7, + "column": 35 + } + }, + "range": [ + 183, + 188 + ], + "value": "vue", + "raw": "'vue'" + } + }, + { + "type": "ImportDeclaration", + "start": 250, + "end": 281, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 31 + } + }, + "range": [ + 250, + 281 + ], + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 259, + "end": 267, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "range": [ + 259, + 267 + ], + "imported": { + "type": "Identifier", + "start": 259, + "end": 267, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "range": [ + 259, + 267 + ], + "name": "useStore" + }, + "local": { + "type": "Identifier", + "start": 259, + "end": 267, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "range": [ + 259, + 267 + ], + "name": "useStore" + } + } + ], + "source": { + "type": "Literal", + "start": 275, + "end": 281, + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 31 + } + }, + "range": [ + 275, + 281 + ], + "value": "vuex", + "raw": "'vuex'" + } + }, + { + "type": "ExportDefaultDeclaration", + "start": 328, + "end": 382, + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "range": [ + 328, + 382 + ], + "declaration": { + "type": "ObjectExpression", + "start": 343, + "end": 382, + "loc": { + "start": { + "line": 12, + "column": 15 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "range": [ + 343, + 382 + ], + "properties": [ + { + "type": "Property", + "start": 347, + "end": 358, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 13 + } + }, + "range": [ + 347, + 358 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 347, + "end": 351, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 6 + } + }, + "range": [ + 347, + 351 + ], + "name": "name" + }, + "value": { + "type": "Literal", + "start": 353, + "end": 358, + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 13 + } + }, + "range": [ + 353, + 358 + ], + "value": "App", + "raw": "'App'" + }, + "kind": "init" + }, + { + "type": "Property", + "start": 362, + "end": 379, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 15, + "column": 3 + } + }, + "range": [ + 362, + 379 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 362, + "end": 372, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 12 + } + }, + "range": [ + 362, + 372 + ], + "name": "components" + }, + "value": { + "type": "ObjectExpression", + "start": 374, + "end": 379, + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 15, + "column": 3 + } + }, + "range": [ + 374, + 379 + ], + "properties": [] + }, + "kind": "init" + } + ] + } + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " each time uncomment error will print. anything from 'vue'", + "start": 189, + "end": 249, + "range": [ + 189, + 249 + ], + "loc": { + "start": { + "line": 7, + "column": 36 + }, + "end": { + "line": 7, + "column": 96 + } + } + }, + { + "type": "Line", + "value": " others like this is ok", + "start": 282, + "end": 307, + "range": [ + 282, + 307 + ], + "loc": { + "start": { + "line": 8, + "column": 32 + }, + "end": { + "line": 8, + "column": 57 + } + } + } + ], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 138, + 152 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 319, + 327 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 8 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 64, + 137 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 64, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 74, + 77 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 77, + 125 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 77, + 116 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 82, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "name": "class", + "rawName": "class" + }, + "value": { + "type": "VLiteral", + "range": [ + 88, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "f-c" + } + }, + { + "type": "VAttribute", + "range": [ + 94, + 115 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 40 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "name": "style", + "rawName": "style" + }, + "value": { + "type": "VLiteral", + "range": [ + 100, + 115 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 40 + } + }, + "value": "height: 100%;" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 116, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 41 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "\n " + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 119, + 125 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 126, + 137 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLWhitespace", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 1, + "column": 63 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 64, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 74, + 77 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 77, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "value": "class" + }, + { + "type": "HTMLAssociation", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 88, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "f-c" + }, + { + "type": "HTMLIdentifier", + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "value": "style" + }, + { + "type": "HTMLAssociation", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 100, + 115 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 40 + } + }, + "value": "height: 100%;" + }, + { + "type": "HTMLTagClose", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 3, + "column": 40 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 116, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 41 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 119, + 124 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 126, + 136 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 138, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 146, + 151 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 151, + 152 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 152, + 153 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 153, + 159 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 160, + 161 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 161, + 162 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 162, + 166 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "ref," + }, + { + "type": "HTMLWhitespace", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 167, + 175 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "value": "computed" + }, + { + "type": "HTMLWhitespace", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 24 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 178, + 182 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 7, + "column": 29 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 7, + "column": 29 + }, + "end": { + "line": 7, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 183, + 188 + ], + "loc": { + "start": { + "line": 7, + "column": 30 + }, + "end": { + "line": 7, + "column": 35 + } + }, + "value": "'vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 188, + 189 + ], + "loc": { + "start": { + "line": 7, + "column": 35 + }, + "end": { + "line": 7, + "column": 36 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 189, + 191 + ], + "loc": { + "start": { + "line": 7, + "column": 36 + }, + "end": { + "line": 7, + "column": 38 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 191, + 192 + ], + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 39 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 192, + 196 + ], + "loc": { + "start": { + "line": 7, + "column": 39 + }, + "end": { + "line": 7, + "column": 43 + } + }, + "value": "each" + }, + { + "type": "HTMLWhitespace", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 7, + "column": 43 + }, + "end": { + "line": 7, + "column": 44 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 197, + 201 + ], + "loc": { + "start": { + "line": 7, + "column": 44 + }, + "end": { + "line": 7, + "column": 48 + } + }, + "value": "time" + }, + { + "type": "HTMLWhitespace", + "range": [ + 201, + 202 + ], + "loc": { + "start": { + "line": 7, + "column": 48 + }, + "end": { + "line": 7, + "column": 49 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 7, + "column": 49 + }, + "end": { + "line": 7, + "column": 58 + } + }, + "value": "uncomment" + }, + { + "type": "HTMLWhitespace", + "range": [ + 211, + 212 + ], + "loc": { + "start": { + "line": 7, + "column": 58 + }, + "end": { + "line": 7, + "column": 59 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 212, + 217 + ], + "loc": { + "start": { + "line": 7, + "column": 59 + }, + "end": { + "line": 7, + "column": 64 + } + }, + "value": "error" + }, + { + "type": "HTMLWhitespace", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 7, + "column": 64 + }, + "end": { + "line": 7, + "column": 65 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 218, + 222 + ], + "loc": { + "start": { + "line": 7, + "column": 65 + }, + "end": { + "line": 7, + "column": 69 + } + }, + "value": "will" + }, + { + "type": "HTMLWhitespace", + "range": [ + 222, + 223 + ], + "loc": { + "start": { + "line": 7, + "column": 69 + }, + "end": { + "line": 7, + "column": 70 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 223, + 229 + ], + "loc": { + "start": { + "line": 7, + "column": 70 + }, + "end": { + "line": 7, + "column": 76 + } + }, + "value": "print." + }, + { + "type": "HTMLWhitespace", + "range": [ + 229, + 230 + ], + "loc": { + "start": { + "line": 7, + "column": 76 + }, + "end": { + "line": 7, + "column": 77 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 230, + 238 + ], + "loc": { + "start": { + "line": 7, + "column": 77 + }, + "end": { + "line": 7, + "column": 85 + } + }, + "value": "anything" + }, + { + "type": "HTMLWhitespace", + "range": [ + 238, + 239 + ], + "loc": { + "start": { + "line": 7, + "column": 85 + }, + "end": { + "line": 7, + "column": 86 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 239, + 243 + ], + "loc": { + "start": { + "line": 7, + "column": 86 + }, + "end": { + "line": 7, + "column": 90 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 243, + 244 + ], + "loc": { + "start": { + "line": 7, + "column": 90 + }, + "end": { + "line": 7, + "column": 91 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 244, + 249 + ], + "loc": { + "start": { + "line": 7, + "column": 91 + }, + "end": { + "line": 7, + "column": 96 + } + }, + "value": "'vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 249, + 250 + ], + "loc": { + "start": { + "line": 7, + "column": 96 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 250, + 256 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 256, + 257 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 257, + 258 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 258, + 259 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 259, + 267 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "value": "useStore" + }, + { + "type": "HTMLWhitespace", + "range": [ + 267, + 268 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 268, + 269 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 269, + 270 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 8, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 270, + 274 + ], + "loc": { + "start": { + "line": 8, + "column": 20 + }, + "end": { + "line": 8, + "column": 24 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 274, + 275 + ], + "loc": { + "start": { + "line": 8, + "column": 24 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 275, + 281 + ], + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 31 + } + }, + "value": "'vuex'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 281, + 282 + ], + "loc": { + "start": { + "line": 8, + "column": 31 + }, + "end": { + "line": 8, + "column": 32 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 282, + 284 + ], + "loc": { + "start": { + "line": 8, + "column": 32 + }, + "end": { + "line": 8, + "column": 34 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 284, + 285 + ], + "loc": { + "start": { + "line": 8, + "column": 34 + }, + "end": { + "line": 8, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 285, + 291 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 41 + } + }, + "value": "others" + }, + { + "type": "HTMLWhitespace", + "range": [ + 291, + 292 + ], + "loc": { + "start": { + "line": 8, + "column": 41 + }, + "end": { + "line": 8, + "column": 42 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 292, + 296 + ], + "loc": { + "start": { + "line": 8, + "column": 42 + }, + "end": { + "line": 8, + "column": 46 + } + }, + "value": "like" + }, + { + "type": "HTMLWhitespace", + "range": [ + 296, + 297 + ], + "loc": { + "start": { + "line": 8, + "column": 46 + }, + "end": { + "line": 8, + "column": 47 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 297, + 301 + ], + "loc": { + "start": { + "line": 8, + "column": 47 + }, + "end": { + "line": 8, + "column": 51 + } + }, + "value": "this" + }, + { + "type": "HTMLWhitespace", + "range": [ + 301, + 302 + ], + "loc": { + "start": { + "line": 8, + "column": 51 + }, + "end": { + "line": 8, + "column": 52 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 302, + 304 + ], + "loc": { + "start": { + "line": 8, + "column": 52 + }, + "end": { + "line": 8, + "column": 54 + } + }, + "value": "is" + }, + { + "type": "HTMLWhitespace", + "range": [ + 304, + 305 + ], + "loc": { + "start": { + "line": 8, + "column": 54 + }, + "end": { + "line": 8, + "column": 55 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 305, + 307 + ], + "loc": { + "start": { + "line": 8, + "column": 55 + }, + "end": { + "line": 8, + "column": 57 + } + }, + "value": "ok" + }, + { + "type": "HTMLWhitespace", + "range": [ + 307, + 308 + ], + "loc": { + "start": { + "line": 8, + "column": 57 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 308, + 316 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 316, + 317 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 317, + 319 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 319, + 326 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 326, + 327 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 327, + 328 + ], + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 328, + 334 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 6 + } + }, + "value": "export" + }, + { + "type": "HTMLWhitespace", + "range": [ + 334, + 335 + ], + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 335, + 342 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 14 + } + }, + "value": "default" + }, + { + "type": "HTMLWhitespace", + "range": [ + 342, + 343 + ], + "loc": { + "start": { + "line": 12, + "column": 14 + }, + "end": { + "line": 12, + "column": 15 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 343, + 344 + ], + "loc": { + "start": { + "line": 12, + "column": 15 + }, + "end": { + "line": 12, + "column": 16 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 344, + 347 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 347, + 352 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 7 + } + }, + "value": "name:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 352, + 353 + ], + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 353, + 359 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 14 + } + }, + "value": "'App'," + }, + { + "type": "HTMLWhitespace", + "range": [ + 359, + 362 + ], + "loc": { + "start": { + "line": 13, + "column": 14 + }, + "end": { + "line": 14, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 362, + 373 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 13 + } + }, + "value": "components:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 373, + 374 + ], + "loc": { + "start": { + "line": 14, + "column": 13 + }, + "end": { + "line": 14, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 374, + 375 + ], + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 14, + "column": 15 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 375, + 378 + ], + "loc": { + "start": { + "line": 14, + "column": 15 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 378, + 380 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 4 + } + }, + "value": "}," + }, + { + "type": "HTMLWhitespace", + "range": [ + 380, + 381 + ], + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 381, + 382 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 382, + 383 + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 383, + 391 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 391, + 392 + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 9 + } + }, + "value": "" + } + ], + "comments": [ + { + "type": "HTMLComment", + "range": [ + 0, + 63 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 63 + } + }, + "value": " https://github.com/vuejs/eslint-plugin-vue/issues/1690 " + } + ], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-11/parser-options.json b/test/fixtures/ast/multiple-scripts-11/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-11/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-11/requirements.json b/test/fixtures/ast/multiple-scripts-11/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-11/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-11/scope.json b/test/fixtures/ast/multiple-scripts-11/scope.json new file mode 100644 index 00000000..23e5c0ee --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-11/scope.json @@ -0,0 +1,133 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "ref", + "identifiers": [ + { + "type": "Identifier", + "name": "ref", + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 12 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "node": { + "type": "ImportSpecifier", + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "name": "ref" + } + ], + "references": [] + }, + { + "name": "computed", + "identifiers": [ + { + "type": "Identifier", + "name": "computed", + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 22 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "node": { + "type": "ImportSpecifier", + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 22 + } + } + }, + "name": "computed" + } + ], + "references": [] + }, + { + "name": "useStore", + "identifiers": [ + { + "type": "Identifier", + "name": "useStore", + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 17 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "node": { + "type": "ImportSpecifier", + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 17 + } + } + }, + "name": "useStore" + } + ], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-11/source.vue b/test/fixtures/ast/multiple-scripts-11/source.vue new file mode 100644 index 00000000..923d3c47 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-11/source.vue @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-11/token-ranges.json b/test/fixtures/ast/multiple-scripts-11/token-ranges.json new file mode 100644 index 00000000..b02c52a8 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-11/token-ranges.json @@ -0,0 +1,143 @@ +[ + "", + "", + "// each time uncomment error will print. anything from 'vue'", + "// others like this is ok", + "\n", + "", + "\n ", + "", + "\n ", + "", + "\n", + "", + "\n", + "", + "\n", + "import", + " ", + "{", + " ", + "ref,", + " ", + "computed", + " ", + "}", + " ", + "from", + " ", + "'vue'", + " ", + "//", + " ", + "each", + " ", + "time", + " ", + "uncomment", + " ", + "error", + " ", + "will", + " ", + "print.", + " ", + "anything", + " ", + "from", + " ", + "'vue'", + "\n", + "import", + " ", + "{", + " ", + "useStore", + " ", + "}", + " ", + "from", + " ", + "'vuex'", + " ", + "//", + " ", + "others", + " ", + "like", + " ", + "this", + " ", + "is", + " ", + "ok", + "\n", + "", + "\n\n", + "", + "\n", + "export", + " ", + "default", + " ", + "{", + "\n ", + "name:", + " ", + "'App',", + "\n ", + "components:", + " ", + "{", + "\n ", + "},", + "\n", + "}", + "\n", + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-11/tree.json b/test/fixtures/ast/multiple-scripts-11/tree.json new file mode 100644 index 00000000..9ef29fd9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-11/tree.json @@ -0,0 +1,82 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-2/ast.json b/test/fixtures/ast/multiple-scripts-2/ast.json index 86f3e690..3a94a274 100644 --- a/test/fixtures/ast/multiple-scripts-2/ast.json +++ b/test/fixtures/ast/multiple-scripts-2/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 106, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-3/ast.json b/test/fixtures/ast/multiple-scripts-3/ast.json index 82eb0fa4..85552110 100644 --- a/test/fixtures/ast/multiple-scripts-3/ast.json +++ b/test/fixtures/ast/multiple-scripts-3/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 91, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-5/ast.json b/test/fixtures/ast/multiple-scripts-5/ast.json index 2eb697cd..0c0ff3e9 100644 --- a/test/fixtures/ast/multiple-scripts-5/ast.json +++ b/test/fixtures/ast/multiple-scripts-5/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 145, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-6/ast.json b/test/fixtures/ast/multiple-scripts-6/ast.json index 4c6b2507..06ab461d 100644 --- a/test/fixtures/ast/multiple-scripts-6/ast.json +++ b/test/fixtures/ast/multiple-scripts-6/ast.json @@ -1,10 +1,10 @@ { "type": "Program", - "start": 48, + "start": 14, "end": 98, "loc": { "start": { - "line": 5, + "line": 2, "column": 0 }, "end": { @@ -13,7 +13,7 @@ } }, "range": [ - 48, + 15, 97 ], "body": [ diff --git a/test/fixtures/ast/multiple-scripts-7/ast.json b/test/fixtures/ast/multiple-scripts-7/ast.json index b8cf33d6..6689eb9a 100644 --- a/test/fixtures/ast/multiple-scripts-7/ast.json +++ b/test/fixtures/ast/multiple-scripts-7/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 178, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-8/ast.json b/test/fixtures/ast/multiple-scripts-8/ast.json index 653e9c4f..ba64ede6 100644 --- a/test/fixtures/ast/multiple-scripts-8/ast.json +++ b/test/fixtures/ast/multiple-scripts-8/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 20, + "start": 8, "end": 340, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-9/ast.json b/test/fixtures/ast/multiple-scripts-9/ast.json index 685d774d..ae3782a8 100644 --- a/test/fixtures/ast/multiple-scripts-9/ast.json +++ b/test/fixtures/ast/multiple-scripts-9/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 31, + "start": 8, "end": 48, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-with-export01/ast.json b/test/fixtures/ast/multiple-scripts-with-export01/ast.json index dec9df00..2b9018f4 100644 --- a/test/fixtures/ast/multiple-scripts-with-export01/ast.json +++ b/test/fixtures/ast/multiple-scripts-with-export01/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 75, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-with-export02/ast.json b/test/fixtures/ast/multiple-scripts-with-export02/ast.json index fff04120..2d8fc7a3 100644 --- a/test/fixtures/ast/multiple-scripts-with-export02/ast.json +++ b/test/fixtures/ast/multiple-scripts-with-export02/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 262, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-with-export03/ast.json b/test/fixtures/ast/multiple-scripts-with-export03/ast.json index 67331ae4..449ffd40 100644 --- a/test/fixtures/ast/multiple-scripts-with-export03/ast.json +++ b/test/fixtures/ast/multiple-scripts-with-export03/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 241, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-with-export04/ast.json b/test/fixtures/ast/multiple-scripts-with-export04/ast.json index 6962d6ee..c95d2858 100644 --- a/test/fixtures/ast/multiple-scripts-with-export04/ast.json +++ b/test/fixtures/ast/multiple-scripts-with-export04/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 178, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts/ast.json b/test/fixtures/ast/multiple-scripts/ast.json index b55bc2c0..bdaec0c7 100644 --- a/test/fixtures/ast/multiple-scripts/ast.json +++ b/test/fixtures/ast/multiple-scripts/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 9, + "start": 8, "end": 99, "loc": { "start": { diff --git a/test/fixtures/ast/script-setup-example14/ast.json b/test/fixtures/ast/script-setup-example14/ast.json index 73f00c5d..03765608 100644 --- a/test/fixtures/ast/script-setup-example14/ast.json +++ b/test/fixtures/ast/script-setup-example14/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 11, + "start": 8, "end": 168, "loc": { "start": { diff --git a/test/fixtures/ast/script-setup-example15/ast.json b/test/fixtures/ast/script-setup-example15/ast.json index fbaf0f38..7d2e71bd 100644 --- a/test/fixtures/ast/script-setup-example15/ast.json +++ b/test/fixtures/ast/script-setup-example15/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 11, + "start": 8, "end": 154, "loc": { "start": {