refactor(ivy): i18n - remove hack around TS tagged literals (#34135)

When first written there was no way to specify the raw text when
programmatically creating a template tagged literal AST node.

This is now fixed in TS and so the hack is no longer needed.

PR Close #34135
This commit is contained in:
Pete Bacon Darwin 2019-12-03 08:36:38 +00:00 committed by Miško Hevery
parent e12933a3aa
commit 80d326bd49
3 changed files with 0 additions and 42 deletions

View File

@ -159,25 +159,12 @@ const BLOCK_MARKER = ':';
* escaped with a backslash, `\:`. This function checks for this by looking at the `raw`
* messagePart, which should still contain the backslash.
*
* ---
*
* If the template literal was synthesized and downleveled by TypeScript to ES5 then its
* raw array will only contain empty strings. This is because the current TypeScript compiler uses
* the original source code to find the raw text and in the case of synthesized AST nodes, there is
* no source code to draw upon.
*
* The workaround in this function is to assume that the template literal did not contain an escaped
* placeholder name, and fall back on checking the cooked array instead.
* This is a limitation if compiling to ES5 in TypeScript but is not a problem if the TypeScript
* output is ES2015 and the code is downleveled by a separate tool as happens in the Angular CLI.
*
* @param messagePart The cooked message part to process.
* @param rawMessagePart The raw message part to check.
* @returns the message part with the placeholder name stripped, if found.
* @throws an error if the block is unterminated
*/
function stripBlock(messagePart: string, rawMessagePart: string) {
rawMessagePart = rawMessagePart || messagePart;
return rawMessagePart.charAt(0) === BLOCK_MARKER ?
messagePart.substring(findEndOfBlock(messagePart, rawMessagePart) + 1) :
messagePart;

View File

@ -182,18 +182,6 @@ export function parseMetadata(cooked: string, raw: string): MessageMetadata {
* Since blocks are optional, it is possible that the content of a message block actually starts
* with a block marker. In this case the marker must be escaped `\:`.
*
* ---
*
* If the template literal was synthesized and downleveled by TypeScript to ES5 then its
* raw array will only contain empty strings. This is because the current TypeScript compiler uses
* the original source code to find the raw text and in the case of synthesized AST nodes, there is
* no source code to draw upon.
*
* The workaround in this function is to assume that the template literal did not contain an escaped
* placeholder name, and fall back on checking the cooked array instead.
* This is a limitation if compiling to ES5 in TypeScript but is not a problem if the TypeScript
* output is ES2015 and the code is downlevelled by a separate tool as happens in the Angular CLI.
*
* @param cooked The cooked version of the message part to parse.
* @param raw The raw version of the message part to parse.
* @returns An object containing the `text` of the message part and the text of the `block`, if it
@ -201,7 +189,6 @@ export function parseMetadata(cooked: string, raw: string): MessageMetadata {
* @throws an error if the `block` is unterminated
*/
export function splitBlock(cooked: string, raw: string): {text: string, block?: string} {
raw = raw || cooked;
if (raw.charAt(0) !== BLOCK_MARKER) {
return {text: cooked};
} else {

View File

@ -61,12 +61,6 @@ describe('messages utils', () => {
expect(message.messageId).toEqual('2623373088949454037');
});
it('should handle raw values that are empty (from synthesized AST)', () => {
const message =
parseMessage(makeTemplateObject(['a', ':one:b', ':two:c'], ['', '', '']), [1, 2]);
expect(message.messageId).toEqual('8865273085679272414');
});
it('should extract the meaning, description and placeholder names', () => {
const message1 = parseMessage(makeTemplateObject(['abc'], ['abc']), []);
expect(message1.messageParts).toEqual(['abc']);
@ -128,10 +122,6 @@ describe('messages utils', () => {
':block with escaped : in it:abc def', ':block with escaped \\: in it:abc def'))
.toEqual({text: 'abc def', block: 'block with escaped : in it'});
});
it('should handle the empty raw part', () => {
expect(splitBlock(':block info:abc def', '')).toEqual({text: 'abc def', block: 'block info'});
});
});
describe('findEndOfBlock()', () => {
@ -193,11 +183,5 @@ describe('messages utils', () => {
id: undefined
});
});
it('should handle the empty raw part', () => {
expect(parseMetadata(':description:abc def', ''))
.toEqual(
{text: 'abc def', meaning: undefined, description: 'description', id: undefined});
});
});
});