Skip to content

Commit abde8f2

Browse files
rkirovjelbourn
authored andcommitted
refactor(platform-browser): Hoist functions to workaround optimization bug (#16831)
Technically, function definitions can live anywhere because they are hoisted. However, in this case Closure optimizations break when exported function definitions are referred in another static object that is exported. The bad pattern is: ``` exports const obj = {f}; export function f() {...} ``` which turns to the following in Closure's module system: ``` goog.module('m'); exports.obj = {f}; function f() {...} exports.f = f; ``` which badly optimizes to (note module objects are collapsed) ``` var b = a; var a = function() {...}; // now b is undefined. ``` This is an optimizer bug and should be fixed in Closure, but in the meantime this change is a noop and will unblock other changes we want to make.
1 parent 421ce3a commit abde8f2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/material/core/common-behaviors/common-module.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ import {VERSION as CDK_VERSION} from '@angular/cdk';
1717
// re-exports all secondary entry-points
1818
const VERSION = new Version('0.0.0-PLACEHOLDER');
1919

20+
/** @docs-private */
21+
export function MATERIAL_SANITY_CHECKS_FACTORY(): boolean {
22+
return true;
23+
}
2024

2125
/** Injection token that configures whether the Material sanity checks are enabled. */
2226
export const MATERIAL_SANITY_CHECKS = new InjectionToken<boolean>('mat-sanity-checks', {
2327
providedIn: 'root',
2428
factory: MATERIAL_SANITY_CHECKS_FACTORY,
2529
});
2630

27-
/** @docs-private */
28-
export function MATERIAL_SANITY_CHECKS_FACTORY(): boolean {
29-
return true;
30-
}
31-
3231
/**
3332
* Module that captures anything that should be loaded and/or run for *all* Angular Material
3433
* components. This includes Bidi, etc.

0 commit comments

Comments
 (0)