diff --git a/package.json b/package.json index f5f2330f..e3b4822a 100644 --- a/package.json +++ b/package.json @@ -64,8 +64,8 @@ "setup": "git submodule update --init && cd test/fixtures/eslint && npm install", "pretest": "run-s build lint", "test": "npm run -s test:mocha", - "test:mocha": "nyc mocha \"test/*.js\" --reporter dot --timeout 10000", - "test:debug": "mocha --inspect --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 10000", + "test:mocha": "nyc mocha \"test/*.js\" --reporter dot --timeout 60000", + "test:debug": "mocha --inspect --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 60000", "preupdate-fixtures": "npm run -s build", "update-fixtures": "node scripts/update-fixtures-ast.js && node scripts/update-fixtures-document-fragment.js", "preversion": "npm test", diff --git a/scripts/update-fixtures-ast.js b/scripts/update-fixtures-ast.js index 234405f0..9e0fa561 100644 --- a/scripts/update-fixtures-ast.js +++ b/scripts/update-fixtures-ast.js @@ -228,6 +228,7 @@ for (const name of TARGETS) { ? JSON.parse(fs.readFileSync(optionsPath, "utf8")) : {} ) + // console.log("Start:", name) const actual = parser.parseForESLint(source, options) const tokenRanges = getAllTokens(actual.ast).map((t) => source.slice(t.range[0], t.range[1]) diff --git a/src/ast/nodes.ts b/src/ast/nodes.ts index 18ca044a..96c0fad9 100644 --- a/src/ast/nodes.ts +++ b/src/ast/nodes.ts @@ -310,6 +310,7 @@ export interface ESLintExportNamedDeclaration extends HasLocation, HasParent { export interface ESLintExportSpecifier extends HasLocation, HasParent { type: "ExportSpecifier" + local: ESLintIdentifier exported: ESLintIdentifier } diff --git a/src/common/fix-locations.ts b/src/common/fix-locations.ts index b5e3641c..f92e7598 100644 --- a/src/common/fix-locations.ts +++ b/src/common/fix-locations.ts @@ -1,5 +1,6 @@ import type { ESLintExtendedProgram, + ESLintNode, HasLocation, LocationRange, Node, @@ -20,13 +21,28 @@ import type { LocationCalculator } from "./location-calculator" export function fixLocations( result: ESLintExtendedProgram, locationCalculator: LocationCalculator, +): void { + fixNodeLocations(result.ast, result.visitorKeys, locationCalculator) + + for (const token of result.ast.tokens || []) { + fixLocation(token, locationCalculator) + } + for (const comment of result.ast.comments || []) { + fixLocation(comment, locationCalculator) + } +} + +export function fixNodeLocations( + rootNode: ESLintNode, + visitorKeys: ESLintExtendedProgram["visitorKeys"], + locationCalculator: LocationCalculator, ): void { // There are cases which the same node instance appears twice in the tree. // E.g. `let {a} = {}` // This `a` appears twice at `Property#key` and `Property#value`. const traversed = new Map() - traverseNodes(result.ast, { - visitorKeys: result.visitorKeys, + traverseNodes(rootNode, { + visitorKeys, enterNode(node, parent) { if (!traversed.has(node)) { @@ -65,13 +81,6 @@ export function fixLocations( // Do nothing. }, }) - - for (const token of result.ast.tokens || []) { - fixLocation(token, locationCalculator) - } - for (const comment of result.ast.comments || []) { - fixLocation(comment, locationCalculator) - } } /** diff --git a/src/script-setup/index.ts b/src/script-setup/index.ts index 2795b3c0..8b305f40 100644 --- a/src/script-setup/index.ts +++ b/src/script-setup/index.ts @@ -5,22 +5,39 @@ import type { ScopeManager, Scope } from "eslint-scope" import type { ESLintBlockStatement, + ESLintExportSpecifier, ESLintExtendedProgram, + ESLintIdentifier, + ESLintModuleDeclaration, + ESLintNode, + ESLintProgram, ESLintStatement, + Token, VElement, } from "../ast" import { ParseError, traverseNodes } from "../ast" -import { fixErrorLocation, fixLocations } from "../common/fix-locations" +import { + fixErrorLocation, + fixLocation, + fixLocations, + fixNodeLocations, +} from "../common/fix-locations" import type { LinesAndColumns } from "../common/lines-and-columns" import type { LocationCalculator } from "../common/location-calculator" import type { ParserOptions } from "../common/parser-options" -import { parseScript, parseScriptFragment } from "../script" +import { parseScript as parseScriptBase, parseScriptFragment } from "../script" import { getScriptSetupParserOptions } from "./parser-options" type RemapBlock = { range: [number, number] offset: number } + +/** + * `parseScriptSetupElements` rewrites the source code so that it can parse + * the combination of ` + * + * ``` + * + * ↓ + * + * ```js + * export let count = 42 + * export let count2 = 42 + * ; + * import MyComponent1 from './MyComponent1.vue'; + * { + * let count = 42; + * let a + * ; + * ({count}) + * ; + * let count2 = 42 + * ; + * count2++ + * ; + * } + * ``` */ -function getScriptsCodeBlocks( +function getScriptSetupModuleCodeBlocks( scriptSetupElement: VElement, scriptElement: VElement, sfcCode: string, linesAndColumns: LinesAndColumns, parserOptions: ParserOptions, -): ScriptSetupCodeBlocks | null { +): ScriptSetupModuleCodeBlocks | null { const scriptSetupCodeBlocks = getScriptSetupCodeBlocks( scriptSetupElement, sfcCode, @@ -295,17 +449,11 @@ function getScriptsCodeBlocks( codeBlocks.appendCodeBlocks(scriptSetupCodeBlocks.codeBlocks) return { codeBlocks, - scriptSetupImportRange: - scriptSetupCodeBlocks.scriptSetupImportRange && [ - scriptSetupCodeBlocks.scriptSetupImportRange[0] + - scriptSetupOffset, - scriptSetupCodeBlocks.scriptSetupImportRange[1] + - scriptSetupOffset, - ], - scriptSetupBlockRange: scriptSetupCodeBlocks.scriptSetupBlockRange && [ + scriptSetupBlockRange: [ scriptSetupCodeBlocks.scriptSetupBlockRange[0] + scriptSetupOffset, scriptSetupCodeBlocks.scriptSetupBlockRange[1] + scriptSetupOffset, ], + restoreASTCallbacks: scriptSetupCodeBlocks.restoreASTCallbacks, } } @@ -325,101 +473,302 @@ function getScriptSetupCodeBlocks( return null } - const [scriptStartOffset, scriptEndOffset] = textNode.range - const scriptCode = sfcCode.slice(scriptStartOffset, scriptEndOffset) + const [scriptSetupStartOffset, scriptSetupEndOffset] = textNode.range + const scriptCode = sfcCode.slice( + scriptSetupStartOffset, + scriptSetupEndOffset, + ) + + const offsetLocationCalculator = simpleOffsetLocationCalculator( + scriptSetupStartOffset, + linesAndColumns, + ) + + const result = parseScript( + scriptCode, + parserOptions, + offsetLocationCalculator, + ) - let result - try { - result = parseScript(scriptCode, parserOptions) - } catch (err) { - const perr = ParseError.normalize(err) - if (perr) { - fixErrorLocation( - perr, - simpleOffsetLocationCalculator( - scriptStartOffset, - linesAndColumns, - ), - ) - throw perr - } - throw err - } const { ast } = result + // Holds the `import` and re-`export` statements. + // All import and re-`export` statements are hoisted to the top. const importCodeBlocks = new CodeBlocks() + // Holds statements other than `import`, re-`export` and `export default` statements. + // This is moved to a block statement to avoid conflicts with variables of the same name in `" + }, + { + "type": "Punctuator", + "range": [ + 34, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export01/parser-options.json b/test/fixtures/ast/multiple-scripts-with-export01/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export01/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-with-export01/source.vue b/test/fixtures/ast/multiple-scripts-with-export01/source.vue new file mode 100644 index 00000000..ae0413c9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export01/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-with-export01/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-export01/token-ranges.json new file mode 100644 index 00000000..c1a94ddf --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export01/token-ranges.json @@ -0,0 +1,15 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export01/tree.json b/test/fixtures/ast/multiple-scripts-with-export01/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export01/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export02/ast.json b/test/fixtures/ast/multiple-scripts-with-export02/ast.json new file mode 100644 index 00000000..2d8fc7a3 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export02/ast.json @@ -0,0 +1,2518 @@ +{ + "type": "Program", + "start": 8, + "end": 262, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 18, + "column": 12 + } + }, + "range": [ + 9, + 261 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 9, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 9, + 22 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 13, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 13, + 22 + ], + "id": { + "type": "Identifier", + "start": 13, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "range": [ + 13, + 18 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 21, + 22 + ], + "value": 0, + "raw": "0" + } + } + ], + "kind": "let" + }, + { + "type": "ImportDeclaration", + "start": 49, + "end": 66, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "range": [ + 49, + 66 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "range": [ + 56, + 57 + ], + "local": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "range": [ + 56, + 57 + ], + "name": "A" + } + } + ], + "source": { + "type": "Literal", + "start": 63, + "end": 66, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "range": [ + 63, + 66 + ], + "value": "a", + "raw": "'a'" + } + }, + { + "type": "VariableDeclaration", + "start": 67, + "end": 79, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "range": [ + 67, + 79 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 73, + "end": 79, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "range": [ + 73, + 79 + ], + "id": { + "type": "Identifier", + "start": 73, + "end": 74, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "range": [ + 73, + 74 + ], + "name": "a" + }, + "init": { + "type": "Literal", + "start": 77, + "end": 79, + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "range": [ + 77, + 79 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + }, + { + "type": "ExportNamedDeclaration", + "start": 80, + "end": 105, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "range": [ + 80, + 105 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 87, + "end": 105, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "range": [ + 87, + 105 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 91, + "end": 105, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "range": [ + 91, + 105 + ], + "id": { + "type": "Identifier", + "start": 91, + "end": 94, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "range": [ + 91, + 94 + ], + "name": "msg" + }, + "init": { + "type": "Literal", + "start": 97, + "end": 105, + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "range": [ + 97, + 105 + ], + "value": "Hello!", + "raw": "'Hello!'" + } + } + ], + "kind": "let" + }, + "specifiers": [], + "source": null + }, + { + "type": "ImportDeclaration", + "start": 106, + "end": 123, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "range": [ + 106, + 123 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 113, + "end": 114, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "range": [ + 113, + 114 + ], + "local": { + "type": "Identifier", + "start": 113, + "end": 114, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "range": [ + 113, + 114 + ], + "name": "B" + } + } + ], + "source": { + "type": "Literal", + "start": 120, + "end": 123, + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "range": [ + 120, + 123 + ], + "value": "a", + "raw": "'a'" + } + }, + { + "type": "VariableDeclaration", + "start": 124, + "end": 136, + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 12 + } + }, + "range": [ + 124, + 136 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 130, + "end": 136, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 12 + } + }, + "range": [ + 130, + 136 + ], + "id": { + "type": "Identifier", + "start": 130, + "end": 131, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + }, + "range": [ + 130, + 131 + ], + "name": "b" + }, + "init": { + "type": "Literal", + "start": 134, + "end": 136, + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 12 + } + }, + "range": [ + 134, + 136 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + }, + { + "type": "ExportAllDeclaration", + "start": 137, + "end": 156, + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 19 + } + }, + "range": [ + 137, + 156 + ], + "exported": null, + "source": { + "type": "Literal", + "start": 151, + "end": 156, + "loc": { + "start": { + "line": 11, + "column": 14 + }, + "end": { + "line": 11, + "column": 19 + } + }, + "range": [ + 151, + 156 + ], + "value": "foo", + "raw": "'foo'" + } + }, + { + "type": "VariableDeclaration", + "start": 157, + "end": 169, + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "range": [ + 157, + 169 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 163, + "end": 169, + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "range": [ + 163, + 169 + ], + "id": { + "type": "Identifier", + "start": 163, + "end": 164, + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "range": [ + 163, + 164 + ], + "name": "c" + }, + "init": { + "type": "Literal", + "start": 167, + "end": 169, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "range": [ + 167, + 169 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + }, + { + "type": "ExportDefaultDeclaration", + "start": 170, + "end": 187, + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 17 + } + }, + "range": [ + 170, + 187 + ], + "declaration": { + "type": "ObjectExpression", + "start": 185, + "end": 187, + "loc": { + "start": { + "line": 13, + "column": 15 + }, + "end": { + "line": 13, + "column": 17 + } + }, + "range": [ + 185, + 187 + ], + "properties": [] + } + }, + { + "type": "VariableDeclaration", + "start": 188, + "end": 200, + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 12 + } + }, + "range": [ + 188, + 200 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 194, + "end": 200, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 12 + } + }, + "range": [ + 194, + 200 + ], + "id": { + "type": "Identifier", + "start": 194, + "end": 195, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 7 + } + }, + "range": [ + 194, + 195 + ], + "name": "d" + }, + "init": { + "type": "Literal", + "start": 198, + "end": 200, + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 14, + "column": 12 + } + }, + "range": [ + 198, + 200 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + }, + { + "type": "ExportNamedDeclaration", + "start": 201, + "end": 213, + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 12 + } + }, + "range": [ + 201, + 213 + ], + "declaration": null, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 209, + "end": 210, + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "range": [ + 209, + 210 + ], + "local": { + "type": "Identifier", + "start": 209, + "end": 210, + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "range": [ + 209, + 210 + ], + "name": "b" + }, + "exported": { + "type": "Identifier", + "start": 209, + "end": 210, + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "range": [ + 209, + 210 + ], + "name": "b" + } + }, + { + "type": "ExportSpecifier", + "start": 211, + "end": 212, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "range": [ + 211, + 212 + ], + "local": { + "type": "Identifier", + "start": 211, + "end": 212, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "range": [ + 211, + 212 + ], + "name": "c" + }, + "exported": { + "type": "Identifier", + "start": 211, + "end": 212, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "range": [ + 211, + 212 + ], + "name": "c" + } + } + ], + "source": null + }, + { + "type": "ExportNamedDeclaration", + "start": 214, + "end": 238, + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 24 + } + }, + "range": [ + 214, + 238 + ], + "declaration": null, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 222, + "end": 229, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 15 + } + }, + "range": [ + 222, + 229 + ], + "local": { + "type": "Identifier", + "start": 222, + "end": 223, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 9 + } + }, + "range": [ + 222, + 223 + ], + "name": "b" + }, + "exported": { + "type": "Identifier", + "start": 227, + "end": 229, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 15 + } + }, + "range": [ + 227, + 229 + ], + "name": "b2" + } + }, + { + "type": "ExportSpecifier", + "start": 230, + "end": 237, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 23 + } + }, + "range": [ + 230, + 237 + ], + "local": { + "type": "Identifier", + "start": 230, + "end": 231, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 17 + } + }, + "range": [ + 230, + 231 + ], + "name": "c" + }, + "exported": { + "type": "Identifier", + "start": 235, + "end": 237, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 23 + } + }, + "range": [ + 235, + 237 + ], + "name": "c2" + } + } + ], + "source": null + }, + { + "type": "ExportNamedDeclaration", + "start": 239, + "end": 248, + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 9 + } + }, + "range": [ + 239, + 248 + ], + "declaration": null, + "specifiers": [], + "source": null + }, + { + "type": "VariableDeclaration", + "start": 249, + "end": 261, + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 12 + } + }, + "range": [ + 249, + 261 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 255, + "end": 261, + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 12 + } + }, + "range": [ + 255, + 261 + ], + "id": { + "type": "Identifier", + "start": 255, + "end": 256, + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 7 + } + }, + "range": [ + 255, + 256 + ], + "name": "e" + }, + "init": { + "type": "Literal", + "start": 259, + "end": 261, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 12 + } + }, + "range": [ + 259, + 261 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 34, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export02/parser-options.json b/test/fixtures/ast/multiple-scripts-with-export02/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export02/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-with-export02/source.vue b/test/fixtures/ast/multiple-scripts-with-export02/source.vue new file mode 100644 index 00000000..67210d80 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export02/source.vue @@ -0,0 +1,19 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-with-export02/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-export02/token-ranges.json new file mode 100644 index 00000000..b5d9365b --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export02/token-ranges.json @@ -0,0 +1,70 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export02/tree.json b/test/fixtures/ast/multiple-scripts-with-export02/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export02/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export03/ast.json b/test/fixtures/ast/multiple-scripts-with-export03/ast.json new file mode 100644 index 00000000..449ffd40 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export03/ast.json @@ -0,0 +1,2054 @@ +{ + "type": "Program", + "start": 8, + "end": 241, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 15, + "column": 12 + } + }, + "range": [ + 9, + 240 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 9, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 9, + 22 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 13, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 13, + 22 + ], + "id": { + "type": "Identifier", + "start": 13, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "range": [ + 13, + 18 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 21, + 22 + ], + "value": 0, + "raw": "0" + } + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start": 49, + "end": 61, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "range": [ + 49, + 61 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 55, + "end": 61, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "range": [ + 55, + 61 + ], + "id": { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "range": [ + 55, + 56 + ], + "name": "a" + }, + "init": { + "type": "Literal", + "start": 59, + "end": 61, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "range": [ + 59, + 61 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + }, + { + "type": "ImportDeclaration", + "start": 62, + "end": 81, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "range": [ + 62, + 81 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "range": [ + 69, + 70 + ], + "local": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "range": [ + 69, + 70 + ], + "name": "A" + } + } + ], + "source": { + "type": "Literal", + "start": 76, + "end": 81, + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "range": [ + 76, + 81 + ], + "value": "foo", + "raw": "'foo'" + } + }, + { + "type": "ExportAllDeclaration", + "start": 82, + "end": 107, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "range": [ + 82, + 107 + ], + "exported": { + "type": "Identifier", + "start": 94, + "end": 96, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "range": [ + 94, + 96 + ], + "name": "ns" + }, + "source": { + "type": "Literal", + "start": 102, + "end": 107, + "loc": { + "start": { + "line": 8, + "column": 20 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "range": [ + 102, + 107 + ], + "value": "foo", + "raw": "'foo'" + } + }, + { + "type": "ImportDeclaration", + "start": 108, + "end": 127, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 19 + } + }, + "range": [ + 108, + 127 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 115, + "end": 116, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "range": [ + 115, + 116 + ], + "local": { + "type": "Identifier", + "start": 115, + "end": 116, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "range": [ + 115, + 116 + ], + "name": "B" + } + } + ], + "source": { + "type": "Literal", + "start": 122, + "end": 127, + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 19 + } + }, + "range": [ + 122, + 127 + ], + "value": "foo", + "raw": "'foo'" + } + }, + { + "type": "VariableDeclaration", + "start": 128, + "end": 140, + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 12 + } + }, + "range": [ + 128, + 140 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 134, + "end": 140, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 12 + } + }, + "range": [ + 134, + 140 + ], + "id": { + "type": "Identifier", + "start": 134, + "end": 135, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + }, + "range": [ + 134, + 135 + ], + "name": "b" + }, + "init": { + "type": "Literal", + "start": 138, + "end": 140, + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 12 + } + }, + "range": [ + 138, + 140 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + }, + { + "type": "ExportNamedDeclaration", + "start": 141, + "end": 164, + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 23 + } + }, + "range": [ + 141, + 164 + ], + "declaration": null, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 149, + "end": 152, + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "range": [ + 149, + 152 + ], + "local": { + "type": "Identifier", + "start": 149, + "end": 152, + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "range": [ + 149, + 152 + ], + "name": "ns2" + }, + "exported": { + "type": "Identifier", + "start": 149, + "end": 152, + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "range": [ + 149, + 152 + ], + "name": "ns2" + } + } + ], + "source": { + "type": "Literal", + "start": 159, + "end": 164, + "loc": { + "start": { + "line": 11, + "column": 18 + }, + "end": { + "line": 11, + "column": 23 + } + }, + "range": [ + 159, + 164 + ], + "value": "foo", + "raw": "'foo'" + } + }, + { + "type": "VariableDeclaration", + "start": 165, + "end": 177, + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "range": [ + 165, + 177 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 171, + "end": 177, + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "range": [ + 171, + 177 + ], + "id": { + "type": "Identifier", + "start": 171, + "end": 172, + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "range": [ + 171, + 172 + ], + "name": "c" + }, + "init": { + "type": "Literal", + "start": 175, + "end": 177, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "range": [ + 175, + 177 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + }, + { + "type": "ImportDeclaration", + "start": 178, + "end": 197, + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 19 + } + }, + "range": [ + 178, + 197 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 185, + "end": 186, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "range": [ + 185, + 186 + ], + "local": { + "type": "Identifier", + "start": 185, + "end": 186, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "range": [ + 185, + 186 + ], + "name": "C" + } + } + ], + "source": { + "type": "Literal", + "start": 192, + "end": 197, + "loc": { + "start": { + "line": 13, + "column": 14 + }, + "end": { + "line": 13, + "column": 19 + } + }, + "range": [ + 192, + 197 + ], + "value": "foo", + "raw": "'foo'" + } + }, + { + "type": "ExportNamedDeclaration", + "start": 198, + "end": 227, + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 29 + } + }, + "range": [ + 198, + 227 + ], + "declaration": null, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 206, + "end": 215, + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "range": [ + 206, + 215 + ], + "local": { + "type": "Identifier", + "start": 206, + "end": 208, + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "range": [ + 206, + 208 + ], + "name": "ns" + }, + "exported": { + "type": "Identifier", + "start": 212, + "end": 215, + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "range": [ + 212, + 215 + ], + "name": "ns3" + } + } + ], + "source": { + "type": "Literal", + "start": 222, + "end": 227, + "loc": { + "start": { + "line": 14, + "column": 24 + }, + "end": { + "line": 14, + "column": 29 + } + }, + "range": [ + 222, + 227 + ], + "value": "foo", + "raw": "'foo'" + } + }, + { + "type": "VariableDeclaration", + "start": 228, + "end": 240, + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 12 + } + }, + "range": [ + 228, + 240 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 234, + "end": 240, + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 12 + } + }, + "range": [ + 234, + 240 + ], + "id": { + "type": "Identifier", + "start": 234, + "end": 235, + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "range": [ + 234, + 235 + ], + "name": "d" + }, + "init": { + "type": "Literal", + "start": 238, + "end": 240, + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 12 + } + }, + "range": [ + 238, + 240 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 34, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export03/parser-options.json b/test/fixtures/ast/multiple-scripts-with-export03/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export03/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-with-export03/source.vue b/test/fixtures/ast/multiple-scripts-with-export03/source.vue new file mode 100644 index 00000000..c1b579c6 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export03/source.vue @@ -0,0 +1,16 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-with-export03/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-export03/token-ranges.json new file mode 100644 index 00000000..fc1ab24d --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export03/token-ranges.json @@ -0,0 +1,58 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export03/tree.json b/test/fixtures/ast/multiple-scripts-with-export03/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export03/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export04/ast.json b/test/fixtures/ast/multiple-scripts-with-export04/ast.json new file mode 100644 index 00000000..c95d2858 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export04/ast.json @@ -0,0 +1,1191 @@ +{ + "type": "Program", + "start": 8, + "end": 178, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 22 + } + }, + "range": [ + 9, + 177 + ], + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 9, + 30 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 16, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 16, + 30 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 20, + 30 + ], + "id": { + "type": "Identifier", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "range": [ + 20, + 25 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 28, + 30 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "let" + }, + "specifiers": [], + "source": null + }, + { + "type": "ExportNamedDeclaration", + "start": 31, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 31, + 53 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 38, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 38, + 53 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 42, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 42, + 53 + ], + "id": { + "type": "Identifier", + "start": 42, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "range": [ + 42, + 48 + ], + "name": "count2" + }, + "init": { + "type": "Literal", + "start": 51, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 51, + 53 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "let" + }, + "specifiers": [], + "source": null + }, + { + "type": "ImportDeclaration", + "start": 79, + "end": 124, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 45 + } + }, + "range": [ + 79, + 124 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 86, + "end": 98, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "range": [ + 86, + 98 + ], + "local": { + "type": "Identifier", + "start": 86, + "end": 98, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "range": [ + 86, + 98 + ], + "name": "MyComponent1" + } + } + ], + "source": { + "type": "Literal", + "start": 104, + "end": 124, + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 45 + } + }, + "range": [ + 104, + 124 + ], + "value": "./MyComponent1.vue", + "raw": "'./MyComponent1.vue'" + } + }, + { + "type": "VariableDeclaration", + "start": 125, + "end": 139, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "range": [ + 125, + 139 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 129, + "end": 139, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "range": [ + 129, + 139 + ], + "id": { + "type": "Identifier", + "start": 129, + "end": 134, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "range": [ + 129, + 134 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 137, + "end": 139, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "range": [ + 137, + 139 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "let" + }, + { + "type": "ExportNamedDeclaration", + "start": 140, + "end": 154, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "range": [ + 140, + 154 + ], + "declaration": null, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 148, + "end": 153, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "range": [ + 148, + 153 + ], + "local": { + "type": "Identifier", + "start": 148, + "end": 153, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "range": [ + 148, + 153 + ], + "name": "count" + }, + "exported": { + "type": "Identifier", + "start": 148, + "end": 153, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "range": [ + 148, + 153 + ], + "name": "count" + } + } + ], + "source": null + }, + { + "type": "ExportNamedDeclaration", + "start": 155, + "end": 177, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 22 + } + }, + "range": [ + 155, + 177 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 162, + "end": 177, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 22 + } + }, + "range": [ + 162, + 177 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 166, + "end": 177, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 22 + } + }, + "range": [ + 166, + 177 + ], + "id": { + "type": "Identifier", + "start": 166, + "end": 172, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "range": [ + 166, + 172 + ], + "name": "count2" + }, + "init": { + "type": "Literal", + "start": 175, + "end": 177, + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 22 + } + }, + "range": [ + 175, + 177 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "let" + }, + "specifiers": [], + "source": null + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 64, + 78 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export04/parser-options.json b/test/fixtures/ast/multiple-scripts-with-export04/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export04/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-with-export04/source.vue b/test/fixtures/ast/multiple-scripts-with-export04/source.vue new file mode 100644 index 00000000..188597dc --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export04/source.vue @@ -0,0 +1,10 @@ + + diff --git a/test/fixtures/ast/multiple-scripts-with-export04/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-export04/token-ranges.json new file mode 100644 index 00000000..bfab1925 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export04/token-ranges.json @@ -0,0 +1,33 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-export04/tree.json b/test/fixtures/ast/multiple-scripts-with-export04/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-export04/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/ast.json b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/ast.json new file mode 100644 index 00000000..eeeed2fc --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/ast.json @@ -0,0 +1,733 @@ +{ + "type": "Program", + "body": [ + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "init": { + "type": "Literal", + "value": 42, + "raw": "42", + "range": [ + 24, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "range": [ + 20, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 17 + } + } + } + ], + "kind": "let", + "range": [ + 16, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "specifiers": [], + "source": null, + "exportKind": "value", + "range": [ + 9, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "ClassDeclaration", + "id": { + "type": "Identifier", + "name": "A", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + "body": { + "type": "ClassBody", + "body": [], + "range": [ + 79, + 82 + ], + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + "superClass": null, + "range": [ + 53, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "decorators": [ + { + "type": "Decorator", + "expression": { + "type": "Identifier", + "name": "Decorator", + "range": [ + 54, + 63 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 10 + } + } + }, + "range": [ + 53, + 63 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 10 + } + } + } + ] + }, + "specifiers": [], + "source": null, + "exportKind": "value", + "range": [ + 64, + 82 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + } + }, + "init": { + "type": "NewExpression", + "callee": { + "type": "Identifier", + "name": "A", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 15 + } + } + }, + "arguments": [], + "range": [ + 93, + 100 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + "range": [ + 89, + 100 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 17 + } + } + } + ], + "kind": "const", + "range": [ + 83, + 100 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 17 + } + } + } + ], + "sourceType": "module", + "range": [ + 9, + 100 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 38, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + } + ], + "comments": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/parser-options.json b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/requirements.json b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/requirements.json new file mode 100644 index 00000000..945cf775 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/requirements.json @@ -0,0 +1,3 @@ +{ + "@typescript-eslint/parser": "^4.0.0" +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/source.vue b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/source.vue new file mode 100644 index 00000000..a91efd79 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/source.vue @@ -0,0 +1,10 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/token-ranges.json new file mode 100644 index 00000000..deeb00ef --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/token-ranges.json @@ -0,0 +1,25 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/tree.json b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-export-decorator-1/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-with-export/ast.json b/test/fixtures/ast/script-setup-with-export/ast.json new file mode 100644 index 00000000..1d101196 --- /dev/null +++ b/test/fixtures/ast/script-setup-with-export/ast.json @@ -0,0 +1,264 @@ +{ + "type": "Program", + "start": 14, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 15, + 40 + ], + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 15, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 15, + 40 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 22, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 22, + 40 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 26, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 26, + 40 + ], + "id": { + "type": "Identifier", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "range": [ + 26, + 29 + ], + "name": "msg" + }, + "init": { + "type": "Literal", + "start": 32, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 32, + 40 + ], + "value": "Hello!", + "raw": "'Hello!'" + } + } + ], + "kind": "let" + }, + "specifiers": [], + "source": null + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-with-export/parser-options.json b/test/fixtures/ast/script-setup-with-export/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-with-export/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-with-export/source.vue b/test/fixtures/ast/script-setup-with-export/source.vue new file mode 100644 index 00000000..8aae4009 --- /dev/null +++ b/test/fixtures/ast/script-setup-with-export/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/script-setup-with-export/token-ranges.json b/test/fixtures/ast/script-setup-with-export/token-ranges.json new file mode 100644 index 00000000..72b76885 --- /dev/null +++ b/test/fixtures/ast/script-setup-with-export/token-ranges.json @@ -0,0 +1,9 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-with-export/tree.json b/test/fixtures/ast/script-setup-with-export/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-with-export/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file