diff --git a/.changeset/chilly-numbers-smell.md b/.changeset/chilly-numbers-smell.md new file mode 100644 index 00000000..2804b9ab --- /dev/null +++ b/.changeset/chilly-numbers-smell.md @@ -0,0 +1,5 @@ +--- +"astro-eslint-parser": patch +--- + +fix: crash in scope analysis when using espree diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml index 83207b60..15e74da2 100644 --- a/.github/workflows/NodeCI.yml +++ b/.github/workflows/NodeCI.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [20.x, 22.x] + node-version: [18.x, 20.x, 22.x] steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} @@ -33,26 +33,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: Install Packages - run: npm install --legacy-peer-deps - - name: Test - run: npm test - test-for-old-node: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18.x] - steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - name: Install old versions - run: |+ - npm i -D @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 --legacy-peer-deps - npx rimraf node_modules - - name: Install Packages - run: npm install --legacy-peer-deps + run: npm install -f - name: Test run: npm test test-for-eslint-v7: @@ -68,10 +49,10 @@ jobs: node-version: ${{ matrix.node-version }} - name: Install eslint v7 run: |+ - npm i -D eslint@7 @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 --legacy-peer-deps + npm i -D eslint@7 @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 -f npx rimraf node_modules - name: Install Packages - run: npm install --legacy-peer-deps + run: npm install -f - name: Test run: npm test test-and-coverage: @@ -84,6 +65,6 @@ jobs: - name: Test run: npm run cover - name: Coveralls GitHub Action - uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # v2.2.3 + uses: coverallsapp/github-action@v2.2.3 with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index 97fbad50..8a7f657b 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "astrojs-compiler-sync": "^1.0.0", "debug": "^4.3.4", "entities": "^4.5.0", + "eslint-scope": "^8.0.1", "eslint-visitor-keys": "^4.0.0", "espree": "^10.0.0", "globby": "^11.1.0", diff --git a/src/parser/script.ts b/src/parser/script.ts index aa3a9851..6507bfdc 100644 --- a/src/parser/script.ts +++ b/src/parser/script.ts @@ -1,10 +1,17 @@ import type { Context } from "../context"; import { debug } from "../debug"; -import type { ParserOptionsContext } from "../context/parser-options"; +import type { + ParserOptions, + ParserOptionsContext, +} from "../context/parser-options"; import type { ESLintExtendedProgram } from "../types"; import { tsPatch } from "./ts-patch"; import { isEnhancedParserObject } from "../context/resolve-parser/parser-object"; -import { analyze } from "@typescript-eslint/scope-manager"; +import type { ScopeManager } from "@typescript-eslint/scope-manager"; +import { analyze as analyzeForTypeScript } from "@typescript-eslint/scope-manager"; +import { analyze as analyzeForEcmaScript } from "eslint-scope"; +import { KEYS } from "../visitor-keys"; +import { getKeys } from "../traverse"; /** * Parse for script */ @@ -17,17 +24,45 @@ export function parseScript( const parserOptions = parserOptionsCtx.parserOptions; if (!result.scopeManager && parserOptions.eslintScopeManager) { - result.scopeManager = analyze(result.ast, { - ecmaVersion: 1e8, + result.scopeManager = analyzeScope(result, parserOptions); + } + + return result; +} + +/** + * Analyze scope + */ +function analyzeScope( + result: ESLintExtendedProgram, + parserOptions: ParserOptions, +): ScopeManager { + try { + return analyzeForTypeScript(result.ast, { globalReturn: parserOptions.ecmaFeatures?.globalReturn, jsxPragma: parserOptions.jsxPragma, jsxFragmentName: parserOptions.jsxFragmentName, lib: parserOptions.lib, sourceType: parserOptions.sourceType, }); + } catch { + // ignore } + const ecmaFeatures = parserOptions.ecmaFeatures || {}; - return result; + return analyzeForEcmaScript(result.ast, { + ignoreEval: true, + nodejsScope: ecmaFeatures.globalReturn, + impliedStrict: ecmaFeatures.impliedStrict as never, + ecmaVersion: 1e8, + sourceType: + parserOptions.sourceType === "commonjs" + ? "script" + : parserOptions.sourceType || "script", + // @ts-expect-error -- Type bug? + childVisitorKeys: result.visitorKeys || KEYS, + fallback: getKeys, + }) as ScopeManager; } /** diff --git a/tests/fixtures/parser/ast/js-jsx01-requirements.json b/tests/fixtures/parser/ast/js-jsx01-requirements.json new file mode 100644 index 00000000..2484807f --- /dev/null +++ b/tests/fixtures/parser/ast/js-jsx01-requirements.json @@ -0,0 +1,5 @@ +{ + "scope": { + "@typescript-eslint/parser" : ">=7" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/js-jsx01-scope-output.json b/tests/fixtures/parser/ast/js-jsx01-scope-output.json index ec747fa4..8f35cf53 100644 --- a/tests/fixtures/parser/ast/js-jsx01-scope-output.json +++ b/tests/fixtures/parser/ast/js-jsx01-scope-output.json @@ -1 +1,180 @@ -null \ No newline at end of file +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "MyComponent", + "identifiers": [ + { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 11, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 11, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 11, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "range": [ + 11, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "JSXIdentifier", + "name": "MyComponent", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 11, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "JSXIdentifier", + "name": "MyComponent", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "MyComponent", + "range": [ + 11, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/js-test01-input.astro b/tests/fixtures/parser/ast/js-test01-input.astro new file mode 100644 index 00000000..b2d8d1aa --- /dev/null +++ b/tests/fixtures/parser/ast/js-test01-input.astro @@ -0,0 +1,19 @@ +--- +const sidebarSections = [{ text: "foo" }] +--- + + + + diff --git a/tests/fixtures/parser/ast/js-test01-output.json b/tests/fixtures/parser/ast/js-test01-output.json new file mode 100644 index 00000000..73831289 --- /dev/null +++ b/tests/fixtures/parser/ast/js-test01-output.json @@ -0,0 +1,2683 @@ +{ + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "text", + "range": [ + 31, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 31 + } + } + }, + "method": false, + "shorthand": false, + "value": { + "type": "Literal", + "raw": "\"foo\"", + "value": "foo", + "range": [ + 37, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + "range": [ + 31, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 38 + } + } + } + ], + "range": [ + 29, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 40 + } + } + } + ], + "range": [ + 28, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + "range": [ + 10, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 41 + } + } + } + ], + "range": [ + 4, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + { + "type": "AstroFragment", + "children": [ + { + "type": "JSXElement", + "children": [ + { + "type": "JSXText", + "raw": "\n ", + "value": "\n ", + "range": [ + 84, + 87 + ], + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "JSXElement", + "children": [ + { + "type": "JSXText", + "raw": "\n ", + "value": "\n ", + "range": [ + 110, + 115 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 7, + "column": 4 + } + } + }, + { + "type": "JSXExpressionContainer", + "expression": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "JSXElement", + "children": [ + { + "type": "JSXText", + "raw": "\n ", + "value": "\n ", + "range": [ + 161, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + { + "type": "JSXElement", + "children": [ + { + "type": "JSXExpressionContainer", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "section", + "range": [ + 194, + 201 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 9, + "column": 39 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "text", + "range": [ + 202, + 206 + ], + "loc": { + "start": { + "line": 9, + "column": 40 + }, + "end": { + "line": 9, + "column": 44 + } + } + }, + "range": [ + 194, + 206 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 9, + "column": 44 + } + } + }, + "range": [ + 193, + 207 + ], + "loc": { + "start": { + "line": 9, + "column": 31 + }, + "end": { + "line": 9, + "column": 45 + } + } + } + ], + "closingElement": { + "type": "JSXClosingElement", + "name": { + "type": "JSXIdentifier", + "name": "div", + "range": [ + 209, + 212 + ], + "loc": { + "start": { + "line": 9, + "column": 47 + }, + "end": { + "line": 9, + "column": 50 + } + } + }, + "range": [ + 207, + 213 + ], + "loc": { + "start": { + "line": 9, + "column": 45 + }, + "end": { + "line": 9, + "column": 51 + } + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "name": { + "type": "JSXIdentifier", + "name": "div", + "range": [ + 171, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "attributes": [ + { + "type": "JSXAttribute", + "name": { + "type": "JSXIdentifier", + "name": "class", + "range": [ + 175, + 180 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 18 + } + } + }, + "value": { + "type": "Literal", + "raw": "\"nav-group\"", + "value": "nav-group", + "range": [ + 181, + 192 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 30 + } + } + }, + "range": [ + 175, + 192 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 30 + } + } + } + ], + "selfClosing": false, + "range": [ + 170, + 193 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 31 + } + } + }, + "range": [ + 170, + 213 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 51 + } + } + }, + { + "type": "JSXText", + "raw": "\n ", + "value": "\n ", + "range": [ + 213, + 220 + ], + "loc": { + "start": { + "line": 9, + "column": 51 + }, + "end": { + "line": 10, + "column": 6 + } + } + } + ], + "closingElement": { + "type": "JSXClosingElement", + "name": { + "type": "JSXIdentifier", + "name": "li", + "range": [ + 222, + 224 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 10 + } + } + }, + "range": [ + 220, + 225 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 11 + } + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "name": { + "type": "JSXIdentifier", + "name": "li", + "range": [ + 158, + 160 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + "attributes": [], + "selfClosing": false, + "range": [ + 157, + 161 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 10 + } + } + }, + "range": [ + 157, + 225 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 10, + "column": 11 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "section", + "range": [ + 137, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 33 + } + } + } + ], + "range": [ + 136, + 231 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 11, + "column": 5 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 116, + 131 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "map", + "range": [ + 132, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + "range": [ + 116, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + "optional": false, + "range": [ + 116, + 232 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 11, + "column": 6 + } + } + }, + "range": [ + 115, + 233 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 11, + "column": 7 + } + } + }, + { + "type": "JSXText", + "raw": "\n ", + "value": "\n ", + "range": [ + 233, + 236 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 12, + "column": 2 + } + } + } + ], + "closingElement": { + "type": "JSXClosingElement", + "name": { + "type": "JSXIdentifier", + "name": "ul", + "range": [ + 238, + 240 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 6 + } + } + }, + "range": [ + 236, + 241 + ], + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "name": { + "type": "JSXIdentifier", + "name": "ul", + "range": [ + 88, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + "attributes": [ + { + "type": "JSXAttribute", + "name": { + "type": "JSXIdentifier", + "name": "class", + "range": [ + 91, + 96 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + "value": { + "type": "Literal", + "raw": "\"nav-groups\"", + "value": "nav-groups", + "range": [ + 97, + 109 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 24 + } + } + }, + "range": [ + 91, + 109 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 24 + } + } + } + ], + "selfClosing": false, + "range": [ + 87, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 87, + 241 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + { + "type": "JSXText", + "raw": "\n", + "value": "\n", + "range": [ + 241, + 242 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 13, + "column": 0 + } + } + } + ], + "closingElement": { + "type": "JSXClosingElement", + "name": { + "type": "JSXIdentifier", + "name": "nav", + "range": [ + 244, + 247 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 5 + } + } + }, + "range": [ + 242, + 248 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 6 + } + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "name": { + "type": "JSXIdentifier", + "name": "nav", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 4 + } + } + }, + "attributes": [ + { + "type": "JSXAttribute", + "name": { + "type": "JSXIdentifier", + "name": "aria-labelledby", + "range": [ + 56, + 71 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + "value": { + "type": "Literal", + "raw": "\"grid-left\"", + "value": "grid-left", + "range": [ + 72, + 83 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 32 + } + } + }, + "range": [ + 56, + 83 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 32 + } + } + } + ], + "selfClosing": false, + "range": [ + 51, + 84 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "range": [ + 51, + 248 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 13, + "column": 6 + } + } + }, + { + "type": "JSXText", + "raw": "\n\n", + "value": "\n\n", + "range": [ + 248, + 250 + ], + "loc": { + "start": { + "line": 13, + "column": 6 + }, + "end": { + "line": 15, + "column": 0 + } + } + }, + { + "type": "JSXElement", + "children": [ + { + "type": "AstroRawText", + "value": "\n .nav-groups > li + li {\n margin-top: 2rem;\n }\n", + "raw": "\n .nav-groups > li + li {\n margin-top: 2rem;\n }\n", + "range": [ + 257, + 310 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 19, + "column": 0 + } + } + } + ], + "closingElement": { + "type": "JSXClosingElement", + "name": { + "type": "JSXIdentifier", + "name": "style", + "range": [ + 312, + 317 + ], + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "range": [ + 310, + 318 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "name": { + "type": "JSXIdentifier", + "name": "style", + "range": [ + 251, + 256 + ], + "loc": { + "start": { + "line": 15, + "column": 1 + }, + "end": { + "line": 15, + "column": 6 + } + } + }, + "attributes": [], + "selfClosing": false, + "range": [ + 250, + 257 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 7 + } + } + }, + "range": [ + 250, + 318 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + { + "type": "JSXText", + "raw": "\n", + "value": "\n", + "range": [ + 318, + 319 + ], + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 20, + "column": 0 + } + } + } + ], + "range": [ + 51, + 319 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 20, + "column": 0 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "---", + "range": [ + 0, + 3 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 4, + 9 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "text", + "range": [ + 31, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "String", + "value": "\"foo\"", + "range": [ + 37, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 40 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + { + "type": "Punctuator", + "value": "---", + "range": [ + 46, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "JSXIdentifier", + "value": "nav", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 4 + } + } + }, + { + "type": "JSXIdentifier", + "value": "aria-labelledby", + "range": [ + 56, + 71 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + }, + { + "type": "JSXText", + "value": "\"grid-left\"", + "range": [ + 72, + 83 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + { + "type": "JSXText", + "value": "\n ", + "range": [ + 84, + 87 + ], + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + { + "type": "JSXIdentifier", + "value": "ul", + "range": [ + 88, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + { + "type": "JSXIdentifier", + "value": "class", + "range": [ + 91, + 96 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 96, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + { + "type": "JSXText", + "value": "\"nav-groups\"", + "range": [ + 97, + 109 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + { + "type": "JSXText", + "value": "\n ", + "range": [ + 110, + 115 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 7, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "sidebarSections", + "range": [ + 116, + 131 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "map", + "range": [ + 132, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 7, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "section", + "range": [ + 137, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 7, + "column": 33 + }, + "end": { + "line": 7, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 146, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 35 + }, + "end": { + "line": 7, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 157, + 158 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + { + "type": "JSXIdentifier", + "value": "li", + "range": [ + 158, + 160 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 160, + 161 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 10 + } + } + }, + { + "type": "JSXText", + "value": "\n ", + "range": [ + 161, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + { + "type": "JSXIdentifier", + "value": "div", + "range": [ + 171, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "JSXIdentifier", + "value": "class", + "range": [ + 175, + 180 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 180, + 181 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + { + "type": "JSXText", + "value": "\"nav-group\"", + "range": [ + 181, + 192 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 192, + 193 + ], + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 193, + 194 + ], + "loc": { + "start": { + "line": 9, + "column": 31 + }, + "end": { + "line": 9, + "column": 32 + } + } + }, + { + "type": "Identifier", + "value": "section", + "range": [ + 194, + 201 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 9, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 201, + 202 + ], + "loc": { + "start": { + "line": 9, + "column": 39 + }, + "end": { + "line": 9, + "column": 40 + } + } + }, + { + "type": "Identifier", + "value": "text", + "range": [ + 202, + 206 + ], + "loc": { + "start": { + "line": 9, + "column": 40 + }, + "end": { + "line": 9, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 206, + 207 + ], + "loc": { + "start": { + "line": 9, + "column": 44 + }, + "end": { + "line": 9, + "column": 45 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 207, + 208 + ], + "loc": { + "start": { + "line": 9, + "column": 45 + }, + "end": { + "line": 9, + "column": 46 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 208, + 209 + ], + "loc": { + "start": { + "line": 9, + "column": 46 + }, + "end": { + "line": 9, + "column": 47 + } + } + }, + { + "type": "JSXIdentifier", + "value": "div", + "range": [ + 209, + 212 + ], + "loc": { + "start": { + "line": 9, + "column": 47 + }, + "end": { + "line": 9, + "column": 50 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 212, + 213 + ], + "loc": { + "start": { + "line": 9, + "column": 50 + }, + "end": { + "line": 9, + "column": 51 + } + } + }, + { + "type": "JSXText", + "value": "\n ", + "range": [ + 213, + 220 + ], + "loc": { + "start": { + "line": 9, + "column": 51 + }, + "end": { + "line": 10, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 220, + 221 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 221, + 222 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + } + } + }, + { + "type": "JSXIdentifier", + "value": "li", + "range": [ + 222, + 224 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 224, + 225 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 230, + 231 + ], + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 231, + 232 + ], + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 232, + 233 + ], + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 7 + } + } + }, + { + "type": "JSXText", + "value": "\n ", + "range": [ + 233, + 236 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 12, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 236, + 237 + ], + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 237, + 238 + ], + "loc": { + "start": { + "line": 12, + "column": 3 + }, + "end": { + "line": 12, + "column": 4 + } + } + }, + { + "type": "JSXIdentifier", + "value": "ul", + "range": [ + 238, + 240 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 240, + 241 + ], + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + { + "type": "JSXText", + "value": "\n", + "range": [ + 241, + 242 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 13, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 242, + 243 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 243, + 244 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 2 + } + } + }, + { + "type": "JSXIdentifier", + "value": "nav", + "range": [ + 244, + 247 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 247, + 248 + ], + "loc": { + "start": { + "line": 13, + "column": 5 + }, + "end": { + "line": 13, + "column": 6 + } + } + }, + { + "type": "JSXText", + "value": "\n\n", + "range": [ + 248, + 250 + ], + "loc": { + "start": { + "line": 13, + "column": 6 + }, + "end": { + "line": 15, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 250, + 251 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 1 + } + } + }, + { + "type": "JSXIdentifier", + "value": "style", + "range": [ + 251, + 256 + ], + "loc": { + "start": { + "line": 15, + "column": 1 + }, + "end": { + "line": 15, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 256, + 257 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + } + }, + { + "type": "JSXText", + "value": "\n .nav-groups > li + li {\n margin-top: 2rem;\n }\n", + "range": [ + 257, + 310 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 19, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 310, + 311 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 311, + 312 + ], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "JSXIdentifier", + "value": "style", + "range": [ + 312, + 317 + ], + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 317, + 318 + ], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + { + "type": "JSXText", + "value": "\n", + "range": [ + 318, + 319 + ], + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 20, + "column": 0 + } + } + } + ], + "range": [ + 0, + 319 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 20, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/js-test01-scope-output.json b/tests/fixtures/parser/ast/js-test01-scope-output.json new file mode 100644 index 00000000..6c99b876 --- /dev/null +++ b/tests/fixtures/parser/ast/js-test01-scope-output.json @@ -0,0 +1,882 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "sidebarSections", + "identifiers": [ + { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "text", + "range": [ + 31, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 31 + } + } + }, + "method": false, + "shorthand": false, + "value": { + "type": "Literal", + "raw": "\"foo\"", + "value": "foo", + "range": [ + 37, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + "range": [ + 31, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 38 + } + } + } + ], + "range": [ + 29, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 40 + } + } + } + ], + "range": [ + 28, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + "range": [ + 10, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 41 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 116, + 131 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 116, + 131 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "sidebarSections", + "range": [ + 10, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "section", + "identifiers": [ + { + "type": "Identifier", + "name": "section", + "range": [ + 137, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 33 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "section", + "range": [ + 137, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 33 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "JSXElement", + "children": [ + { + "type": "JSXText", + "raw": "\n ", + "value": "\n ", + "range": [ + 161, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + { + "type": "JSXElement", + "children": [ + { + "type": "JSXExpressionContainer", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "section", + "range": [ + 194, + 201 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 9, + "column": 39 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "text", + "range": [ + 202, + 206 + ], + "loc": { + "start": { + "line": 9, + "column": 40 + }, + "end": { + "line": 9, + "column": 44 + } + } + }, + "range": [ + 194, + 206 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 9, + "column": 44 + } + } + }, + "range": [ + 193, + 207 + ], + "loc": { + "start": { + "line": 9, + "column": 31 + }, + "end": { + "line": 9, + "column": 45 + } + } + } + ], + "closingElement": { + "type": "JSXClosingElement", + "name": { + "type": "JSXIdentifier", + "name": "div", + "range": [ + 209, + 212 + ], + "loc": { + "start": { + "line": 9, + "column": 47 + }, + "end": { + "line": 9, + "column": 50 + } + } + }, + "range": [ + 207, + 213 + ], + "loc": { + "start": { + "line": 9, + "column": 45 + }, + "end": { + "line": 9, + "column": 51 + } + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "name": { + "type": "JSXIdentifier", + "name": "div", + "range": [ + 171, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "attributes": [ + { + "type": "JSXAttribute", + "name": { + "type": "JSXIdentifier", + "name": "class", + "range": [ + 175, + 180 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 18 + } + } + }, + "value": { + "type": "Literal", + "raw": "\"nav-group\"", + "value": "nav-group", + "range": [ + 181, + 192 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 30 + } + } + }, + "range": [ + 175, + 192 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 30 + } + } + } + ], + "selfClosing": false, + "range": [ + 170, + 193 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 31 + } + } + }, + "range": [ + 170, + 213 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 51 + } + } + }, + { + "type": "JSXText", + "raw": "\n ", + "value": "\n ", + "range": [ + 213, + 220 + ], + "loc": { + "start": { + "line": 9, + "column": 51 + }, + "end": { + "line": 10, + "column": 6 + } + } + } + ], + "closingElement": { + "type": "JSXClosingElement", + "name": { + "type": "JSXIdentifier", + "name": "li", + "range": [ + 222, + 224 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 10 + } + } + }, + "range": [ + 220, + 225 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 11 + } + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "name": { + "type": "JSXIdentifier", + "name": "li", + "range": [ + 158, + 160 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + "attributes": [], + "selfClosing": false, + "range": [ + 157, + 161 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 10 + } + } + }, + "range": [ + 157, + 225 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 10, + "column": 11 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "section", + "range": [ + 137, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 33 + } + } + } + ], + "range": [ + 136, + 231 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 11, + "column": 5 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "section", + "range": [ + 194, + 201 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 9, + "column": 39 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "section", + "range": [ + 137, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 33 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "section", + "range": [ + 194, + 201 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 9, + "column": 39 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "section", + "range": [ + 137, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 33 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/js-test01-semi-result.json b/tests/fixtures/parser/ast/js-test01-semi-result.json new file mode 100644 index 00000000..21fbc9e3 --- /dev/null +++ b/tests/fixtures/parser/ast/js-test01-semi-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "semi", + "code": "\n", + "line": 2, + "column": 42 + } +] \ No newline at end of file diff --git a/tests/src/parser/test-utils.ts b/tests/src/parser/test-utils.ts index 08e684f6..a4b61b80 100644 --- a/tests/src/parser/test-utils.ts +++ b/tests/src/parser/test-utils.ts @@ -31,6 +31,7 @@ export function getBasicParserOptions( project: require.resolve("../../fixtures/tsconfig.test.json"), extraFileExtensions: [".astro", ".md"], sourceType: "module", + eslintScopeManager: true, }; }