@@ -90,13 +90,21 @@ export class MatCommonModule {
90
90
return typeof win === 'object' && win ? win : null ;
91
91
}
92
92
93
- /** Whether any sanity checks are enabled. */
94
- private _checksAreEnabled ( ) : boolean {
93
+ /** Gets whether a specific sanity check is enabled. */
94
+ private _checkIsEnabled ( name : keyof GranularSanityChecks ) : boolean {
95
95
// TODO(crisbeto): we can't use `ngDevMode` here yet, because ViewEngine apps might not support
96
96
// it. Since these checks can have performance implications and they aren't tree shakeable
97
97
// in their current form, we can leave the `isDevMode` check in for now.
98
98
// tslint:disable-next-line:ban
99
- return isDevMode ( ) && ! this . _isTestEnv ( ) ;
99
+ if ( ! isDevMode ( ) || this . _isTestEnv ( ) ) {
100
+ return false ;
101
+ }
102
+
103
+ if ( typeof this . _sanityChecks === 'boolean' ) {
104
+ return this . _sanityChecks ;
105
+ }
106
+
107
+ return ! ! this . _sanityChecks [ name ] ;
100
108
}
101
109
102
110
/** Whether the code is running in tests. */
@@ -106,10 +114,7 @@ export class MatCommonModule {
106
114
}
107
115
108
116
private _checkDoctypeIsDefined ( ) : void {
109
- const isEnabled = this . _checksAreEnabled ( ) &&
110
- ( this . _sanityChecks === true || ( this . _sanityChecks as GranularSanityChecks ) . doctype ) ;
111
-
112
- if ( isEnabled && ! this . _document . doctype ) {
117
+ if ( this . _checkIsEnabled ( 'doctype' ) && ! this . _document . doctype ) {
113
118
console . warn (
114
119
'Current document does not have a doctype. This may cause ' +
115
120
'some Angular Material components not to behave as expected.'
@@ -120,10 +125,8 @@ export class MatCommonModule {
120
125
private _checkThemeIsPresent ( ) : void {
121
126
// We need to assert that the `body` is defined, because these checks run very early
122
127
// and the `body` won't be defined if the consumer put their scripts in the `head`.
123
- const isDisabled = ! this . _checksAreEnabled ( ) ||
124
- ( this . _sanityChecks === false || ! ( this . _sanityChecks as GranularSanityChecks ) . theme ) ;
125
-
126
- if ( isDisabled || ! this . _document . body || typeof getComputedStyle !== 'function' ) {
128
+ if ( ! this . _checkIsEnabled ( 'theme' ) || ! this . _document . body ||
129
+ typeof getComputedStyle !== 'function' ) {
127
130
return ;
128
131
}
129
132
@@ -150,10 +153,7 @@ export class MatCommonModule {
150
153
151
154
/** Checks whether the material version matches the cdk version */
152
155
private _checkCdkVersionMatch ( ) : void {
153
- const isEnabled = this . _checksAreEnabled ( ) &&
154
- ( this . _sanityChecks === true || ( this . _sanityChecks as GranularSanityChecks ) . version ) ;
155
-
156
- if ( isEnabled && VERSION . full !== CDK_VERSION . full ) {
156
+ if ( this . _checkIsEnabled ( 'version' ) && VERSION . full !== CDK_VERSION . full ) {
157
157
console . warn (
158
158
'The Angular Material version (' + VERSION . full + ') does not match ' +
159
159
'the Angular CDK version (' + CDK_VERSION . full + ').\n' +
0 commit comments