Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit d7ef237

Browse files
committed
fix(core): remove unreadable short names
1 parent 3e445e4 commit d7ef237

28 files changed

+300
-433
lines changed

lib/browser/browser.ts

+28-35
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,49 @@
1212

1313
import {findEventTasks} from '../common/events';
1414
import {patchTimer} from '../common/timers';
15-
import {bindArguments, i, j, o, patchClass, patchMacroTask, patchMethod, patchOnProperties, patchPrototype, r, zoneSymbol} from '../common/utils';
15+
import {bindArguments, patchClass, patchMacroTask, patchMethod, patchOnProperties, patchPrototype, ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, zoneSymbol} from '../common/utils';
1616

1717
import {propertyPatch} from './define-property';
1818
import {eventTargetPatch, patchEvent} from './event-target';
1919
import {propertyDescriptorPatch} from './property-descriptor';
2020
import {registerElementPatch} from './register-element';
2121

22-
(Zone as any).l('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
22+
Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
2323
api.patchOnProperties = patchOnProperties;
2424
api.patchMethod = patchMethod;
2525
api.bindArguments = bindArguments;
2626
});
2727

28-
(Zone as any).l('timers', (global: any) => {
28+
Zone.__load_patch('timers', (global: any) => {
2929
const set = 'set';
3030
const clear = 'clear';
3131
patchTimer(global, set, clear, 'Timeout');
3232
patchTimer(global, set, clear, 'Interval');
3333
patchTimer(global, set, clear, 'Immediate');
3434
});
3535

36-
(Zone as any).l('requestAnimationFrame', (global: any) => {
36+
Zone.__load_patch('requestAnimationFrame', (global: any) => {
3737
patchTimer(global, 'request', 'cancel', 'AnimationFrame');
3838
patchTimer(global, 'mozRequest', 'mozCancel', 'AnimationFrame');
3939
patchTimer(global, 'webkitRequest', 'webkitCancel', 'AnimationFrame');
4040
});
4141

42-
(Zone as any).l('blocking', (global: any, Zone: ZoneType) => {
42+
Zone.__load_patch('blocking', (global: any, Zone: ZoneType) => {
4343
const blockingMethods = ['alert', 'prompt', 'confirm'];
4444
for (let i = 0; i < blockingMethods.length; i++) {
4545
const name = blockingMethods[i];
4646
patchMethod(global, name, (delegate, symbol, name) => {
4747
return function(s: any, args: any[]) {
48-
// Zone.current.run
49-
return (Zone as any).c.r(delegate, global, args, name);
48+
return Zone.current.run(delegate, global, args, name);
5049
};
5150
});
5251
}
5352
});
5453

55-
(Zone as any).l('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
54+
Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
5655
// load blackListEvents from global
5756
// Zone.__symbol__
58-
const SYMBOL_BLACK_LISTED_EVENTS = (Zone as any).s('BLACK_LISTED_EVENTS');
57+
const SYMBOL_BLACK_LISTED_EVENTS = Zone.__symbol__('BLACK_LISTED_EVENTS');
5958
if (global[SYMBOL_BLACK_LISTED_EVENTS]) {
6059
(Zone as any)[SYMBOL_BLACK_LISTED_EVENTS] = global[SYMBOL_BLACK_LISTED_EVENTS];
6160
}
@@ -73,25 +72,24 @@ import {registerElementPatch} from './register-element';
7372
patchClass('FileReader');
7473
});
7574

76-
(Zone as any).l('on_property', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
75+
Zone.__load_patch('on_property', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
7776
propertyDescriptorPatch(api, global);
7877
propertyPatch();
7978
registerElementPatch(global);
8079
});
8180

82-
(Zone as any).l('canvas', (global: any) => {
81+
Zone.__load_patch('canvas', (global: any) => {
8382
const HTMLCanvasElement = global['HTMLCanvasElement'];
84-
// o is 'undefined'
85-
if (typeof HTMLCanvasElement !== o && HTMLCanvasElement.prototype &&
83+
if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype &&
8684
HTMLCanvasElement.prototype.toBlob) {
8785
patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', (self: any, args: any[]) => {
8886
return {name: 'HTMLCanvasElement.toBlob', target: self, cbIdx: 0, args: args};
8987
});
9088
}
9189
});
9290

93-
(Zone as any).l('XHR', (global: any, Zone: ZoneType) => {
94-
// Treat XMLHTTPRequest as a macrotask.
91+
Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
92+
// Treat XMLHttpRequest as a macrotask.
9593
patchXHR(global);
9694

9795
const XHR_TASK = zoneSymbol('xhrTask');
@@ -111,18 +109,17 @@ import {registerElementPatch} from './register-element';
111109
const XMLHttpRequestPrototype: any = XMLHttpRequest.prototype;
112110

113111
function findPendingTask(target: any) {
114-
const pendingTask: Task = target[XHR_TASK];
115-
return pendingTask;
112+
return target[XHR_TASK];
116113
}
117114

118-
let oriAddListener = XMLHttpRequestPrototype[i];
119-
let oriRemoveListener = XMLHttpRequestPrototype[j];
115+
let oriAddListener = XMLHttpRequestPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER];
116+
let oriRemoveListener = XMLHttpRequestPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
120117
if (!oriAddListener) {
121118
const XMLHttpRequestEventTarget = window['XMLHttpRequestEventTarget'];
122119
if (XMLHttpRequestEventTarget) {
123120
const XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget.prototype;
124-
oriAddListener = XMLHttpRequestEventTargetPrototype[i];
125-
oriRemoveListener = XMLHttpRequestEventTargetPrototype[j];
121+
oriAddListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER];
122+
oriRemoveListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
126123
}
127124
}
128125

@@ -136,14 +133,12 @@ import {registerElementPatch} from './register-element';
136133
// remove existing event listener
137134
const listener = target[XHR_LISTENER];
138135
if (!oriAddListener) {
139-
// i is addEventListener zoneSymbol
140-
// j is removeEventListener zoneSymbol
141-
oriAddListener = target[i];
142-
oriRemoveListener = target[j];
136+
oriAddListener = target[ZONE_SYMBOL_ADD_EVENT_LISTENER];
137+
oriRemoveListener = target[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
143138
}
144139

145140
if (listener) {
146-
oriRemoveListener.apply(target, [READY_STATE_CHANGE, listener]);
141+
oriRemoveListener.call(target, READY_STATE_CHANGE, listener);
147142
}
148143
const newListener = target[XHR_LISTENER] = () => {
149144
if (target.readyState === target.DONE) {
@@ -154,7 +149,7 @@ import {registerElementPatch} from './register-element';
154149
}
155150
}
156151
};
157-
oriAddListener.apply(target, [READY_STATE_CHANGE, newListener]);
152+
oriAddListener.call(target, READY_STATE_CHANGE, newListener);
158153

159154
const storedTask: Task = target[XHR_TASK];
160155
if (!storedTask) {
@@ -186,7 +181,7 @@ import {registerElementPatch} from './register-element';
186181
const sendNative: Function =
187182
patchMethod(XMLHttpRequestPrototype, 'send', () => function(self: any, args: any[]) {
188183
// Zone.current
189-
const zone = (Zone as any).c;
184+
const zone = Zone.current;
190185
if (self[XHR_SYNC]) {
191186
// if the XHR is sync there is no task to schedule, just execute the code.
192187
return sendNative.apply(self, args);
@@ -199,16 +194,14 @@ import {registerElementPatch} from './register-element';
199194
args: args,
200195
aborted: false
201196
};
202-
// Zone.scheduleMacroTask
203-
return zone.sc(
197+
return zone.scheduleMacroTask(
204198
XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask);
205199
}
206200
});
207201

208202
const abortNative = patchMethod(XMLHttpRequestPrototype, 'abort', () => function(self: any) {
209203
const task: Task = findPendingTask(self);
210-
// r is 'string'
211-
if (task && typeof task.type == r) {
204+
if (task && typeof task.type == 'string') {
212205
// If the XHR has already completed, do nothing.
213206
// If the XHR has already been aborted, do nothing.
214207
// Fix #569, call abort multiple times before done will cause
@@ -217,7 +210,7 @@ import {registerElementPatch} from './register-element';
217210
return;
218211
}
219212
// Zone.cancelTask
220-
(task.zone as any).ct(task);
213+
task.zone.cancelTask(task);
221214
}
222215
// Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no
223216
// task
@@ -226,14 +219,14 @@ import {registerElementPatch} from './register-element';
226219
}
227220
});
228221

229-
(Zone as any).l('geolocation', (global: any) => {
222+
Zone.__load_patch('geolocation', (global: any) => {
230223
/// GEO_LOCATION
231224
if (global['navigator'] && global['navigator'].geolocation) {
232225
patchPrototype(global['navigator'].geolocation, ['getCurrentPosition', 'watchPosition']);
233226
}
234227
});
235228

236-
(Zone as any).l('PromiseRejectionEvent', (global: any, Zone: ZoneType) => {
229+
Zone.__load_patch('PromiseRejectionEvent', (global: any, Zone: ZoneType) => {
237230
// handle unhandled promise rejection
238231
function findPromiseRejectionHandler(evtName: string) {
239232
return function(e: any) {

lib/browser/define-property.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {o, p, zoneSymbol} from '../common/utils';
9+
import {zoneSymbol} from '../common/utils';
1010
/*
1111
* This is necessary for Chrome and Chrome mobile, to enable
1212
* things like redefining `createdCallback` on an element.
@@ -38,8 +38,7 @@ export function propertyPatch() {
3838
};
3939

4040
Object.create = <any>function(obj: any, proto: any) {
41-
// o is 'object' string
42-
if (typeof proto === p && !Object.isFrozen(proto)) {
41+
if (typeof proto === 'object' && !Object.isFrozen(proto)) {
4342
Object.keys(proto).forEach(function(prop) {
4443
proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
4544
});
@@ -90,8 +89,7 @@ function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigura
9089
if (desc.configurable) {
9190
// In case of errors, when the configurable flag was likely set by rewriteDescriptor(), let's
9291
// retry with the original flag value
93-
// o is 'undefined' string
94-
if (typeof originalConfigurableFlag == o) {
92+
if (typeof originalConfigurableFlag == 'undefined') {
9593
delete desc.configurable;
9694
} else {
9795
desc.configurable = originalConfigurableFlag;

lib/browser/event-target.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ens, gs, patchEventPrototype, patchEventTarget} from '../common/events';
10-
import {isIEOrEdge, k, l, m} from '../common/utils';
9+
import {globalSources, patchEventPrototype, patchEventTarget, zoneSymbolEventNames} from '../common/events';
10+
import {FALSE_STR, isIEOrEdge, TRUE_STR, ZONE_SYMBOL_PREFIX} from '../common/utils';
1111

1212
import {eventNames} from './property-descriptor';
1313

@@ -45,27 +45,19 @@ export function eventTargetPatch(_global: any, api: _ZonePrivate) {
4545
// predefine all __zone_symbol__ + eventName + true/false string
4646
for (let i = 0; i < eventNames.length; i++) {
4747
const eventName = eventNames[i];
48-
// l is 'false' string
49-
const falseEventName = eventName + l;
50-
// k is 'true' string
51-
const trueEventName = eventName + k;
52-
// m is '__zone_symbol__' string
53-
const symbol = m + falseEventName;
54-
// m is '__zone_symbol__' string
55-
const symbolCapture = m + trueEventName;
56-
// ens is globalEventNames cache
57-
ens[eventName] = {};
58-
// l is 'false' string
59-
ens[eventName][l] = symbol;
60-
// k is 'true' string
61-
ens[eventName][k] = symbolCapture;
48+
const falseEventName = eventName + FALSE_STR;
49+
const trueEventName = eventName + TRUE_STR;
50+
const symbol = ZONE_SYMBOL_PREFIX + falseEventName;
51+
const symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
52+
zoneSymbolEventNames[eventName] = {};
53+
zoneSymbolEventNames[eventName][FALSE_STR] = symbol;
54+
zoneSymbolEventNames[eventName][TRUE_STR] = symbolCapture;
6255
}
6356

6457
// predefine all task.source string
6558
for (let i = 0; i < WTF_ISSUE_555.length; i++) {
6659
const target: any = WTF_ISSUE_555_ARRAY[i];
67-
// gs is global source cache
68-
const targets: any = gs[target] = {};
60+
const targets: any = globalSources[target] = {};
6961
for (let j = 0; j < eventNames.length; j++) {
7062
const eventName = eventNames[j];
7163
targets[eventName] = target + ADD_EVENT_LISTENER_SOURCE + eventName;

lib/browser/property-descriptor.ts

+20-21
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @suppress {globalThis}
1111
*/
1212

13-
import {a, b, d, isBrowser, isMix, isNode, o, patchClass, patchOnProperties, zoneSymbol} from '../common/utils';
13+
import {isBrowser, isMix, isNode, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, ObjectGetPrototypeOf, patchClass, patchOnProperties, zoneSymbol} from '../common/utils';
1414

1515
import * as webSocketPatch from './websocket';
1616

@@ -265,20 +265,22 @@ export function propertyDescriptorPatch(api: _ZonePrivate, _global: any) {
265265
return;
266266
}
267267

268-
// o is 'undefined' string
269-
const supportsWebSocket = typeof WebSocket !== o;
268+
const supportsWebSocket = typeof WebSocket !== 'undefined';
270269
if (canPatchViaPropertyDescriptor()) {
271270
const ignoreProperties: IgnoreProperty[] = _global.__Zone_ignore_on_properties;
272271
// for browsers that we can patch the descriptor: Chrome & Firefox
273272
if (isBrowser) {
274-
const w: any = window;
273+
const internalWindow: any = window;
275274
// in IE/Edge, onProp not exist in window object, but in WindowPrototype
276275
// so we need to pass WindowPrototype to check onProp exist or not
277-
patchFilteredProperties(w, eventNames.concat(['messageerror']), ignoreProperties, d(w));
276+
patchFilteredProperties(
277+
internalWindow, eventNames.concat(['messageerror']), ignoreProperties,
278+
ObjectGetPrototypeOf(internalWindow));
278279
patchFilteredProperties(Document.prototype, eventNames, ignoreProperties);
279280

280-
if (typeof w['SVGElement'] !== o) {
281-
patchFilteredProperties(w['SVGElement'].prototype, eventNames, ignoreProperties);
281+
if (typeof internalWindow['SVGElement'] !== 'undefined') {
282+
patchFilteredProperties(
283+
internalWindow['SVGElement'].prototype, eventNames, ignoreProperties);
282284
}
283285
patchFilteredProperties(Element.prototype, eventNames, ignoreProperties);
284286
patchFilteredProperties(HTMLElement.prototype, eventNames, ignoreProperties);
@@ -291,11 +293,11 @@ export function propertyDescriptorPatch(api: _ZonePrivate, _global: any) {
291293
patchFilteredProperties(HTMLFrameElement.prototype, frameEventNames, ignoreProperties);
292294
patchFilteredProperties(HTMLIFrameElement.prototype, frameEventNames, ignoreProperties);
293295

294-
const HTMLMarqueeElement = w['HTMLMarqueeElement'];
296+
const HTMLMarqueeElement = internalWindow['HTMLMarqueeElement'];
295297
if (HTMLMarqueeElement) {
296298
patchFilteredProperties(HTMLMarqueeElement.prototype, marqueeEventNames, ignoreProperties);
297299
}
298-
const Worker = w['Worker'];
300+
const Worker = internalWindow['Worker'];
299301
if (Worker) {
300302
patchFilteredProperties(Worker.prototype, workerEventNames, ignoreProperties);
301303
}
@@ -307,8 +309,7 @@ export function propertyDescriptorPatch(api: _ZonePrivate, _global: any) {
307309
XMLHttpRequestEventTarget && XMLHttpRequestEventTarget.prototype,
308310
XMLHttpRequestEventNames, ignoreProperties);
309311
}
310-
// o is 'undefined' string
311-
if (typeof IDBIndex !== o) {
312+
if (typeof IDBIndex !== 'undefined') {
312313
patchFilteredProperties(IDBIndex.prototype, IDBIndexEventNames, ignoreProperties);
313314
patchFilteredProperties(IDBRequest.prototype, IDBIndexEventNames, ignoreProperties);
314315
patchFilteredProperties(IDBOpenDBRequest.prototype, IDBIndexEventNames, ignoreProperties);
@@ -330,18 +331,18 @@ export function propertyDescriptorPatch(api: _ZonePrivate, _global: any) {
330331
}
331332

332333
function canPatchViaPropertyDescriptor() {
333-
if ((isBrowser || isMix) && !a(HTMLElement.prototype, 'onclick') && typeof Element !== o) {
334+
if ((isBrowser || isMix) && !ObjectGetOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') &&
335+
typeof Element !== 'undefined') {
334336
// WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
335337
// IDL interface attributes are not configurable
336-
const desc = a(Element.prototype, 'onclick');
338+
const desc = ObjectGetOwnPropertyDescriptor(Element.prototype, 'onclick');
337339
if (desc && !desc.configurable) return false;
338340
}
339341

340342
const ON_READY_STATE_CHANGE = 'onreadystatechange';
341343
const XMLHttpRequestPrototype = XMLHttpRequest.prototype;
342344

343-
// a is Object.getOwnPropertyDescriptor
344-
const xhrDesc = a(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE);
345+
const xhrDesc = ObjectGetOwnPropertyDescriptor(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE);
345346

346347
// add enumerable and configurable here because in opera
347348
// by default XMLHttpRequest.prototype.onreadystatechange is undefined
@@ -350,8 +351,7 @@ function canPatchViaPropertyDescriptor() {
350351
// and if XMLHttpRequest.prototype.onreadystatechange is undefined,
351352
// we should set a real desc instead a fake one
352353
if (xhrDesc) {
353-
// b is Object.defineProperty
354-
b(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
354+
ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
355355
enumerable: true,
356356
configurable: true,
357357
get: function() {
@@ -361,11 +361,11 @@ function canPatchViaPropertyDescriptor() {
361361
const req = new XMLHttpRequest();
362362
const result = !!req.onreadystatechange;
363363
// restore original desc
364-
b(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, xhrDesc || {});
364+
ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, xhrDesc || {});
365365
return result;
366366
} else {
367367
const SYMBOL_FAKE_ONREADYSTATECHANGE = zoneSymbol('fake');
368-
b(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
368+
ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
369369
enumerable: true,
370370
configurable: true,
371371
get: function() {
@@ -402,8 +402,7 @@ function patchViaCapturingAllTheEvents() {
402402
}
403403
while (elt) {
404404
if (elt[onproperty] && !elt[onproperty][unboundKey]) {
405-
// Zone.current.wrap
406-
bound = (Zone as any).c.w(elt[onproperty], source);
405+
bound = Zone.current.wrap(elt[onproperty], source);
407406
bound[unboundKey] = elt[onproperty];
408407
elt[onproperty] = bound;
409408
}

0 commit comments

Comments
 (0)