Skip to content

Commit 294e56d

Browse files
rkirovmhevery
authored andcommitted
refactor(platform-browser): Hoist functions to workaround optimization bug. (angular#32230)
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. PR Close angular#32230
1 parent 8e354da commit 294e56d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

packages/platform-browser/src/browser.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ import {KeyEventsPlugin} from './dom/events/key_events';
2020
import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';
2121
import {DomSanitizer, DomSanitizerImpl} from './security/dom_sanitization_service';
2222

23+
export function initDomAdapter() {
24+
BrowserDomAdapter.makeCurrent();
25+
BrowserGetTestability.init();
26+
}
27+
28+
export function errorHandler(): ErrorHandler {
29+
return new ErrorHandler();
30+
}
31+
32+
export function _document(): any {
33+
// Tell ivy about the global document
34+
ɵsetDocument(document);
35+
return document;
36+
}
37+
2338
export const INTERNAL_BROWSER_PLATFORM_PROVIDERS: StaticProvider[] = [
2439
{provide: PLATFORM_ID, useValue: PLATFORM_BROWSER_ID},
2540
{provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true},
@@ -47,21 +62,6 @@ export const BROWSER_SANITIZATION_PROVIDERS = BROWSER_SANITIZATION_PROVIDERS__PR
4762
export const platformBrowser: (extraProviders?: StaticProvider[]) => PlatformRef =
4863
createPlatformFactory(platformCore, 'browser', INTERNAL_BROWSER_PLATFORM_PROVIDERS);
4964

50-
export function initDomAdapter() {
51-
BrowserDomAdapter.makeCurrent();
52-
BrowserGetTestability.init();
53-
}
54-
55-
export function errorHandler(): ErrorHandler {
56-
return new ErrorHandler();
57-
}
58-
59-
export function _document(): any {
60-
// Tell ivy about the global document
61-
ɵsetDocument(document);
62-
return document;
63-
}
64-
6565
export const BROWSER_MODULE_PROVIDERS: StaticProvider[] = [
6666
BROWSER_SANITIZATION_PROVIDERS,
6767
{provide: INJECTOR_SCOPE, useValue: 'root'},

0 commit comments

Comments
 (0)