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

@ -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 {