diff --git a/package.json b/package.json index a5dbd835..14243367 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "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 \"test/*.js\" --reporter dot --timeout 10000", + "test:debug": "mocha --inspect --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 10000", "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 18b4c030..7934b4a9 100644 --- a/scripts/update-fixtures-ast.js +++ b/scripts/update-fixtures-ast.js @@ -12,6 +12,7 @@ const fs = require("fs") const path = require("path") const parser = require("../") +const escope = require("eslint-scope") //------------------------------------------------------------------------------ // Helpers @@ -38,7 +39,7 @@ function replacer(key, value) { return undefined } if (key === "errors" && Array.isArray(value)) { - return value.map(e => ({ + return value.map((e) => ({ message: e.message, index: e.index, lineNumber: e.lineNumber, @@ -95,6 +96,106 @@ function getTree(source, ast) { return root.children } +function scopeToJSON(scopeManager) { + return JSON.stringify(normalizeScope(scopeManager.globalScope), replacer, 4) + + function normalizeScope(scope) { + return { + type: scope.type, + variables: scope.variables.map(normalizeVar), + references: scope.references.map(normalizeReference), + childScopes: scope.childScopes.map(normalizeScope), + through: scope.through.map(normalizeReference), + } + } + + function normalizeVar(v) { + return { + name: v.name, + identifiers: v.identifiers.map(normalizeId), + defs: v.defs.map(normalizeDef), + references: v.references.map(normalizeReference), + } + } + + function normalizeReference(reference) { + return { + identifier: normalizeId(reference.identifier), + from: reference.from.type, + resolved: normalizeId( + reference.resolved && + reference.resolved.defs && + reference.resolved.defs[0] && + reference.resolved.defs[0].name + ), + init: reference.init || null, + } + } + + function normalizeDef(def) { + return { + type: def.type, + node: normalizeDefNode(def.node), + name: def.name.name, + } + } + + function normalizeId(identifier) { + return ( + identifier && { + type: identifier.type, + name: identifier.name, + loc: identifier.loc, + } + ) + } + + function normalizeDefNode(node) { + return { + type: node.type, + loc: node.loc, + } + } +} + +/** + * Analyze scope + */ +function analyze(ast, parserOptions) { + const ecmaVersion = parserOptions.ecmaVersion || 2017 + const ecmaFeatures = parserOptions.ecmaFeatures || {} + const sourceType = parserOptions.sourceType || "script" + const result = escope.analyze(ast, { + ignoreEval: true, + nodejsScope: false, + impliedStrict: ecmaFeatures.impliedStrict, + ecmaVersion, + sourceType, + fallback: getFallbackKeys, + }) + + return result + + function getFallbackKeys(node) { + return Object.keys(node).filter(fallbackKeysFilter, node) + } + + function fallbackKeysFilter(key) { + const value = null + return ( + key !== "comments" && + key !== "leadingComments" && + key !== "loc" && + key !== "parent" && + key !== "range" && + key !== "tokens" && + key !== "trailingComments" && + typeof value === "object" && + (typeof value.type === "string" || Array.isArray(value)) + ) + } +} + //------------------------------------------------------------------------------ // Main //------------------------------------------------------------------------------ @@ -105,25 +206,30 @@ for (const name of TARGETS) { const astPath = path.join(ROOT, `${name}/ast.json`) const tokenRangesPath = path.join(ROOT, `${name}/token-ranges.json`) const treePath = path.join(ROOT, `${name}/tree.json`) + const scopePath = path.join(ROOT, `${name}/scope.json`) const source = fs.readFileSync(sourcePath, "utf8") - const actual = parser.parse( - source, - Object.assign( - { filePath: sourcePath }, - PARSER_OPTIONS, - fs.existsSync(optionsPath) - ? JSON.parse(fs.readFileSync(optionsPath, "utf8")) - : {} - ) + const options = Object.assign( + { filePath: sourcePath }, + PARSER_OPTIONS, + fs.existsSync(optionsPath) + ? JSON.parse(fs.readFileSync(optionsPath, "utf8")) + : {} ) - const tokenRanges = getAllTokens(actual).map(t => + const actual = parser.parseForESLint(source, options) + const tokenRanges = getAllTokens(actual.ast).map((t) => source.slice(t.range[0], t.range[1]) ) - const tree = getTree(source, actual) + const tree = getTree(source, actual.ast) console.log("Update:", name) - fs.writeFileSync(astPath, JSON.stringify(actual, replacer, 4)) + fs.writeFileSync(astPath, JSON.stringify(actual.ast, replacer, 4)) fs.writeFileSync(tokenRangesPath, JSON.stringify(tokenRanges, replacer, 4)) fs.writeFileSync(treePath, JSON.stringify(tree, replacer, 4)) + if (fs.existsSync(scopePath)) { + fs.writeFileSync( + scopePath, + scopeToJSON(actual.scopeManager || analyze(actual.ast, options)) + ) + } } diff --git a/src/common/fix-locations.ts b/src/common/fix-locations.ts index 2d691d22..63987d39 100644 --- a/src/common/fix-locations.ts +++ b/src/common/fix-locations.ts @@ -1,4 +1,10 @@ -import type { ESLintExtendedProgram, LocationRange, Node } from "../ast" +import type { + ESLintExtendedProgram, + HasLocation, + LocationRange, + Node, + ParseError, +} from "../ast" import { traverseNodes } from "../ast" import type { LocationCalculator } from "./location-calculator" @@ -42,7 +48,7 @@ export function fixLocations( traversed.add(node.loc) } } else { - locationCalculator.fixLocation(node) + fixLocation(node, locationCalculator) traversed.add(node.range) traversed.add(node.loc) } @@ -55,9 +61,57 @@ export function fixLocations( }) for (const token of result.ast.tokens || []) { - locationCalculator.fixLocation(token) + fixLocation(token, locationCalculator) } for (const comment of result.ast.comments || []) { - locationCalculator.fixLocation(comment) + fixLocation(comment, locationCalculator) } } + +/** + * Modify the location information of the given node with using the base offset and gaps of this calculator. + * @param node The node to modify their location. + */ +export function fixLocation( + node: T, + locationCalculator: LocationCalculator, +): T { + const range = node.range + const loc = node.loc + const d0 = locationCalculator.getFixOffset(range[0], "start") + const d1 = locationCalculator.getFixOffset(range[1], "end") + + if (d0 !== 0) { + range[0] += d0 + if (node.start != null) { + node.start += d0 + } + loc.start = locationCalculator.getLocFromIndex(range[0]) + } + if (d1 !== 0) { + range[1] += d1 + if (node.end != null) { + node.end += d0 + } + loc.end = locationCalculator.getLocFromIndex(range[1]) + } + + return node +} + +/** + * Modify the location information of the given error with using the base offset and gaps of this calculator. + * @param error The error to modify their location. + */ +export function fixErrorLocation( + error: ParseError, + locationCalculator: LocationCalculator, +) { + const diff = locationCalculator.getFixOffset(error.index, "start") + + error.index += diff + + const loc = locationCalculator.getLocFromIndex(error.index) + error.lineNumber = loc.line + error.column = loc.column +} diff --git a/src/common/lines-and-columns.ts b/src/common/lines-and-columns.ts new file mode 100644 index 00000000..e6b7028f --- /dev/null +++ b/src/common/lines-and-columns.ts @@ -0,0 +1,27 @@ +import sortedLastIndex from "lodash/sortedLastIndex" +import type { Location } from "../ast" +/** + * A class for getting lines and columns location. + */ +export class LinesAndColumns { + protected ltOffsets: number[] + + /** + * Initialize. + * @param ltOffsets The list of the offset of line terminators. + */ + public constructor(ltOffsets: number[]) { + this.ltOffsets = ltOffsets + } + + /** + * Calculate the location of the given index. + * @param index The index to calculate their location. + * @returns The location of the index. + */ + public getLocFromIndex(index: number): Location { + const line = sortedLastIndex(this.ltOffsets, index) + 1 + const column = index - (line === 1 ? 0 : this.ltOffsets[line - 2]) + return { line, column } + } +} diff --git a/src/common/location-calculator.ts b/src/common/location-calculator.ts index 6b3d6ba1..ee2be166 100644 --- a/src/common/location-calculator.ts +++ b/src/common/location-calculator.ts @@ -4,7 +4,26 @@ * See LICENSE file in root directory for full license. */ import sortedLastIndex from "lodash/sortedLastIndex" -import type { HasLocation, Location, ParseError } from "../ast" +import type { Location } from "../ast" +import { LinesAndColumns } from "./lines-and-columns" + +/** + * Location calculators. + */ +export interface LocationCalculator { + /** + * Gets the fix location offset of the given offset with using the base offset of this calculator. + * @param offset The offset to modify. + */ + getFixOffset(offset: number, kind: "start" | "end"): number + + /** + * Calculate the location of the given index. + * @param index The index to calculate their location. + * @returns The location of the index. + */ + getLocFromIndex(index: number): Location +} /** * Location calculators. @@ -18,9 +37,11 @@ import type { HasLocation, Location, ParseError } from "../ast" * - Adjusts the locations of script ASTs. * - Creates expression containers in postprocess. */ -export class LocationCalculator { +export class LocationCalculatorForHtml + extends LinesAndColumns + implements LocationCalculator +{ private gapOffsets: number[] - private ltOffsets: number[] private baseOffset: number private baseIndexOfGap: number private shiftOffset: number @@ -38,6 +59,7 @@ export class LocationCalculator { baseOffset?: number, shiftOffset = 0, ) { + super(ltOffsets) this.gapOffsets = gapOffsets this.ltOffsets = ltOffsets this.baseOffset = baseOffset || 0 @@ -53,8 +75,8 @@ export class LocationCalculator { * @param offset The base offset of new sub calculator. * @returns Sub calculator. */ - public getSubCalculatorAfter(offset: number): LocationCalculator { - return new LocationCalculator( + public getSubCalculatorAfter(offset: number): LocationCalculatorForHtml { + return new LocationCalculatorForHtml( this.gapOffsets, this.ltOffsets, this.baseOffset + offset, @@ -67,8 +89,8 @@ export class LocationCalculator { * @param offset The shift of new sub calculator. * @returns Sub calculator. */ - public getSubCalculatorShift(offset: number): LocationCalculator { - return new LocationCalculator( + public getSubCalculatorShift(offset: number): LocationCalculatorForHtml { + return new LocationCalculatorForHtml( this.gapOffsets, this.ltOffsets, this.baseOffset, @@ -76,26 +98,6 @@ export class LocationCalculator { ) } - /** - * Calculate the location of the given index. - * @param index The index to calculate their location. - * @returns The location of the index. - */ - public getLocFromIndex(index: number): Location { - return this._getLocation(index) - } - - /** - * Calculate the location of the given offset. - * @param offset The offset to calculate their location. - * @returns The location of the offset. - */ - private _getLocation(offset: number): Location { - const line = sortedLastIndex(this.ltOffsets, offset) + 1 - const column = offset - (line === 1 ? 0 : this.ltOffsets[line - 2]) - return { line, column } - } - /** * Calculate gap at the given index. * @param index The index to calculate gap. @@ -119,7 +121,7 @@ export class LocationCalculator { * @returns The location of the index. */ public getLocation(index: number): Location { - return this._getLocation(this.baseOffset + index + this.shiftOffset) + return this.getLocFromIndex(this.baseOffset + index + this.shiftOffset) } /** @@ -138,49 +140,12 @@ export class LocationCalculator { } /** - * Modify the location information of the given node with using the base offset and gaps of this calculator. - * @param node The node to modify their location. + * Gets the fix location offset of the given offset with using the base offset of this calculator. + * @param offset The offset to modify. */ - public fixLocation(node: T): T { + public getFixOffset(offset: number): number { const shiftOffset = this.shiftOffset - const range = node.range - const loc = node.loc - const gap0 = this._getGap(range[0] + shiftOffset) - const gap1 = this._getGap(range[1] + shiftOffset) - const d0 = this.baseOffset + Math.max(0, gap0) + shiftOffset - const d1 = this.baseOffset + Math.max(0, gap1) + shiftOffset - - if (d0 !== 0) { - range[0] += d0 - if (node.start != null) { - node.start += d0 - } - loc.start = this._getLocation(range[0]) - } - if (d1 !== 0) { - range[1] += d1 - if (node.end != null) { - node.end += d0 - } - loc.end = this._getLocation(range[1]) - } - - return node - } - - /** - * Modify the location information of the given error with using the base offset and gaps of this calculator. - * @param error The error to modify their location. - */ - public fixErrorLocation(error: ParseError) { - const shiftOffset = this.shiftOffset - const gap = this._getGap(error.index + shiftOffset) - const diff = this.baseOffset + Math.max(0, gap) + shiftOffset - - error.index += diff - - const loc = this._getLocation(error.index) - error.lineNumber = loc.line - error.column = loc.column + const gap = this._getGap(offset + shiftOffset) + return this.baseOffset + Math.max(0, gap) + shiftOffset } } diff --git a/src/html/parser.ts b/src/html/parser.ts index fa7d99c0..2f139e27 100644 --- a/src/html/parser.ts +++ b/src/html/parser.ts @@ -18,7 +18,7 @@ import type { } from "../ast" import { NS, ParseError } from "../ast" import { debug } from "../common/debug" -import { LocationCalculator } from "../common/location-calculator" +import { LocationCalculatorForHtml } from "../common/location-calculator" import { convertToDirective, processMustache, @@ -161,7 +161,7 @@ function propagateEndLocation(node: VDocumentFragment | VElement): void { */ export class Parser { private tokenizer: IntermediateTokenizer - private locationCalculator: LocationCalculator + private locationCalculator: LocationCalculatorForHtml private parserOptions: ParserOptions private isSFC: boolean private document: VDocumentFragment @@ -239,7 +239,7 @@ export class Parser { */ public constructor(tokenizer: Tokenizer, parserOptions: ParserOptions) { this.tokenizer = new IntermediateTokenizer(tokenizer) - this.locationCalculator = new LocationCalculator( + this.locationCalculator = new LocationCalculatorForHtml( tokenizer.gaps, tokenizer.lineTerminators, ) diff --git a/src/index.ts b/src/index.ts index 92ff7408..3918694f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,11 +5,14 @@ */ import * as path from "path" import * as AST from "./ast" -import { LocationCalculator } from "./common/location-calculator" +import { LocationCalculatorForHtml } from "./common/location-calculator" import { HTMLParser, HTMLTokenizer } from "./html" import { parseScript, parseScriptElement } from "./script" import * as services from "./parser-services" import type { ParserOptions } from "./common/parser-options" +import { parseScriptSetupElements } from "./script-setup" +import { LinesAndColumns } from "./common/lines-and-columns" +import type { VElement } from "./ast" const STARTS_WITH_LT = /^\s*`. + */ +function isScriptSetup(script: AST.VElement): boolean { + return script.startTag.attributes.some( + (attr) => !attr.directive && attr.key.name === "setup", + ) +} + /** * Parse the given source code. * @param code The source code to parse. @@ -92,7 +104,7 @@ export function parseForESLint( let result: AST.ESLintExtendedProgram let document: AST.VDocumentFragment | null - let locationCalculator: LocationCalculator | null + let locationCalculator: LocationCalculatorForHtml | null if (!isVueFile(code, options)) { result = parseScript(code, options) document = null @@ -101,11 +113,12 @@ export function parseForESLint( const skipParsingScript = options.parser === false const tokenizer = new HTMLTokenizer(code, options) const rootAST = new HTMLParser(tokenizer, options).parse() - locationCalculator = new LocationCalculator( + + locationCalculator = new LocationCalculatorForHtml( tokenizer.gaps, tokenizer.lineTerminators, ) - const script = rootAST.children.find(isScriptElement) + const scripts = rootAST.children.filter(isScriptElement) const template = rootAST.children.find(isTemplateElement) const templateLang = getLang(template, "html") const concreteInfo: AST.HasConcreteInfo = { @@ -118,10 +131,22 @@ export function parseForESLint( ? Object.assign(template, concreteInfo) : undefined - if (skipParsingScript || script == null) { + let scriptSetup: VElement | undefined + if (skipParsingScript || !scripts.length) { result = parseScript("", options) + } else if ( + scripts.length === 2 && + (scriptSetup = scripts.find(isScriptSetup)) + ) { + result = parseScriptSetupElements( + scriptSetup, + scripts.find((e) => e !== scriptSetup)!, + code, + new LinesAndColumns(tokenizer.lineTerminators), + options, + ) } else { - result = parseScriptElement(script, locationCalculator, options) + result = parseScriptElement(scripts[0], locationCalculator, options) } result.ast.templateBody = templateBody diff --git a/src/parser-services.ts b/src/parser-services.ts index d2af06b0..693c1ea2 100644 --- a/src/parser-services.ts +++ b/src/parser-services.ts @@ -14,7 +14,7 @@ import type { VAttribute, } from "./ast" import { getFallbackKeys, KEYS, traverseNodes } from "./ast/traverse" -import type { LocationCalculator } from "./common/location-calculator" +import type { LocationCalculatorForHtml } from "./common/location-calculator" import type { CustomBlockContext, ESLintCustomBlockParser, @@ -98,7 +98,7 @@ export function define( sourceText: string, rootAST: ESLintProgram, document: VDocumentFragment | null, - globalLocationCalculator: LocationCalculator | null, + globalLocationCalculator: LocationCalculatorForHtml | null, { parserOptions }: { parserOptions: ParserOptions }, ): ParserServices { const customBlocksEmitters = new Map< diff --git a/src/script-setup/index.ts b/src/script-setup/index.ts new file mode 100644 index 00000000..0a5c4403 --- /dev/null +++ b/src/script-setup/index.ts @@ -0,0 +1,558 @@ +/** + * @author Yosuke Ota + * See LICENSE file in root directory for full license. + */ +import type { ScopeManager, Scope } from "eslint-scope" +import type { + ESLintBlockStatement, + ESLintExtendedProgram, + ESLintStatement, + VElement, +} from "../ast" +import { ParseError, traverseNodes } from "../ast" +import { fixErrorLocation, fixLocations } 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" + +type RemapBlock = { + range: [number, number] + offset: number +} +class CodeBlocks { + public code: string + // The location information for remapping. + public remapBlocks: RemapBlock[] = [] + // The list of extra punctuation locations added to split the statement. + public splitPunctuators: number[] = [] + + public constructor() { + this.code = "" + } + public get length() { + return this.code.length + } + public append(codeLet: string, originalOffset: number) { + const rangeStart = this.code.length + this.code += codeLet.trimRight() + this.remapBlocks.push({ + range: [rangeStart, this.code.length], + offset: originalOffset - rangeStart, + }) + } + public appendSplitPunctuators(punctuator: string) { + this.splitPunctuators.push(this.code.length) + this.code += `${punctuator}\n` + } + public appendCodeBlocks(codeBlocks: CodeBlocks) { + const start = this.code.length + this.code += codeBlocks.code + this.remapBlocks.push( + ...codeBlocks.remapBlocks.map( + (b): RemapBlock => ({ + range: [b.range[0] + start, b.range[1] + start], + offset: b.offset - start, + }), + ), + ) + this.splitPunctuators.push( + ...codeBlocks.splitPunctuators.map((s) => s + start), + ) + } +} + +type ScriptSetupCodeBlocks = { + codeBlocks: CodeBlocks + // The location of the code of the import statements in `", + }) + } + } + result.ast.tokens.sort((a, b) => a.range[0] - b.range[0]) + } + result.ast.body.sort((a, b) => a.range[0] - b.range[0]) + + const programEndOffset = result.ast.body.reduce( + (end, node) => Math.max(end, node.range[1]), + 0, + ) + result.ast.range[1] = programEndOffset + result.ast.loc.end = locationCalculator.getLocFromIndex(programEndOffset) + if (result.ast.end != null) { + result.ast.end = [scriptSetupElement, scriptElement].reduce( + (end, node) => { + const textNode = node.children[0] + return Math.max( + end, + textNode != null && textNode.type === "VText" + ? textNode.range[1] + : node.endTag?.range[1] ?? node.range[1], + ) + }, + 0, + ) + } + + return result +} + +/** + * Parses the scripts of the given ` + * + * ``` + * + * ↓ + * + * ```js + * export let count = 42 + * ; + * import MyComponent from './MyComponent.vue'; + * { + * let count = 42 + * } + * ``` + * + * Example 2: + * + * ```vue + * + * + * ``` + * + * ↓ + * + * ```js + * export let count = 42 + * ; + * import MyComponent1 from './MyComponent1.vue'; + * import MyComponent2 from './MyComponent2.vue'; + * { + * let count = 42; + * let a + * } + * ``` + */ +function getScriptsCodeBlocks( + scriptSetupElement: VElement, + scriptElement: VElement, + sfcCode: string, + linesAndColumns: LinesAndColumns, + parserOptions: ParserOptions, +): ScriptSetupCodeBlocks | null { + const scriptSetupCodeBlocks = getScriptSetupCodeBlocks( + scriptSetupElement, + sfcCode, + linesAndColumns, + parserOptions, + ) + + const textNode = scriptElement.children[0] + if (textNode == null || textNode.type !== "VText") { + return scriptSetupCodeBlocks + } + + const [scriptStartOffset, scriptEndOffset] = textNode.range + const codeBlocks = new CodeBlocks() + codeBlocks.append( + sfcCode.slice(scriptStartOffset, scriptEndOffset), + scriptStartOffset, + ) + if (scriptSetupCodeBlocks == null) { + return { codeBlocks } + } + + codeBlocks.appendSplitPunctuators(";") + const scriptSetupOffset = codeBlocks.length + codeBlocks.appendCodeBlocks(scriptSetupCodeBlocks.codeBlocks) + return { + codeBlocks, + scriptSetupImportRange: + scriptSetupCodeBlocks.scriptSetupImportRange && [ + scriptSetupCodeBlocks.scriptSetupImportRange[0] + + scriptSetupOffset, + scriptSetupCodeBlocks.scriptSetupImportRange[1] + + scriptSetupOffset, + ], + scriptSetupBlockRange: scriptSetupCodeBlocks.scriptSetupBlockRange && [ + scriptSetupCodeBlocks.scriptSetupBlockRange[0] + scriptSetupOffset, + scriptSetupCodeBlocks.scriptSetupBlockRange[1] + scriptSetupOffset, + ], + } +} + +/** + * Parses the script in the given `" + }, + { + "type": "Punctuator", + "range": [ + 40, + 54 + ], + "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-2/parser-options.json b/test/fixtures/ast/multiple-scripts-2/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-2/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-2/source.vue b/test/fixtures/ast/multiple-scripts-2/source.vue new file mode 100644 index 00000000..c4c3f1e2 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-2/source.vue @@ -0,0 +1,9 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-2/token-ranges.json b/test/fixtures/ast/multiple-scripts-2/token-ranges.json new file mode 100644 index 00000000..0570d8ea --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-2/token-ranges.json @@ -0,0 +1,26 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-2/tree.json b/test/fixtures/ast/multiple-scripts-2/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-2/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-3/ast.json b/test/fixtures/ast/multiple-scripts-3/ast.json new file mode 100644 index 00000000..85552110 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-3/ast.json @@ -0,0 +1,749 @@ +{ + "type": "Program", + "start": 8, + "end": 91, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "range": [ + 9, + 90 + ], + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "range": [ + 9, + 17 + ], + "expression": { + "type": "Literal", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "range": [ + 9, + 17 + ], + "value": "script", + "raw": "\"script\"" + }, + "directive": "script" + }, + { + "type": "ExpressionStatement", + "start": 76, + "end": 90, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "range": [ + 76, + 90 + ], + "expression": { + "type": "Literal", + "start": 76, + "end": 90, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "range": [ + 76, + 90 + ], + "value": "script setup", + "raw": "\"script setup\"" + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 61, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 29, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 29, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 39, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "Template!" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 48, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "\"script\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 18, + 26 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 29, + 38 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 39, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "Template!" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 48, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 59, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 69, + 74 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 76, + 83 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": "\"script" + }, + { + "type": "HTMLWhitespace", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 84, + 90 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "value": "setup\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 91, + 99 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-3/parser-options.json b/test/fixtures/ast/multiple-scripts-3/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-3/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-3/source.vue b/test/fixtures/ast/multiple-scripts-3/source.vue new file mode 100644 index 00000000..e136f806 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-3/source.vue @@ -0,0 +1,9 @@ + + + + + diff --git a/test/fixtures/ast/multiple-scripts-3/token-ranges.json b/test/fixtures/ast/multiple-scripts-3/token-ranges.json new file mode 100644 index 00000000..91b6f7d5 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-3/token-ranges.json @@ -0,0 +1,33 @@ +[ + "", + "", + "", + "\n", + "\"script\"", + "\n", + "", + "\n\n", + "", + "Template!", + "", + "\n\n", + "", + "\n", + "\"script", + " ", + "setup\"", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-3/tree.json b/test/fixtures/ast/multiple-scripts-3/tree.json new file mode 100644 index 00000000..7cedc5f9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-3/tree.json @@ -0,0 +1,23 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-4/ast.json b/test/fixtures/ast/multiple-scripts-4/ast.json new file mode 100644 index 00000000..84d2d8cf --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-4/ast.json @@ -0,0 +1,851 @@ +{ + "type": "Program", + "start": 8, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "range": [ + 9, + 17 + ], + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "range": [ + 9, + 17 + ], + "expression": { + "type": "Literal", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "range": [ + 9, + 17 + ], + "value": "script", + "raw": "\"script\"" + }, + "directive": "script" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 29, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 29, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 39, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "Template!" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 48, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "\"script\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 18, + 26 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 29, + 38 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 39, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "Template!" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 48, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 59, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 69, + 74 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 76, + 83 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": "\"script" + }, + { + "type": "HTMLWhitespace", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 84, + 90 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "value": "setup\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 91, + 99 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 102 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 102, + 109 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 110, + 117 + ], + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "value": "unknown" + }, + { + "type": "HTMLTagClose", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 11, + "column": 15 + }, + "end": { + "line": 11, + "column": 16 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 11, + "column": 16 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 119, + 126 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "value": "\"script" + }, + { + "type": "HTMLWhitespace", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 127, + 135 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 16 + } + }, + "value": "unknown\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 136, + 144 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-4/parser-options.json b/test/fixtures/ast/multiple-scripts-4/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-4/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-4/source.vue b/test/fixtures/ast/multiple-scripts-4/source.vue new file mode 100644 index 00000000..7d1a37de --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-4/source.vue @@ -0,0 +1,13 @@ + + + + + + + diff --git a/test/fixtures/ast/multiple-scripts-4/token-ranges.json b/test/fixtures/ast/multiple-scripts-4/token-ranges.json new file mode 100644 index 00000000..002d3fc9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-4/token-ranges.json @@ -0,0 +1,41 @@ +[ + "", + "", + "\n", + "\"script\"", + "\n", + "", + "\n\n", + "", + "Template!", + "", + "\n\n", + "", + "\n", + "\"script", + " ", + "setup\"", + "\n", + "", + "\n\n", + "", + "\n", + "\"script", + " ", + "unknown\"", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-4/tree.json b/test/fixtures/ast/multiple-scripts-4/tree.json new file mode 100644 index 00000000..7cedc5f9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-4/tree.json @@ -0,0 +1,23 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-5/ast.json b/test/fixtures/ast/multiple-scripts-5/ast.json new file mode 100644 index 00000000..0c0ff3e9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-5/ast.json @@ -0,0 +1,1727 @@ +{ + "type": "Program", + "start": 8, + "end": 145, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "range": [ + 9, + 144 + ], + "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": "ImportDeclaration", + "start": 102, + "end": 129, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "range": [ + 102, + 129 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 109, + "end": 112, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "range": [ + 109, + 112 + ], + "local": { + "type": "Identifier", + "start": 109, + "end": 112, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "range": [ + 109, + 112 + ], + "name": "Foo" + } + } + ], + "source": { + "type": "Literal", + "start": 118, + "end": 129, + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "range": [ + 118, + 129 + ], + "value": "./Foo.vue", + "raw": "'./Foo.vue'" + } + }, + { + "type": "VariableDeclaration", + "start": 130, + "end": 144, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "range": [ + 130, + 144 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 134, + "end": 144, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "range": [ + 134, + 144 + ], + "id": { + "type": "Identifier", + "start": 134, + "end": 139, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "range": [ + 134, + 139 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 142, + "end": 144, + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "range": [ + 142, + 144 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "let" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 87, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 42, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 43 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 42, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VElement", + "range": [ + 52, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 32 + } + }, + "name": "foo", + "rawName": "Foo", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 52, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VExpressionContainer", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "expression": { + "type": "Identifier", + "start": 60, + "end": 65, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "range": [ + 60, + 65 + ], + "name": "count" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 60, + "end": 65, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "range": [ + 60, + 65 + ], + "name": "count" + }, + "mode": "r" + } + ] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 32 + } + } + }, + "variables": [] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 74, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 43 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "export" + }, + { + "type": "HTMLWhitespace", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "value": "42" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 31, + 39 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 40, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 42, + 51 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLTagOpen", + "range": [ + 52, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "foo" + }, + { + "type": "HTMLTagClose", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "value": "" + }, + { + "type": "VExpressionStart", + "range": [ + 57, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "count", + "start": 60, + "end": 65, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "range": [ + 60, + 65 + ] + }, + { + "type": "VExpressionEnd", + "range": [ + 66, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "value": "}}" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 68, + 73 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 31 + } + }, + "value": "foo" + }, + { + "type": "HTMLTagClose", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 32 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 74, + 84 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 42 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 42 + }, + "end": { + "line": 5, + "column": 43 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 85, + 87 + ], + "loc": { + "start": { + "line": 5, + "column": 43 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 87, + 94 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 95, + 100 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 102, + 108 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 109, + 112 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 113, + 117 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 15 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 118, + 129 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "value": "'./Foo.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 8, + "column": 27 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 134, + 139 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 141, + 142 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 142, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "value": "42" + }, + { + "type": "HTMLWhitespace", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 145, + 153 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-5/parser-options.json b/test/fixtures/ast/multiple-scripts-5/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-5/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-5/source.vue b/test/fixtures/ast/multiple-scripts-5/source.vue new file mode 100644 index 00000000..267b0f65 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-5/source.vue @@ -0,0 +1,10 @@ + + + + + diff --git a/test/fixtures/ast/multiple-scripts-5/token-ranges.json b/test/fixtures/ast/multiple-scripts-5/token-ranges.json new file mode 100644 index 00000000..5da2f7d5 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-5/token-ranges.json @@ -0,0 +1,70 @@ +[ + "", + "", + "", + "\n", + "export", + " ", + "let", + " ", + "count", + " ", + "=", + " ", + "42", + "\n", + "", + "\n\n", + "", + "", + "{{", + "count", + "}}", + "", + "", + "\n\n", + "", + "\n", + "import", + " ", + "Foo", + " ", + "from", + " ", + "'./Foo.vue'", + "\n", + "let", + " ", + "count", + " ", + "=", + " ", + "42", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-5/tree.json b/test/fixtures/ast/multiple-scripts-5/tree.json new file mode 100644 index 00000000..f84d7918 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-5/tree.json @@ -0,0 +1,45 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-6/ast.json b/test/fixtures/ast/multiple-scripts-6/ast.json new file mode 100644 index 00000000..69df8c8b --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-6/ast.json @@ -0,0 +1,581 @@ +{ + "type": "Program", + "start": 47, + "end": 98, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "range": [ + 48, + 97 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 15, + 28 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 19, + 28 + ], + "id": { + "type": "Identifier", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "range": [ + 19, + 24 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 27, + 28 + ], + "value": 0, + "raw": "0" + } + } + ], + "kind": "let" + }, + { + "type": "ExpressionStatement", + "start": 48, + "end": 73, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "range": [ + 48, + 73 + ], + "expression": { + "type": "CallExpression", + "start": 48, + "end": 73, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "range": [ + 48, + 73 + ], + "callee": { + "type": "Identifier", + "start": 48, + "end": 71, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "range": [ + 48, + 71 + ], + "name": "performGlobalSideEffect" + }, + "arguments": [] + } + }, + { + "type": "ExportNamedDeclaration", + "start": 75, + "end": 97, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "range": [ + 75, + 97 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 82, + "end": 97, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "range": [ + 82, + 97 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 88, + "end": 97, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "range": [ + 88, + 97 + ], + "id": { + "type": "Identifier", + "start": 88, + "end": 93, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "range": [ + 88, + 93 + ], + "name": "named" + }, + "init": { + "type": "Literal", + "start": 96, + "end": 97, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "range": [ + 96, + 97 + ], + "value": 1, + "raw": "1" + } + } + ], + "kind": "const" + }, + "specifiers": [], + "source": null + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 39, + 47 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-6/parser-options.json b/test/fixtures/ast/multiple-scripts-6/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-6/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-6/source.vue b/test/fixtures/ast/multiple-scripts-6/source.vue new file mode 100644 index 00000000..ecaf529b --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-6/source.vue @@ -0,0 +1,8 @@ + + diff --git a/test/fixtures/ast/multiple-scripts-6/token-ranges.json b/test/fixtures/ast/multiple-scripts-6/token-ranges.json new file mode 100644 index 00000000..fb1b1bda --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-6/token-ranges.json @@ -0,0 +1,18 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-6/tree.json b/test/fixtures/ast/multiple-scripts-6/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-6/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-7/ast.json b/test/fixtures/ast/multiple-scripts-7/ast.json new file mode 100644 index 00000000..6689eb9a --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-7/ast.json @@ -0,0 +1,2682 @@ +{ + "type": "Program", + "start": 8, + "end": 178, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "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": "ImportDeclaration", + "start": 57, + "end": 102, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 45 + } + }, + "range": [ + 57, + 102 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 64, + "end": 76, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "range": [ + 64, + 76 + ], + "local": { + "type": "Identifier", + "start": 64, + "end": 76, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "range": [ + 64, + 76 + ], + "name": "MyComponent1" + } + } + ], + "source": { + "type": "Literal", + "start": 82, + "end": 102, + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 45 + } + }, + "range": [ + 82, + 102 + ], + "value": "./MyComponent1.vue", + "raw": "'./MyComponent1.vue'" + } + }, + { + "type": "VariableDeclaration", + "start": 103, + "end": 117, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "range": [ + 103, + 117 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 107, + "end": 117, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "range": [ + 107, + 117 + ], + "id": { + "type": "Identifier", + "start": 107, + "end": 112, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "range": [ + 107, + 112 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 115, + "end": 117, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "range": [ + 115, + 117 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "let" + }, + { + "type": "ImportDeclaration", + "start": 118, + "end": 163, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 45 + } + }, + "range": [ + 118, + 163 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 125, + "end": 137, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "range": [ + 125, + 137 + ], + "local": { + "type": "Identifier", + "start": 125, + "end": 137, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "range": [ + 125, + 137 + ], + "name": "MyComponent2" + } + } + ], + "source": { + "type": "Literal", + "start": 143, + "end": 163, + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 45 + } + }, + "range": [ + 143, + 163 + ], + "value": "./MyComponent2.vue", + "raw": "'./MyComponent2.vue'" + } + }, + { + "type": "VariableDeclaration", + "start": 164, + "end": 177, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "range": [ + 164, + 177 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 168, + "end": 177, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "range": [ + 168, + 177 + ], + "id": { + "type": "Identifier", + "start": 168, + "end": 169, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "range": [ + 168, + 169 + ], + "name": "a" + }, + "init": { + "type": "BinaryExpression", + "start": 172, + "end": 177, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "range": [ + 172, + 177 + ], + "left": { + "type": "Identifier", + "start": 172, + "end": 173, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "range": [ + 172, + 173 + ], + "name": "b" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 176, + "end": 177, + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "range": [ + 176, + 177 + ], + "name": "c" + } + } + } + ], + "kind": "let" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 42, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 189, + 276 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 189, + 199 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 199, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 204, + 244 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 44 + } + }, + "name": "mycomponent1", + "rawName": "MyComponent1", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 204, + 218 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 18 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VExpressionContainer", + "range": [ + 218, + 229 + ], + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "start": 221, + "end": 226, + "loc": { + "start": { + "line": 13, + "column": 21 + }, + "end": { + "line": 13, + "column": 26 + } + }, + "range": [ + 221, + 226 + ], + "name": "count" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 221, + "end": 226, + "loc": { + "start": { + "line": 13, + "column": 21 + }, + "end": { + "line": 13, + "column": 26 + } + }, + "range": [ + 221, + 226 + ], + "name": "count" + }, + "mode": "r" + } + ] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 229, + 244 + ], + "loc": { + "start": { + "line": 13, + "column": 29 + }, + "end": { + "line": 13, + "column": 44 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 244, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 44 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 249, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "name": "mycomponent2", + "rawName": "MyComponent2", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 249, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "selfClosing": true, + "attributes": [] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 265, + 276 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "export" + }, + { + "type": "HTMLWhitespace", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "value": "42" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 31, + 39 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 40, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 42, + 49 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 50, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 57, + 63 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 64, + 76 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "value": "MyComponent1" + }, + { + "type": "HTMLWhitespace", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 77, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 82, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 45 + } + }, + "value": "'./MyComponent1.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 45 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 106 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 107, + 112 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 115, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "42" + }, + { + "type": "HTMLWhitespace", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 118, + 124 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 125, + 137 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "value": "MyComponent2" + }, + { + "type": "HTMLWhitespace", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 8, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 138, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 20 + }, + "end": { + "line": 8, + "column": 24 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 142, + 143 + ], + "loc": { + "start": { + "line": 8, + "column": 24 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 143, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 45 + } + }, + "value": "'./MyComponent2.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 163, + 164 + ], + "loc": { + "start": { + "line": 8, + "column": 45 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 164, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "value": "a" + }, + { + "type": "HTMLWhitespace", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 171, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "b" + }, + { + "type": "HTMLWhitespace", + "range": [ + 173, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": "+" + }, + { + "type": "HTMLWhitespace", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "value": "c" + }, + { + "type": "HTMLWhitespace", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 178, + 186 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 186, + 187 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 187, + 189 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 189, + 198 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 198, + 199 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 199, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 204, + 217 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 17 + } + }, + "value": "mycomponent1" + }, + { + "type": "HTMLTagClose", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 13, + "column": 17 + }, + "end": { + "line": 13, + "column": 18 + } + }, + "value": "" + }, + { + "type": "VExpressionStart", + "range": [ + 218, + 220 + ], + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 20 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "count", + "start": 221, + "end": 226, + "loc": { + "start": { + "line": 13, + "column": 21 + }, + "end": { + "line": 13, + "column": 26 + } + }, + "range": [ + 221, + 226 + ] + }, + { + "type": "VExpressionEnd", + "range": [ + 227, + 229 + ], + "loc": { + "start": { + "line": 13, + "column": 27 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "value": "}}" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 229, + 243 + ], + "loc": { + "start": { + "line": 13, + "column": 29 + }, + "end": { + "line": 13, + "column": 43 + } + }, + "value": "mycomponent1" + }, + { + "type": "HTMLTagClose", + "range": [ + 243, + 244 + ], + "loc": { + "start": { + "line": 13, + "column": 43 + }, + "end": { + "line": 13, + "column": 44 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 244, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 44 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 249, + 262 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "value": "mycomponent2" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 262, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 265, + 275 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 275, + 276 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 276, + 278 + ], + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n\n" + } + ], + "comments": [], + "errors": [ + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 249, + "lineNumber": 14, + "column": 4 + } + ] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-7/parser-options.json b/test/fixtures/ast/multiple-scripts-7/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-7/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-7/scope.json b/test/fixtures/ast/multiple-scripts-7/scope.json new file mode 100644 index 00000000..ee330a3e --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-7/scope.json @@ -0,0 +1,514 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "count", + "identifiers": [ + { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "name": "count" + }, + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + "name": "count" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + } + ] + }, + { + "name": "MyComponent1", + "identifiers": [ + { + "type": "Identifier", + "name": "MyComponent1", + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "node": { + "type": "ImportDefaultSpecifier", + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "name": "MyComponent1" + } + ], + "references": [] + }, + { + "name": "MyComponent2", + "identifiers": [ + { + "type": "Identifier", + "name": "MyComponent2", + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "node": { + "type": "ImportDefaultSpecifier", + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + "name": "MyComponent2" + } + ], + "references": [] + }, + { + "name": "a", + "identifiers": [ + { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "name": "a" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "init": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "from": "module", + "resolved": null, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "c", + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "from": "module", + "resolved": null, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "c", + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "from": "module", + "resolved": null, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "c", + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-7/source.vue b/test/fixtures/ast/multiple-scripts-7/source.vue new file mode 100644 index 00000000..3bd3b5d1 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-7/source.vue @@ -0,0 +1,16 @@ + + + + + + diff --git a/test/fixtures/ast/multiple-scripts-7/token-ranges.json b/test/fixtures/ast/multiple-scripts-7/token-ranges.json new file mode 100644 index 00000000..acbbc20c --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-7/token-ranges.json @@ -0,0 +1,105 @@ +[ + "", + "", + "", + "\n", + "export", + " ", + "let", + " ", + "count", + " ", + "=", + " ", + "42", + "\n", + "", + "\n\n", + "", + "\n", + "import", + " ", + "MyComponent1", + " ", + "from", + " ", + "'./MyComponent1.vue'", + "\n", + "let", + " ", + "count", + " ", + "=", + " ", + "42", + "\n", + "import", + " ", + "MyComponent2", + " ", + "from", + " ", + "'./MyComponent2.vue'", + "\n", + "let", + " ", + "a", + " ", + "=", + " ", + "b", + " ", + "+", + " ", + "c", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "{{", + "count", + "}}", + "", + "\n ", + "", + "\n", + "", + "\n\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-7/tree.json b/test/fixtures/ast/multiple-scripts-7/tree.json new file mode 100644 index 00000000..b3d62709 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-7/tree.json @@ -0,0 +1,71 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-2/ast.json b/test/fixtures/ast/multiple-scripts-with-ts-2/ast.json new file mode 100644 index 00000000..f9931353 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-2/ast.json @@ -0,0 +1,806 @@ +{ + "type": "Program", + "body": [ + { + "type": "ImportDeclaration", + "source": { + "type": "Literal", + "value": "./a", + "raw": "'./a'", + "range": [ + 23, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ], + "importKind": "value", + "range": [ + 9, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "Literal", + "value": "./a", + "raw": "'./a'", + "range": [ + 69, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "B", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 8 + } + } + } + ], + "importKind": "value", + "range": [ + 55, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + } + } + }, + "init": { + "type": "Literal", + "value": 42, + "raw": "42", + "range": [ + 85, + 87 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 81, + 87 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 12 + } + } + } + ], + "kind": "const", + "range": [ + 75, + 87 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "d", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + } + }, + "property": { + "type": "Identifier", + "name": "use", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 98, + 103 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 98, + 105 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 17 + } + } + }, + "range": [ + 94, + 105 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 17 + } + } + } + ], + "kind": "const", + "range": [ + 88, + 105 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 17 + } + } + } + ], + "sourceType": "module", + "range": [ + 9, + 105 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 40, + 54 + ], + "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-2/parser-options.json b/test/fixtures/ast/multiple-scripts-with-ts-2/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-2/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/multiple-scripts-with-ts-2/requirements.json b/test/fixtures/ast/multiple-scripts-with-ts-2/requirements.json new file mode 100644 index 00000000..945cf775 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-2/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-2/source.vue b/test/fixtures/ast/multiple-scripts-with-ts-2/source.vue new file mode 100644 index 00000000..c4c3f1e2 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-2/source.vue @@ -0,0 +1,9 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-with-ts-2/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-ts-2/token-ranges.json new file mode 100644 index 00000000..0570d8ea --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-2/token-ranges.json @@ -0,0 +1,26 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-2/tree.json b/test/fixtures/ast/multiple-scripts-with-ts-2/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-2/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-3/ast.json b/test/fixtures/ast/multiple-scripts-with-ts-3/ast.json new file mode 100644 index 00000000..32b118ed --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-3/ast.json @@ -0,0 +1,735 @@ +{ + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "Literal", + "value": "script", + "raw": "\"script\"", + "range": [ + 9, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "range": [ + 9, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "directive": "script" + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "Literal", + "value": "script setup", + "raw": "\"script setup\"", + "range": [ + 76, + 90 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 76, + 90 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 14 + } + } + } + ], + "sourceType": "module", + "range": [ + 9, + 90 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 61, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 29, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 29, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 39, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "Template!" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 48, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "\"script\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 18, + 26 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 29, + 38 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 39, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "Template!" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 48, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 59, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 69, + 74 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 76, + 83 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": "\"script" + }, + { + "type": "HTMLWhitespace", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 84, + 90 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "value": "setup\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 91, + 99 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-3/parser-options.json b/test/fixtures/ast/multiple-scripts-with-ts-3/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-3/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/multiple-scripts-with-ts-3/requirements.json b/test/fixtures/ast/multiple-scripts-with-ts-3/requirements.json new file mode 100644 index 00000000..945cf775 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-3/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-3/source.vue b/test/fixtures/ast/multiple-scripts-with-ts-3/source.vue new file mode 100644 index 00000000..e136f806 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-3/source.vue @@ -0,0 +1,9 @@ + + + + + diff --git a/test/fixtures/ast/multiple-scripts-with-ts-3/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-ts-3/token-ranges.json new file mode 100644 index 00000000..91b6f7d5 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-3/token-ranges.json @@ -0,0 +1,33 @@ +[ + "", + "", + "", + "\n", + "\"script\"", + "\n", + "", + "\n\n", + "", + "Template!", + "", + "\n\n", + "", + "\n", + "\"script", + " ", + "setup\"", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-3/tree.json b/test/fixtures/ast/multiple-scripts-with-ts-3/tree.json new file mode 100644 index 00000000..7cedc5f9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-3/tree.json @@ -0,0 +1,23 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-4/ast.json b/test/fixtures/ast/multiple-scripts-with-ts-4/ast.json new file mode 100644 index 00000000..ad815425 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-4/ast.json @@ -0,0 +1,843 @@ +{ + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "Literal", + "value": "script", + "raw": "\"script\"", + "range": [ + 9, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "range": [ + 9, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "directive": "script" + } + ], + "sourceType": "module", + "range": [ + 9, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 29, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 29, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 39, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "Template!" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 48, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "\"script\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 18, + 26 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 29, + 38 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 39, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "value": "Template!" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 48, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 59, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 69, + 74 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 76, + 83 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": "\"script" + }, + { + "type": "HTMLWhitespace", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 84, + 90 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "value": "setup\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 91, + 99 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 102 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 102, + 109 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 110, + 117 + ], + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "value": "unknown" + }, + { + "type": "HTMLTagClose", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 11, + "column": 15 + }, + "end": { + "line": 11, + "column": 16 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 11, + "column": 16 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 119, + 126 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "value": "\"script" + }, + { + "type": "HTMLWhitespace", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 127, + 135 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 16 + } + }, + "value": "unknown\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 136, + 144 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-4/parser-options.json b/test/fixtures/ast/multiple-scripts-with-ts-4/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-4/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/multiple-scripts-with-ts-4/requirements.json b/test/fixtures/ast/multiple-scripts-with-ts-4/requirements.json new file mode 100644 index 00000000..945cf775 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-4/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-4/source.vue b/test/fixtures/ast/multiple-scripts-with-ts-4/source.vue new file mode 100644 index 00000000..7d1a37de --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-4/source.vue @@ -0,0 +1,13 @@ + + + + + + + diff --git a/test/fixtures/ast/multiple-scripts-with-ts-4/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-ts-4/token-ranges.json new file mode 100644 index 00000000..002d3fc9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-4/token-ranges.json @@ -0,0 +1,41 @@ +[ + "", + "", + "\n", + "\"script\"", + "\n", + "", + "\n\n", + "", + "Template!", + "", + "\n\n", + "", + "\n", + "\"script", + " ", + "setup\"", + "\n", + "", + "\n\n", + "", + "\n", + "\"script", + " ", + "unknown\"", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-4/tree.json b/test/fixtures/ast/multiple-scripts-with-ts-4/tree.json new file mode 100644 index 00000000..7cedc5f9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-4/tree.json @@ -0,0 +1,23 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-5/ast.json b/test/fixtures/ast/multiple-scripts-with-ts-5/ast.json new file mode 100644 index 00000000..edd413d0 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-5/ast.json @@ -0,0 +1,1669 @@ +{ + "type": "Program", + "body": [ + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": { + "type": "Literal", + "value": 42, + "raw": "42", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "range": [ + 20, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + ], + "kind": "let", + "range": [ + 16, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "specifiers": [], + "source": null, + "exportKind": "value", + "range": [ + 9, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "Literal", + "value": "./Foo.vue", + "raw": "'./Foo.vue'", + "range": [ + 118, + 129 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 27 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Foo", + "range": [ + 109, + 112 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 10 + } + } + }, + "range": [ + 109, + 112 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 10 + } + } + } + ], + "importKind": "value", + "range": [ + 102, + 129 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 27 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 134, + 139 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "init": { + "type": "Literal", + "value": 42, + "raw": "42", + "range": [ + 142, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 14 + } + } + }, + "range": [ + 134, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 14 + } + } + } + ], + "kind": "let", + "range": [ + 130, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 14 + } + } + } + ], + "sourceType": "module", + "range": [ + 9, + 144 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 87, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 42, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 43 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 42, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VElement", + "range": [ + 52, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 32 + } + }, + "name": "foo", + "rawName": "Foo", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 52, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VExpressionContainer", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "expression": { + "type": "Identifier", + "name": "count", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + "mode": "r" + } + ] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 32 + } + } + }, + "variables": [] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 74, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 43 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "export" + }, + { + "type": "HTMLWhitespace", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "value": "42" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 31, + 39 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 40, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 42, + 51 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLTagOpen", + "range": [ + 52, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "foo" + }, + { + "type": "HTMLTagClose", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "value": "" + }, + { + "type": "VExpressionStart", + "range": [ + 57, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 60, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 66, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "value": "}}" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 68, + 73 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 31 + } + }, + "value": "foo" + }, + { + "type": "HTMLTagClose", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 32 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 74, + 84 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 42 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 42 + }, + "end": { + "line": 5, + "column": 43 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 85, + 87 + ], + "loc": { + "start": { + "line": 5, + "column": 43 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 87, + 94 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 95, + 100 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 102, + 108 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 109, + 112 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 113, + 117 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 15 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 118, + 129 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "value": "'./Foo.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 8, + "column": 27 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 134, + 139 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 141, + 142 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 142, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "value": "42" + }, + { + "type": "HTMLWhitespace", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 145, + 153 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-5/parser-options.json b/test/fixtures/ast/multiple-scripts-with-ts-5/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-5/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/multiple-scripts-with-ts-5/requirements.json b/test/fixtures/ast/multiple-scripts-with-ts-5/requirements.json new file mode 100644 index 00000000..945cf775 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-5/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-5/source.vue b/test/fixtures/ast/multiple-scripts-with-ts-5/source.vue new file mode 100644 index 00000000..267b0f65 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-5/source.vue @@ -0,0 +1,10 @@ + + + + + diff --git a/test/fixtures/ast/multiple-scripts-with-ts-5/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-ts-5/token-ranges.json new file mode 100644 index 00000000..5da2f7d5 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-5/token-ranges.json @@ -0,0 +1,70 @@ +[ + "", + "", + "", + "\n", + "export", + " ", + "let", + " ", + "count", + " ", + "=", + " ", + "42", + "\n", + "", + "\n\n", + "", + "", + "{{", + "count", + "}}", + "", + "", + "\n\n", + "", + "\n", + "import", + " ", + "Foo", + " ", + "from", + " ", + "'./Foo.vue'", + "\n", + "let", + " ", + "count", + " ", + "=", + " ", + "42", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-5/tree.json b/test/fixtures/ast/multiple-scripts-with-ts-5/tree.json new file mode 100644 index 00000000..f84d7918 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-5/tree.json @@ -0,0 +1,45 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-7/ast.json b/test/fixtures/ast/multiple-scripts-with-ts-7/ast.json new file mode 100644 index 00000000..f860e330 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/ast.json @@ -0,0 +1,2585 @@ +{ + "type": "Program", + "body": [ + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": { + "type": "Literal", + "value": 42, + "raw": "42", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "range": [ + 20, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + ], + "kind": "let", + "range": [ + 16, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "specifiers": [], + "source": null, + "exportKind": "value", + "range": [ + 9, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "Literal", + "value": "./MyComponent1.vue", + "raw": "'./MyComponent1.vue'", + "range": [ + 82, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 45 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "MyComponent1", + "range": [ + 64, + 76 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "range": [ + 64, + 76 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + ], + "importKind": "value", + "range": [ + 57, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 45 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 107, + 112 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "init": { + "type": "Literal", + "value": 42, + "raw": "42", + "range": [ + 115, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + "range": [ + 107, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 14 + } + } + } + ], + "kind": "let", + "range": [ + 103, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "Literal", + "value": "./MyComponent2.vue", + "raw": "'./MyComponent2.vue'", + "range": [ + 143, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 45 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "MyComponent2", + "range": [ + 125, + 137 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + "range": [ + 125, + 137 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + } + } + ], + "importKind": "value", + "range": [ + 118, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 45 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "init": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "Identifier", + "name": "b", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "right": { + "type": "Identifier", + "name": "c", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "range": [ + 172, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "range": [ + 168, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 13 + } + } + } + ], + "kind": "let", + "range": [ + 164, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 13 + } + } + } + ], + "sourceType": "module", + "range": [ + 9, + 177 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 42, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 189, + 276 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 189, + 199 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 199, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 204, + 244 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 44 + } + }, + "name": "mycomponent1", + "rawName": "MyComponent1", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 204, + 218 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 18 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VExpressionContainer", + "range": [ + 218, + 229 + ], + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "name": "count", + "range": [ + 221, + 226 + ], + "loc": { + "start": { + "line": 13, + "column": 21 + }, + "end": { + "line": 13, + "column": 26 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 221, + 226 + ], + "loc": { + "start": { + "line": 13, + "column": 21 + }, + "end": { + "line": 13, + "column": 26 + } + } + }, + "mode": "r" + } + ] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 229, + 244 + ], + "loc": { + "start": { + "line": 13, + "column": 29 + }, + "end": { + "line": 13, + "column": 44 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 244, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 44 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 249, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "name": "mycomponent2", + "rawName": "MyComponent2", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 249, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "selfClosing": true, + "attributes": [] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 265, + 276 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "export" + }, + { + "type": "HTMLWhitespace", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "value": "42" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 31, + 39 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 40, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 42, + 49 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 50, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 57, + 63 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 64, + 76 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "value": "MyComponent1" + }, + { + "type": "HTMLWhitespace", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 77, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 82, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 45 + } + }, + "value": "'./MyComponent1.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 45 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 106 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 107, + 112 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 115, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "42" + }, + { + "type": "HTMLWhitespace", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 118, + 124 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 125, + 137 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "value": "MyComponent2" + }, + { + "type": "HTMLWhitespace", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 8, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 138, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 20 + }, + "end": { + "line": 8, + "column": 24 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 142, + 143 + ], + "loc": { + "start": { + "line": 8, + "column": 24 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 143, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 45 + } + }, + "value": "'./MyComponent2.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 163, + 164 + ], + "loc": { + "start": { + "line": 8, + "column": 45 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 164, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "value": "a" + }, + { + "type": "HTMLWhitespace", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 171, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "b" + }, + { + "type": "HTMLWhitespace", + "range": [ + 173, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": "+" + }, + { + "type": "HTMLWhitespace", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "value": "c" + }, + { + "type": "HTMLWhitespace", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 178, + 186 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 186, + 187 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 187, + 189 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 189, + 198 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 198, + 199 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 199, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 204, + 217 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 17 + } + }, + "value": "mycomponent1" + }, + { + "type": "HTMLTagClose", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 13, + "column": 17 + }, + "end": { + "line": 13, + "column": 18 + } + }, + "value": "" + }, + { + "type": "VExpressionStart", + "range": [ + 218, + 220 + ], + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 20 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 221, + 226 + ], + "loc": { + "start": { + "line": 13, + "column": 21 + }, + "end": { + "line": 13, + "column": 26 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 227, + 229 + ], + "loc": { + "start": { + "line": 13, + "column": 27 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "value": "}}" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 229, + 243 + ], + "loc": { + "start": { + "line": 13, + "column": 29 + }, + "end": { + "line": 13, + "column": 43 + } + }, + "value": "mycomponent1" + }, + { + "type": "HTMLTagClose", + "range": [ + 243, + 244 + ], + "loc": { + "start": { + "line": 13, + "column": 43 + }, + "end": { + "line": 13, + "column": 44 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 244, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 44 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 249, + 262 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "value": "mycomponent2" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 262, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 265, + 275 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 275, + 276 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 276, + 278 + ], + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n\n" + } + ], + "comments": [], + "errors": [ + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 249, + "lineNumber": 14, + "column": 4 + } + ] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-7/parser-options.json b/test/fixtures/ast/multiple-scripts-with-ts-7/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/multiple-scripts-with-ts-7/requirements.json b/test/fixtures/ast/multiple-scripts-with-ts-7/requirements.json new file mode 100644 index 00000000..945cf775 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/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-7/scope.json b/test/fixtures/ast/multiple-scripts-with-ts-7/scope.json new file mode 100644 index 00000000..0e204975 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/scope.json @@ -0,0 +1,1319 @@ +{ + "type": "global", + "variables": [ + { + "name": "Symbol", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyKey", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDescriptor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDescriptorMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Object", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ObjectConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Function", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "FunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ThisParameterType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "OmitThisParameter", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "CallableFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NewableFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IArguments", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "String", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "StringConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Boolean", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BooleanConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Number", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NumberConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TemplateStringsArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportMeta", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Math", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Date", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DateConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpMatchArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpExecArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExp", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Error", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "EvalError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "EvalErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RangeError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RangeErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReferenceError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReferenceErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SyntaxError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SyntaxErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypeError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypeErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "URIError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "URIErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "JSON", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlyArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ConcatArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypedPropertyDescriptor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "MethodDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ParameterDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseConstructorLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Promise", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Partial", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Required", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Readonly", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Pick", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Record", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Exclude", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Extract", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Omit", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NonNullable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Parameters", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ConstructorParameters", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReturnType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "InstanceType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uppercase", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Lowercase", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Capitalize", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uncapitalize", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ThisType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBuffer", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferTypes", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferView", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DataView", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DataViewConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int8Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int8ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ClampedArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ClampedArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int16Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int16ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint16Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint16ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float64Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float64ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Intl", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Map", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "MapConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlyMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakMapConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Set", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SetConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlySet", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakSet", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakSetConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SymbolConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorYieldResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorReturnResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Iterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Iterable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IterableIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Generator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "GeneratorFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "GeneratorFunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ProxyHandler", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ProxyConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Reflect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SharedArrayBuffer", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SharedArrayBufferConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Atomics", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterableIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGenerator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGeneratorFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGeneratorFunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "const", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "count", + "identifiers": [ + { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "name": "count" + }, + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + "name": "count" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + } + ] + }, + { + "name": "MyComponent1", + "identifiers": [ + { + "type": "Identifier", + "name": "MyComponent1", + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "node": { + "type": "ImportDefaultSpecifier", + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "name": "MyComponent1" + } + ], + "references": [] + }, + { + "name": "MyComponent2", + "identifiers": [ + { + "type": "Identifier", + "name": "MyComponent2", + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "node": { + "type": "ImportDefaultSpecifier", + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + "name": "MyComponent2" + } + ], + "references": [] + }, + { + "name": "a", + "identifiers": [ + { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "name": "a" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "init": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "from": "module", + "resolved": null, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "c", + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "from": "module", + "resolved": null, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "c", + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "b", + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "from": "module", + "resolved": null, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "c", + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-7/source.vue b/test/fixtures/ast/multiple-scripts-with-ts-7/source.vue new file mode 100644 index 00000000..3bd3b5d1 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/source.vue @@ -0,0 +1,16 @@ + + + + + + diff --git a/test/fixtures/ast/multiple-scripts-with-ts-7/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-ts-7/token-ranges.json new file mode 100644 index 00000000..acbbc20c --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/token-ranges.json @@ -0,0 +1,105 @@ +[ + "", + "", + "", + "\n", + "export", + " ", + "let", + " ", + "count", + " ", + "=", + " ", + "42", + "\n", + "", + "\n\n", + "", + "\n", + "import", + " ", + "MyComponent1", + " ", + "from", + " ", + "'./MyComponent1.vue'", + "\n", + "let", + " ", + "count", + " ", + "=", + " ", + "42", + "\n", + "import", + " ", + "MyComponent2", + " ", + "from", + " ", + "'./MyComponent2.vue'", + "\n", + "let", + " ", + "a", + " ", + "=", + " ", + "b", + " ", + "+", + " ", + "c", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "{{", + "count", + "}}", + "", + "\n ", + "", + "\n", + "", + "\n\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts-7/tree.json b/test/fixtures/ast/multiple-scripts-with-ts-7/tree.json new file mode 100644 index 00000000..b3d62709 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/tree.json @@ -0,0 +1,71 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts/ast.json b/test/fixtures/ast/multiple-scripts-with-ts/ast.json new file mode 100644 index 00000000..94c84439 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts/ast.json @@ -0,0 +1,533 @@ +{ + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "performGlobalSideEffect", + "range": [ + 9, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 9, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "range": [ + 9, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "named", + "range": [ + 49, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 18 + } + } + }, + "init": { + "type": "Literal", + "value": 1, + "raw": "1", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + "range": [ + 49, + 58 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 22 + } + } + } + ], + "kind": "const", + "range": [ + 43, + 58 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + "specifiers": [], + "source": null, + "exportKind": "value", + "range": [ + 36, + 58 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 89, + 94 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + "init": { + "type": "Literal", + "value": 0, + "raw": "0", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 13 + } + } + }, + "range": [ + 89, + 98 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 13 + } + } + } + ], + "kind": "let", + "range": [ + 85, + 98 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 13 + } + } + } + ], + "sourceType": "module", + "range": [ + 9, + 98 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 70, + 84 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + } + ], + "comments": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts/parser-options.json b/test/fixtures/ast/multiple-scripts-with-ts/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/multiple-scripts-with-ts/source.vue b/test/fixtures/ast/multiple-scripts-with-ts/source.vue new file mode 100644 index 00000000..f1b3e9d4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts/source.vue @@ -0,0 +1,9 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-with-ts/token-ranges.json b/test/fixtures/ast/multiple-scripts-with-ts/token-ranges.json new file mode 100644 index 00000000..c7118715 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts/token-ranges.json @@ -0,0 +1,18 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-with-ts/tree.json b/test/fixtures/ast/multiple-scripts-with-ts/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-with-ts/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts/ast.json b/test/fixtures/ast/multiple-scripts/ast.json new file mode 100644 index 00000000..e16d8214 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts/ast.json @@ -0,0 +1,581 @@ +{ + "type": "Program", + "start": 8, + "end": 99, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "range": [ + 9, + 98 + ], + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 9, + 34 + ], + "expression": { + "type": "CallExpression", + "start": 9, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 9, + 34 + ], + "callee": { + "type": "Identifier", + "start": 9, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 9, + 32 + ], + "name": "performGlobalSideEffect" + }, + "arguments": [] + } + }, + { + "type": "ExportNamedDeclaration", + "start": 36, + "end": 58, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 22 + } + }, + "range": [ + 36, + 58 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 43, + "end": 58, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 22 + } + }, + "range": [ + 43, + 58 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 49, + "end": 58, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 22 + } + }, + "range": [ + 49, + 58 + ], + "id": { + "type": "Identifier", + "start": 49, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "range": [ + 49, + 54 + ], + "name": "named" + }, + "init": { + "type": "Literal", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 22 + } + }, + "range": [ + 57, + 58 + ], + "value": 1, + "raw": "1" + } + } + ], + "kind": "const" + }, + "specifiers": [], + "source": null + }, + { + "type": "VariableDeclaration", + "start": 85, + "end": 98, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "range": [ + 85, + 98 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 89, + "end": 98, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "range": [ + 89, + 98 + ], + "id": { + "type": "Identifier", + "start": 89, + "end": 94, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "range": [ + 89, + 94 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 97, + "end": 98, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "range": [ + 97, + 98 + ], + "value": 0, + "raw": "0" + } + } + ], + "kind": "let" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 70, + 84 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts/parser-options.json b/test/fixtures/ast/multiple-scripts/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts/source.vue b/test/fixtures/ast/multiple-scripts/source.vue new file mode 100644 index 00000000..f1b3e9d4 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts/source.vue @@ -0,0 +1,9 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts/token-ranges.json b/test/fixtures/ast/multiple-scripts/token-ranges.json new file mode 100644 index 00000000..c7118715 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts/token-ranges.json @@ -0,0 +1,18 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts/tree.json b/test/fixtures/ast/multiple-scripts/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup/ast.json b/test/fixtures/ast/script-setup/ast.json new file mode 100644 index 00000000..a946b6b1 --- /dev/null +++ b/test/fixtures/ast/script-setup/ast.json @@ -0,0 +1,223 @@ +{ + "type": "Program", + "start": 14, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 15, + 28 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 15, + 28 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 19, + 28 + ], + "id": { + "type": "Identifier", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "range": [ + 19, + 24 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 27, + 28 + ], + "value": 0, + "raw": "0" + } + } + ], + "kind": "let" + } + ], + "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/parser-options.json b/test/fixtures/ast/script-setup/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup/source.vue b/test/fixtures/ast/script-setup/source.vue new file mode 100644 index 00000000..7290631a --- /dev/null +++ b/test/fixtures/ast/script-setup/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/script-setup/token-ranges.json b/test/fixtures/ast/script-setup/token-ranges.json new file mode 100644 index 00000000..24aad52a --- /dev/null +++ b/test/fixtures/ast/script-setup/token-ranges.json @@ -0,0 +1,8 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup/tree.json b/test/fixtures/ast/script-setup/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/index.js b/test/index.js index 4ea35b5e..42b23e5a 100644 --- a/test/index.js +++ b/test/index.js @@ -643,4 +643,80 @@ describe("Basic tests", () => { assert.strictEqual(messages2[0].message, "OK") }) }) + + describe("Multiple ' + const config = { + parser: PARSER_PATH, + } + const linter = new Linter() + + linter.defineParser(PARSER_PATH, require(PARSER_PATH)) + + const messages = linter.verify(code, config) + + assert.strictEqual(messages.length, 1) + // assert.strictEqual( + // messages[0].message, + // "Parsing error: Unterminated comment" + // ) + }) + it("should notify parsing error #2", () => { + const code = "" + const config = { + parser: PARSER_PATH, + parserOptions: { + ecmaVersion: 2015, + }, + } + const linter = new Linter() + + linter.defineParser(PARSER_PATH, require(PARSER_PATH)) + + const messages = linter.verify(code, config) + + assert.strictEqual(messages.length, 1) + assert.strictEqual( + messages[0].message, + "Parsing error: Unterminated template literal" + ) + }) + it("should notify parsing error #3", () => { + const code = '' + const config = { + parser: PARSER_PATH, + } + const linter = new Linter() + + linter.defineParser(PARSER_PATH, require(PARSER_PATH)) + + const messages = linter.verify(code, config) + + assert.strictEqual(messages.length, 1) + assert.strictEqual( + messages[0].message, + "Parsing error: Unterminated string constant" + ) + }) + it("should notify 1 no-undef error", () => { + const code = + "" + const config = { + parser: PARSER_PATH, + rules: { + "no-undef": "error", + }, + } + const linter = new Linter() + + linter.defineParser(PARSER_PATH, require(PARSER_PATH)) + + const messages = linter.verify(code, config) + + assert.strictEqual(messages.length, 1) + assert.strictEqual(messages[0].message, "'c' is not defined.") + }) + }) })