8000 [Patch port] fix(compiler): error if rawText isn't estimated correctly (#60529) by crisbeto · Pull Request #60753 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

[Patch port] fix(compiler): error if rawText isn't estimated correctly (#60529) #60753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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 @@ -683,23 +683,22 @@ export class TemplateLiteralExpr extends Expression {
}
}
export class TemplateLiteralElementExpr extends Expression {
rawText: string;
readonly rawText: string;

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
1 change: 1 addition & 0 deletions packages/core/test/application_ref_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Type,
ViewChild,
ViewContainerRef,
Injector,
} from '../src/core';
import {ErrorHandler} from '../src/error_handler';
import {ComponentRef} from '../src/linker/component_factory';
Expand Down
0