perf(core): guard i18n insertion assertion with ngDevMode

Guard the insertBeforeIndex array invariant so production bundles can
remove the development-only assertion while preserving runtime behavior.

Add an optimized i18n fixture with nested placeholders and ICU plural
cases, using the standard symbol extractor test and generated golden.
Removing the guard makes the test fail because assertEqual and throwError
are retained in the production bundle.
This commit is contained in:
Максим Иванов
2026-10-20 13:37:47 -07:00
committed by Leon Senft
parent 63f4bd4c7e
commit 85e7e5054a
4 changed files with 889 additions and 1 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ export function setTNodeInsertBeforeIndex(tNode: TNode, index: number) {
index,
];
} else {
assertEqual(Array.isArray(insertBeforeIndex), true, 'Expecting array here');
ngDevMode && assertEqual(Array.isArray(insertBeforeIndex), true, 'Expecting array here');
(insertBeforeIndex as number[]).push(index);
}
}
@@ -0,0 +1,28 @@
load("@rules_angular//src/optimization:index.bzl", "optimize_angular_app")
load("//tools/symbol-extractor:index.bzl", "js_expected_symbol_test")
package(default_visibility = ["//visibility:public"])
optimize_angular_app(
name = "bundles",
srcs = [
"main.ts",
],
env = {
"NG_BUILD_MANGLE": "0",
},
deps = [
"//:node_modules/rxjs",
"//:node_modules/tslib",
"//packages/core/test/bundling:node_modules/@angular/build",
"//packages/core/test/bundling:node_modules/@angular/common",
"//packages/core/test/bundling:node_modules/@angular/core",
"//packages/core/test/bundling:node_modules/@angular/platform-browser",
],
)
js_expected_symbol_test(
name = "symbol_test",
bundles_dir = ":bundles",
golden = ":bundle.golden_symbols.json",
)
File diff suppressed because it is too large Load Diff
+29
View File
@@ -0,0 +1,29 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Component} from '@angular/core';
import {bootstrapApplication} from '@angular/platform-browser';
@Component({
selector: 'app-root',
template: `
<h1 i18n="@@greeting">
Hello <strong>{{ name }}</strong
>!
</h1>
<p i18n="@@notificationCount">
{count, plural, =0 {No notifications} =1 {One notification} other {Many notifications}}
</p>
`,
})
class AppComponent {
name = 'Angular';
count = 2;
}
bootstrapApplication(AppComponent);