refactor: remove toplevel property accesses (#29329)

PR Close #29329
This commit is contained in:
Filipe Silva
2019-05-02 16:44:24 +01:00
committed by Jason Aden
parent 739e5a4f53
commit ac34a1429b
32 changed files with 231 additions and 253 deletions

View File

@ -117,7 +117,6 @@ const enum OptionFlags {
CheckParent = 1 << 2,
Default = CheckSelf | CheckParent
}
const NULL_INJECTOR = Injector.NULL;
const NO_NEW_LINE = 'ɵ';
export class StaticInjector implements Injector {
@ -127,7 +126,7 @@ export class StaticInjector implements Injector {
private _records: Map<any, Record>;
constructor(
providers: StaticProvider[], parent: Injector = NULL_INJECTOR, source: string|null = null) {
providers: StaticProvider[], parent: Injector = Injector.NULL, source: string|null = null) {
this.parent = parent;
this.source = source;
const records = this._records = new Map<any, Record>();
@ -304,7 +303,7 @@ function resolveToken(
records,
// If we don't know how to resolve dependency and we should not check parent for it,
// than pass in Null injector.
!childRecord && !(options & OptionFlags.CheckParent) ? NULL_INJECTOR : parent,
!childRecord && !(options & OptionFlags.CheckParent) ? Injector.NULL : parent,
options & OptionFlags.Optional ? null : Injector.THROW_IF_NOT_FOUND,
InjectFlags.Default));
}

View File

@ -19,6 +19,10 @@ export const EMPTY_ARRAY: any[] = [];
// freezing the values prevents any code from accidentally inserting new values in
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
// These property accesses can be ignored because ngDevMode will be set to false
// 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);
}

View File

@ -45,7 +45,7 @@ import {getComponentViewByIndex, getNativeByIndex, getNativeByTNode, getTNode, i
* A permanent marker promise which signifies that the current CD tree is
* clean.
*/
const _CLEAN_PROMISE = Promise.resolve(null);
const _CLEAN_PROMISE = (() => Promise.resolve(null))();
export const enum BindingDirection {
Input,

View File

@ -241,10 +241,10 @@ export class NodeInjectorFactory {
}
}
const FactoryPrototype = NodeInjectorFactory.prototype;
export function isFactory(obj: any): obj is NodeInjectorFactory {
// See: https://jsperf.com/instanceof-vs-getprototypeof
return obj !== null && typeof obj == 'object' && Object.getPrototypeOf(obj) == FactoryPrototype;
return obj !== null && typeof obj == 'object' &&
Object.getPrototypeOf(obj) == NodeInjectorFactory.prototype;
}
// Note: This hack is necessary so we don't erroneously get a circular dependency

View File

@ -17,125 +17,126 @@ import * as sanitization from '../../sanitization/sanitization';
*
* This should be kept up to date with the public exports of @angular/core.
*/
export const angularCoreEnv: {[name: string]: Function} = {
'ΔdefineBase': r3.ΔdefineBase,
'ΔdefineComponent': r3.ΔdefineComponent,
'ΔdefineDirective': r3.ΔdefineDirective,
'ΔdefineInjectable': ΔdefineInjectable,
'ΔdefineInjector': ΔdefineInjector,
'ΔdefineNgModule': r3.ΔdefineNgModule,
'ΔdefinePipe': r3.ΔdefinePipe,
'ΔdirectiveInject': r3.ΔdirectiveInject,
'ΔgetFactoryOf': r3.ΔgetFactoryOf,
'ΔgetInheritedFactory': r3.ΔgetInheritedFactory,
'Δinject': Δinject,
'ΔinjectAttribute': r3.ΔinjectAttribute,
'ΔtemplateRefExtractor': r3.ΔtemplateRefExtractor,
'ΔNgOnChangesFeature': r3.ΔNgOnChangesFeature,
'ΔProvidersFeature': r3.ΔProvidersFeature,
'ΔInheritDefinitionFeature': r3.ΔInheritDefinitionFeature,
'ΔelementAttribute': r3.ΔelementAttribute,
'Δbind': r3.Δbind,
'Δcontainer': r3.Δcontainer,
'ΔnextContext': r3.ΔnextContext,
'ΔcontainerRefreshStart': r3.ΔcontainerRefreshStart,
'ΔcontainerRefreshEnd': r3.ΔcontainerRefreshEnd,
'ΔnamespaceHTML': r3.ΔnamespaceHTML,
'ΔnamespaceMathML': r3.ΔnamespaceMathML,
'ΔnamespaceSVG': r3.ΔnamespaceSVG,
enableBindings': r3.ΔenableBindings,
disableBindings': r3.ΔdisableBindings,
'ΔallocHostVars': r3.ΔallocHostVars,
'ΔelementStart': r3.ΔelementStart,
'ΔelementEnd': r3.ΔelementEnd,
'Δelement': r3.Δelement,
'ΔelementContainerStart': r3.ΔelementContainerStart,
'ΔelementContainerEnd': r3.ΔelementContainerEnd,
'ΔpureFunction0': r3.ΔpureFunction0,
'ΔpureFunction1': r3.ΔpureFunction1,
'ΔpureFunction2': r3.ΔpureFunction2,
'ΔpureFunction3': r3.ΔpureFunction3,
'ΔpureFunction4': r3.ΔpureFunction4,
'ΔpureFunction5': r3.ΔpureFunction5,
'ΔpureFunction6': r3.ΔpureFunction6,
'ΔpureFunction7': r3.ΔpureFunction7,
'ΔpureFunction8': r3.ΔpureFunction8,
'ΔpureFunctionV': r3.ΔpureFunctionV,
'ΔgetCurrentView': r3.ΔgetCurrentView,
'ΔrestoreView': r3.ΔrestoreView,
'Δinterpolation1': r3.Δinterpolation1,
'Δinterpolation2': r3.Δinterpolation2,
'Δinterpolation3': r3.Δinterpolation3,
'Δinterpolation4': r3.Δinterpolation4,
'Δinterpolation5': r3.Δinterpolation5,
'Δinterpolation6': r3.Δinterpolation6,
'Δinterpolation7': r3.Δinterpolation7,
'Δinterpolation8': r3.Δinterpolation8,
'ΔinterpolationV': r3.ΔinterpolationV,
'Δlistener': r3.Δlistener,
'Δload': r3.Δload,
'Δprojection': r3.Δprojection,
'ΔelementProperty': r3.ΔelementProperty,
'ΔcomponentHostSyntheticProperty': r3.ΔcomponentHostSyntheticProperty,
'ΔcomponentHostSyntheticListener': r3.ΔcomponentHostSyntheticListener,
'ΔpipeBind1': r3.ΔpipeBind1,
'ΔpipeBind2': r3.ΔpipeBind2,
'ΔpipeBind3': r3.ΔpipeBind3,
'ΔpipeBind4': r3.ΔpipeBind4,
'ΔpipeBindV': r3.ΔpipeBindV,
'ΔprojectionDef': r3.ΔprojectionDef,
'Δproperty': r3.Δproperty,
'ΔpropertyInterpolate': r3.ΔpropertyInterpolate,
'ΔpropertyInterpolate1': r3.ΔpropertyInterpolate1,
'ΔpropertyInterpolate2': r3.ΔpropertyInterpolate2,
'ΔpropertyInterpolate3': r3.ΔpropertyInterpolate3,
'ΔpropertyInterpolate4': r3.ΔpropertyInterpolate4,
'ΔpropertyInterpolate5': r3.ΔpropertyInterpolate5,
'ΔpropertyInterpolate6': r3.ΔpropertyInterpolate6,
'ΔpropertyInterpolate7': r3.ΔpropertyInterpolate7,
'ΔpropertyInterpolate8': r3.ΔpropertyInterpolate8,
'ΔpropertyInterpolateV': r3.ΔpropertyInterpolateV,
'Δpipe': r3.Δpipe,
'ΔqueryRefresh': r3.ΔqueryRefresh,
'ΔviewQuery': r3.ΔviewQuery,
'ΔstaticViewQuery': r3.ΔstaticViewQuery,
'ΔstaticContentQuery': r3.ΔstaticContentQuery,
'ΔloadViewQuery': r3.ΔloadViewQuery,
'ΔcontentQuery': r3.ΔcontentQuery,
'ΔloadContentQuery': r3.ΔloadContentQuery,
'Δreference': r3.Δreference,
'ΔelementHostAttrs': r3.ΔelementHostAttrs,
'ΔclassMap': r3.ΔclassMap,
'Δstyling': r3.Δstyling,
'ΔstyleMap': r3.ΔstyleMap,
'ΔstyleProp': r3.ΔstyleProp,
'ΔstylingApply': r3.ΔstylingApply,
'ΔclassProp': r3.ΔclassProp,
'Δselect': r3.Δselect,
'Δtemplate': r3.Δtemplate,
'Δtext': r3.Δtext,
'ΔtextBinding': r3.ΔtextBinding,
'ΔembeddedViewStart': r3.ΔembeddedViewStart,
'ΔembeddedViewEnd': r3.ΔembeddedViewEnd,
'Δi18n': r3.Δi18n,
'Δi18nAttributes': r3.Δi18nAttributes,
'Δi18nExp': r3.Δi18nExp,
'Δi18nStart': r3.Δi18nStart,
'Δi18nEnd': r3.Δi18nEnd,
'Δi18nApply': r3.Δi18nApply,
'Δi18nPostprocess': r3.Δi18nPostprocess,
'Δi18nLocalize': r3.Δi18nLocalize,
'ΔresolveWindow': r3.ΔresolveWindow,
'ΔresolveDocument': r3.ΔresolveDocument,
'ΔresolveBody': r3.ΔresolveBody,
'ΔsetComponentScope': r3.ΔsetComponentScope,
'ΔsetNgModuleScope': r3.ΔsetNgModuleScope,
export const angularCoreEnv: {[name: string]: Function} =
(() => ({
'ΔdefineBase': r3.ΔdefineBase,
'ΔdefineComponent': r3.ΔdefineComponent,
'ΔdefineDirective': r3.ΔdefineDirective,
'ΔdefineInjectable': ΔdefineInjectable,
'ΔdefineInjector': ΔdefineInjector,
'ΔdefineNgModule': r3.ΔdefineNgModule,
'ΔdefinePipe': r3.ΔdefinePipe,
'ΔdirectiveInject': r3.ΔdirectiveInject,
'ΔgetFactoryOf': r3.ΔgetFactoryOf,
'ΔgetInheritedFactory': r3.ΔgetInheritedFactory,
'Δinject': Δinject,
'ΔinjectAttribute': r3.ΔinjectAttribute,
'ΔtemplateRefExtractor': r3.ΔtemplateRefExtractor,
'ΔNgOnChangesFeature': r3.ΔNgOnChangesFeature,
'ΔProvidersFeature': r3.ΔProvidersFeature,
'ΔInheritDefinitionFeature': r3.ΔInheritDefinitionFeature,
'ΔelementAttribute': r3.ΔelementAttribute,
'Δbind': r3.Δbind,
'Δcontainer': r3.Δcontainer,
'ΔnextContext': r3.ΔnextContext,
'ΔcontainerRefreshStart': r3.ΔcontainerRefreshStart,
'ΔcontainerRefreshEnd': r3.ΔcontainerRefreshEnd,
'ΔnamespaceHTML': r3.ΔnamespaceHTML,
'ΔnamespaceMathML': r3.ΔnamespaceMathML,
'ΔnamespaceSVG': r3.ΔnamespaceSVG,
enableBindings': r3.ΔenableBindings,
'ΔdisableBindings': r3.ΔdisableBindings,
'ΔallocHostVars': r3.ΔallocHostVars,
'ΔelementStart': r3.ΔelementStart,
'ΔelementEnd': r3.ΔelementEnd,
'Δelement': r3.Δelement,
'ΔelementContainerStart': r3.ΔelementContainerStart,
'ΔelementContainerEnd': r3.ΔelementContainerEnd,
'ΔpureFunction0': r3.ΔpureFunction0,
'ΔpureFunction1': r3.ΔpureFunction1,
'ΔpureFunction2': r3.ΔpureFunction2,
'ΔpureFunction3': r3.ΔpureFunction3,
'ΔpureFunction4': r3.ΔpureFunction4,
'ΔpureFunction5': r3.ΔpureFunction5,
'ΔpureFunction6': r3.ΔpureFunction6,
'ΔpureFunction7': r3.ΔpureFunction7,
'ΔpureFunction8': r3.ΔpureFunction8,
'ΔpureFunctionV': r3.ΔpureFunctionV,
'ΔgetCurrentView': r3.ΔgetCurrentView,
'ΔrestoreView': r3.ΔrestoreView,
'Δinterpolation1': r3.Δinterpolation1,
'Δinterpolation2': r3.Δinterpolation2,
'Δinterpolation3': r3.Δinterpolation3,
'Δinterpolation4': r3.Δinterpolation4,
'Δinterpolation5': r3.Δinterpolation5,
'Δinterpolation6': r3.Δinterpolation6,
'Δinterpolation7': r3.Δinterpolation7,
'Δinterpolation8': r3.Δinterpolation8,
'ΔinterpolationV': r3.ΔinterpolationV,
'Δlistener': r3.Δlistener,
'Δload': r3.Δload,
'Δprojection': r3.Δprojection,
'ΔelementProperty': r3.ΔelementProperty,
'ΔcomponentHostSyntheticProperty': r3.ΔcomponentHostSyntheticProperty,
'ΔcomponentHostSyntheticListener': r3.ΔcomponentHostSyntheticListener,
'ΔpipeBind1': r3.ΔpipeBind1,
'ΔpipeBind2': r3.ΔpipeBind2,
'ΔpipeBind3': r3.ΔpipeBind3,
'ΔpipeBind4': r3.ΔpipeBind4,
'ΔpipeBindV': r3.ΔpipeBindV,
'ΔprojectionDef': r3.ΔprojectionDef,
'Δproperty': r3.Δproperty,
'ΔpropertyInterpolate': r3.ΔpropertyInterpolate,
'ΔpropertyInterpolate1': r3.ΔpropertyInterpolate1,
'ΔpropertyInterpolate2': r3.ΔpropertyInterpolate2,
'ΔpropertyInterpolate3': r3.ΔpropertyInterpolate3,
'ΔpropertyInterpolate4': r3.ΔpropertyInterpolate4,
'ΔpropertyInterpolate5': r3.ΔpropertyInterpolate5,
'ΔpropertyInterpolate6': r3.ΔpropertyInterpolate6,
'ΔpropertyInterpolate7': r3.ΔpropertyInterpolate7,
'ΔpropertyInterpolate8': r3.ΔpropertyInterpolate8,
'ΔpropertyInterpolateV': r3.ΔpropertyInterpolateV,
'Δpipe': r3.Δpipe,
'ΔqueryRefresh': r3.ΔqueryRefresh,
'ΔviewQuery': r3.ΔviewQuery,
'ΔstaticViewQuery': r3.ΔstaticViewQuery,
'ΔstaticContentQuery': r3.ΔstaticContentQuery,
'ΔloadViewQuery': r3.ΔloadViewQuery,
'ΔcontentQuery': r3.ΔcontentQuery,
'ΔloadContentQuery': r3.ΔloadContentQuery,
'Δreference': r3.Δreference,
'ΔelementHostAttrs': r3.ΔelementHostAttrs,
'ΔclassMap': r3.ΔclassMap,
'Δstyling': r3.Δstyling,
'ΔstyleMap': r3.ΔstyleMap,
'ΔstyleProp': r3.ΔstyleProp,
'ΔstylingApply': r3.ΔstylingApply,
'ΔclassProp': r3.ΔclassProp,
'Δselect': r3.Δselect,
'Δtemplate': r3.Δtemplate,
'Δtext': r3.Δtext,
'ΔtextBinding': r3.ΔtextBinding,
'ΔembeddedViewStart': r3.ΔembeddedViewStart,
'ΔembeddedViewEnd': r3.ΔembeddedViewEnd,
'Δi18n': r3.Δi18n,
'Δi18nAttributes': r3.Δi18nAttributes,
'Δi18nExp': r3.Δi18nExp,
'Δi18nStart': r3.Δi18nStart,
'Δi18nEnd': r3.Δi18nEnd,
'Δi18nApply': r3.Δi18nApply,
'Δi18nPostprocess': r3.Δi18nPostprocess,
'Δi18nLocalize': r3.Δi18nLocalize,
'ΔresolveWindow': r3.ΔresolveWindow,
'ΔresolveDocument': r3.ΔresolveDocument,
'ΔresolveBody': r3.ΔresolveBody,
'ΔsetComponentScope': r3.ΔsetComponentScope,
'ΔsetNgModuleScope': r3.ΔsetNgModuleScope,
'ΔsanitizeHtml': sanitization.ΔsanitizeHtml,
'ΔsanitizeStyle': sanitization.ΔsanitizeStyle,
'ΔdefaultStyleSanitizer': sanitization.ΔdefaultStyleSanitizer,
'ΔsanitizeResourceUrl': sanitization.ΔsanitizeResourceUrl,
'ΔsanitizeScript': sanitization.ΔsanitizeScript,
'ΔsanitizeUrl': sanitization.ΔsanitizeUrl,
'ΔsanitizeUrlOrResourceUrl': sanitization.ΔsanitizeUrlOrResourceUrl,
};
'ΔsanitizeHtml': sanitization.ΔsanitizeHtml,
'ΔsanitizeStyle': sanitization.ΔsanitizeStyle,
'ΔdefaultStyleSanitizer': sanitization.ΔdefaultStyleSanitizer,
'ΔsanitizeResourceUrl': sanitization.ΔsanitizeResourceUrl,
'ΔsanitizeScript': sanitization.ΔsanitizeScript,
'ΔsanitizeUrl': sanitization.ΔsanitizeUrl,
'ΔsanitizeUrlOrResourceUrl': sanitization.ΔsanitizeUrlOrResourceUrl,
}))();

View File

@ -48,9 +48,10 @@ export function stringifyForError(value: any) {
export const defaultScheduler =
(typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame || // browser only
setTimeout // everything else
).bind(global);
(() =>
(typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame || // browser only
setTimeout // everything else
).bind(global))();
/**
*

View File

@ -19,6 +19,10 @@ export const EMPTY_ARRAY: any[] = [];
// freezing the values prevents any code from accidentally inserting new values in
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
// These property accesses can be ignored because ngDevMode will be set to false
// 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);
}

View File

@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
const promise: Promise<any> = Promise.resolve(0);
const promise: Promise<any> = (() => Promise.resolve(0))();
declare const Zone: any;

View File

@ -16,8 +16,12 @@ declare global {
* NOTE: changes to the `ngI18nClosureMode` name must be synced with `compiler-cli/src/tooling.ts`.
*/
if (typeof ngI18nClosureMode === 'undefined') {
// These property accesses can be ignored because ngI18nClosureMode will be set to false
// when optimizing code and the whole if statement will be dropped.
// Make sure to refer to ngI18nClosureMode as ['ngI18nClosureMode'] for closure.
// tslint:disable-next-line:no-toplevel-property-access
global['ngI18nClosureMode'] =
// TODO(FW-1250): validate that this actually, you know, works.
// tslint:disable-next-line:no-toplevel-property-access
typeof goog !== 'undefined' && typeof goog.getMsg === 'function';
}