Skip to content

Support for typescript-eslint v5 #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/NodeCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ jobs:
run: npm install
- name: Test
run: npm test
test-for-ts-eslint-v4:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install @typescript-eslint v4
run: |+
npm i -D @typescript-eslint/parser@4 @typescript-eslint/eslint-plugin@4 --legacy-peer-deps
npx rimraf node_modules
- name: Install Packages
run: npm install
- name: Test
run: npm test
test-and-coverage:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"@types/eslint-visitor-keys": "^1.0.0",
"@types/mocha": "^9.0.0",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"code-red": "^0.2.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "^8.0.0",
Expand Down
25 changes: 20 additions & 5 deletions src/context/script-let.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ import type { ESLintExtendedProgram } from "../parser"
import { getWithLoc } from "../parser/converts/common"
import { traverseNodes } from "../traverse"

type TSAsExpression = {
type: "TSAsExpression"
expression: ESTree.Expression
typeAnnotation: TSParenthesizedType | ESTree.Node
}

// TS ESLint v4 Node
type TSParenthesizedType = {
type: "TSParenthesizedType"
typeAnnotation: ESTree.Node
}

export type ScriptLetCallback<E extends ESTree.Node> = (
es: E,
options: ScriptLetCallbackOption,
Expand Down Expand Up @@ -117,9 +129,11 @@ export class ScriptLetContext {
range[0] - 1,
(st, tokens, comments, result) => {
const exprSt = st as ESTree.ExpressionStatement
const node: ESTree.Expression = isTS
? (exprSt.expression as any).expression
: exprSt.expression
const tsAs: TSAsExpression | null = isTS
? (exprSt.expression as any)
: null
const node: ESTree.Expression =
tsAs?.expression || exprSt.expression
// Process for nodes
for (const callback of callbacks) {
callback(node as E, result)
Expand All @@ -134,8 +148,9 @@ export class ScriptLetContext {
removeScope(
result.scopeManager,
result.getScope(
(exprSt.expression as any).typeAnnotation
.typeAnnotation,
tsAs!.typeAnnotation.type === "TSParenthesizedType"
? tsAs!.typeAnnotation.typeAnnotation
: tsAs!.typeAnnotation,
),
)
this.remapNodes(
Expand Down