fix(ivy): strip newlines from selectors in .d.ts files (#24738)

When writing selectors as string literal types in .d.ts files,
strip newlines to avoid generating invalid code. Newlines carry
no meaning in selectors anyway.

PR Close #24738
This commit is contained in:
Alex Rickabaugh 2018-07-02 11:24:58 -07:00 committed by Matias Niemelä
parent 02b5087685
commit d98b1c3bc4
1 changed files with 11 additions and 2 deletions

View File

@ -88,9 +88,14 @@ export function compileDirectiveFromMetadata(
bindingParser: BindingParser): R3DirectiveDef { bindingParser: BindingParser): R3DirectiveDef {
const definitionMap = baseDirectiveFields(meta, constantPool, bindingParser); const definitionMap = baseDirectiveFields(meta, constantPool, bindingParser);
const expression = o.importExpr(R3.defineDirective).callFn([definitionMap.toLiteralMap()]); const expression = o.importExpr(R3.defineDirective).callFn([definitionMap.toLiteralMap()]);
// On the type side, remove newlines from the selector as it will need to fit into a TypeScript
// string literal, which must be on one line.
const selectorForType = (meta.selector || '').replace(/\n/g, '');
const type = new o.ExpressionType(o.importExpr( const type = new o.ExpressionType(o.importExpr(
R3.DirectiveDef, R3.DirectiveDef,
[new o.ExpressionType(meta.type), new o.ExpressionType(o.literal(meta.selector || ''))])); [new o.ExpressionType(meta.type), new o.ExpressionType(o.literal(selectorForType))]));
return {expression, type}; return {expression, type};
} }
@ -157,10 +162,14 @@ export function compileComponentFromMetadata(
definitionMap.set('pipes', o.literalArr(Array.from(pipesUsed))); definitionMap.set('pipes', o.literalArr(Array.from(pipesUsed)));
} }
// On the type side, remove newlines from the selector as it will need to fit into a TypeScript
// string literal, which must be on one line.
const selectorForType = (meta.selector || '').replace(/\n/g, '');
const expression = o.importExpr(R3.defineComponent).callFn([definitionMap.toLiteralMap()]); const expression = o.importExpr(R3.defineComponent).callFn([definitionMap.toLiteralMap()]);
const type = new o.ExpressionType(o.importExpr( const type = new o.ExpressionType(o.importExpr(
R3.ComponentDef, R3.ComponentDef,
[new o.ExpressionType(meta.type), new o.ExpressionType(o.literal(meta.selector || ''))])); [new o.ExpressionType(meta.type), new o.ExpressionType(o.literal(selectorForType))]));
return {expression, type}; return {expression, type};
} }