Skip to content

Commit 1da004b

Browse files
Support for typescript-eslint v5 (#95)
* Update typescript-eslint monorepo to v5 * Support ts-eslint v5 * Add test Co-authored-by: Renovate Bot <[email protected]>
1 parent 8a51f07 commit 1da004b

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

.github/workflows/NodeCI.yml

+19
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ jobs:
3333
run: npm install
3434
- name: Test
3535
run: npm test
36+
test-for-ts-eslint-v4:
37+
runs-on: ubuntu-latest
38+
strategy:
39+
matrix:
40+
node-version: [14.x]
41+
steps:
42+
- uses: actions/checkout@v2
43+
- name: Use Node.js ${{ matrix.node-version }}
44+
uses: actions/setup-node@v2
45+
with:
46+
node-version: ${{ matrix.node-version }}
47+
- name: Install @typescript-eslint v4
48+
run: |+
49+
npm i -D @typescript-eslint/parser@4 @typescript-eslint/eslint-plugin@4 --legacy-peer-deps
50+
npx rimraf node_modules
51+
- name: Install Packages
52+
run: npm install
53+
- name: Test
54+
run: npm test
3655
test-and-coverage:
3756
runs-on: ubuntu-latest
3857
steps:

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
"@types/eslint-visitor-keys": "^1.0.0",
5252
"@types/mocha": "^9.0.0",
5353
"@types/node": "^14.0.13",
54-
"@typescript-eslint/eslint-plugin": "^4.9.1",
55-
"@typescript-eslint/parser": "^4.9.1",
54+
"@typescript-eslint/eslint-plugin": "^5.0.0",
55+
"@typescript-eslint/parser": "^5.0.0",
5656
"code-red": "^0.2.0",
5757
"eslint": "^7.5.0",
5858
"eslint-config-prettier": "^8.0.0",

src/context/script-let.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ import type { ESLintExtendedProgram } from "../parser"
1414
import { getWithLoc } from "../parser/converts/common"
1515
import { traverseNodes } from "../traverse"
1616

17+
type TSAsExpression = {
18+
type: "TSAsExpression"
19+
expression: ESTree.Expression
20+
typeAnnotation: TSParenthesizedType | ESTree.Node
21+
}
22+
23+
// TS ESLint v4 Node
24+
type TSParenthesizedType = {
25+
type: "TSParenthesizedType"
26+
typeAnnotation: ESTree.Node
27+
}
28+
1729
export type ScriptLetCallback<E extends ESTree.Node> = (
1830
es: E,
1931
options: ScriptLetCallbackOption,
@@ -117,9 +129,11 @@ export class ScriptLetContext {
117129
range[0] - 1,
118130
(st, tokens, comments, result) => {
119131
const exprSt = st as ESTree.ExpressionStatement
120-
const node: ESTree.Expression = isTS
121-
? (exprSt.expression as any).expression
122-
: exprSt.expression
132+
const tsAs: TSAsExpression | null = isTS
133+
? (exprSt.expression as any)
134+
: null
135+
const node: ESTree.Expression =
136+
tsAs?.expression || exprSt.expression
123137
// Process for nodes
124138
for (const callback of callbacks) {
125139
callback(node as E, result)
@@ -134,8 +148,9 @@ export class ScriptLetContext {
134148
removeScope(
135149
result.scopeManager,
136150
result.getScope(
137-
(exprSt.expression as any).typeAnnotation
138-
.typeAnnotation,
151+
tsAs!.typeAnnotation.type === "TSParenthesizedType"
152+
? tsAs!.typeAnnotation.typeAnnotation
153+
: tsAs!.typeAnnotation,
139154
),
140155
)
141156
this.remapNodes(

0 commit comments

Comments
 (0)