From 88f8ddd3d3a5da575590a6cc332c2ecf9483a742 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 28 Jan 2021 14:35:03 -0800 Subject: [PATCH] Revert "fix(core): remove duplicated EMPTY_ARRAY constant (#40587)" This reverts commit 34aa9c35318a79cf9ef8ae0c32c182eb90d5dc92. --- packages/core/src/di/r3_injector.ts | 3 ++- packages/core/src/di/util.ts | 2 +- packages/core/src/render3/context_discovery.ts | 2 +- packages/core/src/render3/definition.ts | 3 +-- packages/core/src/render3/empty.ts | 3 +++ .../core/src/render3/features/inherit_definition_feature.ts | 3 +-- .../src/render3/instructions/i18n_icu_container_visitor.ts | 2 +- packages/core/src/render3/jit/directive.ts | 3 +-- packages/core/src/render3/jit/module.ts | 3 ++- packages/core/src/view/index.ts | 3 +-- packages/core/src/view/util.ts | 1 + .../core/test/bundling/forms/bundle.golden_symbols.json | 6 ++++++ .../core/test/bundling/router/bundle.golden_symbols.json | 3 +++ packages/core/test/bundling/todo/bundle.golden_symbols.json | 3 +++ 14 files changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/core/src/di/r3_injector.ts b/packages/core/src/di/r3_injector.ts index 9596c3c4ea..c993e6a738 100644 --- a/packages/core/src/di/r3_injector.ts +++ b/packages/core/src/di/r3_injector.ts @@ -13,7 +13,6 @@ import {AbstractType, Type} from '../interface/type'; import {FactoryFn, getFactoryDef} from '../render3/definition_factory'; import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiProviderError} from '../render3/errors_di'; import {deepForEach, newArray} from '../util/array_utils'; -import {EMPTY_ARRAY} from '../util/empty'; import {stringify} from '../util/stringify'; import {resolveForwardRef} from './forward_ref'; @@ -49,6 +48,8 @@ const NOT_YET = {}; */ const CIRCULAR = {}; +const EMPTY_ARRAY = [] as any[]; + /** * A lazily initialized NullInjector. */ diff --git a/packages/core/src/di/util.ts b/packages/core/src/di/util.ts index 1bb5537581..2070b057e3 100644 --- a/packages/core/src/di/util.ts +++ b/packages/core/src/di/util.ts @@ -8,7 +8,6 @@ import {Type} from '../interface/type'; import {ReflectionCapabilities} from '../reflection/reflection_capabilities'; -import {EMPTY_ARRAY} from '../util/empty'; import {getClosureSafeProperty} from '../util/property'; import {resolveForwardRef} from './forward_ref'; @@ -17,6 +16,7 @@ import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, Factor const USE_VALUE = getClosureSafeProperty({provide: String, useValue: getClosureSafeProperty}); +const EMPTY_ARRAY: any[] = []; export function convertInjectableProviderToFactory( type: Type, diff --git a/packages/core/src/render3/context_discovery.ts b/packages/core/src/render3/context_discovery.ts index 49dc61d169..096d4f2056 100644 --- a/packages/core/src/render3/context_discovery.ts +++ b/packages/core/src/render3/context_discovery.ts @@ -9,7 +9,7 @@ import '../util/ng_dev_mode'; import {assertDomNode} from '../util/assert'; -import {EMPTY_ARRAY} from '../util/empty'; +import {EMPTY_ARRAY} from './empty'; import {LContext, MONKEY_PATCH_KEY_NAME} from './interfaces/context'; import {TNode, TNodeFlags} from './interfaces/node'; import {RElement, RNode} from './interfaces/renderer_dom'; diff --git a/packages/core/src/render3/definition.ts b/packages/core/src/render3/definition.ts index 03d665978c..0b75b5c836 100644 --- a/packages/core/src/render3/definition.ts +++ b/packages/core/src/render3/definition.ts @@ -12,10 +12,9 @@ import {NgModuleDef, NgModuleType} from '../metadata/ng_module_def'; import {SchemaMetadata} from '../metadata/schema'; import {ViewEncapsulation} from '../metadata/view'; import {noSideEffects} from '../util/closure'; -import {EMPTY_ARRAY} from '../util/empty'; import {initNgDevMode} from '../util/ng_dev_mode'; import {stringify} from '../util/stringify'; -import {EMPTY_OBJ} from './empty'; +import {EMPTY_ARRAY, EMPTY_OBJ} from './empty'; import {NG_COMP_DEF, NG_DIR_DEF, NG_LOC_ID_DEF, NG_MOD_DEF, NG_PIPE_DEF} from './fields'; import {ComponentDef, ComponentDefFeature, ComponentTemplate, ComponentType, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, DirectiveTypesOrFactory, HostBindingsFunction, PipeDef, PipeTypesOrFactory, ViewQueriesFunction} from './interfaces/definition'; import {AttributeMarker, TAttributes, TConstantsOrFactory} from './interfaces/node'; diff --git a/packages/core/src/render3/empty.ts b/packages/core/src/render3/empty.ts index 78ef36a82d..52382fcf72 100644 --- a/packages/core/src/render3/empty.ts +++ b/packages/core/src/render3/empty.ts @@ -15,6 +15,7 @@ import {initNgDevMode} from '../util/ng_dev_mode'; */ export const EMPTY_OBJ: {} = {}; +export const EMPTY_ARRAY: any[] = []; // freezing the values prevents any code from accidentally inserting new values in if ((typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode()) { @@ -22,4 +23,6 @@ if ((typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode()) { // when optimizing code and the whole if statement will be dropped. // tslint:disable-next-line:no-toplevel-property-access Object.freeze(EMPTY_OBJ); + // tslint:disable-next-line:no-toplevel-property-access + Object.freeze(EMPTY_ARRAY); } diff --git a/packages/core/src/render3/features/inherit_definition_feature.ts b/packages/core/src/render3/features/inherit_definition_feature.ts index 7f454c6588..891a2b9a92 100644 --- a/packages/core/src/render3/features/inherit_definition_feature.ts +++ b/packages/core/src/render3/features/inherit_definition_feature.ts @@ -7,9 +7,8 @@ */ import {Type, Writable} from '../../interface/type'; -import {EMPTY_ARRAY} from '../../util/empty'; import {fillProperties} from '../../util/property'; -import {EMPTY_OBJ} from '../empty'; +import {EMPTY_ARRAY, EMPTY_OBJ} from '../empty'; import {ComponentDef, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, HostBindingsFunction, RenderFlags, ViewQueriesFunction} from '../interfaces/definition'; import {TAttributes} from '../interfaces/node'; import {isComponentDef} from '../interfaces/type_checks'; diff --git a/packages/core/src/render3/instructions/i18n_icu_container_visitor.ts b/packages/core/src/render3/instructions/i18n_icu_container_visitor.ts index acb42f498c..1d203a2acf 100644 --- a/packages/core/src/render3/instructions/i18n_icu_container_visitor.ts +++ b/packages/core/src/render3/instructions/i18n_icu_container_visitor.ts @@ -7,8 +7,8 @@ */ import {assertDomNode, assertNumber, assertNumberInRange} from '../../util/assert'; -import {EMPTY_ARRAY} from '../../util/empty'; import {assertTIcu, assertTNodeForLView} from '../assert'; +import {EMPTY_ARRAY} from '../empty'; import {getCurrentICUCaseIndex} from '../i18n/i18n_util'; import {I18nRemoveOpCodes, TIcu} from '../interfaces/i18n'; import {TIcuContainerNode} from '../interfaces/node'; diff --git a/packages/core/src/render3/jit/directive.ts b/packages/core/src/render3/jit/directive.ts index 91ce5262dd..1b7085ebd3 100644 --- a/packages/core/src/render3/jit/directive.ts +++ b/packages/core/src/render3/jit/directive.ts @@ -15,10 +15,9 @@ import {Query} from '../../metadata/di'; import {Component, Directive, Input} from '../../metadata/directives'; import {componentNeedsResolution, maybeQueueResolutionOfComponentResources} from '../../metadata/resource_loading'; import {ViewEncapsulation} from '../../metadata/view'; -import {EMPTY_ARRAY} from '../../util/empty'; import {initNgDevMode} from '../../util/ng_dev_mode'; import {getComponentDef, getDirectiveDef} from '../definition'; -import {EMPTY_OBJ} from '../empty'; +import {EMPTY_ARRAY, EMPTY_OBJ} from '../empty'; import {NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF} from '../fields'; import {ComponentType} from '../interfaces/definition'; import {stringifyForError} from '../util/stringify_utils'; diff --git a/packages/core/src/render3/jit/module.ts b/packages/core/src/render3/jit/module.ts index 478a8f544c..7450c5dc7f 100644 --- a/packages/core/src/render3/jit/module.ts +++ b/packages/core/src/render3/jit/module.ts @@ -16,7 +16,6 @@ import {ModuleWithProviders, NgModule} from '../../metadata/ng_module'; import {NgModuleDef, NgModuleTransitiveScopes, NgModuleType} from '../../metadata/ng_module_def'; import {deepForEach, flatten} from '../../util/array_utils'; import {assertDefined} from '../../util/assert'; -import {EMPTY_ARRAY} from '../../util/empty'; import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition'; import {NG_COMP_DEF, NG_DIR_DEF, NG_MOD_DEF, NG_PIPE_DEF} from '../fields'; import {ComponentDef} from '../interfaces/definition'; @@ -25,6 +24,8 @@ import {stringifyForError} from '../util/stringify_utils'; import {angularCoreEnv} from './environment'; +const EMPTY_ARRAY: Type[] = []; + interface ModuleQueueItem { moduleType: Type; ngModule: NgModule; diff --git a/packages/core/src/view/index.ts b/packages/core/src/view/index.ts index 74e9cfc8a2..7a828eb1dc 100644 --- a/packages/core/src/view/index.ts +++ b/packages/core/src/view/index.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -export {EMPTY_ARRAY} from '../util/empty'; export {anchorDef, elementDef} from './element'; export {clearOverrides, createNgModuleFactory, overrideComponentView, overrideProvider} from './entrypoint'; export {ngContentDef} from './ng_content'; @@ -17,7 +16,7 @@ export {queryDef} from './query'; export {createComponentFactory, getComponentViewDefinitionFactory, nodeValue, ViewRef_} from './refs'; export {initServicesIfNeeded} from './services'; export {textDef} from './text'; -export {createRendererType2, elementEventFullName, EMPTY_MAP, inlineInterpolate, interpolate, rootRenderNodes, tokenKey, unwrapValue} from './util'; +export {createRendererType2, elementEventFullName, EMPTY_ARRAY, EMPTY_MAP, inlineInterpolate, interpolate, rootRenderNodes, tokenKey, unwrapValue} from './util'; export {viewDef} from './view'; export {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView} from './view_attach'; diff --git a/packages/core/src/view/util.ts b/packages/core/src/view/util.ts index c83b49360c..459b222381 100644 --- a/packages/core/src/view/util.ts +++ b/packages/core/src/view/util.ts @@ -444,4 +444,5 @@ function _toStringWithNull(v: any): string { return v != null ? v.toString() : ''; } +export const EMPTY_ARRAY: any[] = []; export const EMPTY_MAP: {[key: string]: any} = {}; diff --git a/packages/core/test/bundling/forms/bundle.golden_symbols.json b/packages/core/test/bundling/forms/bundle.golden_symbols.json index 91167e7414..8ef0dcdff9 100644 --- a/packages/core/test/bundling/forms/bundle.golden_symbols.json +++ b/packages/core/test/bundling/forms/bundle.golden_symbols.json @@ -173,6 +173,12 @@ { "name": "EMPTY_ARRAY" }, + { + "name": "EMPTY_ARRAY" + }, + { + "name": "EMPTY_ARRAY" + }, { "name": "EMPTY_OBJ" }, diff --git a/packages/core/test/bundling/router/bundle.golden_symbols.json b/packages/core/test/bundling/router/bundle.golden_symbols.json index b131ed3a3c..d7ca828b94 100644 --- a/packages/core/test/bundling/router/bundle.golden_symbols.json +++ b/packages/core/test/bundling/router/bundle.golden_symbols.json @@ -236,6 +236,9 @@ { "name": "EMPTY_ARRAY" }, + { + "name": "EMPTY_ARRAY" + }, { "name": "EMPTY_OBJ" }, diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index b070bffadd..86bd5b20cf 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -14,6 +14,9 @@ { "name": "EMPTY_ARRAY" }, + { + "name": "EMPTY_ARRAY" + }, { "name": "EMPTY_OBJ" },