From d39a2beae17bcd75e2555033a6d827e067f12d33 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Thu, 18 Jul 2019 21:05:32 +0100 Subject: [PATCH] refactor(ivy): ngcc - move decorator analysis types into their own file (#31544) PR Close #31544 --- .../ngcc/src/analysis/decoration_analyzer.ts | 32 +-------------- .../compiler-cli/ngcc/src/analysis/types.ts | 40 +++++++++++++++++++ .../ngcc/src/packages/transformer.ts | 3 +- .../ngcc/src/rendering/dts_renderer.ts | 2 +- .../src/rendering/esm5_rendering_formatter.ts | 2 +- .../src/rendering/esm_rendering_formatter.ts | 2 +- .../ngcc/src/rendering/renderer.ts | 2 +- .../ngcc/src/rendering/rendering_formatter.ts | 2 +- .../test/analysis/decoration_analyzer_spec.ts | 3 +- .../ngcc/test/rendering/dts_renderer_spec.ts | 3 +- .../ngcc/test/rendering/renderer_spec.ts | 3 +- 11 files changed, 54 insertions(+), 40 deletions(-) create mode 100644 packages/compiler-cli/ngcc/src/analysis/types.ts diff --git a/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts b/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts index f87c448561..38e5910046 100644 --- a/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts +++ b/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts @@ -7,7 +7,6 @@ */ import {ConstantPool} from '@angular/compiler'; import * as ts from 'typescript'; - import {BaseDefDecoratorHandler, ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, ReferencesRegistry, ResourceLoader} from '../../../src/ngtsc/annotations'; import {CycleAnalyzer, ImportGraph} from '../../../src/ngtsc/cycles'; import {FileSystem, LogicalFileSystem, absoluteFrom, dirname, resolve} from '../../../src/ngtsc/file_system'; @@ -20,36 +19,7 @@ import {CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from ' import {NgccReflectionHost} from '../host/ngcc_host'; import {EntryPointBundle} from '../packages/entry_point_bundle'; import {isDefined} from '../utils'; -import {isWithinPackage} from './util'; - -export interface AnalyzedFile { - sourceFile: ts.SourceFile; - analyzedClasses: AnalyzedClass[]; -} - -export interface AnalyzedClass { - name: string; - decorators: Decorator[]|null; - declaration: ClassDeclaration; - diagnostics?: ts.Diagnostic[]; - matches: {handler: DecoratorHandler; analysis: any;}[]; -} - -export interface CompiledClass extends AnalyzedClass { compilation: CompileResult[]; } - -export interface CompiledFile { - compiledClasses: CompiledClass[]; - sourceFile: ts.SourceFile; - constantPool: ConstantPool; -} - -export type DecorationAnalyses = Map; -export const DecorationAnalyses = Map; - -export interface MatchingHandler { - handler: DecoratorHandler; - detected: M; -} +import {AnalyzedClass, AnalyzedFile, CompiledClass, CompiledFile, DecorationAnalyses, MatchingHandler} from './types'; /** * Simple class that resolves and loads files directly from the filesystem. diff --git a/packages/compiler-cli/ngcc/src/analysis/types.ts b/packages/compiler-cli/ngcc/src/analysis/types.ts new file mode 100644 index 0000000000..d84041d300 --- /dev/null +++ b/packages/compiler-cli/ngcc/src/analysis/types.ts @@ -0,0 +1,40 @@ +/** + * @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 {ConstantPool} from '@angular/compiler'; +import * as ts from 'typescript'; +import {ClassDeclaration, Decorator} from '../../../src/ngtsc/reflection'; +import {CompileResult, DecoratorHandler} from '../../../src/ngtsc/transform'; + +export interface AnalyzedFile { + sourceFile: ts.SourceFile; + analyzedClasses: AnalyzedClass[]; +} + +export interface AnalyzedClass { + name: string; + decorators: Decorator[]|null; + declaration: ClassDeclaration; + diagnostics?: ts.Diagnostic[]; + matches: {handler: DecoratorHandler; analysis: any;}[]; +} + +export interface CompiledClass extends AnalyzedClass { compilation: CompileResult[]; } + +export interface CompiledFile { + compiledClasses: CompiledClass[]; + sourceFile: ts.SourceFile; + constantPool: ConstantPool; +} + +export type DecorationAnalyses = Map; +export const DecorationAnalyses = Map; + +export interface MatchingHandler { + handler: DecoratorHandler; + detected: M; +} diff --git a/packages/compiler-cli/ngcc/src/packages/transformer.ts b/packages/compiler-cli/ngcc/src/packages/transformer.ts index 99549ce9aa..11bbc4900a 100644 --- a/packages/compiler-cli/ngcc/src/packages/transformer.ts +++ b/packages/compiler-cli/ngcc/src/packages/transformer.ts @@ -7,11 +7,12 @@ */ import * as ts from 'typescript'; import {FileSystem} from '../../../src/ngtsc/file_system'; -import {CompiledFile, DecorationAnalyzer} from '../analysis/decoration_analyzer'; +import {DecorationAnalyzer} from '../analysis/decoration_analyzer'; import {ModuleWithProvidersAnalyses, ModuleWithProvidersAnalyzer} from '../analysis/module_with_providers_analyzer'; import {NgccReferencesRegistry} from '../analysis/ngcc_references_registry'; import {ExportInfo, PrivateDeclarationsAnalyzer} from '../analysis/private_declarations_analyzer'; import {SwitchMarkerAnalyses, SwitchMarkerAnalyzer} from '../analysis/switch_marker_analyzer'; +import {CompiledFile} from '../analysis/types'; import {CommonJsReflectionHost} from '../host/commonjs_host'; import {Esm2015ReflectionHost} from '../host/esm2015_host'; import {Esm5ReflectionHost} from '../host/esm5_host'; diff --git a/packages/compiler-cli/ngcc/src/rendering/dts_renderer.ts b/packages/compiler-cli/ngcc/src/rendering/dts_renderer.ts index 6059fd8bfc..6161e309b5 100644 --- a/packages/compiler-cli/ngcc/src/rendering/dts_renderer.ts +++ b/packages/compiler-cli/ngcc/src/rendering/dts_renderer.ts @@ -10,7 +10,7 @@ import * as ts from 'typescript'; import {FileSystem} from '../../../src/ngtsc/file_system'; import {CompileResult} from '../../../src/ngtsc/transform'; import {translateType, ImportManager} from '../../../src/ngtsc/translator'; -import {DecorationAnalyses} from '../analysis/decoration_analyzer'; +import {DecorationAnalyses} from '../analysis/types'; import {ModuleWithProvidersInfo, ModuleWithProvidersAnalyses} from '../analysis/module_with_providers_analyzer'; import {PrivateDeclarationsAnalyses, ExportInfo} from '../analysis/private_declarations_analyzer'; import {IMPORT_PREFIX} from '../constants'; diff --git a/packages/compiler-cli/ngcc/src/rendering/esm5_rendering_formatter.ts b/packages/compiler-cli/ngcc/src/rendering/esm5_rendering_formatter.ts index 8b22f7519f..138398ec00 100644 --- a/packages/compiler-cli/ngcc/src/rendering/esm5_rendering_formatter.ts +++ b/packages/compiler-cli/ngcc/src/rendering/esm5_rendering_formatter.ts @@ -7,7 +7,7 @@ */ import MagicString from 'magic-string'; import * as ts from 'typescript'; -import {CompiledClass} from '../analysis/decoration_analyzer'; +import {CompiledClass} from '../analysis/types'; import {getIifeBody} from '../host/esm5_host'; import {EsmRenderingFormatter} from './esm_rendering_formatter'; diff --git a/packages/compiler-cli/ngcc/src/rendering/esm_rendering_formatter.ts b/packages/compiler-cli/ngcc/src/rendering/esm_rendering_formatter.ts index 895c8d8a52..901d28a5d7 100644 --- a/packages/compiler-cli/ngcc/src/rendering/esm_rendering_formatter.ts +++ b/packages/compiler-cli/ngcc/src/rendering/esm_rendering_formatter.ts @@ -10,7 +10,7 @@ import * as ts from 'typescript'; import {relative, dirname, AbsoluteFsPath, absoluteFromSourceFile} from '../../../src/ngtsc/file_system'; import {Import, ImportManager} from '../../../src/ngtsc/translator'; import {isDtsPath} from '../../../src/ngtsc/util/src/typescript'; -import {CompiledClass} from '../analysis/decoration_analyzer'; +import {CompiledClass} from '../analysis/types'; import {NgccReflectionHost, POST_R3_MARKER, PRE_R3_MARKER, SwitchableVariableDeclaration} from '../host/ngcc_host'; import {ModuleWithProvidersInfo} from '../analysis/module_with_providers_analyzer'; import {ExportInfo} from '../analysis/private_declarations_analyzer'; diff --git a/packages/compiler-cli/ngcc/src/rendering/renderer.ts b/packages/compiler-cli/ngcc/src/rendering/renderer.ts index 1e3588f55e..5052a153eb 100644 --- a/packages/compiler-cli/ngcc/src/rendering/renderer.ts +++ b/packages/compiler-cli/ngcc/src/rendering/renderer.ts @@ -10,7 +10,7 @@ import MagicString from 'magic-string'; import * as ts from 'typescript'; import {NOOP_DEFAULT_IMPORT_RECORDER} from '../../../src/ngtsc/imports'; import {translateStatement, ImportManager} from '../../../src/ngtsc/translator'; -import {CompiledClass, CompiledFile, DecorationAnalyses} from '../analysis/decoration_analyzer'; +import {CompiledClass, CompiledFile, DecorationAnalyses} from '../analysis/types'; import {PrivateDeclarationsAnalyses} from '../analysis/private_declarations_analyzer'; import {SwitchMarkerAnalyses, SwitchMarkerAnalysis} from '../analysis/switch_marker_analyzer'; import {IMPORT_PREFIX} from '../constants'; diff --git a/packages/compiler-cli/ngcc/src/rendering/rendering_formatter.ts b/packages/compiler-cli/ngcc/src/rendering/rendering_formatter.ts index b2a0ad2ca3..c81fddb4fc 100644 --- a/packages/compiler-cli/ngcc/src/rendering/rendering_formatter.ts +++ b/packages/compiler-cli/ngcc/src/rendering/rendering_formatter.ts @@ -9,7 +9,7 @@ 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 {CompiledClass} from '../analysis/types'; import {SwitchableVariableDeclaration} from '../host/ngcc_host'; import {ModuleWithProvidersInfo} from '../analysis/module_with_providers_analyzer'; diff --git a/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts index f5e462864e..47b71fe136 100644 --- a/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts @@ -12,8 +12,9 @@ import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/test import {Decorator} from '../../../src/ngtsc/reflection'; import {DecoratorHandler, DetectResult} from '../../../src/ngtsc/transform'; import {loadFakeCore, loadTestFiles} from '../../../test/helpers'; -import {CompiledClass, DecorationAnalyses, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer'; +import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer'; import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry'; +import {CompiledClass, DecorationAnalyses} from '../../src/analysis/types'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; import {MockLogger} from '../helpers/mock_logger'; import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils'; diff --git a/packages/compiler-cli/ngcc/test/rendering/dts_renderer_spec.ts b/packages/compiler-cli/ngcc/test/rendering/dts_renderer_spec.ts index e4651655c8..563b795eca 100644 --- a/packages/compiler-cli/ngcc/test/rendering/dts_renderer_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/dts_renderer_spec.ts @@ -11,7 +11,8 @@ import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system'; import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; import {loadTestFiles} from '../../../test/helpers'; import {Import, ImportManager} from '../../../src/ngtsc/translator'; -import {CompiledClass, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer'; +import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer'; +import {CompiledClass} from '../../src/analysis/types'; import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry'; import {ModuleWithProvidersAnalyzer, ModuleWithProvidersInfo} from '../../src/analysis/module_with_providers_analyzer'; import {PrivateDeclarationsAnalyzer, ExportInfo} from '../../src/analysis/private_declarations_analyzer'; diff --git a/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts b/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts index adf8b57d0f..830b2db446 100644 --- a/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts @@ -12,7 +12,8 @@ import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system'; import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; import {loadTestFiles} from '../../../test/helpers'; import {Import, ImportManager} from '../../../src/ngtsc/translator'; -import {CompiledClass, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer'; +import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer'; +import {CompiledClass} from '../../src/analysis/types'; import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry'; import {ModuleWithProvidersInfo} from '../../src/analysis/module_with_providers_analyzer'; import {PrivateDeclarationsAnalyzer, ExportInfo} from '../../src/analysis/private_declarations_analyzer';