@@ -608,7 +608,19 @@ type AmbientZoneDelegate = ZoneDelegate;
608
608
609
609
const Zone : ZoneType = ( function ( global : any ) {
610
610
if ( global [ 'Zone' ] ) {
611
- throw new Error ( 'Zone already loaded.' ) ;
611
+ let zoneAlreadyLoadedMessage : string = 'Zone already loaded.' ;
612
+ // try to findout the already loaded zone.js script file
613
+ // require the loaded zone.js version to be newer than 0.8.6
614
+ try {
615
+ const LoadedZone : any = global [ 'Zone' ] ;
616
+ const scriptFileName : string = LoadedZone [ '__zone_symbol__scriptFileName' ] ;
617
+ if ( scriptFileName ) {
618
+ zoneAlreadyLoadedMessage =
619
+ 'Zone already loaded. The loaded Zone.js script file seems to be ' + scriptFileName ;
620
+ }
621
+ } catch ( error ) {
622
+ }
623
+ throw new Error ( zoneAlreadyLoadedMessage ) ;
612
624
}
613
625
614
626
const NO_ZONE = { name : 'NO ZONE' } ;
@@ -623,12 +635,17 @@ const Zone: ZoneType = (function(global: any) {
623
635
624
636
static assertZonePatched ( ) {
625
637
if ( global . Promise !== ZoneAwarePromise ) {
638
+ // try to findout the already loaded zone.js script file
639
+ // require the loaded zone.js version to be newer than 0.8.6
640
+ const scriptFileName : string = ( Zone as any ) [ __symbol__ ( 'scriptFileName' ) ] ;
641
+ const scriptFileErrorMessage : string =
642
+ scriptFileName ? 'the loaded Zone.js script file seems to be ' + scriptFileName : '' ;
626
643
throw new Error (
627
644
'Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
628
645
'has been overwritten.\n' +
629
646
'Most likely cause is that a Promise polyfill has been loaded ' +
630
647
'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' +
631
- 'If you must load one, do so before loading zone.js.)' ) ;
648
+ 'If you must load one, do so before loading zone.js.)' + scriptFileErrorMessage ) ;
632
649
}
633
650
}
634
651
@@ -1803,11 +1820,24 @@ const Zone: ZoneType = (function(global: any) {
1803
1820
// Chrome: at Zone.run (http://localhost:9876/base/build/lib/zone.js:100:24)
1804
1821
// FireFox: Zone.prototype.run@http ://localhost:9876/base/build/lib/zone.js:101:24
1805
1822
// Safari: run@http ://localhost:9876/base/build/lib/zone.js:101:24
1806
- let fnName : string = frame . split ( '(' ) [ 0 ] . split ( '@' ) [ 0 ] ;
1823
+ let frameParts : string [ ] = frame . split ( '(' ) ;
1824
+ let fnNamePart : string = frameParts [ 0 ] ;
1825
+
1826
+ let fnName : string = fnNamePart . split ( '@' ) [ 0 ] ;
1807
1827
let frameType = FrameType . transition ;
1808
1828
if ( fnName . indexOf ( 'ZoneAwareError' ) !== - 1 ) {
1809
1829
zoneAwareFrame1 = frame ;
1810
1830
zoneAwareFrame2 = frame . replace ( 'Error.' , '' ) ;
1831
+
1832
+ // try to find the filename where zone.js live with
1833
+ let fileNamePart1 : string = frameParts . length > 1 ? frameParts [ 1 ] : fnNamePart ;
1834
+ let fileNameParts : string [ ] = fileNamePart1 . split ( '@' ) ;
1835
+ let fileNamePart2 : string =
1836
+ fileNameParts . length > 1 ? fileNameParts [ 1 ] : fileNameParts [ 0 ] ;
1837
+ // Keep a script file name in Zone, so when zone.js report 'already loaded'
1838
+ // error, it can report which file include the loaded zone.js
1839
+ ( Zone as any ) [ __symbol__ ( 'scriptFileName' ) ] = fileNamePart2 ;
1840
+
1811
1841
blackListedStackFrames [ zoneAwareFrame2 ] = FrameType . blackList ;
1812
1842
}
1813
1843
if ( fnName . indexOf ( 'runGuarded' ) !== - 1 ) {
0 commit comments