Skip to content

Commit

Permalink
refactor: remove toplevel property accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and alxhub committed May 14, 2019
1 parent ed74f92 commit e55db3c
Show file tree
Hide file tree
Showing 32 changed files with 231 additions and 253 deletions.
2 changes: 1 addition & 1 deletion integration/_payload-limits.json
Expand Up @@ -3,7 +3,7 @@
"master": {
"uncompressed": {
"runtime": 1497,
"main": 164945,
"main": 166739,
"polyfills": 43626
}
}
Expand Down
11 changes: 0 additions & 11 deletions integration/side-effects/snapshots/animations-browser/esm2015.js
@@ -1,14 +1,3 @@
import "@angular/animations";

import "@angular/core";

function isNode() {
return "undefined" !== typeof process;
}

const _isNode = isNode();

if (_isNode || "undefined" !== typeof Element) if (_isNode || Element.prototype.matches) ; else {
const proto = Element.prototype;
const fn = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector;
}
11 changes: 0 additions & 11 deletions integration/side-effects/snapshots/animations-browser/esm5.js
Expand Up @@ -3,14 +3,3 @@ import "tslib";
import "@angular/animations";

import "@angular/core";

function isNode() {
return "undefined" !== typeof process;
}

var _isNode = isNode();

if (_isNode || "undefined" !== typeof Element) if (_isNode || Element.prototype.matches) ; else {
var proto = Element.prototype;
var fn_1 = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector;
}
4 changes: 0 additions & 4 deletions integration/side-effects/snapshots/elements/esm2015.js
Expand Up @@ -3,7 +3,3 @@ import "@angular/core";
import "rxjs";

import "rxjs/operators";

const elProto = Element.prototype;

const matches = elProto.matches || elProto.matchesSelector || elProto.mozMatchesSelector || elProto.msMatchesSelector || elProto.oMatchesSelector || elProto.webkitMatchesSelector;
4 changes: 0 additions & 4 deletions integration/side-effects/snapshots/elements/esm5.js
Expand Up @@ -5,7 +5,3 @@ import "@angular/core";
import "rxjs";

import "rxjs/operators";

var elProto = Element.prototype;

var matches = elProto.matches || elProto.matchesSelector || elProto.mozMatchesSelector || elProto.msMatchesSelector || elProto.oMatchesSelector || elProto.webkitMatchesSelector;
16 changes: 1 addition & 15 deletions integration/side-effects/snapshots/platform-browser/esm2015.js
@@ -1,17 +1,3 @@
import "@angular/common";

import { ɵglobal } from "@angular/core";

let nodeContains;

if (ɵglobal["Node"]) nodeContains = ɵglobal["Node"].prototype.contains || function(node) {
return !!(16 & this.compareDocumentPosition(node));
};

const ɵ0 = function(v) {
return "__zone_symbol__" + v;
};

const __symbol__ = "undefined" !== typeof Zone && Zone["__symbol__"] || ɵ0;

const blackListedEvents = "undefined" !== typeof Zone && Zone[__symbol__("BLACK_LISTED_EVENTS")];
import "@angular/core";
16 changes: 1 addition & 15 deletions integration/side-effects/snapshots/platform-browser/esm5.js
Expand Up @@ -2,18 +2,4 @@ import "tslib";

import "@angular/common";

import { ɵglobal } from "@angular/core";

var nodeContains;

if (ɵglobal["Node"]) nodeContains = ɵglobal["Node"].prototype.contains || function(node) {
return !!(16 & this.compareDocumentPosition(node));
};

var ɵ0 = function(v) {
return "__zone_symbol__" + v;
};

var __symbol__ = "undefined" !== typeof Zone && Zone["__symbol__"] || ɵ0;

var blackListedEvents = "undefined" !== typeof Zone && Zone[__symbol__("BLACK_LISTED_EVENTS")];
import "@angular/core";
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -155,6 +155,7 @@
"sauce-connect": "https://saucelabs.com/downloads/sc-4.5.1-linux.tar.gz",
"semver": "5.4.1",
"tslint-eslint-rules": "4.1.1",
"tslint-no-toplevel-property-access": "0.0.2",
"tsutils": "2.27.2",
"universal-analytics": "0.4.15",
"vlq": "0.2.2",
Expand Down
Expand Up @@ -34,9 +34,10 @@ export class WebAnimationsStyleNormalizer extends AnimationStyleNormalizer {
}
}

const DIMENSIONAL_PROP_MAP = makeBooleanMap(
'width,height,minWidth,minHeight,maxWidth,maxHeight,left,top,bottom,right,fontSize,outlineWidth,outlineOffset,paddingTop,paddingLeft,paddingBottom,paddingRight,marginTop,marginLeft,marginBottom,marginRight,borderRadius,borderWidth,borderTopWidth,borderLeftWidth,borderRightWidth,borderBottomWidth,textIndent,perspective'
.split(','));
const DIMENSIONAL_PROP_MAP =
(() => makeBooleanMap(
'width,height,minWidth,minHeight,maxWidth,maxHeight,left,top,bottom,right,fontSize,outlineWidth,outlineOffset,paddingTop,paddingLeft,paddingBottom,paddingRight,marginTop,marginLeft,marginBottom,marginRight,borderRadius,borderWidth,borderTopWidth,borderLeftWidth,borderRightWidth,borderBottomWidth,textIndent,perspective'
.split(',')))();

function makeBooleanMap(keys: string[]): {[key: string]: boolean} {
const map: {[key: string]: boolean} = {};
Expand Down
22 changes: 13 additions & 9 deletions packages/animations/browser/src/render/shared.ts
Expand Up @@ -158,16 +158,20 @@ if (_isNode || typeof Element !== 'undefined') {
// this is well supported in all browsers
_contains = (elm1: any, elm2: any) => { return elm1.contains(elm2) as boolean; };

if (_isNode || Element.prototype.matches) {
_matches = (element: any, selector: string) => element.matches(selector);
} else {
const proto = Element.prototype as any;
const fn = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector ||
proto.oMatchesSelector || proto.webkitMatchesSelector;
if (fn) {
_matches = (element: any, selector: string) => fn.apply(element, [selector]);
_matches = (() => {
if (_isNode || Element.prototype.matches) {
return (element: any, selector: string) => element.matches(selector);
} else {
const proto = Element.prototype as any;
const fn = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector ||
proto.oMatchesSelector || proto.webkitMatchesSelector;
if (fn) {
return (element: any, selector: string) => fn.apply(element, [selector]);
} else {
return _matches;
}
}
}
})();

_query = (element: any, selector: string, multi: boolean): any[] => {
let results: any[] = [];
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/di/injector.ts
Expand Up @@ -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 {
Expand All @@ -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>();
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/render3/empty.ts
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion packages/core/src/render3/instructions/shared.ts
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/interfaces/injector.ts
Expand Up @@ -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
Expand Down

0 comments on commit e55db3c

Please sign in to comment.