refactor(core): rename ngDirectiveDef to ɵdir (#33110)

Directive defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.

This commit adds the prefix and shortens the name from
ngDirectiveDef to dir. This is because property names
cannot be minified by Uglify without turning on property
mangling (which most apps have turned off) and are thus
size-sensitive.

Note that the other "defs" (ngFactoryDef, etc) will be
prefixed and shortened in follow-up PRs, in an attempt to
limit how large and conflict-y this change is.

PR Close #33110
This commit is contained in:
Kara Erickson 2019-10-11 12:28:12 -07:00 committed by Miško Hevery
parent d8249d1230
commit 1a67d70bf8
47 changed files with 150 additions and 156 deletions

View File

@ -54,16 +54,16 @@ export const ngClassFactoryDef = ngClassFactoryDef__PRE_R3__;
* While this is a base class that NgClass extends from, the
* class itself acts as a container for non-VE code to setup
* a link to the `[class]` host binding (via the static
* `ngDirectiveDef` property on the class).
* `ɵdir` property on the class).
*
* Note that the `ngDirectiveDef` property's code is switched
* Note that the `ɵdir` property's code is switched
* depending if VE is present or not (this allows for the
* binding code to be set only for newer versions of Angular).
*
* @publicApi
*/
export class NgClassBase {
static ngDirectiveDef: any = ngClassDirectiveDef;
static ɵdir: any = ngClassDirectiveDef;
static ngFactoryDef: any = ngClassFactoryDef;
constructor(protected _delegate: NgClassImpl) {}

View File

@ -54,16 +54,16 @@ export const ngStyleFactoryDef = ngStyleDirectiveDef__PRE_R3__;
* While this is a base class that NgStyle extends from, the
* class itself acts as a container for non-VE code to setup
* a link to the `[style]` host binding (via the static
* `ngDirectiveDef` property on the class).
* `ɵdir` property on the class).
*
* Note that the `ngDirectiveDef` property's code is switched
* Note that the `ɵdir` property's code is switched
* depending if VE is present or not (this allows for the
* binding code to be set only for newer versions of Angular).
*
* @publicApi
*/
export class NgStyleBase {
static ngDirectiveDef: any = ngStyleDirectiveDef;
static ɵdir: any = ngStyleDirectiveDef;
static ngFactory: any = ngStyleFactoryDef;
constructor(protected _delegate: NgStyleImpl) {}

View File

@ -28,8 +28,8 @@ import {createDirectiveDecorator, hasConstructor, hasDirectiveDecorator, isClass
* ```
*
* When compiling `DerivedDir` which extends the undecorated `BasePlain` class, the compiler needs
* to generate an `ngDirectiveDef` for `DerivedDir`. In particular, it needs to generate a factory
* function that creates instances of `DerivedDir`.
* to generate a directive def (`ɵdir`) for `DerivedDir`. In particular, it needs to generate a
* factory function that creates instances of `DerivedDir`.
*
* As `DerivedDir` has no constructor, the factory function for `DerivedDir` must delegate to the
* factory function for `BasePlain`. But for this to work, `BasePlain` must have a factory function,

View File

@ -119,7 +119,7 @@ runInEachFileSystem(() => {
const typingsFile = result.find(f => f.path === _('/typings/file.d.ts')) !;
expect(typingsFile.contents)
.toContain(
'foo(x: number): number;\n static ngFactoryDef: ɵngcc0.ɵɵFactoryDef<A>;\n static ngDirectiveDef: ɵngcc0.ɵɵDirectiveDefWithMeta');
'foo(x: number): number;\n static ngFactoryDef: ɵngcc0.ɵɵFactoryDef<A>;\n static ɵdir: ɵngcc0.ɵɵDirectiveDefWithMeta');
});
it('should render imports into typings files', () => {

View File

@ -230,7 +230,7 @@ A.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], decls: 1, v
expect(addDefinitionsSpy.calls.first().args[2])
.toEqual(`A.ngFactoryDef = function A_Factory(t) { return new (t || A)(); };
A.ngDirectiveDef = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });
A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });
/*@__PURE__*/ ɵngcc0.ɵsetClassMetadata(A, [{
type: Directive,
args: [{ selector: '[a]' }]

View File

@ -100,7 +100,7 @@ export class DirectiveDecoratorHandler implements
}
return [
factoryRes, {
name: 'ngDirectiveDef',
name: 'ɵdir',
initializer: res.expression,
statements: [],
type: res.type,

View File

@ -69,7 +69,7 @@ export class DtsMetadataReader implements MetadataReader {
getDirectiveMetadata(ref: Reference<ClassDeclaration>): DirectiveMeta|null {
const clazz = ref.node;
const def = this.reflector.getMembersOfClass(clazz).find(
field => field.isStatic && (field.name === 'ɵcmp' || field.name === 'ngDirectiveDef'));
field => field.isStatic && (field.name === 'ɵcmp' || field.name === 'ɵdir'));
if (def === undefined) {
// No definition could be found.
return null;

View File

@ -85,7 +85,7 @@ runInEachFileSystem(() => {
const {resolver, refs} = makeTestEnv({
'test': `
export declare class Dir {
static ngDirectiveDef: DirectiveMeta<Dir, '[dir]', ['exportAs'], {'input': 'input2'},
static ɵdir: DirectiveMeta<Dir, '[dir]', ['exportAs'], {'input': 'input2'},
{'output': 'output2'}, ['query']>;
}
@ -103,7 +103,7 @@ runInEachFileSystem(() => {
const {resolver, refs} = makeTestEnv({
'test': `
export declare class Dir {
static ngDirectiveDef: DirectiveMeta<Dir, '[dir]', never, never, never, never>;
static ɵdir: DirectiveMeta<Dir, '[dir]', never, never, never, never>;
}
export declare class ModuleA {
@ -124,7 +124,7 @@ runInEachFileSystem(() => {
const {resolver, refs} = makeTestEnv({
'declaration': `
export declare class Dir {
static ngDirectiveDef: DirectiveMeta<Dir, '[dir]', never, never, never, never>;
static ɵdir: DirectiveMeta<Dir, '[dir]', never, never, never, never>;
}
export declare class ModuleA {
@ -152,7 +152,7 @@ runInEachFileSystem(() => {
{
'deep': `
export declare class DeepDir {
static ngDirectiveDef: DirectiveMeta<DeepDir, '[deep]', never, never, never, never>;
static ɵdir: DirectiveMeta<DeepDir, '[deep]', never, never, never, never>;
}
export declare class DeepModule {
@ -163,7 +163,7 @@ runInEachFileSystem(() => {
import * as deep from 'deep';
export declare class MiddleDir {
static ngDirectiveDef: DirectiveMeta<MiddleDir, '[middle]', never, never, never, never>;
static ɵdir: DirectiveMeta<MiddleDir, '[middle]', never, never, never, never>;
}
export declare class MiddleModule {
@ -174,7 +174,7 @@ runInEachFileSystem(() => {
import * as middle from 'middle';
export declare class ShallowDir {
static ngDirectiveDef: DirectiveMeta<ShallowDir, '[middle]', never, never, never, never>;
static ɵdir: DirectiveMeta<ShallowDir, '[middle]', never, never, never, never>;
}
export declare class ShallowModule {
@ -202,7 +202,7 @@ runInEachFileSystem(() => {
{
'deep': `
export declare class DeepDir {
static ngDirectiveDef: DirectiveMeta<DeepDir, '[deep]', never, never, never, never>;
static ɵdir: DirectiveMeta<DeepDir, '[deep]', never, never, never, never>;
}
export declare class DeepModule {
@ -213,7 +213,7 @@ runInEachFileSystem(() => {
import * as deep from 'deep';
export declare class MiddleDir {
static ngDirectiveDef: DirectiveMeta<MiddleDir, '[middle]', never, never, never, never>;
static ɵdir: DirectiveMeta<MiddleDir, '[middle]', never, never, never, never>;
}
export declare class MiddleModule {
@ -224,7 +224,7 @@ runInEachFileSystem(() => {
import * as middle from 'middle';
export declare class ShallowDir {
static ngDirectiveDef: DirectiveMeta<ShallowDir, '[middle]', never, never, never, never>;
static ɵdir: DirectiveMeta<ShallowDir, '[middle]', never, never, never, never>;
}
export declare class ShallowModule {
@ -253,7 +253,7 @@ runInEachFileSystem(() => {
{
'module': `
export declare class DeepDir {
static ngDirectiveDef: DirectiveMeta<DeepDir, '[deep]', never, never, never, never>;
static ɵdir: DirectiveMeta<DeepDir, '[deep]', never, never, never, never>;
}
export declare class DeepModule {

View File

@ -21,7 +21,7 @@
const R3_DEF_NAME_PATTERN = [
'ngBaseDef',
'ɵcmp',
'ngDirectiveDef',
'ɵdir',
'ngInjectableDef',
'ngInjectorDef',
'ngModuleDef',

View File

@ -583,7 +583,7 @@ describe('compiler compliance', () => {
// SomeDirective definition should be:
const SomeDirectiveDefinition = `
SomeDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
SomeDirective.ɵdir = $r3$.ɵɵdefineDirective({
type: SomeDirective,
selectors: [["", "some-directive", ""]]
});
@ -620,7 +620,7 @@ describe('compiler compliance', () => {
expectEmit(source, ChildComponentDefinition, 'Incorrect ChildComponent.ɵcmp');
expectEmit(source, ChildComponentFactory, 'Incorrect ChildComponent.ngFactoryDef');
expectEmit(source, SomeDirectiveDefinition, 'Incorrect SomeDirective.ngDirectiveDef');
expectEmit(source, SomeDirectiveDefinition, 'Incorrect SomeDirective.ɵdir');
expectEmit(source, SomeDirectiveFactory, 'Incorrect SomeDirective.ngFactoryDef');
expectEmit(source, MyComponentDefinition, 'Incorrect MyComponentDefinition.ɵcmp');
expectEmit(source, MyComponentFactory, 'Incorrect MyComponentDefinition.ngFactoryDef');
@ -646,7 +646,7 @@ describe('compiler compliance', () => {
// SomeDirective definition should be:
const SomeDirectiveDefinition = `
SomeDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
SomeDirective.ɵdir = $r3$.ɵɵdefineDirective({
type: SomeDirective,
selectors: [["div", "some-directive", "", 8, "foo", 3, "title", "", 9, "baz"]]
});
@ -657,7 +657,7 @@ describe('compiler compliance', () => {
// OtherDirective definition should be:
const OtherDirectiveDefinition = `
OtherDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
OtherDirective.ɵdir = $r3$.ɵɵdefineDirective({
type: OtherDirective,
selectors: [["", 5, "span", "title", "", 9, "baz"]]
});
@ -669,9 +669,9 @@ describe('compiler compliance', () => {
const result = compile(files, angularFiles);
const source = result.source;
expectEmit(source, SomeDirectiveDefinition, 'Incorrect SomeDirective.ngDirectiveDef');
expectEmit(source, SomeDirectiveDefinition, 'Incorrect SomeDirective.ɵdir');
expectEmit(source, SomeDirectiveFactory, 'Incorrect SomeDirective.ngFactoryDef');
expectEmit(source, OtherDirectiveDefinition, 'Incorrect OtherDirective.ngDirectiveDef');
expectEmit(source, OtherDirectiveDefinition, 'Incorrect OtherDirective.ɵdir');
expectEmit(source, OtherDirectiveFactory, 'Incorrect OtherDirective.ngFactoryDef');
});
@ -789,7 +789,7 @@ describe('compiler compliance', () => {
};
const IfDirectiveDefinition = `
IfDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
IfDirective.ɵdir = $r3$.ɵɵdefineDirective({
type: IfDirective,
selectors: [["", "if", ""]]
});`;
@ -835,7 +835,7 @@ describe('compiler compliance', () => {
const result = compile(files, angularFiles);
const source = result.source;
expectEmit(source, IfDirectiveDefinition, 'Incorrect IfDirective.ngDirectiveDef');
expectEmit(source, IfDirectiveDefinition, 'Incorrect IfDirective.ɵdir');
expectEmit(source, IfDirectiveFactory, 'Incorrect IfDirective.ngFactoryDef');
expectEmit(source, MyComponentDefinition, 'Incorrect MyComponent.ɵcmp');
expectEmit(source, MyComponentFactory, 'Incorrect MyComponent.ngFactoryDef');
@ -2595,7 +2595,7 @@ describe('compiler compliance', () => {
// TODO(benlesh): Enforce this when the directives are specified
const ForDirectiveDefinition = `
ForOfDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
ForOfDirective.ɵdir = $r3$.ɵɵdefineDirective({
type: ForOfDirective,
selectors: [["", "forOf", ""]],
features: [$r3$.ɵɵNgOnChangesFeature()],
@ -2676,7 +2676,7 @@ describe('compiler compliance', () => {
// TODO(chuckj): Enforce this when the directives are specified
const ForDirectiveDefinition = `
ForOfDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
ForOfDirective.ɵdir = $r3$.ɵɵdefineDirective({
type: ForOfDirective,
selectors: [["", "forOf", ""]],
features: [$r3$.ɵɵNgOnChangesFeature()],
@ -2926,7 +2926,7 @@ describe('compiler compliance', () => {
// SomeDirective definition should be:
const SomeDirectiveDefinition = `
SomeDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
SomeDirective.ɵdir = $r3$.ɵɵdefineDirective({
type: SomeDirective,
selectors: [["", "some-directive", ""]],
exportAs: ["someDir", "otherDir"]
@ -2936,7 +2936,7 @@ describe('compiler compliance', () => {
const result = compile(files, angularFiles);
const source = result.source;
expectEmit(source, SomeDirectiveDefinition, 'Incorrect SomeDirective.ngDirectiveDef');
expectEmit(source, SomeDirectiveDefinition, 'Incorrect SomeDirective.ɵdir');
});
it('should not throw for empty property bindings on ng-template', () => {

View File

@ -668,7 +668,7 @@ describe('compiler compliance: bindings', () => {
};
const HostBindingDirDeclaration = `
HostBindingDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
HostBindingDir.ɵdir = $r3$.ɵɵdefineDirective({
type: HostBindingDir,
selectors: [["", "hostBindingDir", ""]],
hostBindings: function HostBindingDir_HostBindings(rf, ctx, elIndex) {
@ -761,7 +761,7 @@ describe('compiler compliance: bindings', () => {
};
const HostAttributeDirDeclaration = `
HostAttributeDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
HostAttributeDir.ɵdir = $r3$.ɵɵdefineDirective({
type: HostAttributeDir,
selectors: [["", "hostAttributeDir", ""]],
hostBindings: function HostAttributeDir_HostBindings(rf, ctx, elIndex) {
@ -805,7 +805,7 @@ describe('compiler compliance: bindings', () => {
const HostAttributeDirDeclaration = `
const $c0$ = ["aria-label", "label"];
HostAttributeDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
HostAttributeDir.ɵdir = $r3$.ɵɵdefineDirective({
type: HostAttributeDir,
selectors: [["", "hostAttributeDir", ""]],
hostBindings: function HostAttributeDir_HostBindings(rf, ctx, elIndex) {
@ -873,7 +873,7 @@ describe('compiler compliance: bindings', () => {
}
HostAttributeDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
HostAttributeDir.ɵdir = $r3$.ɵɵdefineDirective({
type: HostAttributeDir,
selectors: [["", "hostAttributeDir", ""]],
hostBindings: function HostAttributeDir_HostBindings(rf, ctx, elIndex) {

View File

@ -66,7 +66,7 @@ describe('compiler compliance: listen()', () => {
});`;
const directiveDef = `
MyDirective.ngDirectiveDef = IDENT.ɵɵdefineDirective({
MyDirective.ɵdir = IDENT.ɵɵdefineDirective({
inputs:{
directiveInput: "directiveInput",

View File

@ -332,7 +332,7 @@ describe('compiler compliance: styling', () => {
};
const template = `
MyAnimDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
MyAnimDir.ɵdir = $r3$.ɵɵdefineDirective({
hostBindings: function MyAnimDir_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {

View File

@ -373,7 +373,7 @@ runInEachFileSystem(os => {
const jsContents = env.getContents('test.js');
expect(jsContents).toContain('TestBase.ngBaseDef = i0.ɵɵdefineBase');
expect(jsContents).toContain('TestComponent.ɵcmp = i0.ɵɵdefineComponent');
expect(jsContents).toContain('TestDirective.ngDirectiveDef = i0.ɵɵdefineDirective');
expect(jsContents).toContain('TestDirective.ɵdir = i0.ɵɵdefineDirective');
expect(jsContents).toContain('TestPipe.ngPipeDef = i0.ɵɵdefinePipe');
expect(jsContents).toContain('TestInjectable.ngInjectableDef = i0.ɵɵdefineInjectable');
expect(jsContents).toContain('MyModule.ngModuleDef = i0.ɵɵdefineNgModule');
@ -1180,7 +1180,7 @@ runInEachFileSystem(os => {
// Validate that each class has the primary definition.
expect(jsContents).toContain('TestCmp.ɵcmp =');
expect(jsContents).toContain('TestDir.ngDirectiveDef =');
expect(jsContents).toContain('TestDir.ɵdir =');
expect(jsContents).toContain('TestPipe.ngPipeDef =');
expect(jsContents).toContain('TestNgModule.ngModuleDef =');
@ -2946,7 +2946,7 @@ runInEachFileSystem(os => {
import {ɵɵDirectiveDefWithMeta, ɵɵNgModuleDefWithMeta} from '@angular/core';
export declare class ExternalDir {
static ngDirectiveDef: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;
static ɵdir: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;
}
export declare class ExternalModule {
@ -2990,7 +2990,7 @@ runInEachFileSystem(os => {
env.write('node_modules/external/internal.d.ts', `
export declare class InternalDir {
static ngDirectiveDef: ɵɵDirectiveDefWithMeta<InternalDir, '[test]', never, never, never, never>;
static ɵdir: ɵɵDirectiveDefWithMeta<InternalDir, '[test]', never, never, never, never>;
}
`);
env.write('test.ts', `
@ -3233,7 +3233,7 @@ runInEachFileSystem(os => {
import {ɵɵDirectiveDefWithMeta, ɵɵNgModuleDefWithMeta} from '@angular/core';
export declare class ExternalDir {
static ngDirectiveDef: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;
static ɵdir: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;
}
export declare class ExternalModule {
@ -4179,7 +4179,7 @@ export const Foo = Foo__PRE_R3__;
import {ɵɵDirectiveDefWithMeta, ɵɵNgModuleDefWithMeta} from '@angular/core';
export declare class ExternalDir {
static ngDirectiveDef: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;
static ɵdir: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;
}
export declare class AlphaModule {
@ -4230,7 +4230,7 @@ export const Foo = Foo__PRE_R3__;
import {LibModule} from './lib';
export declare class ExternalDir {
static ngDirectiveDef: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;
static ɵdir: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;
}
export declare class ExternalModule {
@ -4241,7 +4241,7 @@ export const Foo = Foo__PRE_R3__;
import {ɵɵDirectiveDefWithMeta, ɵɵNgModuleDefWithMeta} from '@angular/core';
export declare class LibDir {
static ngDirectiveDef: ɵɵDirectiveDefWithMeta<LibDir, '[lib]', never, never, never, never>;
static ɵdir: ɵɵDirectiveDefWithMeta<LibDir, '[lib]', never, never, never, never>;
}
export declare class LibModule {

View File

@ -46,13 +46,13 @@ export declare class IndexPipe {
export declare class NgForOf<T> {
ngForOf: T[];
static ngTemplateContextGuard<T>(dir: NgForOf<T>, ctx: any): ctx is NgForOfContext<T>;
static ngDirectiveDef: i0.ɵɵDirectiveDefWithMeta<NgForOf<any>, '[ngFor][ngForOf]', never, {'ngForOf': 'ngForOf'}, {}, never>;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<NgForOf<any>, '[ngFor][ngForOf]', never, {'ngForOf': 'ngForOf'}, {}, never>;
}
export declare class NgIf {
ngIf: any;
static ngTemplateGuard_ngIf: 'binding';
static ngDirectiveDef: i0.ɵɵDirectiveDefWithMeta<NgForOf<any>, '[ngIf]', never, {'ngIf': 'ngIf'}, {}, never>;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<NgForOf<any>, '[ngIf]', never, {'ngIf': 'ngIf'}, {}, never>;
}
export declare class CommonModule {

View File

@ -171,7 +171,7 @@ There are also a list of helper decorators that make the `@Component` and `@Dire
Each of the class decorators can be thought of as class transformers that take the declared class and transform it, possibly using information from the helper decorators, to produce an Angular class. The JIT compiler performs this transformation at runtime. The AoT compiler performs this transformation at compile time.
Each of the class decorators' class transformer creates a corresponding static member on the class that describes to the runtime how to use the class. For example, the `@Component` decorator creates a `ɵcmp` static member, `@Directive` create an `ngDirectiveDef`, etc. Internally, these class transformers are called a "Compiler". Most of the compilers are straight forward translations of the metadata specified in the decorator to the information provided in the corresponding definition and, therefore, do not require anything outside the source file to perform the conversion. However, the component, during production builds and for type checking a template require the module scope of the component which requires information from other files in the program.
Each of the class decorators' class transformer creates a corresponding static member on the class that describes to the runtime how to use the class. For example, the `@Component` decorator creates a `ɵcmp` static member, `@Directive` create a `ɵdir`, etc. Internally, these class transformers are called a "Compiler". Most of the compilers are straight forward translations of the metadata specified in the decorator to the information provided in the corresponding definition and, therefore, do not require anything outside the source file to perform the conversion. However, the component, during production builds and for type checking a template require the module scope of the component which requires information from other files in the program.
#### Compiler design

View File

@ -39,7 +39,7 @@ The mental model of Ivy is that the decorator is the compiler. That is
the decorator can be thought of as parameters to a class transformer that
transforms the class by generating definitions based on the decorator
parameters. An `@Component` decorator transforms the class by adding
a `ɵcmp` static property, `@Directive` adds `ngDirectiveDef`,
a `ɵcmp` static property, `@Directive` adds `ɵdir`,
`@Pipe` adds `ngPipeDef`, etc. In most cases values supplied to the
decorator is sufficient to generate the definition. However, in the case of
interpreting the template, the compiler needs to know the selector defined for
@ -67,15 +67,15 @@ class:
| `type` | implicit |
| `isComponent` | `ɵcmp` |
| `selector` | `ngModuleScope` |
| `exportAs` | `ngDirectiveDef` |
| `inputs` | `ngDirectiveDef` |
| `outputs` | `ngDirectiveDef` |
| `hostListeners` | `ngDirectiveDef` |
| `hostProperties` | `ngDirectiveDef` |
| `hostAttributes` | `ngDirectiveDef` |
| `exportAs` | `ɵdir` |
| `inputs` | `ɵdir` |
| `outputs` | `ɵdir` |
| `hostListeners` | `ɵdir` |
| `hostProperties` | `ɵdir` |
| `hostAttributes` | `ɵdir` |
| `providers` | `ngInjectorDef` |
| `viewProviders` | `ɵcmp` |
| `queries` | `ngDirectiveDef` |
| `queries` | `ɵdir` |
| `guards` | not used |
| `viewQueries` | `ɵcmp` |
| `entryComponents` | not used |
@ -86,8 +86,8 @@ class:
| `componentFactory` | not used |
Only one definition is generated per class. All components are directives so a
`ɵcmp` contains all the `ngDirectiveDef` information. All directives
are injectable so `ɵcmp` and `ngDirectiveDef` contain `ngInjectableDef`
`ɵcmp` contains all the `ɵdir` information. All directives
are injectable so `ɵcmp` and `ɵdir` contain `ngInjectableDef`
information.
For `CompilePipeSummary` the table looks like:
@ -193,7 +193,7 @@ manually.
The metadata for a directive is transformed by:
1. Removing the `@Directive` directive.
2. Add `"ngDirectiveDef": {}` static field.
2. Add `"ɵdir": {}` static field.
3. Add `"ngSelector": <selector-value>` static field.
##### example
@ -213,7 +213,7 @@ export class MyDirective {
constructor() {
this.dirId = 'some id';
}
static ngDirectiveDef = ɵɵdefineDirective({...});
static ɵdir = ɵɵdefineDirective({...});
}
```
@ -226,7 +226,7 @@ export class MyDirective {
"MyDirective": {
"__symbolic": "class",
"statics": {
"ngDirectiveDef": {},
"ɵdir": {},
"ngSelector": "[my-dir]"
}
}

View File

@ -202,7 +202,7 @@ export class ConstantPool {
case DefinitionKind.Component:
return 'ɵcmp';
case DefinitionKind.Directive:
return 'ngDirectiveDef';
return 'ɵdir';
case DefinitionKind.Injector:
return 'ngInjectorDef';
case DefinitionKind.Pipe:

View File

@ -222,7 +222,7 @@ export {
export {
NG_ELEMENT_ID as ɵNG_ELEMENT_ID,
NG_COMP_DEF as ɵNG_COMP_DEF,
NG_DIRECTIVE_DEF as ɵNG_DIRECTIVE_DEF,
NG_DIR_DEF as ɵNG_DIR_DEF,
NG_PIPE_DEF as ɵNG_PIPE_DEF,
NG_MODULE_DEF as ɵNG_MODULE_DEF,
NG_BASE_DEF as ɵNG_BASE_DEF

View File

@ -13,7 +13,7 @@ Here is an abbreviated example of breakage of tree-shake-ability.
})
export class TooltipDirective {
// ngtsc generates this:
static ngDirectiveDef = ɵɵdefineDirective(...);
static ɵdir = ɵɵdefineDirective(...);
}
@Component({
@ -22,7 +22,7 @@ export class TooltipDirective {
})
class MyAppComponent {
// ngtsc generates this:
static ngDirectiveDef = ɵɵdefineComponent({
static ɵdir = ɵɵdefineComponent({
...
directives: [
// BREAKS TREE-SHAKING!!!
@ -41,7 +41,7 @@ class MyAppComponent {
})
class MyAppModule {
// ngtsc generates this:
static ngDirectiveDef = ɵɵdefineNgModule(...);
static ɵdir = ɵɵdefineNgModule(...);
}
```
@ -52,6 +52,6 @@ We store the information in the `.d.ts` file like so.
```typescript
class TooltipDirective {
static ngDirectiveDef: DirectiveDefWithMeta<TooltipDirective, '[tooltip]', '', {}, {}, []>
static ɵdir: DirectiveDefWithMeta<TooltipDirective, '[tooltip]', '', {}, {}, []>
}
```

View File

@ -172,7 +172,7 @@ class Child {
})
class Tooltip {
@HostBinding('title') hostTitle = 'greeting';
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
...
hostVars: 1
});
@ -206,8 +206,8 @@ The `EXPANDO` section needs additional information for information stored in `TV
| 1 | 2 | Injector size. Number of values to skip to get to Host Bindings.
| 2 | Child.ɵcmp.hostBindings | The function to call. (Only when `hostVars` is not `0`)
| 3 | Child.ɵcmp.hostVars | Number of host bindings to process. (Only when `hostVars` is not `0`)
| 4 | Tooltip.ngDirectiveDef.hostBindings | The function to call. (Only when `hostVars` is not `0`)
| 5 | Tooltip.ngDirectiveDef.hostVars | Number of host bindings to process. (Only when `hostVars` is not `0`)
| 4 | Tooltip.ɵdir.hostBindings | The function to call. (Only when `hostVars` is not `0`)
| 5 | Tooltip.ɵdir.hostVars | Number of host bindings to process. (Only when `hostVars` is not `0`)
The reason for this layout is to make the host binding update efficient using this pseudo code:
```typescript
@ -245,9 +245,9 @@ The above code should execute as:
| `Child.ɵcmp.hostBindings` | invoke with => | `\* new Child() *\ 19` | `\* <child> *\ 10`
| | `21` | `\* new Tooltip() *\ 20` | `\* <child> *\ 10`
| `Child.ɵcmp.hostVars` | `22` | `\* new Tooltip() *\ 20` | `\* <child> *\ 10`
| `Tooltip.ngDirectiveDef.hostBindings` | invoke with => | `\* new Tooltip() *\ 20` | `\* <child> *\ 10`
| `Tooltip.ɵdir.hostBindings` | invoke with => | `\* new Tooltip() *\ 20` | `\* <child> *\ 10`
| | `22` | `21` | `\* <child> *\ 10`
| `Tooltip.ngDirectiveDef.hostVars` | `22` | `21` | `\* <child> *\ 10`
| `Tooltip.ɵdir.hostVars` | `22` | `21` | `\* <child> *\ 10`
## `EXPANDO` and Injection

View File

@ -182,7 +182,7 @@ export function isComponentInstance(instance: any): boolean {
}
export function isDirectiveInstance(instance: any): boolean {
return instance && instance.constructor && instance.constructor.ngDirectiveDef;
return instance && instance.constructor && instance.constructor.ɵdir;
}
/**

View File

@ -16,7 +16,7 @@ import {initNgDevMode} from '../util/ng_dev_mode';
import {stringify} from '../util/stringify';
import {EMPTY_ARRAY, EMPTY_OBJ} from './empty';
import {NG_BASE_DEF, NG_COMP_DEF, NG_DIRECTIVE_DEF, NG_FACTORY_DEF, NG_LOCALE_ID_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from './fields';
import {NG_BASE_DEF, NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF, NG_LOCALE_ID_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from './fields';
import {ComponentDef, ComponentDefFeature, ComponentTemplate, ComponentType, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, DirectiveType, DirectiveTypesOrFactory, FactoryFn, HostBindingsFunction, PipeDef, PipeType, PipeTypesOrFactory, ViewQueriesFunction, ɵɵBaseDef} from './interfaces/definition';
import {TAttributes} from './interfaces/node';
// while SelectorFlags is unused here, it's required so that types don't get resolved lazily
@ -593,7 +593,7 @@ export function ɵɵdefineBase<T>(baseDefinition: {
* class MyDirective {
* // Generated by Angular Template Compiler
* // [Symbol] syntax will not be supported by TypeScript until v2.7
* static ngDirectiveDef = ɵɵdefineDirective({
* static ɵdir = ɵɵdefineDirective({
* ...
* });
* }
@ -744,7 +744,7 @@ export function getComponentDef<T>(type: any): ComponentDef<T>|null {
}
export function getDirectiveDef<T>(type: any): DirectiveDef<T>|null {
return type[NG_DIRECTIVE_DEF] || null;
return type[NG_DIR_DEF] || null;
}
export function getPipeDef<T>(type: any): PipeDef<T>|null {

View File

@ -15,7 +15,7 @@ import {isComponentDef} from '../interfaces/type_checks';
import {ɵɵNgOnChangesFeature} from './ng_onchanges_feature';
function getSuperType(type: Type<any>): Type<any>&
{ɵcmp?: ComponentDef<any>, ngDirectiveDef?: DirectiveDef<any>} {
{ɵcmp?: ComponentDef<any>, ɵdir?: DirectiveDef<any>} {
return Object.getPrototypeOf(type.prototype).constructor;
}
@ -32,13 +32,13 @@ export function ɵɵInheritDefinitionFeature(definition: DirectiveDef<any>| Comp
let superDef: DirectiveDef<any>|ComponentDef<any>|undefined = undefined;
if (isComponentDef(definition)) {
// Don't use getComponentDef/getDirectiveDef. This logic relies on inheritance.
superDef = superType.ɵcmp || superType.ngDirectiveDef;
superDef = superType.ɵcmp || superType.ɵdir;
} else {
if (superType.ɵcmp) {
throw new Error('Directives cannot inherit Components');
}
// Don't use getComponentDef/getDirectiveDef. This logic relies on inheritance.
superDef = superType.ngDirectiveDef;
superDef = superType.ɵdir;
}
const baseDef = (superType as any).ngBaseDef;

View File

@ -9,7 +9,7 @@
import {getClosureSafeProperty} from '../util/property';
export const NG_COMP_DEF = getClosureSafeProperty({ɵcmp: getClosureSafeProperty});
export const NG_DIRECTIVE_DEF = getClosureSafeProperty({ngDirectiveDef: getClosureSafeProperty});
export const NG_DIR_DEF = getClosureSafeProperty({ɵdir: getClosureSafeProperty});
export const NG_PIPE_DEF = getClosureSafeProperty({ngPipeDef: getClosureSafeProperty});
export const NG_MODULE_DEF = getClosureSafeProperty({ngModuleDef: getClosureSafeProperty});
export const NG_LOCALE_ID_DEF = getClosureSafeProperty({ngLocaleIdDef: getClosureSafeProperty});

View File

@ -24,7 +24,7 @@ import {getLView, getPreviousOrParentTNode} from '../state';
* class SomeDirective {
* constructor(directive: DirectiveA) {}
*
* static ngDirectiveDef = ɵɵdefineDirective({
* static ɵdir = ɵɵdefineDirective({
* type: SomeDirective,
* factory: () => new SomeDirective(ɵɵdirectiveInject(DirectiveA))
* });

View File

@ -75,11 +75,11 @@ export const enum RenderFlags {
export interface ComponentType<T> extends Type<T> { ɵcmp: never; }
/**
* A subclass of `Type` which has a static `ngDirectiveDef`:`DirectiveDef` field making it
* A subclass of `Type` which has a static `ɵdir`:`DirectiveDef` field making it
* consumable for rendering.
*/
export interface DirectiveType<T> extends Type<T> {
ngDirectiveDef: never;
ɵdir: never;
ngFactoryDef: () => T;
}

View File

@ -18,7 +18,7 @@ import {ViewEncapsulation} from '../../metadata/view';
import {initNgDevMode} from '../../util/ng_dev_mode';
import {getBaseDef, getComponentDef, getDirectiveDef} from '../definition';
import {EMPTY_ARRAY, EMPTY_OBJ} from '../empty';
import {NG_BASE_DEF, NG_COMP_DEF, NG_DIRECTIVE_DEF, NG_FACTORY_DEF} from '../fields';
import {NG_BASE_DEF, NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF} from '../fields';
import {ComponentType} from '../interfaces/definition';
import {stringifyForError} from '../util/misc_utils';
@ -119,7 +119,7 @@ function hasSelectorScope<T>(component: Type<T>): component is Type<T>&
/**
* Compile an Angular directive according to its decorator metadata, and patch the resulting
* ngDirectiveDef onto the component type.
* directive def onto the component type.
*
* In the event that compilation is not immediate, `compileDirective` will return a `Promise` which
* will resolve when compilation completes and the directive becomes usable.
@ -129,7 +129,7 @@ export function compileDirective(type: Type<any>, directive: Directive | null):
addDirectiveFactoryDef(type, directive || {});
Object.defineProperty(type, NG_DIRECTIVE_DEF, {
Object.defineProperty(type, NG_DIR_DEF, {
get: () => {
if (ngDirectiveDef === null) {
// `directive` can be null in the case of abstract directives as a base class
@ -148,7 +148,7 @@ export function compileDirective(type: Type<any>, directive: Directive | null):
function getDirectiveMetadata(type: Type<any>, metadata: Directive) {
const name = type && type.name;
const sourceMapUrl = `ng:///${name}/ngDirectiveDef.js`;
const sourceMapUrl = `ng:///${name}/ɵdir.js`;
const compiler = getCompilerFacade();
const facade = directiveMetadata(type as ComponentType<any>, metadata);
facade.typeSourceSpan = compiler.createParseSourceSpan('Directive', name, sourceMapUrl);

View File

@ -16,7 +16,7 @@ import {ModuleWithProviders, NgModule, NgModuleDef, NgModuleTransitiveScopes} fr
import {deepForEach, flatten} from '../../util/array_utils';
import {assertDefined} from '../../util/assert';
import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition';
import {NG_COMP_DEF, NG_DIRECTIVE_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from '../fields';
import {NG_COMP_DEF, NG_DIR_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from '../fields';
import {ComponentDef} from '../interfaces/definition';
import {NgModuleType} from '../ng_module_ref';
import {maybeUnwrapFn, stringifyForError} from '../util/misc_utils';
@ -388,7 +388,7 @@ function setScopeOnDeclaredComponents(moduleType: Type<any>, ngModule: NgModule)
const componentDef = getComponentDef(component) !;
patchComponentDefWithScope(componentDef, transitiveScopes);
} else if (
!declaration.hasOwnProperty(NG_DIRECTIVE_DEF) && !declaration.hasOwnProperty(NG_PIPE_DEF)) {
!declaration.hasOwnProperty(NG_DIR_DEF) && !declaration.hasOwnProperty(NG_PIPE_DEF)) {
// Set `ngSelectorScope` for future reference when the component compilation finishes.
(declaration as Type<any>& {ngSelectorScope?: any}).ngSelectorScope = moduleType;
}
@ -455,7 +455,7 @@ export function transitiveScopesFor<T>(
if (getPipeDef(declaredWithDefs)) {
scopes.compilation.pipes.add(declared);
} else {
// Either declared has a ɵcmp or ngDirectiveDef, or it's a component which hasn't
// Either declared has a ɵcmp or ɵdir, or it's a component which hasn't
// had its template compiled yet. In either case, it gets added to the compilation's
// directives.
scopes.compilation.directives.add(declared);
@ -487,7 +487,7 @@ export function transitiveScopesFor<T>(
const exportedType = exported as Type<E>& {
// Components, Directives, NgModules, and Pipes can all be exported.
ɵcmp?: any;
ngDirectiveDef?: any;
ɵdir?: any;
ngModuleDef?: NgModuleDef<E>;
ngPipeDef?: any;
};

View File

@ -69,7 +69,7 @@
"name": "NG_COMP_DEF"
},
{
"name": "NG_DIRECTIVE_DEF"
"name": "NG_DIR_DEF"
},
{
"name": "NG_ELEMENT_ID"

View File

@ -63,7 +63,7 @@
"name": "NG_COMP_DEF"
},
{
"name": "NG_DIRECTIVE_DEF"
"name": "NG_DIR_DEF"
},
{
"name": "NG_ELEMENT_ID"

View File

@ -126,7 +126,7 @@
"name": "NG_COMP_DEF"
},
{
"name": "NG_DIRECTIVE_DEF"
"name": "NG_DIR_DEF"
},
{
"name": "NG_ELEMENT_ID"

View File

@ -15,7 +15,7 @@ export const NgForOf: DirectiveType<NgForOfDef<any>> = NgForOfDef as any;
export const NgIf: DirectiveType<NgIfDef> = NgIfDef as any;
export const NgTemplateOutlet: DirectiveType<NgTemplateOutletDef> = NgTemplateOutletDef as any;
NgForOf.ngDirectiveDef = ɵɵdefineDirective({
NgForOf.ɵdir = ɵɵdefineDirective({
type: NgForOfDef,
selectors: [['', 'ngForOf', '']],
inputs: {
@ -29,7 +29,7 @@ NgForOf.ngFactoryDef = () => new NgForOfDef(
ɵɵdirectiveInject(ViewContainerRef as any), ɵɵdirectiveInject(TemplateRef as any),
ɵɵdirectiveInject(IterableDiffers));
NgIf.ngDirectiveDef = ɵɵdefineDirective({
NgIf.ɵdir = ɵɵdefineDirective({
type: NgIfDef,
selectors: [['', 'ngIf', '']],
inputs: {ngIf: 'ngIf', ngIfThen: 'ngIfThen', ngIfElse: 'ngIfElse'}
@ -38,7 +38,7 @@ NgIf.ngDirectiveDef = ɵɵdefineDirective({
NgIf.ngFactoryDef = () =>
new NgIfDef(ɵɵdirectiveInject(ViewContainerRef as any), ɵɵdirectiveInject(TemplateRef as any));
NgTemplateOutlet.ngDirectiveDef = ɵɵdefineDirective({
NgTemplateOutlet.ɵdir = ɵɵdefineDirective({
type: NgTemplateOutletDef,
selectors: [['', 'ngTemplateOutlet', '']],
features: [ɵɵNgOnChangesFeature()],

View File

@ -437,8 +437,7 @@ describe('recursive components', () => {
}
}
(NgIfTree.ɵcmp as ComponentDef<NgIfTree>).directiveDefs =
() => [NgIfTree.ɵcmp, NgIf.ngDirectiveDef];
(NgIfTree.ɵcmp as ComponentDef<NgIfTree>).directiveDefs = () => [NgIfTree.ɵcmp, NgIf.ɵdir];
function _buildTree(currDepth: number): TreeNode {
const children = currDepth < 2 ? _buildTree(currDepth + 1) : null;

View File

@ -29,7 +29,7 @@ describe('di', () => {
value = 'DirB';
static ngFactoryDef = () => new DirB();
static ngDirectiveDef =
static ɵdir =
ɵɵdefineDirective({selectors: [['', 'dirB', '']], type: DirB, inputs: {value: 'value'}});
}
@ -40,7 +40,7 @@ describe('di', () => {
value !: string;
static ngFactoryDef = () => new DirB();
static ngDirectiveDef =
static ɵdir =
ɵɵdefineDirective({type: DirB, selectors: [['', 'dirB', '']], inputs: {value: 'dirB'}});
}
@ -56,7 +56,7 @@ describe('di', () => {
return dirA;
}
static ngDirectiveDef = ɵɵdefineDirective({type: DirA, selectors: [['', 'dirA', '']]});
static ɵdir = ɵɵdefineDirective({type: DirA, selectors: [['', 'dirA', '']]});
}
beforeEach(() => dirA = null);
@ -82,7 +82,7 @@ describe('di', () => {
constructor(@Self() public dirB: DirB) {}
static ngFactoryDef = () => dirA = new DirA(ɵɵdirectiveInject(DirB, InjectFlags.Self));
static ngDirectiveDef = ɵɵdefineDirective({type: DirA, selectors: [['', 'dirA', '']]});
static ɵdir = ɵɵdefineDirective({type: DirA, selectors: [['', 'dirA', '']]});
}
const DirC = createDirective('dirC');

View File

@ -346,7 +346,7 @@ describe('component animations', () => {
// it('should allow host binding animations to be picked up and rendered', () => {
// class ChildCompWithAnim {
// static ngFactoryDef = () => new ChildCompWithAnim();
// static ngDirectiveDef = ɵɵdefineDirective({
// static ɵdir = ɵɵdefineDirective({
// type: ChildCompWithAnim,
// selectors: [['child-comp-with-anim']],
// hostBindings: function(rf: RenderFlags, ctx: any, elementIndex: number): void {
@ -837,20 +837,17 @@ describe('element discovery', () => {
class MyDir1 {
static ngFactoryDef = () => myDir1Instance = new MyDir1();
static ngDirectiveDef =
ɵɵdefineDirective({type: MyDir1, selectors: [['', 'my-dir-1', '']]});
static ɵdir = ɵɵdefineDirective({type: MyDir1, selectors: [['', 'my-dir-1', '']]});
}
class MyDir2 {
static ngFactoryDef = () => myDir2Instance = new MyDir2();
static ngDirectiveDef =
ɵɵdefineDirective({type: MyDir2, selectors: [['', 'my-dir-2', '']]});
static ɵdir = ɵɵdefineDirective({type: MyDir2, selectors: [['', 'my-dir-2', '']]});
}
class MyDir3 {
static ngFactoryDef = () => myDir3Instance = new MyDir2();
static ngDirectiveDef =
ɵɵdefineDirective({type: MyDir3, selectors: [['', 'my-dir-3', '']]});
static ɵdir = ɵɵdefineDirective({type: MyDir3, selectors: [['', 'my-dir-3', '']]});
}
class StructuredComp {
@ -921,14 +918,12 @@ describe('element discovery', () => {
class MyDir1 {
static ngFactoryDef = () => myDir1Instance = new MyDir1();
static ngDirectiveDef =
ɵɵdefineDirective({type: MyDir1, selectors: [['', 'my-dir-1', '']]});
static ɵdir = ɵɵdefineDirective({type: MyDir1, selectors: [['', 'my-dir-1', '']]});
}
class MyDir2 {
static ngFactoryDef = () => myDir2Instance = new MyDir2();
static ngDirectiveDef =
ɵɵdefineDirective({type: MyDir2, selectors: [['', 'my-dir-2', '']]});
static ɵdir = ɵɵdefineDirective({type: MyDir2, selectors: [['', 'my-dir-2', '']]});
}
class ChildComp {
@ -1114,7 +1109,7 @@ describe('sanitization', () => {
cite: any = 'http://cite-dir-value';
static ngFactoryDef = () => hostBindingDir = new UnsafeUrlHostBindingDir();
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: UnsafeUrlHostBindingDir,
selectors: [['', 'unsafeUrlHostBindingDir', '']],
hostBindings: (rf: RenderFlags, ctx: any) => {

View File

@ -281,8 +281,8 @@ ivyEnabled && describe('render3 jit', () => {
}
const InputDirAny = InputDir as any;
expect(InputDirAny.ngDirectiveDef.inputs).toEqual({publicName: 'privateName'});
expect(InputDirAny.ngDirectiveDef.declaredInputs).toEqual({publicName: 'privateName'});
expect(InputDirAny.ɵdir.inputs).toEqual({publicName: 'privateName'});
expect(InputDirAny.ɵdir.declaredInputs).toEqual({publicName: 'privateName'});
});
it('should compile ContentChildren query with string predicate on a directive', () => {
@ -291,7 +291,7 @@ ivyEnabled && describe('render3 jit', () => {
@ContentChildren('foo') foos: QueryList<ElementRef>|undefined;
}
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
expect((TestDirective as any).ɵdir.contentQueries).not.toBeNull();
});
it('should compile ContentChild query with string predicate on a directive', () => {
@ -300,7 +300,7 @@ ivyEnabled && describe('render3 jit', () => {
@ContentChild('foo', {static: false}) foo: ElementRef|undefined;
}
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
expect((TestDirective as any).ɵdir.contentQueries).not.toBeNull();
});
it('should compile ContentChildren query with type predicate on a directive', () => {
@ -311,7 +311,7 @@ ivyEnabled && describe('render3 jit', () => {
@ContentChildren(SomeDir) dirs: QueryList<SomeDir>|undefined;
}
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
expect((TestDirective as any).ɵdir.contentQueries).not.toBeNull();
});
it('should compile ContentChild query with type predicate on a directive', () => {
@ -322,7 +322,7 @@ ivyEnabled && describe('render3 jit', () => {
@ContentChild(SomeDir, {static: false}) dir: SomeDir|undefined;
}
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
expect((TestDirective as any).ɵdir.contentQueries).not.toBeNull();
});
it('should compile ViewChild query on a component', () => {

View File

@ -71,7 +71,7 @@ describe('lifecycles', () => {
ngOnInit() { events.push('dir'); }
static ngFactoryDef = () => new Directive();
static ngDirectiveDef = ɵɵdefineDirective({type: Directive, selectors: [['', 'dir', '']]});
static ɵdir = ɵɵdefineDirective({type: Directive, selectors: [['', 'dir', '']]});
}
const directives = [Comp, Parent, ProjectedComp, Directive, NgIf];

View File

@ -101,7 +101,7 @@ describe('event listeners', () => {
static ngFactoryDef = function HostListenerDir_Factory() {
return new GlobalHostListenerDir();
};
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: GlobalHostListenerDir,
selectors: [['', 'hostListenerDir', '']],
hostBindings: function HostListenerDir_HostBindings(
@ -581,7 +581,7 @@ describe('event listeners', () => {
onClick() { events.push('click!'); }
static ngFactoryDef = function HostListenerDir_Factory() { return new HostListenerDir(); };
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: HostListenerDir,
selectors: [['', 'hostListenerDir', '']],
hostBindings: function HostListenerDir_HostBindings(

View File

@ -38,7 +38,7 @@ describe('outputs', () => {
changeStream = new EventEmitter();
static ngFactoryDef = () => otherDir = new OtherDir;
static ngDirectiveDef = ɵɵdefineDirective(
static ɵdir = ɵɵdefineDirective(
{type: OtherDir, selectors: [['', 'otherDir', '']], outputs: {changeStream: 'change'}});
}

View File

@ -1459,7 +1459,7 @@ function expectProvidersScenario(defs: {
class ViewChildDirective {
static ngFactoryDef = () => testDirectiveInjection(defs.viewChild, new ViewChildDirective());
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: ViewChildDirective,
selectors: [['view-child']],
features: defs.viewChild && [ɵɵProvidersFeature(defs.viewChild.directiveProviders || [])],
@ -1490,7 +1490,7 @@ function expectProvidersScenario(defs: {
static ngFactoryDef =
() => { return testDirectiveInjection(defs.contentChild, new ContentChildDirective()); }
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: ContentChildDirective,
selectors: [['content-child']],
features:
@ -1519,7 +1519,7 @@ function expectProvidersScenario(defs: {
class ParentDirective {
static ngFactoryDef = () => testDirectiveInjection(defs.parent, new ParentDirective());
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: ParentDirective,
selectors: [['parent']],
features: defs.parent && [ɵɵProvidersFeature(defs.parent.directiveProviders || [])],
@ -1528,7 +1528,7 @@ function expectProvidersScenario(defs: {
class ParentDirective2 {
static ngFactoryDef = () => testDirectiveInjection(defs.parent, new ParentDirective2());
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: ParentDirective2,
selectors: [['parent']],
features: defs.parent && [ɵɵProvidersFeature(defs.parent.directive2Providers || [])],

View File

@ -223,7 +223,7 @@ describe('query', () => {
static ngFactoryDef = function MyDirective_Factory() {
return directive = new MyDirective(ɵɵdirectiveInject(Service));
};
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: MyDirective,
selectors: [['', 'myDir', '']],
features: [ɵɵProvidersFeature([Service, {provide: Alias, useExisting: Service}])],
@ -1423,7 +1423,7 @@ describe('query', () => {
static ngFactoryDef = () => new SomeDir(
ɵɵdirectiveInject(ViewContainerRef as any), ɵɵdirectiveInject(TemplateRef as any))
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: SomeDir,
selectors: [['', 'someDir', '']],
});
@ -1482,7 +1482,7 @@ describe('query', () => {
}
static ngFactoryDef = () => withContentInstance = new WithContentDirective();
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: WithContentDirective,
selectors: [['', 'with-content', '']],
contentQueries: (rf: RenderFlags, ctx: any, dirIndex: number) => {
@ -1680,7 +1680,7 @@ describe('query', () => {
class QueryDirective {
fooBars: any;
static ngFactoryDef = () => new QueryDirective();
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: QueryDirective,
selectors: [['', 'query', '']],
exportAs: ['query'],
@ -1746,7 +1746,7 @@ describe('query', () => {
class QueryDirective {
fooBars: any;
static ngFactoryDef = () => new QueryDirective();
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: QueryDirective,
selectors: [['', 'query', '']],
exportAs: ['query'],
@ -1803,7 +1803,7 @@ describe('query', () => {
class QueryDirective {
fooBars: any;
static ngFactoryDef = () => new QueryDirective();
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: QueryDirective,
selectors: [['', 'query', '']],
exportAs: ['query'],
@ -1864,7 +1864,7 @@ describe('query', () => {
class ShallowQueryDirective {
foos: any;
static ngFactoryDef = () => new ShallowQueryDirective();
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: ShallowQueryDirective,
selectors: [['', 'shallow-query', '']],
exportAs: ['shallow-query'],
@ -1885,7 +1885,7 @@ describe('query', () => {
class DeepQueryDirective {
foos: any;
static ngFactoryDef = () => new DeepQueryDirective();
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: DeepQueryDirective,
selectors: [['', 'deep-query', '']],
exportAs: ['deep-query'],
@ -1947,7 +1947,7 @@ describe('query', () => {
value !: string;
static ngFactoryDef = () => new TextDirective();
static ngDirectiveDef = ɵɵdefineDirective(
static ɵdir = ɵɵdefineDirective(
{type: TextDirective, selectors: [['', 'text', '']], inputs: {value: 'text'}});
}

View File

@ -395,7 +395,7 @@ export function createDirective(
name: string, {exportAs}: {exportAs?: string[]} = {}): DirectiveType<any> {
return class Directive {
static ngFactoryDef = () => new Directive();
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: Directive,
selectors: [['', name, '']],
exportAs: exportAs,

View File

@ -32,7 +32,7 @@ describe('ViewContainerRef', () => {
static ngFactoryDef = () => directiveInstance = new DirectiveWithVCRef(
ɵɵdirectiveInject(ViewContainerRef as any), injectComponentFactoryResolver())
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: DirectiveWithVCRef,
selectors: [['', 'vcref', '']],
inputs: {tplRef: 'tplRef', name: 'name'}
@ -68,7 +68,7 @@ describe('ViewContainerRef', () => {
return instance;
}
static ngDirectiveDef = ɵɵdefineDirective({
static ɵdir = ɵɵdefineDirective({
type: TestDirective,
selectors: [['', 'testdir', '']],
});
@ -140,7 +140,7 @@ describe('ViewContainerRef', () => {
static ngFactoryDef = () => directiveInstance = new TestDirective(
ɵɵdirectiveInject(ViewContainerRef as any), ɵɵdirectiveInject(TemplateRef as any))
static ngDirectiveDef =
static ɵdir =
ɵɵdefineDirective({type: TestDirective, selectors: [['', 'testdir', '']]});
constructor(private _vcRef: ViewContainerRef, private _tplRef: TemplateRef<{}>) {}

View File

@ -657,8 +657,8 @@ describe('TestBed', () => {
expect(ComponentWithNoAnnotations.hasOwnProperty('ɵcmp')).toBeTruthy();
expect(SomeComponent.hasOwnProperty('ɵcmp')).toBeTruthy();
expect(DirectiveWithNoAnnotations.hasOwnProperty('ngDirectiveDef')).toBeTruthy();
expect(SomeDirective.hasOwnProperty('ngDirectiveDef')).toBeTruthy();
expect(DirectiveWithNoAnnotations.hasOwnProperty('ɵdir')).toBeTruthy();
expect(SomeDirective.hasOwnProperty('ɵdir')).toBeTruthy();
expect(PipeWithNoAnnotations.hasOwnProperty('ngPipeDef')).toBeTruthy();
expect(SomePipe.hasOwnProperty('ngPipeDef')).toBeTruthy();
@ -667,12 +667,12 @@ describe('TestBed', () => {
// ng defs should be removed from classes with no annotations
expect(ComponentWithNoAnnotations.hasOwnProperty('ɵcmp')).toBeFalsy();
expect(DirectiveWithNoAnnotations.hasOwnProperty('ngDirectiveDef')).toBeFalsy();
expect(DirectiveWithNoAnnotations.hasOwnProperty('ɵdir')).toBeFalsy();
expect(PipeWithNoAnnotations.hasOwnProperty('ngPipeDef')).toBeFalsy();
// ng defs should be preserved on super types
expect(SomeComponent.hasOwnProperty('ɵcmp')).toBeTruthy();
expect(SomeDirective.hasOwnProperty('ngDirectiveDef')).toBeTruthy();
expect(SomeDirective.hasOwnProperty('ɵdir')).toBeTruthy();
expect(SomePipe.hasOwnProperty('ngPipeDef')).toBeTruthy();
});

View File

@ -7,7 +7,7 @@
*/
import {ResourceLoader} from '@angular/compiler';
import {ApplicationInitStatus, COMPILER_OPTIONS, Compiler, Component, Directive, Injector, LOCALE_ID, ModuleWithComponentFactories, ModuleWithProviders, NgModule, NgModuleFactory, NgZone, Pipe, PlatformRef, Provider, Type, ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID, ɵDirectiveDef as DirectiveDef, ɵNG_COMP_DEF as NG_COMP_DEF, ɵNG_DIRECTIVE_DEF as NG_DIRECTIVE_DEF, ɵNG_INJECTOR_DEF as NG_INJECTOR_DEF, ɵNG_MODULE_DEF as NG_MODULE_DEF, ɵNG_PIPE_DEF as NG_PIPE_DEF, ɵNgModuleFactory as R3NgModuleFactory, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵNgModuleType as NgModuleType, ɵRender3ComponentFactory as ComponentFactory, ɵRender3NgModuleRef as NgModuleRef, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵgetInjectableDef as getInjectableDef, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵsetLocaleId as setLocaleId, ɵtransitiveScopesFor as transitiveScopesFor, ɵɵInjectableDef as InjectableDef} from '@angular/core';
import {ApplicationInitStatus, COMPILER_OPTIONS, Compiler, Component, Directive, Injector, LOCALE_ID, ModuleWithComponentFactories, ModuleWithProviders, NgModule, NgModuleFactory, NgZone, Pipe, PlatformRef, Provider, Type, ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID, ɵDirectiveDef as DirectiveDef, ɵNG_COMP_DEF as NG_COMP_DEF, ɵNG_DIR_DEF as NG_DIR_DEF, ɵNG_INJECTOR_DEF as NG_INJECTOR_DEF, ɵNG_MODULE_DEF as NG_MODULE_DEF, ɵNG_PIPE_DEF as NG_PIPE_DEF, ɵNgModuleFactory as R3NgModuleFactory, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵNgModuleType as NgModuleType, ɵRender3ComponentFactory as ComponentFactory, ɵRender3NgModuleRef as NgModuleRef, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵgetInjectableDef as getInjectableDef, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵsetLocaleId as setLocaleId, ɵtransitiveScopesFor as transitiveScopesFor, ɵɵInjectableDef as InjectableDef} from '@angular/core';
import {ModuleRegistrationMap, getRegisteredModulesState, restoreRegisteredModulesState} from '../../src/linker/ng_module_factory_registration';
import {clearResolutionOfComponentResourcesQueue, isComponentDefPendingResolution, resolveComponentResources, restoreComponentResolutionQueue} from '../../src/metadata/resource_loading';
@ -305,7 +305,7 @@ export class R3TestBedCompiler {
this.pendingDirectives.forEach(declaration => {
const metadata = this.resolvers.directive.resolve(declaration);
this.maybeStoreNgDef(NG_DIRECTIVE_DEF, declaration);
this.maybeStoreNgDef(NG_DIR_DEF, declaration);
compileDirective(declaration, metadata);
});
this.pendingDirectives.clear();
@ -350,7 +350,7 @@ export class R3TestBedCompiler {
}
};
this.seenComponents.forEach(maybeApplyOverrides(NG_COMP_DEF));
this.seenDirectives.forEach(maybeApplyOverrides(NG_DIRECTIVE_DEF));
this.seenDirectives.forEach(maybeApplyOverrides(NG_DIR_DEF));
this.seenComponents.clear();
this.seenDirectives.clear();
@ -450,7 +450,7 @@ export class R3TestBedCompiler {
const directive = this.resolvers.directive.resolve(type);
if (directive) {
if (!type.hasOwnProperty(NG_DIRECTIVE_DEF)) {
if (!type.hasOwnProperty(NG_DIR_DEF)) {
this.pendingDirectives.add(type);
}
this.seenDirectives.add(type);

View File

@ -224,8 +224,8 @@ export declare class NgClassBase {
getValue(): {
[key: string]: any;
} | null;
static ngDirectiveDef: any;
static ngFactoryDef: any;
static ɵdir: any;
}
export declare class NgComponentOutlet implements OnChanges, OnDestroy {
@ -309,8 +309,8 @@ export declare class NgStyleBase {
getValue(): {
[key: string]: any;
} | null;
static ngDirectiveDef: any;
static ngFactory: any;
static ɵdir: any;
}
export declare class NgSwitch {