perf: delete pre-view-engine core, compiler, platform-browser, etc code (#14788)
After the introduction of the view engine, we can drop a lot of code that is not used any more. This should reduce the size of the app bundles because a lot of this code was not being properly tree-shaken by today's tools even though it was dead code.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
|
||||
import {PlatformLocation, ɵPLATFORM_SERVER_ID as PLATFORM_SERVER_ID} from '@angular/common';
|
||||
import {platformCoreDynamic} from '@angular/compiler';
|
||||
import {Injectable, InjectionToken, Injector, NgModule, PLATFORM_ID, PLATFORM_INITIALIZER, PlatformRef, Provider, RendererFactoryV2, RootRenderer, createPlatformFactory, isDevMode, platformCore, ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS, ɵDebugDomRootRenderer as DebugDomRootRenderer} from '@angular/core';
|
||||
import {Injectable, InjectionToken, Injector, NgModule, PLATFORM_ID, PLATFORM_INITIALIZER, PlatformRef, Provider, RendererFactoryV2, RootRenderer, createPlatformFactory, isDevMode, platformCore, ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS} from '@angular/core';
|
||||
import {HttpModule} from '@angular/http';
|
||||
import {BrowserModule, DOCUMENT, ɵSharedStylesHost as SharedStylesHost, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
|
||||
@ -16,7 +16,7 @@ import {SERVER_HTTP_PROVIDERS} from './http';
|
||||
import {ServerPlatformLocation} from './location';
|
||||
import {Parse5DomAdapter, parseDocument} from './parse5_adapter';
|
||||
import {PlatformState} from './platform_state';
|
||||
import {ServerRendererFactoryV2, ServerRootRenderer} from './server_renderer';
|
||||
import {ServerRendererFactoryV2} from './server_renderer';
|
||||
import {ServerStylesHost} from './styles_host';
|
||||
import {INITIAL_CONFIG, PlatformConfig} from './tokens';
|
||||
|
||||
@ -37,14 +37,7 @@ function initParse5Adapter(injector: Injector) {
|
||||
return () => { Parse5DomAdapter.makeCurrent(); };
|
||||
}
|
||||
|
||||
export function _createConditionalRootRenderer(rootRenderer: any) {
|
||||
return isDevMode() ? new DebugDomRootRenderer(rootRenderer) : rootRenderer;
|
||||
}
|
||||
|
||||
|
||||
export const SERVER_RENDER_PROVIDERS: Provider[] = [
|
||||
ServerRootRenderer,
|
||||
{provide: RootRenderer, useFactory: _createConditionalRootRenderer, deps: [ServerRootRenderer]},
|
||||
ServerRendererFactoryV2,
|
||||
{provide: RendererFactoryV2, useExisting: ServerRendererFactoryV2},
|
||||
ServerStylesHost,
|
||||
|
@ -7,263 +7,13 @@
|
||||
*/
|
||||
|
||||
import {DomElementSchemaRegistry} from '@angular/compiler';
|
||||
import {APP_ID, Inject, Injectable, NgZone, RenderComponentType, Renderer, RendererFactoryV2, RendererTypeV2, RendererV2, RootRenderer, ViewEncapsulation, ɵAnimationKeyframe as AnimationKeyframe, ɵAnimationPlayer as AnimationPlayer, ɵAnimationStyles as AnimationStyles, ɵRenderDebugInfo as RenderDebugInfo} from '@angular/core';
|
||||
import {AnimationDriver, DOCUMENT, ɵNAMESPACE_URIS as NAMESPACE_URIS, ɵSharedStylesHost as SharedStylesHost, ɵflattenStyles as flattenStyles, ɵgetDOM as getDOM, ɵisNamespaced as isNamespaced, ɵshimContentAttribute as shimContentAttribute, ɵshimHostAttribute as shimHostAttribute, ɵsplitNamespace as splitNamespace} from '@angular/platform-browser';
|
||||
import {APP_ID, Inject, Injectable, NgZone, RenderComponentType, Renderer, RendererFactoryV2, RendererTypeV2, RendererV2, RootRenderer, ViewEncapsulation} from '@angular/core';
|
||||
import {DOCUMENT, ɵNAMESPACE_URIS as NAMESPACE_URIS, ɵSharedStylesHost as SharedStylesHost, ɵflattenStyles as flattenStyles, ɵgetDOM as getDOM, ɵshimContentAttribute as shimContentAttribute, ɵshimHostAttribute as shimHostAttribute} from '@angular/platform-browser';
|
||||
|
||||
import {isBlank, isPresent, stringify} from './facade/lang';
|
||||
|
||||
const TEMPLATE_COMMENT_TEXT = 'template bindings={}';
|
||||
const TEMPLATE_BINDINGS_EXP = /^template bindings=(.*)$/;
|
||||
|
||||
const EMPTY_ARRAY: any[] = [];
|
||||
|
||||
@Injectable()
|
||||
export class ServerRootRenderer implements RootRenderer {
|
||||
protected registeredComponents: Map<string, ServerRenderer> = new Map<string, ServerRenderer>();
|
||||
private _schema = new DomElementSchemaRegistry();
|
||||
|
||||
constructor(
|
||||
@Inject(DOCUMENT) public document: any, public sharedStylesHost: SharedStylesHost,
|
||||
public animationDriver: AnimationDriver, @Inject(APP_ID) public appId: string,
|
||||
private _zone: NgZone) {
|
||||
throw new Error(
|
||||
'RootRenderer is no longer supported. Please use the `RendererFactoryV2` instead!');
|
||||
}
|
||||
|
||||
renderComponent(componentProto: RenderComponentType): Renderer {
|
||||
let renderer = this.registeredComponents.get(componentProto.id);
|
||||
if (!renderer) {
|
||||
renderer = new ServerRenderer(
|
||||
this, componentProto, this.animationDriver, `${this.appId}-${componentProto.id}`,
|
||||
this._zone, this._schema);
|
||||
this.registeredComponents.set(componentProto.id, renderer);
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
}
|
||||
|
||||
export class ServerRenderer implements Renderer {
|
||||
private _contentAttr: string;
|
||||
private _hostAttr: string;
|
||||
private _styles: string[];
|
||||
|
||||
constructor(
|
||||
private _rootRenderer: ServerRootRenderer, private componentProto: RenderComponentType,
|
||||
private _animationDriver: AnimationDriver, styleShimId: string, private _zone: NgZone,
|
||||
private _schema: DomElementSchemaRegistry) {
|
||||
this._styles = flattenStyles(styleShimId, componentProto.styles, []);
|
||||
if (componentProto.encapsulation === ViewEncapsulation.Native) {
|
||||
throw new Error('Native encapsulation is not supported on the server!');
|
||||
}
|
||||
this._rootRenderer.sharedStylesHost.addStyles(this._styles);
|
||||
if (this.componentProto.encapsulation === ViewEncapsulation.Emulated) {
|
||||
this._contentAttr = shimContentAttribute(styleShimId);
|
||||
this._hostAttr = shimHostAttribute(styleShimId);
|
||||
} else {
|
||||
this._contentAttr = null;
|
||||
this._hostAttr = null;
|
||||
}
|
||||
}
|
||||
|
||||
selectRootElement(selectorOrNode: string|any, debugInfo: RenderDebugInfo): Element {
|
||||
let el: any /** TODO #9100 */;
|
||||
if (typeof selectorOrNode === 'string') {
|
||||
el = getDOM().querySelector(this._rootRenderer.document, selectorOrNode);
|
||||
if (isBlank(el)) {
|
||||
throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
|
||||
}
|
||||
} else {
|
||||
el = selectorOrNode;
|
||||
}
|
||||
getDOM().clearNodes(el);
|
||||
return el;
|
||||
}
|
||||
|
||||
createElement(parent: Element, name: string, debugInfo: RenderDebugInfo): Node {
|
||||
let el: any;
|
||||
if (isNamespaced(name)) {
|
||||
const nsAndName = splitNamespace(name);
|
||||
el = getDOM().createElementNS(NAMESPACE_URIS[nsAndName[0]], nsAndName[1]);
|
||||
} else {
|
||||
el = getDOM().createElement(name);
|
||||
}
|
||||
if (isPresent(this._contentAttr)) {
|
||||
getDOM().setAttribute(el, this._contentAttr, '');
|
||||
}
|
||||
if (isPresent(parent)) {
|
||||
getDOM().appendChild(parent, el);
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
createViewRoot(hostElement: any): any {
|
||||
let nodesParent: any /** TODO #9100 */;
|
||||
if (isPresent(this._hostAttr)) {
|
||||
getDOM().setAttribute(hostElement, this._hostAttr, '');
|
||||
}
|
||||
nodesParent = hostElement;
|
||||
return nodesParent;
|
||||
}
|
||||
|
||||
createTemplateAnchor(parentElement: any, debugInfo: RenderDebugInfo): any {
|
||||
const comment = getDOM().createComment(TEMPLATE_COMMENT_TEXT);
|
||||
if (isPresent(parentElement)) {
|
||||
getDOM().appendChild(parentElement, comment);
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
|
||||
createText(parentElement: any, value: string, debugInfo: RenderDebugInfo): any {
|
||||
const node = getDOM().createTextNode(value);
|
||||
if (isPresent(parentElement)) {
|
||||
getDOM().appendChild(parentElement, node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
projectNodes(parentElement: any, nodes: any[]) {
|
||||
if (isBlank(parentElement)) return;
|
||||
appendNodes(parentElement, nodes);
|
||||
}
|
||||
|
||||
attachViewAfter(node: any, viewRootNodes: any[]) { moveNodesAfterSibling(node, viewRootNodes); }
|
||||
|
||||
detachView(viewRootNodes: any[]) {
|
||||
for (let i = 0; i < viewRootNodes.length; i++) {
|
||||
getDOM().remove(viewRootNodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
destroyView(hostElement: any, viewAllNodes: any[]) {}
|
||||
|
||||
listen(renderElement: any, name: string, callback: Function): Function {
|
||||
// Note: We are not using the EventsPlugin here as this is not needed
|
||||
// to run our tests.
|
||||
const outsideHandler = (event: any) => this._zone.runGuarded(() => callback(event));
|
||||
return this._zone.runOutsideAngular(
|
||||
() => getDOM().onAndCancel(renderElement, name, outsideHandler));
|
||||
}
|
||||
|
||||
listenGlobal(target: string, name: string, callback: Function): Function {
|
||||
const renderElement = getDOM().getGlobalEventTarget(this._rootRenderer.document, target);
|
||||
return this.listen(renderElement, name, callback);
|
||||
}
|
||||
|
||||
// The value was validated already as a property binding, against the property name.
|
||||
// To know this value is safe to use as an attribute, the security context of the
|
||||
// attribute with the given name is checked against that security context of the
|
||||
// property.
|
||||
private _isSafeToReflectProperty(tagName: string, propertyName: string): boolean {
|
||||
return this._schema.securityContext(tagName, propertyName, true) ===
|
||||
this._schema.securityContext(tagName, propertyName, false);
|
||||
}
|
||||
|
||||
setElementProperty(renderElement: any, propertyName: string, propertyValue: any): void {
|
||||
getDOM().setProperty(renderElement, propertyName, propertyValue);
|
||||
|
||||
// Mirror property values for known HTML element properties in the attributes.
|
||||
const tagName = (renderElement.tagName as string).toLowerCase();
|
||||
if (isPresent(propertyValue) &&
|
||||
(typeof propertyValue === 'number' || typeof propertyValue == 'string') &&
|
||||
this._schema.hasElement(tagName, EMPTY_ARRAY) &&
|
||||
this._schema.hasProperty(tagName, propertyName, EMPTY_ARRAY) &&
|
||||
this._isSafeToReflectProperty(tagName, propertyName)) {
|
||||
this.setElementAttribute(renderElement, propertyName, propertyValue.toString());
|
||||
}
|
||||
}
|
||||
|
||||
setElementAttribute(renderElement: any, attributeName: string, attributeValue: string): void {
|
||||
let attrNs: string;
|
||||
let attrNameWithoutNs = attributeName;
|
||||
if (isNamespaced(attributeName)) {
|
||||
const nsAndName = splitNamespace(attributeName);
|
||||
attrNameWithoutNs = nsAndName[1];
|
||||
attributeName = nsAndName[0] + ':' + nsAndName[1];
|
||||
attrNs = NAMESPACE_URIS[nsAndName[0]];
|
||||
}
|
||||
if (isPresent(attributeValue)) {
|
||||
if (isPresent(attrNs)) {
|
||||
getDOM().setAttributeNS(renderElement, attrNs, attributeName, attributeValue);
|
||||
} else {
|
||||
getDOM().setAttribute(renderElement, attributeName, attributeValue);
|
||||
}
|
||||
} else {
|
||||
if (isPresent(attrNs)) {
|
||||
getDOM().removeAttributeNS(renderElement, attrNs, attrNameWithoutNs);
|
||||
} else {
|
||||
getDOM().removeAttribute(renderElement, attributeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setBindingDebugInfo(renderElement: any, propertyName: string, propertyValue: string): void {
|
||||
if (getDOM().isCommentNode(renderElement)) {
|
||||
const existingBindings =
|
||||
getDOM().getText(renderElement).replace(/\n/g, '').match(TEMPLATE_BINDINGS_EXP);
|
||||
const parsedBindings = JSON.parse(existingBindings[1]);
|
||||
(parsedBindings as any /** TODO #9100 */)[propertyName] = propertyValue;
|
||||
getDOM().setText(
|
||||
renderElement,
|
||||
TEMPLATE_COMMENT_TEXT.replace('{}', JSON.stringify(parsedBindings, null, 2)));
|
||||
} else {
|
||||
propertyName = propertyName.replace(/\$/g, '_');
|
||||
this.setElementAttribute(renderElement, propertyName, propertyValue);
|
||||
}
|
||||
}
|
||||
|
||||
setElementClass(renderElement: any, className: string, isAdd: boolean): void {
|
||||
if (isAdd) {
|
||||
getDOM().addClass(renderElement, className);
|
||||
} else {
|
||||
getDOM().removeClass(renderElement, className);
|
||||
}
|
||||
}
|
||||
|
||||
setElementStyle(renderElement: any, styleName: string, styleValue: string): void {
|
||||
if (isPresent(styleValue)) {
|
||||
getDOM().setStyle(renderElement, styleName, stringify(styleValue));
|
||||
} else {
|
||||
getDOM().removeStyle(renderElement, styleName);
|
||||
}
|
||||
}
|
||||
|
||||
invokeElementMethod(renderElement: any, methodName: string, args: any[]): void {
|
||||
getDOM().invoke(renderElement, methodName, args);
|
||||
}
|
||||
|
||||
setText(renderNode: any, text: string): void { getDOM().setText(renderNode, text); }
|
||||
|
||||
animate(
|
||||
element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[],
|
||||
duration: number, delay: number, easing: string,
|
||||
previousPlayers: AnimationPlayer[] = []): AnimationPlayer {
|
||||
return this._animationDriver.animate(
|
||||
element, startingStyles, keyframes, duration, delay, easing, previousPlayers);
|
||||
}
|
||||
}
|
||||
|
||||
function moveNodesAfterSibling(ref: any, nodes: any) {
|
||||
const parent = getDOM().parentElement(ref);
|
||||
if (nodes.length > 0 && parent) {
|
||||
const nextSibling = getDOM().nextSibling(ref);
|
||||
if (nextSibling) {
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
getDOM().insertBefore(parent, nextSibling, nodes[i]);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
getDOM().appendChild(parent, nodes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function appendNodes(parent: any, nodes: any) {
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
getDOM().appendChild(parent, nodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ServerRendererFactoryV2 implements RendererFactoryV2 {
|
||||
private rendererByCompId = new Map<string, RendererV2>();
|
||||
|
@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {PlatformLocation, isPlatformServer} from '@angular/common';
|
||||
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
|
||||
import {ApplicationRef, CompilerFactory, Component, NgModule, NgModuleRef, NgZone, PLATFORM_ID, PlatformRef, destroyPlatform, getPlatform} from '@angular/core';
|
||||
import {TestBed, async, inject} from '@angular/core/testing';
|
||||
import {Http, HttpModule, Response, ResponseOptions, XHRBackend} from '@angular/http';
|
||||
@ -106,25 +105,6 @@ class ImageExampleModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('regular', () => { declareTests({viewEngine: false}); });
|
||||
|
||||
describe('view engine', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureCompiler({
|
||||
useJit: true,
|
||||
providers: [{
|
||||
provide: USE_VIEW_ENGINE,
|
||||
useValue: true,
|
||||
}],
|
||||
});
|
||||
});
|
||||
|
||||
declareTests({viewEngine: true});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function declareTests({viewEngine}: {viewEngine: boolean}) {
|
||||
if (getDOM().supportsDOMEvents()) return; // NODE only
|
||||
|
||||
describe('platform-server integration', () => {
|
||||
|
Reference in New Issue
Block a user