refactor(compiler-cli): remove i18n options from `LinkerOptions` (#41554)

There were three options being made available to users of the linker:

- ` enableI18nLegacyMessageIdFormat`
-  `i18nNormalizeLineEndingsInICUs`
- ` i18nUseExternalIds`

None of these should actually be configurable at linking time
because partially-linked libraries have tighter restrictions on
what i18n options can be used.

This commit removes those options from the `LinkerOptions` interface.
It was considered to add a check for backwards compatibilty to ensure
that if these options were being passed, and were different to the expected
defaults, we would throw an informative error. But from looking at the
Angular CLI (the only known client of the linker) it has never been setting
these options so they have already always been set to the defaults.

BREAKING CHANGE:

Linked libraries no longer generate legacy i18n message ids. Any downstream
application that provides translations for these messages, will need to
migrate their message ids using the `localize-migrate` command line tool.

Closes #40673

PR Close #41554
This commit is contained in:
Pete Bacon Darwin 2021-04-09 17:50:50 +01:00 committed by Zach Arend
parent 261bce65fb
commit ba84fa6f42
7 changed files with 20 additions and 44 deletions

View File

@ -29,11 +29,6 @@ export class LinkerEnvironment<TStatement, TExpression> {
factory: AstFactory<TStatement, TExpression>, factory: AstFactory<TStatement, TExpression>,
options: Partial<LinkerOptions>): LinkerEnvironment<TStatement, TExpression> { options: Partial<LinkerOptions>): LinkerEnvironment<TStatement, TExpression> {
return new LinkerEnvironment(fileSystem, logger, host, factory, { return new LinkerEnvironment(fileSystem, logger, host, factory, {
enableI18nLegacyMessageIdFormat: options.enableI18nLegacyMessageIdFormat ??
DEFAULT_LINKER_OPTIONS.enableI18nLegacyMessageIdFormat,
i18nNormalizeLineEndingsInICUs: options.i18nNormalizeLineEndingsInICUs ??
DEFAULT_LINKER_OPTIONS.i18nNormalizeLineEndingsInICUs,
i18nUseExternalIds: options.i18nUseExternalIds ?? DEFAULT_LINKER_OPTIONS.i18nUseExternalIds,
sourceMapping: options.sourceMapping ?? DEFAULT_LINKER_OPTIONS.sourceMapping, sourceMapping: options.sourceMapping ?? DEFAULT_LINKER_OPTIONS.sourceMapping,
linkerJitMode: options.linkerJitMode ?? DEFAULT_LINKER_OPTIONS.linkerJitMode, linkerJitMode: options.linkerJitMode ?? DEFAULT_LINKER_OPTIONS.linkerJitMode,
}); });

View File

@ -10,24 +10,6 @@
* Options to configure the linking behavior. * Options to configure the linking behavior.
*/ */
export interface LinkerOptions { export interface LinkerOptions {
/**
* Whether to generate legacy i18n message ids.
* The default is `true`.
*/
enableI18nLegacyMessageIdFormat: boolean;
/**
* Whether to convert all line-endings in ICU expressions to `\n` characters.
* 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;
/** /**
* Whether to use source-mapping to compute the original source for external templates. * Whether to use source-mapping to compute the original source for external templates.
* The default is `true`. * The default is `true`.
@ -47,9 +29,6 @@ export interface LinkerOptions {
* The default linker options to use if properties are not provided. * The default linker options to use if properties are not provided.
*/ */
export const DEFAULT_LINKER_OPTIONS: LinkerOptions = { export const DEFAULT_LINKER_OPTIONS: LinkerOptions = {
enableI18nLegacyMessageIdFormat: true,
i18nNormalizeLineEndingsInICUs: false,
i18nUseExternalIds: false,
sourceMapping: true, sourceMapping: true,
linkerJitMode: false, linkerJitMode: false,
}; };

View File

@ -14,7 +14,6 @@ import {Range} from '../../ast/ast_host';
import {AstObject, AstValue} from '../../ast/ast_value'; import {AstObject, AstValue} from '../../ast/ast_value';
import {FatalLinkerError} from '../../fatal_linker_error'; import {FatalLinkerError} from '../../fatal_linker_error';
import {GetSourceFileFn} from '../get_source_file'; import {GetSourceFileFn} from '../get_source_file';
import {LinkerEnvironment} from '../linker_environment';
import {toR3DirectiveMeta} from './partial_directive_linker_1'; import {toR3DirectiveMeta} from './partial_directive_linker_1';
import {PartialLinker} from './partial_linker'; import {PartialLinker} from './partial_linker';
@ -25,14 +24,7 @@ import {extractForwardRef} from './util';
*/ */
export class PartialComponentLinkerVersion1<TStatement, TExpression> implements export class PartialComponentLinkerVersion1<TStatement, TExpression> implements
PartialLinker<TExpression> { PartialLinker<TExpression> {
private readonly i18nNormalizeLineEndingsInICUs =
this.environment.options.i18nNormalizeLineEndingsInICUs;
private readonly enableI18nLegacyMessageIdFormat =
this.environment.options.enableI18nLegacyMessageIdFormat;
private readonly i18nUseExternalIds = this.environment.options.i18nUseExternalIds;
constructor( constructor(
private readonly environment: LinkerEnvironment<TStatement, TExpression>,
private readonly getSourceFile: GetSourceFileFn, private sourceUrl: AbsoluteFsPath, private readonly getSourceFile: GetSourceFileFn, private sourceUrl: AbsoluteFsPath,
private code: string) {} private code: string) {}
@ -54,17 +46,15 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression> implements
const isInline = metaObj.has('isInline') ? metaObj.getBoolean('isInline') : false; const isInline = metaObj.has('isInline') ? metaObj.getBoolean('isInline') : false;
const templateInfo = this.getTemplateInfo(templateSource, isInline); const templateInfo = this.getTemplateInfo(templateSource, isInline);
// We always normalize line endings if the template is inline.
const i18nNormalizeLineEndingsInICUs = isInline || this.i18nNormalizeLineEndingsInICUs;
const template = parseTemplate(templateInfo.code, templateInfo.sourceUrl, { const template = parseTemplate(templateInfo.code, templateInfo.sourceUrl, {
escapedString: templateInfo.isEscaped, escapedString: templateInfo.isEscaped,
interpolationConfig: interpolation, interpolationConfig: interpolation,
range: templateInfo.range, range: templateInfo.range,
enableI18nLegacyMessageIdFormat: this.enableI18nLegacyMessageIdFormat, enableI18nLegacyMessageIdFormat: false,
preserveWhitespaces: preserveWhitespaces:
metaObj.has('preserveWhitespaces') ? metaObj.getBoolean('preserveWhitespaces') : false, metaObj.has('preserveWhitespaces') ? metaObj.getBoolean('preserveWhitespaces') : false,
i18nNormalizeLineEndingsInICUs, // We normalize line endings if the template is was inline.
i18nNormalizeLineEndingsInICUs: isInline,
isInline, isInline,
}); });
if (template.errors !== null) { if (template.errors !== null) {
@ -141,7 +131,7 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression> implements
ChangeDetectionStrategy.Default, ChangeDetectionStrategy.Default,
animations: metaObj.has('animations') ? metaObj.getOpaque('animations') : null, animations: metaObj.has('animations') ? metaObj.getOpaque('animations') : null,
relativeContextFilePath: this.sourceUrl, relativeContextFilePath: this.sourceUrl,
i18nUseExternalIds: this.i18nUseExternalIds, i18nUseExternalIds: false,
pipes, pipes,
directives, directives,
}; };

View File

@ -95,8 +95,7 @@ export class PartialLinkerSelector<TStatement, TExpression> {
const partialDirectiveLinkerVersion1 = new PartialDirectiveLinkerVersion1(sourceUrl, code); const partialDirectiveLinkerVersion1 = new PartialDirectiveLinkerVersion1(sourceUrl, code);
const partialClassMetadataLinkerVersion1 = new PartialClassMetadataLinkerVersion1(); const partialClassMetadataLinkerVersion1 = new PartialClassMetadataLinkerVersion1();
const partialComponentLinkerVersion1 = new PartialComponentLinkerVersion1( const partialComponentLinkerVersion1 = new PartialComponentLinkerVersion1(
environment, createGetSourceFile(sourceUrl, code, environment.sourceFileLoader), sourceUrl, createGetSourceFile(sourceUrl, code, environment.sourceFileLoader), sourceUrl, code);
code);
const partialFactoryLinkerVersion1 = new PartialFactoryLinkerVersion1(); const partialFactoryLinkerVersion1 = new PartialFactoryLinkerVersion1();
const partialInjectableLinkerVersion1 = new PartialInjectableLinkerVersion1(); const partialInjectableLinkerVersion1 = new PartialInjectableLinkerVersion1();
const partialInjectorLinkerVersion1 = new PartialInjectorLinkerVersion1(); const partialInjectorLinkerVersion1 = new PartialInjectorLinkerVersion1();

View File

@ -32,8 +32,6 @@ function linkPartials(fileSystem: FileSystem, test: ComplianceTest): CompileResu
const linkerPlugin = createEs2015LinkerPlugin({ const linkerPlugin = createEs2015LinkerPlugin({
fileSystem, fileSystem,
logger, logger,
// By default we don't render legacy message ids in compliance tests.
enableI18nLegacyMessageIdFormat: false,
sourceMapping: test.compilerOptions?.sourceMap === true, sourceMapping: test.compilerOptions?.sourceMap === true,
...test.angularCompilerOptions ...test.angularCompilerOptions
}); });

View File

@ -106,6 +106,9 @@
"i18nNormalizeLineEndingsInICUs": true, "i18nNormalizeLineEndingsInICUs": true,
"enableI18nLegacyMessageIdFormat": true "enableI18nLegacyMessageIdFormat": true
}, },
"compilationModeFilter": [
"full compile"
],
"expectations": [ "expectations": [
{ {
"files": [ "files": [
@ -130,6 +133,9 @@
"i18nNormalizeLineEndingsInICUs": false, "i18nNormalizeLineEndingsInICUs": false,
"enableI18nLegacyMessageIdFormat": true "enableI18nLegacyMessageIdFormat": true
}, },
"compilationModeFilter": [
"full compile"
],
"expectations": [ "expectations": [
{ {
"files": [ "files": [
@ -154,6 +160,9 @@
"i18nNormalizeLineEndingsInICUs": true, "i18nNormalizeLineEndingsInICUs": true,
"enableI18nLegacyMessageIdFormat": true "enableI18nLegacyMessageIdFormat": true
}, },
"compilationModeFilter": [
"full compile"
],
"expectations": [ "expectations": [
{ {
"extraChecks": [ "extraChecks": [
@ -172,6 +181,9 @@
"i18nNormalizeLineEndingsInICUs": false, "i18nNormalizeLineEndingsInICUs": false,
"enableI18nLegacyMessageIdFormat": true "enableI18nLegacyMessageIdFormat": true
}, },
"compilationModeFilter": [
"full compile"
],
"expectations": [ "expectations": [
{ {
"extraChecks": [ "extraChecks": [

View File

@ -9,6 +9,9 @@
"angularCompilerOptions": { "angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": true "enableI18nLegacyMessageIdFormat": true
}, },
"compilationModeFilter": [
"full compile"
],
"expectations": [ "expectations": [
{ {
"extraChecks": [ "extraChecks": [