From 8959c8d6d5cc7b3a1af1a3e0ae4016936286986b Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 30 Jun 2021 13:47:21 +0900 Subject: [PATCH 1/6] Supports script setup --- package.json | 9 +- scripts/update-fixtures-ast.js | 2 +- src/common/eslint-scope.ts | 25 + src/common/espree.ts | 128 + src/common/fix-locations.ts | 16 +- src/common/linter-require.ts | 43 + src/common/parser-options.ts | 2 +- src/index.ts | 11 +- src/script-setup/index.ts | 32 +- src/script-setup/parser-options.ts | 63 + src/script/espree.ts | 70 - src/script/index.ts | 23 +- src/script/scope-analyzer.ts | 7 +- src/sfc/custom-block/index.ts | 7 +- test/ast.js | 4 +- test/define-custom-blocks-visitor.js | 2 +- .../ast/dynamic-argument-dot/ast.json | 3 +- test/fixtures/ast/end-of-line01/ast.json | 4 +- test/fixtures/ast/end-of-line02/ast.json | 4 +- test/fixtures/ast/filters/ast.json | 3 +- test/fixtures/ast/link-component/ast.json | 3 +- .../fixtures/ast/multiple-scripts-10/ast.json | 259 ++ .../multiple-scripts-10/parser-options.json | 3 + .../ast/multiple-scripts-10/source.vue | 5 + .../ast/multiple-scripts-10/token-ranges.json | 10 + .../ast/multiple-scripts-10/tree.json | 1 + test/fixtures/ast/multiple-scripts-2/ast.json | 8 +- test/fixtures/ast/multiple-scripts-3/ast.json | 2 +- test/fixtures/ast/multiple-scripts-4/ast.json | 4 +- test/fixtures/ast/multiple-scripts-5/ast.json | 2 +- test/fixtures/ast/multiple-scripts-6/ast.json | 5 +- test/fixtures/ast/multiple-scripts-7/ast.json | 2 +- test/fixtures/ast/multiple-scripts-8/ast.json | 3445 ++++++++++++++ .../multiple-scripts-8/parser-options.json | 3 + .../ast/multiple-scripts-8/source.vue | 25 + .../ast/multiple-scripts-8/token-ranges.json | 142 + .../fixtures/ast/multiple-scripts-8/tree.json | 71 + test/fixtures/ast/multiple-scripts-9/ast.json | 259 ++ .../multiple-scripts-9/parser-options.json | 3 + .../ast/multiple-scripts-9/source.vue | 5 + .../ast/multiple-scripts-9/token-ranges.json | 10 + .../fixtures/ast/multiple-scripts-9/tree.json | 1 + .../ast/multiple-scripts-with-ts-7/scope.json | 102 + test/fixtures/ast/multiple-scripts/ast.json | 5 +- .../ast/script-setup-example01/ast.json | 3944 +++++++++++++++++ .../parser-options.json | 3 + .../ast/script-setup-example01/source.vue | 16 + .../script-setup-example01/token-ranges.json | 164 + .../ast/script-setup-example01/tree.json | 106 + .../ast/script-setup-example02/ast.json | 915 ++++ .../parser-options.json | 3 + .../ast/script-setup-example02/source.vue | 8 + .../script-setup-example02/token-ranges.json | 29 + .../ast/script-setup-example02/tree.json | 1 + .../ast/script-setup-example03/ast.json | 81 + .../parser-options.json | 3 + .../ast/script-setup-example03/source.vue | 3 + .../script-setup-example03/token-ranges.json | 5 + .../ast/script-setup-example03/tree.json | 1 + .../ast/script-setup-example04/ast.json | 967 ++++ .../parser-options.json | 3 + .../ast/script-setup-example04/source.vue | 7 + .../script-setup-example04/token-ranges.json | 37 + .../ast/script-setup-example04/tree.json | 55 + .../ast/script-setup-example05/ast.json | 1282 ++++++ .../parser-options.json | 3 + .../ast/script-setup-example05/source.vue | 10 + .../script-setup-example05/token-ranges.json | 49 + .../ast/script-setup-example05/tree.json | 60 + .../ast/script-setup-example06/ast.json | 1906 ++++++++ .../parser-options.json | 3 + .../ast/script-setup-example06/source.vue | 9 + .../script-setup-example06/token-ranges.json | 63 + .../ast/script-setup-example06/tree.json | 139 + .../ast/script-setup-example07/ast.json | 1122 +++++ .../parser-options.json | 3 + .../ast/script-setup-example07/source.vue | 7 + .../script-setup-example07/token-ranges.json | 45 + .../ast/script-setup-example07/tree.json | 57 + .../ast/script-setup-example08/ast.json | 895 ++++ .../parser-options.json | 3 + .../ast/script-setup-example08/source.vue | 8 + .../script-setup-example08/token-ranges.json | 28 + .../ast/script-setup-example08/tree.json | 1 + .../ast/script-setup-example09/ast.json | 825 ++++ .../parser-options.json | 3 + .../ast/script-setup-example09/source.vue | 6 + .../script-setup-example09/token-ranges.json | 24 + .../ast/script-setup-example09/tree.json | 1 + .../ast/script-setup-example10/ast.json | 1694 +++++++ .../parser-options.json | 4 + .../ast/script-setup-example10/source.vue | 11 + .../script-setup-example10/token-ranges.json | 53 + .../ast/script-setup-example10/tree.json | 1 + .../ast/script-setup-example11/ast.json | 913 ++++ .../parser-options.json | 4 + .../ast/script-setup-example11/source.vue | 9 + .../script-setup-example11/token-ranges.json | 30 + .../ast/script-setup-example11/tree.json | 1 + .../ast/script-setup-example12/ast.json | 839 ++++ .../parser-options.json | 4 + .../ast/script-setup-example12/source.vue | 3 + .../script-setup-example12/token-ranges.json | 25 + .../ast/script-setup-example12/tree.json | 1 + .../ast/script-setup-example13/ast.json | 855 ++++ .../parser-options.json | 3 + .../ast/script-setup-example13/source.vue | 9 + .../script-setup-example13/token-ranges.json | 23 + .../ast/script-setup-example13/tree.json | 1 + .../ast/script-setup-example14/ast.json | 603 +++ .../parser-options.json | 3 + .../ast/script-setup-example14/source.vue | 10 + .../script-setup-example14/token-ranges.json | 19 + .../ast/script-setup-example14/tree.json | 1 + .../ast/script-setup-example15/ast.json | 689 +++ .../parser-options.json | 3 + .../ast/script-setup-example15/source.vue | 11 + .../script-setup-example15/token-ranges.json | 24 + .../ast/script-setup-example15/tree.json | 1 + .../ast.json | 839 ++++ .../parser-options.json | 3 + .../source.vue | 3 + .../token-ranges.json | 25 + .../tree.json | 1 + test/fixtures/ast/script-setup/ast.json | 4 +- .../ast/slot-scope-destructuring/ast.json | 3 +- .../ast/svg-attrs-camel-case/ast.json | 7 +- test/fixtures/ast/svg-attrs-colon/ast.json | 7 +- test/fixtures/ast/svg-namespace/ast.json | 7 +- .../v-on-arrow-function-expression.1/ast.json | 3 +- .../v-on-arrow-function-expression.2/ast.json | 3 +- .../ast/v-on-function-expression/ast.json | 3 +- .../ast/v-on-multiple-statements/ast.json | 6 +- test/fixtures/ast/v-on-simple-path.2/ast.json | 3 +- test/fixtures/ast/v-on-simple-path.3/ast.json | 6 +- test/fixtures/ast/v-on-simple-path.4/ast.json | 3 +- typings/eslint-scope/index.d.ts | 3 +- 137 files changed, 24349 insertions(+), 163 deletions(-) create mode 100644 src/common/eslint-scope.ts create mode 100644 src/common/espree.ts create mode 100644 src/common/linter-require.ts create mode 100644 src/script-setup/parser-options.ts delete mode 100644 src/script/espree.ts create mode 100644 test/fixtures/ast/multiple-scripts-10/ast.json create mode 100644 test/fixtures/ast/multiple-scripts-10/parser-options.json create mode 100644 test/fixtures/ast/multiple-scripts-10/source.vue create mode 100644 test/fixtures/ast/multiple-scripts-10/token-ranges.json create mode 100644 test/fixtures/ast/multiple-scripts-10/tree.json create mode 100644 test/fixtures/ast/multiple-scripts-8/ast.json create mode 100644 test/fixtures/ast/multiple-scripts-8/parser-options.json create mode 100644 test/fixtures/ast/multiple-scripts-8/source.vue create mode 100644 test/fixtures/ast/multiple-scripts-8/token-ranges.json create mode 100644 test/fixtures/ast/multiple-scripts-8/tree.json create mode 100644 test/fixtures/ast/multiple-scripts-9/ast.json create mode 100644 test/fixtures/ast/multiple-scripts-9/parser-options.json create mode 100644 test/fixtures/ast/multiple-scripts-9/source.vue create mode 100644 test/fixtures/ast/multiple-scripts-9/token-ranges.json create mode 100644 test/fixtures/ast/multiple-scripts-9/tree.json create mode 100644 test/fixtures/ast/script-setup-example01/ast.json create mode 100644 test/fixtures/ast/script-setup-example01/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example01/source.vue create mode 100644 test/fixtures/ast/script-setup-example01/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example01/tree.json create mode 100644 test/fixtures/ast/script-setup-example02/ast.json create mode 100644 test/fixtures/ast/script-setup-example02/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example02/source.vue create mode 100644 test/fixtures/ast/script-setup-example02/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example02/tree.json create mode 100644 test/fixtures/ast/script-setup-example03/ast.json create mode 100644 test/fixtures/ast/script-setup-example03/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example03/source.vue create mode 100644 test/fixtures/ast/script-setup-example03/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example03/tree.json create mode 100644 test/fixtures/ast/script-setup-example04/ast.json create mode 100644 test/fixtures/ast/script-setup-example04/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example04/source.vue create mode 100644 test/fixtures/ast/script-setup-example04/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example04/tree.json create mode 100644 test/fixtures/ast/script-setup-example05/ast.json create mode 100644 test/fixtures/ast/script-setup-example05/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example05/source.vue create mode 100644 test/fixtures/ast/script-setup-example05/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example05/tree.json create mode 100644 test/fixtures/ast/script-setup-example06/ast.json create mode 100644 test/fixtures/ast/script-setup-example06/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example06/source.vue create mode 100644 test/fixtures/ast/script-setup-example06/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example06/tree.json create mode 100644 test/fixtures/ast/script-setup-example07/ast.json create mode 100644 test/fixtures/ast/script-setup-example07/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example07/source.vue create mode 100644 test/fixtures/ast/script-setup-example07/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example07/tree.json create mode 100644 test/fixtures/ast/script-setup-example08/ast.json create mode 100644 test/fixtures/ast/script-setup-example08/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example08/source.vue create mode 100644 test/fixtures/ast/script-setup-example08/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example08/tree.json create mode 100644 test/fixtures/ast/script-setup-example09/ast.json create mode 100644 test/fixtures/ast/script-setup-example09/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example09/source.vue create mode 100644 test/fixtures/ast/script-setup-example09/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example09/tree.json create mode 100644 test/fixtures/ast/script-setup-example10/ast.json create mode 100644 test/fixtures/ast/script-setup-example10/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example10/source.vue create mode 100644 test/fixtures/ast/script-setup-example10/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example10/tree.json create mode 100644 test/fixtures/ast/script-setup-example11/ast.json create mode 100644 test/fixtures/ast/script-setup-example11/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example11/source.vue create mode 100644 test/fixtures/ast/script-setup-example11/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example11/tree.json create mode 100644 test/fixtures/ast/script-setup-example12/ast.json create mode 100644 test/fixtures/ast/script-setup-example12/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example12/source.vue create mode 100644 test/fixtures/ast/script-setup-example12/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example12/tree.json create mode 100644 test/fixtures/ast/script-setup-example13/ast.json create mode 100644 test/fixtures/ast/script-setup-example13/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example13/source.vue create mode 100644 test/fixtures/ast/script-setup-example13/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example13/tree.json create mode 100644 test/fixtures/ast/script-setup-example14/ast.json create mode 100644 test/fixtures/ast/script-setup-example14/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example14/source.vue create mode 100644 test/fixtures/ast/script-setup-example14/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example14/tree.json create mode 100644 test/fixtures/ast/script-setup-example15/ast.json create mode 100644 test/fixtures/ast/script-setup-example15/parser-options.json create mode 100644 test/fixtures/ast/script-setup-example15/source.vue create mode 100644 test/fixtures/ast/script-setup-example15/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-example15/tree.json create mode 100644 test/fixtures/ast/script-setup-top-level-await-with-es2021/ast.json create mode 100644 test/fixtures/ast/script-setup-top-level-await-with-es2021/parser-options.json create mode 100644 test/fixtures/ast/script-setup-top-level-await-with-es2021/source.vue create mode 100644 test/fixtures/ast/script-setup-top-level-await-with-es2021/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-top-level-await-with-es2021/tree.json diff --git a/package.json b/package.json index 14243367..639b297d 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,12 @@ }, "dependencies": { "debug": "^4.1.1", - "eslint-scope": "^5.0.0", + "eslint-scope": "^5.1.1", "eslint-visitor-keys": "^1.1.0", - "espree": "^6.2.1", + "espree": "^8.0.0", "esquery": "^1.4.0", - "lodash": "^4.17.15" + "lodash": "^4.17.21", + "semver": "^7.3.5" }, "devDependencies": { "@mysticatea/eslint-plugin": "^13.0.0", @@ -28,6 +29,7 @@ "@types/lodash": "^4.14.120", "@types/mocha": "^5.2.4", "@types/node": "^10.12.21", + "@types/semver": "^7.3.6", "@typescript-eslint/eslint-plugin": "^4.9.1", "@typescript-eslint/parser": "^4.14.0", "babel-eslint": "^10.0.1", @@ -47,7 +49,6 @@ "rollup": "^1.1.2", "rollup-plugin-node-resolve": "^4.0.0", "rollup-plugin-sourcemaps": "^0.4.2", - "semver": "^7.3.4", "ts-node": "^8.1.0", "typescript": "~4.0.5", "wait-on": "^3.2.0", diff --git a/scripts/update-fixtures-ast.js b/scripts/update-fixtures-ast.js index 7934b4a9..11ad1d36 100644 --- a/scripts/update-fixtures-ast.js +++ b/scripts/update-fixtures-ast.js @@ -22,7 +22,7 @@ const ROOT = path.join(__dirname, "../test/fixtures/ast") const TARGETS = fs.readdirSync(ROOT) const PARSER_OPTIONS = { comment: true, - ecmaVersion: 2018, + ecmaVersion: 2022, loc: true, range: true, tokens: true, diff --git a/src/common/eslint-scope.ts b/src/common/eslint-scope.ts new file mode 100644 index 00000000..b4b1d360 --- /dev/null +++ b/src/common/eslint-scope.ts @@ -0,0 +1,25 @@ +import escope from "eslint-scope" +import { getLinterRequire } from "./linter-require" +import { lte } from "semver" + +let escopeCache: typeof escope | null = null + +/** + * Load the newest `eslint-scope` from the loaded ESLint or dependency. + */ +export function getEslintScope(): typeof escope & { + version: string +} { + if (!escopeCache) { + escopeCache = getLinterRequire()?.("eslint-scope") + if ( + !escopeCache || + escopeCache.version == null || + lte(escopeCache.version, escope.version) + ) { + escopeCache = escope + } + } + + return escopeCache +} diff --git a/src/common/espree.ts b/src/common/espree.ts new file mode 100644 index 00000000..84cec93b --- /dev/null +++ b/src/common/espree.ts @@ -0,0 +1,128 @@ +import type { ESLintExtendedProgram, ESLintProgram } from "../ast" +import type { ParserOptions } from "../common/parser-options" +import { getLinterRequire } from "./linter-require" +// @ts-expect-error -- ignore +import * as espree from "espree" +import { lte, lt } from "semver" + +/** + * The interface of a result of ESLint custom parser. + */ +export type ESLintCustomParserResult = ESLintProgram | ESLintExtendedProgram + +/** + * The interface of ESLint custom parsers. + */ +export interface ESLintCustomParser { + parse(code: string, options: any): ESLintCustomParserResult + parseForESLint?(code: string, options: any): ESLintCustomParserResult +} +type OldEspree = ESLintCustomParser & { + latestEcmaVersion?: number + version: string +} +type Espree = ESLintCustomParser & { + latestEcmaVersion: number + version: string +} +let espreeCache: OldEspree | Espree | null = null + +/** + * Gets the espree that the given ecmaVersion can parse. + */ +export function getEspreeFromEcmaVersion( + ecmaVersion: ParserOptions["ecmaVersion"], +): OldEspree | Espree { + const linterEspree = getEspreeFromLinter() + if ( + linterEspree.version != null && + lte(espree.version, linterEspree.version) + ) { + // linterEspree is newest + return linterEspree + } + if (ecmaVersion == null) { + return linterEspree + } + if (ecmaVersion === "latest") { + return espree + } + if (normalizeEcmaVersion(ecmaVersion) <= getLinterLatestEcmaVersion()) { + return linterEspree + } + return espree + + function getLinterLatestEcmaVersion() { + if (linterEspree.latestEcmaVersion == null) { + for (const { v, latest } of [ + { v: "6.1.0", latest: 2020 }, + { v: "4.0.0", latest: 2019 }, + ]) { + if (lte(v, linterEspree.version)) { + return latest + } + } + return 2018 + } + return normalizeEcmaVersion(linterEspree.latestEcmaVersion) + } +} + +/** + * Load `espree` from the loaded ESLint. + * If the loaded ESLint was not found, just returns `require("espree")`. + */ +export function getEspreeFromLinter(): Espree | OldEspree { + if (!espreeCache) { + espreeCache = getLinterRequire()?.("espree") + if (!espreeCache) { + espreeCache = espree + } + } + + return espreeCache! +} + +/** + * Load the newest `espree` from the loaded ESLint or dependency. + */ +function getNewestEspree(): Espree { + const linterEspree = getEspreeFromLinter() + if ( + linterEspree.version == null || + lte(linterEspree.version, espree.version) + ) { + return espree + } + return linterEspree as Espree +} + +export function getEcmaVersionIfUseEspree( + parserOptions: ParserOptions, +): number | undefined { + if (parserOptions.parser != null && parserOptions.parser !== "espree") { + return undefined + } + + if (parserOptions.ecmaVersion === "latest") { + return normalizeEcmaVersion(getNewestEspree().latestEcmaVersion) + } + if (parserOptions.ecmaVersion == null) { + if (lt(getEspreeFromLinter().version, "9.0.0")) { + return 5 + } + // Perhaps the version 9 will change the default to "latest". + return normalizeEcmaVersion(getNewestEspree().latestEcmaVersion) + } + return normalizeEcmaVersion(parserOptions.ecmaVersion) +} + +/** + * Normalize ECMAScript version + */ +function normalizeEcmaVersion(version: number) { + if (version > 5 && version < 2015) { + return version + 2009 + } + return version +} diff --git a/src/common/fix-locations.ts b/src/common/fix-locations.ts index 63987d39..b5e3641c 100644 --- a/src/common/fix-locations.ts +++ b/src/common/fix-locations.ts @@ -23,14 +23,14 @@ export function fixLocations( ): void { // There are cases which the same node instance appears twice in the tree. // E.g. `let {a} = {}` // This `a` appears twice at `Property#key` and `Property#value`. - const traversed = new Set() + const traversed = new Map() traverseNodes(result.ast, { visitorKeys: result.visitorKeys, enterNode(node, parent) { if (!traversed.has(node)) { - traversed.add(node) + traversed.set(node, node) node.parent = parent // `babel-eslint@8` has shared `Node#range` with multiple nodes. @@ -45,12 +45,18 @@ export function fixLocations( node.loc.end = locationCalculator.getLocFromIndex( node.range[1], ) - traversed.add(node.loc) + traversed.set(node.loc, node) + } else if (node.start != null || node.end != null) { + const traversedNode = traversed.get(node.range)! + if (traversedNode.type === node.type) { + node.start = traversedNode.start + node.end = traversedNode.end + } } } else { fixLocation(node, locationCalculator) - traversed.add(node.range) - traversed.add(node.loc) + traversed.set(node.range, node) + traversed.set(node.loc, node) } } }, diff --git a/src/common/linter-require.ts b/src/common/linter-require.ts new file mode 100644 index 00000000..22cd8526 --- /dev/null +++ b/src/common/linter-require.ts @@ -0,0 +1,43 @@ +import Module from "module" +import path from "path" + +const createRequire: (filename: string) => (modname: string) => any = + // Added in v12.2.0 + (Module as any).createRequire || + // Added in v10.12.0, but deprecated in v12.2.0. + // eslint-disable-next-line @mysticatea/node/no-deprecated-api + Module.createRequireFromPath || + // Polyfill - This is not executed on the tests on node@>=10. + /* istanbul ignore next */ + ((modname) => { + const mod = new Module(modname) + + mod.filename = modname + mod.paths = (Module as any)._nodeModulePaths(path.dirname(modname)) + ;(mod as any)._compile("module.exports = require;", modname) + return mod.exports + }) + +function isLinterPath(p: string): boolean { + return ( + // ESLint 6 and above + p.includes( + `eslint${path.sep}lib${path.sep}linter${path.sep}linter.js`, + ) || + // ESLint 5 + p.includes(`eslint${path.sep}lib${path.sep}linter.js`) + ) +} + +export function getLinterRequire() { + // Lookup the loaded eslint + const linterPath = Object.keys(require.cache).find(isLinterPath) + if (linterPath) { + try { + return createRequire(linterPath) + } catch { + // ignore + } + } + return null +} diff --git a/src/common/parser-options.ts b/src/common/parser-options.ts index 7f5dadfe..8ff00ee1 100644 --- a/src/common/parser-options.ts +++ b/src/common/parser-options.ts @@ -9,7 +9,7 @@ export interface ParserOptions { } // espree options - ecmaVersion?: number + ecmaVersion?: number | "latest" sourceType?: "script" | "module" ecmaFeatures?: { [key: string]: any } diff --git a/src/index.ts b/src/index.ts index 3918694f..c5b47e07 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,7 @@ 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 { isScriptSetup, parseScriptSetupElements } from "./script-setup" import { LinesAndColumns } from "./common/lines-and-columns" import type { VElement } from "./ast" @@ -71,15 +71,6 @@ function getLang( return lang || defaultLang } -/** - * Checks whether the given script element is `" + }, + { + "type": "Punctuator", + "range": [ + 34, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-10/parser-options.json b/test/fixtures/ast/multiple-scripts-10/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-10/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-10/source.vue b/test/fixtures/ast/multiple-scripts-10/source.vue new file mode 100644 index 00000000..9765b0b9 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-10/source.vue @@ -0,0 +1,5 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-10/token-ranges.json b/test/fixtures/ast/multiple-scripts-10/token-ranges.json new file mode 100644 index 00000000..0ede0b05 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-10/token-ranges.json @@ -0,0 +1,10 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-10/tree.json b/test/fixtures/ast/multiple-scripts-10/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-10/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-2/ast.json b/test/fixtures/ast/multiple-scripts-2/ast.json index 4bd6d24c..86f3e690 100644 --- a/test/fixtures/ast/multiple-scripts-2/ast.json +++ b/test/fixtures/ast/multiple-scripts-2/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 8, + "start": 9, "end": 106, "loc": { "start": { @@ -394,9 +394,11 @@ ], "name": "use" }, - "computed": false + "computed": false, + "optional": false }, - "arguments": [] + "arguments": [], + "optional": false } } ], diff --git a/test/fixtures/ast/multiple-scripts-3/ast.json b/test/fixtures/ast/multiple-scripts-3/ast.json index 85552110..82eb0fa4 100644 --- a/test/fixtures/ast/multiple-scripts-3/ast.json +++ b/test/fixtures/ast/multiple-scripts-3/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 8, + "start": 9, "end": 91, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-4/ast.json b/test/fixtures/ast/multiple-scripts-4/ast.json index 84d2d8cf..03a1f108 100644 --- a/test/fixtures/ast/multiple-scripts-4/ast.json +++ b/test/fixtures/ast/multiple-scripts-4/ast.json @@ -1,7 +1,7 @@ { "type": "Program", - "start": 8, - "end": 18, + "start": 9, + "end": 17, "loc": { "start": { "line": 2, diff --git a/test/fixtures/ast/multiple-scripts-5/ast.json b/test/fixtures/ast/multiple-scripts-5/ast.json index 0c0ff3e9..2eb697cd 100644 --- a/test/fixtures/ast/multiple-scripts-5/ast.json +++ b/test/fixtures/ast/multiple-scripts-5/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 8, + "start": 9, "end": 145, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-6/ast.json b/test/fixtures/ast/multiple-scripts-6/ast.json index 69df8c8b..4c6b2507 100644 --- a/test/fixtures/ast/multiple-scripts-6/ast.json +++ b/test/fixtures/ast/multiple-scripts-6/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 47, + "start": 48, "end": 98, "loc": { "start": { @@ -155,7 +155,8 @@ ], "name": "performGlobalSideEffect" }, - "arguments": [] + "arguments": [], + "optional": false } }, { diff --git a/test/fixtures/ast/multiple-scripts-7/ast.json b/test/fixtures/ast/multiple-scripts-7/ast.json index 6689eb9a..b8cf33d6 100644 --- a/test/fixtures/ast/multiple-scripts-7/ast.json +++ b/test/fixtures/ast/multiple-scripts-7/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 8, + "start": 9, "end": 178, "loc": { "start": { diff --git a/test/fixtures/ast/multiple-scripts-8/ast.json b/test/fixtures/ast/multiple-scripts-8/ast.json new file mode 100644 index 00000000..c11f7b77 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-8/ast.json @@ -0,0 +1,3445 @@ +{ + "type": "Program", + "start": 20, + "end": 340, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 17, + "column": 13 + } + }, + "range": [ + 20, + 316 + ], + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 20, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "range": [ + 20, + 62 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 27, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "range": [ + 27, + 62 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 31, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "range": [ + 31, + 41 + ], + "id": { + "type": "Identifier", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "range": [ + 31, + 36 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "range": [ + 39, + 41 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "let" + }, + "specifiers": [], + "source": null + }, + { + "type": "VariableDeclaration", + "start": 100, + "end": 108, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "range": [ + 100, + 108 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 104, + "end": 107, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "range": [ + 104, + 107 + ], + "id": { + "type": "Identifier", + "start": 104, + "end": 107, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "range": [ + 104, + 107 + ], + "name": "foo" + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "ImportDeclaration", + "start": 130, + "end": 175, + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 45 + } + }, + "range": [ + 130, + 175 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 137, + "end": 149, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 19 + } + }, + "range": [ + 137, + 149 + ], + "local": { + "type": "Identifier", + "start": 137, + "end": 149, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 19 + } + }, + "range": [ + 137, + 149 + ], + "name": "MyComponent1" + } + } + ], + "source": { + "type": "Literal", + "start": 155, + "end": 175, + "loc": { + "start": { + "line": 11, + "column": 25 + }, + "end": { + "line": 11, + "column": 45 + } + }, + "range": [ + 155, + 175 + ], + "value": "./MyComponent1.vue", + "raw": "'./MyComponent1.vue'" + } + }, + { + "type": "VariableDeclaration", + "start": 197, + "end": 233, + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "range": [ + 197, + 233 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 201, + "end": 211, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 14 + } + }, + "range": [ + 201, + 211 + ], + "id": { + "type": "Identifier", + "start": 201, + "end": 206, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "range": [ + 201, + 206 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 209, + "end": 211, + "loc": { + "start": { + "line": 13, + "column": 12 + }, + "end": { + "line": 13, + "column": 14 + } + }, + "range": [ + 209, + 211 + ], + "value": 42, + "raw": "42" + } + } + ], + "kind": "let" + }, + { + "type": "ImportDeclaration", + "start": 234, + "end": 279, + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 45 + } + }, + "range": [ + 234, + 279 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 241, + "end": 253, + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 19 + } + }, + "range": [ + 241, + 253 + ], + "local": { + "type": "Identifier", + "start": 241, + "end": 253, + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 19 + } + }, + "range": [ + 241, + 253 + ], + "name": "MyComponent2" + } + } + ], + "source": { + "type": "Literal", + "start": 259, + "end": 279, + "loc": { + "start": { + "line": 15, + "column": 25 + }, + "end": { + "line": 15, + "column": 45 + } + }, + "range": [ + 259, + 279 + ], + "value": "./MyComponent2.vue", + "raw": "'./MyComponent2.vue'" + } + }, + { + "type": "VariableDeclaration", + "start": 303, + "end": 316, + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 13 + } + }, + "range": [ + 303, + 316 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 307, + "end": 316, + "loc": { + "start": { + "line": 17, + "column": 4 + }, + "end": { + "line": 17, + "column": 13 + } + }, + "range": [ + 307, + 316 + ], + "id": { + "type": "Identifier", + "start": 307, + "end": 308, + "loc": { + "start": { + "line": 17, + "column": 4 + }, + "end": { + "line": 17, + "column": 5 + } + }, + "range": [ + 307, + 308 + ], + "name": "a" + }, + "init": { + "type": "BinaryExpression", + "start": 311, + "end": 316, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 13 + } + }, + "range": [ + 311, + 316 + ], + "left": { + "type": "Identifier", + "start": 311, + "end": 312, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 9 + } + }, + "range": [ + 311, + 312 + ], + "name": "b" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 315, + "end": 316, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 13 + } + }, + "range": [ + 315, + 316 + ], + "name": "c" + } + } + } + ], + "kind": "let" + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": "comment1", + "start": 9, + "end": 19, + "range": [ + 9, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Line", + "value": "comment2", + "start": 41, + "end": 51, + "range": [ + 41, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + { + "type": "Line", + "value": "comment3", + "start": 52, + "end": 62, + "range": [ + 52, + 62 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 10 + } + } + }, + { + "type": "Line", + "value": "comment4", + "start": 89, + "end": 99, + "range": [ + 89, + 99 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 10 + } + } + }, + { + "type": "Line", + "value": "comment5", + "start": 108, + "end": 118, + "range": [ + 108, + 118 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 18 + } + } + }, + { + "type": "Line", + "value": "comment6", + "start": 119, + "end": 129, + "range": [ + 119, + 129 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 10 + } + } + }, + { + "type": "Line", + "value": "comment7", + "start": 175, + "end": 185, + "range": [ + 175, + 185 + ], + "loc": { + "start": { + "line": 11, + "column": 45 + }, + "end": { + "line": 11, + "column": 55 + } + } + }, + { + "type": "Line", + "value": "comment8", + "start": 186, + "end": 196, + "range": [ + 186, + 196 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 10 + } + } + }, + { + "type": "Line", + "value": "comment9", + "start": 211, + "end": 221, + "range": [ + 211, + 221 + ], + "loc": { + "start": { + "line": 13, + "column": 14 + }, + "end": { + "line": 13, + "column": 24 + } + } + }, + { + "type": "Line", + "value": "comment10", + "start": 222, + "end": 233, + "range": [ + 222, + 233 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 11 + } + } + }, + { + "type": "Line", + "value": "comment11", + "start": 279, + "end": 290, + "range": [ + 279, + 290 + ], + "loc": { + "start": { + "line": 15, + "column": 45 + }, + "end": { + "line": 15, + "column": 56 + } + } + }, + { + "type": "Line", + "value": "comment12", + "start": 291, + "end": 302, + "range": [ + 291, + 302 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "Line", + "value": "comment13", + "start": 316, + "end": 327, + "range": [ + 316, + 327 + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + { + "type": "Line", + "value": "comment14", + "start": 328, + "end": 339, + "range": [ + 328, + 339 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 11 + } + } + } + ], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 74, + 88 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 351, + 438 + ], + "loc": { + "start": { + "line": 21, + "column": 0 + }, + "end": { + "line": 24, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 351, + 361 + ], + "loc": { + "start": { + "line": 21, + "column": 0 + }, + "end": { + "line": 21, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 361, + 366 + ], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 22, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 366, + 406 + ], + "loc": { + "start": { + "line": 22, + "column": 4 + }, + "end": { + "line": 22, + "column": 44 + } + }, + "name": "mycomponent1", + "rawName": "MyComponent1", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 366, + 380 + ], + "loc": { + "start": { + "line": 22, + "column": 4 + }, + "end": { + "line": 22, + "column": 18 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VExpressionContainer", + "range": [ + 380, + 391 + ], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "start": 383, + "end": 388, + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 26 + } + }, + "range": [ + 383, + 388 + ], + "name": "count" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 383, + "end": 388, + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 26 + } + }, + "range": [ + 383, + 388 + ], + "name": "count" + }, + "mode": "r" + } + ] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 391, + 406 + ], + "loc": { + "start": { + "line": 22, + "column": 29 + }, + "end": { + "line": 22, + "column": 44 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 406, + 411 + ], + "loc": { + "start": { + "line": 22, + "column": 44 + }, + "end": { + "line": 23, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 411, + 426 + ], + "loc": { + "start": { + "line": 23, + "column": 4 + }, + "end": { + "line": 23, + "column": 19 + } + }, + "name": "mycomponent2", + "rawName": "MyComponent2", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 411, + 426 + ], + "loc": { + "start": { + "line": 23, + "column": 4 + }, + "end": { + "line": 23, + "column": 19 + } + }, + "selfClosing": true, + "attributes": [] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 426, + 427 + ], + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 24, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 427, + 438 + ], + "loc": { + "start": { + "line": 24, + "column": 0 + }, + "end": { + "line": 24, + "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, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": "//comment1" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 20, + 26 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "value": "export" + }, + { + "type": "HTMLWhitespace", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 31, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 39, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "value": "42//comment2" + }, + { + "type": "HTMLWhitespace", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 52, + 62 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "value": "//comment3" + }, + { + "type": "HTMLWhitespace", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 63, + 71 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 72, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 74, + 81 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 89, + 99 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "//comment4" + }, + { + "type": "HTMLWhitespace", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 104, + 118 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "value": "foo;//comment5" + }, + { + "type": "HTMLWhitespace", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 119, + 129 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 10 + } + }, + "value": "//comment6" + }, + { + "type": "HTMLWhitespace", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 130, + 136 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 137, + 149 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 19 + } + }, + "value": "MyComponent1" + }, + { + "type": "HTMLWhitespace", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 11, + "column": 19 + }, + "end": { + "line": 11, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 150, + 154 + ], + "loc": { + "start": { + "line": 11, + "column": 20 + }, + "end": { + "line": 11, + "column": 24 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 11, + "column": 24 + }, + "end": { + "line": 11, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 155, + 185 + ], + "loc": { + "start": { + "line": 11, + "column": 25 + }, + "end": { + "line": 11, + "column": 55 + } + }, + "value": "'./MyComponent1.vue'//comment7" + }, + { + "type": "HTMLWhitespace", + "range": [ + 185, + 186 + ], + "loc": { + "start": { + "line": 11, + "column": 55 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 186, + 196 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "value": "//comment8" + }, + { + "type": "HTMLWhitespace", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 197, + 200 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 200, + 201 + ], + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 201, + 206 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 206, + 207 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 207, + 208 + ], + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 13, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 208, + 209 + ], + "loc": { + "start": { + "line": 13, + "column": 11 + }, + "end": { + "line": 13, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 209, + 221 + ], + "loc": { + "start": { + "line": 13, + "column": 12 + }, + "end": { + "line": 13, + "column": 24 + } + }, + "value": "42//comment9" + }, + { + "type": "HTMLWhitespace", + "range": [ + 221, + 222 + ], + "loc": { + "start": { + "line": 13, + "column": 24 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 222, + 233 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "value": "//comment10" + }, + { + "type": "HTMLWhitespace", + "range": [ + 233, + 234 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 234, + 240 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 6 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 240, + 241 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 241, + 253 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 19 + } + }, + "value": "MyComponent2" + }, + { + "type": "HTMLWhitespace", + "range": [ + 253, + 254 + ], + "loc": { + "start": { + "line": 15, + "column": 19 + }, + "end": { + "line": 15, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 254, + 258 + ], + "loc": { + "start": { + "line": 15, + "column": 20 + }, + "end": { + "line": 15, + "column": 24 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 258, + 259 + ], + "loc": { + "start": { + "line": 15, + "column": 24 + }, + "end": { + "line": 15, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 259, + 290 + ], + "loc": { + "start": { + "line": 15, + "column": 25 + }, + "end": { + "line": 15, + "column": 56 + } + }, + "value": "'./MyComponent2.vue'//comment11" + }, + { + "type": "HTMLWhitespace", + "range": [ + 290, + 291 + ], + "loc": { + "start": { + "line": 15, + "column": 56 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 291, + 302 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "//comment12" + }, + { + "type": "HTMLWhitespace", + "range": [ + 302, + 303 + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 303, + 306 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 306, + 307 + ], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 307, + 308 + ], + "loc": { + "start": { + "line": 17, + "column": 4 + }, + "end": { + "line": 17, + "column": 5 + } + }, + "value": "a" + }, + { + "type": "HTMLWhitespace", + "range": [ + 308, + 309 + ], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 309, + 310 + ], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 7 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 310, + 311 + ], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 311, + 312 + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 9 + } + }, + "value": "b" + }, + { + "type": "HTMLWhitespace", + "range": [ + 312, + 313 + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 313, + 314 + ], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + }, + "value": "+" + }, + { + "type": "HTMLWhitespace", + "range": [ + 314, + 315 + ], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 315, + 327 + ], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 24 + } + }, + "value": "c//comment13" + }, + { + "type": "HTMLWhitespace", + "range": [ + 327, + 328 + ], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 328, + 339 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 11 + } + }, + "value": "//comment14" + }, + { + "type": "HTMLWhitespace", + "range": [ + 339, + 340 + ], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 340, + 348 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 348, + 349 + ], + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 349, + 351 + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 21, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 351, + 360 + ], + "loc": { + "start": { + "line": 21, + "column": 0 + }, + "end": { + "line": 21, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 360, + 361 + ], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 361, + 366 + ], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 22, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 366, + 379 + ], + "loc": { + "start": { + "line": 22, + "column": 4 + }, + "end": { + "line": 22, + "column": 17 + } + }, + "value": "mycomponent1" + }, + { + "type": "HTMLTagClose", + "range": [ + 379, + 380 + ], + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 18 + } + }, + "value": "" + }, + { + "type": "VExpressionStart", + "range": [ + 380, + 382 + ], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 20 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "count", + "start": 383, + "end": 388, + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 26 + } + }, + "range": [ + 383, + 388 + ] + }, + { + "type": "VExpressionEnd", + "range": [ + 389, + 391 + ], + "loc": { + "start": { + "line": 22, + "column": 27 + }, + "end": { + "line": 22, + "column": 29 + } + }, + "value": "}}" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 391, + 405 + ], + "loc": { + "start": { + "line": 22, + "column": 29 + }, + "end": { + "line": 22, + "column": 43 + } + }, + "value": "mycomponent1" + }, + { + "type": "HTMLTagClose", + "range": [ + 405, + 406 + ], + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 44 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 406, + 411 + ], + "loc": { + "start": { + "line": 22, + "column": 44 + }, + "end": { + "line": 23, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 411, + 424 + ], + "loc": { + "start": { + "line": 23, + "column": 4 + }, + "end": { + "line": 23, + "column": 17 + } + }, + "value": "mycomponent2" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 424, + 426 + ], + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 426, + 427 + ], + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 24, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 427, + 437 + ], + "loc": { + "start": { + "line": 24, + "column": 0 + }, + "end": { + "line": 24, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 437, + 438 + ], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 438, + 440 + ], + "loc": { + "start": { + "line": 24, + "column": 11 + }, + "end": { + "line": 26, + "column": 0 + } + }, + "value": "\n\n" + } + ], + "comments": [], + "errors": [ + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 411, + "lineNumber": 23, + "column": 4 + } + ] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-8/parser-options.json b/test/fixtures/ast/multiple-scripts-8/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-8/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-8/source.vue b/test/fixtures/ast/multiple-scripts-8/source.vue new file mode 100644 index 00000000..64663ded --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-8/source.vue @@ -0,0 +1,25 @@ + + + + + + diff --git a/test/fixtures/ast/multiple-scripts-8/token-ranges.json b/test/fixtures/ast/multiple-scripts-8/token-ranges.json new file mode 100644 index 00000000..69888352 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-8/token-ranges.json @@ -0,0 +1,142 @@ +[ + "", + "", + "//comment1", + "//comment2", + "//comment3", + "//comment4", + "//comment5", + "//comment6", + "//comment7", + "//comment8", + "//comment9", + "//comment10", + "//comment11", + "//comment12", + "//comment13", + "//comment14", + "", + "\n", + "//comment1", + "\n", + "export", + " ", + "let", + " ", + "count", + " ", + "=", + " ", + "42//comment2", + "\n", + "//comment3", + "\n", + "", + "\n\n", + "", + "\n", + "//comment4", + "\n", + "let", + " ", + "foo;//comment5", + "\n", + "//comment6", + "\n", + "import", + " ", + "MyComponent1", + " ", + "from", + " ", + "'./MyComponent1.vue'//comment7", + "\n", + "//comment8", + "\n", + "let", + " ", + "count", + " ", + "=", + " ", + "42//comment9", + "\n", + "//comment10", + "\n", + "import", + " ", + "MyComponent2", + " ", + "from", + " ", + "'./MyComponent2.vue'//comment11", + "\n", + "//comment12", + "\n", + "let", + " ", + "a", + " ", + "=", + " ", + "b", + " ", + "+", + " ", + "c//comment13", + "\n", + "//comment14", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "{{", + "count", + "}}", + "", + "\n ", + "", + "\n", + "", + "\n\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-8/tree.json b/test/fixtures/ast/multiple-scripts-8/tree.json new file mode 100644 index 00000000..b3d62709 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-8/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-9/ast.json b/test/fixtures/ast/multiple-scripts-9/ast.json new file mode 100644 index 00000000..685d774d --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-9/ast.json @@ -0,0 +1,259 @@ +{ + "type": "Program", + "start": 31, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "range": [ + 31, + 47 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 34, + "end": 47, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "range": [ + 34, + 47 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 38, + "end": 47, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "range": [ + 38, + 47 + ], + "id": { + "type": "Identifier", + "start": 38, + "end": 43, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "range": [ + 38, + 43 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "range": [ + 46, + 47 + ], + "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": [ + 19, + 33 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-9/parser-options.json b/test/fixtures/ast/multiple-scripts-9/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-9/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/multiple-scripts-9/source.vue b/test/fixtures/ast/multiple-scripts-9/source.vue new file mode 100644 index 00000000..90521f52 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-9/source.vue @@ -0,0 +1,5 @@ + + + diff --git a/test/fixtures/ast/multiple-scripts-9/token-ranges.json b/test/fixtures/ast/multiple-scripts-9/token-ranges.json new file mode 100644 index 00000000..1530a12e --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-9/token-ranges.json @@ -0,0 +1,10 @@ +[ + "", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/multiple-scripts-9/tree.json b/test/fixtures/ast/multiple-scripts-9/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/multiple-scripts-9/tree.json @@ -0,0 +1 @@ +[] \ 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 index 0e204975..100fd2f6 100644 --- a/test/fixtures/ast/multiple-scripts-with-ts-7/scope.json +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/scope.json @@ -799,6 +799,108 @@ "defs": [], "references": [] }, + { + "name": "FlatArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BigIntToLocaleStringOptions", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BigInt", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BigIntConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BigInt64Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BigInt64ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BigUint64Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BigUint64ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseFulfilledResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseRejectedResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseSettledResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AggregateError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AggregateErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakRef", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakRefConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "FinalizationRegistry", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "FinalizationRegistryConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, { "name": "const", "identifiers": [], diff --git a/test/fixtures/ast/multiple-scripts/ast.json b/test/fixtures/ast/multiple-scripts/ast.json index e16d8214..b55bc2c0 100644 --- a/test/fixtures/ast/multiple-scripts/ast.json +++ b/test/fixtures/ast/multiple-scripts/ast.json @@ -1,6 +1,6 @@ { "type": "Program", - "start": 8, + "start": 9, "end": 99, "loc": { "start": { @@ -73,7 +73,8 @@ ], "name": "performGlobalSideEffect" }, - "arguments": [] + "arguments": [], + "optional": false } }, { diff --git a/test/fixtures/ast/script-setup-example01/ast.json b/test/fixtures/ast/script-setup-example01/ast.json new file mode 100644 index 00000000..e4d8d462 --- /dev/null +++ b/test/fixtures/ast/script-setup-example01/ast.json @@ -0,0 +1,3944 @@ +{ + "type": "Program", + "start": 79, + "end": 311, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "range": [ + 79, + 311 + ], + "body": [ + { + "type": "ImportDeclaration", + "start": 79, + "end": 106, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "range": [ + 79, + 106 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 86, + "end": 89, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "range": [ + 86, + 89 + ], + "local": { + "type": "Identifier", + "start": 86, + "end": 89, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "range": [ + 86, + 89 + ], + "name": "Foo" + } + } + ], + "source": { + "type": "Literal", + "start": 95, + "end": 106, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "range": [ + 95, + 106 + ], + "value": "./Foo.vue", + "raw": "'./Foo.vue'" + } + }, + { + "type": "ImportDeclaration", + "start": 109, + "end": 134, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "range": [ + 109, + 134 + ], + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 118, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "range": [ + 118, + 121 + ], + "imported": { + "type": "Identifier", + "start": 118, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "range": [ + 118, + 121 + ], + "name": "ref" + }, + "local": { + "type": "Identifier", + "start": 118, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "range": [ + 118, + 121 + ], + "name": "ref" + } + } + ], + "source": { + "type": "Literal", + "start": 129, + "end": 134, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "range": [ + 129, + 134 + ], + "value": "vue", + "raw": "'vue'" + } + }, + { + "type": "VariableDeclaration", + "start": 247, + "end": 267, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "range": [ + 247, + 267 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 253, + "end": 267, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "range": [ + 253, + 267 + ], + "id": { + "type": "Identifier", + "start": 253, + "end": 258, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "range": [ + 253, + 258 + ], + "name": "count" + }, + "init": { + "type": "CallExpression", + "start": 261, + "end": 267, + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "range": [ + 261, + 267 + ], + "callee": { + "type": "Identifier", + "start": 261, + "end": 264, + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "range": [ + 261, + 264 + ], + "name": "ref" + }, + "arguments": [ + { + "type": "Literal", + "start": 265, + "end": 266, + "loc": { + "start": { + "line": 8, + "column": 20 + }, + "end": { + "line": 8, + "column": 21 + } + }, + "range": [ + 265, + 266 + ], + "value": 0, + "raw": "0" + } + ], + "optional": false + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 270, + "end": 311, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "range": [ + 270, + 311 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 276, + "end": 311, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "range": [ + 276, + 311 + ], + "id": { + "type": "Identifier", + "start": 276, + "end": 279, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "range": [ + 276, + 279 + ], + "name": "inc" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 282, + "end": 311, + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "range": [ + 282, + 311 + ], + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 288, + "end": 311, + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "range": [ + 288, + 311 + ], + "body": [ + { + "type": "ExpressionStatement", + "start": 294, + "end": 307, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 17 + } + }, + "range": [ + 294, + 307 + ], + "expression": { + "type": "UpdateExpression", + "start": 294, + "end": 307, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 17 + } + }, + "range": [ + 294, + 307 + ], + "operator": "++", + "prefix": false, + "argument": { + "type": "MemberExpression", + "start": 294, + "end": 305, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "range": [ + 294, + 305 + ], + "object": { + "type": "Identifier", + "start": 294, + "end": 299, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "range": [ + 294, + 299 + ], + "name": "count" + }, + "property": { + "type": "Identifier", + "start": 300, + "end": 305, + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "range": [ + 300, + 305 + ], + "name": "value" + }, + "computed": false, + "optional": false + } + } + } + ] + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " imported components are also directly usable in template", + "start": 17, + "end": 76, + "range": [ + 17, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 61 + } + } + }, + { + "type": "Line", + "value": " write Composition API code just like in a normal setup()", + "start": 138, + "end": 197, + "range": [ + 138, + 197 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 61 + } + } + }, + { + "type": "Line", + "value": " but no need to manually return everything", + "start": 200, + "end": 244, + "range": [ + 200, + 244 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 46 + } + } + } + ], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 323, + 383 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 323, + 333 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 333, + 336 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 336, + 371 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 37 + } + }, + "name": "foo", + "rawName": "Foo", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 336, + 371 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 37 + } + }, + "selfClosing": true, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 341, + 355 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 21 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 341, + 347 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 13 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 341, + 342 + ], + "loc": { + "start": { + "column": 7, + "line": 15 + }, + "end": { + "column": 8, + "line": 15 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 342, + 347 + ], + "loc": { + "start": { + "column": 8, + "line": 15 + }, + "end": { + "column": 13, + "line": 15 + } + }, + "name": "count", + "rawName": "count" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 348, + 355 + ], + "loc": { + "start": { + "line": 15, + "column": 14 + }, + "end": { + "line": 15, + "column": 21 + } + }, + "expression": { + "type": "Identifier", + "start": 349, + "end": 354, + "loc": { + "start": { + "line": 15, + "column": 15 + }, + "end": { + "line": 15, + "column": 20 + } + }, + "range": [ + 349, + 354 + ], + "name": "count" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 349, + "end": 354, + "loc": { + "start": { + "line": 15, + "column": 15 + }, + "end": { + "line": 15, + "column": 20 + } + }, + "range": [ + 349, + 354 + ], + "name": "count" + }, + "mode": "r" + } + ] + } + }, + { + "type": "VAttribute", + "range": [ + 356, + 368 + ], + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 356, + 362 + ], + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 28 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 356, + 357 + ], + "loc": { + "start": { + "column": 22, + "line": 15 + }, + "end": { + "column": 23, + "line": 15 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 357, + 362 + ], + "loc": { + "start": { + "column": 23, + "line": 15 + }, + "end": { + "column": 28, + "line": 15 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 363, + 368 + ], + "loc": { + "start": { + "line": 15, + "column": 29 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "expression": { + "type": "Identifier", + "start": 364, + "end": 367, + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 33 + } + }, + "range": [ + 364, + 367 + ], + "name": "inc" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 364, + "end": 367, + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 33 + } + }, + "range": [ + 364, + 367 + ], + "name": "inc" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 371, + 372 + ], + "loc": { + "start": { + "line": 15, + "column": 37 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 372, + 383 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 20, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": "imported" + }, + { + "type": "HTMLWhitespace", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 29, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "value": "components" + }, + { + "type": "HTMLWhitespace", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 40, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "value": "are" + }, + { + "type": "HTMLWhitespace", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 44, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "value": "also" + }, + { + "type": "HTMLWhitespace", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 49, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "value": "directly" + }, + { + "type": "HTMLWhitespace", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 58, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "value": "usable" + }, + { + "type": "HTMLWhitespace", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 49 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 65, + 67 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 2, + "column": 52 + } + }, + "value": "in" + }, + { + "type": "HTMLWhitespace", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 2, + "column": 52 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 68, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 61 + } + }, + "value": "template" + }, + { + "type": "HTMLWhitespace", + "range": [ + 76, + 79 + ], + "loc": { + "start": { + "line": 2, + "column": 61 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 86, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 90, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 95, + 106 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "value": "'./Foo.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 106, + 109 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 109, + 115 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 118, + 121 + ], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "value": "ref" + }, + { + "type": "HTMLWhitespace", + "range": [ + 121, + 122 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 122, + 123 + ], + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 123, + 124 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 124, + 128 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 21 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 22 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 129, + 134 + ], + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "value": "'vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n\n " + }, + { + "type": "HTMLRawText", + "range": [ + 138, + 140 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 141, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": "write" + }, + { + "type": "HTMLWhitespace", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 147, + 158 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 22 + } + }, + "value": "Composition" + }, + { + "type": "HTMLWhitespace", + "range": [ + 158, + 159 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 159, + 162 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "value": "API" + }, + { + "type": "HTMLWhitespace", + "range": [ + 162, + 163 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 163, + 167 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "value": "code" + }, + { + "type": "HTMLWhitespace", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 32 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 168, + 172 + ], + "loc": { + "start": { + "line": 6, + "column": 32 + }, + "end": { + "line": 6, + "column": 36 + } + }, + "value": "just" + }, + { + "type": "HTMLWhitespace", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 6, + "column": 36 + }, + "end": { + "line": 6, + "column": 37 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 173, + 177 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 6, + "column": 41 + } + }, + "value": "like" + }, + { + "type": "HTMLWhitespace", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 6, + "column": 41 + }, + "end": { + "line": 6, + "column": 42 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 178, + 180 + ], + "loc": { + "start": { + "line": 6, + "column": 42 + }, + "end": { + "line": 6, + "column": 44 + } + }, + "value": "in" + }, + { + "type": "HTMLWhitespace", + "range": [ + 180, + 181 + ], + "loc": { + "start": { + "line": 6, + "column": 44 + }, + "end": { + "line": 6, + "column": 45 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 181, + 182 + ], + "loc": { + "start": { + "line": 6, + "column": 45 + }, + "end": { + "line": 6, + "column": 46 + } + }, + "value": "a" + }, + { + "type": "HTMLWhitespace", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 6, + "column": 46 + }, + "end": { + "line": 6, + "column": 47 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 183, + 189 + ], + "loc": { + "start": { + "line": 6, + "column": 47 + }, + "end": { + "line": 6, + "column": 53 + } + }, + "value": "normal" + }, + { + "type": "HTMLWhitespace", + "range": [ + 189, + 190 + ], + "loc": { + "start": { + "line": 6, + "column": 53 + }, + "end": { + "line": 6, + "column": 54 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 190, + 197 + ], + "loc": { + "start": { + "line": 6, + "column": 54 + }, + "end": { + "line": 6, + "column": 61 + } + }, + "value": "setup()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 197, + 200 + ], + "loc": { + "start": { + "line": 6, + "column": 61 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 200, + 202 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 202, + 203 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 203, + 206 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "value": "but" + }, + { + "type": "HTMLWhitespace", + "range": [ + 206, + 207 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 207, + 209 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "no" + }, + { + "type": "HTMLWhitespace", + "range": [ + 209, + 210 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 210, + 214 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "value": "need" + }, + { + "type": "HTMLWhitespace", + "range": [ + 214, + 215 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 215, + 217 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "value": "to" + }, + { + "type": "HTMLWhitespace", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 218, + 226 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 28 + } + }, + "value": "manually" + }, + { + "type": "HTMLWhitespace", + "range": [ + 226, + 227 + ], + "loc": { + "start": { + "line": 7, + "column": 28 + }, + "end": { + "line": 7, + "column": 29 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 227, + 233 + ], + "loc": { + "start": { + "line": 7, + "column": 29 + }, + "end": { + "line": 7, + "column": 35 + } + }, + "value": "return" + }, + { + "type": "HTMLWhitespace", + "range": [ + 233, + 234 + ], + "loc": { + "start": { + "line": 7, + "column": 35 + }, + "end": { + "line": 7, + "column": 36 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 234, + 244 + ], + "loc": { + "start": { + "line": 7, + "column": 36 + }, + "end": { + "line": 7, + "column": 46 + } + }, + "value": "everything" + }, + { + "type": "HTMLWhitespace", + "range": [ + 244, + 247 + ], + "loc": { + "start": { + "line": 7, + "column": 46 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 247, + 252 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 252, + 253 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 253, + 258 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "value": "count" + }, + { + "type": "HTMLWhitespace", + "range": [ + 258, + 259 + ], + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 259, + 260 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 260, + 261 + ], + "loc": { + "start": { + "line": 8, + "column": 15 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 261, + 267 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "value": "ref(0)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 267, + 270 + ], + "loc": { + "start": { + "line": 8, + "column": 22 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 270, + 275 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 275, + 276 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 276, + 279 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": "inc" + }, + { + "type": "HTMLWhitespace", + "range": [ + 279, + 280 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 280, + 281 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 281, + 282 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 282, + 284 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "value": "()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 284, + 285 + ], + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 285, + 287 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 19 + } + }, + "value": "=>" + }, + { + "type": "HTMLWhitespace", + "range": [ + 287, + 288 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 288, + 289 + ], + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 21 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 289, + 294 + ], + "loc": { + "start": { + "line": 9, + "column": 21 + }, + "end": { + "line": 10, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 294, + 307 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 17 + } + }, + "value": "count.value++" + }, + { + "type": "HTMLWhitespace", + "range": [ + 307, + 310 + ], + "loc": { + "start": { + "line": 10, + "column": 17 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 310, + 311 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 311, + 312 + ], + "loc": { + "start": { + "line": 11, + "column": 3 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 312, + 320 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 320, + 321 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 321, + 323 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 323, + 332 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 332, + 333 + ], + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 333, + 336 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 336, + 340 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 6 + } + }, + "value": "foo" + }, + { + "type": "Punctuator", + "range": [ + 341, + 342 + ], + "loc": { + "start": { + "column": 7, + "line": 15 + }, + "end": { + "column": 8, + "line": 15 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 342, + 347 + ], + "loc": { + "start": { + "column": 8, + "line": 15 + }, + "end": { + "column": 13, + "line": 15 + } + }, + "value": "count" + }, + { + "type": "HTMLAssociation", + "range": [ + 347, + 348 + ], + "loc": { + "start": { + "line": 15, + "column": 13 + }, + "end": { + "line": 15, + "column": 14 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 348, + 349 + ], + "loc": { + "start": { + "line": 15, + "column": 14 + }, + "end": { + "line": 15, + "column": 15 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "count", + "start": 349, + "end": 354, + "loc": { + "start": { + "line": 15, + "column": 15 + }, + "end": { + "line": 15, + "column": 20 + } + }, + "range": [ + 349, + 354 + ] + }, + { + "type": "Punctuator", + "range": [ + 354, + 355 + ], + "loc": { + "start": { + "line": 15, + "column": 20 + }, + "end": { + "line": 15, + "column": 21 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 356, + 357 + ], + "loc": { + "start": { + "column": 22, + "line": 15 + }, + "end": { + "column": 23, + "line": 15 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 357, + 362 + ], + "loc": { + "start": { + "column": 23, + "line": 15 + }, + "end": { + "column": 28, + "line": 15 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 362, + 363 + ], + "loc": { + "start": { + "line": 15, + "column": 28 + }, + "end": { + "line": 15, + "column": 29 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 363, + 364 + ], + "loc": { + "start": { + "line": 15, + "column": 29 + }, + "end": { + "line": 15, + "column": 30 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "inc", + "start": 364, + "end": 367, + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 33 + } + }, + "range": [ + 364, + 367 + ] + }, + { + "type": "Punctuator", + "range": [ + 367, + 368 + ], + "loc": { + "start": { + "line": 15, + "column": 33 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "value": "\"" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 369, + 371 + ], + "loc": { + "start": { + "line": 15, + "column": 35 + }, + "end": { + "line": 15, + "column": 37 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 371, + 372 + ], + "loc": { + "start": { + "line": 15, + "column": 37 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 372, + 382 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 382, + 383 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 383, + 384 + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [ + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 336, + "lineNumber": 15, + "column": 2 + } + ] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example01/parser-options.json b/test/fixtures/ast/script-setup-example01/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example01/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example01/source.vue b/test/fixtures/ast/script-setup-example01/source.vue new file mode 100644 index 00000000..5668e615 --- /dev/null +++ b/test/fixtures/ast/script-setup-example01/source.vue @@ -0,0 +1,16 @@ + + + diff --git a/test/fixtures/ast/script-setup-example01/token-ranges.json b/test/fixtures/ast/script-setup-example01/token-ranges.json new file mode 100644 index 00000000..147d127a --- /dev/null +++ b/test/fixtures/ast/script-setup-example01/token-ranges.json @@ -0,0 +1,164 @@ +[ + "", + "// imported components are also directly usable in template", + "// write Composition API code just like in a normal setup()", + "// but no need to manually return everything", + "", + "\n ", + "//", + " ", + "imported", + " ", + "components", + " ", + "are", + " ", + "also", + " ", + "directly", + " ", + "usable", + " ", + "in", + " ", + "template", + "\n ", + "import", + " ", + "Foo", + " ", + "from", + " ", + "'./Foo.vue'", + "\n ", + "import", + " ", + "{", + " ", + "ref", + " ", + "}", + " ", + "from", + " ", + "'vue'", + "\n\n ", + "//", + " ", + "write", + " ", + "Composition", + " ", + "API", + " ", + "code", + " ", + "just", + " ", + "like", + " ", + "in", + " ", + "a", + " ", + "normal", + " ", + "setup()", + "\n ", + "//", + " ", + "but", + " ", + "no", + " ", + "need", + " ", + "to", + " ", + "manually", + " ", + "return", + " ", + "everything", + "\n ", + "const", + " ", + "count", + " ", + "=", + " ", + "ref(0)", + "\n ", + "const", + " ", + "inc", + " ", + "=", + " ", + "()", + " ", + "=>", + " ", + "{", + "\n ", + "count.value++", + "\n ", + "}", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example01/tree.json b/test/fixtures/ast/script-setup-example01/tree.json new file mode 100644 index 00000000..268d4c65 --- /dev/null +++ b/test/fixtures/ast/script-setup-example01/tree.json @@ -0,0 +1,106 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example02/ast.json b/test/fixtures/ast/script-setup-example02/ast.json new file mode 100644 index 00000000..f7f9e75c --- /dev/null +++ b/test/fixtures/ast/script-setup-example02/ast.json @@ -0,0 +1,915 @@ +{ + "type": "Program", + "start": 44, + "end": 169, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 7, + "column": 48 + } + }, + "range": [ + 44, + 169 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 44, + "end": 93, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "range": [ + 44, + 93 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 50, + "end": 93, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "range": [ + 50, + 93 + ], + "id": { + "type": "Identifier", + "start": 50, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 50, + 55 + ], + "name": "props" + }, + "init": { + "type": "CallExpression", + "start": 58, + "end": 93, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "range": [ + 58, + 93 + ], + "callee": { + "type": "Identifier", + "start": 58, + "end": 69, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "range": [ + 58, + 69 + ], + "name": "defineProps" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 70, + "end": 92, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "range": [ + 70, + 92 + ], + "properties": [ + { + "type": "Property", + "start": 76, + "end": 87, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "range": [ + 76, + 87 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 76, + "end": 79, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "range": [ + 76, + 79 + ], + "name": "foo" + }, + "value": { + "type": "Identifier", + "start": 81, + "end": 87, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "range": [ + 81, + 87 + ], + "name": "String" + }, + "kind": "init" + } + ] + } + ], + "optional": false + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 123, + "end": 169, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 48 + } + }, + "range": [ + 123, + 169 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 129, + "end": 169, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 48 + } + }, + "range": [ + 129, + 169 + ], + "id": { + "type": "Identifier", + "start": 129, + "end": 133, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "range": [ + 129, + 133 + ], + "name": "emit" + }, + "init": { + "type": "CallExpression", + "start": 136, + "end": 169, + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 48 + } + }, + "range": [ + 136, + 169 + ], + "callee": { + "type": "Identifier", + "start": 136, + "end": 147, + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 26 + } + }, + "range": [ + 136, + 147 + ], + "name": "defineEmits" + }, + "arguments": [ + { + "type": "ArrayExpression", + "start": 148, + "end": 168, + "loc": { + "start": { + "line": 7, + "column": 27 + }, + "end": { + "line": 7, + "column": 47 + } + }, + "range": [ + 148, + 168 + ], + "elements": [ + { + "type": "Literal", + "start": 149, + "end": 157, + "loc": { + "start": { + "line": 7, + "column": 28 + }, + "end": { + "line": 7, + "column": 36 + } + }, + "range": [ + 149, + 157 + ], + "value": "update", + "raw": "'update'" + }, + { + "type": "Literal", + "start": 159, + "end": 167, + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 46 + } + }, + "range": [ + 159, + 167 + ], + "value": "delete", + "raw": "'delete'" + } + ] + } + ], + "optional": false + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " expects props options", + "start": 17, + "end": 41, + "range": [ + 17, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Line", + "value": " expects emits options", + "start": 96, + "end": 120, + "range": [ + 96, + 120 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 26 + } + } + } + ], + "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-example02/parser-options.json b/test/fixtures/ast/script-setup-example02/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example02/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example02/source.vue b/test/fixtures/ast/script-setup-example02/source.vue new file mode 100644 index 00000000..444a488c --- /dev/null +++ b/test/fixtures/ast/script-setup-example02/source.vue @@ -0,0 +1,8 @@ + diff --git a/test/fixtures/ast/script-setup-example02/token-ranges.json b/test/fixtures/ast/script-setup-example02/token-ranges.json new file mode 100644 index 00000000..eeb110c6 --- /dev/null +++ b/test/fixtures/ast/script-setup-example02/token-ranges.json @@ -0,0 +1,29 @@ +[ + "", + "// expects props options", + "// expects emits options" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example02/tree.json b/test/fixtures/ast/script-setup-example02/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example02/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example03/ast.json b/test/fixtures/ast/script-setup-example03/ast.json new file mode 100644 index 00000000..4cf27b21 --- /dev/null +++ b/test/fixtures/ast/script-setup-example03/ast.json @@ -0,0 +1,81 @@ +{ + "type": "Program", + "start": 14, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "range": [ + 14, + 35 + ], + "body": [], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " syntax enabled", + "start": 17, + "end": 34, + "range": [ + 17, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + ], + "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-example03/parser-options.json b/test/fixtures/ast/script-setup-example03/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example03/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example03/source.vue b/test/fixtures/ast/script-setup-example03/source.vue new file mode 100644 index 00000000..72b679a6 --- /dev/null +++ b/test/fixtures/ast/script-setup-example03/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/script-setup-example03/token-ranges.json b/test/fixtures/ast/script-setup-example03/token-ranges.json new file mode 100644 index 00000000..b83274c6 --- /dev/null +++ b/test/fixtures/ast/script-setup-example03/token-ranges.json @@ -0,0 +1,5 @@ +[ + "", + "// syntax enabled" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example03/tree.json b/test/fixtures/ast/script-setup-example03/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example03/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example04/ast.json b/test/fixtures/ast/script-setup-example04/ast.json new file mode 100644 index 00000000..637a4493 --- /dev/null +++ b/test/fixtures/ast/script-setup-example04/ast.json @@ -0,0 +1,967 @@ +{ + "type": "Program", + "start": 17, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "range": [ + 17, + 37 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 17, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "range": [ + 17, + 37 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 23, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "range": [ + 23, + 37 + ], + "id": { + "type": "Identifier", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 23, + 26 + ], + "name": "msg" + }, + "init": { + "type": "Literal", + "start": 29, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "range": [ + 29, + 37 + ], + "value": "Hello!", + "raw": "'Hello!'" + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 49, + 94 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 49, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 59, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 62, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 22 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VExpressionContainer", + "range": [ + 67, + 76 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "expression": { + "type": "Identifier", + "start": 70, + "end": 73, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "range": [ + 70, + 73 + ], + "name": "msg" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 70, + "end": 73, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "range": [ + 70, + 73 + ], + "name": "msg" + }, + "mode": "r" + } + ] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 22 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 83, + 94 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 23, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "msg" + }, + { + "type": "HTMLWhitespace", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 29, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "value": "'Hello!'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 38, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 47, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 49, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 59, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 62, + 66 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "value": "" + }, + { + "type": "VExpressionStart", + "range": [ + 67, + 69 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "msg", + "start": 70, + "end": 73, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "range": [ + 70, + 73 + ] + }, + { + "type": "VExpressionEnd", + "range": [ + 74, + 76 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "value": "}}" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 76, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 22 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 83, + 93 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 93, + 94 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example04/parser-options.json b/test/fixtures/ast/script-setup-example04/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example04/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example04/source.vue b/test/fixtures/ast/script-setup-example04/source.vue new file mode 100644 index 00000000..648028f5 --- /dev/null +++ b/test/fixtures/ast/script-setup-example04/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/script-setup-example04/token-ranges.json b/test/fixtures/ast/script-setup-example04/token-ranges.json new file mode 100644 index 00000000..eec92350 --- /dev/null +++ b/test/fixtures/ast/script-setup-example04/token-ranges.json @@ -0,0 +1,37 @@ +[ + "", + "", + "\n ", + "const", + " ", + "msg", + " ", + "=", + " ", + "'Hello!'", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "{{", + "msg", + "}}", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example04/tree.json b/test/fixtures/ast/script-setup-example04/tree.json new file mode 100644 index 00000000..d2c8c9d4 --- /dev/null +++ b/test/fixtures/ast/script-setup-example04/tree.json @@ -0,0 +1,55 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example05/ast.json b/test/fixtures/ast/script-setup-example05/ast.json new file mode 100644 index 00000000..d179c1df --- /dev/null +++ b/test/fixtures/ast/script-setup-example05/ast.json @@ -0,0 +1,1282 @@ +{ + "type": "Program", + "start": 17, + "end": 90, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "range": [ + 17, + 90 + ], + "body": [ + { + "type": "ImportDeclaration", + "start": 17, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 17, + 44 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "range": [ + 24, + 27 + ], + "local": { + "type": "Identifier", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "range": [ + 24, + 27 + ], + "name": "Foo" + } + } + ], + "source": { + "type": "Literal", + "start": 33, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 33, + 44 + ], + "value": "./Foo.vue", + "raw": "'./Foo.vue'" + } + }, + { + "type": "ImportDeclaration", + "start": 47, + "end": 90, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "range": [ + 47, + 90 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 54, + "end": 65, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "range": [ + 54, + 65 + ], + "local": { + "type": "Identifier", + "start": 54, + "end": 65, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "range": [ + 54, + 65 + ], + "name": "MyComponent" + } + } + ], + "source": { + "type": "Literal", + "start": 71, + "end": 90, + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "range": [ + 71, + 90 + ], + "value": "./MyComponent.vue", + "raw": "'./MyComponent.vue'" + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 102, + 186 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 10, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 102, + 112 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 112, + 115 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "name": "foo", + "rawName": "Foo", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "selfClosing": true, + "attributes": [] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 122, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VText", + "range": [ + 155, + 158 + ], + "loc": { + "start": { + "line": 8, + "column": 32 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 158, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "name": "my-component", + "rawName": "my-component", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 158, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "selfClosing": true, + "attributes": [] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 175, + 186 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 24, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 33, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "value": "'./Foo.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 44, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 47, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 54, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "value": "MyComponent" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 66, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 71, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "value": "'./MyComponent.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 3, + "column": 45 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 91, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 102, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 115 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 115, + 119 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 6 + } + }, + "value": "foo" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 120, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 122, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLWhitespace", + "range": [ + 155, + 158 + ], + "loc": { + "start": { + "line": 8, + "column": 32 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 158, + 171 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "value": "my-component" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 172, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 175, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 185, + 186 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 186, + 187 + ], + "loc": { + "start": { + "line": 10, + "column": 11 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [ + { + "type": "HTMLComment", + "range": [ + 125, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 32 + } + }, + "value": " kebab-case also works " + } + ], + "errors": [ + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 115, + "lineNumber": 7, + "column": 2 + }, + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 158, + "lineNumber": 9, + "column": 2 + } + ] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example05/parser-options.json b/test/fixtures/ast/script-setup-example05/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example05/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example05/source.vue b/test/fixtures/ast/script-setup-example05/source.vue new file mode 100644 index 00000000..bd432d32 --- /dev/null +++ b/test/fixtures/ast/script-setup-example05/source.vue @@ -0,0 +1,10 @@ + + + diff --git a/test/fixtures/ast/script-setup-example05/token-ranges.json b/test/fixtures/ast/script-setup-example05/token-ranges.json new file mode 100644 index 00000000..80b6caeb --- /dev/null +++ b/test/fixtures/ast/script-setup-example05/token-ranges.json @@ -0,0 +1,49 @@ +[ + "", + "", + "\n ", + "import", + " ", + "Foo", + " ", + "from", + " ", + "'./Foo.vue'", + "\n ", + "import", + " ", + "MyComponent", + " ", + "from", + " ", + "'./MyComponent.vue'", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n ", + "\n ", + "", + "\n", + "", + "\n", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example05/tree.json b/test/fixtures/ast/script-setup-example05/tree.json new file mode 100644 index 00000000..f2cb42a4 --- /dev/null +++ b/test/fixtures/ast/script-setup-example05/tree.json @@ -0,0 +1,60 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example06/ast.json b/test/fixtures/ast/script-setup-example06/ast.json new file mode 100644 index 00000000..9b8daba2 --- /dev/null +++ b/test/fixtures/ast/script-setup-example06/ast.json @@ -0,0 +1,1906 @@ +{ + "type": "Program", + "start": 17, + "end": 74, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "range": [ + 17, + 74 + ], + "body": [ + { + "type": "ImportDeclaration", + "start": 17, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 17, + 44 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "range": [ + 24, + 27 + ], + "local": { + "type": "Identifier", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "range": [ + 24, + 27 + ], + "name": "Foo" + } + } + ], + "source": { + "type": "Literal", + "start": 33, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 33, + 44 + ], + "value": "./Foo.vue", + "raw": "'./Foo.vue'" + } + }, + { + "type": "ImportDeclaration", + "start": 47, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "range": [ + 47, + 74 + ], + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 54, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "range": [ + 54, + 57 + ], + "local": { + "type": "Identifier", + "start": 54, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "range": [ + 54, + 57 + ], + "name": "Bar" + } + } + ], + "source": { + "type": "Literal", + "start": 63, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "range": [ + 63, + 74 + ], + "value": "./Bar.vue", + "raw": "'./Bar.vue'" + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 86, + 182 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 86, + 96 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 96, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 99, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 25 + } + }, + "name": "component", + "rawName": "component", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 99, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 25 + } + }, + "selfClosing": true, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 110, + 113 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "column": 13, + "line": 7 + }, + "end": { + "column": 14, + "line": 7 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 111, + 113 + ], + "loc": { + "start": { + "column": 14, + "line": 7 + }, + "end": { + "column": 16, + "line": 7 + } + }, + "name": "is", + "rawName": "is" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 114, + 119 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "expression": { + "type": "Identifier", + "start": 115, + "end": 118, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 21 + } + }, + "range": [ + 115, + 118 + ], + "name": "Foo" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 115, + "end": 118, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 21 + } + }, + "range": [ + 115, + 118 + ], + "name": "Foo" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 122, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 125, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 47 + } + }, + "name": "component", + "rawName": "component", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 125, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 47 + } + }, + "selfClosing": true, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 136, + 167 + ], + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 44 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 136, + 139 + ], + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "column": 13, + "line": 8 + }, + "end": { + "column": 14, + "line": 8 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 137, + 139 + ], + "loc": { + "start": { + "column": 14, + "line": 8 + }, + "end": { + "column": 16, + "line": 8 + } + }, + "name": "is", + "rawName": "is" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 140, + 167 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 44 + } + }, + "expression": { + "type": "ConditionalExpression", + "start": 141, + "end": 166, + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "range": [ + 141, + 166 + ], + "test": { + "type": "Identifier", + "start": 141, + "end": 154, + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 31 + } + }, + "range": [ + 141, + 154 + ], + "name": "someCondition" + }, + "consequent": { + "type": "Identifier", + "start": 157, + "end": 160, + "loc": { + "start": { + "line": 8, + "column": 34 + }, + "end": { + "line": 8, + "column": 37 + } + }, + "range": [ + 157, + 160 + ], + "name": "Foo" + }, + "alternate": { + "type": "Identifier", + "start": 163, + "end": 166, + "loc": { + "start": { + "line": 8, + "column": 40 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "range": [ + 163, + 166 + ], + "name": "Bar" + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 141, + "end": 154, + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 31 + } + }, + "range": [ + 141, + 154 + ], + "name": "someCondition" + }, + "mode": "r" + }, + { + "id": { + "type": "Identifier", + "start": 157, + "end": 160, + "loc": { + "start": { + "line": 8, + "column": 34 + }, + "end": { + "line": 8, + "column": 37 + } + }, + "range": [ + 157, + 160 + ], + "name": "Foo" + }, + "mode": "r" + }, + { + "id": { + "type": "Identifier", + "start": 163, + "end": 166, + "loc": { + "start": { + "line": 8, + "column": 40 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "range": [ + 163, + 166 + ], + "name": "Bar" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 8, + "column": 47 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 171, + 182 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 24, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 33, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "value": "'./Foo.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 44, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 47, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 54, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "value": "Bar" + }, + { + "type": "HTMLWhitespace", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 58, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 63, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "value": "'./Bar.vue'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 75, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 84, + 86 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 95, + 96 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 96, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 99, + 109 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "value": "component" + }, + { + "type": "Punctuator", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "column": 13, + "line": 7 + }, + "end": { + "column": 14, + "line": 7 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 111, + 113 + ], + "loc": { + "start": { + "column": 14, + "line": 7 + }, + "end": { + "column": 16, + "line": 7 + } + }, + "value": "is" + }, + { + "type": "HTMLAssociation", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "Foo", + "start": 115, + "end": 118, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 21 + } + }, + "range": [ + 115, + 118 + ] + }, + { + "type": "Punctuator", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "value": "\"" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 120, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 122, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 125, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "value": "component" + }, + { + "type": "Punctuator", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "column": 13, + "line": 8 + }, + "end": { + "column": 14, + "line": 8 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 137, + 139 + ], + "loc": { + "start": { + "column": 14, + "line": 8 + }, + "end": { + "column": 16, + "line": 8 + } + }, + "value": "is" + }, + { + "type": "HTMLAssociation", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "someCondition", + "start": 141, + "end": 154, + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 31 + } + }, + "range": [ + 141, + 154 + ] + }, + { + "type": "Punctuator", + "value": "?", + "start": 155, + "end": 156, + "loc": { + "start": { + "line": 8, + "column": 32 + }, + "end": { + "line": 8, + "column": 33 + } + }, + "range": [ + 155, + 156 + ] + }, + { + "type": "Identifier", + "value": "Foo", + "start": 157, + "end": 160, + "loc": { + "start": { + "line": 8, + "column": 34 + }, + "end": { + "line": 8, + "column": 37 + } + }, + "range": [ + 157, + 160 + ] + }, + { + "type": "Punctuator", + "value": ":", + "start": 161, + "end": 162, + "loc": { + "start": { + "line": 8, + "column": 38 + }, + "end": { + "line": 8, + "column": 39 + } + }, + "range": [ + 161, + 162 + ] + }, + { + "type": "Identifier", + "value": "Bar", + "start": 163, + "end": 166, + "loc": { + "start": { + "line": 8, + "column": 40 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "range": [ + 163, + 166 + ] + }, + { + "type": "Punctuator", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 8, + "column": 43 + }, + "end": { + "line": 8, + "column": 44 + } + }, + "value": "\"" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 168, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 45 + }, + "end": { + "line": 8, + "column": 47 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 8, + "column": 47 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 171, + 181 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 181, + 182 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [ + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 99, + "lineNumber": 7, + "column": 2 + }, + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 125, + "lineNumber": 8, + "column": 2 + } + ] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example06/parser-options.json b/test/fixtures/ast/script-setup-example06/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example06/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example06/source.vue b/test/fixtures/ast/script-setup-example06/source.vue new file mode 100644 index 00000000..cb1a5379 --- /dev/null +++ b/test/fixtures/ast/script-setup-example06/source.vue @@ -0,0 +1,9 @@ + + + diff --git a/test/fixtures/ast/script-setup-example06/token-ranges.json b/test/fixtures/ast/script-setup-example06/token-ranges.json new file mode 100644 index 00000000..1b81a518 --- /dev/null +++ b/test/fixtures/ast/script-setup-example06/token-ranges.json @@ -0,0 +1,63 @@ +[ + "", + "", + "\n ", + "import", + " ", + "Foo", + " ", + "from", + " ", + "'./Foo.vue'", + "\n ", + "import", + " ", + "Bar", + " ", + "from", + " ", + "'./Bar.vue'", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example06/tree.json b/test/fixtures/ast/script-setup-example06/tree.json new file mode 100644 index 00000000..0e040608 --- /dev/null +++ b/test/fixtures/ast/script-setup-example06/tree.json @@ -0,0 +1,139 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example07/ast.json b/test/fixtures/ast/script-setup-example07/ast.json new file mode 100644 index 00000000..46ad7ed6 --- /dev/null +++ b/test/fixtures/ast/script-setup-example07/ast.json @@ -0,0 +1,1122 @@ +{ + "type": "Program", + "start": 17, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 17, + 77 + ], + "body": [ + { + "type": "ImportDeclaration", + "start": 17, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 17, + 77 + ], + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 26, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "range": [ + 26, + 52 + ], + "imported": { + "type": "Identifier", + "start": 26, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "range": [ + 26, + 35 + ], + "name": "directive" + }, + "local": { + "type": "Identifier", + "start": 39, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "range": [ + 39, + 52 + ], + "name": "vClickOutside" + } + } + ], + "source": { + "type": "Literal", + "start": 60, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 60, + 77 + ], + "value": "v-click-outside", + "raw": "'v-click-outside'" + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 89, + 137 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 89, + 99 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 99, + 102 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 102, + 125 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 102, + 125 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "selfClosing": true, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 107, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 22 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 107, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 22 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 107, + 122 + ], + "loc": { + "start": { + "column": 7, + "line": 6 + }, + "end": { + "column": 22, + "line": 6 + } + }, + "name": "click-outside", + "rawName": "click-outside" + }, + "argument": null, + "modifiers": [] + }, + "value": null + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 126, + 137 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "setup" + }, + { + "type": "HTMLTagClose", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "import" + }, + { + "type": "HTMLWhitespace", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 26, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "directive" + }, + { + "type": "HTMLWhitespace", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 36, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "value": "as" + }, + { + "type": "HTMLWhitespace", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 39, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "value": "vClickOutside" + }, + { + "type": "HTMLWhitespace", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 55, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "value": "from" + }, + { + "type": "HTMLWhitespace", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 60, + 77 + ], + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "value": "'v-click-outside'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 2, + "column": 62 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 78, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 87, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 89, + 98 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 99, + 102 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 102, + 106 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 107, + 122 + ], + "loc": { + "start": { + "column": 7, + "line": 6 + }, + "end": { + "column": 22, + "line": 6 + } + }, + "value": "v-click-outside" + }, + { + "type": "HTMLSelfClosingTagClose", + "range": [ + 123, + 125 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 126, + 136 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [ + { + "message": "non-void-html-element-start-tag-with-trailing-solidus", + "index": 102, + "lineNumber": 6, + "column": 2 + } + ] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example07/parser-options.json b/test/fixtures/ast/script-setup-example07/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example07/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example07/source.vue b/test/fixtures/ast/script-setup-example07/source.vue new file mode 100644 index 00000000..5dc21392 --- /dev/null +++ b/test/fixtures/ast/script-setup-example07/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/script-setup-example07/token-ranges.json b/test/fixtures/ast/script-setup-example07/token-ranges.json new file mode 100644 index 00000000..72d2f42e --- /dev/null +++ b/test/fixtures/ast/script-setup-example07/token-ranges.json @@ -0,0 +1,45 @@ +[ + "", + "", + "\n ", + "import", + " ", + "{", + " ", + "directive", + " ", + "as", + " ", + "vClickOutside", + " ", + "}", + " ", + "from", + " ", + "'v-click-outside'", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example07/tree.json b/test/fixtures/ast/script-setup-example07/tree.json new file mode 100644 index 00000000..4a519bfd --- /dev/null +++ b/test/fixtures/ast/script-setup-example07/tree.json @@ -0,0 +1,57 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example08/ast.json b/test/fixtures/ast/script-setup-example08/ast.json new file mode 100644 index 00000000..0d64e4a4 --- /dev/null +++ b/test/fixtures/ast/script-setup-example08/ast.json @@ -0,0 +1,895 @@ +{ + "type": "Program", + "start": 17, + "end": 116, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 48 + } + }, + "range": [ + 17, + 116 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 17, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "range": [ + 17, + 66 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 23, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "range": [ + 23, + 66 + ], + "id": { + "type": "Identifier", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 23, + 28 + ], + "name": "props" + }, + "init": { + "type": "CallExpression", + "start": 31, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "range": [ + 31, + 66 + ], + "callee": { + "type": "Identifier", + "start": 31, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 31, + 42 + ], + "name": "defineProps" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 43, + "end": 65, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "range": [ + 43, + 65 + ], + "properties": [ + { + "type": "Property", + "start": 49, + "end": 60, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "range": [ + 49, + 60 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "range": [ + 49, + 52 + ], + "name": "foo" + }, + "value": { + "type": "Identifier", + "start": 54, + "end": 60, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "range": [ + 54, + 60 + ], + "name": "String" + }, + "kind": "init" + } + ] + } + ], + "optional": false + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 70, + "end": 116, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 48 + } + }, + "range": [ + 70, + 116 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 76, + "end": 116, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 48 + } + }, + "range": [ + 76, + 116 + ], + "id": { + "type": "Identifier", + "start": 76, + "end": 80, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "range": [ + 76, + 80 + ], + "name": "emit" + }, + "init": { + "type": "CallExpression", + "start": 83, + "end": 116, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 48 + } + }, + "range": [ + 83, + 116 + ], + "callee": { + "type": "Identifier", + "start": 83, + "end": 94, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "range": [ + 83, + 94 + ], + "name": "defineEmits" + }, + "arguments": [ + { + "type": "ArrayExpression", + "start": 95, + "end": 115, + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 47 + } + }, + "range": [ + 95, + 115 + ], + "elements": [ + { + "type": "Literal", + "start": 96, + "end": 104, + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 36 + } + }, + "range": [ + 96, + 104 + ], + "value": "change", + "raw": "'change'" + }, + { + "type": "Literal", + "start": 106, + "end": 114, + "loc": { + "start": { + "line": 6, + "column": 38 + }, + "end": { + "line": 6, + "column": 46 + } + }, + "range": [ + 106, + 114 + ], + "value": "delete", + "raw": "'delete'" + } + ] + } + ], + "optional": false + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " setup code", + "start": 119, + "end": 132, + "range": [ + 119, + 132 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 15 + } + } + } + ], + "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-example08/parser-options.json b/test/fixtures/ast/script-setup-example08/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example08/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example08/source.vue b/test/fixtures/ast/script-setup-example08/source.vue new file mode 100644 index 00000000..e8da0cce --- /dev/null +++ b/test/fixtures/ast/script-setup-example08/source.vue @@ -0,0 +1,8 @@ + diff --git a/test/fixtures/ast/script-setup-example08/token-ranges.json b/test/fixtures/ast/script-setup-example08/token-ranges.json new file mode 100644 index 00000000..65c748a9 --- /dev/null +++ b/test/fixtures/ast/script-setup-example08/token-ranges.json @@ -0,0 +1,28 @@ +[ + "", + "// setup code" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example08/tree.json b/test/fixtures/ast/script-setup-example08/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example08/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example09/ast.json b/test/fixtures/ast/script-setup-example09/ast.json new file mode 100644 index 00000000..8cc45989 --- /dev/null +++ b/test/fixtures/ast/script-setup-example09/ast.json @@ -0,0 +1,825 @@ +{ + "type": "Program", + "start": 17, + "end": 112, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "range": [ + 17, + 112 + ], + "body": [ + { + "type": "ImportDeclaration", + "start": 17, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 17, + 57 + ], + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 26, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "range": [ + 26, + 34 + ], + "imported": { + "type": "Identifier", + "start": 26, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "range": [ + 26, + 34 + ], + "name": "useSlots" + }, + "local": { + "type": "Identifier", + "start": 26, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "range": [ + 26, + 34 + ], + "name": "useSlots" + } + }, + { + "type": "ImportSpecifier", + "start": 36, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 36, + 44 + ], + "imported": { + "type": "Identifier", + "start": 36, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 36, + 44 + ], + "name": "useAttrs" + }, + "local": { + "type": "Identifier", + "start": 36, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 36, + 44 + ], + "name": "useAttrs" + } + } + ], + "source": { + "type": "Literal", + "start": 52, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 52, + 57 + ], + "value": "vue", + "raw": "'vue'" + } + }, + { + "type": "VariableDeclaration", + "start": 61, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "range": [ + 61, + 85 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 67, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "range": [ + 67, + 85 + ], + "id": { + "type": "Identifier", + "start": 67, + "end": 72, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "range": [ + 67, + 72 + ], + "name": "slots" + }, + "init": { + "type": "CallExpression", + "start": 75, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "range": [ + 75, + 85 + ], + "callee": { + "type": "Identifier", + "start": 75, + "end": 83, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "range": [ + 75, + 83 + ], + "name": "useSlots" + }, + "arguments": [], + "optional": false + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 88, + "end": 112, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "range": [ + 88, + 112 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 94, + "end": 112, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "range": [ + 94, + 112 + ], + "id": { + "type": "Identifier", + "start": 94, + "end": 99, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "range": [ + 94, + 99 + ], + "name": "attrs" + }, + "init": { + "type": "CallExpression", + "start": 102, + "end": 112, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "range": [ + 102, + 112 + ], + "callee": { + "type": "Identifier", + "start": 102, + "end": 110, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 24 + } + }, + "range": [ + 102, + 110 + ], + "name": "useAttrs" + }, + "arguments": [], + "optional": false + } + } + ], + "kind": "const" + } + ], + "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-example09/parser-options.json b/test/fixtures/ast/script-setup-example09/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example09/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example09/source.vue b/test/fixtures/ast/script-setup-example09/source.vue new file mode 100644 index 00000000..274985ef --- /dev/null +++ b/test/fixtures/ast/script-setup-example09/source.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/ast/script-setup-example09/token-ranges.json b/test/fixtures/ast/script-setup-example09/token-ranges.json new file mode 100644 index 00000000..98aa0896 --- /dev/null +++ b/test/fixtures/ast/script-setup-example09/token-ranges.json @@ -0,0 +1,24 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example09/tree.json b/test/fixtures/ast/script-setup-example09/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example09/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example10/ast.json b/test/fixtures/ast/script-setup-example10/ast.json new file mode 100644 index 00000000..7cc84e94 --- /dev/null +++ b/test/fixtures/ast/script-setup-example10/ast.json @@ -0,0 +1,1694 @@ +{ + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "props", + "range": [ + 31, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineProps", + "range": [ + 39, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 39, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 50, + 84 + ], + "params": [ + { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "foo", + "range": [ + 55, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 58, + 66 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 60, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + }, + "range": [ + 55, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + { + "type": "TSPropertySignature", + "optional": true, + "computed": false, + "key": { + "type": "Identifier", + "name": "bar", + "range": [ + 69, + 72 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "range": [ + 73, + 81 + ], + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 75, + 81 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 14 + } + } + } + }, + "range": [ + 69, + 81 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 14 + } + } + } + ], + "range": [ + 51, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 5, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 5, + "column": 2 + } + } + } + }, + "range": [ + 31, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 5, + "column": 4 + } + } + } + ], + "kind": "const", + "range": [ + 25, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 5, + "column": 4 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "emit", + "range": [ + 94, + 98 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineEmits", + "range": [ + 101, + 112 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 101, + 190 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 10, + "column": 4 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 112, + 188 + ], + "params": [ + { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSCallSignatureDeclaration", + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 118, + 129 + ], + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "range": [ + 119, + 129 + ], + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "Literal", + "value": "change", + "raw": "'change'", + "range": [ + 121, + 129 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 121, + 129 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 14 + } + } + } + } + }, + { + "type": "Identifier", + "name": "id", + "range": [ + 131, + 141 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 26 + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 26 + } + }, + "range": [ + 133, + 141 + ], + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 135, + 141 + ], + "loc": { + "start": { + "line": 8, + "column": 20 + }, + "end": { + "line": 8, + "column": 26 + } + } + } + } + } + ], + "range": [ + 117, + 148 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 33 + } + }, + "returnType": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 8, + "column": 27 + }, + "end": { + "line": 8, + "column": 33 + } + }, + "range": [ + 142, + 148 + ], + "typeAnnotation": { + "type": "TSVoidKeyword", + "range": [ + 144, + 148 + ], + "loc": { + "start": { + "line": 8, + "column": 29 + }, + "end": { + "line": 8, + "column": 33 + } + } + } + } + }, + { + "type": "TSCallSignatureDeclaration", + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 152, + 163 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "range": [ + 153, + 163 + ], + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "Literal", + "value": "update", + "raw": "'update'", + "range": [ + 155, + 163 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 14 + } + } + }, + "range": [ + 155, + 163 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 14 + } + } + } + } + }, + { + "type": "Identifier", + "name": "value", + "range": [ + 165, + 178 + ], + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 9, + "column": 21 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "range": [ + 170, + 178 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 172, + 178 + ], + "loc": { + "start": { + "line": 9, + "column": 23 + }, + "end": { + "line": 9, + "column": 29 + } + } + } + } + } + ], + "range": [ + 151, + 185 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 36 + } + }, + "returnType": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 36 + } + }, + "range": [ + 179, + 185 + ], + "typeAnnotation": { + "type": "TSVoidKeyword", + "range": [ + 181, + 185 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 9, + "column": 36 + } + } + } + } + } + ], + "range": [ + 113, + 187 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 10, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 10, + "column": 2 + } + } + } + }, + "range": [ + 94, + 190 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 10, + "column": 4 + } + } + } + ], + "kind": "const", + "range": [ + 88, + 190 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 10, + "column": 4 + } + } + } + ], + "sourceType": "module", + "range": [ + 25, + 191 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "value": "" + } + ], + "comments": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example10/parser-options.json b/test/fixtures/ast/script-setup-example10/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/script-setup-example10/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/script-setup-example10/source.vue b/test/fixtures/ast/script-setup-example10/source.vue new file mode 100644 index 00000000..dd518a69 --- /dev/null +++ b/test/fixtures/ast/script-setup-example10/source.vue @@ -0,0 +1,11 @@ + diff --git a/test/fixtures/ast/script-setup-example10/token-ranges.json b/test/fixtures/ast/script-setup-example10/token-ranges.json new file mode 100644 index 00000000..b95f769b --- /dev/null +++ b/test/fixtures/ast/script-setup-example10/token-ranges.json @@ -0,0 +1,53 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example10/tree.json b/test/fixtures/ast/script-setup-example10/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example10/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example11/ast.json b/test/fixtures/ast/script-setup-example11/ast.json new file mode 100644 index 00000000..a1fb4046 --- /dev/null +++ b/test/fixtures/ast/script-setup-example11/ast.json @@ -0,0 +1,913 @@ +{ + "type": "Program", + "body": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSPropertySignature", + "optional": true, + "computed": false, + "key": { + "type": "Identifier", + "name": "msg", + "range": [ + 45, + 48 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "range": [ + 49, + 57 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 51, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 14 + } + } + } + }, + "range": [ + 45, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + } + } + ], + "range": [ + 41, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + "id": { + "type": "Identifier", + "name": "Props", + "range": [ + 35, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "range": [ + 25, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "props", + "range": [ + 67, + 72 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "withDefaults", + "range": [ + 75, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + "arguments": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineProps", + "range": [ + 88, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 38 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 88, + 108 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 47 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 99, + 106 + ], + "params": [ + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Props", + "range": [ + 100, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 39 + }, + "end": { + "line": 6, + "column": 44 + } + } + }, + "range": [ + 100, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 39 + }, + "end": { + "line": 6, + "column": 44 + } + } + } + ], + "loc": { + "start": { + "line": 6, + "column": 38 + }, + "end": { + "line": 6, + "column": 45 + } + } + } + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "msg", + "range": [ + 114, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + "value": { + "type": "Literal", + "value": "hello", + "raw": "'hello'", + "range": [ + 119, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + "computed": false, + "method": false, + "shorthand": false, + "kind": "init", + "range": [ + 114, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 14 + } + } + } + ], + "range": [ + 110, + 128 + ], + "loc": { + "start": { + "line": 6, + "column": 49 + }, + "end": { + "line": 8, + "column": 1 + } + } + } + ], + "optional": false, + "range": [ + 75, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 8, + "column": 2 + } + } + }, + "range": [ + 67, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 8, + "column": 2 + } + } + } + ], + "kind": "const", + "range": [ + 61, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 8, + "column": 2 + } + } + } + ], + "sourceType": "module", + "range": [ + 25, + 130 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "value": "" + } + ], + "comments": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example11/parser-options.json b/test/fixtures/ast/script-setup-example11/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/script-setup-example11/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/script-setup-example11/source.vue b/test/fixtures/ast/script-setup-example11/source.vue new file mode 100644 index 00000000..f70c2d7e --- /dev/null +++ b/test/fixtures/ast/script-setup-example11/source.vue @@ -0,0 +1,9 @@ + diff --git a/test/fixtures/ast/script-setup-example11/token-ranges.json b/test/fixtures/ast/script-setup-example11/token-ranges.json new file mode 100644 index 00000000..e270378c --- /dev/null +++ b/test/fixtures/ast/script-setup-example11/token-ranges.json @@ -0,0 +1,30 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example11/tree.json b/test/fixtures/ast/script-setup-example11/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example11/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example12/ast.json b/test/fixtures/ast/script-setup-example12/ast.json new file mode 100644 index 00000000..fffdf813 --- /dev/null +++ b/test/fixtures/ast/script-setup-example12/ast.json @@ -0,0 +1,839 @@ +{ + "type": "Program", + "start": 17, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 17, + 78 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 17, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 17, + 78 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 23, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 23, + 78 + ], + "id": { + "type": "Identifier", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "range": [ + 23, + 27 + ], + "name": "post" + }, + "init": { + "type": "AwaitExpression", + "start": 30, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 30, + 78 + ], + "argument": { + "type": "CallExpression", + "start": 36, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 36, + 78 + ], + "callee": { + "type": "MemberExpression", + "start": 36, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 36, + 61 + ], + "object": { + "type": "CallExpression", + "start": 36, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 36, + 56 + ], + "callee": { + "type": "Identifier", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "range": [ + 36, + 41 + ], + "name": "fetch" + }, + "arguments": [ + { + "type": "TemplateLiteral", + "start": 42, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 42, + 55 + ], + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 42, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 42, + 55 + ], + "value": { + "raw": "/api/post/1", + "cooked": "/api/post/1" + }, + "tail": true + } + ] + } + ], + "optional": false + }, + "property": { + "type": "Identifier", + "start": 57, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 57, + 61 + ], + "name": "then" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 62, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 47 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 62, + 77 + ], + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 63, + 64 + ], + "name": "r" + } + ], + "body": { + "type": "CallExpression", + "start": 69, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 69, + 77 + ], + "callee": { + "type": "MemberExpression", + "start": 69, + "end": 75, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 60 + } + }, + "range": [ + 69, + 75 + ], + "object": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 55 + } + }, + "range": [ + 69, + 70 + ], + "name": "r" + }, + "property": { + "type": "Identifier", + "start": 71, + "end": 75, + "loc": { + "start": { + "line": 2, + "column": 56 + }, + "end": { + "line": 2, + "column": 60 + } + }, + "range": [ + 71, + 75 + ], + "name": "json" + }, + "computed": false, + "optional": false + }, + "arguments": [], + "optional": false + } + } + ], + "optional": false + } + } + } + ], + "kind": "const" + } + ], + "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-example12/parser-options.json b/test/fixtures/ast/script-setup-example12/parser-options.json new file mode 100644 index 00000000..9f047d2c --- /dev/null +++ b/test/fixtures/ast/script-setup-example12/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "ecmaVersion": 2022 +} diff --git a/test/fixtures/ast/script-setup-example12/source.vue b/test/fixtures/ast/script-setup-example12/source.vue new file mode 100644 index 00000000..bc11f0b4 --- /dev/null +++ b/test/fixtures/ast/script-setup-example12/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/script-setup-example12/token-ranges.json b/test/fixtures/ast/script-setup-example12/token-ranges.json new file mode 100644 index 00000000..e8347441 --- /dev/null +++ b/test/fixtures/ast/script-setup-example12/token-ranges.json @@ -0,0 +1,25 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example12/tree.json b/test/fixtures/ast/script-setup-example12/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example12/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example13/ast.json b/test/fixtures/ast/script-setup-example13/ast.json new file mode 100644 index 00000000..6a67da3b --- /dev/null +++ b/test/fixtures/ast/script-setup-example13/ast.json @@ -0,0 +1,855 @@ +{ + "type": "Program", + "start": 15, + "end": 71, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "range": [ + 15, + 71 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 15, + 26 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 21, + 26 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "range": [ + 21, + 22 + ], + "name": "a" + }, + "init": { + "type": "Literal", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 25, + 26 + ], + "value": 1, + "raw": "1" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 27, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "range": [ + 27, + 43 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 33, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "range": [ + 33, + 43 + ], + "id": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "range": [ + 33, + 34 + ], + "name": "b" + }, + "init": { + "type": "CallExpression", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "range": [ + 37, + 43 + ], + "callee": { + "type": "Identifier", + "start": 37, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 37, + 40 + ], + "name": "ref" + }, + "arguments": [ + { + "type": "Literal", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "range": [ + 41, + 42 + ], + "value": 2, + "raw": "2" + } + ], + "optional": false + } + } + ], + "kind": "const" + }, + { + "type": "ExpressionStatement", + "start": 45, + "end": 71, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "range": [ + 45, + 71 + ], + "expression": { + "type": "CallExpression", + "start": 45, + "end": 71, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "range": [ + 45, + 71 + ], + "callee": { + "type": "Identifier", + "start": 45, + "end": 57, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "range": [ + 45, + 57 + ], + "name": "defineExpose" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 58, + "end": 70, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "range": [ + 58, + 70 + ], + "properties": [ + { + "type": "Property", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "range": [ + 62, + 63 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "range": [ + 62, + 63 + ], + "name": "a" + }, + "kind": "init", + "value": { + "type": "Identifier", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "range": [ + 62, + 63 + ], + "name": "a" + } + }, + { + "type": "Property", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "range": [ + 67, + 68 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "range": [ + 67, + 68 + ], + "name": "b" + }, + "kind": "init", + "value": { + "type": "Identifier", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "range": [ + 67, + 68 + ], + "name": "b" + } + } + ] + } + ], + "optional": false + } + } + ], + "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-example13/parser-options.json b/test/fixtures/ast/script-setup-example13/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example13/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example13/source.vue b/test/fixtures/ast/script-setup-example13/source.vue new file mode 100644 index 00000000..97e8c115 --- /dev/null +++ b/test/fixtures/ast/script-setup-example13/source.vue @@ -0,0 +1,9 @@ + diff --git a/test/fixtures/ast/script-setup-example13/token-ranges.json b/test/fixtures/ast/script-setup-example13/token-ranges.json new file mode 100644 index 00000000..2dc98c2b --- /dev/null +++ b/test/fixtures/ast/script-setup-example13/token-ranges.json @@ -0,0 +1,23 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example13/tree.json b/test/fixtures/ast/script-setup-example13/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example13/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example14/ast.json b/test/fixtures/ast/script-setup-example14/ast.json new file mode 100644 index 00000000..73f00c5d --- /dev/null +++ b/test/fixtures/ast/script-setup-example14/ast.json @@ -0,0 +1,603 @@ +{ + "type": "Program", + "start": 11, + "end": 168, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "range": [ + 11, + 167 + ], + "body": [ + { + "type": "ExpressionStatement", + "start": 11, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 11, + 36 + ], + "expression": { + "type": "CallExpression", + "start": 11, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 11, + 36 + ], + "callee": { + "type": "Identifier", + "start": 11, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 11, + 34 + ], + "name": "performGlobalSideEffect" + }, + "arguments": [], + "optional": false + } + }, + { + "type": "ExportNamedDeclaration", + "start": 103, + "end": 125, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 24 + } + }, + "range": [ + 103, + 125 + ], + "declaration": { + "type": "VariableDeclaration", + "start": 110, + "end": 125, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 24 + } + }, + "range": [ + 110, + 125 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 116, + "end": 125, + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 24 + } + }, + "range": [ + 116, + 125 + ], + "id": { + "type": "Identifier", + "start": 116, + "end": 121, + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "range": [ + 116, + 121 + ], + "name": "named" + }, + "init": { + "type": "Literal", + "start": 124, + "end": 125, + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 24 + } + }, + "range": [ + 124, + 125 + ], + "value": 1, + "raw": "1" + } + } + ], + "kind": "const" + }, + "specifiers": [], + "source": null + }, + { + "type": "VariableDeclaration", + "start": 154, + "end": 167, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "range": [ + 154, + 167 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 158, + "end": 167, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "range": [ + 158, + 167 + ], + "id": { + "type": "Identifier", + "start": 158, + "end": 163, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "range": [ + 158, + 163 + ], + "name": "count" + }, + "init": { + "type": "Literal", + "start": 166, + "end": 167, + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "range": [ + 166, + 167 + ], + "value": 0, + "raw": "0" + } + } + ], + "kind": "let" + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " this can be imported as `import { named } from './*.vue'`", + "start": 40, + "end": 100, + "range": [ + 40, + 100 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 62 + } + } + } + ], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 137, + 151 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example14/parser-options.json b/test/fixtures/ast/script-setup-example14/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example14/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example14/source.vue b/test/fixtures/ast/script-setup-example14/source.vue new file mode 100644 index 00000000..3d927d00 --- /dev/null +++ b/test/fixtures/ast/script-setup-example14/source.vue @@ -0,0 +1,10 @@ + + + diff --git a/test/fixtures/ast/script-setup-example14/token-ranges.json b/test/fixtures/ast/script-setup-example14/token-ranges.json new file mode 100644 index 00000000..d4dbe02d --- /dev/null +++ b/test/fixtures/ast/script-setup-example14/token-ranges.json @@ -0,0 +1,19 @@ +[ + "", + "", + "// this can be imported as `import { named } from './*.vue'`" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example14/tree.json b/test/fixtures/ast/script-setup-example14/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example14/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example15/ast.json b/test/fixtures/ast/script-setup-example15/ast.json new file mode 100644 index 00000000..fbaf0f38 --- /dev/null +++ b/test/fixtures/ast/script-setup-example15/ast.json @@ -0,0 +1,689 @@ +{ + "type": "Program", + "start": 11, + "end": 154, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "range": [ + 11, + 103 + ], + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 11, + "end": 103, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "range": [ + 11, + 103 + ], + "declaration": { + "type": "ObjectExpression", + "start": 26, + "end": 103, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "range": [ + 26, + 103 + ], + "properties": [ + { + "type": "Property", + "start": 32, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 32, + 50 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 32, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "range": [ + 32, + 36 + ], + "name": "name" + }, + "value": { + "type": "Literal", + "start": 38, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 38, + 50 + ], + "value": "CustomName", + "raw": "'CustomName'" + }, + "kind": "init" + }, + { + "type": "Property", + "start": 56, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "range": [ + 56, + 75 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 56, + "end": 68, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "range": [ + 56, + 68 + ], + "name": "inheritAttrs" + }, + "value": { + "type": "Literal", + "start": 70, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "range": [ + 70, + 75 + ], + "value": false, + "raw": "false" + }, + "kind": "init" + }, + { + "type": "Property", + "start": 81, + "end": 98, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "range": [ + 81, + 98 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 81, + "end": 94, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "range": [ + 81, + 94 + ], + "name": "customOptions" + }, + "value": { + "type": "ObjectExpression", + "start": 96, + "end": 98, + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "range": [ + 96, + 98 + ], + "properties": [] + }, + "kind": "init" + } + ] + } + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " script setup logic", + "start": 132, + "end": 153, + "range": [ + 132, + 153 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 23 + } + } + } + ], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 115, + 129 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "value": "" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example15/parser-options.json b/test/fixtures/ast/script-setup-example15/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/script-setup-example15/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/script-setup-example15/source.vue b/test/fixtures/ast/script-setup-example15/source.vue new file mode 100644 index 00000000..ec003be2 --- /dev/null +++ b/test/fixtures/ast/script-setup-example15/source.vue @@ -0,0 +1,11 @@ + + + diff --git a/test/fixtures/ast/script-setup-example15/token-ranges.json b/test/fixtures/ast/script-setup-example15/token-ranges.json new file mode 100644 index 00000000..b27e16ce --- /dev/null +++ b/test/fixtures/ast/script-setup-example15/token-ranges.json @@ -0,0 +1,24 @@ +[ + "", + "", + "// script setup logic" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example15/tree.json b/test/fixtures/ast/script-setup-example15/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-example15/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/ast.json b/test/fixtures/ast/script-setup-top-level-await-with-es2021/ast.json new file mode 100644 index 00000000..fffdf813 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await-with-es2021/ast.json @@ -0,0 +1,839 @@ +{ + "type": "Program", + "start": 17, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 17, + 78 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 17, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 17, + 78 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 23, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 23, + 78 + ], + "id": { + "type": "Identifier", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "range": [ + 23, + 27 + ], + "name": "post" + }, + "init": { + "type": "AwaitExpression", + "start": 30, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 30, + 78 + ], + "argument": { + "type": "CallExpression", + "start": 36, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 36, + 78 + ], + "callee": { + "type": "MemberExpression", + "start": 36, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 36, + 61 + ], + "object": { + "type": "CallExpression", + "start": 36, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 36, + 56 + ], + "callee": { + "type": "Identifier", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "range": [ + 36, + 41 + ], + "name": "fetch" + }, + "arguments": [ + { + "type": "TemplateLiteral", + "start": 42, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 42, + 55 + ], + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 42, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 42, + 55 + ], + "value": { + "raw": "/api/post/1", + "cooked": "/api/post/1" + }, + "tail": true + } + ] + } + ], + "optional": false + }, + "property": { + "type": "Identifier", + "start": 57, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 57, + 61 + ], + "name": "then" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 62, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 47 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 62, + 77 + ], + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 63, + 64 + ], + "name": "r" + } + ], + "body": { + "type": "CallExpression", + "start": 69, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 69, + 77 + ], + "callee": { + "type": "MemberExpression", + "start": 69, + "end": 75, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 60 + } + }, + "range": [ + 69, + 75 + ], + "object": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 55 + } + }, + "range": [ + 69, + 70 + ], + "name": "r" + }, + "property": { + "type": "Identifier", + "start": 71, + "end": 75, + "loc": { + "start": { + "line": 2, + "column": 56 + }, + "end": { + "line": 2, + "column": 60 + } + }, + "range": [ + 71, + 75 + ], + "name": "json" + }, + "computed": false, + "optional": false + }, + "arguments": [], + "optional": false + } + } + ], + "optional": false + } + } + } + ], + "kind": "const" + } + ], + "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-top-level-await-with-es2021/parser-options.json b/test/fixtures/ast/script-setup-top-level-await-with-es2021/parser-options.json new file mode 100644 index 00000000..d3ad3890 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await-with-es2021/parser-options.json @@ -0,0 +1,3 @@ +{ + "ecmaVersion": 2021 +} diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/source.vue b/test/fixtures/ast/script-setup-top-level-await-with-es2021/source.vue new file mode 100644 index 00000000..bc11f0b4 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await-with-es2021/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/token-ranges.json b/test/fixtures/ast/script-setup-top-level-await-with-es2021/token-ranges.json new file mode 100644 index 00000000..e8347441 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await-with-es2021/token-ranges.json @@ -0,0 +1,25 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/tree.json b/test/fixtures/ast/script-setup-top-level-await-with-es2021/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await-with-es2021/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 index a946b6b1..7ae70685 100644 --- a/test/fixtures/ast/script-setup/ast.json +++ b/test/fixtures/ast/script-setup/ast.json @@ -1,7 +1,7 @@ { "type": "Program", - "start": 14, - "end": 29, + "start": 15, + "end": 28, "loc": { "start": { "line": 2, diff --git a/test/fixtures/ast/slot-scope-destructuring/ast.json b/test/fixtures/ast/slot-scope-destructuring/ast.json index 86571321..b7360160 100644 --- a/test/fixtures/ast/slot-scope-destructuring/ast.json +++ b/test/fixtures/ast/slot-scope-destructuring/ast.json @@ -606,7 +606,8 @@ ], "name": "d" }, - "computed": false + "computed": false, + "optional": false } }, "references": [ diff --git a/test/fixtures/ast/svg-attrs-camel-case/ast.json b/test/fixtures/ast/svg-attrs-camel-case/ast.json index 84a9e6da..1e3a6aa0 100644 --- a/test/fixtures/ast/svg-attrs-camel-case/ast.json +++ b/test/fixtures/ast/svg-attrs-camel-case/ast.json @@ -1,7 +1,7 @@ { "type": "Program", - "start": 93, - "end": 114, + "start": 94, + "end": 113, "loc": { "start": { "line": 8, @@ -112,7 +112,8 @@ ], "name": "exports" }, - "computed": false + "computed": false, + "optional": false }, "right": { "type": "ObjectExpression", diff --git a/test/fixtures/ast/svg-attrs-colon/ast.json b/test/fixtures/ast/svg-attrs-colon/ast.json index 35342c2b..b5a4c622 100644 --- a/test/fixtures/ast/svg-attrs-colon/ast.json +++ b/test/fixtures/ast/svg-attrs-colon/ast.json @@ -1,7 +1,7 @@ { "type": "Program", - "start": 92, - "end": 113, + "start": 93, + "end": 112, "loc": { "start": { "line": 8, @@ -112,7 +112,8 @@ ], "name": "exports" }, - "computed": false + "computed": false, + "optional": false }, "right": { "type": "ObjectExpression", diff --git a/test/fixtures/ast/svg-namespace/ast.json b/test/fixtures/ast/svg-namespace/ast.json index 3e6cc6ed..68f9c796 100644 --- a/test/fixtures/ast/svg-namespace/ast.json +++ b/test/fixtures/ast/svg-namespace/ast.json @@ -1,7 +1,7 @@ { "type": "Program", - "start": 149, - "end": 170, + "start": 150, + "end": 169, "loc": { "start": { "line": 8, @@ -112,7 +112,8 @@ ], "name": "exports" }, - "computed": false + "computed": false, + "optional": false }, "right": { "type": "ObjectExpression", diff --git a/test/fixtures/ast/v-on-arrow-function-expression.1/ast.json b/test/fixtures/ast/v-on-arrow-function-expression.1/ast.json index fc1427fa..4ecfef08 100644 --- a/test/fixtures/ast/v-on-arrow-function-expression.1/ast.json +++ b/test/fixtures/ast/v-on-arrow-function-expression.1/ast.json @@ -264,7 +264,8 @@ ], "name": "act" }, - "arguments": [] + "arguments": [], + "optional": false } }, "references": [ diff --git a/test/fixtures/ast/v-on-arrow-function-expression.2/ast.json b/test/fixtures/ast/v-on-arrow-function-expression.2/ast.json index 0f9594b5..a4a43c5b 100644 --- a/test/fixtures/ast/v-on-arrow-function-expression.2/ast.json +++ b/test/fixtures/ast/v-on-arrow-function-expression.2/ast.json @@ -285,7 +285,8 @@ ], "name": "act" }, - "arguments": [] + "arguments": [], + "optional": false } }, "references": [ diff --git a/test/fixtures/ast/v-on-function-expression/ast.json b/test/fixtures/ast/v-on-function-expression/ast.json index 4b3db6a1..24049e41 100644 --- a/test/fixtures/ast/v-on-function-expression/ast.json +++ b/test/fixtures/ast/v-on-function-expression/ast.json @@ -301,7 +301,8 @@ ], "name": "act" }, - "arguments": [] + "arguments": [], + "optional": false } } ] diff --git a/test/fixtures/ast/v-on-multiple-statements/ast.json b/test/fixtures/ast/v-on-multiple-statements/ast.json index 9d7007c0..03f0a0c4 100644 --- a/test/fixtures/ast/v-on-multiple-statements/ast.json +++ b/test/fixtures/ast/v-on-multiple-statements/ast.json @@ -318,7 +318,8 @@ "value": "DIR", "raw": "'DIR'" } - ] + ], + "optional": false } }, { @@ -399,7 +400,8 @@ "value": "uploadFile", "raw": "'uploadFile'" } - ] + ], + "optional": false } } ] diff --git a/test/fixtures/ast/v-on-simple-path.2/ast.json b/test/fixtures/ast/v-on-simple-path.2/ast.json index 9ce25191..9f05e47b 100644 --- a/test/fixtures/ast/v-on-simple-path.2/ast.json +++ b/test/fixtures/ast/v-on-simple-path.2/ast.json @@ -261,7 +261,8 @@ ], "name": "bar" }, - "computed": false + "computed": false, + "optional": false }, "references": [ { diff --git a/test/fixtures/ast/v-on-simple-path.3/ast.json b/test/fixtures/ast/v-on-simple-path.3/ast.json index e3e74c41..a9b40fae 100644 --- a/test/fixtures/ast/v-on-simple-path.3/ast.json +++ b/test/fixtures/ast/v-on-simple-path.3/ast.json @@ -262,7 +262,8 @@ "value": "bar", "raw": "'bar'" }, - "computed": true + "computed": true, + "optional": false }, "references": [ { @@ -439,7 +440,8 @@ "value": 0, "raw": "0" }, - "computed": true + "computed": true, + "optional": false }, "references": [ { diff --git a/test/fixtures/ast/v-on-simple-path.4/ast.json b/test/fixtures/ast/v-on-simple-path.4/ast.json index 06693b6d..10bc3274 100644 --- a/test/fixtures/ast/v-on-simple-path.4/ast.json +++ b/test/fixtures/ast/v-on-simple-path.4/ast.json @@ -261,7 +261,8 @@ ], "name": "bar" }, - "computed": true + "computed": true, + "optional": false }, "references": [ { diff --git a/typings/eslint-scope/index.d.ts b/typings/eslint-scope/index.d.ts index d85f2c2b..45c4af98 100644 --- a/typings/eslint-scope/index.d.ts +++ b/typings/eslint-scope/index.d.ts @@ -3,7 +3,7 @@ * @copyright 2017 Toru Nagashima. All rights reserved. * See LICENSE file in root directory for full license. */ -import * as estree from "estree" +import type * as estree from "estree" export interface AnalysisOptions { optimistic?: boolean @@ -75,5 +75,6 @@ export interface Reference { declare const eslintScope: { analyze(ast: object, options?: AnalysisOptions): ScopeManager + version: string } export default eslintScope From 002c93524eec2c1b5c2be76510ab03af7adb0d3b Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 1 Jul 2021 09:45:57 +0900 Subject: [PATCH 2/6] Update test --- test/fixtures/ast/script-setup-example10/requirements.json | 3 +++ test/fixtures/ast/script-setup-example11/requirements.json | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 test/fixtures/ast/script-setup-example10/requirements.json create mode 100644 test/fixtures/ast/script-setup-example11/requirements.json diff --git a/test/fixtures/ast/script-setup-example10/requirements.json b/test/fixtures/ast/script-setup-example10/requirements.json new file mode 100644 index 00000000..945cf775 --- /dev/null +++ b/test/fixtures/ast/script-setup-example10/requirements.json @@ -0,0 +1,3 @@ +{ + "@typescript-eslint/parser": "^4.0.0" +} \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-example11/requirements.json b/test/fixtures/ast/script-setup-example11/requirements.json new file mode 100644 index 00000000..945cf775 --- /dev/null +++ b/test/fixtures/ast/script-setup-example11/requirements.json @@ -0,0 +1,3 @@ +{ + "@typescript-eslint/parser": "^4.0.0" +} \ No newline at end of file From fe61bfc72e0ba5679a6e8395d95a133dbfa5724c Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 1 Jul 2021 10:29:46 +0900 Subject: [PATCH 3/6] Change to respect the user parser options. --- src/common/espree.ts | 16 +++-- src/script-setup/index.ts | 1 - src/script-setup/parser-options.ts | 61 +++++-------------- src/script/index.ts | 2 +- .../parser-options.json | 3 - 5 files changed, 27 insertions(+), 56 deletions(-) delete mode 100644 test/fixtures/ast/script-setup-top-level-await-with-es2021/parser-options.json diff --git a/src/common/espree.ts b/src/common/espree.ts index 84cec93b..b59464bc 100644 --- a/src/common/espree.ts +++ b/src/common/espree.ts @@ -99,6 +99,7 @@ function getNewestEspree(): Espree { export function getEcmaVersionIfUseEspree( parserOptions: ParserOptions, + getDefault?: (defaultVer: number) => number, ): number | undefined { if (parserOptions.parser != null && parserOptions.parser !== "espree") { return undefined @@ -108,15 +109,20 @@ export function getEcmaVersionIfUseEspree( return normalizeEcmaVersion(getNewestEspree().latestEcmaVersion) } if (parserOptions.ecmaVersion == null) { - if (lt(getEspreeFromLinter().version, "9.0.0")) { - return 5 - } - // Perhaps the version 9 will change the default to "latest". - return normalizeEcmaVersion(getNewestEspree().latestEcmaVersion) + const defVer = getDefaultEcmaVersion() + return getDefault?.(defVer) ?? defVer } return normalizeEcmaVersion(parserOptions.ecmaVersion) } +function getDefaultEcmaVersion(): number { + if (lt(getEspreeFromLinter().version, "9.0.0")) { + return 5 + } + // Perhaps the version 9 will change the default to "latest". + return normalizeEcmaVersion(getNewestEspree().latestEcmaVersion) +} + /** * Normalize ECMAScript version */ diff --git a/src/script-setup/index.ts b/src/script-setup/index.ts index 0448687b..2795b3c0 100644 --- a/src/script-setup/index.ts +++ b/src/script-setup/index.ts @@ -98,7 +98,6 @@ export function parseScriptSetupElements( ): ESLintExtendedProgram { const parserOptions: ParserOptions = getScriptSetupParserOptions( originalParserOptions, - scriptSetupElement, ) const scriptSetupCodeBlocks = getScriptsCodeBlocks( scriptSetupElement, diff --git a/src/script-setup/parser-options.ts b/src/script-setup/parser-options.ts index ddc4cdd9..25a4c934 100644 --- a/src/script-setup/parser-options.ts +++ b/src/script-setup/parser-options.ts @@ -1,8 +1,6 @@ -import { lt } from "semver" -import type { VElement } from "../ast" +import { lte } from "semver" import { getEcmaVersionIfUseEspree, - getEspreeFromEcmaVersion, getEspreeFromLinter, } from "../common/espree" import type { ParserOptions } from "../common/parser-options" @@ -11,53 +9,24 @@ import type { ParserOptions } from "../common/parser-options" */ export function getScriptSetupParserOptions( parserOptions: ParserOptions, - scriptSetupNode: VElement, ): ParserOptions { - const espreeEcmaVersion = getEcmaVersionIfUseEspree(parserOptions) - const moduleParserOptions: ParserOptions = { - ...parserOptions, + const espreeEcmaVersion = getEcmaVersionIfUseEspree( + parserOptions, + getDefaultEcmaVersion, + ) + + return { // Script setup requires module support, so set module to sourceType. sourceType: "module", - ecmaVersion: - espreeEcmaVersion != null && espreeEcmaVersion < 2015 - ? 2015 - : parserOptions.ecmaVersion, - } - if ( - // User don't use espree. - espreeEcmaVersion == null || - espreeEcmaVersion >= 2022 - ) { - return moduleParserOptions + ...parserOptions, + ecmaVersion: espreeEcmaVersion, } +} - const text = scriptSetupNode.children[0] - if (text != null && text.type === "VText") { - const code = text.value - if (code.includes("await")) { - if (lt(getEspreeFromLinter().version, "8.0.0")) { - return { - ...moduleParserOptions, - // Script setup requires top level await support, so set the ecma version to 2022. - ecmaVersion: 2022, - } - } - // espree v8.x is not compatible with eslint v7.x, so use espree < v8.x whenever possible. - // To determine that, parse it once and check if an error occurs. - try { - getEspreeFromEcmaVersion(espreeEcmaVersion).parse( - code, - moduleParserOptions, - ) - } catch { - return { - ...moduleParserOptions, - // Script setup requires top level await support, so set the ecma version to 2022. - ecmaVersion: 2022, - } - } - } +function getDefaultEcmaVersion(def: number) { + if (lte("8.0.0", getEspreeFromLinter().version)) { + // Script setup requires top level await support, so default the ecma version to 2022. + return getEspreeFromLinter().latestEcmaVersion! } - - return moduleParserOptions + return Math.max(def, 2015) } diff --git a/src/script/index.ts b/src/script/index.ts index 676b6135..2311ef0c 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -561,7 +561,7 @@ export function parseScriptElement( originalParserOptions: ParserOptions, ): ESLintExtendedProgram { const parserOptions: ParserOptions = isScriptSetup(node) - ? getScriptSetupParserOptions(originalParserOptions, node) + ? getScriptSetupParserOptions(originalParserOptions) : originalParserOptions const text = node.children[0] diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/parser-options.json b/test/fixtures/ast/script-setup-top-level-await-with-es2021/parser-options.json deleted file mode 100644 index d3ad3890..00000000 --- a/test/fixtures/ast/script-setup-top-level-await-with-es2021/parser-options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "ecmaVersion": 2021 -} From 3df7d089250656aa646cb8d2603576224a079dfb Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 1 Jul 2021 11:33:15 +0900 Subject: [PATCH 4/6] Update test --- .../ast/multiple-scripts-with-ts-7/scope.json | 102 --- .../ast.json | 0 .../parser-options.json | 3 + .../source.vue | 0 .../token-ranges.json | 0 .../tree.json | 0 .../ast/script-setup-top-level-await/ast.json | 839 ++++++++++++++++++ .../script-setup-top-level-await/source.vue | 3 + .../token-ranges.json | 25 + .../script-setup-top-level-await/tree.json | 1 + 10 files changed, 871 insertions(+), 102 deletions(-) rename test/fixtures/ast/{script-setup-top-level-await-with-es2021 => script-setup-top-level-await-with-latest}/ast.json (100%) create mode 100644 test/fixtures/ast/script-setup-top-level-await-with-latest/parser-options.json rename test/fixtures/ast/{script-setup-top-level-await-with-es2021 => script-setup-top-level-await-with-latest}/source.vue (100%) rename test/fixtures/ast/{script-setup-top-level-await-with-es2021 => script-setup-top-level-await-with-latest}/token-ranges.json (100%) rename test/fixtures/ast/{script-setup-top-level-await-with-es2021 => script-setup-top-level-await-with-latest}/tree.json (100%) create mode 100644 test/fixtures/ast/script-setup-top-level-await/ast.json create mode 100644 test/fixtures/ast/script-setup-top-level-await/source.vue create mode 100644 test/fixtures/ast/script-setup-top-level-await/token-ranges.json create mode 100644 test/fixtures/ast/script-setup-top-level-await/tree.json diff --git a/test/fixtures/ast/multiple-scripts-with-ts-7/scope.json b/test/fixtures/ast/multiple-scripts-with-ts-7/scope.json index 100fd2f6..0e204975 100644 --- a/test/fixtures/ast/multiple-scripts-with-ts-7/scope.json +++ b/test/fixtures/ast/multiple-scripts-with-ts-7/scope.json @@ -799,108 +799,6 @@ "defs": [], "references": [] }, - { - "name": "FlatArray", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "BigIntToLocaleStringOptions", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "BigInt", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "BigIntConstructor", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "BigInt64Array", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "BigInt64ArrayConstructor", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "BigUint64Array", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "BigUint64ArrayConstructor", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "PromiseFulfilledResult", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "PromiseRejectedResult", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "PromiseSettledResult", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "AggregateError", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "AggregateErrorConstructor", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "WeakRef", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "WeakRefConstructor", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "FinalizationRegistry", - "identifiers": [], - "defs": [], - "references": [] - }, - { - "name": "FinalizationRegistryConstructor", - "identifiers": [], - "defs": [], - "references": [] - }, { "name": "const", "identifiers": [], diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/ast.json b/test/fixtures/ast/script-setup-top-level-await-with-latest/ast.json similarity index 100% rename from test/fixtures/ast/script-setup-top-level-await-with-es2021/ast.json rename to test/fixtures/ast/script-setup-top-level-await-with-latest/ast.json diff --git a/test/fixtures/ast/script-setup-top-level-await-with-latest/parser-options.json b/test/fixtures/ast/script-setup-top-level-await-with-latest/parser-options.json new file mode 100644 index 00000000..59478da8 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await-with-latest/parser-options.json @@ -0,0 +1,3 @@ +{ + "ecmaVersion": "latest" +} diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/source.vue b/test/fixtures/ast/script-setup-top-level-await-with-latest/source.vue similarity index 100% rename from test/fixtures/ast/script-setup-top-level-await-with-es2021/source.vue rename to test/fixtures/ast/script-setup-top-level-await-with-latest/source.vue diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/token-ranges.json b/test/fixtures/ast/script-setup-top-level-await-with-latest/token-ranges.json similarity index 100% rename from test/fixtures/ast/script-setup-top-level-await-with-es2021/token-ranges.json rename to test/fixtures/ast/script-setup-top-level-await-with-latest/token-ranges.json diff --git a/test/fixtures/ast/script-setup-top-level-await-with-es2021/tree.json b/test/fixtures/ast/script-setup-top-level-await-with-latest/tree.json similarity index 100% rename from test/fixtures/ast/script-setup-top-level-await-with-es2021/tree.json rename to test/fixtures/ast/script-setup-top-level-await-with-latest/tree.json diff --git a/test/fixtures/ast/script-setup-top-level-await/ast.json b/test/fixtures/ast/script-setup-top-level-await/ast.json new file mode 100644 index 00000000..fffdf813 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await/ast.json @@ -0,0 +1,839 @@ +{ + "type": "Program", + "start": 17, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 17, + 78 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 17, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 17, + 78 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 23, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 23, + 78 + ], + "id": { + "type": "Identifier", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "range": [ + 23, + 27 + ], + "name": "post" + }, + "init": { + "type": "AwaitExpression", + "start": 30, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 30, + 78 + ], + "argument": { + "type": "CallExpression", + "start": 36, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 36, + 78 + ], + "callee": { + "type": "MemberExpression", + "start": 36, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 36, + 61 + ], + "object": { + "type": "CallExpression", + "start": 36, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 36, + 56 + ], + "callee": { + "type": "Identifier", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "range": [ + 36, + 41 + ], + "name": "fetch" + }, + "arguments": [ + { + "type": "TemplateLiteral", + "start": 42, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 42, + 55 + ], + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 42, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 42, + 55 + ], + "value": { + "raw": "/api/post/1", + "cooked": "/api/post/1" + }, + "tail": true + } + ] + } + ], + "optional": false + }, + "property": { + "type": "Identifier", + "start": 57, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 57, + 61 + ], + "name": "then" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 62, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 47 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 62, + 77 + ], + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 63, + 64 + ], + "name": "r" + } + ], + "body": { + "type": "CallExpression", + "start": 69, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "range": [ + 69, + 77 + ], + "callee": { + "type": "MemberExpression", + "start": 69, + "end": 75, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 60 + } + }, + "range": [ + 69, + 75 + ], + "object": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 55 + } + }, + "range": [ + 69, + 70 + ], + "name": "r" + }, + "property": { + "type": "Identifier", + "start": 71, + "end": 75, + "loc": { + "start": { + "line": 2, + "column": 56 + }, + "end": { + "line": 2, + "column": 60 + } + }, + "range": [ + 71, + 75 + ], + "name": "json" + }, + "computed": false, + "optional": false + }, + "arguments": [], + "optional": false + } + } + ], + "optional": false + } + } + } + ], + "kind": "const" + } + ], + "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-top-level-await/source.vue b/test/fixtures/ast/script-setup-top-level-await/source.vue new file mode 100644 index 00000000..bc11f0b4 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/script-setup-top-level-await/token-ranges.json b/test/fixtures/ast/script-setup-top-level-await/token-ranges.json new file mode 100644 index 00000000..e8347441 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await/token-ranges.json @@ -0,0 +1,25 @@ +[ + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/script-setup-top-level-await/tree.json b/test/fixtures/ast/script-setup-top-level-await/tree.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/ast/script-setup-top-level-await/tree.json @@ -0,0 +1 @@ +[] \ No newline at end of file From b23599dfb6ec35410636639e6fb4a2668bed806a Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 1 Jul 2021 14:52:56 +0900 Subject: [PATCH 5/6] update --- src/parser-services.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/parser-services.ts b/src/parser-services.ts index 693c1ea2..726959bc 100644 --- a/src/parser-services.ts +++ b/src/parser-services.ts @@ -39,9 +39,6 @@ type CustomBlockVisitorFactory = (context: CustomBlockContext) => | null | undefined -const emitters = new WeakMap() -const stores = new WeakMap() - //------------------------------------------------------------------------------ // Exports //------------------------------------------------------------------------------ @@ -51,10 +48,12 @@ export interface ParserServices { * Define handlers to traverse the template body. * @param templateBodyVisitor The template body handlers. * @param scriptVisitor The script handlers. This is optional. + * @param options The options. This is optional. */ defineTemplateBodyVisitor( templateBodyVisitor: { [key: string]: (...args: any) => void }, scriptVisitor?: { [key: string]: (...args: any) => void }, + options?: { templateBodyTriggerSelector: "Program" | "Program:exit" }, ): object /** @@ -101,6 +100,9 @@ export function define( globalLocationCalculator: LocationCalculatorForHtml | null, { parserOptions }: { parserOptions: ParserOptions }, ): ParserServices { + const templateBodyEmitters = new Map() + const stores = new WeakMap() + const customBlocksEmitters = new Map< ESLintCustomBlockParser, { @@ -121,6 +123,9 @@ export function define( defineTemplateBodyVisitor( templateBodyVisitor: { [key: string]: (...args: any) => void }, scriptVisitor?: { [key: string]: (...args: any) => void }, + options?: { + templateBodyTriggerSelector: "Program" | "Program:exit" + }, ): object { if (scriptVisitor == null) { scriptVisitor = {} //eslint-disable-line no-param-reassign @@ -128,14 +133,16 @@ export function define( if (rootAST.templateBody == null) { return scriptVisitor } + const templateBodyTriggerSelector = + options?.templateBodyTriggerSelector ?? "Program:exit" - let emitter = emitters.get(rootAST) + let emitter = templateBodyEmitters.get(templateBodyTriggerSelector) // If this is the first time, initialize the intermediate event emitter. if (emitter == null) { emitter = new EventEmitter() emitter.setMaxListeners(0) - emitters.set(rootAST, emitter) + templateBodyEmitters.set(templateBodyTriggerSelector, emitter) const programExitHandler = scriptVisitor["Program:exit"] scriptVisitor["Program:exit"] = (node) => { @@ -160,7 +167,7 @@ export function define( // eslint-disable-next-line @mysticatea/ts/ban-ts-ignore // @ts-ignore scriptVisitor["Program:exit"] = programExitHandler - emitters.delete(rootAST) + templateBodyEmitters.delete(templateBodyTriggerSelector) } } } From 0e7bff15ddf61adb8a654a134f0bcf8f1533d30b Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 1 Jul 2021 15:08:24 +0900 Subject: [PATCH 6/6] Update --- README.md | 36 +++++++++++++++++++++++++++++++++++- src/parser-services.ts | 29 +++++++++++++++-------------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c2e06a24..d0768723 100644 --- a/README.md +++ b/README.md @@ -170,13 +170,47 @@ But, it cannot be parsed with Vue 2. ## 🎇 Usage for custom rules / plugins - This parser provides `parserServices` to traverse `