Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ MyApp.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-
<div>No interpolations: {{ \`hello world \` }}</div>
<span>With interpolations: {{ \`hello \${name}, it is currently \${timeOfDay}!\` }}</span>
<p>With pipe: {{\`hello \${name}\` | uppercase}}</p>
<h4>@let insideLet = \`Hello \${name}\`; Inside let: {{insideLet}}</h4>
`, isInline: true, dependencies: [{ kind: "pipe", type: UppercasePipe, name: "uppercase" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyApp, decorators: [{
type: Component,
Expand All @@ -759,6 +760,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
<div>No interpolations: {{ \`hello world \` }}</div>
<span>With interpolations: {{ \`hello \${name}, it is currently \${timeOfDay}!\` }}</span>
<p>With pipe: {{\`hello \${name}\` | uppercase}}</p>
<h4>@let insideLet = \`Hello \${name}\`; Inside let: {{insideLet}}</h4>
`,
imports: [UppercasePipe],
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ if (rf & 2) {
$r3$.ɵɵadvance(2);
$r3$.ɵɵtextInterpolate1("With interpolations: ", `hello ${ctx.name}, it is currently ${ctx.timeOfDay}!`);
$r3$.ɵɵadvance(2);
$r3$.ɵɵtextInterpolate1("With pipe: ", $r3$.ɵɵpipeBind1(6, 3, `hello ${ctx.name}`));
$r3$.ɵɵtextInterpolate1("With pipe: ", $r3$.ɵɵpipeBind1(6, 4, `hello ${ctx.name}`));
const $insideLet_r1$ = `Hello ${ctx.name}`;
$r3$.ɵɵadvance(4);
$r3$.ɵɵtextInterpolate1(" Inside let: ", $insideLet_r1$);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class UppercasePipe {
<div>No interpolations: {{ \`hello world \` }}</div>
<span>With interpolations: {{ \`hello \${name}, it is currently \${timeOfDay}!\` }}</span>
<p>With pipe: {{\`hello \${name}\` | uppercase}}</p>
<h4>@let insideLet = \`Hello \${name}\`; Inside let: {{insideLet}}</h4>
`,
imports: [UppercasePipe],
})
Expand Down
13 changes: 6 additions & 7 deletions packages/compiler/src/output/output_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,23 +705,22 @@ export class TemplateLiteralExpr extends Expression {
}
}
export class TemplateLiteralElementExpr extends Expression {
rawText: string;
readonly rawText: string;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also exploring an approach where we just don't track the rawText at all and pass undefined for it. With TypeScript this works fine, but the Babel AST, which we use in the linker, has the opposite requirement where the raw string is required and the cooked one is optional.


constructor(
public text: string,
readonly text: string,
sourceSpan?: ParseSourceSpan | null,
rawText?: string,
) {
super(STRING_TYPE, sourceSpan);

// If `rawText` is not provided, try to extract the raw string from its
// associated `sourceSpan`. If that is also not available, "fake" the raw
// string instead by escaping the following control sequences:
// If `rawText` is not provided, "fake" the raw string by escaping the following sequences:
// - "\" would otherwise indicate that the next character is a control character.
// - "`" and "${" are template string control sequences that would otherwise prematurely
// indicate the end of the template literal element.
this.rawText =
rawText ?? sourceSpan?.toString() ?? escapeForTemplateLiteral(escapeSlashes(text));
// Note that we can't rely on the `sourceSpan` here, because it may be incorrect (see
// https://github.com/angular/angular/pull/60267#discussion_r1986402524).
this.rawText = rawText ?? escapeForTemplateLiteral(escapeSlashes(text));
}

override visitExpression(visitor: ExpressionVisitor, context: any) {
Expand Down