refactor(platform-browser): Hoist functions to workaround optimization bug. (#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 #32230
This commit is contained in:
parent
8e354dae00
commit
294e56d529
|
@ -20,6 +20,21 @@ import {KeyEventsPlugin} from './dom/events/key_events';
|
||||||
import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';
|
import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';
|
||||||
import {DomSanitizer, DomSanitizerImpl} from './security/dom_sanitization_service';
|
import {DomSanitizer, DomSanitizerImpl} from './security/dom_sanitization_service';
|
||||||
|
|
||||||
|
export function initDomAdapter() {
|
||||||
|
BrowserDomAdapter.makeCurrent();
|
||||||
|
BrowserGetTestability.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function errorHandler(): ErrorHandler {
|
||||||
|
return new ErrorHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function _document(): any {
|
||||||
|
// Tell ivy about the global document
|
||||||
|
ɵsetDocument(document);
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
export const INTERNAL_BROWSER_PLATFORM_PROVIDERS: StaticProvider[] = [
|
export const INTERNAL_BROWSER_PLATFORM_PROVIDERS: StaticProvider[] = [
|
||||||
{provide: PLATFORM_ID, useValue: PLATFORM_BROWSER_ID},
|
{provide: PLATFORM_ID, useValue: PLATFORM_BROWSER_ID},
|
||||||
{provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true},
|
{provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true},
|
||||||
|
@ -47,21 +62,6 @@ export const BROWSER_SANITIZATION_PROVIDERS = BROWSER_SANITIZATION_PROVIDERS__PR
|
||||||
export const platformBrowser: (extraProviders?: StaticProvider[]) => PlatformRef =
|
export const platformBrowser: (extraProviders?: StaticProvider[]) => PlatformRef =
|
||||||
createPlatformFactory(platformCore, 'browser', INTERNAL_BROWSER_PLATFORM_PROVIDERS);
|
createPlatformFactory(platformCore, 'browser', INTERNAL_BROWSER_PLATFORM_PROVIDERS);
|
||||||
|
|
||||||
export function initDomAdapter() {
|
|
||||||
BrowserDomAdapter.makeCurrent();
|
|
||||||
BrowserGetTestability.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function errorHandler(): ErrorHandler {
|
|
||||||
return new ErrorHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function _document(): any {
|
|
||||||
// Tell ivy about the global document
|
|
||||||
ɵsetDocument(document);
|
|
||||||
return document;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const BROWSER_MODULE_PROVIDERS: StaticProvider[] = [
|
export const BROWSER_MODULE_PROVIDERS: StaticProvider[] = [
|
||||||
BROWSER_SANITIZATION_PROVIDERS,
|
BROWSER_SANITIZATION_PROVIDERS,
|
||||||
{provide: INJECTOR_SCOPE, useValue: 'root'},
|
{provide: INJECTOR_SCOPE, useValue: 'root'},
|
||||||
|
|
Loading…
Reference in New Issue