From cebe49d3c9d379b60bcb5d9560167cfadd9f639a Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 3 Dec 2019 08:36:38 +0000 Subject: [PATCH] refactor(ngcc): store whether to render legacy i18n message ids in the bundle (#34135) Placing this configuration in to the bundle avoids having to pass the value around through lots of function calls, but also could enable support for different behaviour per bundle in the future. PR Close #34135 --- .../ngcc/src/analysis/decoration_analyzer.ts | 6 +++--- packages/compiler-cli/ngcc/src/main.ts | 3 ++- .../compiler-cli/ngcc/src/packages/entry_point_bundle.ts | 9 +++++++-- packages/compiler-cli/ngcc/test/helpers/utils.ts | 9 +++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts b/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts index 0c0b211006..80cb85656b 100644 --- a/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts +++ b/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts @@ -16,7 +16,7 @@ import {CompoundMetadataReader, CompoundMetadataRegistry, DtsMetadataReader, Loc import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator'; import {ClassDeclaration} from '../../../src/ngtsc/reflection'; import {LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver} from '../../../src/ngtsc/scope'; -import {CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../src/ngtsc/transform'; +import {CompileResult, DecoratorHandler} from '../../../src/ngtsc/transform'; import {NgccClassSymbol, NgccReflectionHost} from '../host/ngcc_host'; import {Migration} from '../migrations/migration'; import {MissingInjectableMigration} from '../migrations/missing_injectable_migration'; @@ -88,8 +88,8 @@ export class DecorationAnalyzer { this.reflectionHost, this.evaluator, this.fullRegistry, this.fullMetaReader, this.scopeRegistry, this.scopeRegistry, this.isCore, this.resourceManager, this.rootDirs, /* defaultPreserveWhitespaces */ false, - /* i18nUseExternalIds */ true, /* i18nLegacyMessageIdFormat */ '', this.moduleResolver, - this.cycleAnalyzer, this.refEmitter, NOOP_DEFAULT_IMPORT_RECORDER, + /* i18nUseExternalIds */ true, this.bundle.enableI18nLegacyMessageIdFormat, + this.moduleResolver, this.cycleAnalyzer, this.refEmitter, NOOP_DEFAULT_IMPORT_RECORDER, /* annotateForClosureCompiler */ false), new DirectiveDecoratorHandler( this.reflectionHost, this.evaluator, this.fullRegistry, NOOP_DEFAULT_IMPORT_RECORDER, diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index 60858f5ed4..1937eda373 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -241,7 +241,8 @@ export function mainNgcc( } const bundle = makeEntryPointBundle( - fileSystem, entryPoint, formatPath, isCore, format, processDts, pathMappings, true); + fileSystem, entryPoint, formatPath, isCore, format, processDts, pathMappings, true, + false); logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`); diff --git a/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts b/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts index 72768725a5..bc369b5ada 100644 --- a/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts +++ b/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts @@ -24,6 +24,7 @@ export interface EntryPointBundle { rootDirs: AbsoluteFsPath[]; src: BundleProgram; dts: BundleProgram|null; + enableI18nLegacyMessageIdFormat: boolean; } /** @@ -37,11 +38,14 @@ export interface EntryPointBundle { * @param pathMappings An optional set of mappings to use when compiling files. * @param mirrorDtsFromSrc If true then the `dts` program will contain additional files that * were guessed by mapping the `src` files to `dts` files. + * @param enableI18nLegacyMessageIdFormat Whether to render legacy message ids for i18n messages in + * component templates. */ export function makeEntryPointBundle( fs: FileSystem, entryPoint: EntryPoint, formatPath: string, isCore: boolean, format: EntryPointFormat, transformDts: boolean, pathMappings?: PathMappings, - mirrorDtsFromSrc: boolean = false): EntryPointBundle { + mirrorDtsFromSrc: boolean = false, + enableI18nLegacyMessageIdFormat: boolean = true): EntryPointBundle { // Create the TS program and necessary helpers. const options: ts.CompilerOptions = { allowJs: true, @@ -67,7 +71,8 @@ export function makeEntryPointBundle( null; const isFlatCore = isCore && src.r3SymbolsFile === null; - return {entryPoint, format, rootDirs, isCore, isFlatCore, src, dts}; + return {entryPoint, format, rootDirs, isCore, + isFlatCore, src, dts, enableI18nLegacyMessageIdFormat}; } function computePotentialDtsFilesFromJsFiles( diff --git a/packages/compiler-cli/ngcc/test/helpers/utils.ts b/packages/compiler-cli/ngcc/test/helpers/utils.ts index 7da2c5fc2a..781be94e3d 100644 --- a/packages/compiler-cli/ngcc/test/helpers/utils.ts +++ b/packages/compiler-cli/ngcc/test/helpers/utils.ts @@ -39,13 +39,18 @@ export function makeTestEntryPoint( */ export function makeTestEntryPointBundle( packageName: string, format: EntryPointFormat, isCore: boolean, srcRootNames: AbsoluteFsPath[], - dtsRootNames?: AbsoluteFsPath[], config?: TestConfig): EntryPointBundle { + dtsRootNames?: AbsoluteFsPath[], config?: TestConfig, + enableI18nLegacyMessageIdFormat = false): EntryPointBundle { const entryPoint = makeTestEntryPoint(packageName, packageName, config); const src = makeTestBundleProgram(srcRootNames[0], isCore); const dts = dtsRootNames ? makeTestDtsBundleProgram(dtsRootNames[0], entryPoint.package, isCore) : null; const isFlatCore = isCore && src.r3SymbolsFile === null; - return {entryPoint, format, rootDirs: [absoluteFrom('/')], src, dts, isCore, isFlatCore}; + return { + entryPoint, + format, + rootDirs: [absoluteFrom('/')], src, dts, isCore, isFlatCore, enableI18nLegacyMessageIdFormat + }; } export function makeTestBundleProgram(