diff --git a/integration/_payload-limits.json b/integration/_payload-limits.json index 9d62c9f0fa..9957587800 100644 --- a/integration/_payload-limits.json +++ b/integration/_payload-limits.json @@ -3,7 +3,7 @@ "master": { "uncompressed": { "runtime": 1497, - "main": 166739, + "main": 166799, "polyfills": 43626 } } @@ -34,4 +34,4 @@ } } } -} +} \ No newline at end of file diff --git a/integration/side-effects/snapshots/core/esm2015.js b/integration/side-effects/snapshots/core/esm2015.js index 458c867642..7e58a587f5 100644 --- a/integration/side-effects/snapshots/core/esm2015.js +++ b/integration/side-effects/snapshots/core/esm2015.js @@ -30,20 +30,16 @@ function getSymbolIterator() { if ("undefined" === typeof ngI18nClosureMode) _global["ngI18nClosureMode"] = "undefined" !== typeof goog && "function" === typeof goog.getMsg; -function flatten(list, mapFn) { - const result = []; - let i = 0; - while (i < list.length) { - const item = list[i]; - if (Array.isArray(item)) if (item.length > 0) { - list = item.concat(list.slice(i + 1)); - i = 0; - } else i++; else { - result.push(mapFn ? mapFn(item) : item); - i++; - } +function flatten(list, dst) { + if (void 0 === dst) dst = list; + for (let i = 0; i < list.length; i++) { + let item = list[i]; + if (Array.isArray(item)) { + if (dst === list) dst = list.slice(0, i); + flatten(item, dst); + } else if (dst !== list) dst.push(item); } - return result; + return dst; } class EventEmitter extends Subject { diff --git a/packages/core/src/render3/jit/module.ts b/packages/core/src/render3/jit/module.ts index 4d35a0ec89..fe41493869 100644 --- a/packages/core/src/render3/jit/module.ts +++ b/packages/core/src/render3/jit/module.ts @@ -108,11 +108,13 @@ export function compileNgModuleDefs(moduleType: NgModuleType, ngModule: NgModule ngModuleDef = getCompilerFacade().compileNgModule( angularCoreEnv, `ng:///${moduleType.name}/ngModuleDef.js`, { type: moduleType, - bootstrap: flatten(ngModule.bootstrap || EMPTY_ARRAY, resolveForwardRef), + bootstrap: flatten(ngModule.bootstrap || EMPTY_ARRAY).map(resolveForwardRef), declarations: declarations.map(resolveForwardRef), - imports: flatten(ngModule.imports || EMPTY_ARRAY, resolveForwardRef) + imports: flatten(ngModule.imports || EMPTY_ARRAY) + .map(resolveForwardRef) .map(expandModuleWithProviders), - exports: flatten(ngModule.exports || EMPTY_ARRAY, resolveForwardRef) + exports: flatten(ngModule.exports || EMPTY_ARRAY) + .map(resolveForwardRef) .map(expandModuleWithProviders), emitInline: true, schemas: ngModule.schemas ? flatten(ngModule.schemas) : null, @@ -156,12 +158,12 @@ function verifySemanticsOfNgModuleDef(moduleType: NgModuleType): void { const errors: string[] = []; const declarations = maybeUnwrapFn(ngModuleDef.declarations); const imports = maybeUnwrapFn(ngModuleDef.imports); - flatten(imports, unwrapModuleWithProvidersImports).forEach(verifySemanticsOfNgModuleDef); + flatten(imports).map(unwrapModuleWithProvidersImports).forEach(verifySemanticsOfNgModuleDef); const exports = maybeUnwrapFn(ngModuleDef.exports); declarations.forEach(verifyDeclarationsHaveDefinitions); const combinedDeclarations: Type[] = [ ...declarations.map(resolveForwardRef), // - ...flatten(imports.map(computeCombinedExports), resolveForwardRef), + ...flatten(imports.map(computeCombinedExports)).map(resolveForwardRef), ]; exports.forEach(verifyExportsAreDeclaredOrReExported); declarations.forEach(verifyDeclarationIsUnique); @@ -170,7 +172,8 @@ function verifySemanticsOfNgModuleDef(moduleType: NgModuleType): void { const ngModule = getAnnotation(moduleType, 'NgModule'); if (ngModule) { ngModule.imports && - flatten(ngModule.imports, unwrapModuleWithProvidersImports) + flatten(ngModule.imports) + .map(unwrapModuleWithProvidersImports) .forEach(verifySemanticsOfNgModuleDef); ngModule.bootstrap && ngModule.bootstrap.forEach(verifyCorrectBootstrapType); ngModule.bootstrap && ngModule.bootstrap.forEach(verifyComponentIsPartOfNgModule); diff --git a/packages/core/src/util/array_utils.ts b/packages/core/src/util/array_utils.ts index aac3dba3d8..ab846bbf7b 100644 --- a/packages/core/src/util/array_utils.ts +++ b/packages/core/src/util/array_utils.ts @@ -19,24 +19,23 @@ export function addAllToArray(items: any[], arr: any[]) { } /** - * Flattens an array in non-recursive way. Input arrays are not modified. + * Flattens an array. */ -export function flatten(list: any[], mapFn?: (value: any) => any): any[] { - const result: any[] = []; - let i = 0; - while (i < list.length) { - const item = list[i]; +export function flatten(list: any[], dst?: any[]): any[] { + if (dst === undefined) dst = list; + for (let i = 0; i < list.length; i++) { + let item = list[i]; if (Array.isArray(item)) { - if (item.length > 0) { - list = item.concat(list.slice(i + 1)); - i = 0; - } else { - i++; + // we need to inline it. + if (dst === list) { + // Our assumption that the list was already flat was wrong and + // we need to clone flat since we need to write to it. + dst = list.slice(0, i); } - } else { - result.push(mapFn ? mapFn(item) : item); - i++; + flatten(item, dst); + } else if (dst !== list) { + dst.push(item); } } - return result; -} + return dst; +} \ No newline at end of file