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

Commit

Permalink
fix(promise): support more aggressive optimization. (#431)
Browse files Browse the repository at this point in the history
ZoneAwarePromise does not technically implement or inherit the static
side of Promise, so aggressive optimizers may drop static methods such
as `all`, `race`, `reject`, and `resolve`.

This change explicitly exports them into quoted properties, which is
harmless for normal use and protects users of more aggressive
optimizers, such as Closure Compiler in typed mode.
  • Loading branch information
mprobst authored and mhevery committed Sep 9, 2016
1 parent 6767ff5 commit 26fc3da
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ const Zone: ZoneType = (function(global: any) {
'Unhandled Promise rejection:', rejection instanceof Error ? rejection.message : rejection,
'; Zone:', (<Zone>e.zone).name,
'; Task:', e.task && (<Task>e.task).source,
'; Value:', rejection,
'; Value:', rejection,
rejection instanceof Error ? rejection.stack : undefined
);
}
Expand Down Expand Up @@ -1121,6 +1121,12 @@ const Zone: ZoneType = (function(global: any) {
return this.then(null, onRejected);
}
}
// Protect against aggressive optimizers dropping seemingly unused properties.
// E.g. Closure Compiler in advanced mode.
ZoneAwarePromise['resolve'] = ZoneAwarePromise.resolve;
ZoneAwarePromise['reject'] = ZoneAwarePromise.reject;
ZoneAwarePromise['race'] = ZoneAwarePromise.race;
ZoneAwarePromise['all'] = ZoneAwarePromise.all;

const NativePromise = global[__symbol__('Promise')] = global.Promise;
global.Promise = ZoneAwarePromise;
Expand Down

0 comments on commit 26fc3da

Please sign in to comment.