From 9a7d40d34cfd019b6857aae4942a59402960a0fd Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 11 Oct 2021 22:53:05 +0000 Subject: [PATCH 1/3] Update typescript-eslint monorepo to v5 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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", From cf0bb81fb186cec3d7aeee19d6d29782c4aad0fe Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 14 Oct 2021 12:53:01 +0900 Subject: [PATCH 2/3] Support ts-eslint v5 --- src/context/script-let.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) 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( From 67af272fbffe21215751e59032c51a13a3217cea Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 14 Oct 2021 12:56:16 +0900 Subject: [PATCH 3/3] Add test --- .github/workflows/NodeCI.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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: