forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): support tagged template literals in expressions (angu…
…lar#59947) Adds support for using tagged template literals in Angular templates. Ex: ``` @component({ template: '{{ greet`Hello, ${name()}` }}' }) export class MyComp { name = input(); greet(strings: TemplateStringsArray, name: string) { return strings[0] + name + strings[1] + '!'; } } ``` PR Close angular#59947
- Loading branch information
Showing
20 changed files
with
547 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...mpiler_compliance/components_and_directives/value_composition/tagged_template_literals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if (rf & 2) { | ||
$r3$.ɵɵadvance(); | ||
$r3$.ɵɵtextInterpolate1("No interpolations: ", ctx.tag `hello world `, ""); | ||
$r3$.ɵɵadvance(2); | ||
$r3$.ɵɵtextInterpolate1("With interpolations: ", ctx.tag `hello ${ctx.name}, it is currently ${ctx.timeOfDay}!`, ""); | ||
$r3$.ɵɵadvance(2); | ||
$r3$.ɵɵtextInterpolate1("With pipe: ", $r3$.ɵɵpipeBind1(6, 3, ctx.tag `hello ${ctx.name}`), ""); | ||
} |
23 changes: 23 additions & 0 deletions
23
...mpiler_compliance/components_and_directives/value_composition/tagged_template_literals.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {Component, Pipe} from '@angular/core'; | ||
|
||
@Pipe({name: 'uppercase'}) | ||
export class UppercasePipe { | ||
transform(value: string) { | ||
return value.toUpperCase(); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'my-app', | ||
template: ` | ||
<div>No interpolations: {{ tag\`hello world \` }}</div> | ||
<span>With interpolations: {{ tag\`hello \${name}, it is currently \${timeOfDay}!\` }}</span> | ||
<p>With pipe: {{ tag\`hello \${name}\` | uppercase }}</p> | ||
`, | ||
imports: [UppercasePipe], | ||
}) | ||
export class MyApp { | ||
name = 'Frodo'; | ||
timeOfDay = 'morning'; | ||
tag = (strings: TemplateStringsArray, ...args: string[]) => ''; | ||
} |
Oops, something went wrong.