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
*/
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 {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!
const queryId = queryIndex + 1;
const bindingType = query.first ? QueryBindingType.First : QueryBindingType.All;
let flags = NodeFlags.HasViewQuery;
let flags = NodeFlags.TypeViewQuery;
if (queryIds.staticQueryIds.has(queryId)) {
flags |= NodeFlags.HasStaticQuery;
flags |= NodeFlags.StaticQuery;
} else {
flags |= NodeFlags.HasDynamicQuery;
flags |= NodeFlags.DynamicQuery;
}
this.nodeDefs.push(() => o.importExpr(createIdentifier(Identifiers.queryDef)).callFn([
o.literal(flags), o.literal(queryId),
@ -359,7 +359,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
} {
let flags = NodeFlags.None;
if (ast.hasViewContainer) {
flags |= NodeFlags.HasEmbeddedViews;
flags |= NodeFlags.EmbeddedViews;
}
const usedEvents = new Map<string, [string, string]>();
ast.outputs.forEach((event) => {
@ -450,14 +450,14 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
this.nodeDefs.push(null);
dirAst.directive.queries.forEach((query, queryIndex) => {
let flags = NodeFlags.HasContentQuery;
let flags = NodeFlags.TypeContentQuery;
const queryId = dirAst.contentQueryStartId + queryIndex;
// Note: We only make queries static that query for a single item.
// This is because of backwards compatibility with the old view compiler...
if (queryIds.staticQueryIds.has(queryId) && query.first) {
flags |= NodeFlags.HasStaticQuery;
flags |= NodeFlags.StaticQuery;
} else {
flags |= NodeFlags.HasDynamicQuery;
flags |= NodeFlags.DynamicQuery;
}
const bindingType = query.first ? QueryBindingType.First : QueryBindingType.All;
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.
const childCount = this.nodeDefs.length - nodeIndex - 1;
let {flags, queryMatchExprs, providerExpr, providerType, depsExpr} =
let {flags, queryMatchExprs, providerExpr, depsExpr} =
this._visitProviderOrDirective(providerAst, queryMatches);
refs.forEach((ref) => {
@ -484,7 +484,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
});
if (dirAst.directive.isComponent) {
flags |= NodeFlags.IsComponent;
flags |= NodeFlags.Component;
}
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
this.nodeDefs.push(null);
const {flags, queryMatchExprs, providerExpr, providerType, depsExpr} =
const {flags, queryMatchExprs, providerExpr, depsExpr} =
this._visitProviderOrDirective(providerAst, queryMatches);
// providerDef(
// flags: NodeFlags, matchedQueries: [string, QueryValueType][], type: ProviderType, token:
// any,
// flags: NodeFlags, matchedQueries: [string, QueryValueType][], token:any,
// value: any, deps: ([DepFlags, any] | any)[]): NodeDef;
const nodeDef = () => o.importExpr(createIdentifier(Identifiers.providerDef)).callFn([
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;
}
@ -561,7 +560,6 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
flags: NodeFlags,
queryMatchExprs: o.Expression[],
providerExpr: o.Expression,
providerType: ProviderType,
depsExpr: o.Expression
} {
let flags = NodeFlags.None;
@ -587,8 +585,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
o.literalArr([o.literal(match.queryId), o.literal(QueryValueType.Provider)]));
}
});
const {providerExpr, providerType, depsExpr} = providerDef(providerAst);
return {flags, queryMatchExprs, providerExpr, providerType, depsExpr};
const {providerExpr, depsExpr, flags: providerType} = providerDef(providerAst);
return {flags: flags | providerType, queryMatchExprs, providerExpr, depsExpr};
}
getLocal(name: string): o.Expression {
@ -768,13 +766,14 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
}
function providerDef(providerAst: ProviderAst):
{providerExpr: o.Expression, providerType: ProviderType, depsExpr: o.Expression} {
return providerAst.multiProvider ? multiProviderDef(providerAst.providers) :
singleProviderDef(providerAst.providers[0]);
{providerExpr: o.Expression, flags: NodeFlags, depsExpr: o.Expression} {
return providerAst.multiProvider ?
multiProviderDef(providerAst.providers) :
singleProviderDef(providerAst.providerType, providerAst.providers[0]);
}
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 allParams: o.FnParam[] = [];
const exprs = providers.map((provider, providerIndex) => {
@ -795,7 +794,7 @@ function multiProviderDef(providers: CompileProviderMetadata[]):
});
const providerExpr =
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[]) {
return deps.map((dep, depIndex) => {
@ -807,30 +806,36 @@ function multiProviderDef(providers: CompileProviderMetadata[]):
}
}
function singleProviderDef(providerMeta: CompileProviderMetadata):
{providerExpr: o.Expression, providerType: ProviderType, depsExpr: o.Expression} {
function singleProviderDef(providerType: ProviderAstType, providerMeta: CompileProviderMetadata):
{providerExpr: o.Expression, flags: NodeFlags, depsExpr: o.Expression} {
let providerExpr: o.Expression;
let providerType: ProviderType;
let flags: NodeFlags;
let deps: CompileDiDependencyMetadata[];
if (providerMeta.useClass) {
if (providerType === ProviderAstType.Directive || providerType === ProviderAstType.Component) {
providerExpr = o.importExpr(providerMeta.useClass);
providerType = ProviderType.Class;
flags = NodeFlags.TypeDirective;
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 {
providerExpr = convertValueToOutputAst(providerMeta.useValue);
providerType = ProviderType.Value;
deps = [];
if (providerMeta.useClass) {
providerExpr = o.importExpr(providerMeta.useClass);
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)));
return {providerExpr, providerType, depsExpr};
return {providerExpr, flags, depsExpr};
}
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 {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 {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 {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';
const NOOP: any = () => {};
@ -22,13 +22,13 @@ export function anchorDef(
if (!handleEvent) {
handleEvent = NOOP;
}
flags |= NodeFlags.TypeElement;
const {matchedQueries, references, matchedQueryIds} = splitMatchedQueriesDsl(matchedQueriesDsl);
// skip the call to sliceErrorStack itself + the call to this function.
const source = isDevMode() ? sliceErrorStack(2, 3) : '';
const template = templateFactory ? resolveViewDefinition(templateFactory) : null;
return {
type: NodeType.Element,
// will bet set by the view definition
index: undefined,
reverseChildIndex: undefined,
@ -54,7 +54,6 @@ export function anchorDef(
},
provider: undefined,
text: undefined,
pureExpression: undefined,
query: undefined,
ngContent: undefined
};
@ -126,10 +125,10 @@ export function elementDef(
componentRendererType = null;
}
if (componentView) {
flags |= NodeFlags.HasComponent;
flags |= NodeFlags.ComponentView;
}
flags |= NodeFlags.TypeElement;
return {
type: NodeType.Element,
// will bet set by the view definition
index: undefined,
reverseChildIndex: undefined,
@ -156,7 +155,6 @@ export function elementDef(
},
provider: undefined,
text: undefined,
pureExpression: undefined,
query: undefined,
ngContent: undefined
};

View File

@ -6,12 +6,11 @@
* 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';
export function ngContentDef(ngContentIndex: number, index: number): NodeDef {
return {
type: NodeType.NgContent,
// will bet set by the view definition
index: undefined,
reverseChildIndex: undefined,
@ -20,7 +19,7 @@ export function ngContentDef(ngContentIndex: number, index: number): NodeDef {
bindingIndex: undefined,
outputIndex: undefined,
// regular values
flags: 0,
flags: NodeFlags.TypeNgContent,
childFlags: 0,
childMatchedQueries: 0,
matchedQueries: {},
@ -32,7 +31,6 @@ export function ngContentDef(ngContentIndex: number, index: number): NodeDef {
element: undefined,
provider: undefined,
text: undefined,
pureExpression: undefined,
query: undefined,
ngContent: {index}
};

View File

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

View File

@ -6,23 +6,23 @@
* 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';
export function purePipeDef(argCount: number): NodeDef {
// 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 {
return _pureExpressionDef(PureExpressionType.Array, new Array(argCount));
return _pureExpressionDef(NodeFlags.TypePureArray, new Array(argCount));
}
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);
for (let i = 0; i < propertyNames.length; i++) {
const prop = propertyNames[i];
@ -36,7 +36,6 @@ function _pureExpressionDef(type: PureExpressionType, propertyNames: string[]):
};
}
return {
type: NodeType.PureExpression,
// will bet set by the view definition
index: undefined,
reverseChildIndex: undefined,
@ -45,7 +44,7 @@ function _pureExpressionDef(type: PureExpressionType, propertyNames: string[]):
bindingIndex: undefined,
outputIndex: undefined,
// regular values
flags: 0,
flags,
childFlags: 0,
childMatchedQueries: 0,
matchedQueries: {},
@ -57,7 +56,6 @@ function _pureExpressionDef(type: PureExpressionType, propertyNames: string[]):
element: undefined,
provider: undefined,
text: undefined,
pureExpression: {type},
query: undefined,
ngContent: undefined
};
@ -87,8 +85,8 @@ export function checkAndUpdatePureExpressionInline(
if (changed) {
const data = asPureExpressionData(view, def.index);
let value: any;
switch (def.pureExpression.type) {
case PureExpressionType.Array:
switch (def.flags & NodeFlags.Types) {
case NodeFlags.TypePureArray:
value = new Array(bindings.length);
if (bindLen > 0) value[0] = v0;
if (bindLen > 1) value[1] = v1;
@ -101,7 +99,7 @@ export function checkAndUpdatePureExpressionInline(
if (bindLen > 8) value[8] = v8;
if (bindLen > 9) value[9] = v9;
break;
case PureExpressionType.Object:
case NodeFlags.TypePureObject:
value = {};
if (bindLen > 0) value[bindings[0].name] = v0;
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 > 9) value[bindings[9].name] = v9;
break;
case PureExpressionType.Pipe:
case NodeFlags.TypePurePipe:
const pipe = v0;
switch (bindLen) {
case 1:
@ -169,17 +167,17 @@ export function checkAndUpdatePureExpressionDynamic(
if (changed) {
const data = asPureExpressionData(view, def.index);
let value: any;
switch (def.pureExpression.type) {
case PureExpressionType.Array:
switch (def.flags & NodeFlags.Types) {
case NodeFlags.TypePureArray:
value = values;
break;
case PureExpressionType.Object:
case NodeFlags.TypePureObject:
value = {};
for (let i = 0; i < values.length; i++) {
value[bindings[i].name] = values[i];
}
break;
case PureExpressionType.Pipe:
case NodeFlags.TypePurePipe:
const pipe = values[0];
const params = values.slice(1);
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 {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';
export function queryDef(
@ -24,7 +24,6 @@ export function queryDef(
}
return {
type: NodeType.Query,
// will bet set by the view definition
index: undefined,
reverseChildIndex: undefined,
@ -46,7 +45,6 @@ export function queryDef(
element: undefined,
provider: undefined,
text: undefined,
pureExpression: undefined,
query: {id, filterId: filterQueryId(id), bindings: bindingDefs},
ngContent: undefined
};
@ -65,14 +63,14 @@ export function dirtyParentQueries(view: ViewData) {
const end = tplDef.index + tplDef.childCount;
for (let i = 0; i <= end; i++) {
const nodeDef = view.def.nodes[i];
if ((nodeDef.flags & NodeFlags.HasContentQuery) &&
(nodeDef.flags & NodeFlags.HasDynamicQuery) &&
if ((nodeDef.flags & NodeFlags.TypeContentQuery) &&
(nodeDef.flags & NodeFlags.DynamicQuery) &&
(nodeDef.query.filterId & queryIds) === nodeDef.query.filterId) {
asQueryList(view, i).setDirty();
}
if ((nodeDef.type === NodeType.Element && i + nodeDef.childCount < tplDef.index) ||
!(nodeDef.childFlags & NodeFlags.HasContentQuery) ||
!(nodeDef.childFlags & NodeFlags.HasDynamicQuery)) {
if ((nodeDef.flags & NodeFlags.TypeElement && i + nodeDef.childCount < tplDef.index) ||
!(nodeDef.childFlags & NodeFlags.TypeContentQuery) ||
!(nodeDef.childFlags & NodeFlags.DynamicQuery)) {
// skip elements that don't contain the template element or no query.
i += nodeDef.childCount;
}
@ -80,10 +78,10 @@ export function dirtyParentQueries(view: ViewData) {
}
// view queries
if (view.def.nodeFlags & NodeFlags.HasViewQuery) {
if (view.def.nodeFlags & NodeFlags.TypeViewQuery) {
for (let i = 0; i < view.def.nodes.length; 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();
}
// only visit the root nodes
@ -99,12 +97,12 @@ export function checkAndUpdateQuery(view: ViewData, nodeDef: NodeDef) {
}
let directiveInstance: any;
let newValues: any[];
if (nodeDef.flags & NodeFlags.HasContentQuery) {
if (nodeDef.flags & NodeFlags.TypeContentQuery) {
const elementDef = nodeDef.parent.parent;
newValues = calcQueryValues(
view, elementDef.index, elementDef.index + elementDef.childCount, nodeDef.query, []);
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, []);
directiveInstance = view.component;
}
@ -139,7 +137,7 @@ function calcQueryValues(
if (valueType != null) {
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) {
// check embedded views that were attached at the place of their template.
const elementData = asElementData(view, i);

View File

@ -19,7 +19,7 @@ import {Renderer as RendererV1, RendererV2} from '../render/api';
import {Type} from '../type';
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 {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView, renderDetachView} from './view_attach';
@ -251,7 +251,7 @@ export function createInjector(view: ViewData, elDef: NodeDef): Injector {
class Injector_ implements Injector {
constructor(private view: ViewData, private elDef: NodeDef) {}
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(
this.view, this.elDef, allowPrivateServices,
{flags: DepFlags.None, token, tokenKey: tokenKey(token)}, notFoundValue);
@ -260,21 +260,18 @@ class Injector_ implements Injector {
export function nodeValue(view: ViewData, index: number): any {
const def = view.def.nodes[index];
switch (def.type) {
case NodeType.Element:
if (def.element.template) {
return createTemplateRef(view, def);
} else {
return asElementData(view, def.index).renderElement;
}
case NodeType.Text:
return asTextData(view, def.index).renderText;
case NodeType.Directive:
case NodeType.Pipe:
case NodeType.Provider:
return asProviderData(view, def.index).instance;
if (def.flags & NodeFlags.TypeElement) {
if (def.element.template) {
return createTemplateRef(view, def);
} else {
return asElementData(view, def.index).renderElement;
}
} else if (def.flags & NodeFlags.TypeText) {
return asTextData(view, def.index).renderText;
} else if (def.flags & (NodeFlags.CatProvider | NodeFlags.TypePipe)) {
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 {

View File

@ -16,7 +16,7 @@ import {isViewDebugError, viewDestroyedError, viewWrappedDebugError} from './err
import {resolveDep} from './provider';
import {dirtyParentQueries, getQueryValue} from './query';
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 {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 {
const nodeDef = view.def.nodes[nodeIndex];
checkAndUpdateNode(view, nodeDef, argStyle, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
return (nodeDef.type === NodeType.PureExpression) ? asPureExpressionData(view, nodeIndex).value :
undefined;
return (nodeDef.flags & NodeFlags.CatPureExpression) ?
asPureExpressionData(view, nodeIndex).value :
undefined;
}
function prodCheckNoChangesNode(
@ -123,8 +124,9 @@ function prodCheckNoChangesNode(
v3?: any, v4?: any, v5?: any, v6?: any, v7?: any, v8?: any, v9?: any): any {
const nodeDef = view.def.nodes[nodeIndex];
checkNoChangesNode(view, nodeDef, argStyle, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
return (nodeDef.type === NodeType.PureExpression) ? asPureExpressionData(view, nodeIndex).value :
undefined;
return (nodeDef.flags & NodeFlags.CatPureExpression) ?
asPureExpressionData(view, nodeIndex).value :
undefined;
}
function debugCreateEmbeddedView(parent: ViewData, anchorDef: NodeDef, context?: any): ViewData {
@ -182,10 +184,10 @@ function debugUpdateDirectives(view: ViewData, checkType: CheckType) {
} else {
debugCheckNoChangesNode(view, nodeDef, argStyle, values);
}
if (nodeDef.type === NodeType.Directive) {
if (nodeDef.flags & NodeFlags.TypeDirective) {
debugSetCurrentNode(view, nextDirectiveWithBinding(view, nodeIndex));
}
return (nodeDef.type === NodeType.PureExpression) ?
return (nodeDef.flags & NodeFlags.CatPureExpression) ?
asPureExpressionData(view, nodeDef.index).value :
undefined;
};
@ -206,10 +208,10 @@ function debugUpdateRenderer(view: ViewData, checkType: CheckType) {
} else {
debugCheckNoChangesNode(view, nodeDef, argStyle, values);
}
if (nodeDef.type === NodeType.Element || nodeDef.type === NodeType.Text) {
if (nodeDef.flags & NodeFlags.CatRenderNode) {
debugSetCurrentNode(view, nextRenderNodeWithBinding(view, nodeIndex));
}
return (nodeDef.type === NodeType.PureExpression) ?
return (nodeDef.flags & NodeFlags.CatPureExpression) ?
asPureExpressionData(view, nodeDef.index).value :
undefined;
}
@ -220,19 +222,18 @@ function debugCheckAndUpdateNode(
const changed = (<any>checkAndUpdateNode)(view, nodeDef, argStyle, ...givenValues);
if (changed) {
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} = {};
for (let i = 0; i < nodeDef.bindings.length; i++) {
const binding = nodeDef.bindings[i];
const value = values[i];
if ((binding.type === BindingType.ElementProperty ||
binding.type === BindingType.ComponentHostProperty ||
if ((binding.type === BindingType.ComponentHostProperty ||
binding.type === BindingType.DirectiveProperty)) {
bindingValues[normalizeDebugBindingName(binding.nonMinifiedName)] =
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;
if (!elDef.element.name) {
// a comment.
@ -281,7 +282,7 @@ function normalizeDebugBindingValue(value: any): string {
function nextDirectiveWithBinding(view: ViewData, nodeIndex: number): number {
for (let i = nodeIndex; i < view.def.nodes.length; 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;
}
}
@ -291,8 +292,7 @@ function nextDirectiveWithBinding(view: ViewData, nodeIndex: number): number {
function nextRenderNodeWithBinding(view: ViewData, nodeIndex: number): number {
for (let i = nodeIndex; i < view.def.nodes.length; i++) {
const nodeDef = view.def.nodes[i];
if ((nodeDef.type === NodeType.Element || nodeDef.type === NodeType.Text) && nodeDef.bindings &&
nodeDef.bindings.length) {
if ((nodeDef.flags & NodeFlags.CatRenderNode) && nodeDef.bindings && nodeDef.bindings.length) {
return i;
}
}
@ -310,7 +310,7 @@ class DebugContext_ implements DebugContext {
this.nodeDef = view.def.nodes[nodeIndex];
let elDef = this.nodeDef;
let elView = view;
while (elDef && elDef.type !== NodeType.Element) {
while (elDef && (elDef.flags & NodeFlags.TypeElement) === 0) {
elDef = elDef.parent;
}
if (!elDef) {
@ -334,7 +334,7 @@ class DebugContext_ implements DebugContext {
if (this.elDef) {
for (let i = this.elDef.index + 1; i <= this.elDef.index + this.elDef.childCount; 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);
}
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++) {
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);
}
i += childDef.childCount;
@ -358,7 +358,7 @@ class DebugContext_ implements DebugContext {
return references;
}
get source(): string {
if (this.nodeDef.type === NodeType.Text) {
if (this.nodeDef.flags & NodeFlags.TypeText) {
return this.nodeDef.text.source;
} else {
return this.elDef.element.source;
@ -369,8 +369,8 @@ class DebugContext_ implements DebugContext {
return elData ? elData.renderElement : undefined;
}
get renderNode(): any {
return this.nodeDef.type === NodeType.Text ? renderNode(this.view, this.nodeDef) :
renderNode(this.elView, this.elDef);
return this.nodeDef.flags & NodeFlags.TypeText ? renderNode(this.view, this.nodeDef) :
renderNode(this.elView, this.elDef);
}
}

View File

@ -9,7 +9,7 @@
import {isDevMode} from '../application_ref';
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';
export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
@ -26,8 +26,8 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
suffix: constants[i]
};
}
const flags = NodeFlags.TypeText;
return {
type: NodeType.Text,
// will bet set by the view definition
index: undefined,
reverseChildIndex: undefined,
@ -36,7 +36,7 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
bindingIndex: undefined,
outputIndex: undefined,
// regular values
flags: 0,
flags,
childFlags: 0,
childMatchedQueries: 0,
matchedQueries: {},
@ -47,7 +47,6 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
element: undefined,
provider: undefined,
text: {prefix: constants[0], source},
pureExpression: undefined,
query: undefined,
ngContent: undefined
};

View File

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

View File

@ -18,7 +18,7 @@ import {ViewEncapsulation} from '../metadata/view';
import {Renderer, RendererTypeV2} from '../render/api';
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>();
@ -128,10 +128,10 @@ export function viewParentEl(view: ViewData): NodeDef {
}
export function renderNode(view: ViewData, def: NodeDef): any {
switch (def.type) {
case NodeType.Element:
switch (def.flags & NodeFlags.Types) {
case NodeFlags.TypeElement:
return asElementData(view, def.index).renderElement;
case NodeType.Text:
case NodeFlags.TypeText:
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 {
let renderParent = def.renderParent;
if (renderParent) {
if (renderParent.type !== NodeType.Element ||
(renderParent.flags & NodeFlags.HasComponent) === 0 ||
if ((renderParent.flags & NodeFlags.TypeElement) === 0 ||
(renderParent.flags & NodeFlags.ComponentView) === 0 ||
(renderParent.element.componentRendererType &&
renderParent.element.componentRendererType.encapsulation === ViewEncapsulation.Native)) {
// only children of non components, or children of components with native encapsulation should
@ -245,8 +245,7 @@ export function visitSiblingRenderNodes(
nextSibling: any, target: any[]) {
for (let i = startIndex; i <= endIndex; i++) {
const nodeDef = view.def.nodes[i];
if (nodeDef.type === NodeType.Element || nodeDef.type === NodeType.Text ||
nodeDef.type === NodeType.NgContent) {
if (nodeDef.flags & (NodeFlags.TypeElement | NodeFlags.TypeText | NodeFlags.TypeNgContent)) {
visitRenderNode(view, nodeDef, action, parentNode, nextSibling, target);
}
// jump to next sibling
@ -287,13 +286,13 @@ export function visitProjectedRenderNodes(
function visitRenderNode(
view: ViewData, nodeDef: NodeDef, action: RenderNodeAction, parentNode: any, nextSibling: any,
target: any[]) {
if (nodeDef.type === NodeType.NgContent) {
if (nodeDef.flags & NodeFlags.TypeNgContent) {
visitProjectedRenderNodes(
view, nodeDef.ngContent.index, action, parentNode, nextSibling, target);
} else {
const rn = renderNode(view, nodeDef);
execRenderNodeAction(view, rn, action, parentNode, nextSibling, target);
if (nodeDef.flags & NodeFlags.HasEmbeddedViews) {
if (nodeDef.flags & NodeFlags.EmbeddedViews) {
const embeddedViews = asElementData(view, nodeDef.index).embeddedViews;
if (embeddedViews) {
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(
view, action, nodeDef.index + 1, nodeDef.index + nodeDef.childCount, parentNode,
nextSibling, target);

View File

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

View File

@ -6,7 +6,7 @@
* 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';
export function attachEmbeddedView(

View File

@ -40,7 +40,7 @@ export function main() {
() => compViewDef([
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;
@ -123,7 +123,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 0, 'span', null, [[BindingType.ElementAttribute, 'a', SecurityContext.NONE]]),
], null, update
)),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, []),
directiveDef(NodeFlags.Component, null, 0, AComp, []),
]));
const compView = asElementData(view, 0).componentView;
@ -159,7 +159,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 0, 'span'),
],
update)),
directiveDef(NodeFlags.IsComponent, null, 0, AComp, [], null, null),
directiveDef(NodeFlags.Component, null, 0, AComp, [], null, null),
]));
const compView = asElementData(view, 0).componentView;
@ -201,7 +201,7 @@ export function main() {
],
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); }));
@ -251,7 +251,7 @@ export function main() {
],
null, update)),
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'),
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);

View File

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

View File

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

View File

@ -33,7 +33,7 @@ export function main() {
elementDef(
NodeFlags.None, null, null, 1 + contentNodes.length, 'acomp', null, null, null, null,
() => 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(
[
anchorDef(NodeFlags.HasEmbeddedViews, null, 0, 1, null, embeddedViewDef([textDef(
null, ['a'])])),
anchorDef(
NodeFlags.EmbeddedViews, null, 0, 1, null, embeddedViewDef([textDef(null, ['a'])])),
directiveDef(
NodeFlags.None, null, 0, CreateViewService, [TemplateRef, ViewContainerRef])
],
@ -104,7 +104,7 @@ export function main() {
it('should include projected nodes when attaching / detaching embedded views', () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef([textDef(0, ['a'])], [
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),
// The anchor would be added by the compiler after the ngContent
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 {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 {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
@ -59,7 +59,8 @@ export function main() {
createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 2, 'span'),
providerDef(
NodeFlags.LazyProvider, null, ProviderType.Class, LazyService, LazyService, []),
NodeFlags.TypeClassProvider | NodeFlags.LazyProvider, null, LazyService, LazyService,
[]),
directiveDef(NodeFlags.None, null, 0, SomeService, [Injector])
]));
@ -71,7 +72,7 @@ export function main() {
it('should create value providers', () => {
createAndGetRootNodes(compViewDef([
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']),
]));
@ -83,7 +84,7 @@ export function main() {
createAndGetRootNodes(compViewDef([
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']),
]));
@ -93,11 +94,9 @@ export function main() {
it('should create useExisting providers', () => {
createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 3, 'span'),
providerDef(NodeFlags.TypeValueProvider, null, 'someExistingToken', 'someValue', []),
providerDef(
NodeFlags.None, null, ProviderType.Value, 'someExistingToken', 'someValue', []),
providerDef(
NodeFlags.None, null, ProviderType.UseExisting, 'someToken', null,
['someExistingToken']),
NodeFlags.TypeUseExistingProvider, null, 'someToken', null, ['someExistingToken']),
directiveDef(NodeFlags.None, null, 0, SomeService, ['someToken']),
]));
@ -116,7 +115,7 @@ export function main() {
elementDef(
NodeFlags.None, null, null, 1, 'div', null, null, null, null,
() => compViewDef([textDef(null, ['a'])])),
directiveDef(NodeFlags.IsComponent, null, 0, SomeService, [])
directiveDef(NodeFlags.Component, null, 0, SomeService, [])
]),
TestBed.get(Injector), [], getDOM().createElement('div'));
} catch (e) {
@ -180,7 +179,7 @@ export function main() {
elementDef(NodeFlags.None, null, null, 1, 'span'),
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();
@ -206,10 +205,9 @@ export function main() {
it('should skip the current element when using SkipSelf', () => {
createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 4, 'span'),
providerDef(
NodeFlags.None, null, ProviderType.Value, 'someToken', 'someParentValue', []),
providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someParentValue', []),
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, [[DepFlags.SkipSelf, 'someToken']])
]));
@ -229,7 +227,7 @@ export function main() {
describe('builtin tokens', () => {
it('should inject ViewContainerRef', () => {
createAndGetRootNodes(compViewDef([
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 1),
anchorDef(NodeFlags.EmbeddedViews, null, null, 1),
directiveDef(NodeFlags.None, null, 0, SomeService, [ViewContainerRef])
]));
@ -280,7 +278,7 @@ export function main() {
() => compViewDef([
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;
@ -292,7 +290,7 @@ export function main() {
elementDef(
NodeFlags.None, null, null, 1, 'span', null, null, null, null,
() => 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();
@ -303,7 +301,7 @@ export function main() {
elementDef(
NodeFlags.None, null, null, 1, 'span', null, null, null, null,
() => 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();
@ -317,7 +315,7 @@ export function main() {
describe('data binding', () => {
ARG_TYPE_VALUES.forEach((inlineDynamic) => {
it(`should update ${ArgumentType[inlineDynamic]}`, () => {
it(`should update via strategy ${inlineDynamic}`, () => {
let instance: SomeService;
class SomeService {

View File

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

View File

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

View File

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

View File

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

View File

@ -128,7 +128,9 @@ export function main() {
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', () => {
@ -139,7 +141,8 @@ export function main() {
]);
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([
NodeFlags.AfterContentChecked, NodeFlags.None,
NodeFlags.AfterContentInit | NodeFlags.AfterViewChecked, NodeFlags.None, NodeFlags.None
NodeFlags.TypeDirective | NodeFlags.AfterContentChecked, NodeFlags.None,
NodeFlags.TypeDirective | NodeFlags.AfterContentInit | NodeFlags.AfterViewChecked,
NodeFlags.None, NodeFlags.None
]);
});
@ -169,8 +173,10 @@ export function main() {
]);
expect(childFlags(vd)).toEqual([
NodeFlags.AfterContentChecked, NodeFlags.AfterContentChecked, NodeFlags.None,
NodeFlags.AfterContentInit | NodeFlags.AfterViewInit, NodeFlags.None, NodeFlags.None
NodeFlags.TypeElement | NodeFlags.TypeDirective | NodeFlags.AfterContentChecked,
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 {
return viewDef(viewFlags, [
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,
[
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) => {
const cmp = view.component;
@ -49,7 +49,7 @@ function TreeComponent_2() {
viewFlags,
[
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) => {
const cmp = view.component;
@ -65,10 +65,10 @@ function TreeComponent_0(): ViewDefinition {
NodeFlags.None, null, null, 1, 'span', null,
[[BindingType.ElementStyle, 'backgroundColor', null]]),
textDef(null, [' ', ' ']),
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 1, null, TreeComponent_1),
anchorDef(NodeFlags.EmbeddedViews, null, null, 1, null, TreeComponent_1),
directiveDef(
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(
NodeFlags.None, null, 0, NgIf, [ViewContainerRef, TemplateRef], {ngIf: [0, 'ngIf']}),
],