Skip to content

Commit

Permalink
refactor(zone.js): use Object.prototype.toString directly for impro…
Browse files Browse the repository at this point in the history
…ved tree shakability

These lines were not tree shakable by Closure Compiler because `.toString()` is special cased as a "pure" function eligible to eliminated if it's return value is unused. However `.toString.call` circuments this and makes Closure Compiler think the function may have side effects. Switching to `.toString()` should be fine here as `process.toString()` in Node outputs `[object process]` so this should be safe. Presumably the original motivation for this roundabout approach was for type safety reasons which no longer apply as `_global` is `any`.
  • Loading branch information
dgp1130 committed Apr 18, 2024
1 parent ca517d7 commit b61ab85
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/zone.js/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const isWebWorker: boolean =
// this code.
export const isNode: boolean =
(!('nw' in _global) && typeof _global.process !== 'undefined' &&
{}.toString.call(_global.process) === '[object process]');
_global.process.toString() === '[object process]');

export const isBrowser: boolean =
!isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']);
Expand All @@ -119,7 +119,7 @@ export const isBrowser: boolean =
// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
// this code.
export const isMix: boolean = typeof _global.process !== 'undefined' &&
{}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
_global.process.toString() === '[object process]' && !isWebWorker &&
!!(isWindowExists && internalWindow['HTMLElement']);

const zoneSymbolEventNames: {[eventName: string]: string} = {};
Expand Down

0 comments on commit b61ab85

Please sign in to comment.