refactor(core): move `NodeType` and `ProviderType` into `NodeFlags`

Also removes `ng-reflect` attributes for element properties.
This commit is contained in:
Tobias Bosch 2017-02-27 09:14:18 -08:00 committed by Igor Minar
parent f356041f09
commit 14d37fe052
25 changed files with 326 additions and 340 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {ChangeDetectionStrategy, ViewEncapsulation, ɵArgumentType as ArgumentType, ɵBindingType as BindingType, ɵDepFlags as DepFlags, ɵLifecycleHooks as LifecycleHooks, ɵNodeFlags as NodeFlags, ɵProviderType as ProviderType, ɵQueryBindingType as QueryBindingType, ɵQueryValueType as QueryValueType, ɵViewFlags as ViewFlags, ɵelementEventFullName as elementEventFullName} from '@angular/core'; import {ChangeDetectionStrategy, ViewEncapsulation, ɵArgumentType as ArgumentType, ɵBindingType as BindingType, ɵDepFlags as DepFlags, ɵLifecycleHooks as LifecycleHooks, ɵNodeFlags as NodeFlags, ɵQueryBindingType as QueryBindingType, ɵQueryValueType as QueryValueType, ɵViewFlags as ViewFlags, ɵelementEventFullName as elementEventFullName} from '@angular/core';
import {AnimationEntryCompileResult} from '../animation/animation_compiler'; import {AnimationEntryCompileResult} from '../animation/animation_compiler';
import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileDirectiveSummary, CompilePipeSummary, CompileProviderMetadata, CompileTokenMetadata, CompileTypeMetadata, identifierModuleUrl, identifierName, rendererTypeName, tokenReference, viewClassName} from '../compile_metadata'; import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileDirectiveSummary, CompilePipeSummary, CompileProviderMetadata, CompileTokenMetadata, CompileTypeMetadata, identifierModuleUrl, identifierName, rendererTypeName, tokenReference, viewClassName} from '../compile_metadata';
@ -136,11 +136,11 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
// Note: queries start with id 1 so we can use the number in a Bloom filter! // Note: queries start with id 1 so we can use the number in a Bloom filter!
const queryId = queryIndex + 1; const queryId = queryIndex + 1;
const bindingType = query.first ? QueryBindingType.First : QueryBindingType.All; const bindingType = query.first ? QueryBindingType.First : QueryBindingType.All;
let flags = NodeFlags.HasViewQuery; let flags = NodeFlags.TypeViewQuery;
if (queryIds.staticQueryIds.has(queryId)) { if (queryIds.staticQueryIds.has(queryId)) {
flags |= NodeFlags.HasStaticQuery; flags |= NodeFlags.StaticQuery;
} else { } else {
flags |= NodeFlags.HasDynamicQuery; flags |= NodeFlags.DynamicQuery;
} }
this.nodeDefs.push(() => o.importExpr(createIdentifier(Identifiers.queryDef)).callFn([ this.nodeDefs.push(() => o.importExpr(createIdentifier(Identifiers.queryDef)).callFn([
o.literal(flags), o.literal(queryId), o.literal(flags), o.literal(queryId),
@ -359,7 +359,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
} { } {
let flags = NodeFlags.None; let flags = NodeFlags.None;
if (ast.hasViewContainer) { if (ast.hasViewContainer) {
flags |= NodeFlags.HasEmbeddedViews; flags |= NodeFlags.EmbeddedViews;
} }
const usedEvents = new Map<string, [string, string]>(); const usedEvents = new Map<string, [string, string]>();
ast.outputs.forEach((event) => { ast.outputs.forEach((event) => {
@ -450,14 +450,14 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
this.nodeDefs.push(null); this.nodeDefs.push(null);
dirAst.directive.queries.forEach((query, queryIndex) => { dirAst.directive.queries.forEach((query, queryIndex) => {
let flags = NodeFlags.HasContentQuery; let flags = NodeFlags.TypeContentQuery;
const queryId = dirAst.contentQueryStartId + queryIndex; const queryId = dirAst.contentQueryStartId + queryIndex;
// Note: We only make queries static that query for a single item. // Note: We only make queries static that query for a single item.
// This is because of backwards compatibility with the old view compiler... // This is because of backwards compatibility with the old view compiler...
if (queryIds.staticQueryIds.has(queryId) && query.first) { if (queryIds.staticQueryIds.has(queryId) && query.first) {
flags |= NodeFlags.HasStaticQuery; flags |= NodeFlags.StaticQuery;
} else { } else {
flags |= NodeFlags.HasDynamicQuery; flags |= NodeFlags.DynamicQuery;
} }
const bindingType = query.first ? QueryBindingType.First : QueryBindingType.All; const bindingType = query.first ? QueryBindingType.First : QueryBindingType.All;
this.nodeDefs.push(() => o.importExpr(createIdentifier(Identifiers.queryDef)).callFn([ this.nodeDefs.push(() => o.importExpr(createIdentifier(Identifiers.queryDef)).callFn([
@ -472,7 +472,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
// I.e. we only allow queries as children of directives nodes. // I.e. we only allow queries as children of directives nodes.
const childCount = this.nodeDefs.length - nodeIndex - 1; const childCount = this.nodeDefs.length - nodeIndex - 1;
let {flags, queryMatchExprs, providerExpr, providerType, depsExpr} = let {flags, queryMatchExprs, providerExpr, depsExpr} =
this._visitProviderOrDirective(providerAst, queryMatches); this._visitProviderOrDirective(providerAst, queryMatches);
refs.forEach((ref) => { refs.forEach((ref) => {
@ -484,7 +484,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
}); });
if (dirAst.directive.isComponent) { if (dirAst.directive.isComponent) {
flags |= NodeFlags.IsComponent; flags |= NodeFlags.Component;
} }
const inputDefs = dirAst.inputs.map((inputAst, inputIndex) => { const inputDefs = dirAst.inputs.map((inputAst, inputIndex) => {
@ -543,16 +543,15 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
// reserve the space in the nodeDefs array so we can add children // reserve the space in the nodeDefs array so we can add children
this.nodeDefs.push(null); this.nodeDefs.push(null);
const {flags, queryMatchExprs, providerExpr, providerType, depsExpr} = const {flags, queryMatchExprs, providerExpr, depsExpr} =
this._visitProviderOrDirective(providerAst, queryMatches); this._visitProviderOrDirective(providerAst, queryMatches);
// providerDef( // providerDef(
// flags: NodeFlags, matchedQueries: [string, QueryValueType][], type: ProviderType, token: // flags: NodeFlags, matchedQueries: [string, QueryValueType][], token:any,
// any,
// value: any, deps: ([DepFlags, any] | any)[]): NodeDef; // value: any, deps: ([DepFlags, any] | any)[]): NodeDef;
const nodeDef = () => o.importExpr(createIdentifier(Identifiers.providerDef)).callFn([ const nodeDef = () => o.importExpr(createIdentifier(Identifiers.providerDef)).callFn([
o.literal(flags), queryMatchExprs.length ? o.literalArr(queryMatchExprs) : o.NULL_EXPR, o.literal(flags), queryMatchExprs.length ? o.literalArr(queryMatchExprs) : o.NULL_EXPR,
o.literal(providerType), tokenExpr(providerAst.token), providerExpr, depsExpr tokenExpr(providerAst.token), providerExpr, depsExpr
]); ]);
this.nodeDefs[nodeIndex] = nodeDef; this.nodeDefs[nodeIndex] = nodeDef;
} }
@ -561,7 +560,6 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
flags: NodeFlags, flags: NodeFlags,
queryMatchExprs: o.Expression[], queryMatchExprs: o.Expression[],
providerExpr: o.Expression, providerExpr: o.Expression,
providerType: ProviderType,
depsExpr: o.Expression depsExpr: o.Expression
} { } {
let flags = NodeFlags.None; let flags = NodeFlags.None;
@ -587,8 +585,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
o.literalArr([o.literal(match.queryId), o.literal(QueryValueType.Provider)])); o.literalArr([o.literal(match.queryId), o.literal(QueryValueType.Provider)]));
} }
}); });
const {providerExpr, providerType, depsExpr} = providerDef(providerAst); const {providerExpr, depsExpr, flags: providerType} = providerDef(providerAst);
return {flags, queryMatchExprs, providerExpr, providerType, depsExpr}; return {flags: flags | providerType, queryMatchExprs, providerExpr, depsExpr};
} }
getLocal(name: string): o.Expression { getLocal(name: string): o.Expression {
@ -768,13 +766,14 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
} }
function providerDef(providerAst: ProviderAst): function providerDef(providerAst: ProviderAst):
{providerExpr: o.Expression, providerType: ProviderType, depsExpr: o.Expression} { {providerExpr: o.Expression, flags: NodeFlags, depsExpr: o.Expression} {
return providerAst.multiProvider ? multiProviderDef(providerAst.providers) : return providerAst.multiProvider ?
singleProviderDef(providerAst.providers[0]); multiProviderDef(providerAst.providers) :
singleProviderDef(providerAst.providerType, providerAst.providers[0]);
} }
function multiProviderDef(providers: CompileProviderMetadata[]): function multiProviderDef(providers: CompileProviderMetadata[]):
{providerExpr: o.Expression, providerType: ProviderType, depsExpr: o.Expression} { {providerExpr: o.Expression, flags: NodeFlags, depsExpr: o.Expression} {
const allDepDefs: o.Expression[] = []; const allDepDefs: o.Expression[] = [];
const allParams: o.FnParam[] = []; const allParams: o.FnParam[] = [];
const exprs = providers.map((provider, providerIndex) => { const exprs = providers.map((provider, providerIndex) => {
@ -795,7 +794,7 @@ function multiProviderDef(providers: CompileProviderMetadata[]):
}); });
const providerExpr = const providerExpr =
o.fn(allParams, [new o.ReturnStatement(o.literalArr(exprs))], o.INFERRED_TYPE); o.fn(allParams, [new o.ReturnStatement(o.literalArr(exprs))], o.INFERRED_TYPE);
return {providerExpr, providerType: ProviderType.Factory, depsExpr: o.literalArr(allDepDefs)}; return {providerExpr, flags: NodeFlags.TypeFactoryProvider, depsExpr: o.literalArr(allDepDefs)};
function convertDeps(providerIndex: number, deps: CompileDiDependencyMetadata[]) { function convertDeps(providerIndex: number, deps: CompileDiDependencyMetadata[]) {
return deps.map((dep, depIndex) => { return deps.map((dep, depIndex) => {
@ -807,30 +806,36 @@ function multiProviderDef(providers: CompileProviderMetadata[]):
} }
} }
function singleProviderDef(providerMeta: CompileProviderMetadata): function singleProviderDef(providerType: ProviderAstType, providerMeta: CompileProviderMetadata):
{providerExpr: o.Expression, providerType: ProviderType, depsExpr: o.Expression} { {providerExpr: o.Expression, flags: NodeFlags, depsExpr: o.Expression} {
let providerExpr: o.Expression; let providerExpr: o.Expression;
let providerType: ProviderType; let flags: NodeFlags;
let deps: CompileDiDependencyMetadata[]; let deps: CompileDiDependencyMetadata[];
if (providerMeta.useClass) { if (providerType === ProviderAstType.Directive || providerType === ProviderAstType.Component) {
providerExpr = o.importExpr(providerMeta.useClass); providerExpr = o.importExpr(providerMeta.useClass);
providerType = ProviderType.Class; flags = NodeFlags.TypeDirective;
deps = providerMeta.deps || providerMeta.useClass.diDeps; deps = providerMeta.deps || providerMeta.useClass.diDeps;
} else if (providerMeta.useFactory) {
providerExpr = o.importExpr(providerMeta.useFactory);
providerType = ProviderType.Factory;
deps = providerMeta.deps || providerMeta.useFactory.diDeps;
} else if (providerMeta.useExisting) {
providerExpr = o.NULL_EXPR;
providerType = ProviderType.UseExisting;
deps = [{token: providerMeta.useExisting}];
} else { } else {
providerExpr = convertValueToOutputAst(providerMeta.useValue); if (providerMeta.useClass) {
providerType = ProviderType.Value; providerExpr = o.importExpr(providerMeta.useClass);
deps = []; flags = NodeFlags.TypeClassProvider;
deps = providerMeta.deps || providerMeta.useClass.diDeps;
} else if (providerMeta.useFactory) {
providerExpr = o.importExpr(providerMeta.useFactory);
flags = NodeFlags.TypeFactoryProvider;
deps = providerMeta.deps || providerMeta.useFactory.diDeps;
} else if (providerMeta.useExisting) {
providerExpr = o.NULL_EXPR;
flags = NodeFlags.TypeUseExistingProvider;
deps = [{token: providerMeta.useExisting}];
} else {
providerExpr = convertValueToOutputAst(providerMeta.useValue);
flags = NodeFlags.TypeValueProvider;
deps = [];
}
} }
const depsExpr = o.literalArr(deps.map(dep => depDef(dep))); const depsExpr = o.literalArr(deps.map(dep => depDef(dep)));
return {providerExpr, providerType, depsExpr}; return {providerExpr, flags, depsExpr};
} }
function tokenExpr(tokenMeta: CompileTokenMetadata): o.Expression { function tokenExpr(tokenMeta: CompileTokenMetadata): o.Expression {

View File

@ -26,4 +26,4 @@ export {ViewContainer as ɵViewContainer} from './linker/view_container';
export {ViewType as ɵViewType} from './linker/view_type'; export {ViewType as ɵViewType} from './linker/view_type';
export {EMPTY_ARRAY as ɵEMPTY_ARRAY, EMPTY_INLINE_ARRAY as ɵEMPTY_INLINE_ARRAY, EMPTY_MAP as ɵEMPTY_MAP, InlineArray16 as ɵInlineArray16, InlineArray2 as ɵInlineArray2, InlineArray4 as ɵInlineArray4, InlineArray8 as ɵInlineArray8, InlineArrayDynamic as ɵInlineArrayDynamic, ViewUtils as ɵViewUtils, castByValue as ɵcastByValue, checkBinding as ɵcheckBinding, checkBindingChange as ɵcheckBindingChange, checkRenderAttribute as ɵcheckRenderAttribute, checkRenderClass as ɵcheckRenderClass, checkRenderProperty as ɵcheckRenderProperty, checkRenderStyle as ɵcheckRenderStyle, checkRenderText as ɵcheckRenderText, createRenderComponentType as ɵcreateRenderComponentType, createRenderElement as ɵcreateRenderElement, getComponentFactoryViewClass as ɵgetComponentFactoryViewClass, inlineInterpolate as ɵinlineInterpolate, interpolate as ɵinterpolate, noop as ɵnoop, pureProxy1 as ɵpureProxy1, pureProxy10 as ɵpureProxy10, pureProxy2 as ɵpureProxy2, pureProxy3 as ɵpureProxy3, pureProxy4 as ɵpureProxy4, pureProxy5 as ɵpureProxy5, pureProxy6 as ɵpureProxy6, pureProxy7 as ɵpureProxy7, pureProxy8 as ɵpureProxy8, pureProxy9 as ɵpureProxy9, selectOrCreateRenderHostElement as ɵselectOrCreateRenderHostElement, setBindingDebugInfo as ɵsetBindingDebugInfo, setBindingDebugInfoForChanges as ɵsetBindingDebugInfoForChanges, subscribeToRenderElement as ɵsubscribeToRenderElement} from './linker/view_utils'; export {EMPTY_ARRAY as ɵEMPTY_ARRAY, EMPTY_INLINE_ARRAY as ɵEMPTY_INLINE_ARRAY, EMPTY_MAP as ɵEMPTY_MAP, InlineArray16 as ɵInlineArray16, InlineArray2 as ɵInlineArray2, InlineArray4 as ɵInlineArray4, InlineArray8 as ɵInlineArray8, InlineArrayDynamic as ɵInlineArrayDynamic, ViewUtils as ɵViewUtils, castByValue as ɵcastByValue, checkBinding as ɵcheckBinding, checkBindingChange as ɵcheckBindingChange, checkRenderAttribute as ɵcheckRenderAttribute, checkRenderClass as ɵcheckRenderClass, checkRenderProperty as ɵcheckRenderProperty, checkRenderStyle as ɵcheckRenderStyle, checkRenderText as ɵcheckRenderText, createRenderComponentType as ɵcreateRenderComponentType, createRenderElement as ɵcreateRenderElement, getComponentFactoryViewClass as ɵgetComponentFactoryViewClass, inlineInterpolate as ɵinlineInterpolate, interpolate as ɵinterpolate, noop as ɵnoop, pureProxy1 as ɵpureProxy1, pureProxy10 as ɵpureProxy10, pureProxy2 as ɵpureProxy2, pureProxy3 as ɵpureProxy3, pureProxy4 as ɵpureProxy4, pureProxy5 as ɵpureProxy5, pureProxy6 as ɵpureProxy6, pureProxy7 as ɵpureProxy7, pureProxy8 as ɵpureProxy8, pureProxy9 as ɵpureProxy9, selectOrCreateRenderHostElement as ɵselectOrCreateRenderHostElement, setBindingDebugInfo as ɵsetBindingDebugInfo, setBindingDebugInfoForChanges as ɵsetBindingDebugInfoForChanges, subscribeToRenderElement as ɵsubscribeToRenderElement} from './linker/view_utils';
export {reflector as ɵreflector} from './reflection/reflection'; export {reflector as ɵreflector} from './reflection/reflection';
export {ArgumentType as ɵArgumentType, BindingType as ɵBindingType, DepFlags as ɵDepFlags, NodeFlags as ɵNodeFlags, ProviderType as ɵProviderType, QueryBindingType as ɵQueryBindingType, QueryValueType as ɵQueryValueType, ViewDefinition as ɵViewDefinition, ViewFlags as ɵViewFlags, anchorDef as ɵanchorDef, createComponentFactory as ɵcreateComponentFactory, createRendererTypeV2 as ɵcreateRendererTypeV2, directiveDef as ɵdirectiveDef, elementDef as ɵelementDef, elementEventFullName as ɵelementEventFullName, ngContentDef as ɵngContentDef, nodeValue as ɵnodeValue, pipeDef as ɵpipeDef, providerDef as ɵproviderDef, pureArrayDef as ɵpureArrayDef, pureObjectDef as ɵpureObjectDef, purePipeDef as ɵpurePipeDef, queryDef as ɵqueryDef, textDef as ɵtextDef, unwrapValue as ɵunwrapValue, viewDef as ɵviewDef} from './view/index'; export {ArgumentType as ɵArgumentType, BindingType as ɵBindingType, DepFlags as ɵDepFlags, NodeFlags as ɵNodeFlags, QueryBindingType as ɵQueryBindingType, QueryValueType as ɵQueryValueType, ViewDefinition as ɵViewDefinition, ViewFlags as ɵViewFlags, anchorDef as ɵanchorDef, createComponentFactory as ɵcreateComponentFactory, createRendererTypeV2 as ɵcreateRendererTypeV2, directiveDef as ɵdirectiveDef, elementDef as ɵelementDef, elementEventFullName as ɵelementEventFullName, ngContentDef as ɵngContentDef, nodeValue as ɵnodeValue, pipeDef as ɵpipeDef, providerDef as ɵproviderDef, pureArrayDef as ɵpureArrayDef, pureObjectDef as ɵpureObjectDef, purePipeDef as ɵpurePipeDef, queryDef as ɵqueryDef, textDef as ɵtextDef, unwrapValue as ɵunwrapValue, viewDef as ɵviewDef} from './view/index';

View File

@ -10,7 +10,7 @@ import {isDevMode} from '../application_ref';
import {RendererTypeV2, RendererV2} from '../render/api'; import {RendererTypeV2, RendererV2} from '../render/api';
import {SecurityContext} from '../security'; import {SecurityContext} from '../security';
import {BindingDef, BindingType, DebugContext, DisposableFn, ElementData, ElementHandleEventFn, NodeData, NodeDef, NodeFlags, NodeType, OutputDef, OutputType, QueryValueType, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, asElementData, asProviderData} from './types'; import {BindingDef, BindingType, DebugContext, DisposableFn, ElementData, ElementHandleEventFn, NodeData, NodeDef, NodeFlags, OutputDef, OutputType, QueryValueType, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, asElementData, asProviderData} from './types';
import {checkAndUpdateBinding, dispatchEvent, elementEventFullName, filterQueryId, getParentRenderElement, resolveViewDefinition, sliceErrorStack, splitMatchedQueriesDsl, splitNamespace} from './util'; import {checkAndUpdateBinding, dispatchEvent, elementEventFullName, filterQueryId, getParentRenderElement, resolveViewDefinition, sliceErrorStack, splitMatchedQueriesDsl, splitNamespace} from './util';
const NOOP: any = () => {}; const NOOP: any = () => {};
@ -22,13 +22,13 @@ export function anchorDef(
if (!handleEvent) { if (!handleEvent) {
handleEvent = NOOP; handleEvent = NOOP;
} }
flags |= NodeFlags.TypeElement;
const {matchedQueries, references, matchedQueryIds} = splitMatchedQueriesDsl(matchedQueriesDsl); const {matchedQueries, references, matchedQueryIds} = splitMatchedQueriesDsl(matchedQueriesDsl);
// skip the call to sliceErrorStack itself + the call to this function. // skip the call to sliceErrorStack itself + the call to this function.
const source = isDevMode() ? sliceErrorStack(2, 3) : ''; const source = isDevMode() ? sliceErrorStack(2, 3) : '';
const template = templateFactory ? resolveViewDefinition(templateFactory) : null; const template = templateFactory ? resolveViewDefinition(templateFactory) : null;
return { return {
type: NodeType.Element,
// will bet set by the view definition // will bet set by the view definition
index: undefined, index: undefined,
reverseChildIndex: undefined, reverseChildIndex: undefined,
@ -54,7 +54,6 @@ export function anchorDef(
}, },
provider: undefined, provider: undefined,
text: undefined, text: undefined,
pureExpression: undefined,
query: undefined, query: undefined,
ngContent: undefined ngContent: undefined
}; };
@ -126,10 +125,10 @@ export function elementDef(
componentRendererType = null; componentRendererType = null;
} }
if (componentView) { if (componentView) {
flags |= NodeFlags.HasComponent; flags |= NodeFlags.ComponentView;
} }
flags |= NodeFlags.TypeElement;
return { return {
type: NodeType.Element,
// will bet set by the view definition // will bet set by the view definition
index: undefined, index: undefined,
reverseChildIndex: undefined, reverseChildIndex: undefined,
@ -156,7 +155,6 @@ export function elementDef(
}, },
provider: undefined, provider: undefined,
text: undefined, text: undefined,
pureExpression: undefined,
query: undefined, query: undefined,
ngContent: undefined ngContent: undefined
}; };

View File

@ -6,12 +6,11 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {NodeDef, NodeType, ViewData, asElementData} from './types'; import {NodeDef, NodeFlags, ViewData, asElementData} from './types';
import {RenderNodeAction, getParentRenderElement, visitProjectedRenderNodes} from './util'; import {RenderNodeAction, getParentRenderElement, visitProjectedRenderNodes} from './util';
export function ngContentDef(ngContentIndex: number, index: number): NodeDef { export function ngContentDef(ngContentIndex: number, index: number): NodeDef {
return { return {
type: NodeType.NgContent,
// will bet set by the view definition // will bet set by the view definition
index: undefined, index: undefined,
reverseChildIndex: undefined, reverseChildIndex: undefined,
@ -20,7 +19,7 @@ export function ngContentDef(ngContentIndex: number, index: number): NodeDef {
bindingIndex: undefined, bindingIndex: undefined,
outputIndex: undefined, outputIndex: undefined,
// regular values // regular values
flags: 0, flags: NodeFlags.TypeNgContent,
childFlags: 0, childFlags: 0,
childMatchedQueries: 0, childMatchedQueries: 0,
matchedQueries: {}, matchedQueries: {},
@ -32,7 +31,6 @@ export function ngContentDef(ngContentIndex: number, index: number): NodeDef {
element: undefined, element: undefined,
provider: undefined, provider: undefined,
text: undefined, text: undefined,
pureExpression: undefined,
query: undefined, query: undefined,
ngContent: {index} ngContent: {index}
}; };

View File

@ -15,7 +15,7 @@ import {ViewEncapsulation} from '../metadata/view';
import {Renderer as RendererV1, RendererFactoryV2, RendererTypeV2, RendererV2} from '../render/api'; import {Renderer as RendererV1, RendererFactoryV2, RendererTypeV2, RendererV2} from '../render/api';
import {createChangeDetectorRef, createInjector, createRendererV1, createTemplateRef, createViewContainerRef} from './refs'; import {createChangeDetectorRef, createInjector, createRendererV1, createTemplateRef, createViewContainerRef} from './refs';
import {BindingDef, BindingType, DepDef, DepFlags, DisposableFn, NodeData, NodeDef, NodeFlags, NodeType, OutputDef, OutputType, ProviderData, ProviderType, QueryBindingType, QueryDef, QueryValueType, RootData, Services, ViewData, ViewDefinition, ViewFlags, ViewState, asElementData, asProviderData} from './types'; import {BindingDef, BindingType, DepDef, DepFlags, DisposableFn, NodeData, NodeDef, NodeFlags, OutputDef, OutputType, ProviderData, QueryBindingType, QueryDef, QueryValueType, RootData, Services, ViewData, ViewDefinition, ViewFlags, ViewState, asElementData, asProviderData} from './types';
import {checkBinding, dispatchEvent, filterQueryId, isComponentView, splitMatchedQueriesDsl, tokenKey, viewParentEl} from './util'; import {checkBinding, dispatchEvent, filterQueryId, isComponentView, splitMatchedQueriesDsl, tokenKey, viewParentEl} from './util';
const RendererV1TokenKey = tokenKey(RendererV1); const RendererV1TokenKey = tokenKey(RendererV1);
@ -52,25 +52,25 @@ export function directiveDef(
{type: OutputType.DirectiveOutput, propName, target: null, eventName: outputs[propName]}); {type: OutputType.DirectiveOutput, propName, target: null, eventName: outputs[propName]});
} }
} }
return _def( flags |= NodeFlags.TypeDirective;
NodeType.Directive, flags, matchedQueries, childCount, ProviderType.Class, ctor, ctor, deps, return _def(flags, matchedQueries, childCount, ctor, ctor, deps, bindings, outputDefs);
bindings, outputDefs);
} }
export function pipeDef(flags: NodeFlags, ctor: any, deps: ([DepFlags, any] | any)[]): NodeDef { export function pipeDef(flags: NodeFlags, ctor: any, deps: ([DepFlags, any] | any)[]): NodeDef {
return _def(NodeType.Pipe, flags, null, 0, ProviderType.Class, ctor, ctor, deps); flags |= NodeFlags.TypePipe;
return _def(flags, null, 0, ctor, ctor, deps);
} }
export function providerDef( export function providerDef(
flags: NodeFlags, matchedQueries: [string | number, QueryValueType][], type: ProviderType, flags: NodeFlags, matchedQueries: [string | number, QueryValueType][], token: any, value: any,
token: any, value: any, deps: ([DepFlags, any] | any)[]): NodeDef { deps: ([DepFlags, any] | any)[]): NodeDef {
return _def(NodeType.Provider, flags, matchedQueries, 0, type, token, value, deps); return _def(flags, matchedQueries, 0, token, value, deps);
} }
export function _def( export function _def(
type: NodeType, flags: NodeFlags, matchedQueriesDsl: [string | number, QueryValueType][], flags: NodeFlags, matchedQueriesDsl: [string | number, QueryValueType][], childCount: number,
childCount: number, providerType: ProviderType, token: any, value: any, token: any, value: any, deps: ([DepFlags, any] | any)[], bindings?: BindingDef[],
deps: ([DepFlags, any] | any)[], bindings?: BindingDef[], outputs?: OutputDef[]): NodeDef { outputs?: OutputDef[]): NodeDef {
const {matchedQueries, references, matchedQueryIds} = splitMatchedQueriesDsl(matchedQueriesDsl); const {matchedQueries, references, matchedQueryIds} = splitMatchedQueriesDsl(matchedQueriesDsl);
if (!outputs) { if (!outputs) {
outputs = []; outputs = [];
@ -92,7 +92,6 @@ export function _def(
}); });
return { return {
type,
// will bet set by the view definition // will bet set by the view definition
index: undefined, index: undefined,
reverseChildIndex: undefined, reverseChildIndex: undefined,
@ -106,9 +105,8 @@ export function _def(
childMatchedQueries: 0, matchedQueries, matchedQueryIds, references, childMatchedQueries: 0, matchedQueries, matchedQueryIds, references,
ngContentIndex: undefined, childCount, bindings, outputs, ngContentIndex: undefined, childCount, bindings, outputs,
element: undefined, element: undefined,
provider: {type: providerType, token, tokenKey: tokenKey(token), value, deps: depDefs}, provider: {token, tokenKey: tokenKey(token), value, deps: depDefs},
text: undefined, text: undefined,
pureExpression: undefined,
query: undefined, query: undefined,
ngContent: undefined ngContent: undefined
}; };
@ -134,7 +132,7 @@ export function createPipeInstance(view: ViewData, def: NodeDef): any {
export function createDirectiveInstance(view: ViewData, def: NodeDef): any { export function createDirectiveInstance(view: ViewData, def: NodeDef): any {
// components can see other private services, other directives can't. // components can see other private services, other directives can't.
const allowPrivateServices = (def.flags & NodeFlags.IsComponent) > 0; const allowPrivateServices = (def.flags & NodeFlags.Component) > 0;
const providerDef = def.provider; const providerDef = def.provider;
// directives are always eager and classes! // directives are always eager and classes!
const instance = const instance =
@ -243,19 +241,19 @@ function _createProviderInstance(view: ViewData, def: NodeDef): any {
const allowPrivateServices = (def.flags & NodeFlags.PrivateProvider) > 0; const allowPrivateServices = (def.flags & NodeFlags.PrivateProvider) > 0;
const providerDef = def.provider; const providerDef = def.provider;
let injectable: any; let injectable: any;
switch (providerDef.type) { switch (def.flags & NodeFlags.Types) {
case ProviderType.Class: case NodeFlags.TypeClassProvider:
injectable = injectable =
createClass(view, def.parent, allowPrivateServices, providerDef.value, providerDef.deps); createClass(view, def.parent, allowPrivateServices, providerDef.value, providerDef.deps);
break; break;
case ProviderType.Factory: case NodeFlags.TypeFactoryProvider:
injectable = injectable =
callFactory(view, def.parent, allowPrivateServices, providerDef.value, providerDef.deps); callFactory(view, def.parent, allowPrivateServices, providerDef.value, providerDef.deps);
break; break;
case ProviderType.UseExisting: case NodeFlags.TypeUseExistingProvider:
injectable = resolveDep(view, def.parent, allowPrivateServices, providerDef.deps[0]); injectable = resolveDep(view, def.parent, allowPrivateServices, providerDef.deps[0]);
break; break;
case ProviderType.Value: case NodeFlags.TypeValueProvider:
injectable = providerDef.value; injectable = providerDef.value;
break; break;
} }
@ -407,7 +405,7 @@ function findCompView(view: ViewData, elDef: NodeDef, allowPrivateServices: bool
function updateProp( function updateProp(
view: ViewData, providerData: ProviderData, def: NodeDef, bindingIdx: number, value: any, view: ViewData, providerData: ProviderData, def: NodeDef, bindingIdx: number, value: any,
changes: SimpleChanges): SimpleChanges { changes: SimpleChanges): SimpleChanges {
if (def.flags & NodeFlags.IsComponent) { if (def.flags & NodeFlags.Component) {
const compView = asElementData(view, def.parent.index).componentView; const compView = asElementData(view, def.parent.index).componentView;
if (compView.def.flags & ViewFlags.OnPush) { if (compView.def.flags & ViewFlags.OnPush) {
compView.state |= ViewState.ChecksEnabled; compView.state |= ViewState.ChecksEnabled;

View File

@ -6,23 +6,23 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {BindingDef, BindingType, DepDef, DepFlags, NodeData, NodeDef, NodeType, ProviderData, PureExpressionData, PureExpressionType, Services, ViewData, asPureExpressionData} from './types'; import {BindingDef, BindingType, DepDef, DepFlags, NodeData, NodeDef, NodeFlags, ProviderData, PureExpressionData, Services, ViewData, asPureExpressionData} from './types';
import {checkAndUpdateBinding, tokenKey} from './util'; import {checkAndUpdateBinding, tokenKey} from './util';
export function purePipeDef(argCount: number): NodeDef { export function purePipeDef(argCount: number): NodeDef {
// argCount + 1 to include the pipe as first arg // argCount + 1 to include the pipe as first arg
return _pureExpressionDef(PureExpressionType.Pipe, new Array(argCount + 1)); return _pureExpressionDef(NodeFlags.TypePurePipe, new Array(argCount + 1));
} }
export function pureArrayDef(argCount: number): NodeDef { export function pureArrayDef(argCount: number): NodeDef {
return _pureExpressionDef(PureExpressionType.Array, new Array(argCount)); return _pureExpressionDef(NodeFlags.TypePureArray, new Array(argCount));
} }
export function pureObjectDef(propertyNames: string[]): NodeDef { export function pureObjectDef(propertyNames: string[]): NodeDef {
return _pureExpressionDef(PureExpressionType.Object, propertyNames); return _pureExpressionDef(NodeFlags.TypePureObject, propertyNames);
} }
function _pureExpressionDef(type: PureExpressionType, propertyNames: string[]): NodeDef { function _pureExpressionDef(flags: NodeFlags, propertyNames: string[]): NodeDef {
const bindings: BindingDef[] = new Array(propertyNames.length); const bindings: BindingDef[] = new Array(propertyNames.length);
for (let i = 0; i < propertyNames.length; i++) { for (let i = 0; i < propertyNames.length; i++) {
const prop = propertyNames[i]; const prop = propertyNames[i];
@ -36,7 +36,6 @@ function _pureExpressionDef(type: PureExpressionType, propertyNames: string[]):
}; };
} }
return { return {
type: NodeType.PureExpression,
// will bet set by the view definition // will bet set by the view definition
index: undefined, index: undefined,
reverseChildIndex: undefined, reverseChildIndex: undefined,
@ -45,7 +44,7 @@ function _pureExpressionDef(type: PureExpressionType, propertyNames: string[]):
bindingIndex: undefined, bindingIndex: undefined,
outputIndex: undefined, outputIndex: undefined,
// regular values // regular values
flags: 0, flags,
childFlags: 0, childFlags: 0,
childMatchedQueries: 0, childMatchedQueries: 0,
matchedQueries: {}, matchedQueries: {},
@ -57,7 +56,6 @@ function _pureExpressionDef(type: PureExpressionType, propertyNames: string[]):
element: undefined, element: undefined,
provider: undefined, provider: undefined,
text: undefined, text: undefined,
pureExpression: {type},
query: undefined, query: undefined,
ngContent: undefined ngContent: undefined
}; };
@ -87,8 +85,8 @@ export function checkAndUpdatePureExpressionInline(
if (changed) { if (changed) {
const data = asPureExpressionData(view, def.index); const data = asPureExpressionData(view, def.index);
let value: any; let value: any;
switch (def.pureExpression.type) { switch (def.flags & NodeFlags.Types) {
case PureExpressionType.Array: case NodeFlags.TypePureArray:
value = new Array(bindings.length); value = new Array(bindings.length);
if (bindLen > 0) value[0] = v0; if (bindLen > 0) value[0] = v0;
if (bindLen > 1) value[1] = v1; if (bindLen > 1) value[1] = v1;
@ -101,7 +99,7 @@ export function checkAndUpdatePureExpressionInline(
if (bindLen > 8) value[8] = v8; if (bindLen > 8) value[8] = v8;
if (bindLen > 9) value[9] = v9; if (bindLen > 9) value[9] = v9;
break; break;
case PureExpressionType.Object: case NodeFlags.TypePureObject:
value = {}; value = {};
if (bindLen > 0) value[bindings[0].name] = v0; if (bindLen > 0) value[bindings[0].name] = v0;
if (bindLen > 1) value[bindings[1].name] = v1; if (bindLen > 1) value[bindings[1].name] = v1;
@ -114,7 +112,7 @@ export function checkAndUpdatePureExpressionInline(
if (bindLen > 8) value[bindings[8].name] = v8; if (bindLen > 8) value[bindings[8].name] = v8;
if (bindLen > 9) value[bindings[9].name] = v9; if (bindLen > 9) value[bindings[9].name] = v9;
break; break;
case PureExpressionType.Pipe: case NodeFlags.TypePurePipe:
const pipe = v0; const pipe = v0;
switch (bindLen) { switch (bindLen) {
case 1: case 1:
@ -169,17 +167,17 @@ export function checkAndUpdatePureExpressionDynamic(
if (changed) { if (changed) {
const data = asPureExpressionData(view, def.index); const data = asPureExpressionData(view, def.index);
let value: any; let value: any;
switch (def.pureExpression.type) { switch (def.flags & NodeFlags.Types) {
case PureExpressionType.Array: case NodeFlags.TypePureArray:
value = values; value = values;
break; break;
case PureExpressionType.Object: case NodeFlags.TypePureObject:
value = {}; value = {};
for (let i = 0; i < values.length; i++) { for (let i = 0; i < values.length; i++) {
value[bindings[i].name] = values[i]; value[bindings[i].name] = values[i];
} }
break; break;
case PureExpressionType.Pipe: case NodeFlags.TypePurePipe:
const pipe = values[0]; const pipe = values[0];
const params = values.slice(1); const params = values.slice(1);
value = (<any>pipe.transform)(...params); value = (<any>pipe.transform)(...params);

View File

@ -12,7 +12,7 @@ import {TemplateRef} from '../linker/template_ref';
import {ViewContainerRef} from '../linker/view_container_ref'; import {ViewContainerRef} from '../linker/view_container_ref';
import {createTemplateRef, createViewContainerRef} from './refs'; import {createTemplateRef, createViewContainerRef} from './refs';
import {NodeDef, NodeFlags, NodeType, QueryBindingDef, QueryBindingType, QueryDef, QueryValueType, Services, ViewData, asElementData, asProviderData, asQueryList} from './types'; import {NodeDef, NodeFlags, QueryBindingDef, QueryBindingType, QueryDef, QueryValueType, Services, ViewData, asElementData, asProviderData, asQueryList} from './types';
import {declaredViewContainer, filterQueryId, isEmbeddedView, viewParentEl} from './util'; import {declaredViewContainer, filterQueryId, isEmbeddedView, viewParentEl} from './util';
export function queryDef( export function queryDef(
@ -24,7 +24,6 @@ export function queryDef(
} }
return { return {
type: NodeType.Query,
// will bet set by the view definition // will bet set by the view definition
index: undefined, index: undefined,
reverseChildIndex: undefined, reverseChildIndex: undefined,
@ -46,7 +45,6 @@ export function queryDef(
element: undefined, element: undefined,
provider: undefined, provider: undefined,
text: undefined, text: undefined,
pureExpression: undefined,
query: {id, filterId: filterQueryId(id), bindings: bindingDefs}, query: {id, filterId: filterQueryId(id), bindings: bindingDefs},
ngContent: undefined ngContent: undefined
}; };
@ -65,14 +63,14 @@ export function dirtyParentQueries(view: ViewData) {
const end = tplDef.index + tplDef.childCount; const end = tplDef.index + tplDef.childCount;
for (let i = 0; i <= end; i++) { for (let i = 0; i <= end; i++) {
const nodeDef = view.def.nodes[i]; const nodeDef = view.def.nodes[i];
if ((nodeDef.flags & NodeFlags.HasContentQuery) && if ((nodeDef.flags & NodeFlags.TypeContentQuery) &&
(nodeDef.flags & NodeFlags.HasDynamicQuery) && (nodeDef.flags & NodeFlags.DynamicQuery) &&
(nodeDef.query.filterId & queryIds) === nodeDef.query.filterId) { (nodeDef.query.filterId & queryIds) === nodeDef.query.filterId) {
asQueryList(view, i).setDirty(); asQueryList(view, i).setDirty();
} }
if ((nodeDef.type === NodeType.Element && i + nodeDef.childCount < tplDef.index) || if ((nodeDef.flags & NodeFlags.TypeElement && i + nodeDef.childCount < tplDef.index) ||
!(nodeDef.childFlags & NodeFlags.HasContentQuery) || !(nodeDef.childFlags & NodeFlags.TypeContentQuery) ||
!(nodeDef.childFlags & NodeFlags.HasDynamicQuery)) { !(nodeDef.childFlags & NodeFlags.DynamicQuery)) {
// skip elements that don't contain the template element or no query. // skip elements that don't contain the template element or no query.
i += nodeDef.childCount; i += nodeDef.childCount;
} }
@ -80,10 +78,10 @@ export function dirtyParentQueries(view: ViewData) {
} }
// view queries // view queries
if (view.def.nodeFlags & NodeFlags.HasViewQuery) { if (view.def.nodeFlags & NodeFlags.TypeViewQuery) {
for (let i = 0; i < view.def.nodes.length; i++) { for (let i = 0; i < view.def.nodes.length; i++) {
const nodeDef = view.def.nodes[i]; const nodeDef = view.def.nodes[i];
if ((nodeDef.flags & NodeFlags.HasViewQuery) && (nodeDef.flags & NodeFlags.HasDynamicQuery)) { if ((nodeDef.flags & NodeFlags.TypeViewQuery) && (nodeDef.flags & NodeFlags.DynamicQuery)) {
asQueryList(view, i).setDirty(); asQueryList(view, i).setDirty();
} }
// only visit the root nodes // only visit the root nodes
@ -99,12 +97,12 @@ export function checkAndUpdateQuery(view: ViewData, nodeDef: NodeDef) {
} }
let directiveInstance: any; let directiveInstance: any;
let newValues: any[]; let newValues: any[];
if (nodeDef.flags & NodeFlags.HasContentQuery) { if (nodeDef.flags & NodeFlags.TypeContentQuery) {
const elementDef = nodeDef.parent.parent; const elementDef = nodeDef.parent.parent;
newValues = calcQueryValues( newValues = calcQueryValues(
view, elementDef.index, elementDef.index + elementDef.childCount, nodeDef.query, []); view, elementDef.index, elementDef.index + elementDef.childCount, nodeDef.query, []);
directiveInstance = asProviderData(view, nodeDef.parent.index).instance; directiveInstance = asProviderData(view, nodeDef.parent.index).instance;
} else if (nodeDef.flags & NodeFlags.HasViewQuery) { } else if (nodeDef.flags & NodeFlags.TypeViewQuery) {
newValues = calcQueryValues(view, 0, view.def.nodes.length - 1, nodeDef.query, []); newValues = calcQueryValues(view, 0, view.def.nodes.length - 1, nodeDef.query, []);
directiveInstance = view.component; directiveInstance = view.component;
} }
@ -139,7 +137,7 @@ function calcQueryValues(
if (valueType != null) { if (valueType != null) {
values.push(getQueryValue(view, nodeDef, valueType)); values.push(getQueryValue(view, nodeDef, valueType));
} }
if (nodeDef.type === NodeType.Element && nodeDef.element.template && if (nodeDef.flags & NodeFlags.TypeElement && nodeDef.element.template &&
(nodeDef.element.template.nodeMatchedQueries & queryDef.filterId) === queryDef.filterId) { (nodeDef.element.template.nodeMatchedQueries & queryDef.filterId) === queryDef.filterId) {
// check embedded views that were attached at the place of their template. // check embedded views that were attached at the place of their template.
const elementData = asElementData(view, i); const elementData = asElementData(view, i);

View File

@ -19,7 +19,7 @@ import {Renderer as RendererV1, RendererV2} from '../render/api';
import {Type} from '../type'; import {Type} from '../type';
import {VERSION} from '../version'; import {VERSION} from '../version';
import {ArgumentType, BindingType, DebugContext, DepFlags, ElementData, NodeCheckFn, NodeData, NodeDef, NodeFlags, NodeType, RootData, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewState, asElementData, asProviderData, asTextData} from './types'; import {ArgumentType, BindingType, DebugContext, DepFlags, ElementData, NodeCheckFn, NodeData, NodeDef, NodeFlags, RootData, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewState, asElementData, asProviderData, asTextData} from './types';
import {isComponentView, markParentViewsForCheck, renderNode, resolveViewDefinition, rootRenderNodes, splitNamespace, tokenKey, viewParentEl} from './util'; import {isComponentView, markParentViewsForCheck, renderNode, resolveViewDefinition, rootRenderNodes, splitNamespace, tokenKey, viewParentEl} from './util';
import {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView, renderDetachView} from './view_attach'; import {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView, renderDetachView} from './view_attach';
@ -251,7 +251,7 @@ export function createInjector(view: ViewData, elDef: NodeDef): Injector {
class Injector_ implements Injector { class Injector_ implements Injector {
constructor(private view: ViewData, private elDef: NodeDef) {} constructor(private view: ViewData, private elDef: NodeDef) {}
get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND): any { get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND): any {
const allowPrivateServices = (this.elDef.flags & NodeFlags.HasComponent) !== 0; const allowPrivateServices = (this.elDef.flags & NodeFlags.ComponentView) !== 0;
return Services.resolveDep( return Services.resolveDep(
this.view, this.elDef, allowPrivateServices, this.view, this.elDef, allowPrivateServices,
{flags: DepFlags.None, token, tokenKey: tokenKey(token)}, notFoundValue); {flags: DepFlags.None, token, tokenKey: tokenKey(token)}, notFoundValue);
@ -260,21 +260,18 @@ class Injector_ implements Injector {
export function nodeValue(view: ViewData, index: number): any { export function nodeValue(view: ViewData, index: number): any {
const def = view.def.nodes[index]; const def = view.def.nodes[index];
switch (def.type) { if (def.flags & NodeFlags.TypeElement) {
case NodeType.Element: if (def.element.template) {
if (def.element.template) { return createTemplateRef(view, def);
return createTemplateRef(view, def); } else {
} else { return asElementData(view, def.index).renderElement;
return asElementData(view, def.index).renderElement; }
} } else if (def.flags & NodeFlags.TypeText) {
case NodeType.Text: return asTextData(view, def.index).renderText;
return asTextData(view, def.index).renderText; } else if (def.flags & (NodeFlags.CatProvider | NodeFlags.TypePipe)) {
case NodeType.Directive: return asProviderData(view, def.index).instance;
case NodeType.Pipe:
case NodeType.Provider:
return asProviderData(view, def.index).instance;
} }
return undefined; throw new Error(`Illegal state: read nodeValue for node index ${index}`);
} }
export function createRendererV1(view: ViewData): RendererV1 { export function createRendererV1(view: ViewData): RendererV1 {

View File

@ -16,7 +16,7 @@ import {isViewDebugError, viewDestroyedError, viewWrappedDebugError} from './err
import {resolveDep} from './provider'; import {resolveDep} from './provider';
import {dirtyParentQueries, getQueryValue} from './query'; import {dirtyParentQueries, getQueryValue} from './query';
import {createInjector} from './refs'; import {createInjector} from './refs';
import {ArgumentType, BindingType, CheckType, DebugContext, DepFlags, ElementData, NodeCheckFn, NodeData, NodeDef, NodeFlags, NodeType, RootData, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewState, asElementData, asProviderData, asPureExpressionData} from './types'; import {ArgumentType, BindingType, CheckType, DebugContext, DepFlags, ElementData, NodeCheckFn, NodeData, NodeDef, NodeFlags, RootData, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewState, asElementData, asProviderData, asPureExpressionData} from './types';
import {checkBinding, isComponentView, renderNode, viewParentEl} from './util'; import {checkBinding, isComponentView, renderNode, viewParentEl} from './util';
import {checkAndUpdateNode, checkAndUpdateView, checkNoChangesNode, checkNoChangesView, createEmbeddedView, createRootView, destroyView} from './view'; import {checkAndUpdateNode, checkAndUpdateView, checkNoChangesNode, checkNoChangesView, createEmbeddedView, createRootView, destroyView} from './view';
@ -114,8 +114,9 @@ function prodCheckAndUpdateNode(
v3?: any, v4?: any, v5?: any, v6?: any, v7?: any, v8?: any, v9?: any): any { v3?: any, v4?: any, v5?: any, v6?: any, v7?: any, v8?: any, v9?: any): any {
const nodeDef = view.def.nodes[nodeIndex]; const nodeDef = view.def.nodes[nodeIndex];
checkAndUpdateNode(view, nodeDef, argStyle, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9); checkAndUpdateNode(view, nodeDef, argStyle, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
return (nodeDef.type === NodeType.PureExpression) ? asPureExpressionData(view, nodeIndex).value : return (nodeDef.flags & NodeFlags.CatPureExpression) ?
undefined; asPureExpressionData(view, nodeIndex).value :
undefined;
} }
function prodCheckNoChangesNode( function prodCheckNoChangesNode(
@ -123,8 +124,9 @@ function prodCheckNoChangesNode(
v3?: any, v4?: any, v5?: any, v6?: any, v7?: any, v8?: any, v9?: any): any { v3?: any, v4?: any, v5?: any, v6?: any, v7?: any, v8?: any, v9?: any): any {
const nodeDef = view.def.nodes[nodeIndex]; const nodeDef = view.def.nodes[nodeIndex];
checkNoChangesNode(view, nodeDef, argStyle, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9); checkNoChangesNode(view, nodeDef, argStyle, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
return (nodeDef.type === NodeType.PureExpression) ? asPureExpressionData(view, nodeIndex).value : return (nodeDef.flags & NodeFlags.CatPureExpression) ?
undefined; asPureExpressionData(view, nodeIndex).value :
undefined;
} }
function debugCreateEmbeddedView(parent: ViewData, anchorDef: NodeDef, context?: any): ViewData { function debugCreateEmbeddedView(parent: ViewData, anchorDef: NodeDef, context?: any): ViewData {
@ -182,10 +184,10 @@ function debugUpdateDirectives(view: ViewData, checkType: CheckType) {
} else { } else {
debugCheckNoChangesNode(view, nodeDef, argStyle, values); debugCheckNoChangesNode(view, nodeDef, argStyle, values);
} }
if (nodeDef.type === NodeType.Directive) { if (nodeDef.flags & NodeFlags.TypeDirective) {
debugSetCurrentNode(view, nextDirectiveWithBinding(view, nodeIndex)); debugSetCurrentNode(view, nextDirectiveWithBinding(view, nodeIndex));
} }
return (nodeDef.type === NodeType.PureExpression) ? return (nodeDef.flags & NodeFlags.CatPureExpression) ?
asPureExpressionData(view, nodeDef.index).value : asPureExpressionData(view, nodeDef.index).value :
undefined; undefined;
}; };
@ -206,10 +208,10 @@ function debugUpdateRenderer(view: ViewData, checkType: CheckType) {
} else { } else {
debugCheckNoChangesNode(view, nodeDef, argStyle, values); debugCheckNoChangesNode(view, nodeDef, argStyle, values);
} }
if (nodeDef.type === NodeType.Element || nodeDef.type === NodeType.Text) { if (nodeDef.flags & NodeFlags.CatRenderNode) {
debugSetCurrentNode(view, nextRenderNodeWithBinding(view, nodeIndex)); debugSetCurrentNode(view, nextRenderNodeWithBinding(view, nodeIndex));
} }
return (nodeDef.type === NodeType.PureExpression) ? return (nodeDef.flags & NodeFlags.CatPureExpression) ?
asPureExpressionData(view, nodeDef.index).value : asPureExpressionData(view, nodeDef.index).value :
undefined; undefined;
} }
@ -220,19 +222,18 @@ function debugCheckAndUpdateNode(
const changed = (<any>checkAndUpdateNode)(view, nodeDef, argStyle, ...givenValues); const changed = (<any>checkAndUpdateNode)(view, nodeDef, argStyle, ...givenValues);
if (changed) { if (changed) {
const values = argStyle === ArgumentType.Dynamic ? givenValues[0] : givenValues; const values = argStyle === ArgumentType.Dynamic ? givenValues[0] : givenValues;
if (nodeDef.type === NodeType.Directive || nodeDef.type === NodeType.Element) { if (nodeDef.flags & (NodeFlags.TypeDirective | NodeFlags.TypeElement)) {
const bindingValues: {[key: string]: string} = {}; const bindingValues: {[key: string]: string} = {};
for (let i = 0; i < nodeDef.bindings.length; i++) { for (let i = 0; i < nodeDef.bindings.length; i++) {
const binding = nodeDef.bindings[i]; const binding = nodeDef.bindings[i];
const value = values[i]; const value = values[i];
if ((binding.type === BindingType.ElementProperty || if ((binding.type === BindingType.ComponentHostProperty ||
binding.type === BindingType.ComponentHostProperty ||
binding.type === BindingType.DirectiveProperty)) { binding.type === BindingType.DirectiveProperty)) {
bindingValues[normalizeDebugBindingName(binding.nonMinifiedName)] = bindingValues[normalizeDebugBindingName(binding.nonMinifiedName)] =
normalizeDebugBindingValue(value); normalizeDebugBindingValue(value);
} }
} }
const elDef = nodeDef.type === NodeType.Directive ? nodeDef.parent : nodeDef; const elDef = nodeDef.flags & NodeFlags.TypeDirective ? nodeDef.parent : nodeDef;
const el = asElementData(view, elDef.index).renderElement; const el = asElementData(view, elDef.index).renderElement;
if (!elDef.element.name) { if (!elDef.element.name) {
// a comment. // a comment.
@ -281,7 +282,7 @@ function normalizeDebugBindingValue(value: any): string {
function nextDirectiveWithBinding(view: ViewData, nodeIndex: number): number { function nextDirectiveWithBinding(view: ViewData, nodeIndex: number): number {
for (let i = nodeIndex; i < view.def.nodes.length; i++) { for (let i = nodeIndex; i < view.def.nodes.length; i++) {
const nodeDef = view.def.nodes[i]; const nodeDef = view.def.nodes[i];
if (nodeDef.type === NodeType.Directive && nodeDef.bindings && nodeDef.bindings.length) { if (nodeDef.flags & NodeFlags.TypeDirective && nodeDef.bindings && nodeDef.bindings.length) {
return i; return i;
} }
} }
@ -291,8 +292,7 @@ function nextDirectiveWithBinding(view: ViewData, nodeIndex: number): number {
function nextRenderNodeWithBinding(view: ViewData, nodeIndex: number): number { function nextRenderNodeWithBinding(view: ViewData, nodeIndex: number): number {
for (let i = nodeIndex; i < view.def.nodes.length; i++) { for (let i = nodeIndex; i < view.def.nodes.length; i++) {
const nodeDef = view.def.nodes[i]; const nodeDef = view.def.nodes[i];
if ((nodeDef.type === NodeType.Element || nodeDef.type === NodeType.Text) && nodeDef.bindings && if ((nodeDef.flags & NodeFlags.CatRenderNode) && nodeDef.bindings && nodeDef.bindings.length) {
nodeDef.bindings.length) {
return i; return i;
} }
} }
@ -310,7 +310,7 @@ class DebugContext_ implements DebugContext {
this.nodeDef = view.def.nodes[nodeIndex]; this.nodeDef = view.def.nodes[nodeIndex];
let elDef = this.nodeDef; let elDef = this.nodeDef;
let elView = view; let elView = view;
while (elDef && elDef.type !== NodeType.Element) { while (elDef && (elDef.flags & NodeFlags.TypeElement) === 0) {
elDef = elDef.parent; elDef = elDef.parent;
} }
if (!elDef) { if (!elDef) {
@ -334,7 +334,7 @@ class DebugContext_ implements DebugContext {
if (this.elDef) { if (this.elDef) {
for (let i = this.elDef.index + 1; i <= this.elDef.index + this.elDef.childCount; i++) { for (let i = this.elDef.index + 1; i <= this.elDef.index + this.elDef.childCount; i++) {
const childDef = this.elView.def.nodes[i]; const childDef = this.elView.def.nodes[i];
if (childDef.type === NodeType.Provider || childDef.type === NodeType.Directive) { if (childDef.flags & NodeFlags.CatProvider) {
tokens.push(childDef.provider.token); tokens.push(childDef.provider.token);
} }
i += childDef.childCount; i += childDef.childCount;
@ -349,7 +349,7 @@ class DebugContext_ implements DebugContext {
for (let i = this.elDef.index + 1; i <= this.elDef.index + this.elDef.childCount; i++) { for (let i = this.elDef.index + 1; i <= this.elDef.index + this.elDef.childCount; i++) {
const childDef = this.elView.def.nodes[i]; const childDef = this.elView.def.nodes[i];
if (childDef.type === NodeType.Provider || childDef.type === NodeType.Directive) { if (childDef.flags & NodeFlags.CatProvider) {
collectReferences(this.elView, childDef, references); collectReferences(this.elView, childDef, references);
} }
i += childDef.childCount; i += childDef.childCount;
@ -358,7 +358,7 @@ class DebugContext_ implements DebugContext {
return references; return references;
} }
get source(): string { get source(): string {
if (this.nodeDef.type === NodeType.Text) { if (this.nodeDef.flags & NodeFlags.TypeText) {
return this.nodeDef.text.source; return this.nodeDef.text.source;
} else { } else {
return this.elDef.element.source; return this.elDef.element.source;
@ -369,8 +369,8 @@ class DebugContext_ implements DebugContext {
return elData ? elData.renderElement : undefined; return elData ? elData.renderElement : undefined;
} }
get renderNode(): any { get renderNode(): any {
return this.nodeDef.type === NodeType.Text ? renderNode(this.view, this.nodeDef) : return this.nodeDef.flags & NodeFlags.TypeText ? renderNode(this.view, this.nodeDef) :
renderNode(this.elView, this.elDef); renderNode(this.elView, this.elDef);
} }
} }

View File

@ -9,7 +9,7 @@
import {isDevMode} from '../application_ref'; import {isDevMode} from '../application_ref';
import {looseIdentical} from '../facade/lang'; import {looseIdentical} from '../facade/lang';
import {BindingDef, BindingType, DebugContext, NodeData, NodeDef, NodeFlags, NodeType, RootData, Services, TextData, ViewData, ViewFlags, asElementData, asTextData} from './types'; import {BindingDef, BindingType, DebugContext, NodeData, NodeDef, NodeFlags, RootData, Services, TextData, ViewData, ViewFlags, asElementData, asTextData} from './types';
import {checkAndUpdateBinding, getParentRenderElement, sliceErrorStack} from './util'; import {checkAndUpdateBinding, getParentRenderElement, sliceErrorStack} from './util';
export function textDef(ngContentIndex: number, constants: string[]): NodeDef { export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
@ -26,8 +26,8 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
suffix: constants[i] suffix: constants[i]
}; };
} }
const flags = NodeFlags.TypeText;
return { return {
type: NodeType.Text,
// will bet set by the view definition // will bet set by the view definition
index: undefined, index: undefined,
reverseChildIndex: undefined, reverseChildIndex: undefined,
@ -36,7 +36,7 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
bindingIndex: undefined, bindingIndex: undefined,
outputIndex: undefined, outputIndex: undefined,
// regular values // regular values
flags: 0, flags,
childFlags: 0, childFlags: 0,
childMatchedQueries: 0, childMatchedQueries: 0,
matchedQueries: {}, matchedQueries: {},
@ -47,7 +47,6 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
element: undefined, element: undefined,
provider: undefined, provider: undefined,
text: {prefix: constants[0], source}, text: {prefix: constants[0], source},
pureExpression: undefined,
query: undefined, query: undefined,
ngContent: undefined ngContent: undefined
}; };

View File

@ -64,15 +64,12 @@ export interface NodeCheckFn {
export type ViewHandleEventFn = export type ViewHandleEventFn =
(view: ViewData, nodeIndex: number, eventName: string, event: any) => boolean; (view: ViewData, nodeIndex: number, eventName: string, event: any) => boolean;
export enum ArgumentType { export const enum ArgumentType {Inline, Dynamic}
Inline,
Dynamic
}
/** /**
* Bitmask for ViewDefintion.flags. * Bitmask for ViewDefintion.flags.
*/ */
export enum ViewFlags { export const enum ViewFlags {
None = 0, None = 0,
OnPush = 1 << 1, OnPush = 1 << 1,
} }
@ -84,10 +81,9 @@ export enum ViewFlags {
* of a ViewDefinition stay monomorphic! * of a ViewDefinition stay monomorphic!
*/ */
export interface NodeDef { export interface NodeDef {
type: NodeType; flags: NodeFlags;
index: number; index: number;
reverseChildIndex: number; reverseChildIndex: number;
flags: NodeFlags;
parent: NodeDef; parent: NodeDef;
renderParent: NodeDef; renderParent: NodeDef;
/** this is checked against NgContentDef.index to find matched nodes */ /** this is checked against NgContentDef.index to find matched nodes */
@ -120,44 +116,55 @@ export interface NodeDef {
element: ElementDef; element: ElementDef;
provider: ProviderDef; provider: ProviderDef;
text: TextDef; text: TextDef;
pureExpression: PureExpressionDef;
query: QueryDef; query: QueryDef;
ngContent: NgContentDef; ngContent: NgContentDef;
} }
export enum NodeType {
Element,
Text,
Directive,
Provider,
Pipe,
PureExpression,
Query,
NgContent
}
/** /**
* Bitmask for NodeDef.flags. * Bitmask for NodeDef.flags.
* Naming convention:
* - `Type...`: flags that are mutually exclusive
* - `Cat...`: union of multiple `Type...` (short for category).
*/ */
export enum NodeFlags { export const enum NodeFlags {
None = 0, None = 0,
OnInit = 1 << 0, TypeElement = 1 << 0,
OnDestroy = 1 << 1, TypeText = 1 << 1,
DoCheck = 1 << 2, CatRenderNode = TypeElement | TypeText,
OnChanges = 1 << 3, TypeNgContent = 1 << 2,
AfterContentInit = 1 << 4, TypePipe = 1 << 3,
AfterContentChecked = 1 << 5, TypePureArray = 1 << 4,
AfterViewInit = 1 << 6, TypePureObject = 1 << 5,
AfterViewChecked = 1 << 7, TypePurePipe = 1 << 6,
HasEmbeddedViews = 1 << 8, CatPureExpression = TypePureArray | TypePureObject | TypePurePipe,
HasComponent = 1 << 9, TypeValueProvider = 1 << 7,
IsComponent = 1 << 10, TypeClassProvider = 1 << 8,
HasContentQuery = 1 << 11, TypeFactoryProvider = 1 << 9,
HasStaticQuery = 1 << 12, TypeUseExistingProvider = 1 << 10,
HasDynamicQuery = 1 << 13, LazyProvider = 1 << 11,
HasViewQuery = 1 << 14, PrivateProvider = 1 << 12,
LazyProvider = 1 << 15, TypeDirective = 1 << 13,
PrivateProvider = 1 << 16, Component = 1 << 14,
CatProvider = TypeValueProvider | TypeClassProvider | TypeFactoryProvider |
TypeUseExistingProvider | TypeDirective,
OnInit = 1 << 15,
OnDestroy = 1 << 16,
DoCheck = 1 << 17,
OnChanges = 1 << 18,
AfterContentInit = 1 << 19,
AfterContentChecked = 1 << 20,
AfterViewInit = 1 << 21,
AfterViewChecked = 1 << 22,
EmbeddedViews = 1 << 23,
ComponentView = 1 << 24,
TypeContentQuery = 1 << 25,
TypeViewQuery = 1 << 26,
StaticQuery = 1 << 27,
DynamicQuery = 1 << 28,
CatQuery = TypeContentQuery | TypeViewQuery,
// mutually exclusive values...
Types = CatRenderNode | TypeNgContent | TypePipe | CatPureExpression | CatProvider | CatQuery
} }
export interface BindingDef { export interface BindingDef {
@ -169,7 +176,7 @@ export interface BindingDef {
suffix: string; suffix: string;
} }
export enum BindingType { export const enum BindingType {
ElementAttribute, ElementAttribute,
ElementClass, ElementClass,
ElementStyle, ElementStyle,
@ -187,12 +194,9 @@ export interface OutputDef {
propName: string; propName: string;
} }
export enum OutputType { export const enum OutputType {ElementOutput, DirectiveOutput}
ElementOutput,
DirectiveOutput
}
export enum QueryValueType { export const enum QueryValueType {
ElementRef, ElementRef,
RenderElement, RenderElement,
TemplateRef, TemplateRef,
@ -227,20 +231,12 @@ export interface ElementDef {
export type ElementHandleEventFn = (view: ViewData, eventName: string, event: any) => boolean; export type ElementHandleEventFn = (view: ViewData, eventName: string, event: any) => boolean;
export interface ProviderDef { export interface ProviderDef {
type: ProviderType;
token: any; token: any;
tokenKey: string; tokenKey: string;
value: any; value: any;
deps: DepDef[]; deps: DepDef[];
} }
export enum ProviderType {
Value,
Class,
Factory,
UseExisting
}
export interface DepDef { export interface DepDef {
flags: DepFlags; flags: DepFlags;
token: any; token: any;
@ -250,7 +246,7 @@ export interface DepDef {
/** /**
* Bitmask for DI flags * Bitmask for DI flags
*/ */
export enum DepFlags { export const enum DepFlags {
None = 0, None = 0,
SkipSelf = 1 << 0, SkipSelf = 1 << 0,
Optional = 1 << 1, Optional = 1 << 1,
@ -262,14 +258,6 @@ export interface TextDef {
source: string; source: string;
} }
export interface PureExpressionDef { type: PureExpressionType; }
export enum PureExpressionType {
Array,
Object,
Pipe
}
export interface QueryDef { export interface QueryDef {
id: number; id: number;
// variant of the id that can be used to check against NodeDef.matchedQueryIds, ... // variant of the id that can be used to check against NodeDef.matchedQueryIds, ...
@ -282,10 +270,7 @@ export interface QueryBindingDef {
bindingType: QueryBindingType; bindingType: QueryBindingType;
} }
export enum QueryBindingType { export const enum QueryBindingType {First, All}
First,
All
}
export interface NgContentDef { export interface NgContentDef {
/** /**
@ -329,7 +314,7 @@ export interface ViewData {
/** /**
* Bitmask of states * Bitmask of states
*/ */
export enum ViewState { export const enum ViewState {
FirstCheck = 1 << 0, FirstCheck = 1 << 0,
ChecksEnabled = 1 << 1, ChecksEnabled = 1 << 1,
Errored = 1 << 2, Errored = 1 << 2,
@ -449,10 +434,7 @@ export abstract class DebugContext {
// Other // Other
// ------------------------------------- // -------------------------------------
export enum CheckType { export const enum CheckType {CheckAndUpdate, CheckNoChanges}
CheckAndUpdate,
CheckNoChanges
}
export interface Services { export interface Services {
setCurrentNode(view: ViewData, nodeIndex: number): void; setCurrentNode(view: ViewData, nodeIndex: number): void;

View File

@ -18,7 +18,7 @@ import {ViewEncapsulation} from '../metadata/view';
import {Renderer, RendererTypeV2} from '../render/api'; import {Renderer, RendererTypeV2} from '../render/api';
import {expressionChangedAfterItHasBeenCheckedError, isViewDebugError, viewDestroyedError, viewWrappedDebugError} from './errors'; import {expressionChangedAfterItHasBeenCheckedError, isViewDebugError, viewDestroyedError, viewWrappedDebugError} from './errors';
import {DebugContext, ElementData, NodeData, NodeDef, NodeFlags, NodeType, QueryValueType, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewState, asElementData, asProviderData, asTextData} from './types'; import {DebugContext, ElementData, NodeData, NodeDef, NodeFlags, QueryValueType, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewState, asElementData, asProviderData, asTextData} from './types';
const _tokenKeyCache = new Map<any, string>(); const _tokenKeyCache = new Map<any, string>();
@ -128,10 +128,10 @@ export function viewParentEl(view: ViewData): NodeDef {
} }
export function renderNode(view: ViewData, def: NodeDef): any { export function renderNode(view: ViewData, def: NodeDef): any {
switch (def.type) { switch (def.flags & NodeFlags.Types) {
case NodeType.Element: case NodeFlags.TypeElement:
return asElementData(view, def.index).renderElement; return asElementData(view, def.index).renderElement;
case NodeType.Text: case NodeFlags.TypeText:
return asTextData(view, def.index).renderText; return asTextData(view, def.index).renderText;
} }
} }
@ -176,8 +176,8 @@ export function splitMatchedQueriesDsl(matchedQueriesDsl: [string | number, Quer
export function getParentRenderElement(view: ViewData, renderHost: any, def: NodeDef): any { export function getParentRenderElement(view: ViewData, renderHost: any, def: NodeDef): any {
let renderParent = def.renderParent; let renderParent = def.renderParent;
if (renderParent) { if (renderParent) {
if (renderParent.type !== NodeType.Element || if ((renderParent.flags & NodeFlags.TypeElement) === 0 ||
(renderParent.flags & NodeFlags.HasComponent) === 0 || (renderParent.flags & NodeFlags.ComponentView) === 0 ||
(renderParent.element.componentRendererType && (renderParent.element.componentRendererType &&
renderParent.element.componentRendererType.encapsulation === ViewEncapsulation.Native)) { renderParent.element.componentRendererType.encapsulation === ViewEncapsulation.Native)) {
// only children of non components, or children of components with native encapsulation should // only children of non components, or children of components with native encapsulation should
@ -245,8 +245,7 @@ export function visitSiblingRenderNodes(
nextSibling: any, target: any[]) { nextSibling: any, target: any[]) {
for (let i = startIndex; i <= endIndex; i++) { for (let i = startIndex; i <= endIndex; i++) {
const nodeDef = view.def.nodes[i]; const nodeDef = view.def.nodes[i];
if (nodeDef.type === NodeType.Element || nodeDef.type === NodeType.Text || if (nodeDef.flags & (NodeFlags.TypeElement | NodeFlags.TypeText | NodeFlags.TypeNgContent)) {
nodeDef.type === NodeType.NgContent) {
visitRenderNode(view, nodeDef, action, parentNode, nextSibling, target); visitRenderNode(view, nodeDef, action, parentNode, nextSibling, target);
} }
// jump to next sibling // jump to next sibling
@ -287,13 +286,13 @@ export function visitProjectedRenderNodes(
function visitRenderNode( function visitRenderNode(
view: ViewData, nodeDef: NodeDef, action: RenderNodeAction, parentNode: any, nextSibling: any, view: ViewData, nodeDef: NodeDef, action: RenderNodeAction, parentNode: any, nextSibling: any,
target: any[]) { target: any[]) {
if (nodeDef.type === NodeType.NgContent) { if (nodeDef.flags & NodeFlags.TypeNgContent) {
visitProjectedRenderNodes( visitProjectedRenderNodes(
view, nodeDef.ngContent.index, action, parentNode, nextSibling, target); view, nodeDef.ngContent.index, action, parentNode, nextSibling, target);
} else { } else {
const rn = renderNode(view, nodeDef); const rn = renderNode(view, nodeDef);
execRenderNodeAction(view, rn, action, parentNode, nextSibling, target); execRenderNodeAction(view, rn, action, parentNode, nextSibling, target);
if (nodeDef.flags & NodeFlags.HasEmbeddedViews) { if (nodeDef.flags & NodeFlags.EmbeddedViews) {
const embeddedViews = asElementData(view, nodeDef.index).embeddedViews; const embeddedViews = asElementData(view, nodeDef.index).embeddedViews;
if (embeddedViews) { if (embeddedViews) {
for (let k = 0; k < embeddedViews.length; k++) { for (let k = 0; k < embeddedViews.length; k++) {
@ -301,7 +300,7 @@ function visitRenderNode(
} }
} }
} }
if (nodeDef.type === NodeType.Element && !nodeDef.element.name) { if (nodeDef.flags & NodeFlags.TypeElement && !nodeDef.element.name) {
visitSiblingRenderNodes( visitSiblingRenderNodes(
view, action, nodeDef.index + 1, nodeDef.index + nodeDef.childCount, parentNode, view, action, nodeDef.index + 1, nodeDef.index + nodeDef.childCount, parentNode,
nextSibling, target); nextSibling, target);

View File

@ -16,7 +16,7 @@ import {callLifecycleHooksChildrenFirst, checkAndUpdateDirectiveDynamic, checkAn
import {checkAndUpdatePureExpressionDynamic, checkAndUpdatePureExpressionInline, createPureExpression} from './pure_expression'; import {checkAndUpdatePureExpressionDynamic, checkAndUpdatePureExpressionInline, createPureExpression} from './pure_expression';
import {checkAndUpdateQuery, createQuery, queryDef} from './query'; import {checkAndUpdateQuery, createQuery, queryDef} from './query';
import {checkAndUpdateTextDynamic, checkAndUpdateTextInline, createText} from './text'; import {checkAndUpdateTextDynamic, checkAndUpdateTextInline, createText} from './text';
import {ArgumentType, CheckType, ElementData, ElementDef, NodeData, NodeDef, NodeFlags, NodeType, ProviderData, ProviderDef, RootData, Services, TextDef, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewHandleEventFn, ViewState, ViewUpdateFn, asElementData, asProviderData, asPureExpressionData, asQueryList, asTextData} from './types'; import {ArgumentType, CheckType, ElementData, ElementDef, NodeData, NodeDef, NodeFlags, ProviderData, ProviderDef, RootData, Services, TextDef, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewHandleEventFn, ViewState, ViewUpdateFn, asElementData, asProviderData, asPureExpressionData, asQueryList, asTextData} from './types';
import {checkBindingNoChanges, isComponentView, resolveViewDefinition, viewParentEl} from './util'; import {checkBindingNoChanges, isComponentView, resolveViewDefinition, viewParentEl} from './util';
const NOOP = (): any => undefined; const NOOP = (): any => undefined;
@ -57,7 +57,8 @@ export function viewDef(
// renderParent needs to account for ng-container! // renderParent needs to account for ng-container!
let currentRenderParent: NodeDef; let currentRenderParent: NodeDef;
if (currentParent && currentParent.type === NodeType.Element && !currentParent.element.name) { if (currentParent && currentParent.flags & NodeFlags.TypeElement &&
!currentParent.element.name) {
currentRenderParent = currentParent.renderParent; currentRenderParent = currentParent.renderParent;
} else { } else {
currentRenderParent = currentParent; currentRenderParent = currentParent;
@ -92,10 +93,10 @@ export function viewDef(
viewBindingCount += node.bindings.length; viewBindingCount += node.bindings.length;
viewDisposableCount += node.outputs.length; viewDisposableCount += node.outputs.length;
if (!currentRenderParent && (node.type === NodeType.Element || node.type === NodeType.Text)) { if (!currentRenderParent && (node.flags & NodeFlags.CatRenderNode)) {
lastRenderRootNode = node; lastRenderRootNode = node;
} }
if (node.type === NodeType.Provider || node.type === NodeType.Directive) { if (node.flags & NodeFlags.CatProvider) {
if (!currentElementHasPublicProviders) { if (!currentElementHasPublicProviders) {
currentElementHasPublicProviders = true; currentElementHasPublicProviders = true;
// Use protoypical inheritance to not get O(n^2) complexity... // Use protoypical inheritance to not get O(n^2) complexity...
@ -104,7 +105,7 @@ export function viewDef(
currentParent.element.allProviders = currentParent.element.publicProviders; currentParent.element.allProviders = currentParent.element.publicProviders;
} }
const isPrivateService = (node.flags & NodeFlags.PrivateProvider) !== 0; const isPrivateService = (node.flags & NodeFlags.PrivateProvider) !== 0;
const isComponent = (node.flags & NodeFlags.IsComponent) !== 0; const isComponent = (node.flags & NodeFlags.Component) !== 0;
if (!isPrivateService || isComponent) { if (!isPrivateService || isComponent) {
currentParent.element.publicProviders[node.provider.tokenKey] = node; currentParent.element.publicProviders[node.provider.tokenKey] = node;
} else { } else {
@ -190,24 +191,25 @@ function validateNode(parent: NodeDef, node: NodeDef, nodeCount: number) {
const template = node.element && node.element.template; const template = node.element && node.element.template;
if (template) { if (template) {
if (template.lastRenderRootNode && if (template.lastRenderRootNode &&
template.lastRenderRootNode.flags & NodeFlags.HasEmbeddedViews) { template.lastRenderRootNode.flags & NodeFlags.EmbeddedViews) {
throw new Error( throw new Error(
`Illegal State: Last root node of a template can't have embedded views, at index ${node.index}!`); `Illegal State: Last root node of a template can't have embedded views, at index ${node.index}!`);
} }
} }
if (node.type === NodeType.Provider || node.type === NodeType.Directive) { if (node.flags & NodeFlags.CatProvider) {
const parentType = parent ? parent.type : null; const parentFlags = parent ? parent.flags : null;
if (parentType !== NodeType.Element) { if ((parentFlags & NodeFlags.TypeElement) === 0) {
throw new Error( throw new Error(
`Illegal State: Provider/Directive nodes need to be children of elements or anchors, at index ${node.index}!`); `Illegal State: Provider/Directive nodes need to be children of elements or anchors, at index ${node.index}!`);
} }
} }
if (node.query) { if (node.query) {
if (node.flags & NodeFlags.HasContentQuery && (!parent || parent.type !== NodeType.Directive)) { if (node.flags & NodeFlags.TypeContentQuery &&
(!parent || (parent.flags & NodeFlags.TypeDirective) === 0)) {
throw new Error( throw new Error(
`Illegal State: Content Query nodes need to be children of directives, at index ${node.index}!`); `Illegal State: Content Query nodes need to be children of directives, at index ${node.index}!`);
} }
if (node.flags & NodeFlags.HasViewQuery && parent) { if (node.flags & NodeFlags.TypeViewQuery && parent) {
throw new Error( throw new Error(
`Illegal State: View Query nodes have to be top level nodes, at index ${node.index}!`); `Illegal State: View Query nodes have to be top level nodes, at index ${node.index}!`);
} }
@ -272,11 +274,11 @@ function createViewNodes(view: ViewData) {
const nodeDef = def.nodes[i]; const nodeDef = def.nodes[i];
Services.setCurrentNode(view, i); Services.setCurrentNode(view, i);
let nodeData: any; let nodeData: any;
switch (nodeDef.type) { switch (nodeDef.flags & NodeFlags.Types) {
case NodeType.Element: case NodeFlags.TypeElement:
const el = createElement(view, renderHost, nodeDef) as any; const el = createElement(view, renderHost, nodeDef) as any;
let componentView: ViewData; let componentView: ViewData;
if (nodeDef.flags & NodeFlags.HasComponent) { if (nodeDef.flags & NodeFlags.ComponentView) {
const compViewDef = resolveViewDefinition(nodeDef.element.componentView); const compViewDef = resolveViewDefinition(nodeDef.element.componentView);
const rendererType = nodeDef.element.componentRendererType; const rendererType = nodeDef.element.componentRendererType;
let compRenderer: RendererV2; let compRenderer: RendererV2;
@ -292,39 +294,45 @@ function createViewNodes(view: ViewData) {
nodeData = <ElementData>{ nodeData = <ElementData>{
renderElement: el, renderElement: el,
componentView, componentView,
embeddedViews: (nodeDef.flags & NodeFlags.HasEmbeddedViews) ? [] : undefined, embeddedViews: (nodeDef.flags & NodeFlags.EmbeddedViews) ? [] : undefined,
projectedViews: undefined projectedViews: undefined
}; };
break; break;
case NodeType.Text: case NodeFlags.TypeText:
nodeData = createText(view, renderHost, nodeDef) as any; nodeData = createText(view, renderHost, nodeDef) as any;
break; break;
case NodeType.Provider: { case NodeFlags.TypeClassProvider:
case NodeFlags.TypeFactoryProvider:
case NodeFlags.TypeUseExistingProvider:
case NodeFlags.TypeValueProvider: {
const instance = createProviderInstance(view, nodeDef); const instance = createProviderInstance(view, nodeDef);
nodeData = <ProviderData>{instance}; nodeData = <ProviderData>{instance};
break; break;
} }
case NodeType.Pipe: { case NodeFlags.TypePipe: {
const instance = createPipeInstance(view, nodeDef); const instance = createPipeInstance(view, nodeDef);
nodeData = <ProviderData>{instance}; nodeData = <ProviderData>{instance};
break; break;
} }
case NodeType.Directive: { case NodeFlags.TypeDirective: {
const instance = createDirectiveInstance(view, nodeDef); const instance = createDirectiveInstance(view, nodeDef);
nodeData = <ProviderData>{instance}; nodeData = <ProviderData>{instance};
if (nodeDef.flags & NodeFlags.IsComponent) { if (nodeDef.flags & NodeFlags.Component) {
const compView = asElementData(view, nodeDef.parent.index).componentView; const compView = asElementData(view, nodeDef.parent.index).componentView;
initView(compView, instance, instance); initView(compView, instance, instance);
} }
break; break;
} }
case NodeType.PureExpression: case NodeFlags.TypePureArray:
case NodeFlags.TypePureObject:
case NodeFlags.TypePurePipe:
nodeData = createPureExpression(view, nodeDef) as any; nodeData = createPureExpression(view, nodeDef) as any;
break; break;
case NodeType.Query: case NodeFlags.TypeContentQuery:
case NodeFlags.TypeViewQuery:
nodeData = createQuery() as any; nodeData = createQuery() as any;
break; break;
case NodeType.NgContent: case NodeFlags.TypeNgContent:
appendNgContent(view, renderHost, nodeDef); appendNgContent(view, renderHost, nodeDef);
// no runtime data needed for NgContent... // no runtime data needed for NgContent...
nodeData = undefined; nodeData = undefined;
@ -338,7 +346,7 @@ function createViewNodes(view: ViewData) {
// fill static content and view queries // fill static content and view queries
execQueriesAction( execQueriesAction(
view, NodeFlags.HasContentQuery | NodeFlags.HasViewQuery, NodeFlags.HasStaticQuery, view, NodeFlags.TypeContentQuery | NodeFlags.TypeViewQuery, NodeFlags.StaticQuery,
CheckType.CheckAndUpdate); CheckType.CheckAndUpdate);
} }
@ -346,18 +354,18 @@ export function checkNoChangesView(view: ViewData) {
Services.updateDirectives(view, CheckType.CheckNoChanges); Services.updateDirectives(view, CheckType.CheckNoChanges);
execEmbeddedViewsAction(view, ViewAction.CheckNoChanges); execEmbeddedViewsAction(view, ViewAction.CheckNoChanges);
execQueriesAction( execQueriesAction(
view, NodeFlags.HasContentQuery, NodeFlags.HasDynamicQuery, CheckType.CheckNoChanges); view, NodeFlags.TypeContentQuery, NodeFlags.DynamicQuery, CheckType.CheckNoChanges);
Services.updateRenderer(view, CheckType.CheckNoChanges); Services.updateRenderer(view, CheckType.CheckNoChanges);
execComponentViewsAction(view, ViewAction.CheckNoChanges); execComponentViewsAction(view, ViewAction.CheckNoChanges);
execQueriesAction( execQueriesAction(
view, NodeFlags.HasViewQuery, NodeFlags.HasDynamicQuery, CheckType.CheckNoChanges); view, NodeFlags.TypeViewQuery, NodeFlags.DynamicQuery, CheckType.CheckNoChanges);
} }
export function checkAndUpdateView(view: ViewData) { export function checkAndUpdateView(view: ViewData) {
Services.updateDirectives(view, CheckType.CheckAndUpdate); Services.updateDirectives(view, CheckType.CheckAndUpdate);
execEmbeddedViewsAction(view, ViewAction.CheckAndUpdate); execEmbeddedViewsAction(view, ViewAction.CheckAndUpdate);
execQueriesAction( execQueriesAction(
view, NodeFlags.HasContentQuery, NodeFlags.HasDynamicQuery, CheckType.CheckAndUpdate); view, NodeFlags.TypeContentQuery, NodeFlags.DynamicQuery, CheckType.CheckAndUpdate);
callLifecycleHooksChildrenFirst( callLifecycleHooksChildrenFirst(
view, NodeFlags.AfterContentChecked | view, NodeFlags.AfterContentChecked |
@ -367,7 +375,7 @@ export function checkAndUpdateView(view: ViewData) {
execComponentViewsAction(view, ViewAction.CheckAndUpdate); execComponentViewsAction(view, ViewAction.CheckAndUpdate);
execQueriesAction( execQueriesAction(
view, NodeFlags.HasViewQuery, NodeFlags.HasDynamicQuery, CheckType.CheckAndUpdate); view, NodeFlags.TypeViewQuery, NodeFlags.DynamicQuery, CheckType.CheckAndUpdate);
callLifecycleHooksChildrenFirst( callLifecycleHooksChildrenFirst(
view, NodeFlags.AfterViewChecked | view, NodeFlags.AfterViewChecked |
@ -393,18 +401,20 @@ function checkAndUpdateNodeInline(
view: ViewData, nodeDef: NodeDef, v0?: any, v1?: any, v2?: any, v3?: any, v4?: any, v5?: any, view: ViewData, nodeDef: NodeDef, v0?: any, v1?: any, v2?: any, v3?: any, v4?: any, v5?: any,
v6?: any, v7?: any, v8?: any, v9?: any): boolean { v6?: any, v7?: any, v8?: any, v9?: any): boolean {
let changed = false; let changed = false;
switch (nodeDef.type) { switch (nodeDef.flags & NodeFlags.Types) {
case NodeType.Element: case NodeFlags.TypeElement:
changed = checkAndUpdateElementInline(view, nodeDef, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9); changed = checkAndUpdateElementInline(view, nodeDef, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
break; break;
case NodeType.Text: case NodeFlags.TypeText:
changed = checkAndUpdateTextInline(view, nodeDef, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9); changed = checkAndUpdateTextInline(view, nodeDef, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
break; break;
case NodeType.Directive: case NodeFlags.TypeDirective:
changed = changed =
checkAndUpdateDirectiveInline(view, nodeDef, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9); checkAndUpdateDirectiveInline(view, nodeDef, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
break; break;
case NodeType.PureExpression: case NodeFlags.TypePureArray:
case NodeFlags.TypePureObject:
case NodeFlags.TypePurePipe:
changed = changed =
checkAndUpdatePureExpressionInline(view, nodeDef, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9); checkAndUpdatePureExpressionInline(view, nodeDef, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
break; break;
@ -414,17 +424,19 @@ function checkAndUpdateNodeInline(
function checkAndUpdateNodeDynamic(view: ViewData, nodeDef: NodeDef, values: any[]): boolean { function checkAndUpdateNodeDynamic(view: ViewData, nodeDef: NodeDef, values: any[]): boolean {
let changed = false; let changed = false;
switch (nodeDef.type) { switch (nodeDef.flags & NodeFlags.Types) {
case NodeType.Element: case NodeFlags.TypeElement:
changed = checkAndUpdateElementDynamic(view, nodeDef, values); changed = checkAndUpdateElementDynamic(view, nodeDef, values);
break; break;
case NodeType.Text: case NodeFlags.TypeText:
changed = checkAndUpdateTextDynamic(view, nodeDef, values); changed = checkAndUpdateTextDynamic(view, nodeDef, values);
break; break;
case NodeType.Directive: case NodeFlags.TypeDirective:
changed = checkAndUpdateDirectiveDynamic(view, nodeDef, values); changed = checkAndUpdateDirectiveDynamic(view, nodeDef, values);
break; break;
case NodeType.PureExpression: case NodeFlags.TypePureArray:
case NodeFlags.TypePureObject:
case NodeFlags.TypePurePipe:
changed = checkAndUpdatePureExpressionDynamic(view, nodeDef, values); changed = checkAndUpdatePureExpressionDynamic(view, nodeDef, values);
break; break;
} }
@ -509,9 +521,9 @@ function destroyViewNodes(view: ViewData) {
const len = view.def.nodes.length; const len = view.def.nodes.length;
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
const def = view.def.nodes[i]; const def = view.def.nodes[i];
if (def.type === NodeType.Element) { if (def.flags & NodeFlags.TypeElement) {
view.renderer.destroyNode(asElementData(view, i).renderElement); view.renderer.destroyNode(asElementData(view, i).renderElement);
} else if (def.type === NodeType.Text) { } else if (def.flags & NodeFlags.TypeText) {
view.renderer.destroyNode(asTextData(view, i).renderText); view.renderer.destroyNode(asTextData(view, i).renderText);
} }
} }
@ -526,15 +538,15 @@ enum ViewAction {
function execComponentViewsAction(view: ViewData, action: ViewAction) { function execComponentViewsAction(view: ViewData, action: ViewAction) {
const def = view.def; const def = view.def;
if (!(def.nodeFlags & NodeFlags.HasComponent)) { if (!(def.nodeFlags & NodeFlags.ComponentView)) {
return; return;
} }
for (let i = 0; i < def.nodes.length; i++) { for (let i = 0; i < def.nodes.length; i++) {
const nodeDef = def.nodes[i]; const nodeDef = def.nodes[i];
if (nodeDef.flags & NodeFlags.HasComponent) { if (nodeDef.flags & NodeFlags.ComponentView) {
// a leaf // a leaf
callViewAction(asElementData(view, i).componentView, action); callViewAction(asElementData(view, i).componentView, action);
} else if ((nodeDef.childFlags & NodeFlags.HasComponent) === 0) { } else if ((nodeDef.childFlags & NodeFlags.ComponentView) === 0) {
// a parent with leafs // a parent with leafs
// no child is a component, // no child is a component,
// then skip the children // then skip the children
@ -545,12 +557,12 @@ function execComponentViewsAction(view: ViewData, action: ViewAction) {
function execEmbeddedViewsAction(view: ViewData, action: ViewAction) { function execEmbeddedViewsAction(view: ViewData, action: ViewAction) {
const def = view.def; const def = view.def;
if (!(def.nodeFlags & NodeFlags.HasEmbeddedViews)) { if (!(def.nodeFlags & NodeFlags.EmbeddedViews)) {
return; return;
} }
for (let i = 0; i < def.nodes.length; i++) { for (let i = 0; i < def.nodes.length; i++) {
const nodeDef = def.nodes[i]; const nodeDef = def.nodes[i];
if (nodeDef.flags & NodeFlags.HasEmbeddedViews) { if (nodeDef.flags & NodeFlags.EmbeddedViews) {
// a leaf // a leaf
const embeddedViews = asElementData(view, i).embeddedViews; const embeddedViews = asElementData(view, i).embeddedViews;
if (embeddedViews) { if (embeddedViews) {
@ -558,7 +570,7 @@ function execEmbeddedViewsAction(view: ViewData, action: ViewAction) {
callViewAction(embeddedViews[k], action); callViewAction(embeddedViews[k], action);
} }
} }
} else if ((nodeDef.childFlags & NodeFlags.HasEmbeddedViews) === 0) { } else if ((nodeDef.childFlags & NodeFlags.EmbeddedViews) === 0) {
// a parent with leafs // a parent with leafs
// no child is a component, // no child is a component,
// then skip the children // then skip the children

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {ElementData, NodeData, NodeDef, NodeFlags, NodeType, Services, ViewData, asElementData, asProviderData, asTextData} from './types'; import {ElementData, NodeData, NodeDef, NodeFlags, Services, ViewData, asElementData, asProviderData, asTextData} from './types';
import {RenderNodeAction, declaredViewContainer, isComponentView, renderNode, rootRenderNodes, visitProjectedRenderNodes, visitRootRenderNodes} from './util'; import {RenderNodeAction, declaredViewContainer, isComponentView, renderNode, rootRenderNodes, visitProjectedRenderNodes, visitRootRenderNodes} from './util';
export function attachEmbeddedView( export function attachEmbeddedView(

View File

@ -40,7 +40,7 @@ export function main() {
() => compViewDef([ () => compViewDef([
elementDef(NodeFlags.None, null, null, 0, 'span'), elementDef(NodeFlags.None, null, null, 0, 'span'),
])), ])),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, []), directiveDef(NodeFlags.Component, null, 0, AComp, []),
])); ]));
const compView = asElementData(view, 0).componentView; const compView = asElementData(view, 0).componentView;
@ -123,7 +123,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 0, 'span', null, [[BindingType.ElementAttribute, 'a', SecurityContext.NONE]]), elementDef(NodeFlags.None, null, null, 0, 'span', null, [[BindingType.ElementAttribute, 'a', SecurityContext.NONE]]),
], null, update ], null, update
)), )),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, []), directiveDef(NodeFlags.Component, null, 0, AComp, []),
])); ]));
const compView = asElementData(view, 0).componentView; const compView = asElementData(view, 0).componentView;
@ -159,7 +159,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 0, 'span'), elementDef(NodeFlags.None, null, null, 0, 'span'),
], ],
update)), update)),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, [], null, null), directiveDef(NodeFlags.Component, null, 0, AComp, [], null, null),
])); ]));
const compView = asElementData(view, 0).componentView; const compView = asElementData(view, 0).componentView;
@ -201,7 +201,7 @@ export function main() {
], ],
update, null, ViewFlags.OnPush); update, null, ViewFlags.OnPush);
}), }),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, [], {a: [0, 'a']}), directiveDef(NodeFlags.Component, null, 0, AComp, [], {a: [0, 'a']}),
], ],
(check, view) => { check(view, 1, ArgumentType.Inline, compInputValue); })); (check, view) => { check(view, 1, ArgumentType.Inline, compInputValue); }));
@ -251,7 +251,7 @@ export function main() {
], ],
null, update)), null, update)),
directiveDef( directiveDef(
NodeFlags.IsComponent, null, 0, AComp, [], null, null, NodeFlags.Component, null, 0, AComp, [], null, null,
), ),
])); ]));
@ -286,7 +286,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 1, 'span'), elementDef(NodeFlags.None, null, null, 1, 'span'),
directiveDef(NodeFlags.OnDestroy, null, 0, ChildProvider, []) directiveDef(NodeFlags.OnDestroy, null, 0, ChildProvider, [])
])), ])),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, [], null, null, ), directiveDef(NodeFlags.Component, null, 0, AComp, [], null, null, ),
])); ]));
Services.destroyView(view); Services.destroyView(view);

View File

@ -73,7 +73,7 @@ export function main() {
describe('change properties', () => { describe('change properties', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should update ${ArgumentType[inlineDynamic]}`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef( const {view, rootNodes} = createAndGetRootNodes(compViewDef(
[ [
@ -93,15 +93,13 @@ export function main() {
const el = rootNodes[0]; const el = rootNodes[0];
expect(getDOM().getProperty(el, 'title')).toBe('v1'); expect(getDOM().getProperty(el, 'title')).toBe('v1');
expect(getDOM().getProperty(el, 'value')).toBe('v2'); expect(getDOM().getProperty(el, 'value')).toBe('v2');
expect(getDOM().getAttribute(el, 'ng-reflect-title')).toBe('v1');
}); });
}); });
}); });
describe('change attributes', () => { describe('change attributes', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should update ${ArgumentType[inlineDynamic]}`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef( const {view, rootNodes} = createAndGetRootNodes(compViewDef(
[ [
elementDef( elementDef(
@ -126,7 +124,7 @@ export function main() {
describe('change classes', () => { describe('change classes', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should update ${ArgumentType[inlineDynamic]}`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef( const {view, rootNodes} = createAndGetRootNodes(compViewDef(
[ [
elementDef( elementDef(
@ -148,7 +146,7 @@ export function main() {
describe('change styles', () => { describe('change styles', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should update ${ArgumentType[inlineDynamic]}`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef( const {view, rootNodes} = createAndGetRootNodes(compViewDef(
[ [
elementDef( elementDef(

View File

@ -40,7 +40,7 @@ export function main() {
compViewDef([ compViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
anchorDef( anchorDef(
NodeFlags.HasEmbeddedViews, null, null, 0, null, NodeFlags.EmbeddedViews, null, null, 0, null,
embeddedViewDef([elementDef(NodeFlags.None, null, null, 0, 'span')])), embeddedViewDef([elementDef(NodeFlags.None, null, null, 0, 'span')])),
]), ]),
parentContext); parentContext);
@ -54,7 +54,7 @@ export function main() {
it('should attach and detach embedded views', () => { it('should attach and detach embedded views', () => {
const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([ const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 2, 'div'), elementDef(NodeFlags.None, null, null, 2, 'div'),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 0, 'span', [['name', 'child0']]) elementDef(NodeFlags.None, null, null, 0, 'span', [['name', 'child0']])
])), ])),
anchorDef(NodeFlags.None, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.None, null, null, 0, null, embeddedViewDef([
@ -84,7 +84,7 @@ export function main() {
it('should move embedded views', () => { it('should move embedded views', () => {
const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([ const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 2, 'div'), elementDef(NodeFlags.None, null, null, 2, 'div'),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 0, 'span', [['name', 'child0']]) elementDef(NodeFlags.None, null, null, 0, 'span', [['name', 'child0']])
])), ])),
anchorDef(NodeFlags.None, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.None, null, null, 0, null, embeddedViewDef([
@ -111,7 +111,7 @@ export function main() {
it('should include embedded views in root nodes', () => { it('should include embedded views in root nodes', () => {
const {view: parentView} = createAndGetRootNodes(compViewDef([ const {view: parentView} = createAndGetRootNodes(compViewDef([
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 0, 'span', [['name', 'child0']]) elementDef(NodeFlags.None, null, null, 0, 'span', [['name', 'child0']])
])), ])),
elementDef(NodeFlags.None, null, null, 0, 'span', [['name', 'after']]) elementDef(NodeFlags.None, null, null, 0, 'span', [['name', 'after']])
@ -136,7 +136,7 @@ export function main() {
const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([ const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
anchorDef( anchorDef(
NodeFlags.HasEmbeddedViews, null, null, 0, null, NodeFlags.EmbeddedViews, null, null, 0, null,
embeddedViewDef( embeddedViewDef(
[elementDef( [elementDef(
NodeFlags.None, null, null, 0, 'span', null, NodeFlags.None, null, null, 0, 'span', null,
@ -172,7 +172,7 @@ export function main() {
const {view: parentView} = createAndGetRootNodes(compViewDef([ const {view: parentView} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 1, 'span'), elementDef(NodeFlags.None, null, null, 1, 'span'),
directiveDef(NodeFlags.OnDestroy, null, 0, ChildProvider, []) directiveDef(NodeFlags.OnDestroy, null, 0, ChildProvider, [])
])) ]))

View File

@ -33,7 +33,7 @@ export function main() {
elementDef( elementDef(
NodeFlags.None, null, null, 1 + contentNodes.length, 'acomp', null, null, null, null, NodeFlags.None, null, null, 1 + contentNodes.length, 'acomp', null, null, null, null,
() => aCompViewDef), () => aCompViewDef),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, []), ...contentNodes directiveDef(NodeFlags.Component, null, 0, AComp, []), ...contentNodes
]; ];
} }
@ -86,8 +86,8 @@ export function main() {
const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef( const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef(
[ [
anchorDef(NodeFlags.HasEmbeddedViews, null, 0, 1, null, embeddedViewDef([textDef( anchorDef(
null, ['a'])])), NodeFlags.EmbeddedViews, null, 0, 1, null, embeddedViewDef([textDef(null, ['a'])])),
directiveDef( directiveDef(
NodeFlags.None, null, 0, CreateViewService, [TemplateRef, ViewContainerRef]) NodeFlags.None, null, 0, CreateViewService, [TemplateRef, ViewContainerRef])
], ],
@ -104,7 +104,7 @@ export function main() {
it('should include projected nodes when attaching / detaching embedded views', () => { it('should include projected nodes when attaching / detaching embedded views', () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef([textDef(0, ['a'])], [ const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef([textDef(0, ['a'])], [
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
anchorDef(NodeFlags.HasEmbeddedViews, null, 0, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, 0, 0, null, embeddedViewDef([
ngContentDef(null, 0), ngContentDef(null, 0),
// The anchor would be added by the compiler after the ngContent // The anchor would be added by the compiler after the ngContent
anchorDef(NodeFlags.None, null, null, 0), anchorDef(NodeFlags.None, null, null, 0),

View File

@ -8,7 +8,7 @@
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectorRef, DoCheck, ElementRef, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, RenderComponentType, Renderer, RendererV2, RootRenderer, Sanitizer, SecurityContext, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation, WrappedValue, getDebugNode} from '@angular/core'; import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectorRef, DoCheck, ElementRef, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, RenderComponentType, Renderer, RendererV2, RootRenderer, Sanitizer, SecurityContext, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation, WrappedValue, getDebugNode} from '@angular/core';
import {getDebugContext} from '@angular/core/src/errors'; import {getDebugContext} from '@angular/core/src/errors';
import {ArgumentType, BindingType, DebugContext, DepFlags, NodeDef, NodeFlags, ProviderType, RootData, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewHandleEventFn, ViewUpdateFn, anchorDef, asElementData, asProviderData, directiveDef, elementDef, providerDef, rootRenderNodes, textDef, viewDef} from '@angular/core/src/view/index'; import {ArgumentType, BindingType, DebugContext, DepFlags, NodeDef, NodeFlags, RootData, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewHandleEventFn, ViewUpdateFn, anchorDef, asElementData, asProviderData, directiveDef, elementDef, providerDef, rootRenderNodes, textDef, viewDef} from '@angular/core/src/view/index';
import {TestBed, inject, withModule} from '@angular/core/testing'; import {TestBed, inject, withModule} from '@angular/core/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
@ -59,7 +59,8 @@ export function main() {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 2, 'span'), elementDef(NodeFlags.None, null, null, 2, 'span'),
providerDef( providerDef(
NodeFlags.LazyProvider, null, ProviderType.Class, LazyService, LazyService, []), NodeFlags.TypeClassProvider | NodeFlags.LazyProvider, null, LazyService, LazyService,
[]),
directiveDef(NodeFlags.None, null, 0, SomeService, [Injector]) directiveDef(NodeFlags.None, null, 0, SomeService, [Injector])
])); ]));
@ -71,7 +72,7 @@ export function main() {
it('should create value providers', () => { it('should create value providers', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 2, 'span'), elementDef(NodeFlags.None, null, null, 2, 'span'),
providerDef(NodeFlags.None, null, ProviderType.Value, 'someToken', 'someValue', []), providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someValue', []),
directiveDef(NodeFlags.None, null, 0, SomeService, ['someToken']), directiveDef(NodeFlags.None, null, 0, SomeService, ['someToken']),
])); ]));
@ -83,7 +84,7 @@ export function main() {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 2, 'span'), elementDef(NodeFlags.None, null, null, 2, 'span'),
providerDef(NodeFlags.None, null, ProviderType.Factory, 'someToken', someFactory, []), providerDef(NodeFlags.TypeFactoryProvider, null, 'someToken', someFactory, []),
directiveDef(NodeFlags.None, null, 0, SomeService, ['someToken']), directiveDef(NodeFlags.None, null, 0, SomeService, ['someToken']),
])); ]));
@ -93,11 +94,9 @@ export function main() {
it('should create useExisting providers', () => { it('should create useExisting providers', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 3, 'span'), elementDef(NodeFlags.None, null, null, 3, 'span'),
providerDef(NodeFlags.TypeValueProvider, null, 'someExistingToken', 'someValue', []),
providerDef( providerDef(
NodeFlags.None, null, ProviderType.Value, 'someExistingToken', 'someValue', []), NodeFlags.TypeUseExistingProvider, null, 'someToken', null, ['someExistingToken']),
providerDef(
NodeFlags.None, null, ProviderType.UseExisting, 'someToken', null,
['someExistingToken']),
directiveDef(NodeFlags.None, null, 0, SomeService, ['someToken']), directiveDef(NodeFlags.None, null, 0, SomeService, ['someToken']),
])); ]));
@ -116,7 +115,7 @@ export function main() {
elementDef( elementDef(
NodeFlags.None, null, null, 1, 'div', null, null, null, null, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
() => compViewDef([textDef(null, ['a'])])), () => compViewDef([textDef(null, ['a'])])),
directiveDef(NodeFlags.IsComponent, null, 0, SomeService, []) directiveDef(NodeFlags.Component, null, 0, SomeService, [])
]), ]),
TestBed.get(Injector), [], getDOM().createElement('div')); TestBed.get(Injector), [], getDOM().createElement('div'));
} catch (e) { } catch (e) {
@ -180,7 +179,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 1, 'span'), elementDef(NodeFlags.None, null, null, 1, 'span'),
directiveDef(NodeFlags.None, null, 0, SomeService, [Dep]) directiveDef(NodeFlags.None, null, 0, SomeService, [Dep])
])), ])),
directiveDef(NodeFlags.IsComponent, null, 0, Dep, []), directiveDef(NodeFlags.Component, null, 0, Dep, []),
])); ]));
expect(instance.dep instanceof Dep).toBeTruthy(); expect(instance.dep instanceof Dep).toBeTruthy();
@ -206,10 +205,9 @@ export function main() {
it('should skip the current element when using SkipSelf', () => { it('should skip the current element when using SkipSelf', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 4, 'span'), elementDef(NodeFlags.None, null, null, 4, 'span'),
providerDef( providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someParentValue', []),
NodeFlags.None, null, ProviderType.Value, 'someToken', 'someParentValue', []),
elementDef(NodeFlags.None, null, null, 2, 'span'), elementDef(NodeFlags.None, null, null, 2, 'span'),
providerDef(NodeFlags.None, null, ProviderType.Value, 'someToken', 'someValue', []), providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someValue', []),
directiveDef( directiveDef(
NodeFlags.None, null, 0, SomeService, [[DepFlags.SkipSelf, 'someToken']]) NodeFlags.None, null, 0, SomeService, [[DepFlags.SkipSelf, 'someToken']])
])); ]));
@ -229,7 +227,7 @@ export function main() {
describe('builtin tokens', () => { describe('builtin tokens', () => {
it('should inject ViewContainerRef', () => { it('should inject ViewContainerRef', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 1), anchorDef(NodeFlags.EmbeddedViews, null, null, 1),
directiveDef(NodeFlags.None, null, 0, SomeService, [ViewContainerRef]) directiveDef(NodeFlags.None, null, 0, SomeService, [ViewContainerRef])
])); ]));
@ -280,7 +278,7 @@ export function main() {
() => compViewDef([ () => compViewDef([
elementDef(NodeFlags.None, null, null, 0, 'span'), elementDef(NodeFlags.None, null, null, 0, 'span'),
])), ])),
directiveDef(NodeFlags.IsComponent, null, 0, SomeService, [ChangeDetectorRef]), directiveDef(NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]),
])); ]));
const compView = asElementData(view, 0).componentView; const compView = asElementData(view, 0).componentView;
@ -292,7 +290,7 @@ export function main() {
elementDef( elementDef(
NodeFlags.None, null, null, 1, 'span', null, null, null, null, NodeFlags.None, null, null, 1, 'span', null, null, null, null,
() => compViewDef([anchorDef(NodeFlags.None, null, null, 0)])), () => compViewDef([anchorDef(NodeFlags.None, null, null, 0)])),
directiveDef(NodeFlags.IsComponent, null, 0, SomeService, [Renderer]) directiveDef(NodeFlags.Component, null, 0, SomeService, [Renderer])
])); ]));
expect(instance.dep.createElement).toBeTruthy(); expect(instance.dep.createElement).toBeTruthy();
@ -303,7 +301,7 @@ export function main() {
elementDef( elementDef(
NodeFlags.None, null, null, 1, 'span', null, null, null, null, NodeFlags.None, null, null, 1, 'span', null, null, null, null,
() => compViewDef([anchorDef(NodeFlags.None, null, null, 0)])), () => compViewDef([anchorDef(NodeFlags.None, null, null, 0)])),
directiveDef(NodeFlags.IsComponent, null, 0, SomeService, [RendererV2]) directiveDef(NodeFlags.Component, null, 0, SomeService, [RendererV2])
])); ]));
expect(instance.dep.createElement).toBeTruthy(); expect(instance.dep.createElement).toBeTruthy();
@ -317,7 +315,7 @@ export function main() {
describe('data binding', () => { describe('data binding', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should update ${ArgumentType[inlineDynamic]}`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
let instance: SomeService; let instance: SomeService;
class SomeService { class SomeService {

View File

@ -33,7 +33,7 @@ export function main() {
describe('pure arrays', () => { describe('pure arrays', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should support ${ArgumentType[inlineDynamic]} bindings`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
let values: any[]; let values: any[];
const {view, rootNodes} = createAndGetRootNodes(compViewDef( const {view, rootNodes} = createAndGetRootNodes(compViewDef(
@ -70,7 +70,7 @@ export function main() {
describe('pure objects', () => { describe('pure objects', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should support ${ArgumentType[inlineDynamic]} bindings`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
let values: any[]; let values: any[];
const {view, rootNodes} = createAndGetRootNodes(compViewDef( const {view, rootNodes} = createAndGetRootNodes(compViewDef(
@ -106,7 +106,7 @@ export function main() {
describe('pure pipes', () => { describe('pure pipes', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should support ${ArgumentType[inlineDynamic]} bindings`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
class SomePipe implements PipeTransform { class SomePipe implements PipeTransform {
transform(v1: any, v2: any) { return [v1 + 10, v2 + 20]; } transform(v1: any, v2: any) { return [v1 + 10, v2 + 20]; }
} }

View File

@ -45,7 +45,7 @@ export function main() {
return [ return [
directiveDef(NodeFlags.None, null, 1, QueryService, []), directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef( queryDef(
NodeFlags.HasContentQuery | NodeFlags.HasDynamicQuery, someQueryId, NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.All}) {'a': QueryBindingType.All})
]; ];
} }
@ -56,11 +56,11 @@ export function main() {
NodeFlags.None, null, null, 1 + extraChildCount, 'div', null, null, null, null, NodeFlags.None, null, null, 1 + extraChildCount, 'div', null, null, null, null,
() => compViewDef([ () => compViewDef([
queryDef( queryDef(
NodeFlags.HasViewQuery | NodeFlags.HasDynamicQuery, someQueryId, NodeFlags.TypeViewQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.All}), {'a': QueryBindingType.All}),
...nodes ...nodes
])), ])),
directiveDef(NodeFlags.IsComponent, null, 0, QueryService, [], null, null, ), directiveDef(NodeFlags.Component, null, 0, QueryService, [], null, null, ),
]; ];
} }
@ -148,7 +148,7 @@ export function main() {
const {view} = createAndGetRootNodes(compViewDef([ const {view} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 5, 'div'), elementDef(NodeFlags.None, null, null, 5, 'div'),
...contentQueryProviders(), ...contentQueryProviders(),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 2, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 2, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
aServiceProvider(), aServiceProvider(),
])), ])),
@ -174,13 +174,13 @@ export function main() {
const {view} = createAndGetRootNodes(compViewDef([ const {view} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 3, 'div'), elementDef(NodeFlags.None, null, null, 3, 'div'),
...contentQueryProviders(), ...contentQueryProviders(),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
aServiceProvider(), aServiceProvider(),
])), ])),
elementDef(NodeFlags.None, null, null, 3, 'div'), elementDef(NodeFlags.None, null, null, 3, 'div'),
...contentQueryProviders(), ...contentQueryProviders(),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0), anchorDef(NodeFlags.EmbeddedViews, null, null, 0),
])); ]));
const childView = Services.createEmbeddedView(view, view.def.nodes[3]); const childView = Services.createEmbeddedView(view, view.def.nodes[3]);
@ -203,7 +203,7 @@ export function main() {
const {view} = createAndGetRootNodes(compViewDef([ const {view} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 3, 'div'), elementDef(NodeFlags.None, null, null, 3, 'div'),
...contentQueryProviders(), ...contentQueryProviders(),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
aServiceProvider(), aServiceProvider(),
])), ])),
@ -232,7 +232,7 @@ export function main() {
...compViewQueryProviders( ...compViewQueryProviders(
0, 0,
[ [
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
aServiceProvider(), aServiceProvider(),
])), ])),
@ -268,7 +268,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 4, 'div'), elementDef(NodeFlags.None, null, null, 4, 'div'),
directiveDef(NodeFlags.None, null, 1, QueryService, []), directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef( queryDef(
NodeFlags.HasContentQuery | NodeFlags.HasDynamicQuery, someQueryId, NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.All}), {'a': QueryBindingType.All}),
aServiceProvider(), aServiceProvider(),
aServiceProvider(), aServiceProvider(),
@ -293,7 +293,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 4, 'div'), elementDef(NodeFlags.None, null, null, 4, 'div'),
directiveDef(NodeFlags.None, null, 1, QueryService, []), directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef( queryDef(
NodeFlags.HasContentQuery | NodeFlags.HasDynamicQuery, someQueryId, NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.First}), {'a': QueryBindingType.First}),
aServiceProvider(), aServiceProvider(),
aServiceProvider(), aServiceProvider(),
@ -316,7 +316,7 @@ export function main() {
elementDef(NodeFlags.None, [[someQueryId, QueryValueType.ElementRef]], null, 2, 'div'), elementDef(NodeFlags.None, [[someQueryId, QueryValueType.ElementRef]], null, 2, 'div'),
directiveDef(NodeFlags.None, null, 1, QueryService, []), directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef( queryDef(
NodeFlags.HasContentQuery | NodeFlags.HasDynamicQuery, someQueryId, NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.First}), {'a': QueryBindingType.First}),
])); ]));
@ -337,7 +337,7 @@ export function main() {
embeddedViewDef([anchorDef(NodeFlags.None, null, null, 0)])), embeddedViewDef([anchorDef(NodeFlags.None, null, null, 0)])),
directiveDef(NodeFlags.None, null, 1, QueryService, []), directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef( queryDef(
NodeFlags.HasContentQuery | NodeFlags.HasDynamicQuery, someQueryId, NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.First}), {'a': QueryBindingType.First}),
])); ]));
@ -356,7 +356,7 @@ export function main() {
anchorDef(NodeFlags.None, [[someQueryId, QueryValueType.ViewContainerRef]], null, 2), anchorDef(NodeFlags.None, [[someQueryId, QueryValueType.ViewContainerRef]], null, 2),
directiveDef(NodeFlags.None, null, 1, QueryService, []), directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef( queryDef(
NodeFlags.HasContentQuery | NodeFlags.HasDynamicQuery, someQueryId, NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.First}), {'a': QueryBindingType.First}),
])); ]));
@ -372,7 +372,7 @@ export function main() {
const {view} = createAndGetRootNodes(compViewDef([ const {view} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 3, 'div'), elementDef(NodeFlags.None, null, null, 3, 'div'),
...contentQueryProviders(), ...contentQueryProviders(),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, null, embeddedViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, embeddedViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div'), elementDef(NodeFlags.None, null, null, 1, 'div'),
aServiceProvider(), aServiceProvider(),
])), ])),
@ -408,7 +408,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 3, 'div'), elementDef(NodeFlags.None, null, null, 3, 'div'),
directiveDef(NodeFlags.None, null, 1, QueryService, []), directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef( queryDef(
NodeFlags.HasContentQuery | NodeFlags.HasDynamicQuery, someQueryId, NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.All}), {'a': QueryBindingType.All}),
aServiceProvider(), aServiceProvider(),
])); ]));

View File

@ -41,7 +41,7 @@ export function main() {
elementDef(NodeFlags.None, [['ref', QueryValueType.ElementRef]], null, 2, 'span'), elementDef(NodeFlags.None, [['ref', QueryValueType.ElementRef]], null, 2, 'span'),
directiveDef(NodeFlags.None, null, 0, AService, []), textDef(null, ['a']) directiveDef(NodeFlags.None, null, 0, AService, []), textDef(null, ['a'])
])), ])),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, []), directiveDef(NodeFlags.Component, null, 0, AComp, []),
])); ]));
return view; return view;
} }

View File

@ -62,7 +62,7 @@ export function main() {
describe('change text', () => { describe('change text', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => { ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should update ${ArgumentType[inlineDynamic]}`, () => { it(`should update via strategy ${inlineDynamic}`, () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef( const {view, rootNodes} = createAndGetRootNodes(compViewDef(
[ [
textDef(null, ['0', '1', '2']), textDef(null, ['0', '1', '2']),

View File

@ -128,7 +128,9 @@ export function main() {
directiveDef(NodeFlags.AfterContentChecked, null, 0, AService, []) directiveDef(NodeFlags.AfterContentChecked, null, 0, AService, [])
]); ]);
expect(childFlags(vd)).toEqual([NodeFlags.AfterContentChecked, NodeFlags.None]); expect(childFlags(vd)).toEqual([
NodeFlags.TypeDirective | NodeFlags.AfterContentChecked, NodeFlags.None
]);
}); });
it('should calculate childFlags for two levels', () => { it('should calculate childFlags for two levels', () => {
@ -139,7 +141,8 @@ export function main() {
]); ]);
expect(childFlags(vd)).toEqual([ expect(childFlags(vd)).toEqual([
NodeFlags.AfterContentChecked, NodeFlags.AfterContentChecked, NodeFlags.None NodeFlags.TypeElement | NodeFlags.TypeDirective | NodeFlags.AfterContentChecked,
NodeFlags.TypeDirective | NodeFlags.AfterContentChecked, NodeFlags.None
]); ]);
}); });
@ -153,8 +156,9 @@ export function main() {
]); ]);
expect(childFlags(vd)).toEqual([ expect(childFlags(vd)).toEqual([
NodeFlags.AfterContentChecked, NodeFlags.None, NodeFlags.TypeDirective | NodeFlags.AfterContentChecked, NodeFlags.None,
NodeFlags.AfterContentInit | NodeFlags.AfterViewChecked, NodeFlags.None, NodeFlags.None NodeFlags.TypeDirective | NodeFlags.AfterContentInit | NodeFlags.AfterViewChecked,
NodeFlags.None, NodeFlags.None
]); ]);
}); });
@ -169,8 +173,10 @@ export function main() {
]); ]);
expect(childFlags(vd)).toEqual([ expect(childFlags(vd)).toEqual([
NodeFlags.AfterContentChecked, NodeFlags.AfterContentChecked, NodeFlags.None, NodeFlags.TypeElement | NodeFlags.TypeDirective | NodeFlags.AfterContentChecked,
NodeFlags.AfterContentInit | NodeFlags.AfterViewInit, NodeFlags.None, NodeFlags.None NodeFlags.TypeDirective | NodeFlags.AfterContentChecked, NodeFlags.None,
NodeFlags.TypeDirective | NodeFlags.AfterContentInit | NodeFlags.AfterViewInit,
NodeFlags.None, NodeFlags.None
]); ]);
}); });
}); });

View File

@ -27,7 +27,7 @@ let viewFlags = ViewFlags.None;
function TreeComponent_Host(): ViewDefinition { function TreeComponent_Host(): ViewDefinition {
return viewDef(viewFlags, [ return viewDef(viewFlags, [
elementDef(NodeFlags.None, null, null, 1, 'tree', null, null, null, null, TreeComponent_0), elementDef(NodeFlags.None, null, null, 1, 'tree', null, null, null, null, TreeComponent_0),
directiveDef(NodeFlags.IsComponent, null, 0, TreeComponent, []), directiveDef(NodeFlags.Component, null, 0, TreeComponent, []),
]); ]);
} }
@ -36,7 +36,7 @@ function TreeComponent_1() {
viewFlags, viewFlags,
[ [
elementDef(NodeFlags.None, null, null, 1, 'tree', null, null, null, null, TreeComponent_0), elementDef(NodeFlags.None, null, null, 1, 'tree', null, null, null, null, TreeComponent_0),
directiveDef(NodeFlags.IsComponent, null, 0, TreeComponent, [], {data: [0, 'data']}), directiveDef(NodeFlags.Component, null, 0, TreeComponent, [], {data: [0, 'data']}),
], ],
(check, view) => { (check, view) => {
const cmp = view.component; const cmp = view.component;
@ -49,7 +49,7 @@ function TreeComponent_2() {
viewFlags, viewFlags,
[ [
elementDef(NodeFlags.None, null, null, 1, 'tree', null, null, null, null, TreeComponent_0), elementDef(NodeFlags.None, null, null, 1, 'tree', null, null, null, null, TreeComponent_0),
directiveDef(NodeFlags.IsComponent, null, 0, TreeComponent, [], {data: [0, 'data']}), directiveDef(NodeFlags.Component, null, 0, TreeComponent, [], {data: [0, 'data']}),
], ],
(check, view) => { (check, view) => {
const cmp = view.component; const cmp = view.component;
@ -65,10 +65,10 @@ function TreeComponent_0(): ViewDefinition {
NodeFlags.None, null, null, 1, 'span', null, NodeFlags.None, null, null, 1, 'span', null,
[[BindingType.ElementStyle, 'backgroundColor', null]]), [[BindingType.ElementStyle, 'backgroundColor', null]]),
textDef(null, [' ', ' ']), textDef(null, [' ', ' ']),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 1, null, TreeComponent_1), anchorDef(NodeFlags.EmbeddedViews, null, null, 1, null, TreeComponent_1),
directiveDef( directiveDef(
NodeFlags.None, null, 0, NgIf, [ViewContainerRef, TemplateRef], {ngIf: [0, 'ngIf']}), NodeFlags.None, null, 0, NgIf, [ViewContainerRef, TemplateRef], {ngIf: [0, 'ngIf']}),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 1, null, TreeComponent_2), anchorDef(NodeFlags.EmbeddedViews, null, null, 1, null, TreeComponent_2),
directiveDef( directiveDef(
NodeFlags.None, null, 0, NgIf, [ViewContainerRef, TemplateRef], {ngIf: [0, 'ngIf']}), NodeFlags.None, null, 0, NgIf, [ViewContainerRef, TemplateRef], {ngIf: [0, 'ngIf']}),
], ],