Skip to content

Commit

Permalink
refactor(zone.js): change from scripts to modules (#53445)
Browse files Browse the repository at this point in the history
Make Zone.js compatible with moduleDetection:force by turning files that
are currently incompatible from scripts into modules using an empty
export statement.

PR Close #53445
  • Loading branch information
frigus02 authored and atscott committed Jan 9, 2024
1 parent eb2e879 commit 0dad149
Show file tree
Hide file tree
Showing 6 changed files with 2,104 additions and 2,074 deletions.
24 changes: 14 additions & 10 deletions packages/zone.js/lib/common/error-rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
* @suppress {globalThis,undefinedVars}
*/

/**
* Extend the Error with additional fields for rewritten stack frames
*/
interface Error {
declare global {
/**
* Stack trace where extra frames have been removed and zone names added.
* Extend the Error with additional fields for rewritten stack frames
*/
zoneAwareStack?: string;
interface Error {
/**
* Stack trace where extra frames have been removed and zone names added.
*/
zoneAwareStack?: string;

/**
* Original stack trace with no modifications
*/
originalStack?: string;
/**
* Original stack trace with no modifications
*/
originalStack?: string;
}
}

Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
Expand Down Expand Up @@ -394,3 +396,5 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {

(Error as any).stackTraceLimit = originalStackTraceLimit;
});

export {};
68 changes: 36 additions & 32 deletions packages/zone.js/lib/zone.api.extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,43 @@
* found in the LICENSE file at https://angular.io/license
*/

/**
* Additional `EventTarget` methods added by `Zone.js`.
*
* 1. removeAllListeners, remove all event listeners of the given event name.
* 2. eventListeners, get all event listeners of the given event name.
*/
interface EventTarget {
declare global {
/**
* Additional `EventTarget` methods added by `Zone.js`.
*
* Remove all event listeners by name for this event target.
*
* This method is optional because it may not be available if you use `noop zone` when
* bootstrapping Angular application or disable the `EventTarget` monkey patch by `zone.js`.
*
* If the `eventName` is provided, will remove event listeners of that name.
* If the `eventName` is not provided, will remove all event listeners associated with
* `EventTarget`.
*
* @param eventName the name of the event, such as `click`. This parameter is optional.
* 1. removeAllListeners, remove all event listeners of the given event name.
* 2. eventListeners, get all event listeners of the given event name.
*/
removeAllListeners?(eventName?: string): void;
/**
*
* Retrieve all event listeners by name.
*
* This method is optional because it may not be available if you use `noop zone` when
* bootstrapping Angular application or disable the `EventTarget` monkey patch by `zone.js`.
*
* If the `eventName` is provided, will return an array of event handlers or event listener
* objects of the given event.
* If the `eventName` is not provided, will return all listeners.
*
* @param eventName the name of the event, such as click. This parameter is optional.
*/
eventListeners?(eventName?: string): EventListenerOrEventListenerObject[];
interface EventTarget {
/**
*
* Remove all event listeners by name for this event target.
*
* This method is optional because it may not be available if you use `noop zone` when
* bootstrapping Angular application or disable the `EventTarget` monkey patch by `zone.js`.
*
* If the `eventName` is provided, will remove event listeners of that name.
* If the `eventName` is not provided, will remove all event listeners associated with
* `EventTarget`.
*
* @param eventName the name of the event, such as `click`. This parameter is optional.
*/
removeAllListeners?(eventName?: string): void;
/**
*
* Retrieve all event listeners by name.
*
* This method is optional because it may not be available if you use `noop zone` when
* bootstrapping Angular application or disable the `EventTarget` monkey patch by `zone.js`.
*
* If the `eventName` is provided, will return an array of event handlers or event listener
* objects of the given event.
* If the `eventName` is not provided, will return all listeners.
*
* @param eventName the name of the event, such as click. This parameter is optional.
*/
eventListeners?(eventName?: string): EventListenerOrEventListenerObject[];
}
}

export {};
Loading

0 comments on commit 0dad149

Please sign in to comment.