refactor(compiler): minor cleanup

This commit is contained in:
Tobias Bosch 2016-11-03 11:16:28 -07:00 committed by vikerman
parent 648ce5981b
commit e3687706c7
11 changed files with 34 additions and 22 deletions

View File

@ -8,7 +8,7 @@
import {ApplicationRef, NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {ServerModule} from '@angular/platform-server';
import {MdButtonModule} from '@angular2-material/button';
import {ThirdpartyModule} from '../third_party_src/module';
@ -48,7 +48,7 @@ import {CompForChildQuery, CompWithChildQuery, CompWithDirectiveChild, Directive
ComponentUsingThirdParty,
],
imports: [
BrowserModule,
ServerModule,
FormsModule,
MdButtonModule,
ModuleUsingCustomElements,

View File

@ -8,7 +8,6 @@
import {LowerCasePipe, NgIf} from '@angular/common';
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, ModuleWithProviders, NgModule, OpaqueToken, Pipe} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
@Injectable()
export class SomeService {

View File

@ -528,7 +528,8 @@ function generateCreateMethod(view: CompileView): o.Statement[] {
resultExpr = o.NULL_EXPR;
}
let allNodesExpr: o.Expression =
ViewProperties.renderer.prop('directRenderer')
ViewProperties.renderer.cast(o.DYNAMIC_TYPE)
.prop('directRenderer')
.conditional(o.NULL_EXPR, o.literalArr(view.nodes.map(node => node.renderNode)));
return parentRenderNodeStmts.concat(view.createMethod.finish(), [

View File

@ -100,7 +100,7 @@ export function main() {
const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges();
destroyViewLogs.splice(0, destroyViewLogs.length);
destroyViewLogs.length = 0;
fixture.componentInstance.shown = false;
fixture.detectChanges();

View File

@ -55,11 +55,15 @@ export class DomRootRenderer_ extends DomRootRenderer {
}
export const DIRECT_DOM_RENDERER: DirectRenderer = {
remove(node: Text | Comment | Element) { node.remove();},
remove(node: Text | Comment | Element) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
},
appendChild(node: Node, parent: Element) { parent.appendChild(node);},
insertBefore(node: Node, refNode: Node) { refNode.parentElement.insertBefore(node, refNode);},
insertBefore(node: Node, refNode: Node) { refNode.parentNode.insertBefore(node, refNode);},
nextSibling(node: Node) { return node.nextSibling;},
parentElement(node: Node): Element{return node.parentElement;}
parentElement(node: Node): Element{return node.parentNode as Element;}
};
export class DomRenderer implements Renderer {
@ -165,7 +169,10 @@ export class DomRenderer implements Renderer {
detachView(viewRootNodes: (Element|Text|Comment)[]) {
for (let i = 0; i < viewRootNodes.length; i++) {
viewRootNodes[i].remove();
const node = viewRootNodes[i];
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
}
@ -260,7 +267,7 @@ export class DomRenderer implements Renderer {
}
function moveNodesAfterSibling(sibling: Node, nodes: Node[]) {
const parent = sibling.parentElement;
const parent = sibling.parentNode;
if (nodes.length > 0 && parent) {
const nextSibling = sibling.nextSibling;
if (nextSibling) {

View File

@ -7,9 +7,12 @@
*/
import {INTERNAL_SERVER_PLATFORM_PROVIDERS} from './server';
import {INTERNAL_SERVER_PLATFORM_PROVIDERS, SERVER_RENDER_PROVIDERS} from './server';
export var __platform_server_private__:
{INTERNAL_SERVER_PLATFORM_PROVIDERS: typeof INTERNAL_SERVER_PLATFORM_PROVIDERS} = {
INTERNAL_SERVER_PLATFORM_PROVIDERS: INTERNAL_SERVER_PLATFORM_PROVIDERS
};
export var __platform_server_private__: {
INTERNAL_SERVER_PLATFORM_PROVIDERS: typeof INTERNAL_SERVER_PLATFORM_PROVIDERS,
SERVER_RENDER_PROVIDERS: typeof SERVER_RENDER_PROVIDERS,
} = {
INTERNAL_SERVER_PLATFORM_PROVIDERS: INTERNAL_SERVER_PLATFORM_PROVIDERS,
SERVER_RENDER_PROVIDERS: SERVER_RENDER_PROVIDERS,
};

View File

@ -13,7 +13,7 @@ export var DomAdapter: typeof _.DomAdapter = _.DomAdapter;
export var setRootDomAdapter: typeof _.setRootDomAdapter = _.setRootDomAdapter;
export var getDOM: typeof _.getDOM = _.getDOM;
export var SharedStylesHost: typeof _.SharedStylesHost = _.SharedStylesHost;
export type SharedStylesHost = typeof _.SharedStylesHost;
export type SharedStylesHost = typeof _._SharedStylesHost;
export var NAMESPACE_URIS: typeof _.NAMESPACE_URIS = _.NAMESPACE_URIS;
export var shimContentAttribute: typeof _.shimContentAttribute = _.shimContentAttribute;
export var shimHostAttribute: typeof _.shimHostAttribute = _.shimHostAttribute;

View File

@ -8,7 +8,7 @@
import {PlatformLocation} from '@angular/common';
import {platformCoreDynamic} from '@angular/compiler';
import {NgModule, PLATFORM_INITIALIZER, PlatformRef, Provider, RootRenderer, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
import {Injectable, NgModule, PLATFORM_INITIALIZER, PlatformRef, Provider, RootRenderer, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {Parse5DomAdapter} from './parse5_adapter';
@ -53,7 +53,8 @@ export function _createConditionalRootRenderer(rootRenderer: any) {
export const SERVER_RENDER_PROVIDERS: Provider[] = [
ServerRootRenderer,
{provide: RootRenderer, useFactory: _createConditionalRootRenderer, deps: [ServerRootRenderer]},
{provide: SharedStylesHost, useClass: SharedStylesHost},
// use plain SharedStylesHost, not the DomSharedStylesHost
SharedStylesHost
];
/**
@ -61,7 +62,7 @@ export const SERVER_RENDER_PROVIDERS: Provider[] = [
*
* @experimental
*/
@NgModule({imports: [BrowserModule], providers: SERVER_RENDER_PROVIDERS})
@NgModule({exports: [BrowserModule], providers: SERVER_RENDER_PROVIDERS})
export class ServerModule {
}

View File

@ -128,6 +128,8 @@ export class ServerRenderer implements Renderer {
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.
var outsideHandler = (event: any) => this._zone.runGuarded(() => callback(event));
return this._zone.runOutsideAngular(
() => getDOM().onAndCancel(renderElement, name, outsideHandler));

View File

@ -10,3 +10,4 @@ import {__platform_server_private__ as _} from '@angular/platform-server';
export var INTERNAL_SERVER_PLATFORM_PROVIDERS: typeof _.INTERNAL_SERVER_PLATFORM_PROVIDERS =
_.INTERNAL_SERVER_PLATFORM_PROVIDERS;
export var SERVER_RENDER_PROVIDERS: typeof _.SERVER_RENDER_PROVIDERS = _.SERVER_RENDER_PROVIDERS;

View File

@ -10,9 +10,7 @@ import {platformCoreDynamicTesting} from '@angular/compiler/testing';
import {NgModule, PlatformRef, Provider, createPlatformFactory} from '@angular/core';
import {BrowserDynamicTestingModule} from '@angular/platform-browser-dynamic/testing';
import {SERVER_RENDER_PROVIDERS} from '../src/server';
import {INTERNAL_SERVER_PLATFORM_PROVIDERS} from './private_import_platform_server';
import {INTERNAL_SERVER_PLATFORM_PROVIDERS, SERVER_RENDER_PROVIDERS} from './private_import_platform_server';
/**