Skip to content

Commit

Permalink
refactor: migrate zone.js to prettier formatting (#55427)
Browse files Browse the repository at this point in the history
Migrate formatting to prettier for zone.js from clang-format

PR Close #55427
  • Loading branch information
josephperrott authored and AndrewKushnir committed Apr 29, 2024
1 parent 31fdf0f commit f307e95
Show file tree
Hide file tree
Showing 199 changed files with 15,494 additions and 12,741 deletions.
2 changes: 2 additions & 0 deletions .ng-dev/format.mts
Expand Up @@ -33,6 +33,7 @@ export const format: FormatConfig = {
'packages/router/**/*.{js,ts}',
'packages/service-worker/**/*.{js,ts}',
'packages/upgrade/**/*.{js,ts}',
'packages/zone.js/**/*.{js,ts}',

// Do not format d.ts files as they are generated
'!**/*.d.ts',
Expand Down Expand Up @@ -97,6 +98,7 @@ export const format: FormatConfig = {
'!packages/router/**/*.{js,ts}',
'!packages/service-worker/**/*.{js,ts}',
'!packages/upgrade/**/*.{js,ts}',
'!packages/zone.js/**/*.{js,ts}',
],
},
'buildifier': true,
Expand Down
9 changes: 5 additions & 4 deletions packages/zone.js/check-file-size.js
Expand Up @@ -7,15 +7,16 @@
*/
const fs = require('fs');

module.exports = function(config) {
module.exports = function (config) {
let chkResult = true;
config.targets.forEach(target => {
config.targets.forEach((target) => {
if (target.checkTarget) {
try {
const stats = fs.statSync(target.path);
if (stats.size > target.limit) {
console.error(`file ${target.path} size over limit, limit is ${target.limit}, actual is ${
stats.size}`);
console.error(
`file ${target.path} size over limit, limit is ${target.limit}, actual is ${stats.size}`,
);
chkResult = false;
}
} catch (err) {
Expand Down
16 changes: 6 additions & 10 deletions packages/zone.js/example/benchmarks/event_emitter.js
Expand Up @@ -14,8 +14,8 @@ const callbacks = [];
const size = 100000;
for (let i = 0; i < size; i++) {
const emitter = new EventEmitter();
const callback = (function(i) {
return function() {
const callback = (function (i) {
return function () {
console.log(i);
};
})(i);
Expand All @@ -29,19 +29,15 @@ function addRemoveCallback(reuse, useZone) {
for (let i = 0; i < size; i++) {
const emitter = emitters[i];
if (!reuse) callback = callbacks[i];
if (useZone)
emitter.on('msg', callback);
else
emitter.__zone_symbol__addListener('msg', callback);
if (useZone) emitter.on('msg', callback);
else emitter.__zone_symbol__addListener('msg', callback);
}

for (let i = 0; i < size; i++) {
const emitter = emitters[i];
if (!reuse) callback = callbacks[i];
if (useZone)
emitter.removeListener('msg', callback);
else
emitter.__zone_symbol__removeListener('msg', callback);
if (useZone) emitter.removeListener('msg', callback);
else emitter.__zone_symbol__removeListener('msg', callback);
}
const end = new Date();
console.log(useZone ? 'use zone' : 'native', reuse ? 'reuse' : 'new');
Expand Down
10 changes: 5 additions & 5 deletions packages/zone.js/example/js/counting-zone.js
Expand Up @@ -5,31 +5,31 @@
Zone['countingZoneSpec'] = {
name: 'counterZone',
// setTimeout
onScheduleTask: function(delegate, current, target, task) {
onScheduleTask: function (delegate, current, target, task) {
this.data.count += 1;
delegate.scheduleTask(target, task);
},

// fires when...
// - clearTimeout
// - setTimeout finishes
onInvokeTask: function(delegate, current, target, task, applyThis, applyArgs) {
onInvokeTask: function (delegate, current, target, task, applyThis, applyArgs) {
delegate.invokeTask(target, task, applyThis, applyArgs);
this.data.count -= 1;
},

onHasTask: function(delegate, current, target, hasTask) {
onHasTask: function (delegate, current, target, hasTask) {
if (this.data.count === 0 && !this.data.flushed) {
this.data.flushed = true;
target.run(this.onFlush);
}
},

counter: function() {
counter: function () {
return this.data.count;
},

data: {count: 0, flushed: false},

onFlush: function() {}
onFlush: function () {},
};
14 changes: 8 additions & 6 deletions packages/zone.js/karma-base.conf.js
Expand Up @@ -6,12 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
config.set({
basePath: '',
client: {errorpolicy: config.errorpolicy},
files: [
'node_modules/systemjs/dist/system-polyfills.js', 'node_modules/systemjs/dist/system.src.js',
'node_modules/systemjs/dist/system-polyfills.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/whatwg-fetch/fetch.js',
{pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false},
Expand All @@ -21,12 +22,13 @@ module.exports = function(config) {
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false},
{pattern: 'test/assets/**/*.*', watched: true, served: true, included: false},
{pattern: 'build/**/*.js.map', watched: true, served: true, included: false},
{pattern: 'build/**/*.js', watched: true, served: true, included: false}
{pattern: 'build/**/*.js', watched: true, served: true, included: false},
],

plugins: [
require('karma-chrome-launcher'), require('karma-firefox-launcher'),
require('karma-sourcemap-loader')
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-sourcemap-loader'),
],

preprocessors: {'**/*.js': ['sourcemap']},
Expand All @@ -46,6 +48,6 @@ module.exports = function(config) {
retryLimit: 4,

autoWatch: true,
singleRun: false
singleRun: false,
});
};
3 changes: 1 addition & 2 deletions packages/zone.js/karma-build-jasmine.conf.js
@@ -1,5 +1,4 @@

module.exports = function(config) {
module.exports = function (config) {
require('./karma-build.conf.js')(config);

config.plugins.push(require('karma-jasmine'));
Expand Down
3 changes: 1 addition & 2 deletions packages/zone.js/karma-build-jasmine.es2015.conf.js
@@ -1,5 +1,4 @@

module.exports = function(config) {
module.exports = function (config) {
require('./karma-build-jasmine.conf.js')(config);
config.client.entrypoint = 'browser_es2015_entry_point';
};
7 changes: 3 additions & 4 deletions packages/zone.js/karma-build-mocha.conf.js
@@ -1,11 +1,10 @@

module.exports = function(config) {
module.exports = function (config) {
require('./karma-build.conf.js')(config);

config.plugins.push(require('karma-mocha'));
config.frameworks.push('mocha');
config.client.mocha = {
timeout: 5000 // copied timeout for Jasmine in WebSocket.spec (otherwise Mochas default timeout
// at 2 sec is to low for the tests)
timeout: 5000, // copied timeout for Jasmine in WebSocket.spec (otherwise Mochas default timeout
// at 2 sec is to low for the tests)
};
};
2 changes: 1 addition & 1 deletion packages/zone.js/karma-build-sauce-mocha.conf.js
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-dist-mocha.conf.js')(config);
require('./sauce.conf')(config);
};
2 changes: 1 addition & 1 deletion packages/zone.js/karma-build-sauce-selenium3-mocha.conf.js
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-dist-mocha.conf.js')(config);
require('./sauce-selenium3.conf')(config);
};
2 changes: 1 addition & 1 deletion packages/zone.js/karma-build.conf.js
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/browser-env-setup.js');
config.files.push('build/test/wtf_mock.js');
Expand Down
3 changes: 1 addition & 2 deletions packages/zone.js/karma-dist-jasmine.conf.js
@@ -1,5 +1,4 @@

module.exports = function(config) {
module.exports = function (config) {
require('./karma-dist.conf.js')(config);

config.plugins.push(require('karma-jasmine'));
Expand Down
7 changes: 3 additions & 4 deletions packages/zone.js/karma-dist-mocha.conf.js
@@ -1,5 +1,4 @@

module.exports = function(config) {
module.exports = function (config) {
require('./karma-dist.conf.js')(config);

for (let i = 0; i < config.files.length; i++) {
Expand All @@ -17,7 +16,7 @@ module.exports = function(config) {
config.plugins.push(require('karma-mocha'));
config.frameworks.push('mocha');
config.client.mocha = {
timeout: 5000 // copied timeout for Jasmine in WebSocket.spec (otherwise Mochas default timeout
// at 2 sec is to low for the tests)
timeout: 5000, // copied timeout for Jasmine in WebSocket.spec (otherwise Mochas default timeout
// at 2 sec is to low for the tests)
};
};
2 changes: 1 addition & 1 deletion packages/zone.js/karma-dist-sauce-jasmine.conf.js
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-dist-jasmine.conf.js')(config);
require('./sauce.conf')(config, ['SL_IOS9']);
};
3 changes: 1 addition & 2 deletions packages/zone.js/karma-dist-sauce-jasmine.es2015.conf.js
@@ -1,5 +1,4 @@

module.exports = function(config) {
module.exports = function (config) {
require('./karma-dist-jasmine.conf.js')(config);
require('./sauce.es2015.conf')(config);
config.files.push('build/test/wtf_mock.js');
Expand Down
18 changes: 14 additions & 4 deletions packages/zone.js/karma-dist-sauce-jasmine3.conf.js
Expand Up @@ -6,10 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-dist-jasmine.conf.js')(config);
require('./sauce.conf')(config, [
'SL_IOS9', 'SL_CHROME', 'SL_FIREFOX_54', 'SL_SAFARI8', 'SL_SAFARI9', 'SL_SAFARI10', 'SL_IOS8',
'SL_IOS9', 'SL_IOS10', 'SL_MSEDGE15', 'SL_ANDROID4.4', 'SL_ANDROID5.1'
])
'SL_IOS9',
'SL_CHROME',
'SL_FIREFOX_54',
'SL_SAFARI8',
'SL_SAFARI9',
'SL_SAFARI10',
'SL_IOS8',
'SL_IOS9',
'SL_IOS10',
'SL_MSEDGE15',
'SL_ANDROID4.4',
'SL_ANDROID5.1',
]);
};
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-dist-jasmine.conf.js')(config);
require('./sauce-selenium3.conf')(config);
};
2 changes: 1 addition & 1 deletion packages/zone.js/karma-dist.conf.js
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/browser-env-setup.js');
config.files.push('build/test/wtf_mock.js');
Expand Down
3 changes: 1 addition & 2 deletions packages/zone.js/karma-evergreen-dist-jasmine.conf.js
@@ -1,5 +1,4 @@

module.exports = function(config) {
module.exports = function (config) {
require('./karma-evergreen-dist.conf.js')(config);

config.plugins.push(require('karma-jasmine'));
Expand Down
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-evergreen-dist-jasmine.conf.js')(config);
require('./sauce-evergreen.conf')(config);
};
2 changes: 1 addition & 1 deletion packages/zone.js/karma-evergreen-dist.conf.js
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
module.exports = function (config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/browser-env-setup.js');
config.files.push('build/test/wtf_mock.js');
Expand Down
34 changes: 30 additions & 4 deletions packages/zone.js/lib/browser/api-util.ts
Expand Up @@ -6,8 +6,34 @@
* found in the LICENSE file at https://angular.io/license
*/

import {globalSources, patchEventPrototype, patchEventTarget, zoneSymbolEventNames} from '../common/events';
import {ADD_EVENT_LISTENER_STR, ArraySlice, attachOriginToPatched, bindArguments, FALSE_STR, isBrowser, isIEOrEdge, isMix, isNode, ObjectCreate, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, patchClass, patchMacroTask, patchMethod, patchOnProperties, REMOVE_EVENT_LISTENER_STR, TRUE_STR, wrapWithCurrentZone, ZONE_SYMBOL_PREFIX} from '../common/utils';
import {
globalSources,
patchEventPrototype,
patchEventTarget,
zoneSymbolEventNames,
} from '../common/events';
import {
ADD_EVENT_LISTENER_STR,
ArraySlice,
attachOriginToPatched,
bindArguments,
FALSE_STR,
isBrowser,
isIEOrEdge,
isMix,
isNode,
ObjectCreate,
ObjectDefineProperty,
ObjectGetOwnPropertyDescriptor,
patchClass,
patchMacroTask,
patchMethod,
patchOnProperties,
REMOVE_EVENT_LISTENER_STR,
TRUE_STR,
wrapWithCurrentZone,
ZONE_SYMBOL_PREFIX,
} from '../common/utils';
import {ZoneType} from '../zone-impl';

import {patchCallbacks} from './browser-util';
Expand All @@ -34,7 +60,7 @@ export function patchUtil(Zone: ZoneType): void {
}
if (global[SYMBOL_BLACK_LISTED_EVENTS]) {
(Zone as any)[SYMBOL_BLACK_LISTED_EVENTS] = (Zone as any)[SYMBOL_UNPATCHED_EVENTS] =
global[SYMBOL_BLACK_LISTED_EVENTS];
global[SYMBOL_BLACK_LISTED_EVENTS];
}
api.patchEventPrototype = patchEventPrototype;
api.patchEventTarget = patchEventTarget;
Expand All @@ -60,7 +86,7 @@ export function patchUtil(Zone: ZoneType): void {
FALSE_STR,
ZONE_SYMBOL_PREFIX,
ADD_EVENT_LISTENER_STR,
REMOVE_EVENT_LISTENER_STR
REMOVE_EVENT_LISTENER_STR,
});
});
}
14 changes: 9 additions & 5 deletions packages/zone.js/lib/browser/browser-legacy.ts
Expand Up @@ -16,15 +16,19 @@ import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy';
import {registerElementPatch} from './register-element';

export function patchBrowserLegacy(): void {
const _global: any = typeof window !== 'undefined' ? window :
typeof global !== 'undefined' ? global :
typeof self !== 'undefined' ? self :
{};
const _global: any =
typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: typeof self !== 'undefined'
? self
: {};
const symbolPrefix = _global['__Zone_symbol_prefix'] || '__zone_symbol__';
function __symbol__(name: string) {
return symbolPrefix + name;
}
_global[__symbol__('legacyPatch')] = function() {
_global[__symbol__('legacyPatch')] = function () {
const Zone = _global['Zone'];
Zone.__load_patch('defineProperty', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
api._redefineProperty = _redefineProperty;
Expand Down

0 comments on commit f307e95

Please sign in to comment.