mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
The `ng_rollup_bundle` rule has been replaced with a new rule called `app_bundle`. This rule replicates the Angular v13 optimization pipeline in the CLI, so that we can get better benchmarking results. Also the rule is much simpler to maintain as it relies on ESbuild. The old `ng_rollup_bundle` rule did rely on e.g. build-optimizer that no longer has an effect on v13 Angular packages, so technically size tests/symbol tests were no longer as correct as they were before. This commit fixes that. A couple of different changes and their explanation: * Language-service will no longer use the benchmark rule for creating its NPM bundles! It will use plain `rollup_bundle`. ESBuild would have been nice but the language-service relies on AMD that ESBuild cannot generate (yet?) * Service-worker ngsw-worker.js file was generated using the benchmark bundle rule. This is wrong. We will use a simple ESbuild rule in the future. The output is more predictable that way, and we can have a clear use of the benchmark bundle rule.. * A couple of benchmarks in `modules/` had to be updated to use e.g. `initTableUtils` calls. This is done because with the new rule, all files except for the entry-point are considered side-effect free. The utilities for benchmarks relied on side-effects in some transitively-loaded file (bad practice anyway IMO). We are now initializing the utilities using a proper init function that is exported... PR Close #44490
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
/**
|
|
* @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.io/license
|
|
*/
|
|
|
|
import {getIntParameter} from '../util';
|
|
|
|
export class TreeNode {
|
|
transitiveChildCount: number;
|
|
children: TreeNode[];
|
|
|
|
constructor(
|
|
public value: string, public depth: number, public maxDepth: number,
|
|
public left: TreeNode|null, public right: TreeNode|null) {
|
|
this.transitiveChildCount = Math.pow(2, (this.maxDepth - this.depth + 1)) - 1;
|
|
this.children = this.left ? [this.left, this.right!] : [];
|
|
}
|
|
|
|
// Needed for Polymer as it does not support ternary nor modulo operator
|
|
// in expressions
|
|
get style(): string {
|
|
return this.depth % 2 === 0 ? 'background-color: grey' : '';
|
|
}
|
|
}
|
|
|
|
let treeCreateCount: number;
|
|
let maxDepth: number;
|
|
let numberData: TreeNode;
|
|
let charData: TreeNode;
|
|
|
|
export function getMaxDepth() {
|
|
return maxDepth;
|
|
}
|
|
|
|
export function initTreeUtils() {
|
|
maxDepth = getIntParameter('depth');
|
|
treeCreateCount = 0;
|
|
numberData = _buildTree(0, numberValues);
|
|
charData = _buildTree(0, charValues);
|
|
}
|
|
|
|
function _buildTree(currDepth: number, valueFn: (depth: number) => string): TreeNode {
|
|
const children = currDepth < maxDepth ? _buildTree(currDepth + 1, valueFn) : null;
|
|
return new TreeNode(valueFn(currDepth), currDepth, maxDepth, children, children);
|
|
}
|
|
|
|
export const emptyTree = new TreeNode('', 0, 0, null, null);
|
|
|
|
export function buildTree(): TreeNode {
|
|
treeCreateCount++;
|
|
return treeCreateCount % 2 ? numberData : charData;
|
|
}
|
|
|
|
function numberValues(depth: number): string {
|
|
return depth.toString();
|
|
}
|
|
|
|
function charValues(depth: number): string {
|
|
return String.fromCharCode('A'.charCodeAt(0) + (depth % 26));
|
|
}
|
|
|
|
export function flattenTree(node: TreeNode, target: TreeNode[] = []): TreeNode[] {
|
|
target.push(node);
|
|
if (node.left) {
|
|
flattenTree(node.left, target);
|
|
}
|
|
if (node.right) {
|
|
flattenTree(node.right, target);
|
|
}
|
|
return target;
|
|
}
|
|
|
|
export function newArray<T = any>(size: number): T[];
|
|
export function newArray<T>(size: number, value: T): T[];
|
|
export function newArray<T>(size: number, value?: T): T[] {
|
|
const list: T[] = [];
|
|
for (let i = 0; i < size; i++) {
|
|
list.push(value!);
|
|
}
|
|
return list;
|
|
}
|