fix(ngcc): render localized strings when in ES5 format (#33857)
Recently the ngtsc translator was modified to be more `ScriptTarget` aware, which basically means that it will not generate non-ES5 code when the output format is ES5 or similar. This commit enhances that change by also "downleveling" localized messages. In ES2015 the messages use tagged template literals, which are not available in ES5. PR Close #33857
This commit is contained in:

committed by
Alex Rickabaugh

parent
346e1c14d9
commit
bf1bcd1e08
@ -223,6 +223,38 @@ runInEachFileSystem(() => {
|
||||
expect(esm5Contents).toContain(`export {InternalFooModule} from './src/internal';`);
|
||||
});
|
||||
|
||||
it('should use `$localize` calls rather than tagged templates in ES5 generated code', () => {
|
||||
compileIntoFlatEs5Package('test-package', {
|
||||
'/index.ts': `
|
||||
import {Component, Input, NgModule} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: '[foo]',
|
||||
template: '<div i18n="some:\`description\`">A message</div>'
|
||||
})
|
||||
export class FooComponent {
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [FooComponent],
|
||||
})
|
||||
export class FooModule {}
|
||||
`,
|
||||
});
|
||||
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: 'test-package',
|
||||
propertiesToConsider: ['main'],
|
||||
});
|
||||
|
||||
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`));
|
||||
expect(jsContents).not.toMatch(/\$localize\s*`/);
|
||||
expect(jsContents)
|
||||
.toMatch(
|
||||
/\$localize\(ɵngcc\d+\.__makeTemplateObject\(\[":some:`description`:A message"], \[":some\\\\:\\\\`description\\\\`:A message"]\)\);/);
|
||||
});
|
||||
|
||||
describe('in async mode', () => {
|
||||
it('should run ngcc without errors for fesm2015', async() => {
|
||||
const promise = mainNgcc({
|
||||
|
Reference in New Issue
Block a user