Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression>
// Enable the new block syntax if compiled with v17 and
// above, or when using the local placeholder version.
const enableBlockSyntax = semver.major(version) >= 17 || version === PLACEHOLDER_VERSION;
const enableLetSyntax = version === PLACEHOLDER_VERSION;

const template = parseTemplate(templateInfo.code, templateInfo.sourceUrl, {
escapedString: templateInfo.isEscaped,
Expand All @@ -116,6 +117,7 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression>
// We normalize line endings if the template is was inline.
i18nNormalizeLineEndingsInICUs: isInline,
enableBlockSyntax,
enableLetSyntax,
});
if (template.errors !== null) {
const errors = template.errors.map((err) => err.toString()).join('\n');
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
{
"$schema": "../test_case_schema.json",
"cases": [
{
"description": "should create a simple @let declaration",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"simple_let.ts"
],
"expectations": [
{
"files": [
{
"expected": "simple_let_template.js",
"generated": "simple_let.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should create multiple @let declarations that depend on each other",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"multiple_let.ts"
],
"expectations": [
{
"files": [
{
"expected": "multiple_let_template.js",
"generated": "multiple_let.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should create a let using a pipe",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_with_pipe.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_with_pipe_template.js",
"generated": "let_with_pipe.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should be able to use let declarations in event listeners",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_in_listener.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_in_listener_template.js",
"generated": "let_in_listener.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should be able to use let declarations in child views",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_in_child_view.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_in_child_view_template.js",
"generated": "let_in_child_view.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should share let declarations between parent and child views",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_shared_with_child_view.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_shared_with_child_view_template.js",
"generated": "let_shared_with_child_view.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should be able to use let declarations in event listeners inside child views",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_in_child_view_listener.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_in_child_view_listener_template.js",
"generated": "let_in_child_view_listener.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should be able to use local references in let declarations",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_local_refs.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_local_refs_template.js",
"generated": "let_local_refs.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should be able to use forward references defined after the let declaration",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_local_forward_refs.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_local_forward_refs_template.js",
"generated": "let_local_forward_refs.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should be able to use for loop variables in let declarations",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_for_loop.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_for_loop_template.js",
"generated": "let_for_loop.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should transform an invalid let reference to undefined",
"angularCompilerOptions": {
"_enableLetSyntax": true,
"checkTemplateBodies": false
},
"inputFiles": [
"let_invalid_forward_ref.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_invalid_forward_ref_template.js",
"generated": "let_invalid_forward_ref.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should remove a single unused let declaration",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_single_optimization.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_single_optimization_template.js",
"generated": "let_single_optimization.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should remove a chain of unused let declarations",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_multiple_optimization.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_multiple_optimization_template.js",
"generated": "let_multiple_optimization.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should remove only the unused let declarations from the middle of a chain of declarations",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_partial_optimization.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_partial_optimization_template.js",
"generated": "let_partial_optimization.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should not remove let declarations that are only used in an event listener",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_optimization_listener.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_optimization_listener_template.js",
"generated": "let_optimization_listener.js"
}
],
"failureMessage": "Incorrect template"
}
]
},
{
"description": "should not remove let declarations that are only used in a child view",
"angularCompilerOptions": {
"_enableLetSyntax": true
},
"inputFiles": [
"let_optimization_child_view.ts"
],
"expectations": [
{
"files": [
{
"expected": "let_optimization_child_view_template.js",
"generated": "let_optimization_child_view.js"
}
],
"failureMessage": "Incorrect template"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Component} from '@angular/core';

@Component({
template: `
@for (item of items; track item) {
@let outerFirst = $first;
@for (subitem of item.children; track subitem) {
@let innerFirst = $first;
{{outerFirst || innerFirst}}
}
}
`,
standalone: true,
})
export class MyApp {
items: {children: any[]}[] = [];
}
Loading