fix(compiler-cli): plumb i18nPreserveWhitespaceForLegacyExtraction into hybrid compiler

Forward angularCompilerOptions.i18nPreserveWhitespaceForLegacyExtraction into
templateParseOptions.preserveSignificantWhitespace (defaulting to true) across
the CLI entry point, test utilities, and NGP test driver so legacy i18n
whitespace collapsing matches ngtsc.
This commit is contained in:
Matthew Beck
2026-10-21 08:22:52 +02:00
committed by Kristiyan Kostadinov
parent 4d83882b05
commit 0fc2bfee4c
6 changed files with 13 additions and 3 deletions
@@ -168,6 +168,8 @@ import {run} from './ngp.js';
enableI18nLegacyMessageIdFormat: angularCompilerOptions?.enableI18nLegacyMessageIdFormat,
i18nUseExternalIds: angularCompilerOptions?.i18nUseExternalIds,
i18nNormalizeLineEndingsInICUs: angularCompilerOptions?.i18nNormalizeLineEndingsInICUs,
i18nPreserveWhitespaceForLegacyExtraction:
angularCompilerOptions?.i18nPreserveWhitespaceForLegacyExtraction,
enableHmr,
rootDir,
workspaceName,
@@ -70,6 +70,7 @@ export interface NgpCompilerOptions {
enableI18nLegacyMessageIdFormat?: boolean;
i18nUseExternalIds?: boolean;
i18nNormalizeLineEndingsInICUs?: boolean;
i18nPreserveWhitespaceForLegacyExtraction?: boolean;
// TypeScript `compilerOptions` that ngtsc reads off the same merged options object.
emitDeclarationOnly?: boolean;
@@ -136,6 +136,8 @@ export interface HybridCompilerOptions {
i18nUseExternalIds?: boolean;
/** Literal inline templates always normalize, whatever this is set to. */
i18nNormalizeLineEndingsInICUs?: boolean;
/** Legacy i18n whitespace preservation fallback for `preserveWhitespaces`. */
i18nPreserveWhitespaceForLegacyExtraction?: boolean;
/**
* Whether HMR is enabled (`_enableHmr`): emits an HMR initializer after every component and
* enables `emitHmrUpdateModule`. The analyzer must run with `enableHmr` as well.
@@ -182,6 +184,7 @@ export class HybridCompiler {
this.virtualFiles = options.virtualFiles;
this.templateParseOptions = {
preserveWhitespaces: options.preserveWhitespaces ?? false,
preserveSignificantWhitespace: options.i18nPreserveWhitespaceForLegacyExtraction ?? true,
enableI18nLegacyMessageIdFormat: options.enableI18nLegacyMessageIdFormat !== false,
i18nNormalizeLineEndingsInICUs: options.i18nNormalizeLineEndingsInICUs === true,
...options.templateParseOptions,
@@ -35,17 +35,17 @@ export class AppComp {
/**
* @suppress {msgDescriptions}
*/
const MSG_EXTERNAL_2706437655713359815$$APP_TS_0 =
const MSG_EXTERNAL_5990241859543196033$$APP_TS_0 =
/* @ts-ignore */
goog.getMsg(
' hello {$startTagSpan}world{$closeTagSpan}',
{ 'closeTagSpan': '\uFFFD/#2\uFFFD', 'startTagSpan': '\uFFFD#2\uFFFD' },
{ original_code: { 'closeTagSpan': '</span>', 'startTagSpan': '<span>' } },
);
i18n_0 = MSG_EXTERNAL_2706437655713359815$$APP_TS_0;
i18n_0 = MSG_EXTERNAL_5990241859543196033$$APP_TS_0;
} else {
/* @ts-ignore */
i18n_0 = $localize`:␟a595f893476a55f9061a2ac4a1620b58461957fb␟2706437655713359815: hello ${'\uFFFD#2\uFFFD'}:START_TAG_SPAN:world${'\uFFFD/#2\uFFFD'}:CLOSE_TAG_SPAN:`;
i18n_0 = $localize`:␟3c43e6854ab71b2d5be4e4dc83c53d25e4c5f52d␟5990241859543196033: hello ${'\uFFFD#2\uFFFD'}:START_TAG_SPAN:world${'\uFFFD/#2\uFFFD'}:CLOSE_TAG_SPAN:`;
}
return [i18n_0];
},
@@ -407,6 +407,8 @@ export async function runPipeline(
enableI18nLegacyMessageIdFormat: tsconfigOptions.enableI18nLegacyMessageIdFormat ?? false,
i18nUseExternalIds: tsconfigOptions.i18nUseExternalIds,
i18nNormalizeLineEndingsInICUs: tsconfigOptions.i18nNormalizeLineEndingsInICUs,
i18nPreserveWhitespaceForLegacyExtraction:
tsconfigOptions.i18nPreserveWhitespaceForLegacyExtraction,
};
const workspaceName = tsconfigOptions.workspaceName;
@@ -351,6 +351,7 @@ export function performNgpCompilationSync(params: {
enableI18nLegacyMessageIdFormat: options.enableI18nLegacyMessageIdFormat,
i18nNormalizeLineEndingsInICUs: options.i18nNormalizeLineEndingsInICUs,
preserveWhitespaces: options.preserveWhitespaces,
preserveSignificantWhitespace: options.i18nPreserveWhitespaceForLegacyExtraction ?? true,
enableSelectorless: Boolean(rawOpts['_enableSelectorless']),
},
legacyOptionalChaining: Boolean(rawOpts['legacyOptionalChaining']),
@@ -369,6 +370,7 @@ export function performNgpCompilationSync(params: {
enableI18nLegacyMessageIdFormat: options.enableI18nLegacyMessageIdFormat,
i18nUseExternalIds: options.i18nUseExternalIds,
i18nNormalizeLineEndingsInICUs: options.i18nNormalizeLineEndingsInICUs,
i18nPreserveWhitespaceForLegacyExtraction: options.i18nPreserveWhitespaceForLegacyExtraction,
enableHmr: Boolean(rawOpts['_enableHmr']),
rootDir: options.rootDir
? toPosixPath(fs.resolve(basePath, options.rootDir))