perf(forms): use `ngDevMode` to tree-shake `_ngModelWarning` (#39964) · angular/angular@735556d

File tree

3 files changed

lines changed

  • packages/forms/src/directives

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -125,7 +125,9 @@ export class FormControlDirective extends NgControl implements OnChanges {

125125

this.form.updateValueAndValidity({emitEvent: false});

126126

}

127127

if (isPropertyUpdated(changes, this.viewModel)) {

128-

_ngModelWarning('formControl', FormControlDirective, this, this._ngModelWarningConfig);

128+

if (typeof ngDevMode === 'undefined' || ngDevMode) {

129+

_ngModelWarning('formControl', FormControlDirective, this, this._ngModelWarningConfig);

130+

}

129131

this.form.setValue(this.model);

130132

this.viewModel = this.model;

131133

}

Original file line numberDiff line numberDiff line change

@@ -145,7 +145,9 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {

145145

ngOnChanges(changes: SimpleChanges) {

146146

if (!this._added) this._setUpControl();

147147

if (isPropertyUpdated(changes, this.viewModel)) {

148-

_ngModelWarning('formControlName', FormControlName, this, this._ngModelWarningConfig);

148+

if (typeof ngDevMode === 'undefined' || ngDevMode) {

149+

_ngModelWarning('formControlName', FormControlName, this, this._ngModelWarningConfig);

150+

}

149151

this.viewModel = this.model;

150152

this.formDirective.updateModel(this, this.model);

151153

}

Original file line numberDiff line numberDiff line change

@@ -6,8 +6,6 @@

66

* found in the LICENSE file at https://angular.io/license

77

*/

88
9-

import {isDevMode} from '@angular/core';

10-
119

import {AbstractControl, FormArray, FormControl, FormGroup} from '../model';

1210

import {getControlAsyncValidators, getControlValidators, mergeValidators} from '../validators';

1311

@@ -324,13 +322,11 @@ export function removeListItem<T>(list: T[], el: T): void {

324322

export function _ngModelWarning(

325323

name: string, type: {_ngModelWarningSentOnce: boolean},

326324

instance: {_ngModelWarningSent: boolean}, warningConfig: string|null) {

327-

if (!isDevMode() || warningConfig === 'never') return;

325+

if (warningConfig === 'never') return;

328326
329327

if (((warningConfig === null || warningConfig === 'once') && !type._ngModelWarningSentOnce) ||

330328

(warningConfig === 'always' && !instance._ngModelWarningSent)) {

331-

if (typeof ngDevMode === 'undefined' || ngDevMode) {

332-

ReactiveErrors.ngModelWarning(name);

333-

}

329+

ReactiveErrors.ngModelWarning(name);

334330

type._ngModelWarningSentOnce = true;

335331

instance._ngModelWarningSent = true;

336332

}