Skip to content

Commit 4b83588

Browse files
authored
chore: update deps and fixtures (#358)
* chore: update deps and fixtures * Fixed `no-undef` crash for omit closing tag * Create wet-turtles-jam.md * fix * update * update
1 parent 768fd09 commit 4b83588

28 files changed

Lines changed: 1868 additions & 105 deletions

.changeset/wet-turtles-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro-eslint-parser": patch
3+
---
4+
5+
Fixed the parser issue where `no-undef` rule would crash if closing tag was omitted

.github/workflows/NodeCI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: npm install -f
3737
- name: Test
3838
run: npm test
39-
test-for-eslint-v7:
39+
test-for-eslint-v8:
4040
runs-on: ubuntu-latest
4141
strategy:
4242
matrix:
@@ -47,9 +47,9 @@ jobs:
4747
uses: actions/setup-node@v4
4848
with:
4949
node-version: ${{ matrix.node-version }}
50-
- name: Install eslint v7
50+
- name: Install eslint v8
5151
run: |+
52-
npm i -D eslint@7 @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 -f
52+
npm i -D eslint@8 -f
5353
npx rimraf node_modules
5454
- name: Install Packages
5555
run: npm install -f

.npmrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
package-lock=false
1+
package-lock=false
2+
force=true

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"@astrojs/compiler": "^2.0.0",
5252
"@typescript-eslint/scope-manager": "^7.0.0 || ^8.0.0",
5353
"@typescript-eslint/types": "^7.0.0 || ^8.0.0",
54-
"@typescript-eslint/typescript-estree": "^7.0.0 || ^8.0.0",
5554
"astrojs-compiler-sync": "^1.0.0",
5655
"debug": "^4.3.4",
5756
"entities": "^4.5.0",
@@ -76,8 +75,9 @@
7675
"@types/mocha": "^10.0.0",
7776
"@types/node": "^22.0.0",
7877
"@types/semver": "^7.3.9",
79-
"@typescript-eslint/eslint-plugin": "^8.0.0",
80-
"@typescript-eslint/parser": "^8.0.0",
78+
"@typescript-eslint/eslint-plugin": "^8.21.0",
79+
"@typescript-eslint/parser": "^8.21.0",
80+
"@typescript-eslint/typescript-estree": "^8.21.0",
8181
"astro": "^5.0.0",
8282
"astro-eslint-parser": ">=0.1.0",
8383
"benchmark": "^2.1.4",

src/parser/process-template.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
JSXElement,
2525
} from "../ast";
2626
import type { AttributeNode } from "@astrojs/compiler/types";
27+
import { removeAllScopeAndVariableAndReference } from "./scope";
2728

2829
/**
2930
* Process the template to generate a ScriptContext.
@@ -416,6 +417,10 @@ export function processTemplate(
416417
scriptNode.type === AST_NODE_TYPES.JSXClosingElement &&
417418
parent.type === AST_NODE_TYPES.JSXElement
418419
) {
420+
removeAllScopeAndVariableAndReference(scriptNode, {
421+
visitorKeys: context.result.visitorKeys,
422+
scopeManager: context.result.scopeManager!,
423+
});
419424
parent.closingElement = null;
420425
return true;
421426
}

src/parser/scope/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ export function removeAllScopeAndVariableAndReference(
4040
scopeManager: ScopeManager;
4141
},
4242
): void {
43-
const targetScopes = new Set<Scope>();
43+
const removeTargetScopes = new Set<Scope>();
4444
traverseNodes(target, {
4545
visitorKeys: info.visitorKeys,
4646
enterNode(node) {
4747
const scope = info.scopeManager.acquire(node);
4848
if (scope) {
49-
targetScopes.add(scope);
49+
removeTargetScopes.add(scope);
5050
return;
5151
}
52-
if (node.type === "Identifier") {
52+
if (node.type === "Identifier" || node.type === "JSXIdentifier") {
5353
let scope = getInnermostScopeFromNode(info.scopeManager, node);
5454
while (
5555
scope &&
@@ -59,7 +59,7 @@ export function removeAllScopeAndVariableAndReference(
5959
) {
6060
scope = scope.upper!;
6161
}
62-
if (targetScopes.has(scope)) {
62+
if (removeTargetScopes.has(scope)) {
6363
return;
6464
}
6565

@@ -72,7 +72,7 @@ export function removeAllScopeAndVariableAndReference(
7272
},
7373
});
7474

75-
for (const scope of targetScopes) {
75+
for (const scope of removeTargetScopes) {
7676
removeScope(info.scopeManager, scope);
7777
}
7878
}
@@ -221,7 +221,7 @@ function removeReference(reference: Reference, baseScope: Scope): void {
221221

222222
/** Remove variable */
223223
function removeIdentifierVariable(
224-
node: TSESTree.Identifier,
224+
node: TSESTree.Identifier | TSESTree.JSXIdentifier,
225225
scope: Scope,
226226
): void {
227227
for (let varIndex = 0; varIndex < scope.variables.length; varIndex++) {
@@ -244,7 +244,7 @@ function removeIdentifierVariable(
244244
scope.set.delete(name);
245245
}
246246
} else {
247-
const idIndex = variable.identifiers.indexOf(node);
247+
const idIndex = variable.identifiers.indexOf(node as TSESTree.Identifier);
248248
if (idIndex >= 0) {
249249
variable.identifiers.splice(idIndex, 1);
250250
}
@@ -255,7 +255,7 @@ function removeIdentifierVariable(
255255

256256
/** Remove reference */
257257
function removeIdentifierReference(
258-
node: TSESTree.Identifier,
258+
node: TSESTree.Identifier | TSESTree.JSXIdentifier,
259259
scope: Scope,
260260
): boolean {
261261
const reference = scope.references.find((ref) => ref.identifier === node);

src/parser/script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function parseScriptInternal(
107107
"`astro-eslint-parser` does not support the `projectService` option, it will parse it as `project: true` instead.",
108108
);
109109
patchResult = tsPatch(
110-
{ ...parserOptions, project: true },
110+
{ ...parserOptions, project: true, projectService: undefined },
111111
parserOptionsCtx.getTSParserName()!,
112112
);
113113
}

tests/fixtures/parser/ast/alpinejs02-no-undef-result.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,34 @@
55
"line": 1,
66
"column": 2
77
},
8+
{
9+
"ruleId": "no-undef",
10+
"code": "Button",
11+
"line": 1,
12+
"column": 47
13+
},
814
{
915
"ruleId": "no-undef",
1016
"code": "Button",
1117
"line": 3,
1218
"column": 2
1319
},
20+
{
21+
"ruleId": "no-undef",
22+
"code": "Button",
23+
"line": 3,
24+
"column": 51
25+
},
1426
{
1527
"ruleId": "no-undef",
1628
"code": "Button",
1729
"line": 5,
1830
"column": 2
31+
},
32+
{
33+
"ruleId": "no-undef",
34+
"code": "Button",
35+
"line": 5,
36+
"column": 42
1937
}
2038
]

0 commit comments

Comments
 (0)