fix(core): remove duplicated EMPTY_ARRAY constant (#40991)

The codebase currently contains several `EMPTY_ARRAY` constants,
and they can end up in the bundle of an application.
A recent commit 6fbe219 tipped us off
as it introduced several `noop` occurrences in the golden symbol files.
After investigating with @petebacondarwin,
we decided to remove the duplicated symbols.

This probably shaves only a few bytes,
but this commit removes the duplicated functions,
by always using the one in `core/src/utils/empty`.

PR Close #40991
This commit is contained in:
cexbrayat 2021-01-20 18:13:00 +01:00 committed by Zach Arend
parent be8893fd1d
commit e12d9dec64
14 changed files with 13 additions and 27 deletions

View File

@ -13,6 +13,7 @@ import {AbstractType, Type} from '../interface/type';
import {FactoryFn, getFactoryDef} from '../render3/definition_factory'; import {FactoryFn, getFactoryDef} from '../render3/definition_factory';
import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiProviderError} from '../render3/errors_di'; import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiProviderError} from '../render3/errors_di';
import {deepForEach, newArray} from '../util/array_utils'; import {deepForEach, newArray} from '../util/array_utils';
import {EMPTY_ARRAY} from '../util/empty';
import {stringify} from '../util/stringify'; import {stringify} from '../util/stringify';
import {resolveForwardRef} from './forward_ref'; import {resolveForwardRef} from './forward_ref';
@ -48,8 +49,6 @@ const NOT_YET = {};
*/ */
const CIRCULAR = {}; const CIRCULAR = {};
const EMPTY_ARRAY = [] as any[];
/** /**
* A lazily initialized NullInjector. * A lazily initialized NullInjector.
*/ */

View File

@ -8,6 +8,7 @@
import {Type} from '../interface/type'; import {Type} from '../interface/type';
import {ReflectionCapabilities} from '../reflection/reflection_capabilities'; import {ReflectionCapabilities} from '../reflection/reflection_capabilities';
import {EMPTY_ARRAY} from '../util/empty';
import {getClosureSafeProperty} from '../util/property'; import {getClosureSafeProperty} from '../util/property';
import {resolveForwardRef} from './forward_ref'; import {resolveForwardRef} from './forward_ref';
@ -16,7 +17,6 @@ import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, Factor
const USE_VALUE = const USE_VALUE =
getClosureSafeProperty<ValueProvider>({provide: String, useValue: getClosureSafeProperty}); getClosureSafeProperty<ValueProvider>({provide: String, useValue: getClosureSafeProperty});
const EMPTY_ARRAY: any[] = [];
export function convertInjectableProviderToFactory( export function convertInjectableProviderToFactory(
type: Type<any>, type: Type<any>,

View File

@ -9,7 +9,7 @@ import '../util/ng_dev_mode';
import {assertDomNode} from '../util/assert'; import {assertDomNode} from '../util/assert';
import {EMPTY_ARRAY} from './empty'; import {EMPTY_ARRAY} from '../util/empty';
import {LContext, MONKEY_PATCH_KEY_NAME} from './interfaces/context'; import {LContext, MONKEY_PATCH_KEY_NAME} from './interfaces/context';
import {TNode, TNodeFlags} from './interfaces/node'; import {TNode, TNodeFlags} from './interfaces/node';
import {RElement, RNode} from './interfaces/renderer_dom'; import {RElement, RNode} from './interfaces/renderer_dom';

View File

@ -12,9 +12,10 @@ import {NgModuleDef, NgModuleType} from '../metadata/ng_module_def';
import {SchemaMetadata} from '../metadata/schema'; import {SchemaMetadata} from '../metadata/schema';
import {ViewEncapsulation} from '../metadata/view'; import {ViewEncapsulation} from '../metadata/view';
import {noSideEffects} from '../util/closure'; import {noSideEffects} from '../util/closure';
import {EMPTY_ARRAY} from '../util/empty';
import {initNgDevMode} from '../util/ng_dev_mode'; import {initNgDevMode} from '../util/ng_dev_mode';
import {stringify} from '../util/stringify'; import {stringify} from '../util/stringify';
import {EMPTY_ARRAY, EMPTY_OBJ} from './empty'; import {EMPTY_OBJ} from './empty';
import {NG_COMP_DEF, NG_DIR_DEF, NG_LOC_ID_DEF, NG_MOD_DEF, NG_PIPE_DEF} from './fields'; 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 {ComponentDef, ComponentDefFeature, ComponentTemplate, ComponentType, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, DirectiveTypesOrFactory, HostBindingsFunction, PipeDef, PipeTypesOrFactory, ViewQueriesFunction} from './interfaces/definition';
import {AttributeMarker, TAttributes, TConstantsOrFactory} from './interfaces/node'; import {AttributeMarker, TAttributes, TConstantsOrFactory} from './interfaces/node';

View File

@ -15,7 +15,6 @@ import {initNgDevMode} from '../util/ng_dev_mode';
*/ */
export const EMPTY_OBJ: {} = {}; export const EMPTY_OBJ: {} = {};
export const EMPTY_ARRAY: any[] = [];
// freezing the values prevents any code from accidentally inserting new values in // freezing the values prevents any code from accidentally inserting new values in
if ((typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode()) { if ((typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode()) {
@ -23,6 +22,4 @@ if ((typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode()) {
// when optimizing code and the whole if statement will be dropped. // when optimizing code and the whole if statement will be dropped.
// tslint:disable-next-line:no-toplevel-property-access // tslint:disable-next-line:no-toplevel-property-access
Object.freeze(EMPTY_OBJ); Object.freeze(EMPTY_OBJ);
// tslint:disable-next-line:no-toplevel-property-access
Object.freeze(EMPTY_ARRAY);
} }

View File

@ -7,8 +7,9 @@
*/ */
import {Type, Writable} from '../../interface/type'; import {Type, Writable} from '../../interface/type';
import {EMPTY_ARRAY} from '../../util/empty';
import {fillProperties} from '../../util/property'; import {fillProperties} from '../../util/property';
import {EMPTY_ARRAY, EMPTY_OBJ} from '../empty'; import {EMPTY_OBJ} from '../empty';
import {ComponentDef, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, HostBindingsFunction, RenderFlags, ViewQueriesFunction} from '../interfaces/definition'; import {ComponentDef, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, HostBindingsFunction, RenderFlags, ViewQueriesFunction} from '../interfaces/definition';
import {TAttributes} from '../interfaces/node'; import {TAttributes} from '../interfaces/node';
import {isComponentDef} from '../interfaces/type_checks'; import {isComponentDef} from '../interfaces/type_checks';

View File

@ -7,8 +7,8 @@
*/ */
import {assertDomNode, assertNumber, assertNumberInRange} from '../../util/assert'; import {assertDomNode, assertNumber, assertNumberInRange} from '../../util/assert';
import {EMPTY_ARRAY} from '../../util/empty';
import {assertTIcu, assertTNodeForLView} from '../assert'; import {assertTIcu, assertTNodeForLView} from '../assert';
import {EMPTY_ARRAY} from '../empty';
import {getCurrentICUCaseIndex} from '../i18n/i18n_util'; import {getCurrentICUCaseIndex} from '../i18n/i18n_util';
import {I18nRemoveOpCodes, TIcu} from '../interfaces/i18n'; import {I18nRemoveOpCodes, TIcu} from '../interfaces/i18n';
import {TIcuContainerNode} from '../interfaces/node'; import {TIcuContainerNode} from '../interfaces/node';

View File

@ -15,9 +15,10 @@ import {Query} from '../../metadata/di';
import {Component, Directive, Input} from '../../metadata/directives'; import {Component, Directive, Input} from '../../metadata/directives';
import {componentNeedsResolution, maybeQueueResolutionOfComponentResources} from '../../metadata/resource_loading'; import {componentNeedsResolution, maybeQueueResolutionOfComponentResources} from '../../metadata/resource_loading';
import {ViewEncapsulation} from '../../metadata/view'; import {ViewEncapsulation} from '../../metadata/view';
import {EMPTY_ARRAY} from '../../util/empty';
import {initNgDevMode} from '../../util/ng_dev_mode'; import {initNgDevMode} from '../../util/ng_dev_mode';
import {getComponentDef, getDirectiveDef} from '../definition'; import {getComponentDef, getDirectiveDef} from '../definition';
import {EMPTY_ARRAY, EMPTY_OBJ} from '../empty'; import {EMPTY_OBJ} from '../empty';
import {NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF} from '../fields'; import {NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF} from '../fields';
import {ComponentType} from '../interfaces/definition'; import {ComponentType} from '../interfaces/definition';
import {stringifyForError} from '../util/stringify_utils'; import {stringifyForError} from '../util/stringify_utils';

View File

@ -16,6 +16,7 @@ import {ModuleWithProviders, NgModule} from '../../metadata/ng_module';
import {NgModuleDef, NgModuleTransitiveScopes, NgModuleType} from '../../metadata/ng_module_def'; import {NgModuleDef, NgModuleTransitiveScopes, NgModuleType} from '../../metadata/ng_module_def';
import {deepForEach, flatten} from '../../util/array_utils'; import {deepForEach, flatten} from '../../util/array_utils';
import {assertDefined} from '../../util/assert'; import {assertDefined} from '../../util/assert';
import {EMPTY_ARRAY} from '../../util/empty';
import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition'; import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition';
import {NG_COMP_DEF, NG_DIR_DEF, NG_MOD_DEF, NG_PIPE_DEF} from '../fields'; import {NG_COMP_DEF, NG_DIR_DEF, NG_MOD_DEF, NG_PIPE_DEF} from '../fields';
import {ComponentDef} from '../interfaces/definition'; import {ComponentDef} from '../interfaces/definition';
@ -24,8 +25,6 @@ import {stringifyForError} from '../util/stringify_utils';
import {angularCoreEnv} from './environment'; import {angularCoreEnv} from './environment';
const EMPTY_ARRAY: Type<any>[] = [];
interface ModuleQueueItem { interface ModuleQueueItem {
moduleType: Type<any>; moduleType: Type<any>;
ngModule: NgModule; ngModule: NgModule;

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
export {EMPTY_ARRAY} from '../util/empty';
export {anchorDef, elementDef} from './element'; export {anchorDef, elementDef} from './element';
export {clearOverrides, createNgModuleFactory, overrideComponentView, overrideProvider} from './entrypoint'; export {clearOverrides, createNgModuleFactory, overrideComponentView, overrideProvider} from './entrypoint';
export {ngContentDef} from './ng_content'; export {ngContentDef} from './ng_content';
@ -16,7 +17,7 @@ export {queryDef} from './query';
export {createComponentFactory, getComponentViewDefinitionFactory, nodeValue, ViewRef_} from './refs'; export {createComponentFactory, getComponentViewDefinitionFactory, nodeValue, ViewRef_} from './refs';
export {initServicesIfNeeded} from './services'; export {initServicesIfNeeded} from './services';
export {textDef} from './text'; export {textDef} from './text';
export {createRendererType2, elementEventFullName, EMPTY_ARRAY, EMPTY_MAP, inlineInterpolate, interpolate, rootRenderNodes, tokenKey, unwrapValue} from './util'; export {createRendererType2, elementEventFullName, EMPTY_MAP, inlineInterpolate, interpolate, rootRenderNodes, tokenKey, unwrapValue} from './util';
export {viewDef} from './view'; export {viewDef} from './view';
export {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView} from './view_attach'; export {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView} from './view_attach';

View File

@ -444,5 +444,4 @@ function _toStringWithNull(v: any): string {
return v != null ? v.toString() : ''; return v != null ? v.toString() : '';
} }
export const EMPTY_ARRAY: any[] = [];
export const EMPTY_MAP: {[key: string]: any} = {}; export const EMPTY_MAP: {[key: string]: any} = {};

View File

@ -173,12 +173,6 @@
{ {
"name": "EMPTY_ARRAY" "name": "EMPTY_ARRAY"
}, },
{
"name": "EMPTY_ARRAY"
},
{
"name": "EMPTY_ARRAY"
},
{ {
"name": "EMPTY_OBJ" "name": "EMPTY_OBJ"
}, },

View File

@ -236,9 +236,6 @@
{ {
"name": "EMPTY_ARRAY" "name": "EMPTY_ARRAY"
}, },
{
"name": "EMPTY_ARRAY"
},
{ {
"name": "EMPTY_OBJ" "name": "EMPTY_OBJ"
}, },

View File

@ -14,9 +14,6 @@
{ {
"name": "EMPTY_ARRAY" "name": "EMPTY_ARRAY"
}, },
{
"name": "EMPTY_ARRAY"
},
{ {
"name": "EMPTY_OBJ" "name": "EMPTY_OBJ"
}, },