fix(compiler): ensure localized strings are ES5 compatible for JIT mode (#34265)

Previously the JIT evaluated code for ivy localized strings included
backtick tagged template strings, which are not compatible with ES5
in legacy browsers such as IE 11.

Now the generated code is ES5 compatible.

Fixes #34246

PR Close #34265
This commit is contained in:
Pete Bacon Darwin
2019-12-06 08:41:44 +00:00
committed by Andrew Kushnir
parent 24bbcafe78
commit 26dba2180f
3 changed files with 53 additions and 1 deletions

View File

@ -200,6 +200,15 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
].join('\n'));
});
it('should support ES5 localized strings', () => {
expect(emitStmt(new o.ExpressionStatement(o.localizedString(
{}, ['ab\\:c', 'd"e\'f'], ['ph1'],
[o.literal(7, o.NUMBER_TYPE).plus(o.literal(8, o.NUMBER_TYPE))]))))
.toEqual(
String.raw
`$localize((this&&this.__makeTemplateObject||function(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e})(['ab\\:c', ':ph1:d"e\'f'], ['ab\\\\:c', ':ph1:d"e\'f']), (7 + 8));`);
});
it('should support try/catch', () => {
const bodyStmt = o.variable('body').callFn([]).toStmt();
const catchStmt =