Skip to content

Commit

Permalink
Merge pull request #2092 from nestjs/chore/drop-support-for-old-types…
Browse files Browse the repository at this point in the history
…cript

chore: drop support for typescript < 4.8
  • Loading branch information
kamilmysliwiec committed Jun 14, 2023
2 parents 864b6c0 + 6164879 commit 1e607ce
Showing 1 changed file with 15 additions and 39 deletions.
54 changes: 15 additions & 39 deletions lib/compiler/hooks/tsconfig-paths.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export function tsconfigPathsBeforeHookFactory(
compilerOptions: ts.CompilerOptions,
) {
const tsBinary = new TypeScriptBinaryLoader().load();
const [tsVersionMajor, tsVersionMinor] = tsBinary.versionMajorMinor
?.split('.')
.map((x) => +x);
const isInUpdatedAstContext = tsVersionMinor >= 8 || tsVersionMajor > 4;

const { paths = {}, baseUrl = './' } = compilerOptions;
const matcher = tsPaths.createMatchPath(baseUrl!, paths, ['main']);

Expand Down Expand Up @@ -45,43 +40,24 @@ export function tsconfigPathsBeforeHookFactory(
).moduleSpecifier.parent;

if (tsBinary.isImportDeclaration(node)) {
const updatedNode = isInUpdatedAstContext
? (tsBinary.factory as any).updateImportDeclaration(
node,
node.modifiers,
node.importClause,
moduleSpecifier,
node.assertClause,
)
: tsBinary.factory.updateImportDeclaration(
node,
node.decorators,
node.modifiers,
node.importClause,
moduleSpecifier,
node.assertClause,
);
const updatedNode = tsBinary.factory.updateImportDeclaration(
node,
node.modifiers,
node.importClause,
moduleSpecifier,
node.assertClause,
);
(updatedNode as any).flags = node.flags;
return updatedNode;
} else {
const updatedNode = isInUpdatedAstContext
? (tsBinary.factory as any).updateExportDeclaration(
node,
node.modifiers,
node.isTypeOnly,
node.exportClause,
moduleSpecifier,
node.assertClause,
)
: tsBinary.factory.updateExportDeclaration(
node,
node.decorators,
node.modifiers,
node.isTypeOnly,
node.exportClause,
moduleSpecifier,
node.assertClause,
);
const updatedNode = tsBinary.factory.updateExportDeclaration(
node,
node.modifiers,
node.isTypeOnly,
node.exportClause,
moduleSpecifier,
node.assertClause,
);
(updatedNode as any).flags = node.flags;
return updatedNode;
}
Expand Down

0 comments on commit 1e607ce

Please sign in to comment.