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

Commit 00a4e31

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(core): fix shorter name closure conflict
1 parent 73b0061 commit 00a4e31

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

karma-dist.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = function (config) {
1212
config.files.push('build/test/test_fake_polyfill.js');
1313
config.files.push('build/test/custom_error.js');
1414
config.files.push('dist/zone.js');
15+
config.files.push('dist/zone-patch-user-media.js');
1516
config.files.push('dist/async-test.js');
1617
config.files.push('dist/fake-async-test.js');
1718
config.files.push('dist/long-stack-trace-zone.js');

lib/common/utils.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ export const p = 'object';
3131
export const q = 'number';
3232
export const r = 'string';
3333

34+
3435
// Hack since TypeScript isn't compiling this for a worker.
3536
declare const WorkerGlobalScope: any;
3637

3738
export const zoneSymbol = Zone.__symbol__;
38-
const _global: any = typeof window === p && window || typeof self === p && self || global;
39+
const iw = typeof window !== o;
40+
const w: any = iw ? window : undefined;
41+
const _global: any = iw && w || typeof self === p && self || global;
3942

4043
const REMOVE_ATTRIBUTE = 'removeAttribute';
4144
const NULL_ON_PROP_VALUE: any[] = [null];
@@ -95,15 +98,14 @@ export const isNode: boolean =
9598
(!('nw' in _global) && typeof _global.process !== o &&
9699
{}.toString.call(_global.process) === '[object process]');
97100

98-
export const isBrowser: boolean =
99-
!isNode && !isWebWorker && !!(typeof window !== o && (window as any)['HTMLElement']);
101+
export const isBrowser: boolean = !isNode && !isWebWorker && !!(iw && w['HTMLElement']);
100102

101103
// we are in electron of nw, so we are both browser and nodejs
102104
// Make sure to access `process` through `_global` so that WebPack does not accidently browserify
103105
// this code.
104106
export const isMix: boolean = typeof _global.process !== o &&
105107
{}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
106-
!!(typeof window !== o && (window as any)['HTMLElement']);
108+
!!(iw && w['HTMLElement']);
107109

108110
const zoneSymbolEventNames: {[eventName: string]: string} = {};
109111

@@ -430,7 +432,7 @@ export function isIEOrEdge() {
430432
isDetectedIEOrEdge = true;
431433

432434
try {
433-
const ua = window.navigator.userAgent;
435+
const ua = w.navigator.userAgent;
434436
if (ua.indexOf('MSIE ') !== -1 || ua.indexOf('Trident/') !== -1 || ua.indexOf('Edge/') !== -1) {
435437
ieOrEdge = true;
436438
}

test/browser/browser.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,6 @@ describe('Zone', function() {
25042504
const zone = Zone.current.fork({name: 'media'});
25052505
zone.run(() => {
25062506
const constraints = {audio: true, video: {width: 1280, height: 720}};
2507-
25082507
navigator.getUserMedia(
25092508
constraints,
25102509
() => {

test/closure/zone.closure.ts

Lines changed: 5 additions & 3 deletions
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
import '../../dist/zone-node';
9-
9+
const shortKeys = ['w', 'f', 'r', 'rg', 'rt', 'st', 'sc', 'si', 'se', 'ct'];
1010
const testClosureFunction = () => {
1111
const logs: string[] = [];
1212
// call all Zone exposed functions
@@ -69,7 +69,9 @@ const testClosureFunction = () => {
6969
logs.push('get' + keyZone.get('key'));
7070
logs.push('root' + Zone.root.name);
7171
Object.keys((Zone as any).prototype).forEach(key => {
72-
logs.push(key);
72+
if (shortKeys.indexOf(key) === -1) {
73+
logs.push(key);
74+
}
7375
});
7476
Object.keys(testZoneSpec).forEach(key => {
7577
logs.push(key);
@@ -139,4 +141,4 @@ process['on']('uncaughtException', (err: any) => {
139141
process['exit'](1);
140142
});
141143

142-
testClosureFunction();
144+
testClosureFunction();

0 commit comments

Comments
 (0)