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

Commit 26fc3da

Browse files
mprobstmhevery
authored andcommitted
fix(promise): support more aggressive optimization. (#431)
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.
1 parent 6767ff5 commit 26fc3da

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: lib/zone.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ const Zone: ZoneType = (function(global: any) {
916916
'Unhandled Promise rejection:', rejection instanceof Error ? rejection.message : rejection,
917917
'; Zone:', (<Zone>e.zone).name,
918918
'; Task:', e.task && (<Task>e.task).source,
919-
'; Value:', rejection,
919+
'; Value:', rejection,
920920
rejection instanceof Error ? rejection.stack : undefined
921921
);
922922
}
@@ -1121,6 +1121,12 @@ const Zone: ZoneType = (function(global: any) {
11211121
return this.then(null, onRejected);
11221122
}
11231123
}
1124+
// Protect against aggressive optimizers dropping seemingly unused properties.
1125+
// E.g. Closure Compiler in advanced mode.
1126+
ZoneAwarePromise['resolve'] = ZoneAwarePromise.resolve;
1127+
ZoneAwarePromise['reject'] = ZoneAwarePromise.reject;
1128+
ZoneAwarePromise['race'] = ZoneAwarePromise.race;
1129+
ZoneAwarePromise['all'] = ZoneAwarePromise.all;
11241130

11251131
const NativePromise = global[__symbol__('Promise')] = global.Promise;
11261132
global.Promise = ZoneAwarePromise;

0 commit comments

Comments
 (0)