mirror of
https://github.com/angular/angular.git
synced 2026-11-23 07:05:14 -05:00
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:
committed by
Leon Senft
parent
63f4bd4c7e
commit
85e7e5054a
@@ -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
@@ -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);
|
||||
Reference in New Issue
Block a user