From e84a2ba00345c7b6d4c9f5150b1667eb2a0c4830 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Sun, 18 Aug 2024 22:18:37 -0400 Subject: [PATCH] chore!: remove typescript 3 support --- package.json | 1 - src/harmony/harmony-factory.ts | 6 +- src/harmony/versions/index.ts | 1 - src/harmony/versions/three-eight.ts | 158 ---------------------------- test/config.ts | 2 - test/package.json | 2 - test/prepare.mjs | 2 - test/yarn.lock | 37 +------ yarn.lock | 11 -- 9 files changed, 5 insertions(+), 215 deletions(-) delete mode 100644 src/harmony/versions/three-eight.ts diff --git a/package.json b/package.json index 9f5cf4e0..2d07c32a 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "@types/node": "^22.5.2", "@types/ts-expose-internals": "npm:ts-expose-internals@4.9.5", "@types/ts-node": "npm:ts-node@^10.9.2", - "@types/typescript-3": "npm:typescript@3.x", "@types/typescript-4.7": "npm:typescript@4.7.x", "changelogen": "^0.5.5", "eslint": "9.x", diff --git a/src/harmony/harmony-factory.ts b/src/harmony/harmony-factory.ts index 1b002762..3c95f0c2 100644 --- a/src/harmony/harmony-factory.ts +++ b/src/harmony/harmony-factory.ts @@ -1,6 +1,6 @@ import TS from "typescript"; import { TsTransformPathsContext } from "../types"; -import { TsFourSeven, TsThreeEight } from "./versions"; +import { TsFourSeven } from "./versions"; /* ****************************************************************************************************************** */ // region: Types @@ -18,9 +18,7 @@ export interface HarmonyFactory extends TS.NodeFactory {} export function createHarmonyFactory(context: TsTransformPathsContext): HarmonyFactory { return new Proxy(context.tsFactory ?? context.tsInstance, { get(target, prop) { - if (TsThreeEight.predicate(context)) { - return TsThreeEight.handler(context, prop); - } else if (TsFourSeven.predicate(context)) { + if (TsFourSeven.predicate(context)) { return TsFourSeven.handler(context, prop); } else { // @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expression of type 'string | symbol' can't be used to index type 'typeof import("typescript") | NodeFactory'. diff --git a/src/harmony/versions/index.ts b/src/harmony/versions/index.ts index 4fcadcde..457660e4 100644 --- a/src/harmony/versions/index.ts +++ b/src/harmony/versions/index.ts @@ -1,2 +1 @@ -export * as TsThreeEight from "./three-eight"; export * as TsFourSeven from "./four-seven"; diff --git a/src/harmony/versions/three-eight.ts b/src/harmony/versions/three-eight.ts deleted file mode 100644 index e9e615eb..00000000 --- a/src/harmony/versions/three-eight.ts +++ /dev/null @@ -1,158 +0,0 @@ -/** Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-40 */ -import type { - default as TsCurrentModule, - EntityName, - ExportDeclaration, - Expression, - Identifier, - ImportClause, - ImportDeclaration, - ImportTypeAssertionContainer, - ImportTypeNode, - Modifier, - ModuleBody, - ModuleDeclaration, - ModuleName, - NamedExportBindings, - NamedImportBindings, - TypeNode, -} from "typescript"; -import type TsThreeEightModule from "typescript-3"; -import type { TsTransformPathsContext } from "../../types"; -import type { DownSampleTsTypes } from "../utils"; - -/* ****************************************************************************************************************** */ -// region: Mapping -/* ****************************************************************************************************************** */ - -export type TypeMap = [ - [TsCurrentModule.SourceFile, TsThreeEightModule.SourceFile], - [TsCurrentModule.StringLiteral, TsThreeEightModule.StringLiteral], - [TsCurrentModule.CompilerOptions, TsThreeEightModule.CompilerOptions], - // @ts-expect-error typescript 3 doesn't export EmitResolver - [TsCurrentModule.EmitResolver, TsThreeEightModule.EmitResolver], - [TsCurrentModule.CallExpression, TsThreeEightModule.CallExpression], - [TsCurrentModule.ExternalModuleReference, TsThreeEightModule.ExternalModuleReference], - [TsCurrentModule.LiteralTypeNode, TsThreeEightModule.LiteralTypeNode], - [TsCurrentModule.ExternalModuleReference, TsThreeEightModule.ExternalModuleReference], - [TsCurrentModule.ImportTypeNode, TsThreeEightModule.ImportTypeNode], - [TsCurrentModule.EntityName, TsThreeEightModule.EntityName], - [TsCurrentModule.TypeNode, TsThreeEightModule.TypeNode], - [readonly TsCurrentModule.TypeNode[], readonly TsThreeEightModule.TypeNode[]], - [TsCurrentModule.LiteralTypeNode, TsThreeEightModule.LiteralTypeNode], - [TsCurrentModule.ImportDeclaration, TsThreeEightModule.ImportDeclaration], - [TsCurrentModule.ImportClause, TsThreeEightModule.ImportClause], - [TsCurrentModule.Identifier, TsThreeEightModule.Identifier], - [TsCurrentModule.NamedImportBindings, TsThreeEightModule.NamedImportBindings], - [TsCurrentModule.ImportDeclaration, TsThreeEightModule.ImportDeclaration], - [TsCurrentModule.ExportDeclaration, TsThreeEightModule.ExportDeclaration], - [TsCurrentModule.ModuleDeclaration, TsThreeEightModule.ModuleDeclaration], - [TsCurrentModule.Expression, TsThreeEightModule.Expression], - [TsCurrentModule.ModuleBody, TsThreeEightModule.ModuleBody], - [TsCurrentModule.ModuleName, TsThreeEightModule.ModuleName], - [TsCurrentModule.ExportDeclaration["exportClause"], TsThreeEightModule.ExportDeclaration["exportClause"]], -]; - -// endregion - -/* ****************************************************************************************************************** */ -// region: Utils -/* ****************************************************************************************************************** */ - -export const predicate = (context: TsTransformPathsContext) => context.tsVersionMajor < 4; - -export function handler(context: TsTransformPathsContext, prop: string | symbol) { - const ts = context.tsInstance as unknown as typeof TsThreeEightModule; - - switch (prop) { - case "updateCallExpression": { - // @ts-expect-error TS(7019) FIXME: Rest parameter 'args' implicitly has an 'any[]' type. - return (...args) => ts.updateCall.apply(void 0, args); - } - case "updateImportClause": { - return function ( - node: ImportClause, - _isTypeOnly: boolean, - name: Identifier | undefined, - namedBindings: NamedImportBindings | undefined, - ) { - // @ts-expect-error TODO investigate type issue - return ts.updateImportClause.apply(void 0, downSample(node, name, namedBindings)); - }; - } - case "updateImportDeclaration": { - return function ( - node: ImportDeclaration, - _modifiers: readonly Modifier[] | undefined, - importClause: ImportClause | undefined, - moduleSpecifier: Expression, - ) { - const [dsNode, dsImportClause, dsModuleSpecifier] = downSample(node, importClause, moduleSpecifier); - - return ts.updateImportDeclaration( - dsNode, - dsNode.decorators, - dsNode.modifiers, - dsImportClause, - dsModuleSpecifier, - ); - }; - } - case "updateExportDeclaration": { - return function ( - node: ExportDeclaration, - _modifiers: readonly Modifier[] | undefined, - _isTypeOnly: boolean, - exportClause: NamedExportBindings | undefined, - moduleSpecifier: Expression | undefined, - ) { - const [dsNode, dsModuleSpecifier, dsExportClause] = downSample(node, moduleSpecifier, exportClause); - return ts.updateExportDeclaration( - dsNode, - dsNode.decorators, - dsNode.modifiers, - dsExportClause, - dsModuleSpecifier, - dsNode.isTypeOnly, - ); - }; - } - case "updateModuleDeclaration": { - return function ( - node: ModuleDeclaration, - _modifiers: readonly Modifier[] | undefined, - name: ModuleName, - body: ModuleBody | undefined, - ) { - const [dsNode, dsName, dsBody] = downSample(node, name, body); - - return ts.updateModuleDeclaration(dsNode, dsNode.decorators, dsNode.modifiers, dsName, dsBody); - }; - } - case "updateImportTypeNode": { - return function ( - node: ImportTypeNode, - argument: TypeNode, - _assertions: ImportTypeAssertionContainer | undefined, - qualifier: EntityName | undefined, - typeArguments: readonly TypeNode[] | undefined, - isTypeOf?: boolean, - ) { - const [dsNode, dsArgument, dsQualifier, dsTypeArguments] = downSample(node, argument, qualifier, typeArguments); - - return ts.updateImportTypeNode(dsNode, dsArgument, dsQualifier, dsTypeArguments, isTypeOf); - }; - } - default: { - // @ts-expect-error TS(7019) FIXME: Rest parameter 'args' implicitly has an 'any[]' type. - return (...args) => ts[prop](...args); - } - } -} - -export function downSample(...args: T): DownSampleTsTypes { - // @ts-expect-error TS(2322) FIXME: Type 'T' is not assignable to type 'DownSampleTsTypes'. - return args; -} - -// endregion diff --git a/test/config.ts b/test/config.ts index 51bdc5ea..d27a7c4f 100755 --- a/test/config.ts +++ b/test/config.ts @@ -1,10 +1,8 @@ import ts from "typescript"; -import tsThree from "typescript-3"; import tsFourSeven from "typescript-4.7"; import path from "node:path"; export const tsModules = [ - ["3.6.5", tsThree, "typescript-3"], ["4.7.4", tsFourSeven, "typescript-4.7"], ["Latest", ts, "typescript"], ]; diff --git a/test/package.json b/test/package.json index 86340d79..3d19bc39 100755 --- a/test/package.json +++ b/test/package.json @@ -19,10 +19,8 @@ "ts-jest": "^29.2.4", "ts-node": "^10.9.2", "ts-patch": "^3.2.1", - "tsp1": "npm:ts-patch@1.*.*", "tsp2": "npm:ts-patch@2.*.*", "typescript": "^5.5.4", - "typescript-3": "npm:typescript@3.6.5", "typescript-4.7": "npm:typescript@4.7.4", "typescript-transform-paths": "portal:../" }, diff --git a/test/prepare.mjs b/test/prepare.mjs index 9a08fa33..881e5098 100755 --- a/test/prepare.mjs +++ b/test/prepare.mjs @@ -4,7 +4,6 @@ import { symlink } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { patch } from "ts-patch"; -import { patch as patch1 } from "tsp1"; import { patch as patch2 } from "tsp2"; const __dirname = dirname(fileURLToPath(import.meta.url)); // https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules @@ -28,7 +27,6 @@ function patchTsModules() { tspatch(["tsc.js", "typescript.js"], { basedir, dir: basedir }); } - patchTypescript("typescript-3", patch1); patchTypescript("typescript-4.7", patch2); patchTypescript("typescript", patch); } diff --git a/test/yarn.lock b/test/yarn.lock index db309c38..ef42ec46 100644 --- a/test/yarn.lock +++ b/test/yarn.lock @@ -5012,7 +5012,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^7.0.0, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6, glob@npm:^7.1.7": +"glob@npm:^7.0.0, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6": version: 7.2.3 resolution: "glob@npm:7.2.3" dependencies: @@ -6635,7 +6635,7 @@ __metadata: languageName: node linkType: hard -"minimist@npm:^1.2.0, minimist@npm:^1.2.5, minimist@npm:^1.2.6, minimist@npm:^1.2.8": +"minimist@npm:^1.2.0, minimist@npm:^1.2.6, minimist@npm:^1.2.8": version: 1.2.8 resolution: "minimist@npm:1.2.8" checksum: 10c0/19d3fcdca050087b84c2029841a093691a91259a47def2f18222f41e7645a0b7c44ef4b40e88a1e58a40c84d2ef0ee6047c55594d298146d0eb3f6b737c20ce6 @@ -8096,10 +8096,8 @@ __metadata: ts-jest: "npm:^29.2.4" ts-node: "npm:^10.9.2" ts-patch: "npm:^3.2.1" - tsp1: "npm:ts-patch@1.*.*" tsp2: "npm:ts-patch@2.*.*" typescript: "npm:^5.5.4" - typescript-3: "npm:typescript@3.6.5" typescript-4.7: "npm:typescript@4.7.4" typescript-transform-paths: "portal:../" languageName: unknown @@ -8382,7 +8380,7 @@ __metadata: languageName: node linkType: hard -"shelljs@npm:^0.8.4, shelljs@npm:^0.8.5": +"shelljs@npm:^0.8.5": version: 0.8.5 resolution: "shelljs@npm:0.8.5" dependencies: @@ -9170,25 +9168,6 @@ __metadata: languageName: node linkType: hard -"tsp1@npm:ts-patch@1.*.*": - version: 1.4.5 - resolution: "ts-patch@npm:1.4.5" - dependencies: - chalk: "npm:^4.1.0" - glob: "npm:^7.1.7" - global-prefix: "npm:^3.0.0" - minimist: "npm:^1.2.5" - resolve: "npm:^1.20.0" - shelljs: "npm:^0.8.4" - strip-ansi: "npm:^6.0.0" - peerDependencies: - typescript: ">2.7.0" - bin: - ts-patch: bin/cli.js - checksum: 10c0/3e9b0d3838d0fc930f89000206c586485582c7f7f2746f1e4227a6777b10c06c7642395cd88cbd2950a3938da4146d4e8a1fbe0e02f46624764b9d42a01d7470 - languageName: node - linkType: hard - "tsp2@npm:ts-patch@2.*.*": version: 2.1.0 resolution: "ts-patch@npm:2.1.0" @@ -9239,16 +9218,6 @@ __metadata: languageName: node linkType: hard -"typescript-3@npm:typescript@3.6.5": - version: 3.6.5 - resolution: "typescript@npm:3.6.5" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 10c0/b6f0d5d2e2325b28460b8cf3a4a1237d79aec9951ad727014d4ca570327cc5947decec5d262044979cc0a9ab63746b58e6d8438d73d33ce8415e5369d0490dff - languageName: node - linkType: hard - "typescript-4.7@npm:typescript@4.7.4": version: 4.7.4 resolution: "typescript@npm:4.7.4" diff --git a/yarn.lock b/yarn.lock index 5906e919..af8cdd53 100644 --- a/yarn.lock +++ b/yarn.lock @@ -341,16 +341,6 @@ __metadata: languageName: node linkType: hard -"@types/typescript-3@npm:typescript@3.x": - version: 3.9.10 - resolution: "typescript@npm:3.9.10" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 10c0/863cc06070fa18a0f9c6a83265fb4922a8b51bf6f2c6760fb0b73865305ce617ea4bc6477381f9f4b7c3a8cb4a455b054f5469e6e41307733fe6a2bd9aae82f8 - languageName: node - linkType: hard - "@types/typescript-4.7@npm:typescript@4.7.x": version: 4.7.4 resolution: "typescript@npm:4.7.4" @@ -2995,7 +2985,6 @@ __metadata: "@types/node": "npm:^22.5.2" "@types/ts-expose-internals": "npm:ts-expose-internals@4.9.5" "@types/ts-node": "npm:ts-node@^10.9.2" - "@types/typescript-3": "npm:typescript@3.x" "@types/typescript-4.7": "npm:typescript@4.7.x" changelogen: "npm:^0.5.5" eslint: "npm:9.x"