fix(ivy): ngcc - separate typings rendering from src rendering (#25445)
Previously the same `Renderer` was used to render typings (.d.ts) files. But the new `UmdRenderer` is not able to render typings files correctly. This commit splits out the typings rendering from the src rendering. To achieve this the previous renderers have been refactored from sub-classes of the abstract `Renderer` class to classes that implement the `RenderingFormatter` interface, which are then passed to the `Renderer` and `DtsRenderer` to modify its rendering behaviour. Along the way a few utility interfaces and classes have been moved around and renamed for clarity. PR Close #25445
This commit is contained in:

committed by
Jason Aden

parent
f4655ea98a
commit
c613596658
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {Import, ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {ExportInfo} from '../analysis/private_declarations_analyzer';
|
||||
import {CompiledClass} from '../analysis/decoration_analyzer';
|
||||
import {SwitchableVariableDeclaration} from '../host/ngcc_host';
|
||||
import {ModuleWithProvidersInfo} from '../analysis/module_with_providers_analyzer';
|
||||
|
||||
/**
|
||||
* The collected decorators that have become redundant after the compilation
|
||||
* of Ivy static fields. The map is keyed by the container node, such that we
|
||||
* can tell if we should remove the entire decorator property
|
||||
*/
|
||||
export type RedundantDecoratorMap = Map<ts.Node, ts.Node[]>;
|
||||
export const RedundantDecoratorMap = Map;
|
||||
|
||||
/**
|
||||
* Implement this interface with methods that know how to render a specific format,
|
||||
* such as ESM5 or UMD.
|
||||
*/
|
||||
export interface RenderingFormatter {
|
||||
addConstants(output: MagicString, constants: string, file: ts.SourceFile): void;
|
||||
addImports(output: MagicString, imports: Import[], sf: ts.SourceFile): void;
|
||||
addExports(
|
||||
output: MagicString, entryPointBasePath: string, exports: ExportInfo[],
|
||||
importManager: ImportManager, file: ts.SourceFile): void;
|
||||
addDefinitions(output: MagicString, compiledClass: CompiledClass, definitions: string): void;
|
||||
removeDecorators(output: MagicString, decoratorsToRemove: RedundantDecoratorMap): void;
|
||||
rewriteSwitchableDeclarations(
|
||||
outputText: MagicString, sourceFile: ts.SourceFile,
|
||||
declarations: SwitchableVariableDeclaration[]): void;
|
||||
addModuleWithProvidersParams(
|
||||
outputText: MagicString, moduleWithProviders: ModuleWithProvidersInfo[],
|
||||
importManager: ImportManager): void;
|
||||
}
|
Reference in New Issue
Block a user