diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml index e01f8e7d..c5ced881 100644 --- a/.github/workflows/NodeCI.yml +++ b/.github/workflows/NodeCI.yml @@ -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: diff --git a/package.json b/package.json index c9fb64a8..042cd1a7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/context/script-let.ts b/src/context/script-let.ts index 5b0c03a6..c991b809 100644 --- a/src/context/script-let.ts +++ b/src/context/script-let.ts @@ -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 = ( es: E, options: ScriptLetCallbackOption, @@ -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) @@ -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(