fix(ivy): default to `ngDevMode = true` (#25208)
Before the `ngDevMode` had to be set explicitly or it would throw an exception at runtime. This changes it so that if `ngDevModu` is `undefined` than we default to `ngDevMode = true`. In other words unless the developer has explicitly asked to make a prodution build by setting `ngDevMode = false` as compilation constant, the default is `ngDevMode = true`. This also fixes a minor bug where the setup code would read `global['ngDevMode']` but all other code would read `global.ngDevMode`. This would cause issues with closure compiler since the reading of the `ngDevMode` must be consistent. PR Close #25208
This commit is contained in:
parent
4cb1074850
commit
aafd502bcb
|
@ -35,32 +35,43 @@ declare global {
|
|||
|
||||
|
||||
declare let global: any;
|
||||
export const ngDevModeResetPerfCounters: () => void =
|
||||
(typeof ngDevMode == 'undefined' && (function(global: {ngDevMode: NgDevModePerfCounters}) {
|
||||
function ngDevModeResetPerfCounters() {
|
||||
global['ngDevMode'] = {
|
||||
firstTemplatePass: 0,
|
||||
tNode: 0,
|
||||
tView: 0,
|
||||
rendererCreateTextNode: 0,
|
||||
rendererSetText: 0,
|
||||
rendererCreateElement: 0,
|
||||
rendererAddEventListener: 0,
|
||||
rendererSetAttribute: 0,
|
||||
rendererRemoveAttribute: 0,
|
||||
rendererSetProperty: 0,
|
||||
rendererSetClassName: 0,
|
||||
rendererAddClass: 0,
|
||||
rendererRemoveClass: 0,
|
||||
rendererSetStyle: 0,
|
||||
rendererRemoveStyle: 0,
|
||||
rendererDestroy: 0,
|
||||
rendererDestroyNode: 0,
|
||||
rendererMoveNode: 0,
|
||||
rendererRemoveNode: 0,
|
||||
};
|
||||
}
|
||||
ngDevModeResetPerfCounters();
|
||||
return ngDevModeResetPerfCounters;
|
||||
})(typeof window != 'undefined' && window || typeof self != 'undefined' && self ||
|
||||
typeof global != 'undefined' && global)) as() => void;
|
||||
|
||||
const __global: {ngDevMode: NgDevModePerfCounters | boolean} =
|
||||
typeof window != 'undefined' && window || typeof self != 'undefined' && self ||
|
||||
typeof global != 'undefined' && global;
|
||||
|
||||
export function ngDevModeResetPerfCounters() {
|
||||
__global.ngDevMode = {
|
||||
firstTemplatePass: 0,
|
||||
tNode: 0,
|
||||
tView: 0,
|
||||
rendererCreateTextNode: 0,
|
||||
rendererSetText: 0,
|
||||
rendererCreateElement: 0,
|
||||
rendererAddEventListener: 0,
|
||||
rendererSetAttribute: 0,
|
||||
rendererRemoveAttribute: 0,
|
||||
rendererSetProperty: 0,
|
||||
rendererSetClassName: 0,
|
||||
rendererAddClass: 0,
|
||||
rendererRemoveClass: 0,
|
||||
rendererSetStyle: 0,
|
||||
rendererRemoveStyle: 0,
|
||||
rendererDestroy: 0,
|
||||
rendererDestroyNode: 0,
|
||||
rendererMoveNode: 0,
|
||||
rendererRemoveNode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This checks to see if the `ngDevMode` has been set. If yes,
|
||||
* than we honor it, otherwise we default to dev mode with additional checks.
|
||||
*
|
||||
* The idea is that unless we are doing production build where we explicitly
|
||||
* set `ngDevMode == false` we should be helping the developer by providing
|
||||
* as much early warning and errors as possible.
|
||||
*/
|
||||
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
||||
ngDevModeResetPerfCounters();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue