fix(ivy): remove metadata from *Def and introduce *DefWithMeta types (#26203)

Previously in Ivy, metadata for directives/components/modules/etc was
carried in .d.ts files inside type information encoded on the
DirectiveDef, ComponentDef, NgModuleDef, etc types of Ivy definition
fields. This works well, but has the side effect of complicating Ivy's
runtime code as these extra generic type parameters had to be specified
as <any> throughout the codebase. *DefInternal types were introduced
previously to mitigate this issue, but that's the wrong way to solve
the problem.

This commit returns *Def types to their original form, with no metadata
attached. Instead, new *DefWithMeta types are introduced that alias the
plain definition types and add extra generic parameters. This way the
only code that needs to deal with the extra metadata parameters is the
compiler code that reads and writes them - the existence of this metadata
is transparent to the runtime, as it should be.

PR Close #26203
This commit is contained in:
Alex Rickabaugh 2018-09-21 12:12:06 -07:00 committed by Jason Aden
parent b0070dfb9a
commit 79466baef8
42 changed files with 279 additions and 252 deletions

View File

@ -7,7 +7,7 @@
*/
import {ɵRenderFlags, ɵbind, ɵcontainer, ɵcontainerRefreshEnd, ɵcontainerRefreshStart, ɵdefineComponent, ɵdetectChanges, ɵelementEnd, ɵelementStart, ɵelementStyleProp, ɵelementStyling, ɵembeddedViewEnd, ɵembeddedViewStart, ɵtext, ɵtextBinding as ɵtextBinding} from '@angular/core';
import {ComponentDefInternal} from '@angular/core/src/render3/interfaces/definition';
import {ComponentDef} from '@angular/core/src/render3/interfaces/definition';
import {TableCell, buildTable, emptyTable} from '../util';
@ -16,7 +16,7 @@ export class LargeTableComponent {
data: TableCell[][] = emptyTable;
/** @nocollapse */
static ngComponentDef: ComponentDefInternal<LargeTableComponent> = ɵdefineComponent({
static ngComponentDef: ComponentDef<LargeTableComponent> = ɵdefineComponent({
type: LargeTableComponent,
selectors: [['largetable']],
consts: 3,

View File

@ -313,7 +313,7 @@ export class SelectorScopeRegistry {
return null;
} else if (
def.type === null || !ts.isTypeReferenceNode(def.type) ||
def.type.typeArguments === undefined || def.type.typeArguments.length !== 2) {
def.type.typeArguments === undefined || def.type.typeArguments.length < 2) {
// The type metadata was the wrong shape.
return null;
}
@ -337,7 +337,7 @@ export class SelectorScopeRegistry {
return null;
} else if (
def.type === null || !ts.isTypeReferenceNode(def.type) ||
def.type.typeArguments === undefined || def.type.typeArguments.length !== 2) {
def.type.typeArguments === undefined || def.type.typeArguments.length < 2) {
// The type metadata was the wrong shape.
return null;
}

View File

@ -20,7 +20,7 @@ describe('SelectorScopeRegistry', () => {
{
name: 'node_modules/@angular/core/index.d.ts',
contents: `
export interface NgComponentDef<A, B> {}
export interface NgComponentDefWithMeta<A, B, C, D, E, F> {}
export interface NgModuleDef<A, B, C, D> {}
`
},
@ -38,10 +38,10 @@ describe('SelectorScopeRegistry', () => {
{
name: 'node_modules/some_library/component.d.ts',
contents: `
import {NgComponentDef} from '@angular/core';
import {NgComponentDefWithMeta} from '@angular/core';
export declare class SomeCmp {
static ngComponentDef: NgComponentDef<SomeCmp, 'some-cmp'>;
static ngComponentDef: NgComponentDefWithMeta<SomeCmp, 'some-cmp', never, {}, {}, never>;
}
`
},
@ -84,21 +84,21 @@ describe('SelectorScopeRegistry', () => {
{
name: 'node_modules/@angular/core/index.d.ts',
contents: `
export interface NgComponentDef<A, B> {}
export interface NgComponentDefWithMeta<A, B, C, D, E, F> {}
export interface NgModuleDef<A, B, C, D> {}
`
},
{
name: 'node_modules/some_library/index.d.ts',
contents: `
import {NgComponentDef, NgModuleDef} from '@angular/core';
import {NgComponentDefWithMeta, NgModuleDef} from '@angular/core';
export declare class SomeModule {
static ngModuleDef: NgModuleDef<SomeModule, [typeof SomeCmp], never, [typeof SomeCmp]>;
}
export declare class SomeCmp {
static ngComponentDef: NgComponentDef<SomeCmp, 'some-cmp'>;
static ngComponentDef: NgComponentDefWithMeta<SomeCmp, 'some-cmp', never, {}, {}, never>;
}
`
},

View File

@ -45,7 +45,7 @@ const CORE_SUPPORTED_SYMBOLS = new Set<string>([
'inject',
'ɵInjectableDef',
'ɵInjectorDef',
'ɵNgModuleDef',
'ɵNgModuleDefWithMeta',
'ɵNgModuleFactory',
]);
@ -416,7 +416,16 @@ export class TypeTranslatorVisitor implements ExpressionVisitor, TypeVisitor {
}
visitLiteralMapExpr(ast: LiteralMapExpr, context: Context) {
throw new Error('Method not implemented.');
const entries = ast.entries.map(entry => {
const {key, quoted} = entry;
const value = entry.value.visitExpression(this, context);
if (quoted) {
return `'${key}': ${value}`;
} else {
return `${key}: ${value}`;
}
});
return `{${entries.join(', ')}}`;
}
visitCommaExpr(ast: CommaExpr, context: Context) { throw new Error('Method not implemented.'); }

View File

@ -148,7 +148,9 @@ describe('ngtsc behavioral tests', () => {
expect(jsContents).not.toContain('__decorate');
const dtsContents = getContents('test.d.ts');
expect(dtsContents).toContain('static ngComponentDef: i0.ɵComponentDef<TestCmp, \'test-cmp\'>');
expect(dtsContents)
.toContain(
'static ngComponentDef: i0.ɵComponentDefWithMeta<TestCmp, \'test-cmp\', never, {}, {}, never>');
});
it('should compile Components without errors', () => {
@ -201,10 +203,12 @@ describe('ngtsc behavioral tests', () => {
'declarations: [TestCmp], imports: [], exports: [] })');
const dtsContents = getContents('test.d.ts');
expect(dtsContents).toContain('static ngComponentDef: i0.ɵComponentDef<TestCmp, \'test-cmp\'>');
expect(dtsContents)
.toContain(
'static ngModuleDef: i0.ɵNgModuleDef<TestModule, [typeof TestCmp], never, never>');
'static ngComponentDef: i0.ɵComponentDefWithMeta<TestCmp, \'test-cmp\', never, {}, {}, never>');
expect(dtsContents)
.toContain(
'static ngModuleDef: i0.ɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], never, never>');
expect(dtsContents).not.toContain('__decorate');
});
@ -247,7 +251,7 @@ describe('ngtsc behavioral tests', () => {
const dtsContents = getContents('test.d.ts');
expect(dtsContents)
.toContain(
'static ngModuleDef: i0.ɵNgModuleDef<TestModule, [typeof TestCmp], [typeof OtherModule], never>');
'static ngModuleDef: i0.ɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], [typeof OtherModule], never>');
expect(dtsContents).toContain('static ngInjectorDef: i0.ɵInjectorDef');
});
@ -333,7 +337,8 @@ describe('ngtsc behavioral tests', () => {
.toContain(
'TestPipe.ngPipeDef = i0.ɵdefinePipe({ name: "test-pipe", type: TestPipe, ' +
'factory: function TestPipe_Factory(t) { return new (t || TestPipe)(); }, pure: false })');
expect(dtsContents).toContain('static ngPipeDef: i0.ɵPipeDef<TestPipe, \'test-pipe\'>;');
expect(dtsContents)
.toContain('static ngPipeDef: i0.ɵPipeDefWithMeta<TestPipe, \'test-pipe\'>;');
});
it('should compile pure Pipes without errors', () => {
@ -358,7 +363,8 @@ describe('ngtsc behavioral tests', () => {
.toContain(
'TestPipe.ngPipeDef = i0.ɵdefinePipe({ name: "test-pipe", type: TestPipe, ' +
'factory: function TestPipe_Factory(t) { return new (t || TestPipe)(); }, pure: true })');
expect(dtsContents).toContain('static ngPipeDef: i0.ɵPipeDef<TestPipe, \'test-pipe\'>;');
expect(dtsContents)
.toContain('static ngPipeDef: i0.ɵPipeDefWithMeta<TestPipe, \'test-pipe\'>;');
});
it('should compile Pipes with dependencies', () => {
@ -409,7 +415,8 @@ describe('ngtsc behavioral tests', () => {
const dtsContents = getContents('test.d.ts');
expect(dtsContents)
.toContain('i0.ɵNgModuleDef<TestModule, [typeof TestPipe, typeof TestCmp], never, never>');
.toContain(
'i0.ɵNgModuleDefWithMeta<TestModule, [typeof TestPipe, typeof TestCmp], never, never>');
});
it('should unwrap a ModuleWithProviders function if a generic type is provided for it', () => {
@ -440,7 +447,7 @@ describe('ngtsc behavioral tests', () => {
const dtsContents = getContents('test.d.ts');
expect(dtsContents).toContain(`import * as i1 from 'router';`);
expect(dtsContents)
.toContain('i0.ɵNgModuleDef<TestModule, never, [typeof i1.RouterModule], never>');
.toContain('i0.ɵNgModuleDefWithMeta<TestModule, never, [typeof i1.RouterModule], never>');
});
it('should inject special types according to the metadata', () => {

View File

@ -126,8 +126,8 @@ export class Identifiers {
static defineComponent: o.ExternalReference = {name: 'ɵdefineComponent', moduleName: CORE};
static ComponentDef: o.ExternalReference = {
name: 'ɵComponentDef',
static ComponentDefWithMeta: o.ExternalReference = {
name: 'ɵComponentDefWithMeta',
moduleName: CORE,
};
@ -136,8 +136,8 @@ export class Identifiers {
moduleName: CORE,
};
static DirectiveDef: o.ExternalReference = {
name: 'ɵDirectiveDef',
static DirectiveDefWithMeta: o.ExternalReference = {
name: 'ɵDirectiveDefWithMeta',
moduleName: CORE,
};
@ -151,14 +151,14 @@ export class Identifiers {
moduleName: CORE,
};
static NgModuleDef: o.ExternalReference = {
name: 'ɵNgModuleDef',
static NgModuleDefWithMeta: o.ExternalReference = {
name: 'ɵNgModuleDefWithMeta',
moduleName: CORE,
};
static defineNgModule: o.ExternalReference = {name: 'ɵdefineNgModule', moduleName: CORE};
static PipeDef: o.ExternalReference = {name: 'ɵPipeDef', moduleName: CORE};
static PipeDefWithMeta: o.ExternalReference = {name: 'ɵPipeDefWithMeta', moduleName: CORE};
static definePipe: o.ExternalReference = {name: 'ɵdefinePipe', moduleName: CORE};

View File

@ -73,7 +73,7 @@ export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
exports: o.literalArr(exports.map(ref => ref.value)),
})]);
const type = new o.ExpressionType(o.importExpr(R3.NgModuleDef, [
const type = new o.ExpressionType(o.importExpr(R3.NgModuleDefWithMeta, [
new o.ExpressionType(moduleType), tupleTypeOf(declarations), tupleTypeOf(imports),
tupleTypeOf(exports)
]));

View File

@ -50,7 +50,7 @@ export function compilePipeFromMetadata(metadata: R3PipeMetadata) {
definitionMapValues.push({key: 'pure', value: o.literal(metadata.pure), quoted: false});
const expression = o.importExpr(R3.definePipe).callFn([o.literalMap(definitionMapValues)]);
const type = new o.ExpressionType(o.importExpr(R3.PipeDef, [
const type = new o.ExpressionType(o.importExpr(R3.PipeDefWithMeta, [
new o.ExpressionType(metadata.type),
new o.ExpressionType(new o.LiteralExpr(metadata.pipeName)),
]));

View File

@ -117,10 +117,7 @@ export function compileDirectiveFromMetadata(
// string literal, which must be on one line.
const selectorForType = (meta.selector || '').replace(/\n/g, '');
const type = new o.ExpressionType(o.importExpr(R3.DirectiveDef, [
typeWithParameters(meta.type, meta.typeArgumentCount),
new o.ExpressionType(o.literal(selectorForType))
]));
const type = createTypeForDef(meta, R3.DirectiveDefWithMeta);
return {expression, type, statements};
}
@ -257,10 +254,7 @@ export function compileComponentFromMetadata(
const selectorForType = (meta.selector || '').replace(/\n/g, '');
const expression = o.importExpr(R3.defineComponent).callFn([definitionMap.toLiteralMap()]);
const type = new o.ExpressionType(o.importExpr(R3.ComponentDef, [
typeWithParameters(meta.type, meta.typeArgumentCount),
new o.ExpressionType(o.literal(selectorForType))
]));
const type = createTypeForDef(meta, R3.ComponentDefWithMeta);
return {expression, type, statements};
}
@ -509,6 +503,39 @@ function createContentQueriesRefreshFunction(meta: R3DirectiveMetadata): o.Expre
return null;
}
function stringAsType(str: string): o.Type {
return o.expressionType(o.literal(str));
}
function stringMapAsType(map: {[key: string]: string}): o.Type {
const mapValues = Object.keys(map).map(key => ({
key,
value: o.literal(map[key]),
quoted: true,
}));
return o.expressionType(o.literalMap(mapValues));
}
function stringArrayAsType(arr: string[]): o.Type {
return arr.length > 0 ? o.expressionType(o.literalArr(arr.map(value => o.literal(value)))) :
o.NONE_TYPE;
}
function createTypeForDef(meta: R3DirectiveMetadata, typeBase: o.ExternalReference): o.Type {
// On the type side, remove newlines from the selector as it will need to fit into a TypeScript
// string literal, which must be on one line.
const selectorForType = (meta.selector || '').replace(/\n/g, '');
return o.expressionType(o.importExpr(typeBase, [
typeWithParameters(meta.type, meta.typeArgumentCount),
stringAsType(selectorForType),
meta.exportAs !== null ? stringAsType(meta.exportAs) : o.NONE_TYPE,
stringMapAsType(meta.inputs),
stringMapAsType(meta.outputs),
stringArrayAsType(meta.queries.map(q => q.propertyName)),
]));
}
// Define and update any view queries
function createViewQueriesFunction(
meta: R3ComponentMetadata, constantPool: ConstantPool): o.Expression {

View File

@ -100,9 +100,11 @@ export {
pipe as ɵpipe,
BaseDef as ɵBaseDef,
ComponentDef as ɵComponentDef,
ComponentDefInternal as ɵComponentDefInternal,
ComponentDefWithMeta as ɵComponentDefWithMeta,
DirectiveDef as ɵDirectiveDef,
DirectiveDefWithMeta as ɵDirectiveDefWithMeta,
PipeDef as ɵPipeDef,
PipeDefWithMeta as ɵPipeDefWithMeta,
whenRendered as ɵwhenRendered,
i18nApply as ɵi18nApply,
i18nExpMapping as ɵi18nExpMapping,
@ -134,7 +136,7 @@ export {
export {
NgModuleDef as ɵNgModuleDef,
NgModuleDefInternal as ɵNgModuleDefInternal,
NgModuleDefWithMeta as ɵNgModuleDefWithMeta,
NgModuleTransitiveScopes as ɵNgModuleTransitiveScopes,
} from './metadata/ng_module';

View File

@ -26,11 +26,7 @@ export interface NgModuleTransitiveScopes {
exported: {directives: Set<any>; pipes: Set<any>;};
}
/**
* A version of {@link NgModuleDef} that represents the runtime type shape only, and excludes
* metadata parameters.
*/
export type NgModuleDefInternal<T> = NgModuleDef<T, any, any, any>;
export type NgModuleDefWithMeta<T, Declarations, Imports, Exports> = NgModuleDef<T>;
/**
* Runtime link information for NgModules.
@ -42,7 +38,7 @@ export type NgModuleDefInternal<T> = NgModuleDef<T, any, any, any>;
* never create the object directly since the shape of this object
* can change between versions.
*/
export interface NgModuleDef<T, Declarations, Imports, Exports> {
export interface NgModuleDef<T> {
/** Token representing the module. Used by DI. */
type: T;

View File

@ -19,7 +19,7 @@ import {queueInitHooks, queueLifecycleHooks} from './hooks';
import {PlayerHandler} from './interfaces/player';
import {CLEAN_PROMISE, baseDirectiveCreate, createLViewData, createTView, detectChangesInternal, enterView, executeInitAndContentHooks, hostElement, leaveView, locateHostElement, setHostBindings, queueHostBindingForCheck,} from './instructions';
import {ComponentDef, ComponentDefInternal, ComponentType} from './interfaces/definition';
import {ComponentDef, ComponentType} from './interfaces/definition';
import {LElementNode} from './interfaces/node';
import {RElement, RendererFactory3, domRendererFactory3} from './interfaces/renderer';
import {CONTEXT, INJECTOR, LViewData, LViewFlags, RootContext, RootContextFlags, TVIEW} from './interfaces/view';
@ -77,7 +77,7 @@ export interface CreateComponentOptions {
}
/** See CreateComponentOptions.hostFeatures */
type HostFeature = (<T>(component: T, componentDef: ComponentDef<T, string>) => void);
type HostFeature = (<T>(component: T, componentDef: ComponentDef<T>) => void);
// TODO: A hack to not pull in the NullInjector from @angular/core.
export const NULL_INJECTOR: Injector = {
@ -149,7 +149,7 @@ export function renderComponent<T>(
* renderComponent() and ViewContainerRef.createComponent().
*/
export function createRootComponent<T>(
elementNode: LElementNode, componentDef: ComponentDef<T, string>, rootView: LViewData,
elementNode: LElementNode, componentDef: ComponentDef<T>, rootView: LViewData,
rootContext: RootContext, hostFeatures: HostFeature[] | null): any {
// Create directive instance with factory() and store at index 0 in directives array
const component = baseDirectiveCreate(0, componentDef.factory() as T, componentDef, elementNode);
@ -188,7 +188,7 @@ export function createRootContext(
* renderComponent(AppComponent, {features: [RootLifecycleHooks]});
* ```
*/
export function LifecycleHooksFeature(component: any, def: ComponentDefInternal<any>): void {
export function LifecycleHooksFeature(component: any, def: ComponentDef<any>): void {
const rootTView = readPatchedLViewData(component) ![TVIEW];
// Root component is always created at dir index 0

View File

@ -20,7 +20,7 @@ import {assertComponentType, assertDefined} from './assert';
import {LifecycleHooksFeature, createRootComponent, createRootContext} from './component';
import {getComponentDef} from './definition';
import {adjustBlueprintForNewNode, createLViewData, createNodeAtIndex, createTView, elementCreate, enterView, getTNode, hostElement, locateHostElement, renderEmbeddedTemplate} from './instructions';
import {ComponentDefInternal, RenderFlags} from './interfaces/definition';
import {ComponentDef, RenderFlags} from './interfaces/definition';
import {LElementNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node';
import {RElement, RendererFactory3, domRendererFactory3} from './interfaces/renderer';
import {FLAGS, INJECTOR, LViewData, LViewFlags, RootContext, TVIEW} from './interfaces/view';
@ -88,7 +88,7 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
return toRefArray(this.componentDef.outputs);
}
constructor(private componentDef: ComponentDefInternal<any>) {
constructor(private componentDef: ComponentDef<any>) {
super();
this.componentType = componentDef.type;
this.selector = componentDef.selectors[0][0] as string;

View File

@ -10,12 +10,12 @@ import './ng_dev_mode';
import {ChangeDetectionStrategy} from '../change_detection/constants';
import {Provider} from '../di/provider';
import {NgModuleDef, NgModuleDefInternal} from '../metadata/ng_module';
import {NgModuleDef} from '../metadata/ng_module';
import {ViewEncapsulation} from '../metadata/view';
import {Type} from '../type';
import {NG_COMPONENT_DEF, NG_DIRECTIVE_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from './fields';
import {BaseDef, ComponentDefFeature, ComponentDefInternal, ComponentQuery, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveType, DirectiveTypesOrFactory, PipeDefInternal, PipeType, PipeTypesOrFactory} from './interfaces/definition';
import {BaseDef, ComponentDef, ComponentDefFeature, ComponentQuery, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFeature, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory} from './interfaces/definition';
import {CssSelectorList, SelectorFlags} from './interfaces/projection';
export const EMPTY: {} = {};
@ -280,7 +280,7 @@ export function defineComponent<T>(componentDefinition: {
if (animations) {
data.animations = animations;
}
const def: ComponentDefInternal<any> = {
const def: ComponentDef<any> = {
type: type,
diPublic: null,
consts: componentDefinition.consts,
@ -328,7 +328,7 @@ export function defineComponent<T>(componentDefinition: {
}
export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>):
DirectiveDefInternal<any>|ComponentDefInternal<any> {
DirectiveDef<any>|ComponentDef<any> {
const def = getComponentDef(type) || getDirectiveDef(type);
if (ngDevMode && !def) {
throw new Error(`'${type.name}' is neither 'ComponentType' or 'DirectiveType'.`);
@ -336,7 +336,7 @@ export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>
return def !;
}
export function extractPipeDef(type: PipeType<any>): PipeDefInternal<any> {
export function extractPipeDef(type: PipeType<any>): PipeDef<any> {
const def = getPipeDef(type);
if (ngDevMode && !def) {
throw new Error(`'${type.name}' is not a 'PipeType'.`);
@ -344,8 +344,8 @@ export function extractPipeDef(type: PipeType<any>): PipeDefInternal<any> {
return def !;
}
export function defineNgModule<T>(def: {type: T} & Partial<NgModuleDef<T, any, any, any>>): never {
const res: NgModuleDefInternal<T> = {
export function defineNgModule<T>(def: {type: T} & Partial<NgModuleDef<T>>): never {
const res: NgModuleDef<T> = {
type: def.type,
bootstrap: def.bootstrap || EMPTY_ARRAY,
declarations: def.declarations || EMPTY_ARRAY,
@ -656,7 +656,7 @@ export function definePipe<T>(pipeDef: {
/** Whether the pipe is pure. */
pure?: boolean
}): never {
return (<PipeDefInternal<T>>{
return (<PipeDef<T>>{
name: pipeDef.name,
factory: pipeDef.factory,
pure: pipeDef.pure !== false,
@ -670,18 +670,18 @@ export function definePipe<T>(pipeDef: {
* explicit. This would require some sort of migration strategy.
*/
export function getComponentDef<T>(type: any): ComponentDefInternal<T>|null {
export function getComponentDef<T>(type: any): ComponentDef<T>|null {
return (type as any)[NG_COMPONENT_DEF] || null;
}
export function getDirectiveDef<T>(type: any): DirectiveDefInternal<T>|null {
export function getDirectiveDef<T>(type: any): DirectiveDef<T>|null {
return (type as any)[NG_DIRECTIVE_DEF] || null;
}
export function getPipeDef<T>(type: any): PipeDefInternal<T>|null {
export function getPipeDef<T>(type: any): PipeDef<T>|null {
return (type as any)[NG_PIPE_DEF] || null;
}
export function getNgModuleDef<T>(type: any): NgModuleDefInternal<T>|null {
export function getNgModuleDef<T>(type: any): NgModuleDef<T>|null {
return (type as any)[NG_MODULE_DEF] || null;
}

View File

@ -19,7 +19,7 @@ import {assertDefined} from './assert';
import {getComponentDef, getDirectiveDef, getPipeDef} from './definition';
import {NG_ELEMENT_ID} from './fields';
import {_getViewData, assertPreviousIsParent, getPreviousOrParentTNode, resolveDirective, setEnvironment} from './instructions';
import {DirectiveDefInternal} from './interfaces/definition';
import {DirectiveDef} from './interfaces/definition';
import {INJECTOR_SIZE, InjectorLocationFlags, PARENT_INJECTOR, TNODE,} from './interfaces/injector';
import {AttributeMarker, TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeFlags, TNodeType} from './interfaces/node';
import {isProceduralRenderer} from './interfaces/renderer';
@ -196,7 +196,7 @@ export function getParentInjectorView(location: number, startView: LViewData): L
* @param def The definition of the directive to be made public
*/
export function diPublicInInjector(
injectorIndex: number, view: LViewData, def: DirectiveDefInternal<any>): void {
injectorIndex: number, view: LViewData, def: DirectiveDef<any>): void {
bloomAdd(injectorIndex, view[TVIEW], def.type);
}
@ -205,7 +205,7 @@ export function diPublicInInjector(
*
* @param def The definition of the directive to be made public
*/
export function diPublic(def: DirectiveDefInternal<any>): void {
export function diPublic(def: DirectiveDef<any>): void {
diPublicInInjector(getOrCreateNodeInjector(), _getViewData(), def);
}
@ -399,7 +399,7 @@ function searchMatchesQueuedForCreation<T>(token: any, hostTView: TView): T|null
const matches = hostTView.currentMatches;
if (matches) {
for (let i = 0; i < matches.length; i += 2) {
const def = matches[i] as DirectiveDefInternal<any>;
const def = matches[i] as DirectiveDef<any>;
if (def.type === token) {
return resolveDirective(def, i + 1, matches, hostTView);
}
@ -422,7 +422,7 @@ function searchDirectivesOnInjector<T>(
for (let i = start; i < end; i++) {
// Get the definition for the directive at this index and, if it is injectable (diPublic),
// and matches the given token, return the directive instance.
const directiveDef = defs[i] as DirectiveDefInternal<any>;
const directiveDef = defs[i] as DirectiveDef<any>;
if (directiveDef.type === token && directiveDef.diPublic) {
return injectorView[DIRECTIVES] ![i];
}

View File

@ -9,22 +9,22 @@
import {Type} from '../../type';
import {fillProperties} from '../../util/property';
import {EMPTY, EMPTY_ARRAY} from '../definition';
import {ComponentDefInternal, ComponentTemplate, DirectiveDefFeature, DirectiveDefInternal, RenderFlags} from '../interfaces/definition';
import {ComponentDef, ComponentTemplate, DirectiveDef, DirectiveDefFeature, RenderFlags} from '../interfaces/definition';
/**
* Determines if a definition is a {@link ComponentDefInternal} or a {@link DirectiveDefInternal}
* Determines if a definition is a {@link ComponentDef} or a {@link DirectiveDef}
* @param definition The definition to examine
*/
function isComponentDef<T>(definition: ComponentDefInternal<T>| DirectiveDefInternal<T>):
definition is ComponentDefInternal<T> {
const def = definition as ComponentDefInternal<T>;
function isComponentDef<T>(definition: ComponentDef<T>| DirectiveDef<T>):
definition is ComponentDef<T> {
const def = definition as ComponentDef<T>;
return typeof def.template === 'function';
}
function getSuperType(type: Type<any>): Type<any>&
{ngComponentDef?: ComponentDefInternal<any>, ngDirectiveDef?: DirectiveDefInternal<any>} {
{ngComponentDef?: ComponentDef<any>, ngDirectiveDef?: DirectiveDef<any>} {
return Object.getPrototypeOf(type.prototype).constructor;
}
@ -32,12 +32,11 @@ function getSuperType(type: Type<any>): Type<any>&
* Merges the definition from a super class to a sub class.
* @param definition The definition that is a SubClass of another directive of component
*/
export function InheritDefinitionFeature(
definition: DirectiveDefInternal<any>| ComponentDefInternal<any>): void {
export function InheritDefinitionFeature(definition: DirectiveDef<any>| ComponentDef<any>): void {
let superType = getSuperType(definition.type);
while (superType) {
let superDef: DirectiveDefInternal<any>|ComponentDefInternal<any>|undefined = undefined;
let superDef: DirectiveDef<any>|ComponentDef<any>|undefined = undefined;
if (isComponentDef(definition)) {
// Don't use getComponentDef/getDirectiveDef. This logic relies on inheritance.
superDef = superType.ngComponentDef || superType.ngDirectiveDef;

View File

@ -8,7 +8,7 @@
import {SimpleChange} from '../../change_detection/change_detection_util';
import {OnChanges, SimpleChanges} from '../../metadata/lifecycle_hooks';
import {DirectiveDefInternal} from '../interfaces/definition';
import {DirectiveDef} from '../interfaces/definition';
const PRIVATE_PREFIX = '__ngOnChanges_';
@ -38,7 +38,7 @@ type OnChangesExpando = OnChanges & {
* });
* ```
*/
export function NgOnChangesFeature<T>(definition: DirectiveDefInternal<T>): void {
export function NgOnChangesFeature<T>(definition: DirectiveDef<T>): void {
const declaredToMinifiedInputs = definition.declaredInputs;
const proto = definition.type.prototype;
for (const declaredName in declaredToMinifiedInputs) {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {diPublic} from '../di';
import {DirectiveDefInternal} from '../interfaces/definition';
import {DirectiveDef} from '../interfaces/definition';
/**
* This feature publishes the directive (or component) into the DI system, making it visible to
@ -14,6 +14,6 @@ import {DirectiveDefInternal} from '../interfaces/definition';
*
* @param definition
*/
export function PublicFeature<T>(definition: DirectiveDefInternal<T>) {
export function PublicFeature<T>(definition: DirectiveDef<T>) {
definition.diPublic = diPublic;
}

View File

@ -7,7 +7,7 @@
*/
import {assertEqual} from './assert';
import {DirectiveDefInternal} from './interfaces/definition';
import {DirectiveDef} from './interfaces/definition';
import {TNodeFlags} from './interfaces/node';
import {DIRECTIVES, FLAGS, HookData, LViewData, LViewFlags, TView} from './interfaces/view';
@ -52,7 +52,7 @@ export function queueLifecycleHooks(flags: number, tView: TView): void {
// directiveCreate) so we can preserve the current hook order. Content, view, and destroy
// hooks for projected components and directives must be called *before* their hosts.
for (let i = start; i < end; i++) {
const def: DirectiveDefInternal<any> = tView.directives ![i];
const def: DirectiveDef<any> = tView.directives ![i];
queueContentHooks(def, tView, i);
queueViewHooks(def, tView, i);
queueDestroyHooks(def, tView, i);
@ -61,7 +61,7 @@ export function queueLifecycleHooks(flags: number, tView: TView): void {
}
/** Queues afterContentInit and afterContentChecked hooks on TView */
function queueContentHooks(def: DirectiveDefInternal<any>, tView: TView, i: number): void {
function queueContentHooks(def: DirectiveDef<any>, tView: TView, i: number): void {
if (def.afterContentInit) {
(tView.contentHooks || (tView.contentHooks = [])).push(i, def.afterContentInit);
}
@ -73,7 +73,7 @@ function queueContentHooks(def: DirectiveDefInternal<any>, tView: TView, i: numb
}
/** Queues afterViewInit and afterViewChecked hooks on TView */
function queueViewHooks(def: DirectiveDefInternal<any>, tView: TView, i: number): void {
function queueViewHooks(def: DirectiveDef<any>, tView: TView, i: number): void {
if (def.afterViewInit) {
(tView.viewHooks || (tView.viewHooks = [])).push(i, def.afterViewInit);
}
@ -85,7 +85,7 @@ function queueViewHooks(def: DirectiveDefInternal<any>, tView: TView, i: number)
}
/** Queues onDestroy hooks on TView */
function queueDestroyHooks(def: DirectiveDefInternal<any>, tView: TView, i: number): void {
function queueDestroyHooks(def: DirectiveDef<any>, tView: TView, i: number): void {
if (def.onDestroy != null) {
(tView.destroyHooks || (tView.destroyHooks = [])).push(i, def.onDestroy);
}

View File

@ -11,7 +11,7 @@ import {defineBase, defineComponent, defineDirective, defineNgModule, definePipe
import {InheritDefinitionFeature} from './features/inherit_definition_feature';
import {NgOnChangesFeature} from './features/ng_onchanges_feature';
import {PublicFeature} from './features/public_feature';
import {BaseDef, ComponentDef, ComponentDefInternal, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFlags, DirectiveDefInternal, DirectiveType, PipeDef} from './interfaces/definition';
import {BaseDef, ComponentDef, ComponentDefWithMeta, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFlags, DirectiveDefWithMeta, DirectiveType, PipeDef, PipeDefWithMeta} from './interfaces/definition';
export {ComponentFactory, ComponentFactoryResolver, ComponentRef, WRAP_RENDERER_FACTORY2, injectComponentFactoryResolver} from './component_ref';
export {directiveInject, getFactoryOf, getInheritedFactory, injectAttribute, injectRenderer2} from './di';
@ -149,17 +149,18 @@ export {templateRefExtractor} from './view_engine_compatibility_prebound';
export {
BaseDef,
ComponentDef,
ComponentDefInternal,
ComponentDefWithMeta,
ComponentTemplate,
ComponentType,
DirectiveDef,
DirectiveDefFlags,
DirectiveDefInternal,
DirectiveDefWithMeta,
DirectiveType,
NgOnChangesFeature,
InheritDefinitionFeature,
PublicFeature,
PipeDef,
PipeDefWithMeta,
LifecycleHooksFeature,
defineComponent,
defineDirective,

View File

@ -18,7 +18,7 @@ import {getRootView} from './discovery_utils';
import {throwCyclicDependencyError, throwErrorIfNoChangesMode, throwMultipleComponentError} from './errors';
import {executeHooks, executeInitHooks, queueInitHooks, queueLifecycleHooks} from './hooks';
import {ACTIVE_INDEX, LContainer, RENDER_PARENT, VIEWS} from './interfaces/container';
import {ComponentDefInternal, ComponentQuery, ComponentTemplate, DirectiveDefInternal, DirectiveDefListOrFactory, InitialStylingFlags, PipeDefListOrFactory, RenderFlags} from './interfaces/definition';
import {ComponentDef, ComponentQuery, ComponentTemplate, DirectiveDef, DirectiveDefListOrFactory, InitialStylingFlags, PipeDefListOrFactory, RenderFlags} from './interfaces/definition';
import {AttributeMarker, InitialInputData, InitialInputs, LContainerNode, LElementContainerNode, LElementNode, LNode, LProjectionNode, LTextNode, LViewNode, LocalRefExtractor, PropertyAliasValue, PropertyAliases, TAttributes, TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeFlags, TNodeType, TProjectionNode, TViewNode} from './interfaces/node';
import {CssSelectorList, NG_PROJECT_AS_ATTR_NAME} from './interfaces/projection';
import {LQueries} from './interfaces/query';
@ -363,7 +363,7 @@ export function setHostBindings(bindings: number[] | null): void {
const defs = tView.directives !;
for (let i = 0; i < bindings.length; i += 2) {
const dirIndex = bindings[i];
const def = defs[dirIndex] as DirectiveDefInternal<any>;
const def = defs[dirIndex] as DirectiveDef<any>;
if (firstTemplatePass) {
for (let i = 0; i < def.hostVars; i++) {
tView.blueprint.push(NO_CHANGE);
@ -906,7 +906,7 @@ function cacheMatchingDirectivesForNode(
const matches = tView.currentMatches = findDirectiveMatches(tNode);
if (matches) {
for (let i = 0; i < matches.length; i += 2) {
const def = matches[i] as DirectiveDefInternal<any>;
const def = matches[i] as DirectiveDef<any>;
const valueIndex = i + 1;
resolveDirective(def, valueIndex, matches, tView);
saveNameToExportMap(matches[valueIndex] as number, def, exportsMap);
@ -924,9 +924,9 @@ function findDirectiveMatches(tNode: TNode): CurrentMatchesList|null {
const def = registry[i];
if (isNodeMatchingSelectorList(tNode, def.selectors !)) {
matches || (matches = []);
if ((def as ComponentDefInternal<any>).template) {
if ((def as ComponentDef<any>).template) {
if (tNode.flags & TNodeFlags.isComponent) throwMultipleComponentError(tNode);
addComponentLogic(def as ComponentDefInternal<any>);
addComponentLogic(def as ComponentDef<any>);
tNode.flags = TNodeFlags.isComponent;
// The component is always stored first with directives after.
@ -942,8 +942,7 @@ function findDirectiveMatches(tNode: TNode): CurrentMatchesList|null {
}
export function resolveDirective(
def: DirectiveDefInternal<any>, valueIndex: number, matches: CurrentMatchesList,
tView: TView): any {
def: DirectiveDef<any>, valueIndex: number, matches: CurrentMatchesList, tView: TView): any {
if (matches[valueIndex] === null) {
matches[valueIndex] = CIRCULAR;
const instance = def.factory();
@ -993,12 +992,12 @@ function instantiateDirectivesDirectly() {
const tDirectives = tView.directives !;
for (let i = start; i < end; i++) {
const def: DirectiveDefInternal<any> = tDirectives[i];
const def: DirectiveDef<any> = tDirectives[i];
// Component view must be set on node before the factory is created so
// ChangeDetectorRefs have a way to store component view on creation.
if ((def as ComponentDefInternal<any>).template) {
addComponentLogic(def as ComponentDefInternal<any>);
if ((def as ComponentDef<any>).template) {
addComponentLogic(def as ComponentDef<any>);
}
directiveCreate(i, def.factory(), def);
}
@ -1027,11 +1026,11 @@ function cacheMatchingLocalNames(
* to their directive instances.
*/
function saveNameToExportMap(
index: number, def: DirectiveDefInternal<any>| ComponentDefInternal<any>,
index: number, def: DirectiveDef<any>| ComponentDef<any>,
exportsMap: {[key: string]: number} | null) {
if (exportsMap) {
if (def.exportAs) exportsMap[def.exportAs] = index;
if ((def as ComponentDefInternal<any>).template) exportsMap[''] = index;
if ((def as ComponentDef<any>).template) exportsMap[''] = index;
}
}
@ -1212,7 +1211,7 @@ export function locateHostElement(
* @returns LElementNode created
*/
export function hostElement(
tag: string, rNode: RElement | null, def: ComponentDefInternal<any>,
tag: string, rNode: RElement | null, def: ComponentDef<any>,
sanitizer?: Sanitizer | null): LElementNode {
resetComponentState();
const tNode = createNodeAtIndex(
@ -1522,7 +1521,7 @@ function generatePropertyAliases(
const defs = tView.directives !;
for (let i = start; i < end; i++) {
const directiveDef = defs[i] as DirectiveDefInternal<any>;
const directiveDef = defs[i] as DirectiveDef<any>;
const propertyAliasMap: {[publicName: string]: string} =
isInput ? directiveDef.inputs : directiveDef.outputs;
for (let publicName in propertyAliasMap) {
@ -1763,12 +1762,11 @@ export function textBinding<T>(index: number, value: T | NO_CHANGE): void {
* @param directiveDef DirectiveDef object which contains information about the template.
*/
export function directiveCreate<T>(
directiveDefIdx: number, directive: T,
directiveDef: DirectiveDefInternal<T>| ComponentDefInternal<T>): T {
directiveDefIdx: number, directive: T, directiveDef: DirectiveDef<T>| ComponentDef<T>): T {
const hostNode = getLNode(previousOrParentTNode, viewData);
const instance = baseDirectiveCreate(directiveDefIdx, directive, directiveDef, hostNode);
if ((directiveDef as ComponentDefInternal<T>).template) {
if ((directiveDef as ComponentDef<T>).template) {
hostNode.data ![CONTEXT] = directive;
}
@ -1792,7 +1790,7 @@ export function directiveCreate<T>(
return instance;
}
function addComponentLogic<T>(def: ComponentDefInternal<T>): void {
function addComponentLogic<T>(def: ComponentDef<T>): void {
const hostNode = getLNode(previousOrParentTNode, viewData);
const tView = getOrCreateTView(
@ -1821,7 +1819,7 @@ function addComponentLogic<T>(def: ComponentDefInternal<T>): void {
* current Angular. Example: local refs and inputs on root component.
*/
export function baseDirectiveCreate<T>(
index: number, directive: T, directiveDef: DirectiveDefInternal<T>| ComponentDefInternal<T>,
index: number, directive: T, directiveDef: DirectiveDef<T>| ComponentDef<T>,
hostNode: LNode): T {
ngDevMode && assertEqual(
viewData[BINDING_INDEX], tView.bindingStartIndex,

View File

@ -59,11 +59,9 @@ export const enum DirectiveDefFlags {ContentQuery = 0b10}
*/
export interface PipeType<T> extends Type<T> { ngPipeDef: never; }
/**
* A version of {@link DirectiveDef} that represents the runtime type shape only, and excludes
* metadata parameters.
*/
export type DirectiveDefInternal<T> = DirectiveDef<T, string>;
export type DirectiveDefWithMeta<
T, Selector extends string, ExportAs extends string, InputMap extends{[key: string]: string},
OutputMap extends{[key: string]: string}, QueryFields extends string[]> = DirectiveDef<T>;
/**
* Runtime information for classes that are inherited by components or directives
@ -110,12 +108,12 @@ export interface BaseDef<T> {
*
* See: {@link defineDirective}
*/
export interface DirectiveDef<T, Selector extends string> extends BaseDef<T> {
export interface DirectiveDef<T> extends BaseDef<T> {
/** Token representing the directive. Used by DI. */
type: Type<T>;
/** Function that makes a directive public to the DI system. */
diPublic: ((def: DirectiveDef<T, string>) => void)|null;
diPublic: ((def: DirectiveDef<T>) => void)|null;
/** The selectors that will be used to match nodes to this directive. */
selectors: CssSelectorList;
@ -172,11 +170,9 @@ export interface DirectiveDef<T, Selector extends string> extends BaseDef<T> {
features: DirectiveDefFeature[]|null;
}
/**
* A version of {@link ComponentDef} that represents the runtime type shape only, and excludes
* metadata parameters.
*/
export type ComponentDefInternal<T> = ComponentDef<T, string>;
export type ComponentDefWithMeta<
T, Selector extends String, ExportAs extends string, InputMap extends{[key: string]: string},
OutputMap extends{[key: string]: string}, QueryFields extends string[]> = ComponentDef<T>;
/**
* Runtime link information for Components.
@ -190,7 +186,7 @@ export type ComponentDefInternal<T> = ComponentDef<T, string>;
*
* See: {@link defineComponent}
*/
export interface ComponentDef<T, Selector extends string> extends DirectiveDef<T, Selector> {
export interface ComponentDef<T> extends DirectiveDef<T> {
/**
* Runtime unique component ID.
*/
@ -289,13 +285,13 @@ export interface ComponentDef<T, Selector extends string> extends DirectiveDef<T
*
* See: {@link definePipe}
*/
export interface PipeDef<T, S extends string> {
export interface PipeDef<T> {
/**
* Pipe name.
*
* Used to resolve pipe in templates.
*/
name: S;
name: string;
/**
* Factory function used to create a new pipe instance.
@ -314,10 +310,10 @@ export interface PipeDef<T, S extends string> {
onDestroy: (() => void)|null;
}
export type PipeDefInternal<T> = PipeDef<T, string>;
export type PipeDefWithMeta<T, Name extends string> = PipeDef<T>;
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T, string>) => void;
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T, string>) => void;
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
/**
* Type used for directiveDefs on component definition.
@ -326,12 +322,12 @@ export type ComponentDefFeature = <T>(componentDef: ComponentDef<T, string>) =>
*/
export type DirectiveDefListOrFactory = (() => DirectiveDefList) | DirectiveDefList;
export type DirectiveDefList = (DirectiveDef<any, string>| ComponentDef<any, string>)[];
export type DirectiveDefList = (DirectiveDef<any>| ComponentDef<any>)[];
export type DirectiveTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
export type DirectiveTypeList =
(DirectiveDef<any, string>| ComponentDef<any, string>|
(DirectiveDef<any>| ComponentDef<any>|
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
/**
@ -341,13 +337,12 @@ export type DirectiveTypeList =
*/
export type PipeDefListOrFactory = (() => PipeDefList) | PipeDefList;
export type PipeDefList = PipeDefInternal<any>[];
export type PipeDefList = PipeDef<any>[];
export type PipeTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
export type PipeTypeList =
(PipeDefInternal<any>|
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
(PipeDef<any>| Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
// Note: This hack is necessary so we don't erroneously get a circular dependency

View File

@ -12,7 +12,7 @@ import {Sanitizer} from '../../sanitization/security';
import {PlayerHandler} from '../interfaces/player';
import {LContainer} from './container';
import {ComponentQuery, ComponentTemplate, DirectiveDefInternal, DirectiveDefList, PipeDefInternal, PipeDefList} from './definition';
import {ComponentQuery, ComponentTemplate, DirectiveDef, DirectiveDefList, PipeDef, PipeDefList} from './definition';
import {LElementNode, LViewNode, TElementNode, TNode, TViewNode} from './node';
import {LQueries} from './query';
import {Renderer3} from './renderer';
@ -558,10 +558,10 @@ export type HookData = (number | (() => void))[];
*
* Injector bloom filters are also stored here.
*/
export type TData = (TNode | PipeDefInternal<any>| number | null)[];
export type TData = (TNode | PipeDef<any>| number | null)[];
/** Type for TView.currentMatches */
export type CurrentMatchesList = [DirectiveDefInternal<any>, (string | number | null)];
export type CurrentMatchesList = [DirectiveDef<any>, (string | number | null)];
// Note: This hack is necessary so we don't erroneously get a circular dependency
// failure based on types.

View File

@ -8,11 +8,11 @@
import {Expression, R3InjectorMetadata, R3NgModuleMetadata, R3Reference, WrappedNodeExpr, compileInjector, compileNgModule as compileR3NgModule, jitExpression} from '@angular/compiler';
import {ModuleWithProviders, NgModule, NgModuleDefInternal, NgModuleTransitiveScopes} from '../../metadata/ng_module';
import {ModuleWithProviders, NgModule, NgModuleDef, NgModuleTransitiveScopes} from '../../metadata/ng_module';
import {Type} from '../../type';
import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition';
import {NG_COMPONENT_DEF, NG_DIRECTIVE_DEF, NG_INJECTOR_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from '../fields';
import {ComponentDefInternal} from '../interfaces/definition';
import {ComponentDef} from '../interfaces/definition';
import {angularCoreEnv} from './environment';
import {reflectDependencies} from './util';
@ -100,7 +100,7 @@ function setScopeOnDeclaredComponents(moduleType: Type<any>, ngModule: NgModule)
declarations.forEach(declaration => {
if (declaration.hasOwnProperty(NG_COMPONENT_DEF)) {
// An `ngComponentDef` field exists - go ahead and patch the component directly.
const component = declaration as Type<any>& {ngComponentDef: ComponentDefInternal<any>};
const component = declaration as Type<any>& {ngComponentDef: ComponentDef<any>};
const componentDef = getComponentDef(component) !;
patchComponentDefWithScope(componentDef, transitiveScopes);
} else if (
@ -116,7 +116,7 @@ function setScopeOnDeclaredComponents(moduleType: Type<any>, ngModule: NgModule)
* a given module.
*/
export function patchComponentDefWithScope<C>(
componentDef: ComponentDefInternal<C>, transitiveScopes: NgModuleTransitiveScopes) {
componentDef: ComponentDef<C>, transitiveScopes: NgModuleTransitiveScopes) {
componentDef.directiveDefs = () => Array.from(transitiveScopes.compilation.directives)
.map(dir => getDirectiveDef(dir) || getComponentDef(dir) !)
.filter(def => !!def);
@ -168,7 +168,7 @@ export function transitiveScopesFor<T>(moduleType: Type<T>): NgModuleTransitiveS
def.imports.forEach(<I>(imported: Type<I>) => {
const importedTyped = imported as Type<I>& {
// If imported is an @NgModule:
ngModuleDef?: NgModuleDefInternal<I>;
ngModuleDef?: NgModuleDef<I>;
};
if (!isNgModule<I>(importedTyped)) {
@ -187,7 +187,7 @@ export function transitiveScopesFor<T>(moduleType: Type<T>): NgModuleTransitiveS
// Components, Directives, NgModules, and Pipes can all be exported.
ngComponentDef?: any;
ngDirectiveDef?: any;
ngModuleDef?: NgModuleDefInternal<E>;
ngModuleDef?: NgModuleDef<E>;
ngPipeDef?: any;
};
@ -248,6 +248,6 @@ function isModuleWithProviders(value: any): value is ModuleWithProviders<{}> {
return (value as{ngModule?: any}).ngModule !== undefined;
}
function isNgModule<T>(value: Type<T>): value is Type<T>&{ngModuleDef: NgModuleDefInternal<T>} {
function isNgModule<T>(value: Type<T>): value is Type<T>&{ngModuleDef: NgModuleDef<T>} {
return !!getNgModuleDef(value);
}

View File

@ -11,14 +11,14 @@ import {StaticProvider} from '../di/provider';
import {createInjector} from '../di/r3_injector';
import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver';
import {InternalNgModuleRef, NgModuleFactory as viewEngine_NgModuleFactory, NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory';
import {NgModuleDefInternal} from '../metadata/ng_module';
import {NgModuleDef} from '../metadata/ng_module';
import {Type} from '../type';
import {stringify} from '../util';
import {assertDefined} from './assert';
import {ComponentFactoryResolver} from './component_ref';
import {getNgModuleDef} from './definition';
export interface NgModuleType { ngModuleDef: NgModuleDefInternal<any>; }
export interface NgModuleType { ngModuleDef: NgModuleDef<any>; }
export const COMPONENT_FACTORY_RESOLVER: StaticProvider = {
provide: viewEngine_ComponentFactoryResolver,

View File

@ -9,7 +9,7 @@
import {PipeTransform} from '../change_detection/pipe_transform';
import {getTView, load, store} from './instructions';
import {PipeDefInternal, PipeDefList} from './interfaces/definition';
import {PipeDef, PipeDefList} from './interfaces/definition';
import {HEADER_OFFSET} from './interfaces/view';
import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunctionV} from './pure_function';
@ -22,7 +22,7 @@ import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunction
*/
export function pipe(index: number, pipeName: string): any {
const tView = getTView();
let pipeDef: PipeDefInternal<any>;
let pipeDef: PipeDef<any>;
const adjustedIndex = index + HEADER_OFFSET;
if (tView.firstTemplatePass) {
@ -33,7 +33,7 @@ export function pipe(index: number, pipeName: string): any {
])).push(adjustedIndex, pipeDef.onDestroy);
}
} else {
pipeDef = tView.data[adjustedIndex] as PipeDefInternal<any>;
pipeDef = tView.data[adjustedIndex] as PipeDef<any>;
}
const pipeInstance = pipeDef.factory();
@ -49,7 +49,7 @@ export function pipe(index: number, pipeName: string): any {
* @param registry Full list of available pipes
* @returns Matching PipeDef
*/
function getPipeDef(name: string, registry: PipeDefList | null): PipeDefInternal<any> {
function getPipeDef(name: string, registry: PipeDefList | null): PipeDef<any> {
if (registry) {
for (let i = 0; i < registry.length; i++) {
const pipeDef = registry[i];
@ -151,5 +151,5 @@ export function pipeBindV(index: number, slotOffset: number, values: any[]): any
}
function isPure(index: number): boolean {
return (<PipeDefInternal<any>>getTView().data[index + HEADER_OFFSET]).pure;
return (<PipeDef<any>>getTView().data[index + HEADER_OFFSET]).pure;
}

View File

@ -20,7 +20,7 @@ import {getSymbolIterator} from '../util';
import {assertDefined, assertEqual} from './assert';
import {NG_ELEMENT_ID} from './fields';
import {_getViewData, assertPreviousIsParent, getOrCreateCurrentQueries, store, storeCleanupWithContext} from './instructions';
import {DirectiveDefInternal, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
import {unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeFlags, TNodeType, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
import {LQueries, QueryReadType, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
@ -258,7 +258,7 @@ function getIdxOfMatchingDirective(tNode: TNode, currentView: LViewData, type: T
const start = flags >> TNodeFlags.DirectiveStartingIndexShift;
const end = start + count;
for (let i = start; i < end; i++) {
const def = defs[i] as DirectiveDefInternal<any>;
const def = defs[i] as DirectiveDef<any>;
if (def.type === type && def.diPublic) {
return i;
}

View File

@ -9,7 +9,7 @@
import {EventEmitter, Output} from '../../src/core';
import {EMPTY} from '../../src/render3/definition';
import {InheritDefinitionFeature} from '../../src/render3/features/inherit_definition_feature';
import {ComponentDefInternal, DirectiveDefInternal, RenderFlags, defineBase, defineComponent, defineDirective} from '../../src/render3/index';
import {ComponentDef, DirectiveDef, RenderFlags, defineBase, defineComponent, defineDirective} from '../../src/render3/index';
describe('InheritDefinitionFeature', () => {
it('should inherit lifecycle hooks', () => {
@ -36,7 +36,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const finalDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const finalDef = SubDirective.ngDirectiveDef as DirectiveDef<any>;
expect(finalDef.onInit).toBe(SuperDirective.prototype.ngOnInit);
@ -75,7 +75,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = SubDirective.ngDirectiveDef as DirectiveDef<any>;
expect(subDef.inputs).toEqual({
foo: 'superFoo',
@ -118,7 +118,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = SubDirective.ngDirectiveDef as DirectiveDef<any>;
expect(subDef.outputs).toEqual({
foo: 'superFoo',
@ -152,7 +152,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = SubDirective.ngDirectiveDef as DirectiveDef<any>;
expect(subDef.inputs).toEqual({
testIn: 'testIn',
@ -216,7 +216,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = Class1.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = Class1.ngDirectiveDef as DirectiveDef<any>;
expect(subDef.inputs).toEqual({
input1: 'input1',
@ -288,7 +288,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = Class1.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = Class1.ngDirectiveDef as DirectiveDef<any>;
expect(subDef.outputs).toEqual({
alias1: 'output1',
@ -325,7 +325,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = SubDirective.ngDirectiveDef as DirectiveDef<any>;
subDef.hostBindings !(1, 2);
@ -364,7 +364,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = SubComponent.ngComponentDef as ComponentDefInternal<any>;
const subDef = SubComponent.ngComponentDef as ComponentDef<any>;
const context = {foo: 'bar'};
@ -395,7 +395,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = SubDirective.ngDirectiveDef as DirectiveDef<any>;
subDef.contentQueries !();
@ -428,7 +428,7 @@ describe('InheritDefinitionFeature', () => {
});
}
const subDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = SubDirective.ngDirectiveDef as DirectiveDef<any>;
subDef.contentQueriesRefresh !(1, 2);
@ -487,8 +487,8 @@ describe('InheritDefinitionFeature', () => {
});
}
const superDef = SuperDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const subDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
const superDef = SuperDirective.ngDirectiveDef as DirectiveDef<any>;
const subDef = SubDirective.ngDirectiveDef as DirectiveDef<any>;
expect(log).toEqual([
'super1',

View File

@ -8,7 +8,7 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
import * as $r3$ from '../../../src/core_render3_private_export';
import {ComponentDefInternal} from '../../../src/render3/interfaces/definition';
import {ComponentDef} from '../../../src/render3/interfaces/definition';
import {renderComponent, toHtml} from '../render_util';
@ -82,9 +82,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyComponent.ngComponentDef as ComponentDefInternal<any>).directiveDefs = [
(ChildComponent.ngComponentDef as ComponentDefInternal<any>), SomeDirective.ngDirectiveDef
];
(MyComponent.ngComponentDef as ComponentDef<any>).directiveDefs =
[(ChildComponent.ngComponentDef as ComponentDef<any>), SomeDirective.ngDirectiveDef];
// /NON-NORMATIVE
expect(renderComp(MyComponent)).toEqual('<child some-directive="">child-view</child>!');
@ -136,8 +135,7 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[HostBindingDir.ngDirectiveDef];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [HostBindingDir.ngDirectiveDef];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<div hostbindingdir="" id="some id"></div>`);
@ -191,8 +189,7 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[HostListenerDir.ngDirectiveDef];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [HostListenerDir.ngDirectiveDef];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<button hostlistenerdir="">Click</button>`);
@ -238,8 +235,7 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[HostAttributeDir.ngDirectiveDef];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [HostAttributeDir.ngDirectiveDef];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<div hostattributedir="" role="listbox"></div>`);
@ -291,8 +287,7 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[HostBindingDir.ngDirectiveDef];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [HostBindingDir.ngDirectiveDef];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<div aria-label="some label" hostbindingdir=""></div>`);
@ -361,8 +356,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[(MyComp.ngComponentDef as ComponentDefInternal<any>)];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[(MyComp.ngComponentDef as ComponentDef<any>)];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<my-comp>some name</my-comp>`);
@ -495,8 +490,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[(MyArrayComp.ngComponentDef as ComponentDefInternal<any>)];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[(MyArrayComp.ngComponentDef as ComponentDef<any>)];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<my-array-comp>Nancy Bess</my-array-comp>`);
@ -542,8 +537,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[(MyArrayComp.ngComponentDef as ComponentDefInternal<any>)];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[(MyArrayComp.ngComponentDef as ComponentDef<any>)];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<my-array-comp>NANCY Bess</my-array-comp>`);
@ -612,8 +607,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[(MyComp.ngComponentDef as ComponentDefInternal<any>)];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[(MyComp.ngComponentDef as ComponentDef<any>)];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<my-comp>3</my-comp>`);
@ -657,8 +652,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[(MyArrayComp.ngComponentDef as ComponentDefInternal<any>)];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[(MyArrayComp.ngComponentDef as ComponentDef<any>)];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<my-array-comp>Nancy Bess</my-array-comp>`);
@ -774,8 +769,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[(MyComp.ngComponentDef as ComponentDefInternal<any>)];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[(MyComp.ngComponentDef as ComponentDef<any>)];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<my-comp>start-abcde-middle-fghi-end</my-comp>`);
@ -854,8 +849,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[(ObjectComp.ngComponentDef as ComponentDefInternal<any>)];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[(ObjectComp.ngComponentDef as ComponentDef<any>)];
// /NON-NORMATIVE
expect(renderComp(MyApp)).toEqual(`<object-comp><p>500</p><p>slide</p></object-comp>`);
@ -948,8 +943,8 @@ describe('components & directives', () => {
}
// NON-NORMATIVE (done by defineNgModule)
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[(NestedComp.ngComponentDef as ComponentDefInternal<any>)];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[(NestedComp.ngComponentDef as ComponentDef<any>)];
// /NON-NORMATIVE
expect(renderComp(MyApp))

View File

@ -9,7 +9,7 @@
import {Component} from '../../../src/core';
import * as $r3$ from '../../../src/core_render3_private_export';
import {AttributeMarker} from '../../../src/render3';
import {ComponentDefInternal, InitialStylingFlags} from '../../../src/render3/interfaces/definition';
import {ComponentDef, InitialStylingFlags} from '../../../src/render3/interfaces/definition';
import {ComponentFixture, renderComponent, toHtml} from '../render_util';
@ -107,8 +107,7 @@ describe('elements', () => {
}
// NON-NORMATIVE
(LocalRefComp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
() => [Dir.ngDirectiveDef];
(LocalRefComp.ngComponentDef as ComponentDef<any>).directiveDefs = () => [Dir.ngDirectiveDef];
// /NON-NORMATIVE
const fixture = new ComponentFixture(LocalRefComp);

View File

@ -8,7 +8,7 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
import * as $r3$ from '../../../src/core_render3_private_export';
import {ComponentDefInternal} from '../../../src/render3/interfaces/definition';
import {ComponentDef} from '../../../src/render3/interfaces/definition';
import {renderComponent, toHtml} from '../render_util';
@ -88,8 +88,7 @@ describe('lifecycle hooks', () => {
}
// NON-NORMATIVE
(SimpleLayout.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
[LifecycleComp.ngComponentDef];
(SimpleLayout.ngComponentDef as ComponentDef<any>).directiveDefs = [LifecycleComp.ngComponentDef];
// /NON-NORMATIVE
it('should gen hooks with a few simple components', () => {

View File

@ -8,7 +8,7 @@
import {Component, Directive, Input, OnDestroy, Pipe, PipeTransform, TemplateRef, ViewContainerRef} from '../../../src/core';
import * as $r3$ from '../../../src/core_render3_private_export';
import {ComponentDefInternal} from '../../../src/render3/interfaces/definition';
import {ComponentDef} from '../../../src/render3/interfaces/definition';
import {containerEl, renderComponent, toHtml} from '../render_util';
@ -105,7 +105,7 @@ describe('pipes', () => {
}
// NON-NORMATIVE
(MyApp.ngComponentDef as ComponentDefInternal<any>).pipeDefs =
(MyApp.ngComponentDef as ComponentDef<any>).pipeDefs =
() => [MyPurePipe.ngPipeDef, MyPipe.ngPipeDef];
// /NON-NORMATIVE
@ -205,8 +205,8 @@ describe('pipes', () => {
}
// NON-NORMATIVE
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs = [OneTimeIf.ngDirectiveDef];
(MyApp.ngComponentDef as ComponentDefInternal<any>).pipeDefs = [MyPurePipe.ngPipeDef];
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [OneTimeIf.ngDirectiveDef];
(MyApp.ngComponentDef as ComponentDef<any>).pipeDefs = [MyPurePipe.ngPipeDef];
// /NON-NORMATIVE
let myApp: MyApp = renderComponent(MyApp);

View File

@ -8,7 +8,7 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
import * as $r3$ from '../../../src/core_render3_private_export';
import {ComponentDefInternal} from '../../../src/render3/interfaces/definition';
import {ComponentDef} from '../../../src/render3/interfaces/definition';
import {renderComponent, toHtml} from '../render_util';
@ -80,7 +80,7 @@ describe('queries', () => {
}
// NON-NORMATIVE
(ViewQueryComponent.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
(ViewQueryComponent.ngComponentDef as ComponentDef<any>).directiveDefs =
[SomeDirective.ngDirectiveDef];
// /NON-NORMATIVE
@ -171,7 +171,7 @@ describe('queries', () => {
}
// NON-NORMATIVE
(MyApp.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
[ContentQueryComponent.ngComponentDef, SomeDirective.ngDirectiveDef];
// /NON-NORMATIVE

View File

@ -100,7 +100,7 @@ class ToDoAppComponent {
}
// NON-NORMATIVE
(ToDoAppComponent.ngComponentDef as r3.ComponentDefInternal<any>).directiveDefs = () =>
(ToDoAppComponent.ngComponentDef as r3.ComponentDef<any>).directiveDefs = () =>
[ToDoItemComponent.ngComponentDef, (NgForOf as r3.DirectiveType<NgForOf<any>>).ngDirectiveDef];
// /NON-NORMATIVE

View File

@ -8,7 +8,7 @@
import {Component, Directive, Input, SimpleChanges, TemplateRef, ViewContainerRef, inject} from '../../../src/core';
import * as $r3$ from '../../../src/core_render3_private_export';
import {ComponentDefInternal} from '../../../src/render3/interfaces/definition';
import {ComponentDef} from '../../../src/render3/interfaces/definition';
import {renderComponent, toHtml} from '../render_util';
@ -129,7 +129,7 @@ describe('template variables', () => {
}
// NON-NORMATIVE
(MyComponent.ngComponentDef as ComponentDefInternal<any>).directiveDefs =
(MyComponent.ngComponentDef as ComponentDef<any>).directiveDefs =
[ForOfDirective.ngDirectiveDef];
// /NON-NORMATIVE

View File

@ -11,7 +11,7 @@ import {DoCheck, Input, TemplateRef, ViewContainerRef, ViewEncapsulation, create
import {getRenderedText} from '../../src/render3/component';
import {AttributeMarker, ComponentFactory, LifecycleHooksFeature, defineComponent, directiveInject, markDirty, template} from '../../src/render3/index';
import {bind, container, containerRefreshEnd, containerRefreshStart, element, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, nextContext, text, textBinding, tick} from '../../src/render3/instructions';
import {ComponentDefInternal, DirectiveDefInternal, RenderFlags} from '../../src/render3/interfaces/definition';
import {ComponentDef, DirectiveDef, RenderFlags} from '../../src/render3/interfaces/definition';
import {createRendererType2} from '../../src/view/index';
import {NgIf} from './common_with_def';
@ -386,7 +386,7 @@ describe('recursive components', () => {
});
}
(TreeComponent.ngComponentDef as ComponentDefInternal<TreeComponent>).directiveDefs =
(TreeComponent.ngComponentDef as ComponentDef<TreeComponent>).directiveDefs =
() => [TreeComponent.ngComponentDef];
/**
@ -446,7 +446,7 @@ describe('recursive components', () => {
}
}
(NgIfTree.ngComponentDef as ComponentDefInternal<NgIfTree>).directiveDefs =
(NgIfTree.ngComponentDef as ComponentDef<NgIfTree>).directiveDefs =
() => [NgIfTree.ngComponentDef, NgIf.ngDirectiveDef];
function _buildTree(currDepth: number): TreeNode {

View File

@ -13,8 +13,8 @@ import {Injectable} from '@angular/core/src/di/injectable';
import {inject, setCurrentInjector} from '@angular/core/src/di/injector';
import {ivyEnabled} from '@angular/core/src/ivy_switch/compiler/index';
import {Component, HostBinding, HostListener, Input, Output, Pipe} from '@angular/core/src/metadata/directives';
import {NgModule, NgModuleDefInternal} from '@angular/core/src/metadata/ng_module';
import {ComponentDefInternal, PipeDefInternal} from '@angular/core/src/render3/interfaces/definition';
import {NgModule, NgModuleDef} from '@angular/core/src/metadata/ng_module';
import {ComponentDef, PipeDef} from '@angular/core/src/render3/interfaces/definition';
ivyEnabled && describe('render3 jit', () => {
@ -155,7 +155,7 @@ ivyEnabled && describe('render3 jit', () => {
class Module {
}
const moduleDef: NgModuleDefInternal<Module> = (Module as any).ngModuleDef;
const moduleDef: NgModuleDef<Module> = (Module as any).ngModuleDef;
expect(moduleDef).toBeDefined();
expect(moduleDef.declarations.length).toBe(1);
expect(moduleDef.declarations[0]).toBe(Cmp);
@ -193,7 +193,7 @@ ivyEnabled && describe('render3 jit', () => {
})
class Cmp {
}
const cmpDef: ComponentDefInternal<Cmp> = (Cmp as any).ngComponentDef;
const cmpDef: ComponentDef<Cmp> = (Cmp as any).ngComponentDef;
expect(cmpDef.directiveDefs).toBeNull();
@ -203,7 +203,7 @@ ivyEnabled && describe('render3 jit', () => {
class Module {
}
const moduleDef: NgModuleDefInternal<Module> = (Module as any).ngModuleDef;
const moduleDef: NgModuleDef<Module> = (Module as any).ngModuleDef;
expect(cmpDef.directiveDefs instanceof Function).toBe(true);
expect((cmpDef.directiveDefs as Function)()).toEqual([cmpDef]);
});
@ -225,7 +225,7 @@ ivyEnabled && describe('render3 jit', () => {
onChange(event: any): void {}
}
const cmpDef = (Cmp as any).ngComponentDef as ComponentDefInternal<Cmp>;
const cmpDef = (Cmp as any).ngComponentDef as ComponentDef<Cmp>;
expect(cmpDef.hostBindings).toBeDefined();
expect(cmpDef.hostBindings !.length).toBe(2);
@ -236,7 +236,7 @@ ivyEnabled && describe('render3 jit', () => {
class P {
}
const pipeDef = (P as any).ngPipeDef as PipeDefInternal<P>;
const pipeDef = (P as any).ngPipeDef as PipeDef<P>;
expect(pipeDef.name).toBe('test-pipe');
expect(pipeDef.pure).toBe(false, 'pipe should not be pure');
expect(pipeDef.factory() instanceof P)
@ -248,7 +248,7 @@ ivyEnabled && describe('render3 jit', () => {
class P {
}
const pipeDef = (P as any).ngPipeDef as PipeDefInternal<P>;
const pipeDef = (P as any).ngPipeDef as PipeDef<P>;
expect(pipeDef.pure).toBe(true, 'pipe should be pure');
});

View File

@ -13,11 +13,11 @@ import {angularCoreEnv} from '../../src/render3/jit/environment';
const INTERFACE_EXCEPTIONS = new Set<string>([
'ɵBaseDef',
'ɵComponentDef',
'ɵDirectiveDef',
'ɵComponentDefWithMeta',
'ɵDirectiveDefWithMeta',
'ɵInjectorDef',
'ɵNgModuleDef',
'ɵPipeDef',
'ɵNgModuleDefWithMeta',
'ɵPipeDefWithMeta',
]);
describe('r3 jit environment', () => {

View File

@ -8,7 +8,7 @@
import {DoCheck, EventEmitter, Input, OnChanges, Output, SimpleChange, SimpleChanges} from '../../src/core';
import {InheritDefinitionFeature} from '../../src/render3/features/inherit_definition_feature';
import {DirectiveDefInternal, NgOnChangesFeature, defineComponent, defineDirective} from '../../src/render3/index';
import {DirectiveDef, NgOnChangesFeature, defineComponent, defineDirective} from '../../src/render3/index';
describe('NgOnChangesFeature', () => {
it('should patch class', () => {
@ -36,14 +36,14 @@ describe('NgOnChangesFeature', () => {
}
const myDir =
(MyDirective.ngDirectiveDef as DirectiveDefInternal<MyDirective>).factory() as MyDirective;
(MyDirective.ngDirectiveDef as DirectiveDef<MyDirective>).factory() as MyDirective;
myDir.valA = 'first';
expect(myDir.valA).toEqual('first');
myDir.valB = 'second';
expect(myDir.log).toEqual(['second']);
expect(myDir.valB).toEqual('works');
myDir.log.length = 0;
(MyDirective.ngDirectiveDef as DirectiveDefInternal<MyDirective>).doCheck !.call(myDir);
(MyDirective.ngDirectiveDef as DirectiveDef<MyDirective>).doCheck !.call(myDir);
const changeA = new SimpleChange(undefined, 'first', true);
const changeB = new SimpleChange(undefined, 'second', true);
expect(myDir.log).toEqual(['ngOnChanges', 'valA', changeA, 'valB', changeB, 'ngDoCheck']);
@ -88,8 +88,8 @@ describe('NgOnChangesFeature', () => {
});
}
const myDir = (SubDirective.ngDirectiveDef as DirectiveDefInternal<SubDirective>)
.factory() as SubDirective;
const myDir =
(SubDirective.ngDirectiveDef as DirectiveDef<SubDirective>).factory() as SubDirective;
myDir.valA = 'first';
expect(myDir.valA).toEqual('first');
@ -100,7 +100,7 @@ describe('NgOnChangesFeature', () => {
expect(myDir.valC).toEqual('third');
log.length = 0;
(SubDirective.ngDirectiveDef as DirectiveDefInternal<SubDirective>).doCheck !.call(myDir);
(SubDirective.ngDirectiveDef as DirectiveDef<SubDirective>).doCheck !.call(myDir);
const changeA = new SimpleChange(undefined, 'first', true);
const changeB = new SimpleChange(undefined, 'second', true);
const changeC = new SimpleChange(undefined, 'third', true);
@ -141,12 +141,12 @@ describe('NgOnChangesFeature', () => {
});
}
const myDir = (SubDirective.ngDirectiveDef as DirectiveDefInternal<SubDirective>)
.factory() as SubDirective;
const myDir =
(SubDirective.ngDirectiveDef as DirectiveDef<SubDirective>).factory() as SubDirective;
myDir.valA = 'first';
myDir.valB = 'second';
(SubDirective.ngDirectiveDef as DirectiveDefInternal<SubDirective>).doCheck !.call(myDir);
(SubDirective.ngDirectiveDef as DirectiveDef<SubDirective>).doCheck !.call(myDir);
const changeA = new SimpleChange(undefined, 'first', true);
const changeB = new SimpleChange(undefined, 'second', true);
expect(log).toEqual([changeA, changeB, 'sub ngDoCheck']);
@ -182,12 +182,12 @@ describe('NgOnChangesFeature', () => {
});
}
const myDir = (SubDirective.ngDirectiveDef as DirectiveDefInternal<SubDirective>)
.factory() as SubDirective;
const myDir =
(SubDirective.ngDirectiveDef as DirectiveDef<SubDirective>).factory() as SubDirective;
myDir.valA = 'first';
myDir.valB = 'second';
(SubDirective.ngDirectiveDef as DirectiveDefInternal<SubDirective>).doCheck !.call(myDir);
(SubDirective.ngDirectiveDef as DirectiveDef<SubDirective>).doCheck !.call(myDir);
const changeA = new SimpleChange(undefined, 'first', true);
const changeB = new SimpleChange(undefined, 'second', true);
expect(log).toEqual([changeA, changeB, 'super ngDoCheck']);
@ -236,8 +236,8 @@ describe('NgOnChangesFeature', () => {
});
}
const myDir = (SubDirective.ngDirectiveDef as DirectiveDefInternal<SubDirective>)
.factory() as SubDirective;
const myDir =
(SubDirective.ngDirectiveDef as DirectiveDef<SubDirective>).factory() as SubDirective;
myDir.valA = 'first';
expect(myDir.valA).toEqual('first');
@ -249,7 +249,7 @@ describe('NgOnChangesFeature', () => {
expect(myDir.valC).toEqual('third');
log.length = 0;
(SubDirective.ngDirectiveDef as DirectiveDefInternal<SubDirective>).doCheck !.call(myDir);
(SubDirective.ngDirectiveDef as DirectiveDef<SubDirective>).doCheck !.call(myDir);
const changeA = new SimpleChange(undefined, 'first', true);
const changeB = new SimpleChange(undefined, 'second', true);
const changeC = new SimpleChange(undefined, 'third', true);
@ -279,17 +279,17 @@ describe('NgOnChangesFeature', () => {
}
const myDir =
(MyDirective.ngDirectiveDef as DirectiveDefInternal<MyDirective>).factory() as MyDirective;
(MyDirective.ngDirectiveDef as DirectiveDef<MyDirective>).factory() as MyDirective;
myDir.valA = 'first';
myDir.valB = 'second';
(MyDirective.ngDirectiveDef as DirectiveDefInternal<MyDirective>).doCheck !.call(myDir);
(MyDirective.ngDirectiveDef as DirectiveDef<MyDirective>).doCheck !.call(myDir);
const changeA1 = new SimpleChange(undefined, 'first', true);
const changeB1 = new SimpleChange(undefined, 'second', true);
expect(myDir.log).toEqual(['valA', changeA1, 'valB', changeB1]);
myDir.log.length = 0;
myDir.valA = 'third';
(MyDirective.ngDirectiveDef as DirectiveDefInternal<MyDirective>).doCheck !.call(myDir);
(MyDirective.ngDirectiveDef as DirectiveDef<MyDirective>).doCheck !.call(myDir);
const changeA2 = new SimpleChange('first', 'third', false);
expect(myDir.log).toEqual(['valA', changeA2, 'valB', undefined]);
});
@ -315,10 +315,10 @@ describe('NgOnChangesFeature', () => {
}
const myDir =
(MyDirective.ngDirectiveDef as DirectiveDefInternal<MyDirective>).factory() as MyDirective;
(MyDirective.ngDirectiveDef as DirectiveDef<MyDirective>).factory() as MyDirective;
myDir.onlySetter = 'someValue';
expect(myDir.onlySetter).toBeUndefined();
(MyDirective.ngDirectiveDef as DirectiveDefInternal<MyDirective>).doCheck !.call(myDir);
(MyDirective.ngDirectiveDef as DirectiveDef<MyDirective>).doCheck !.call(myDir);
const changeSetter = new SimpleChange(undefined, 'someValue', true);
expect(myDir.log).toEqual(['someValue', 'ngOnChanges', 'onlySetter', changeSetter]);
});

View File

@ -18,9 +18,9 @@ import {CreateComponentOptions} from '../../src/render3/component';
import {getContext, isComponentInstance} from '../../src/render3/context_discovery';
import {extractDirectiveDef, extractPipeDef} from '../../src/render3/definition';
import {NG_ELEMENT_ID} from '../../src/render3/fields';
import {ComponentTemplate, ComponentType, DirectiveDefInternal, DirectiveType, PublicFeature, RenderFlags, defineComponent, defineDirective, renderComponent as _renderComponent, tick} from '../../src/render3/index';
import {ComponentTemplate, ComponentType, DirectiveDef, DirectiveType, PublicFeature, RenderFlags, defineComponent, defineDirective, renderComponent as _renderComponent, tick} from '../../src/render3/index';
import {renderTemplate} from '../../src/render3/instructions';
import {DirectiveDefList, DirectiveTypesOrFactory, PipeDefInternal, PipeDefList, PipeTypesOrFactory} from '../../src/render3/interfaces/definition';
import {DirectiveDefList, DirectiveTypesOrFactory, PipeDef, PipeDefList, PipeTypesOrFactory} from '../../src/render3/interfaces/definition';
import {LElementNode} from '../../src/render3/interfaces/node';
import {PlayerHandler} from '../../src/render3/interfaces/player';
import {RElement, RText, Renderer3, RendererFactory3, domRendererFactory3} from '../../src/render3/interfaces/renderer';
@ -198,13 +198,13 @@ export function renderToHtml(
function toDefs(
types: DirectiveTypesOrFactory | undefined | null,
mapFn: (type: Type<any>) => DirectiveDefInternal<any>): DirectiveDefList|null;
mapFn: (type: Type<any>) => DirectiveDef<any>): DirectiveDefList|null;
function toDefs(
types: PipeTypesOrFactory | undefined | null,
mapFn: (type: Type<any>) => PipeDefInternal<any>): PipeDefList|null;
mapFn: (type: Type<any>) => PipeDef<any>): PipeDefList|null;
function toDefs(
types: PipeTypesOrFactory | DirectiveTypesOrFactory | undefined | null,
mapFn: (type: Type<any>) => PipeDefInternal<any>| DirectiveDefInternal<any>): any {
mapFn: (type: Type<any>) => PipeDef<any>| DirectiveDef<any>): any {
if (!types) return null;
if (typeof types == 'function') {
types = types();

View File

@ -965,7 +965,7 @@ describe('ViewContainerRef', () => {
{provide: RendererFactory2, useValue: getRendererFactory2(document)}
]
});
static ngModuleDef: NgModuleDef<any, any, any, any> = { bootstrap: [] } as any;
static ngModuleDef: NgModuleDef<any> = { bootstrap: [] } as any;
}
const myAppModuleFactory = new NgModuleFactory(MyAppModule);
const ngModuleRef = myAppModuleFactory.create(null);

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Component, Directive, Injector, NgModule, Pipe, PlatformRef, Provider, RendererFactory2, SchemaMetadata, Type, ɵInjectableDef as InjectableDef, ɵNgModuleDefInternal as NgModuleDefInternal, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵRender3ComponentFactory as ComponentFactory, ɵRender3DebugRendererFactory2 as Render3DebugRendererFactory2, ɵRender3NgModuleRef as NgModuleRef, ɵWRAP_RENDERER_FACTORY2 as WRAP_RENDERER_FACTORY2, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵgetInjectableDef as getInjectableDef, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵstringify as stringify} from '@angular/core';
import {Component, Directive, Injector, NgModule, Pipe, PlatformRef, Provider, RendererFactory2, SchemaMetadata, Type, ɵInjectableDef as InjectableDef, ɵNgModuleDef as NgModuleDef, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵRender3ComponentFactory as ComponentFactory, ɵRender3DebugRendererFactory2 as Render3DebugRendererFactory2, ɵRender3NgModuleRef as NgModuleRef, ɵWRAP_RENDERER_FACTORY2 as WRAP_RENDERER_FACTORY2, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵgetInjectableDef as getInjectableDef, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵstringify as stringify} from '@angular/core';
import {ComponentFixture} from './component_fixture';
import {MetadataOverride} from './metadata_override';
@ -557,7 +557,7 @@ function transitiveScopesFor<T>(
// Components, Directives, NgModules, and Pipes can all be exported.
ngComponentDef?: any;
ngDirectiveDef?: any;
ngModuleDef?: NgModuleDefInternal<E>;
ngModuleDef?: NgModuleDef<E>;
ngPipeDef?: any;
};
@ -598,6 +598,6 @@ function flatten<T>(values: any[]): T[] {
return out;
}
function isNgModule<T>(value: Type<T>): value is Type<T>&{ngModuleDef: NgModuleDefInternal<T>} {
return (value as{ngModuleDef?: NgModuleDefInternal<T>}).ngModuleDef !== undefined;
function isNgModule<T>(value: Type<T>): value is Type<T>&{ngModuleDef: NgModuleDef<T>} {
return (value as{ngModuleDef?: NgModuleDef<T>}).ngModuleDef !== undefined;
}