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 (#55412)

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` circumvents 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`.

PR Close #55412
  • Loading branch information
dgp1130 authored and AndrewKushnir committed Apr 30, 2024
1 parent 9f777b6 commit 3312727
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 @@ -115,7 +115,7 @@ export const isWebWorker: boolean =
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 @@ -125,7 +125,7 @@ export const isBrowser: boolean =
// this code.
export const isMix: boolean =
typeof _global.process !== 'undefined' &&
{}.toString.call(_global.process) === '[object process]' &&
_global.process.toString() === '[object process]' &&
!isWebWorker &&
!!(isWindowExists && internalWindow['HTMLElement']);

Expand Down

0 comments on commit 3312727

Please sign in to comment.