revert: refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371)

This reverts commit 2c09b707ce.
This commit is contained in:
Igor Minar 2018-04-13 23:02:29 -07:00
parent 80e483ceac
commit 674c3def31
32 changed files with 172 additions and 179 deletions

View File

@ -7,7 +7,7 @@
*/ */
import {ɵC as C, ɵE as E, ɵRenderFlags as RenderFlags, ɵT as T, ɵV as V, ɵb as b, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as detectChanges, ɵe as e, ɵsn as sn, ɵt as t, ɵv as v} from '@angular/core'; import {ɵC as C, ɵE as E, ɵRenderFlags as RenderFlags, ɵT as T, ɵV as V, ɵb as b, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as detectChanges, ɵe as e, ɵsn as sn, ɵt as t, ɵv as v} from '@angular/core';
import {ɵComponentDef} from '@angular/core/src/render3/interfaces/definition'; import {ComponentDef} from '@angular/core/src/render3/interfaces/definition';
import {TableCell, buildTable, emptyTable} from '../util'; import {TableCell, buildTable, emptyTable} from '../util';
@ -15,7 +15,7 @@ export class LargeTableComponent {
data: TableCell[][] = emptyTable; data: TableCell[][] = emptyTable;
/** @nocollapse */ /** @nocollapse */
static ngComponentDef: ɵComponentDef<LargeTableComponent> = defineComponent({ static ngComponentDef: ComponentDef<LargeTableComponent> = defineComponent({
type: LargeTableComponent, type: LargeTableComponent,
selectors: [['largetable']], selectors: [['largetable']],
template: function(rf: RenderFlags, ctx: LargeTableComponent) { template: function(rf: RenderFlags, ctx: LargeTableComponent) {

View File

@ -7,7 +7,7 @@
*/ */
import {ɵC as C, ɵE as E, ɵRenderFlags as RenderFlags, ɵT as T, ɵV as V, ɵb as b, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as _detectChanges, ɵe as e, ɵi1 as i1, ɵp as p, ɵsn as sn, ɵt as t, ɵv as v} from '@angular/core'; import {ɵC as C, ɵE as E, ɵRenderFlags as RenderFlags, ɵT as T, ɵV as V, ɵb as b, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as _detectChanges, ɵe as e, ɵi1 as i1, ɵp as p, ɵsn as sn, ɵt as t, ɵv as v} from '@angular/core';
import {ɵComponentDef} from '@angular/core/src/render3/interfaces/definition'; import {ComponentDef} from '@angular/core/src/render3/interfaces/definition';
import {TreeNode, buildTree, emptyTree} from '../util'; import {TreeNode, buildTree, emptyTree} from '../util';
@ -35,7 +35,7 @@ export class TreeComponent {
data: TreeNode = emptyTree; data: TreeNode = emptyTree;
/** @nocollapse */ /** @nocollapse */
static ngComponentDef: ɵComponentDef<TreeComponent> = defineComponent({ static ngComponentDef: ComponentDef<TreeComponent> = defineComponent({
type: TreeComponent, type: TreeComponent,
selectors: [['tree']], selectors: [['tree']],
template: function(rf: RenderFlags, ctx: TreeComponent) { template: function(rf: RenderFlags, ctx: TreeComponent) {
@ -95,7 +95,7 @@ export class TreeFunction {
data: TreeNode = emptyTree; data: TreeNode = emptyTree;
/** @nocollapse */ /** @nocollapse */
static ngComponentDef: ɵComponentDef<TreeFunction> = defineComponent({ static ngComponentDef: ComponentDef<TreeFunction> = defineComponent({
type: TreeFunction, type: TreeFunction,
selectors: [['tree']], selectors: [['tree']],
template: function(rf: RenderFlags, ctx: TreeFunction) { template: function(rf: RenderFlags, ctx: TreeFunction) {

View File

@ -2151,7 +2151,7 @@ describe('ngc transformer command-line', () => {
}); });
}); });
it('compiles a basic ɵInjectableDef', () => { it('compiles a basic InjectableDef', () => {
const source = compileService(` const source = compileService(`
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Module} from './module'; import {Module} from './module';
@ -2187,7 +2187,7 @@ describe('ngc transformer command-line', () => {
expect(source).toMatch(/\/\*\* @nocollapse \*\/ Service\.ngInjectableDef =/); expect(source).toMatch(/\/\*\* @nocollapse \*\/ Service\.ngInjectableDef =/);
}); });
it('compiles a useValue ɵInjectableDef', () => { it('compiles a useValue InjectableDef', () => {
const source = compileService(` const source = compileService(`
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Module} from './module'; import {Module} from './module';
@ -2203,7 +2203,7 @@ describe('ngc transformer command-line', () => {
expect(source).toMatch(/ngInjectableDef.*return CONST_SERVICE/); expect(source).toMatch(/ngInjectableDef.*return CONST_SERVICE/);
}); });
it('compiles a useExisting ɵInjectableDef', () => { it('compiles a useExisting InjectableDef', () => {
const source = compileService(` const source = compileService(`
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Module} from './module'; import {Module} from './module';
@ -2220,7 +2220,7 @@ describe('ngc transformer command-line', () => {
expect(source).toMatch(/ngInjectableDef.*return ..\.inject\(Existing\)/); expect(source).toMatch(/ngInjectableDef.*return ..\.inject\(Existing\)/);
}); });
it('compiles a useFactory ɵInjectableDef with optional dep', () => { it('compiles a useFactory InjectableDef with optional dep', () => {
const source = compileService(` const source = compileService(`
import {Injectable, Optional} from '@angular/core'; import {Injectable, Optional} from '@angular/core';
import {Module} from './module'; import {Module} from './module';
@ -2240,7 +2240,7 @@ describe('ngc transformer command-line', () => {
expect(source).toMatch(/ngInjectableDef.*return ..\(..\.inject\(Existing, 8\)/); expect(source).toMatch(/ngInjectableDef.*return ..\(..\.inject\(Existing, 8\)/);
}); });
it('compiles a useFactory ɵInjectableDef with skip-self dep', () => { it('compiles a useFactory InjectableDef with skip-self dep', () => {
const source = compileService(` const source = compileService(`
import {Injectable, SkipSelf} from '@angular/core'; import {Injectable, SkipSelf} from '@angular/core';
import {Module} from './module'; import {Module} from './module';

View File

@ -6,13 +6,12 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {defineInjectable, ɵInjectableDef} from '../../di/defs'; import {InjectableDef, defineInjectable} from '../../di/defs';
import {Optional, SkipSelf} from '../../di/metadata'; import {Optional, SkipSelf} from '../../di/metadata';
import {StaticProvider} from '../../di/provider'; import {StaticProvider} from '../../di/provider';
import {DefaultIterableDifferFactory} from '../differs/default_iterable_differ'; import {DefaultIterableDifferFactory} from '../differs/default_iterable_differ';
/** /**
* A type describing supported iterable types. * A type describing supported iterable types.
* *
@ -138,7 +137,7 @@ export interface IterableDifferFactory {
* *
*/ */
export class IterableDiffers { export class IterableDiffers {
static ngInjectableDef: ɵInjectableDef<IterableDiffers> = defineInjectable({ static ngInjectableDef: InjectableDef<IterableDiffers> = defineInjectable({
providedIn: 'root', providedIn: 'root',
factory: () => new IterableDiffers([new DefaultIterableDifferFactory()]) factory: () => new IterableDiffers([new DefaultIterableDifferFactory()])
}); });

View File

@ -75,9 +75,9 @@ export {
st as ɵst, st as ɵst,
ld as ɵld, ld as ɵld,
Pp as ɵPp, Pp as ɵPp,
ɵComponentDef, ComponentDef as ɵComponentDef,
ɵDirectiveDef, DirectiveDef as ɵDirectiveDef,
ɵPipeDef, PipeDef as ɵPipeDef,
whenRendered as ɵwhenRendered, whenRendered as ɵwhenRendered,
} from './render3/index'; } from './render3/index';
export { export {

View File

@ -17,15 +17,14 @@ import {ClassProvider, ClassSansProvider, ConstructorProvider, ConstructorSansPr
* requesting injection of other types if necessary. * requesting injection of other types if necessary.
* *
* Optionally, a `providedIn` parameter specifies that the given type belongs to a particular * Optionally, a `providedIn` parameter specifies that the given type belongs to a particular
* `ɵInjectorDef`, `NgModule`, or a special scope (e.g. `'root'`). A value of `null` indicates * `InjectorDef`, `NgModule`, or a special scope (e.g. `'root'`). A value of `null` indicates
* that the injectable does not belong to any scope. * that the injectable does not belong to any scope.
* *
* NOTE: This is a semi public API, and there are no guaranties that the shape of this API will * This type is typically generated by the Angular compiler, but can be hand-written if needed.
* remain consistent between version. Use with caution.
* *
* @experimental * @experimental
*/ */
export interface ɵInjectableDef<T> { export interface InjectableDef<T> {
/** /**
* Specifies that the given type belongs to a particular injector: * Specifies that the given type belongs to a particular injector:
* - `InjectorType` such as `NgModule`, * - `InjectorType` such as `NgModule`,
@ -51,13 +50,13 @@ export interface ɵInjectableDef<T> {
* Information about the providers to be included in an `Injector` as well as how the given type * Information about the providers to be included in an `Injector` as well as how the given type
* which carries the information should be created by the DI system. * which carries the information should be created by the DI system.
* *
* An `ɵInjectorDef` can import other types which have `InjectorDefs`, forming a deep nested * An `InjectorDef` can import other types which have `InjectorDefs`, forming a deep nested
* structure of providers with a defined priority (identically to how `NgModule`s also have * structure of providers with a defined priority (identically to how `NgModule`s also have
* an import/dependency structure). * an import/dependency structure).
* *
* @experimental * @experimental
*/ */
export interface ɵInjectorDef<T> { export interface InjectorDef<T> {
factory: () => T; factory: () => T;
// TODO(alxhub): Narrow down the type here once decorators properly change the return type of the // TODO(alxhub): Narrow down the type here once decorators properly change the return type of the
@ -69,29 +68,29 @@ export interface ɵInjectorDef<T> {
} }
/** /**
* A `Type` which has an `ɵInjectableDef` static field. * A `Type` which has an `InjectableDef` static field.
* *
* `InjectableDefType`s contain their own Dependency Injection metadata and are usable in an * `InjectableDefType`s contain their own Dependency Injection metadata and are usable in an
* `ɵInjectorDef`-based `StaticInjector. * `InjectorDef`-based `StaticInjector.
* *
* @experimental * @experimental
*/ */
export interface InjectableType<T> extends Type<T> { ngInjectableDef: ɵInjectableDef<T>; } export interface InjectableType<T> extends Type<T> { ngInjectableDef: InjectableDef<T>; }
/** /**
* A type which has an `ɵInjectorDef` static field. * A type which has an `InjectorDef` static field.
* *
* `InjectorDefTypes` can be used to configure a `StaticInjector`. * `InjectorDefTypes` can be used to configure a `StaticInjector`.
* *
* @experimental * @experimental
*/ */
export interface InjectorType<T> extends Type<T> { ngInjectorDef: ɵInjectorDef<T>; } export interface InjectorType<T> extends Type<T> { ngInjectorDef: InjectorDef<T>; }
/** /**
* Describes the `ɵInjectorDef` equivalent of a `ModuleWithProviders`, an `InjectorDefType` with an * Describes the `InjectorDef` equivalent of a `ModuleWithProviders`, an `InjectorDefType` with an
* associated array of providers. * associated array of providers.
* *
* Objects of this type can be listed in the imports section of an `ɵInjectorDef`. * Objects of this type can be listed in the imports section of an `InjectorDef`.
* *
* @experimental * @experimental
*/ */
@ -103,7 +102,7 @@ export interface InjectorTypeWithProviders<T> {
/** /**
* Construct an `ɵInjectableDef` which defines how a token will be constructed by the DI system, and * Construct an `InjectableDef` which defines how a token will be constructed by the DI system, and
* in which injectors (if any) it will be available. * in which injectors (if any) it will be available.
* *
* This should be assigned to a static `ngInjectableDef` field on a type, which will then be an * This should be assigned to a static `ngInjectableDef` field on a type, which will then be an
@ -121,7 +120,7 @@ export interface InjectorTypeWithProviders<T> {
export function defineInjectable<T>(opts: { export function defineInjectable<T>(opts: {
providedIn?: Type<any>| 'root' | 'any' | null, providedIn?: Type<any>| 'root' | 'any' | null,
factory: () => T, factory: () => T,
}): ɵInjectableDef<T> { }): InjectableDef<T> {
return { return {
providedIn: opts.providedIn as any || null, providedIn: opts.providedIn as any || null,
factory: opts.factory, factory: opts.factory,
@ -130,7 +129,7 @@ export function defineInjectable<T>(opts: {
} }
/** /**
* Construct an `ɵInjectorDef` which configures an injector. * Construct an `InjectorDef` which configures an injector.
* *
* This should be assigned to a static `ngInjectorDef` field on a type, which will then be an * This should be assigned to a static `ngInjectorDef` field on a type, which will then be an
* `InjectorType`. * `InjectorType`.
@ -150,7 +149,7 @@ export function defineInjectable<T>(opts: {
* @experimental * @experimental
*/ */
export function defineInjector(options: {factory: () => any, providers?: any[], imports?: any[]}): export function defineInjector(options: {factory: () => any, providers?: any[], imports?: any[]}):
ɵInjectorDef<any> { InjectorDef<any> {
return { return {
factory: options.factory, factory: options.factory,
providers: options.providers || [], providers: options.providers || [],

View File

@ -11,7 +11,7 @@ import {Type} from '../type';
import {makeDecorator, makeParamDecorator} from '../util/decorators'; import {makeDecorator, makeParamDecorator} from '../util/decorators';
import {getClosureSafeProperty} from '../util/property'; import {getClosureSafeProperty} from '../util/property';
import {InjectableType, defineInjectable, ɵInjectableDef} from './defs'; import {InjectableDef, InjectableType, defineInjectable} from './defs';
import {inject, injectArgs} from './injector'; import {inject, injectArgs} from './injector';
import {ClassSansProvider, ConstructorProvider, ConstructorSansProvider, ExistingProvider, ExistingSansProvider, FactoryProvider, FactorySansProvider, StaticClassProvider, StaticClassSansProvider, ValueProvider, ValueSansProvider} from './provider'; import {ClassSansProvider, ConstructorProvider, ConstructorSansProvider, ExistingProvider, ExistingSansProvider, FactoryProvider, FactorySansProvider, StaticClassProvider, StaticClassSansProvider, ValueProvider, ValueSansProvider} from './provider';
@ -134,4 +134,4 @@ export const Injectable: InjectableDecorator = makeDecorator(
* *
* @experimental * @experimental
*/ */
export interface InjectableType<T> extends Type<T> { ngInjectableDef: ɵInjectableDef<T>; } export interface InjectableType<T> extends Type<T> { ngInjectableDef: InjectableDef<T>; }

View File

@ -8,8 +8,7 @@
import {Type} from '../type'; import {Type} from '../type';
import {defineInjectable, ɵInjectableDef} from './defs'; import {InjectableDef, defineInjectable} from './defs';
/** /**
* Creates a token that can be used in a DI Provider. * Creates a token that can be used in a DI Provider.
@ -53,7 +52,7 @@ export class InjectionToken<T> {
/** @internal */ /** @internal */
readonly ngMetadataName = 'InjectionToken'; readonly ngMetadataName = 'InjectionToken';
readonly ngInjectableDef: ɵInjectableDef<T>|undefined; readonly ngInjectableDef: InjectableDef<T>|undefined;
constructor(protected _desc: string, options?: { constructor(protected _desc: string, options?: {
providedIn?: Type<any>| 'root' | null, providedIn?: Type<any>| 'root' | null,
@ -73,5 +72,5 @@ export class InjectionToken<T> {
} }
export interface InjectableDefToken<T> extends InjectionToken<T> { export interface InjectableDefToken<T> extends InjectionToken<T> {
ngInjectableDef: ɵInjectableDef<T>; ngInjectableDef: InjectableDef<T>;
} }

View File

@ -9,7 +9,7 @@
import {Type} from '../type'; import {Type} from '../type';
import {stringify} from '../util'; import {stringify} from '../util';
import {defineInjectable, ɵInjectableDef} from './defs'; import {InjectableDef, defineInjectable} from './defs';
import {resolveForwardRef} from './forward_ref'; import {resolveForwardRef} from './forward_ref';
import {InjectionToken} from './injection_token'; import {InjectionToken} from './injection_token';
import {Inject, Optional, Self, SkipSelf} from './metadata'; import {Inject, Optional, Self, SkipSelf} from './metadata';
@ -462,7 +462,7 @@ export function inject<T>(token: Type<T>| InjectionToken<T>, flags = InjectFlags
if (_currentInjector === undefined) { if (_currentInjector === undefined) {
throw new Error(`inject() must be called from an injection context`); throw new Error(`inject() must be called from an injection context`);
} else if (_currentInjector === null) { } else if (_currentInjector === null) {
const injectableDef: ɵInjectableDef<T> = (token as any).ngInjectableDef; const injectableDef: InjectableDef<T> = (token as any).ngInjectableDef;
if (injectableDef && injectableDef.providedIn == 'root') { if (injectableDef && injectableDef.providedIn == 'root') {
return injectableDef.value === undefined ? injectableDef.value = injectableDef.factory() : return injectableDef.value === undefined ? injectableDef.value = injectableDef.factory() :
injectableDef.value; injectableDef.value;

View File

@ -10,7 +10,7 @@ import {OnDestroy} from '../metadata/lifecycle_hooks';
import {Type} from '../type'; import {Type} from '../type';
import {stringify} from '../util'; import {stringify} from '../util';
import {InjectableType, InjectorType, InjectorTypeWithProviders, ɵInjectableDef, ɵInjectorDef} from './defs'; import {InjectableDef, InjectableType, InjectorDef, InjectorType, InjectorTypeWithProviders} from './defs';
import {resolveForwardRef} from './forward_ref'; import {resolveForwardRef} from './forward_ref';
import {InjectableDefToken, InjectionToken} from './injection_token'; import {InjectableDefToken, InjectionToken} from './injection_token';
import {INJECTOR, InjectFlags, Injector, NullInjector, THROW_IF_NOT_FOUND, USE_VALUE, inject, injectArgs, setCurrentInjector} from './injector'; import {INJECTOR, InjectFlags, Injector, NullInjector, THROW_IF_NOT_FOUND, USE_VALUE, inject, injectArgs, setCurrentInjector} from './injector';
@ -200,7 +200,7 @@ export class R3Injector {
// read, so care is taken to only do the read once. // read, so care is taken to only do the read once.
// First attempt to read the ngInjectorDef. // First attempt to read the ngInjectorDef.
let def = (defOrWrappedDef as InjectorType<any>).ngInjectorDef as(ɵInjectorDef<any>| undefined); let def = (defOrWrappedDef as InjectorType<any>).ngInjectorDef as(InjectorDef<any>| undefined);
// If that's not present, then attempt to read ngModule from the InjectorDefTypeWithProviders. // If that's not present, then attempt to read ngModule from the InjectorDefTypeWithProviders.
const ngModule = const ngModule =
@ -219,7 +219,7 @@ export class R3Injector {
EMPTY_ARRAY; EMPTY_ARRAY;
// Finally, if defOrWrappedType was an `InjectorDefTypeWithProviders`, then the actual // Finally, if defOrWrappedType was an `InjectorDefTypeWithProviders`, then the actual
// `ɵInjectorDef` is on its `ngModule`. // `InjectorDef` is on its `ngModule`.
if (ngModule !== undefined) { if (ngModule !== undefined) {
def = ngModule.ngInjectorDef; def = ngModule.ngInjectorDef;
} }
@ -314,7 +314,7 @@ export class R3Injector {
return record.value as T; return record.value as T;
} }
private injectableDefInScope(def: ɵInjectableDef<any>): boolean { private injectableDefInScope(def: InjectableDef<any>): boolean {
if (!def.providedIn) { if (!def.providedIn) {
return false; return false;
} else if (typeof def.providedIn === 'string') { } else if (typeof def.providedIn === 'string') {

View File

@ -6,14 +6,13 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {InjectorType, defineInjector, ɵInjectorDef} from '../di/defs'; import {InjectorDef, InjectorType, defineInjector} from '../di/defs';
import {convertInjectableProviderToFactory} from '../di/injectable'; import {convertInjectableProviderToFactory} from '../di/injectable';
import {Provider} from '../di/provider'; import {Provider} from '../di/provider';
import {Type} from '../type'; import {Type} from '../type';
import {TypeDecorator, makeDecorator} from '../util/decorators'; import {TypeDecorator, makeDecorator} from '../util/decorators';
/** /**
* A wrapper around a module that also includes the providers. * A wrapper around a module that also includes the providers.
* *

View File

@ -15,7 +15,7 @@ import {ComponentRef as viewEngine_ComponentRef} from '../linker/component_facto
import {assertComponentType, assertNotNull} from './assert'; import {assertComponentType, assertNotNull} from './assert';
import {queueInitHooks, queueLifecycleHooks} from './hooks'; import {queueInitHooks, queueLifecycleHooks} from './hooks';
import {CLEAN_PROMISE, ROOT_DIRECTIVE_INDICES, _getComponentHostLElementNode, baseDirectiveCreate, createLView, createTView, detectChangesInternal, enterView, executeInitAndContentHooks, getRootView, hostElement, initChangeDetectorIfExisting, leaveView, locateHostElement, setHostBindings} from './instructions'; import {CLEAN_PROMISE, ROOT_DIRECTIVE_INDICES, _getComponentHostLElementNode, baseDirectiveCreate, createLView, createTView, detectChangesInternal, enterView, executeInitAndContentHooks, getRootView, hostElement, initChangeDetectorIfExisting, leaveView, locateHostElement, setHostBindings} from './instructions';
import {ComponentType, ɵComponentDef} from './interfaces/definition'; import {ComponentDef, ComponentType} from './interfaces/definition';
import {LElementNode, TNodeFlags} from './interfaces/node'; import {LElementNode, TNodeFlags} from './interfaces/node';
import {RElement, RendererFactory3, domRendererFactory3} from './interfaces/renderer'; import {RElement, RendererFactory3, domRendererFactory3} from './interfaces/renderer';
import {LView, LViewFlags, RootContext} from './interfaces/view'; import {LView, LViewFlags, RootContext} from './interfaces/view';
@ -51,7 +51,7 @@ export interface CreateComponentOptions {
* features list because there's no way of knowing when the component will be used as * features list because there's no way of knowing when the component will be used as
* a root component. * a root component.
*/ */
hostFeatures?: (<T>(component: T, componentDef: ɵComponentDef<T>) => void)[]; hostFeatures?: (<T>(component: T, componentDef: ComponentDef<T>) => void)[];
/** /**
* A function which is used to schedule change detection work in the future. * A function which is used to schedule change detection work in the future.
@ -120,7 +120,7 @@ export function renderComponent<T>(
opts: CreateComponentOptions = {}): T { opts: CreateComponentOptions = {}): T {
ngDevMode && assertComponentType(componentType); ngDevMode && assertComponentType(componentType);
const rendererFactory = opts.rendererFactory || domRendererFactory3; const rendererFactory = opts.rendererFactory || domRendererFactory3;
const componentDef = (componentType as ComponentType<T>).ngComponentDef as ɵComponentDef<T>; const componentDef = (componentType as ComponentType<T>).ngComponentDef as ComponentDef<T>;
if (componentDef.type != componentType) componentDef.type = componentType; if (componentDef.type != componentType) componentDef.type = componentType;
let component: T; let component: T;
// The first index of the first selector is the tag name. // The first index of the first selector is the tag name.
@ -177,7 +177,7 @@ export function renderComponent<T>(
* renderComponent(AppComponent, {features: [RootLifecycleHooks]}); * renderComponent(AppComponent, {features: [RootLifecycleHooks]});
* ``` * ```
*/ */
export function LifecycleHooksFeature(component: any, def: ɵComponentDef<any>): void { export function LifecycleHooksFeature(component: any, def: ComponentDef<any>): void {
const elementNode = _getComponentHostLElementNode(component); const elementNode = _getComponentHostLElementNode(component);
// Root component is always created at dir index 0 // Root component is always created at dir index 0

View File

@ -16,7 +16,7 @@ import {Type} from '../type';
import {resolveRendererType2} from '../view/util'; import {resolveRendererType2} from '../view/util';
import {diPublic} from './di'; import {diPublic} from './di';
import {ComponentDefFeature, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeType, PipeTypesOrFactory, ɵComponentDef, ɵDirectiveDef, ɵPipeDef} from './interfaces/definition'; import {ComponentDef, ComponentDefFeature, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFeature, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory} from './interfaces/definition';
import {CssSelectorList, SelectorFlags} from './interfaces/projection'; import {CssSelectorList, SelectorFlags} from './interfaces/projection';
@ -150,8 +150,8 @@ export function defineComponent<T>(componentDefinition: {
/** /**
* Registry of directives and components that may be found in this component's view. * Registry of directives and components that may be found in this component's view.
* *
* The property is either an array of `ɵDirectiveDef`s or a function which returns the array of * The property is either an array of `DirectiveDef`s or a function which returns the array of
* `ɵDirectiveDef`s. The function is necessary to be able to support forward declarations. * `DirectiveDef`s. The function is necessary to be able to support forward declarations.
*/ */
directives?: DirectiveTypesOrFactory | null; directives?: DirectiveTypesOrFactory | null;
@ -162,11 +162,11 @@ export function defineComponent<T>(componentDefinition: {
* `PipeDefs`s. The function is necessary to be able to support forward declarations. * `PipeDefs`s. The function is necessary to be able to support forward declarations.
*/ */
pipes?: PipeTypesOrFactory | null; pipes?: PipeTypesOrFactory | null;
}): ɵComponentDef<T> { }): ComponentDef<T> {
const type = componentDefinition.type; const type = componentDefinition.type;
const pipeTypes = componentDefinition.pipes !; const pipeTypes = componentDefinition.pipes !;
const directiveTypes = componentDefinition.directives !; const directiveTypes = componentDefinition.directives !;
const def = <ɵComponentDef<any>>{ const def = <ComponentDef<any>>{
type: type, type: type,
diPublic: null, diPublic: null,
factory: componentDefinition.factory, factory: componentDefinition.factory,
@ -200,7 +200,7 @@ export function defineComponent<T>(componentDefinition: {
} }
export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>): export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>):
ɵDirectiveDef<any>|ɵComponentDef<any> { DirectiveDef<any>|ComponentDef<any> {
const def = type.ngComponentDef || type.ngDirectiveDef; const def = type.ngComponentDef || type.ngDirectiveDef;
if (ngDevMode && !def) { if (ngDevMode && !def) {
throw new Error(`'${type.name}' is neither 'ComponentType' or 'DirectiveType'.`); throw new Error(`'${type.name}' is neither 'ComponentType' or 'DirectiveType'.`);
@ -208,7 +208,7 @@ export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>
return def; return def;
} }
export function extractPipeDef(type: PipeType<any>): ɵPipeDef<any> { export function extractPipeDef(type: PipeType<any>): PipeDef<any> {
const def = type.ngPipeDef; const def = type.ngPipeDef;
if (ngDevMode && !def) { if (ngDevMode && !def) {
throw new Error(`'${type.name}' is not a 'PipeType'.`); throw new Error(`'${type.name}' is not a 'PipeType'.`);
@ -250,7 +250,7 @@ type OnChangesExpando = OnChanges & {
*/ */
export function NgOnChangesFeature(inputPropertyNames?: {[key: string]: string}): export function NgOnChangesFeature(inputPropertyNames?: {[key: string]: string}):
DirectiveDefFeature { DirectiveDefFeature {
return function(definition: ɵDirectiveDef<any>): void { return function(definition: DirectiveDef<any>): void {
const inputs = definition.inputs; const inputs = definition.inputs;
const proto = definition.type.prototype; const proto = definition.type.prototype;
// Place where we will store SimpleChanges if there is a change // Place where we will store SimpleChanges if there is a change
@ -306,7 +306,7 @@ export function NgOnChangesFeature(inputPropertyNames?: {[key: string]: string})
} }
export function PublicFeature<T>(definition: ɵDirectiveDef<T>) { export function PublicFeature<T>(definition: DirectiveDef<T>) {
definition.diPublic = diPublic; definition.diPublic = diPublic;
} }
@ -400,7 +400,7 @@ export const defineDirective = defineComponent as any as<T>(directiveDefinition:
* See: {@link Directive.exportAs} * See: {@link Directive.exportAs}
*/ */
exportAs?: string; exportAs?: string;
}) => ɵDirectiveDef<T>; }) => DirectiveDef<T>;
/** /**
* Create a pipe definition object. * Create a pipe definition object.
@ -428,8 +428,8 @@ export function definePipe<T>(pipeDef: {
/** Whether the pipe is pure. */ /** Whether the pipe is pure. */
pure?: boolean pure?: boolean
}): ɵPipeDef<T> { }): PipeDef<T> {
return <ɵPipeDef<T>>{ return <PipeDef<T>>{
name: pipeDef.name, name: pipeDef.name,
n: pipeDef.factory, n: pipeDef.factory,
pure: pipeDef.pure !== false, pure: pipeDef.pure !== false,

View File

@ -20,7 +20,7 @@ import {Type} from '../type';
import {assertGreaterThan, assertLessThan, assertNotNull} from './assert'; import {assertGreaterThan, assertLessThan, assertNotNull} from './assert';
import {addToViewTree, assertPreviousIsParent, createLContainer, createLNodeObject, getDirectiveInstance, getPreviousOrParentNode, getRenderer, isComponent, renderEmbeddedTemplate, resolveDirective} from './instructions'; import {addToViewTree, assertPreviousIsParent, createLContainer, createLNodeObject, getDirectiveInstance, getPreviousOrParentNode, getRenderer, isComponent, renderEmbeddedTemplate, resolveDirective} from './instructions';
import {ComponentTemplate, DirectiveDefList, PipeDefList, ɵDirectiveDef} from './interfaces/definition'; import {ComponentTemplate, DirectiveDef, DirectiveDefList, PipeDefList} from './interfaces/definition';
import {LInjector} from './interfaces/injector'; import {LInjector} from './interfaces/injector';
import {LContainerNode, LElementNode, LNode, LNodeType, LViewNode, TNodeFlags} from './interfaces/node'; import {LContainerNode, LElementNode, LNode, LNodeType, LViewNode, TNodeFlags} from './interfaces/node';
import {QueryReadType} from './interfaces/query'; import {QueryReadType} from './interfaces/query';
@ -139,7 +139,7 @@ export function getOrCreateNodeInjectorForNode(node: LElementNode | LContainerNo
* @param di The node injector in which a directive will be added * @param di The node injector in which a directive will be added
* @param def The definition of the directive to be made public * @param def The definition of the directive to be made public
*/ */
export function diPublicInInjector(di: LInjector, def: ɵDirectiveDef<any>): void { export function diPublicInInjector(di: LInjector, def: DirectiveDef<any>): void {
bloomAdd(di, def.type); bloomAdd(di, def.type);
} }
@ -148,7 +148,7 @@ export function diPublicInInjector(di: LInjector, def: ɵDirectiveDef<any>): voi
* *
* @param def The definition of the directive to be made public * @param def The definition of the directive to be made public
*/ */
export function diPublic(def: ɵDirectiveDef<any>): void { export function diPublic(def: DirectiveDef<any>): void {
diPublicInInjector(getOrCreateNodeInjector(), def); diPublicInInjector(getOrCreateNodeInjector(), def);
} }
@ -371,7 +371,7 @@ export function getOrCreateInjectable<T>(di: LInjector, token: Type<T>, flags?:
for (let i = start; i < end; i++) { for (let i = start; i < end; i++) {
// Get the definition for the directive at this index and, if it is injectable (diPublic), // Get the definition for the directive at this index and, if it is injectable (diPublic),
// and matches the given token, return the directive instance. // and matches the given token, return the directive instance.
const directiveDef = defs[i] as ɵDirectiveDef<any>; const directiveDef = defs[i] as DirectiveDef<any>;
if (directiveDef.type === token && directiveDef.diPublic) { if (directiveDef.type === token && directiveDef.diPublic) {
return getDirectiveInstance(node.view.directives ![i]); return getDirectiveInstance(node.view.directives ![i]);
} }
@ -400,7 +400,7 @@ function searchMatchesQueuedForCreation<T>(node: LNode, token: any): T|null {
const matches = node.view.tView.currentMatches; const matches = node.view.tView.currentMatches;
if (matches) { if (matches) {
for (let i = 0; i < matches.length; i += 2) { for (let i = 0; i < matches.length; i += 2) {
const def = matches[i] as ɵDirectiveDef<any>; const def = matches[i] as DirectiveDef<any>;
if (def.type === token) { if (def.type === token) {
return resolveDirective(def, i + 1, matches, node.view.tView); return resolveDirective(def, i + 1, matches, node.view.tView);
} }

View File

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

View File

@ -8,7 +8,7 @@
import {LifecycleHooksFeature, createComponentRef, getHostElement, getRenderedText, renderComponent, whenRendered} from './component'; import {LifecycleHooksFeature, createComponentRef, getHostElement, getRenderedText, renderComponent, whenRendered} from './component';
import {NgOnChangesFeature, PublicFeature, defineComponent, defineDirective, definePipe} from './definition'; import {NgOnChangesFeature, PublicFeature, defineComponent, defineDirective, definePipe} from './definition';
import {ComponentTemplate, ComponentType, DirectiveDefFlags, DirectiveType, ɵComponentDef, ɵDirectiveDef, ɵPipeDef} from './interfaces/definition'; import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFlags, DirectiveType, PipeDef} from './interfaces/definition';
export {QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF, directiveInject, injectAttribute, injectChangeDetectorRef, injectElementRef, injectTemplateRef, injectViewContainerRef} from './di'; export {QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF, directiveInject, injectAttribute, injectChangeDetectorRef, injectElementRef, injectTemplateRef, injectViewContainerRef} from './di';
export {RenderFlags} from './interfaces/definition'; export {RenderFlags} from './interfaces/definition';
@ -103,15 +103,15 @@ export {
// clang-format on // clang-format on
export { export {
ɵComponentDef, ComponentDef,
ComponentTemplate, ComponentTemplate,
ComponentType, ComponentType,
ɵDirectiveDef, DirectiveDef,
DirectiveDefFlags, DirectiveDefFlags,
DirectiveType, DirectiveType,
NgOnChangesFeature, NgOnChangesFeature,
PublicFeature, PublicFeature,
ɵPipeDef, PipeDef,
LifecycleHooksFeature, LifecycleHooksFeature,
defineComponent, defineComponent,
defineDirective, defineDirective,

View File

@ -19,7 +19,7 @@ import {LContainerNode, LElementNode, LNode, LNodeType, TNodeFlags, LProjectionN
import {assertNodeType} from './node_assert'; import {assertNodeType} from './node_assert';
import {appendChild, insertChild, insertView, appendProjectedNode, removeView, canInsertNativeNode, createTextNode} from './node_manipulation'; import {appendChild, insertChild, insertView, appendProjectedNode, removeView, canInsertNativeNode, createTextNode} from './node_manipulation';
import {isNodeMatchingSelectorList, matchingSelectorIndex} from './node_selector_matcher'; import {isNodeMatchingSelectorList, matchingSelectorIndex} from './node_selector_matcher';
import {ɵComponentDef, ComponentTemplate, ComponentType, ɵDirectiveDef, DirectiveDefList, DirectiveDefListOrFactory, DirectiveType, ɵPipeDef, PipeDefList, PipeDefListOrFactory, RenderFlags} from './interfaces/definition'; import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefList, DirectiveDefListOrFactory, DirectiveType, PipeDef, PipeDefList, PipeDefListOrFactory, RenderFlags} from './interfaces/definition';
import {RElement, RText, Renderer3, RendererFactory3, ProceduralRenderer3, ObjectOrientedRenderer3, RendererStyleFlags3, isProceduralRenderer} from './interfaces/renderer'; import {RElement, RText, Renderer3, RendererFactory3, ProceduralRenderer3, ObjectOrientedRenderer3, RendererStyleFlags3, isProceduralRenderer} from './interfaces/renderer';
import {isDifferent, stringify} from './util'; import {isDifferent, stringify} from './util';
import {executeHooks, queueLifecycleHooks, queueInitHooks, executeInitHooks} from './hooks'; import {executeHooks, queueLifecycleHooks, queueInitHooks, executeInitHooks} from './hooks';
@ -255,7 +255,7 @@ export function setHostBindings(bindings: number[] | null): void {
const defs = currentView.tView.directives !; const defs = currentView.tView.directives !;
for (let i = 0; i < bindings.length; i += 2) { for (let i = 0; i < bindings.length; i += 2) {
const dirIndex = bindings[i]; const dirIndex = bindings[i];
const def = defs[dirIndex] as ɵDirectiveDef<any>; const def = defs[dirIndex] as DirectiveDef<any>;
def.hostBindings && def.hostBindings(dirIndex, bindings[i + 1]); def.hostBindings && def.hostBindings(dirIndex, bindings[i + 1]);
} }
} }
@ -579,7 +579,7 @@ function cacheMatchingDirectivesForNode(
const matches = tView.currentMatches = findDirectiveMatches(tNode); const matches = tView.currentMatches = findDirectiveMatches(tNode);
if (matches) { if (matches) {
for (let i = 0; i < matches.length; i += 2) { for (let i = 0; i < matches.length; i += 2) {
const def = matches[i] as ɵDirectiveDef<any>; const def = matches[i] as DirectiveDef<any>;
const valueIndex = i + 1; const valueIndex = i + 1;
resolveDirective(def, valueIndex, matches, tView); resolveDirective(def, valueIndex, matches, tView);
saveNameToExportMap(matches[valueIndex] as number, def, exportsMap); saveNameToExportMap(matches[valueIndex] as number, def, exportsMap);
@ -596,7 +596,7 @@ function findDirectiveMatches(tNode: TNode): CurrentMatchesList|null {
for (let i = 0; i < registry.length; i++) { for (let i = 0; i < registry.length; i++) {
const def = registry[i]; const def = registry[i];
if (isNodeMatchingSelectorList(tNode, def.selectors !)) { if (isNodeMatchingSelectorList(tNode, def.selectors !)) {
if ((def as ɵComponentDef<any>).template) { if ((def as ComponentDef<any>).template) {
if (tNode.flags & TNodeFlags.isComponent) throwMultipleComponentError(tNode); if (tNode.flags & TNodeFlags.isComponent) throwMultipleComponentError(tNode);
tNode.flags = TNodeFlags.isComponent; tNode.flags = TNodeFlags.isComponent;
} }
@ -609,7 +609,7 @@ function findDirectiveMatches(tNode: TNode): CurrentMatchesList|null {
} }
export function resolveDirective( export function resolveDirective(
def: ɵDirectiveDef<any>, valueIndex: number, matches: CurrentMatchesList, tView: TView): any { def: DirectiveDef<any>, valueIndex: number, matches: CurrentMatchesList, tView: TView): any {
if (matches[valueIndex] === null) { if (matches[valueIndex] === null) {
matches[valueIndex] = CIRCULAR; matches[valueIndex] = CIRCULAR;
const instance = def.factory(); const instance = def.factory();
@ -664,7 +664,7 @@ function instantiateDirectivesDirectly() {
const tDirectives = currentView.tView.directives !; const tDirectives = currentView.tView.directives !;
for (let i = start; i < end; i++) { for (let i = start; i < end; i++) {
const def: ɵDirectiveDef<any> = tDirectives[i]; const def: DirectiveDef<any> = tDirectives[i];
directiveCreate(i, def.factory(), def); directiveCreate(i, def.factory(), def);
} }
} }
@ -692,11 +692,11 @@ function cacheMatchingLocalNames(
* to their directive instances. * to their directive instances.
*/ */
function saveNameToExportMap( function saveNameToExportMap(
index: number, def: ɵDirectiveDef<any>| ɵComponentDef<any>, index: number, def: DirectiveDef<any>| ComponentDef<any>,
exportsMap: {[key: string]: number} | null) { exportsMap: {[key: string]: number} | null) {
if (exportsMap) { if (exportsMap) {
if (def.exportAs) exportsMap[def.exportAs] = index; if (def.exportAs) exportsMap[def.exportAs] = index;
if ((def as ɵComponentDef<any>).template) exportsMap[''] = index; if ((def as ComponentDef<any>).template) exportsMap[''] = index;
} }
} }
@ -802,12 +802,12 @@ export function locateHostElement(
* Creates the host LNode. * Creates the host LNode.
* *
* @param rNode Render host element. * @param rNode Render host element.
* @param def ɵComponentDef * @param def ComponentDef
* *
* @returns LElementNode created * @returns LElementNode created
*/ */
export function hostElement( export function hostElement(
tag: string, rNode: RElement | null, def: ɵComponentDef<any>): LElementNode { tag: string, rNode: RElement | null, def: ComponentDef<any>): LElementNode {
resetApplicationState(); resetApplicationState();
const node = createLNode( const node = createLNode(
0, LNodeType.Element, rNode, 0, LNodeType.Element, rNode,
@ -1014,7 +1014,7 @@ function generatePropertyAliases(
const defs = currentView.tView.directives !; const defs = currentView.tView.directives !;
for (let i = start; i < end; i++) { for (let i = start; i < end; i++) {
const directiveDef = defs[i] as ɵDirectiveDef<any>; const directiveDef = defs[i] as DirectiveDef<any>;
const propertyAliasMap: {[publicName: string]: string} = const propertyAliasMap: {[publicName: string]: string} =
isInput ? directiveDef.inputs : directiveDef.outputs; isInput ? directiveDef.inputs : directiveDef.outputs;
for (let publicName in propertyAliasMap) { for (let publicName in propertyAliasMap) {
@ -1204,18 +1204,18 @@ export function textBinding<T>(index: number, value: T | NO_CHANGE): void {
* be retrieved before they are created in which case the value will be null. * be retrieved before they are created in which case the value will be null.
* *
* @param directive The directive instance. * @param directive The directive instance.
* @param directiveDef ɵDirectiveDef object which contains information about the template. * @param directiveDef DirectiveDef object which contains information about the template.
*/ */
export function directiveCreate<T>( export function directiveCreate<T>(
index: number, directive: T, directiveDef: ɵDirectiveDef<T>| ɵComponentDef<T>): T { index: number, directive: T, directiveDef: DirectiveDef<T>| ComponentDef<T>): T {
const instance = baseDirectiveCreate(index, directive, directiveDef); const instance = baseDirectiveCreate(index, directive, directiveDef);
ngDevMode && assertNotNull(previousOrParentNode.tNode, 'previousOrParentNode.tNode'); ngDevMode && assertNotNull(previousOrParentNode.tNode, 'previousOrParentNode.tNode');
const tNode = previousOrParentNode.tNode; const tNode = previousOrParentNode.tNode;
const isComponent = (directiveDef as ɵComponentDef<T>).template; const isComponent = (directiveDef as ComponentDef<T>).template;
if (isComponent) { if (isComponent) {
addComponentLogic(index, directive, directiveDef as ɵComponentDef<T>); addComponentLogic(index, directive, directiveDef as ComponentDef<T>);
} }
if (firstTemplatePass) { if (firstTemplatePass) {
@ -1233,7 +1233,7 @@ export function directiveCreate<T>(
return instance; return instance;
} }
function addComponentLogic<T>(index: number, instance: T, def: ɵComponentDef<T>): void { function addComponentLogic<T>(index: number, instance: T, def: ComponentDef<T>): void {
const tView = getOrCreateTView(def.template, def.directiveDefs, def.pipeDefs); const tView = getOrCreateTView(def.template, def.directiveDefs, def.pipeDefs);
// Only component views should be added to the view tree directly. Embedded views are // Only component views should be added to the view tree directly. Embedded views are
@ -1259,7 +1259,7 @@ function addComponentLogic<T>(index: number, instance: T, def: ɵComponentDef<T>
* current Angular. Example: local refs and inputs on root component. * current Angular. Example: local refs and inputs on root component.
*/ */
export function baseDirectiveCreate<T>( export function baseDirectiveCreate<T>(
index: number, directive: T, directiveDef: ɵDirectiveDef<T>| ɵComponentDef<T>): T { index: number, directive: T, directiveDef: DirectiveDef<T>| ComponentDef<T>): T {
ngDevMode && ngDevMode &&
assertEqual( assertEqual(
currentView.bindingStartIndex, -1, 'directives should be created before any bindings'); currentView.bindingStartIndex, -1, 'directives should be created before any bindings');
@ -1632,7 +1632,7 @@ export function componentRefresh<T>(directiveIndex: number, elementIndex: number
// Only attached CheckAlways components or attached, dirty OnPush components should be checked // Only attached CheckAlways components or attached, dirty OnPush components should be checked
if (viewAttached(hostView) && hostView.flags & (LViewFlags.CheckAlways | LViewFlags.Dirty)) { if (viewAttached(hostView) && hostView.flags & (LViewFlags.CheckAlways | LViewFlags.Dirty)) {
ngDevMode && assertDataInRange(directiveIndex, directives !); ngDevMode && assertDataInRange(directiveIndex, directives !);
const def = currentView.tView.directives ![directiveIndex] as ɵComponentDef<T>; const def = currentView.tView.directives ![directiveIndex] as ComponentDef<T>;
detectChangesInternal( detectChangesInternal(
hostView, element, def, getDirectiveInstance(directives ![directiveIndex])); hostView, element, def, getDirectiveInstance(directives ![directiveIndex]));
@ -1944,7 +1944,7 @@ export function detectChanges<T>(component: T): void {
const hostNode = _getComponentHostLElementNode(component); const hostNode = _getComponentHostLElementNode(component);
ngDevMode && assertNotNull(hostNode.data, 'Component host node should be attached to an LView'); ngDevMode && assertNotNull(hostNode.data, 'Component host node should be attached to an LView');
const componentIndex = hostNode.tNode !.flags >> TNodeFlags.DirectiveStartingIndexShift; const componentIndex = hostNode.tNode !.flags >> TNodeFlags.DirectiveStartingIndexShift;
const def = hostNode.view.tView.directives ![componentIndex] as ɵComponentDef<T>; const def = hostNode.view.tView.directives ![componentIndex] as ComponentDef<T>;
detectChangesInternal(hostNode.data as LView, hostNode, def, component); detectChangesInternal(hostNode.data as LView, hostNode, def, component);
} }
@ -1966,7 +1966,7 @@ export function checkNoChanges<T>(component: T): void {
/** Checks the view of the component provided. Does not gate on dirty checks or execute doCheck. */ /** Checks the view of the component provided. Does not gate on dirty checks or execute doCheck. */
export function detectChangesInternal<T>( export function detectChangesInternal<T>(
hostView: LView, hostNode: LElementNode, def: ɵComponentDef<T>, component: T) { hostView: LView, hostNode: LElementNode, def: ComponentDef<T>, component: T) {
const oldView = enterView(hostView, hostNode); const oldView = enterView(hostView, hostNode);
const template = def.template; const template = def.template;

View File

@ -35,24 +35,24 @@ export const enum RenderFlags {
} }
/** /**
* A subclass of `Type` which has a static `ngComponentDef`:`ɵComponentDef` field making it * A subclass of `Type` which has a static `ngComponentDef`:`ComponentDef` field making it
* consumable for rendering. * consumable for rendering.
*/ */
export interface ComponentType<T> extends Type<T> { ngComponentDef: ɵComponentDef<T>; } export interface ComponentType<T> extends Type<T> { ngComponentDef: ComponentDef<T>; }
/** /**
* A subclass of `Type` which has a static `ngDirectiveDef`:`ɵDirectiveDef` field making it * A subclass of `Type` which has a static `ngDirectiveDef`:`DirectiveDef` field making it
* consumable for rendering. * consumable for rendering.
*/ */
export interface DirectiveType<T> extends Type<T> { ngDirectiveDef: ɵDirectiveDef<T>; } export interface DirectiveType<T> extends Type<T> { ngDirectiveDef: DirectiveDef<T>; }
export const enum DirectiveDefFlags {ContentQuery = 0b10} export const enum DirectiveDefFlags {ContentQuery = 0b10}
/** /**
* A subclass of `Type` which has a static `ngPipeDef`:`ɵPipeDef` field making it * A subclass of `Type` which has a static `ngPipeDef`:`PipeDef` field making it
* consumable for rendering. * consumable for rendering.
*/ */
export interface PipeType<T> extends Type<T> { ngPipeDef: ɵPipeDef<T>; } export interface PipeType<T> extends Type<T> { ngPipeDef: PipeDef<T>; }
/** /**
* Runtime link information for Directives. * Runtime link information for Directives.
@ -65,18 +65,13 @@ export interface PipeType<T> extends Type<T> { ngPipeDef: ɵPipeDef<T>; }
* can change between versions. * can change between versions.
* *
* See: {@link defineDirective} * See: {@link defineDirective}
*
* NOTE: This is a semi public API, and there are no guaranties that the shape of this API will
* remain consistent between version. Use with caution.
*
* @experimental
*/ */
export interface ɵDirectiveDef<T> { export interface DirectiveDef<T> {
/** Token representing the directive. Used by DI. */ /** Token representing the directive. Used by DI. */
type: Type<T>; type: Type<T>;
/** Function that makes a directive public to the DI system. */ /** Function that makes a directive public to the DI system. */
diPublic: ((def: ɵDirectiveDef<any>) => void)|null; diPublic: ((def: DirectiveDef<any>) => void)|null;
/** The selectors that will be used to match nodes to this directive. */ /** The selectors that will be used to match nodes to this directive. */
selectors: CssSelectorList; selectors: CssSelectorList;
@ -140,13 +135,8 @@ export interface ɵDirectiveDef<T> {
* can change between versions. * can change between versions.
* *
* See: {@link defineComponent} * See: {@link defineComponent}
*
* NOTE: This is a semi public API, and there are no guaranties that the shape of this API will
* remain consistent between version. Use with caution.
*
* @experimental
*/ */
export interface ɵComponentDef<T> extends ɵDirectiveDef<T> { export interface ComponentDef<T> extends DirectiveDef<T> {
/** /**
* The View template of the component. * The View template of the component.
* *
@ -179,8 +169,8 @@ export interface ɵComponentDef<T> extends ɵDirectiveDef<T> {
/** /**
* Registry of directives and components that may be found in this view. * Registry of directives and components that may be found in this view.
* *
* The property is either an array of `ɵDirectiveDef`s or a function which returns the array of * The property is either an array of `DirectiveDef`s or a function which returns the array of
* `ɵDirectiveDef`s. The function is necessary to be able to support forward declarations. * `DirectiveDef`s. The function is necessary to be able to support forward declarations.
*/ */
directiveDefs: DirectiveDefListOrFactory|null; directiveDefs: DirectiveDefListOrFactory|null;
@ -204,13 +194,8 @@ export interface ɵComponentDef<T> extends ɵDirectiveDef<T> {
* can change between versions. * can change between versions.
* *
* See: {@link definePipe} * See: {@link definePipe}
*
* NOTE: This is a semi public API, and there are no guaranties that the shape of this API will
* remain consistent between version. Use with caution.
*
* @experimental
*/ */
export interface ɵPipeDef<T> { export interface PipeDef<T> {
/** /**
* Pipe name. * Pipe name.
* *
@ -238,8 +223,8 @@ export interface ɵPipeDef<T> {
onDestroy: (() => void)|null; onDestroy: (() => void)|null;
} }
export type DirectiveDefFeature = <T>(directiveDef: ɵDirectiveDef<T>) => void; export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
export type ComponentDefFeature = <T>(componentDef: ɵComponentDef<T>) => void; export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
/** /**
* Type used for directiveDefs on component definition. * Type used for directiveDefs on component definition.
@ -248,12 +233,12 @@ export type ComponentDefFeature = <T>(componentDef: ɵComponentDef<T>) => void;
*/ */
export type DirectiveDefListOrFactory = (() => DirectiveDefList) | DirectiveDefList; export type DirectiveDefListOrFactory = (() => DirectiveDefList) | DirectiveDefList;
export type DirectiveDefList = (ɵDirectiveDef<any>| ɵComponentDef<any>)[]; export type DirectiveDefList = (DirectiveDef<any>| ComponentDef<any>)[];
export type DirectiveTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList; export type DirectiveTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
export type DirectiveTypeList = export type DirectiveTypeList =
(ɵDirectiveDef<any>| ɵComponentDef<any>| (DirectiveDef<any>| ComponentDef<any>|
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[]; Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
/** /**
@ -263,12 +248,12 @@ export type DirectiveTypeList =
*/ */
export type PipeDefListOrFactory = (() => PipeDefList) | PipeDefList; export type PipeDefListOrFactory = (() => PipeDefList) | PipeDefList;
export type PipeDefList = ɵPipeDef<any>[]; export type PipeDefList = PipeDef<any>[];
export type PipeTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList; export type PipeTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
export type PipeTypeList = export type PipeTypeList =
(ɵPipeDef<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 // Note: This hack is necessary so we don't erroneously get a circular dependency

View File

@ -8,7 +8,7 @@
import {Injector} from '../../di/injector'; import {Injector} from '../../di/injector';
import {LContainer} from './container'; import {LContainer} from './container';
import {ComponentTemplate, DirectiveDefList, PipeDefList, ɵDirectiveDef, ɵPipeDef} from './definition'; import {ComponentTemplate, DirectiveDef, DirectiveDefList, PipeDef, PipeDefList} from './definition';
import {LElementNode, LViewNode, TNode} from './node'; import {LElementNode, LViewNode, TNode} from './node';
import {LQueries} from './query'; import {LQueries} from './query';
import {Renderer3} from './renderer'; import {Renderer3} from './renderer';
@ -428,10 +428,10 @@ export const enum LifecycleStage {
* as its pipe instance in the data array. Any nodes that do not have static * as its pipe instance in the data array. Any nodes that do not have static
* data store a null value in tData to avoid a sparse array. * data store a null value in tData to avoid a sparse array.
*/ */
export type TData = (TNode | ɵPipeDef<any>| null)[]; export type TData = (TNode | PipeDef<any>| null)[];
/** Type for TView.currentMatches */ /** Type for TView.currentMatches */
export type CurrentMatchesList = [ɵDirectiveDef<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 // Note: This hack is necessary so we don't erroneously get a circular dependency
// failure based on types. // failure based on types.

View File

@ -9,10 +9,9 @@
import {PipeTransform} from '../change_detection/pipe_transform'; import {PipeTransform} from '../change_detection/pipe_transform';
import {getTView, load, store} from './instructions'; import {getTView, load, store} from './instructions';
import {PipeDefList, ɵPipeDef} from './interfaces/definition'; import {PipeDef, PipeDefList} from './interfaces/definition';
import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunctionV} from './pure_function'; import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunctionV} from './pure_function';
/** /**
* Create a pipe. * Create a pipe.
* *
@ -22,7 +21,7 @@ import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunction
*/ */
export function pipe(index: number, pipeName: string): any { export function pipe(index: number, pipeName: string): any {
const tView = getTView(); const tView = getTView();
let pipeDef: ɵPipeDef<any>; let pipeDef: PipeDef<any>;
if (tView.firstTemplatePass) { if (tView.firstTemplatePass) {
pipeDef = getPipeDef(pipeName, tView.pipeRegistry); pipeDef = getPipeDef(pipeName, tView.pipeRegistry);
@ -31,7 +30,7 @@ export function pipe(index: number, pipeName: string): any {
(tView.pipeDestroyHooks || (tView.pipeDestroyHooks = [])).push(index, pipeDef.onDestroy); (tView.pipeDestroyHooks || (tView.pipeDestroyHooks = [])).push(index, pipeDef.onDestroy);
} }
} else { } else {
pipeDef = tView.data[index] as ɵPipeDef<any>; pipeDef = tView.data[index] as PipeDef<any>;
} }
const pipeInstance = pipeDef.n(); const pipeInstance = pipeDef.n();
@ -45,9 +44,9 @@ export function pipe(index: number, pipeName: string): any {
* *
* @param name Name of pipe to resolve * @param name Name of pipe to resolve
* @param registry Full list of available pipes * @param registry Full list of available pipes
* @returns Matching ɵPipeDef * @returns Matching PipeDef
*/ */
function getPipeDef(name: string, registry: PipeDefList | null): ɵPipeDef<any> { function getPipeDef(name: string, registry: PipeDefList | null): PipeDef<any> {
if (registry) { if (registry) {
for (let i = 0; i < registry.length; i++) { for (let i = 0; i < registry.length; i++) {
const pipeDef = registry[i]; const pipeDef = registry[i];
@ -141,5 +140,5 @@ export function pipeBindV(index: number, values: any[]): any {
} }
function isPure(index: number): boolean { function isPure(index: number): boolean {
return (<ɵPipeDef<any>>getTView().data[index]).pure; return (<PipeDef<any>>getTView().data[index]).pure;
} }

View File

@ -18,7 +18,7 @@ import {getSymbolIterator} from '../util';
import {assertEqual, assertNotNull} from './assert'; import {assertEqual, assertNotNull} from './assert';
import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di'; import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di';
import {assertPreviousIsParent, getCurrentQueries, store} from './instructions'; import {assertPreviousIsParent, getCurrentQueries, store} from './instructions';
import {unusedValueExportToPlacateAjd as unused1, ɵDirectiveDef} from './interfaces/definition'; import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector'; import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
import {LContainerNode, LElementNode, LNode, TNode, TNodeFlags, unusedValueExportToPlacateAjd as unused3} from './interfaces/node'; import {LContainerNode, LElementNode, LNode, TNode, TNodeFlags, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
import {LQueries, QueryReadType, unusedValueExportToPlacateAjd as unused4} from './interfaces/query'; import {LQueries, QueryReadType, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
@ -200,7 +200,7 @@ function getIdxOfMatchingDirective(node: LNode, type: Type<any>): number|null {
const start = flags >> TNodeFlags.DirectiveStartingIndexShift; const start = flags >> TNodeFlags.DirectiveStartingIndexShift;
const end = start + count; const end = start + count;
for (let i = start; i < end; i++) { for (let i = start; i < end; i++) {
const def = defs[i] as ɵDirectiveDef<any>; const def = defs[i] as DirectiveDef<any>;
if (def.type === type && def.diPublic) { if (def.type === type && def.diPublic) {
return i; return i;
} }

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {ɵInjectableDef} from '../di/defs'; import {InjectableDef} from '../di/defs';
import {resolveForwardRef} from '../di/forward_ref'; import {resolveForwardRef} from '../di/forward_ref';
import {INJECTOR, InjectFlags, Injector, setCurrentInjector} from '../di/injector'; import {INJECTOR, InjectFlags, Injector, setCurrentInjector} from '../di/injector';
import {APP_ROOT} from '../di/scope'; import {APP_ROOT} from '../di/scope';
@ -102,7 +102,7 @@ export function resolveNgModuleDep(
} }
return providerInstance === UNDEFINED_VALUE ? undefined : providerInstance; return providerInstance === UNDEFINED_VALUE ? undefined : providerInstance;
} else if (depDef.token.ngInjectableDef && targetsModule(data, depDef.token.ngInjectableDef)) { } else if (depDef.token.ngInjectableDef && targetsModule(data, depDef.token.ngInjectableDef)) {
const injectableDef = depDef.token.ngInjectableDef as ɵInjectableDef<any>; const injectableDef = depDef.token.ngInjectableDef as InjectableDef<any>;
const key = tokenKey; const key = tokenKey;
const index = data._providers.length; const index = data._providers.length;
data._def.providersByKey[depDef.tokenKey] = { data._def.providersByKey[depDef.tokenKey] = {
@ -126,7 +126,7 @@ function moduleTransitivelyPresent(ngModule: NgModuleData, scope: any): boolean
return ngModule._def.modules.indexOf(scope) > -1; return ngModule._def.modules.indexOf(scope) > -1;
} }
function targetsModule(ngModule: NgModuleData, def: ɵInjectableDef<any>): boolean { function targetsModule(ngModule: NgModuleData, def: InjectableDef<any>): boolean {
return def.providedIn != null && (moduleTransitivelyPresent(ngModule, def.providedIn) || return def.providedIn != null && (moduleTransitivelyPresent(ngModule, def.providedIn) ||
def.providedIn === 'root' && ngModule._def.isRoot); def.providedIn === 'root' && ngModule._def.isRoot);
} }

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Injector, createInjector, defineInjectable, defineInjector, ɵInjectableDef, ɵInjectorDef} from '@angular/core'; import {InjectableDef, Injector, InjectorDef, createInjector, defineInjectable, defineInjector} from '@angular/core';
export class RootService { export class RootService {
static ngInjectableDef = defineInjectable({ static ngInjectableDef = defineInjectable({

View File

@ -7,7 +7,7 @@
*/ */
import {CommonModule, NgForOf, NgIf} from '@angular/common'; import {CommonModule, NgForOf, NgIf} from '@angular/common';
import {ChangeDetectionStrategy, Component, EventEmitter, InjectFlags, Injectable, Input, IterableDiffers, NgModule, Output, createInjector, defineInjector, inject, ɵComponentDef, ɵComponentType as ComponentType, ɵDirectiveDef, ɵDirectiveType as DirectiveType, ɵNgOnChangesFeature as NgOnChangesFeature, ɵdefaultIterableDiffers as defaultIterableDiffers, ɵdefineDirective as defineDirective, ɵdirectiveInject as directiveInject, ɵinjectTemplateRef as injectTemplateRef, ɵinjectViewContainerRef as injectViewContainerRef, ɵmarkDirty as markDirty, ɵrenderComponent as renderComponent} from '@angular/core'; import {ChangeDetectionStrategy, Component, EventEmitter, InjectFlags, Injectable, Input, IterableDiffers, NgModule, Output, createInjector, defineInjector, inject, ɵComponentDef as ComponentDef, ɵComponentType as ComponentType, ɵDirectiveDef as DirectiveDef, ɵDirectiveType as DirectiveType, ɵNgOnChangesFeature as NgOnChangesFeature, ɵdefaultIterableDiffers as defaultIterableDiffers, ɵdefineDirective as defineDirective, ɵdirectiveInject as directiveInject, ɵinjectTemplateRef as injectTemplateRef, ɵinjectViewContainerRef as injectViewContainerRef, ɵmarkDirty as markDirty, ɵrenderComponent as renderComponent} from '@angular/core';
export class Todo { export class Todo {

View File

@ -11,7 +11,7 @@ import {InjectionToken} from '../../src/di/injection_token';
import {INJECTOR, Injector, inject} from '../../src/di/injector'; import {INJECTOR, Injector, inject} from '../../src/di/injector';
import {R3Injector, createInjector} from '../../src/di/r3_injector'; import {R3Injector, createInjector} from '../../src/di/r3_injector';
describe('ɵInjectorDef-based createInjector()', () => { describe('InjectorDef-based createInjector()', () => {
class CircularA { class CircularA {
static ngInjectableDef = defineInjectable({ static ngInjectableDef = defineInjectable({
providedIn: null, providedIn: null,

View File

@ -6,13 +6,13 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Component, ContentChild, Directive, Injectable, Injector, Input, NgModule, NgModuleFactory, NgModuleRef, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjector, ɵInjectorDef} from '../../../src/core'; import {Component, ContentChild, Directive, Injectable, Injector, InjectorDef, Input, NgModule, NgModuleFactory, NgModuleRef, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjector} from '../../../src/core';
import * as r3 from '../../../src/render3/index'; import * as r3 from '../../../src/render3/index';
const details_elided = { const details_elided = {
type: Object, type: Object,
} as any; } as any;
export type $ɵComponentDef$ = any; export type $ComponentDef$ = any;
/////////// ///////////
// Lib A - Compiled pre-Ivy // Lib A - Compiled pre-Ivy
@ -52,7 +52,7 @@ const node_modules_libA_module_metadata = {
@Component({}) @Component({})
export class LibBComponent { export class LibBComponent {
// COMPILER GENERATED // COMPILER GENERATED
static ngComponentDef: $ɵComponentDef$ = r3.defineComponent(details_elided); static ngComponentDef: $ComponentDef$ = r3.defineComponent(details_elided);
} }
@NgModule({declarations: [LibAComponent], imports: []}) @NgModule({declarations: [LibAComponent], imports: []})
@ -84,7 +84,7 @@ const node_modules_libB_module_metadata = {
@Component({}) @Component({})
export class AppComponent { export class AppComponent {
// COMPILER GENERATED // COMPILER GENERATED
static ngComponentDef: $ɵComponentDef$ = r3.defineComponent(details_elided); static ngComponentDef: $ComponentDef$ = r3.defineComponent(details_elided);
} }
@NgModule({declarations: [LibAComponent], imports: []}) @NgModule({declarations: [LibAComponent], imports: []})

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, INJECTOR, Inject, InjectFlags, Injectable, Injector, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, SkipSelf, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, defineInjectable, defineInjector, inject, ɵInjectableDef, ɵInjectorDef} from '../../../src/core'; import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, INJECTOR, Inject, InjectFlags, Injectable, InjectableDef, Injector, InjectorDef, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, SkipSelf, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, defineInjectable, defineInjector, inject} from '../../../src/core';
import * as $r3$ from '../../../src/core_render3_private_export'; import * as $r3$ from '../../../src/core_render3_private_export';
import {renderComponent, toHtml} from '../render_util'; import {renderComponent, toHtml} from '../render_util';

View File

@ -6,11 +6,10 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Component, ContentChild, Directive, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjectable, defineInjector, ɵInjectableDef, ɵInjectorDef} from '../../../src/core'; import {Component, ContentChild, Directive, Injectable, InjectableDef, InjectorDef, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjectable, defineInjector} from '../../../src/core';
import * as r3 from '../../../src/render3/index'; import * as r3 from '../../../src/render3/index';
/** /**
* GOALS: * GOALS:
* - Patch types in tree shakable way * - Patch types in tree shakable way

View File

@ -7,7 +7,7 @@
*/ */
import {NgForOf, NgForOfContext} from '@angular/common'; import {NgForOf, NgForOfContext} from '@angular/common';
import {Component, ContentChild, Directive, EventEmitter, Injectable, Input, NgModule, OnDestroy, Optional, Output, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjectable, defineInjector, ɵInjectableDef, ɵInjectorDef} from '@angular/core'; import {Component, ContentChild, Directive, EventEmitter, Injectable, InjectableDef, InjectorDef, Input, NgModule, OnDestroy, Optional, Output, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjectable, defineInjector} from '@angular/core';
import {withBody} from '@angular/core/testing'; import {withBody} from '@angular/core/testing';
import * as r3 from '../../../src/render3/index'; import * as r3 from '../../../src/render3/index';

View File

@ -11,9 +11,9 @@ import {stringifyElement} from '@angular/platform-browser/testing/src/browser_ut
import {Injector} from '../../src/di/injector'; import {Injector} from '../../src/di/injector';
import {CreateComponentOptions} from '../../src/render3/component'; import {CreateComponentOptions} from '../../src/render3/component';
import {extractDirectiveDef, extractPipeDef} from '../../src/render3/definition'; import {extractDirectiveDef, extractPipeDef} from '../../src/render3/definition';
import {ComponentTemplate, ComponentType, DirectiveType, PublicFeature, RenderFlags, defineComponent, defineDirective, renderComponent as _renderComponent, tick, ɵComponentDef, ɵDirectiveDef} from '../../src/render3/index'; import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveType, PublicFeature, RenderFlags, defineComponent, defineDirective, renderComponent as _renderComponent, tick} from '../../src/render3/index';
import {NG_HOST_SYMBOL, renderTemplate} from '../../src/render3/instructions'; import {NG_HOST_SYMBOL, renderTemplate} from '../../src/render3/instructions';
import {DirectiveDefList, DirectiveDefListOrFactory, DirectiveTypesOrFactory, PipeDefList, PipeDefListOrFactory, PipeTypesOrFactory, ɵPipeDef} from '../../src/render3/interfaces/definition'; import {DirectiveDefList, DirectiveDefListOrFactory, DirectiveTypesOrFactory, PipeDef, PipeDefList, PipeDefListOrFactory, PipeTypesOrFactory} from '../../src/render3/interfaces/definition';
import {LElementNode} from '../../src/render3/interfaces/node'; import {LElementNode} from '../../src/render3/interfaces/node';
import {RElement, RText, Renderer3, RendererFactory3, domRendererFactory3} from '../../src/render3/interfaces/renderer'; import {RElement, RText, Renderer3, RendererFactory3, domRendererFactory3} from '../../src/render3/interfaces/renderer';
import {Type} from '../../src/type'; import {Type} from '../../src/type';
@ -171,13 +171,13 @@ export function renderToHtml(
function toDefs( function toDefs(
types: DirectiveTypesOrFactory | undefined | null, types: DirectiveTypesOrFactory | undefined | null,
mapFn: (type: Type<any>) => ɵDirectiveDef<any>): DirectiveDefList|null; mapFn: (type: Type<any>) => DirectiveDef<any>): DirectiveDefList|null;
function toDefs( function toDefs(
types: PipeTypesOrFactory | undefined | null, types: PipeTypesOrFactory | undefined | null,
mapFn: (type: Type<any>) => ɵPipeDef<any>): PipeDefList|null; mapFn: (type: Type<any>) => PipeDef<any>): PipeDefList|null;
function toDefs( function toDefs(
types: PipeTypesOrFactory | DirectiveTypesOrFactory | undefined | null, types: PipeTypesOrFactory | DirectiveTypesOrFactory | undefined | null,
mapFn: (type: Type<any>) => ɵPipeDef<any>| ɵDirectiveDef<any>): any { mapFn: (type: Type<any>) => PipeDef<any>| DirectiveDef<any>): any {
if (!types) return null; if (!types) return null;
if (typeof types == 'function') { if (typeof types == 'function') {
types = types(); types = types();

View File

@ -7,7 +7,7 @@
*/ */
import {NgModuleRef} from '@angular/core'; import {NgModuleRef} from '@angular/core';
import {defineInjectable, ɵInjectableDef} from '@angular/core/src/di/defs'; import {InjectableDef, defineInjectable} from '@angular/core/src/di/defs';
import {INJECTOR, InjectFlags, Injector, inject} from '@angular/core/src/di/injector'; import {INJECTOR, InjectFlags, Injector, inject} from '@angular/core/src/di/injector';
import {makePropDecorator} from '@angular/core/src/util/decorators'; import {makePropDecorator} from '@angular/core/src/util/decorators';
import {NgModuleDefinition, NgModuleProviderDef, NodeFlags} from '@angular/core/src/view'; import {NgModuleDefinition, NgModuleProviderDef, NodeFlags} from '@angular/core/src/view';
@ -24,14 +24,14 @@ class MyChildModule {}
class NotMyModule {} class NotMyModule {}
class Bar { class Bar {
static ngInjectableDef: ɵInjectableDef<Bar> = defineInjectable({ static ngInjectableDef: InjectableDef<Bar> = defineInjectable({
factory: () => new Bar(), factory: () => new Bar(),
providedIn: MyModule, providedIn: MyModule,
}); });
} }
class Baz { class Baz {
static ngInjectableDef: ɵInjectableDef<Baz> = defineInjectable({ static ngInjectableDef: InjectableDef<Baz> = defineInjectable({
factory: () => new Baz(), factory: () => new Baz(),
providedIn: NotMyModule, providedIn: NotMyModule,
}); });
@ -40,7 +40,7 @@ class Baz {
class HasNormalDep { class HasNormalDep {
constructor(public foo: Foo) {} constructor(public foo: Foo) {}
static ngInjectableDef: ɵInjectableDef<HasNormalDep> = defineInjectable({ static ngInjectableDef: InjectableDef<HasNormalDep> = defineInjectable({
factory: () => new HasNormalDep(inject(Foo)), factory: () => new HasNormalDep(inject(Foo)),
providedIn: MyModule, providedIn: MyModule,
}); });
@ -49,7 +49,7 @@ class HasNormalDep {
class HasDefinedDep { class HasDefinedDep {
constructor(public bar: Bar) {} constructor(public bar: Bar) {}
static ngInjectableDef: ɵInjectableDef<HasDefinedDep> = defineInjectable({ static ngInjectableDef: InjectableDef<HasDefinedDep> = defineInjectable({
factory: () => new HasDefinedDep(inject(Bar)), factory: () => new HasDefinedDep(inject(Bar)),
providedIn: MyModule, providedIn: MyModule,
}); });
@ -58,14 +58,14 @@ class HasDefinedDep {
class HasOptionalDep { class HasOptionalDep {
constructor(public baz: Baz|null) {} constructor(public baz: Baz|null) {}
static ngInjectableDef: ɵInjectableDef<HasOptionalDep> = defineInjectable({ static ngInjectableDef: InjectableDef<HasOptionalDep> = defineInjectable({
factory: () => new HasOptionalDep(inject(Baz, InjectFlags.Optional)), factory: () => new HasOptionalDep(inject(Baz, InjectFlags.Optional)),
providedIn: MyModule, providedIn: MyModule,
}); });
} }
class ChildDep { class ChildDep {
static ngInjectableDef: ɵInjectableDef<ChildDep> = defineInjectable({ static ngInjectableDef: InjectableDef<ChildDep> = defineInjectable({
factory: () => new ChildDep(), factory: () => new ChildDep(),
providedIn: MyChildModule, providedIn: MyChildModule,
}); });
@ -73,7 +73,7 @@ class ChildDep {
class FromChildWithOptionalDep { class FromChildWithOptionalDep {
constructor(public baz: Baz|null) {} constructor(public baz: Baz|null) {}
static ngInjectableDef: ɵInjectableDef<FromChildWithOptionalDep> = defineInjectable({ static ngInjectableDef: InjectableDef<FromChildWithOptionalDep> = defineInjectable({
factory: () => new FromChildWithOptionalDep(inject(Baz, InjectFlags.Default)), factory: () => new FromChildWithOptionalDep(inject(Baz, InjectFlags.Default)),
providedIn: MyChildModule, providedIn: MyChildModule,
}); });
@ -81,7 +81,7 @@ class FromChildWithOptionalDep {
class FromChildWithSkipSelfDep { class FromChildWithSkipSelfDep {
constructor(public depFromParent: ChildDep|null, public depFromChild: Bar|null) {} constructor(public depFromParent: ChildDep|null, public depFromChild: Bar|null) {}
static ngInjectableDef: ɵInjectableDef<FromChildWithSkipSelfDep> = defineInjectable({ static ngInjectableDef: InjectableDef<FromChildWithSkipSelfDep> = defineInjectable({
factory: () => new FromChildWithSkipSelfDep( factory: () => new FromChildWithSkipSelfDep(
inject(ChildDep, InjectFlags.SkipSelf|InjectFlags.Optional), inject(ChildDep, InjectFlags.SkipSelf|InjectFlags.Optional),
inject(Bar, InjectFlags.Self|InjectFlags.Optional)), inject(Bar, InjectFlags.Self|InjectFlags.Optional)),
@ -119,10 +119,10 @@ describe('NgModuleRef_ injector', () => {
it('injects a provided value', it('injects a provided value',
() => { expect(ref.injector.get(Foo) instanceof Foo).toBeTruthy(); }); () => { expect(ref.injector.get(Foo) instanceof Foo).toBeTruthy(); });
it('injects an ɵInjectableDef value', it('injects an InjectableDef value',
() => { expect(ref.injector.get(Bar) instanceof Bar).toBeTruthy(); }); () => { expect(ref.injector.get(Bar) instanceof Bar).toBeTruthy(); });
it('caches ɵInjectableDef values', it('caches InjectableDef values',
() => { expect(ref.injector.get(Bar)).toBe(ref.injector.get(Bar)); }); () => { expect(ref.injector.get(Bar)).toBe(ref.injector.get(Bar)); });
it('injects provided deps properly', () => { it('injects provided deps properly', () => {

View File

@ -244,14 +244,14 @@ export declare class DefaultIterableDiffer<V> implements IterableDiffer<V>, Iter
export declare function defineInjectable<T>(opts: { export declare function defineInjectable<T>(opts: {
providedIn?: Type<any> | 'root' | 'any' | null; providedIn?: Type<any> | 'root' | 'any' | null;
factory: () => T; factory: () => T;
}): ɵInjectableDef<T>; }): InjectableDef<T>;
/** @experimental */ /** @experimental */
export declare function defineInjector(options: { export declare function defineInjector(options: {
factory: () => any; factory: () => any;
providers?: any[]; providers?: any[];
imports?: any[]; imports?: any[];
}): ɵInjectorDef<any>; }): InjectorDef<any>;
/** @experimental */ /** @experimental */
export declare function destroyPlatform(): void; export declare function destroyPlatform(): void;
@ -354,12 +354,19 @@ export interface InjectableDecorator {
} & InjectableProvider): Injectable; } & InjectableProvider): Injectable;
} }
/** @experimental */
export interface InjectableDef<T> {
factory: () => T;
providedIn: InjectorType<any> | 'root' | 'any' | null;
value: T | undefined;
}
/** @experimental */ /** @experimental */
export declare type InjectableProvider = ValueSansProvider | ExistingSansProvider | StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider; export declare type InjectableProvider = ValueSansProvider | ExistingSansProvider | StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider;
/** @experimental */ /** @experimental */
export interface InjectableType<T> extends Type<T> { export interface InjectableType<T> extends Type<T> {
ngInjectableDef: ɵInjectableDef<T>; ngInjectableDef: InjectableDef<T>;
} }
export interface InjectDecorator { export interface InjectDecorator {
@ -377,7 +384,7 @@ export declare const enum InjectFlags {
export declare class InjectionToken<T> { export declare class InjectionToken<T> {
protected _desc: string; protected _desc: string;
readonly ngInjectableDef: ɵInjectableDef<T> | undefined; readonly ngInjectableDef: InjectableDef<T> | undefined;
constructor(_desc: string, options?: { constructor(_desc: string, options?: {
providedIn?: Type<any> | 'root' | null; providedIn?: Type<any> | 'root' | null;
factory: () => T; factory: () => T;
@ -390,7 +397,7 @@ export declare abstract class Injector {
/** @deprecated */ abstract get(token: any, notFoundValue?: any): any; /** @deprecated */ abstract get(token: any, notFoundValue?: any): any;
static NULL: Injector; static NULL: Injector;
static THROW_IF_NOT_FOUND: Object; static THROW_IF_NOT_FOUND: Object;
static ngInjectableDef: ɵInjectableDef<Injector>; static ngInjectableDef: InjectableDef<Injector>;
/** @deprecated */ static create(providers: StaticProvider[], parent?: Injector): Injector; /** @deprecated */ static create(providers: StaticProvider[], parent?: Injector): Injector;
static create(options: { static create(options: {
providers: StaticProvider[]; providers: StaticProvider[];
@ -402,9 +409,16 @@ export declare abstract class Injector {
/** @experimental */ /** @experimental */
export declare const INJECTOR: InjectionToken<Injector>; export declare const INJECTOR: InjectionToken<Injector>;
/** @experimental */
export interface InjectorDef<T> {
factory: () => T;
imports: (InjectorType<any> | InjectorTypeWithProviders<any>)[];
providers: (Type<any> | ValueProvider | ExistingProvider | FactoryProvider | ConstructorProvider | StaticClassProvider | ClassProvider | any[])[];
}
/** @experimental */ /** @experimental */
export interface InjectorType<T> extends Type<T> { export interface InjectorType<T> extends Type<T> {
ngInjectorDef: ɵInjectorDef<T>; ngInjectorDef: InjectorDef<T>;
} }
/** @experimental */ /** @experimental */
@ -448,7 +462,7 @@ export declare class IterableDiffers {
/** @deprecated */ factories: IterableDifferFactory[]; /** @deprecated */ factories: IterableDifferFactory[];
constructor(factories: IterableDifferFactory[]); constructor(factories: IterableDifferFactory[]);
find(iterable: any): IterableDifferFactory; find(iterable: any): IterableDifferFactory;
static ngInjectableDef: ɵInjectableDef<IterableDiffers>; static ngInjectableDef: InjectableDef<IterableDiffers>;
static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers; static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers;
static extend(factories: IterableDifferFactory[]): StaticProvider; static extend(factories: IterableDifferFactory[]): StaticProvider;
} }