refactor(compiler-cli): prepare linker options for compilation of components (#39707)

This commit adds the `i18nUseExternalIds` option to the linker options,
as the compliance tests exercise compilation results with and without
this flag enabled. We therefore need to configure the linker to take
this option into account, as otherwise the compliance test output would
not be identical.

Additionally, this commit switches away from spread syntax to set
the default options. This introduced a problem when the user-provided
options object did specify the keys, but with an undefined value. This
would have prevented the default options from being applied.

PR Close #39707
This commit is contained in:
JoostK 2020-11-16 18:10:29 +01:00 committed by Andrew Kushnir
parent 6c7eb351d4
commit 2484ba4f05
2 changed files with 15 additions and 1 deletions

View File

@ -20,6 +20,12 @@ export class LinkerEnvironment<TStatement, TExpression> {
static create<TStatement, TExpression>(
host: AstHost<TExpression>, factory: AstFactory<TStatement, TExpression>,
options: Partial<LinkerOptions>): LinkerEnvironment<TStatement, TExpression> {
return new LinkerEnvironment(host, factory, {...DEFAULT_LINKER_OPTIONS, ...options});
return new LinkerEnvironment(host, factory, {
enableI18nLegacyMessageIdFormat: options.enableI18nLegacyMessageIdFormat ??
DEFAULT_LINKER_OPTIONS.enableI18nLegacyMessageIdFormat,
i18nNormalizeLineEndingsInICUs: options.i18nNormalizeLineEndingsInICUs ??
DEFAULT_LINKER_OPTIONS.i18nNormalizeLineEndingsInICUs,
i18nUseExternalIds: options.i18nUseExternalIds ?? DEFAULT_LINKER_OPTIONS.i18nUseExternalIds,
});
}
}

View File

@ -20,6 +20,13 @@ export interface LinkerOptions {
* The default is `false`.
*/
i18nNormalizeLineEndingsInICUs: boolean;
/**
* Whether translation variable name should contain external message id
* (used by Closure Compiler's output of `goog.getMsg` for transition period)
* The default is `false`.
*/
i18nUseExternalIds: boolean;
}
/**
@ -28,4 +35,5 @@ export interface LinkerOptions {
export const DEFAULT_LINKER_OPTIONS: LinkerOptions = {
enableI18nLegacyMessageIdFormat: true,
i18nNormalizeLineEndingsInICUs: false,
i18nUseExternalIds: false,
};