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,10 +35,13 @@ declare global {
|
|||
|
||||
|
||||
declare let global: any;
|
||||
export const ngDevModeResetPerfCounters: () => void =
|
||||
(typeof ngDevMode == 'undefined' && (function(global: {ngDevMode: NgDevModePerfCounters}) {
|
||||
function ngDevModeResetPerfCounters() {
|
||||
global['ngDevMode'] = {
|
||||
|
||||
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,
|
||||
|
@ -59,8 +62,16 @@ export const ngDevModeResetPerfCounters: () => void =
|
|||
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();
|
||||
return ngDevModeResetPerfCounters;
|
||||
})(typeof window != 'undefined' && window || typeof self != 'undefined' && self ||
|
||||
typeof global != 'undefined' && global)) as() => void;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue