refactor(compiler): move the MessagePiece classes into output_ast.ts (#38645)
The `MessagePiece` and derived classes, `LiteralPiece` and `PlaceholderPiece` need to be referenced in the `LocalizedString` output AST class, so that we can render the source-spans of each piece. PR Close #38645
This commit is contained in:

committed by
atscott

parent
109555b33a
commit
7a6a061a9e
@ -205,9 +205,12 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
});
|
||||
|
||||
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))]))))
|
||||
const messageParts =
|
||||
[new o.LiteralPiece('ab\\:c', {} as any), new o.LiteralPiece('d"e\'f', {} as any)];
|
||||
const placeholders = [new o.PlaceholderPiece('ph1', {} as any)];
|
||||
const expressions = [o.literal(7, o.NUMBER_TYPE).plus(o.literal(8, o.NUMBER_TYPE))];
|
||||
const localizedString = o.localizedString({}, messageParts, placeholders, expressions);
|
||||
expect(emitStmt(new o.ExpressionStatement(localizedString)))
|
||||
.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));`);
|
||||
|
@ -254,9 +254,12 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
|
||||
});
|
||||
|
||||
it('should support 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))]))))
|
||||
const messageParts =
|
||||
[new o.LiteralPiece('ab\\:c', {} as any), new o.LiteralPiece('d"e\'f', {} as any)];
|
||||
const placeholders = [new o.PlaceholderPiece('ph1', {} as any)];
|
||||
const expressions = [o.literal(7, o.NUMBER_TYPE).plus(o.literal(8, o.NUMBER_TYPE))];
|
||||
const localizedString = o.localizedString({}, messageParts, placeholders, expressions);
|
||||
expect(emitStmt(new o.ExpressionStatement(localizedString)))
|
||||
.toEqual('$localize `ab\\\\:c${(7 + 8)}:ph1:d"e\'f`;');
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user