From 69e57827e2be7ca7164c428e32cb3ac187aaac3c Mon Sep 17 00:00:00 2001 From: JoostK Date: Fri, 7 May 2021 22:53:30 +0200 Subject: [PATCH] refactor(compiler-cli): remove unused return type transform (#41996) With the removal of the `ModuleWithProviders` transform in the parent commit, the underlying dts transform can also be removed as it is not used elsewhere. PR Close #41996 --- .../compiler-cli/src/ngtsc/transform/index.ts | 2 +- .../src/ngtsc/transform/src/declaration.ts | 59 ------------------- 2 files changed, 1 insertion(+), 60 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/transform/index.ts b/packages/compiler-cli/src/ngtsc/transform/index.ts index a3fe99dfe6..e3da19c3b1 100644 --- a/packages/compiler-cli/src/ngtsc/transform/index.ts +++ b/packages/compiler-cli/src/ngtsc/transform/index.ts @@ -9,6 +9,6 @@ export * from './src/api'; export {aliasTransformFactory} from './src/alias'; export {ClassRecord, TraitCompiler} from './src/compilation'; -export {declarationTransformFactory, DtsTransformRegistry, IvyDeclarationDtsTransform, ReturnTypeTransform} from './src/declaration'; +export {declarationTransformFactory, DtsTransformRegistry, IvyDeclarationDtsTransform} from './src/declaration'; export {AnalyzedTrait, PendingTrait, ResolvedTrait, SkippedTrait, Trait, TraitState} from './src/trait'; export {ivyTransformFactory} from './src/transform'; diff --git a/packages/compiler-cli/src/ngtsc/transform/src/declaration.ts b/packages/compiler-cli/src/ngtsc/transform/src/declaration.ts index f5f3c26e5a..4adeee9ddb 100644 --- a/packages/compiler-cli/src/ngtsc/transform/src/declaration.ts +++ b/packages/compiler-cli/src/ngtsc/transform/src/declaration.ts @@ -22,7 +22,6 @@ import {addImports} from './utils'; */ export class DtsTransformRegistry { private ivyDeclarationTransforms = new Map(); - private returnTypeTransforms = new Map(); getIvyDeclarationTransform(sf: ts.SourceFile): IvyDeclarationDtsTransform { if (!this.ivyDeclarationTransforms.has(sf)) { @@ -31,13 +30,6 @@ export class DtsTransformRegistry { return this.ivyDeclarationTransforms.get(sf)!; } - getReturnTypeTransform(sf: ts.SourceFile): ReturnTypeTransform { - if (!this.returnTypeTransforms.has(sf)) { - this.returnTypeTransforms.set(sf, new ReturnTypeTransform()); - } - return this.returnTypeTransforms.get(sf)!; - } - /** * Gets the dts transforms to be applied for the given source file, or `null` if no transform is * necessary. @@ -57,10 +49,6 @@ export class DtsTransformRegistry { transforms = []; transforms.push(this.ivyDeclarationTransforms.get(originalSf)!); } - if (this.returnTypeTransforms.has(originalSf)) { - transforms = transforms || []; - transforms.push(this.returnTypeTransforms.get(originalSf)!); - } return transforms; } } @@ -230,50 +218,3 @@ function markForEmitAsSingleLine(node: ts.Node) { ts.setEmitFlags(node, ts.EmitFlags.SingleLine); ts.forEachChild(node, markForEmitAsSingleLine); } - -export class ReturnTypeTransform implements DtsTransform { - private typeReplacements = new Map(); - - addTypeReplacement(declaration: ts.Declaration, type: Type): void { - this.typeReplacements.set(declaration, type); - } - - transformClassElement(element: ts.ClassElement, imports: ImportManager): ts.ClassElement { - if (ts.isMethodDeclaration(element)) { - const original = ts.getOriginalNode(element, ts.isMethodDeclaration); - if (!this.typeReplacements.has(original)) { - return element; - } - const returnType = this.typeReplacements.get(original)!; - const tsReturnType = translateType(returnType, imports); - - return ts.updateMethod( - element, element.decorators, element.modifiers, element.asteriskToken, element.name, - element.questionToken, element.typeParameters, element.parameters, tsReturnType, - element.body); - } - - return element; - } - - transformFunctionDeclaration(element: ts.FunctionDeclaration, imports: ImportManager): - ts.FunctionDeclaration { - const original = ts.getOriginalNode(element) as ts.FunctionDeclaration; - if (!this.typeReplacements.has(original)) { - return element; - } - const returnType = this.typeReplacements.get(original)!; - const tsReturnType = translateType(returnType, imports); - - return ts.updateFunctionDeclaration( - /* node */ element, - /* decorators */ element.decorators, - /* modifiers */ element.modifiers, - /* asteriskToken */ element.asteriskToken, - /* name */ element.name, - /* typeParameters */ element.typeParameters, - /* parameters */ element.parameters, - /* type */ tsReturnType, - /* body */ element.body); - } -}