refactor(core): rename ngComponentDef to ɵcmp (#33088)

Component 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
`ngComponentDef` to `cmp`. 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" (ngDirectiveDef, 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 #33088
This commit is contained in:
Kara Erickson
2019-10-10 14:57:15 -07:00
committed by Miško Hevery
parent d4d07233dc
commit 64fd0d6db9
61 changed files with 306 additions and 312 deletions

View File

@ -66,7 +66,7 @@
"name": "NEXT"
},
{
"name": "NG_COMPONENT_DEF"
"name": "NG_COMP_DEF"
},
{
"name": "NG_DIRECTIVE_DEF"

View File

@ -60,7 +60,7 @@
"name": "NEXT"
},
{
"name": "NG_COMPONENT_DEF"
"name": "NG_COMP_DEF"
},
{
"name": "NG_DIRECTIVE_DEF"

View File

@ -123,7 +123,7 @@
"name": "NEXT"
},
{
"name": "NG_COMPONENT_DEF"
"name": "NG_COMP_DEF"
},
{
"name": "NG_DIRECTIVE_DEF"

View File

@ -125,7 +125,7 @@ function declareTests(config?: {useJit: boolean}) {
}
function createComp<T>(compType: Type<T>, moduleType: Type<any>): ComponentFixture<T> {
const componentDef = (compType as any).ngComponentDef;
const componentDef = (compType as any).ɵcmp;
if (componentDef) {
// Since we avoid Components/Directives/Pipes recompiling in case there are no overrides, we
// may face a problem where previously compiled defs available to a given

View File

@ -18,7 +18,7 @@ describe('resource_loading', () => {
it('should throw an error when compiling component that has unresolved templateUrl', () => {
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
compileComponent(MyComponent, {templateUrl: 'someUrl'});
expect(() => MyComponent.ngComponentDef).toThrowError(`
expect(() => MyComponent.ɵcmp).toThrowError(`
Component 'MyComponent' is not resolved:
- templateUrl: someUrl
Did you run and wait for 'resolveComponentResources()'?`.trim());
@ -27,7 +27,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
it('should throw an error when compiling component that has unresolved styleUrls', () => {
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
compileComponent(MyComponent, {styleUrls: ['someUrl1', 'someUrl2']});
expect(() => MyComponent.ngComponentDef).toThrowError(`
expect(() => MyComponent.ɵcmp).toThrowError(`
Component 'MyComponent' is not resolved:
- styleUrls: ["someUrl1","someUrl2"]
Did you run and wait for 'resolveComponentResources()'?`.trim());
@ -38,7 +38,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
compileComponent(
MyComponent, {templateUrl: 'someUrl', styleUrls: ['someUrl1', 'someUrl2']});
expect(() => MyComponent.ngComponentDef).toThrowError(`
expect(() => MyComponent.ɵcmp).toThrowError(`
Component 'MyComponent' is not resolved:
- templateUrl: someUrl
- styleUrls: ["someUrl1","someUrl2"]
@ -64,7 +64,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
const metadata: Component = {templateUrl: 'test://content'};
compileComponent(MyComponent, metadata);
await resolveComponentResources(testResolver);
expect(MyComponent.ngComponentDef).toBeDefined();
expect(MyComponent.ɵcmp).toBeDefined();
expect(metadata.template).toBe('content');
expect(resourceFetchCount).toBe(1);
});
@ -74,7 +74,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
const metadata: Component = {template: '', styleUrls: ['test://style1', 'test://style2']};
compileComponent(MyComponent, metadata);
await resolveComponentResources(testResolver);
expect(MyComponent.ngComponentDef).toBeDefined();
expect(MyComponent.ɵcmp).toBeDefined();
expect(metadata.styleUrls).toBe(undefined);
expect(metadata.styles).toEqual(['style1', 'style2']);
expect(resourceFetchCount).toBe(2);
@ -85,7 +85,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
const metadata: Component = {template: '', styleUrls: ['test://style1', 'test://style1']};
compileComponent(MyComponent, metadata);
await resolveComponentResources(testResolver);
expect(MyComponent.ngComponentDef).toBeDefined();
expect(MyComponent.ɵcmp).toBeDefined();
expect(metadata.styleUrls).toBe(undefined);
expect(metadata.styles).toEqual(['style1', 'style1']);
expect(resourceFetchCount).toBe(1);
@ -136,7 +136,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
const metadata: Component = {templateUrl: 'test://content'};
compileComponent(MyComponent, metadata);
await resolveComponentResources(fetch);
expect(MyComponent.ngComponentDef).toBeDefined();
expect(MyComponent.ɵcmp).toBeDefined();
expect(metadata.template).toBe('response for test://content');
});
});

View File

@ -34,7 +34,7 @@ describe('iv perf test', () => {
it(`${iteration}. create ${count} divs in Render3`, () => {
class Component {
static ngFactoryDef = () => new Component;
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Component,
selectors: [['div']],
decls: 1,

View File

@ -26,7 +26,7 @@ describe('change detection', () => {
ngDoCheck(): void { this.doCheckCount++; }
static ngFactoryDef = () => new MyComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComponent,
selectors: [['my-comp']],
decls: 2,
@ -102,7 +102,7 @@ describe('change detection', () => {
onClick() {}
static ngFactoryDef = () => comp = new MyComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComponent,
selectors: [['my-comp']],
decls: 2,
@ -140,7 +140,7 @@ describe('change detection', () => {
onClick() {}
static ngFactoryDef = () => comp = new ManualComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ManualComponent,
selectors: [['manual-comp']],
decls: 2,
@ -176,7 +176,7 @@ describe('change detection', () => {
name: string = 'Nancy';
static ngFactoryDef = () => new ManualApp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ManualApp,
selectors: [['manual-app']],
decls: 1,
@ -231,7 +231,7 @@ describe('change detection', () => {
ngDoCheck(): void { this.doCheckCount++; }
static ngFactoryDef = () => parent = new ButtonParent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ButtonParent,
selectors: [['button-parent']],
decls: 2,
@ -308,7 +308,7 @@ describe('change detection', () => {
}
static ngFactoryDef = () => new MyComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComponent,
selectors: [['my-comp']],
decls: 1,

View File

@ -21,7 +21,7 @@ describe('ComponentFactory', () => {
it('should correctly populate default properties', () => {
class TestComponent {
static ngFactoryDef = () => new TestComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: TestComponent,
selectors: [['test', 'foo'], ['bar']],
decls: 0,
@ -42,7 +42,7 @@ describe('ComponentFactory', () => {
it('should correctly populate defined properties', () => {
class TestComponent {
static ngFactoryDef = () => new TestComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: TestComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['test', 'foo'], ['bar']],
@ -90,7 +90,7 @@ describe('ComponentFactory', () => {
class TestComponent {
static ngFactoryDef = () => new TestComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: TestComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['test']],

View File

@ -22,7 +22,7 @@ describe('component', () => {
increment() { this.count++; }
static ngFactoryDef = () => new CounterComponent;
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: CounterComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['counter']],
@ -72,7 +72,7 @@ describe('component', () => {
class MyComponent {
constructor(public myService: MyService) {}
static ngFactoryDef = () => new MyComponent(ɵɵdirectiveInject(MyService));
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['my-component']],
@ -116,7 +116,7 @@ describe('component', () => {
name = '';
static ngFactoryDef = () => new Comp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Comp,
selectors: [['comp']],
decls: 1,
@ -175,7 +175,7 @@ it('should not invoke renderer destroy method for embedded views', () => {
return comp;
}
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Comp,
selectors: [['comp']],
decls: 3,
@ -248,7 +248,7 @@ describe('component with a container', () => {
// TODO(issue/24571): remove '!'.
items !: string[];
static ngFactoryDef = () => new WrapperComponent;
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: WrapperComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['wrapper']],
@ -325,7 +325,7 @@ describe('recursive components', () => {
ngOnDestroy() { events.push('destroy' + this.data.value); }
static ngFactoryDef = () => new TreeComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: TreeComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['tree-comp']],
@ -375,8 +375,7 @@ describe('recursive components', () => {
});
}
(TreeComponent.ngComponentDef as ComponentDef<TreeComponent>).directiveDefs =
() => [TreeComponent.ngComponentDef];
(TreeComponent.ɵcmp as ComponentDef<TreeComponent>).directiveDefs = () => [TreeComponent.ɵcmp];
/**
* {{ data.value }}
@ -391,7 +390,7 @@ describe('recursive components', () => {
ngOnDestroy() { events.push('destroy' + this.data.value); }
static ngFactoryDef = () => new NgIfTree();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: NgIfTree,
encapsulation: ViewEncapsulation.None,
selectors: [['ng-if-tree']],
@ -438,8 +437,8 @@ describe('recursive components', () => {
}
}
(NgIfTree.ngComponentDef as ComponentDef<NgIfTree>).directiveDefs =
() => [NgIfTree.ngComponentDef, NgIf.ngDirectiveDef];
(NgIfTree.ɵcmp as ComponentDef<NgIfTree>).directiveDefs =
() => [NgIfTree.ɵcmp, NgIf.ngDirectiveDef];
function _buildTree(currDepth: number): TreeNode {
const children = currDepth < 2 ? _buildTree(currDepth + 1) : null;
@ -533,7 +532,7 @@ describe('recursive components', () => {
// TODO(issue/24571): remove '!'.
minifiedName !: string;
static ngFactoryDef = () => new TestInputsComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: TestInputsComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['test-inputs']],
@ -546,7 +545,7 @@ describe('recursive components', () => {
});
}
const testInputsComponentFactory = new ComponentFactory(TestInputsComponent.ngComponentDef);
const testInputsComponentFactory = new ComponentFactory(TestInputsComponent.ɵcmp);
expect([
{propName: 'minifiedName', templateName: 'unminifiedName'}

View File

@ -699,7 +699,7 @@ describe('JS control flow', () => {
return new Comp();
}
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Comp,
selectors: [['comp']],
decls: 0,
@ -713,7 +713,7 @@ describe('JS control flow', () => {
condition2 = true;
static ngFactoryDef = () => new App();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: App,
selectors: [['app']],
decls: 3,
@ -769,7 +769,7 @@ describe('JS control flow', () => {
return new Comp();
}
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Comp,
selectors: [['comp']],
decls: 0,
@ -783,7 +783,7 @@ describe('JS control flow', () => {
condition2 = true;
static ngFactoryDef = () => new App();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: App,
selectors: [['app']],
decls: 3,

View File

@ -118,7 +118,7 @@ describe('di', () => {
constructor(public renderer: Renderer2) {}
static ngFactoryDef = () => new MyComp(ɵɵdirectiveInject(Renderer2 as any));
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComp,
selectors: [['my-comp']],
decls: 1,

View File

@ -241,7 +241,7 @@ describe('instructions', () => {
rows = [['a', 'b'], ['A', 'B'], ['a', 'b'], ['A', 'B']];
static ngFactoryDef = function ToDoAppComponent_Factory() { return new NestedLoops(); };
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: NestedLoops,
selectors: [['nested-loops']],
decls: 1,

View File

@ -118,7 +118,7 @@ describe('render3 integration test', () => {
afterTree !: Tree;
static ngFactoryDef = () => new ChildComponent;
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
selectors: [['child']],
type: ChildComponent,
decls: 3,
@ -200,7 +200,7 @@ describe('component styles', () => {
it('should pass in the component styles directly into the underlying renderer', () => {
class StyledComp {
static ngFactoryDef = () => new StyledComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StyledComp,
styles: ['div { color: red; }'],
decls: 1,
@ -228,7 +228,7 @@ describe('component animations', () => {
class AnimComp {
static ngFactoryDef = () => new AnimComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AnimComp,
decls: 0,
vars: 0,
@ -255,7 +255,7 @@ describe('component animations', () => {
it('should include animations in the renderType data array even if the array is empty', () => {
class AnimComp {
static ngFactoryDef = () => new AnimComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AnimComp,
decls: 0,
vars: 0,
@ -275,7 +275,7 @@ describe('component animations', () => {
it('should allow [@trigger] bindings to be picked up by the underlying renderer', () => {
class AnimComp {
static ngFactoryDef = () => new AnimComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AnimComp,
decls: 1,
vars: 1,
@ -312,7 +312,7 @@ describe('component animations', () => {
() => {
class AnimComp {
static ngFactoryDef = () => new AnimComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AnimComp,
decls: 1,
vars: 1,
@ -361,7 +361,7 @@ describe('component animations', () => {
// class ParentComp {
// static ngFactoryDef = () => new ParentComp();
// static ngComponentDef = ɵɵdefineComponent({
// static ɵcmp = ɵɵdefineComponent({
// type: ParentComp,
// decls: 1,
// vars: 1,
@ -391,7 +391,7 @@ describe('element discovery', () => {
it('should only monkey-patch immediate child nodes in a component', () => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
decls: 2,
@ -423,7 +423,7 @@ describe('element discovery', () => {
it('should only monkey-patch immediate child nodes in a sub component', () => {
class ChildComp {
static ngFactoryDef = () => new ChildComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ChildComp,
selectors: [['child-comp']],
decls: 3,
@ -440,7 +440,7 @@ describe('element discovery', () => {
class ParentComp {
static ngFactoryDef = () => new ParentComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ParentComp,
selectors: [['parent-comp']],
directives: [ChildComp],
@ -473,7 +473,7 @@ describe('element discovery', () => {
it('should only monkey-patch immediate child nodes in an embedded template container', () => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
directives: [NgIf],
@ -523,7 +523,7 @@ describe('element discovery', () => {
it('should return a context object from a given dom node', () => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
directives: [NgIf],
@ -561,7 +561,7 @@ describe('element discovery', () => {
it('should cache the element context on a element was pre-emptively monkey-patched', () => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
decls: 1,
@ -593,7 +593,7 @@ describe('element discovery', () => {
() => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
decls: 2,
@ -626,7 +626,7 @@ describe('element discovery', () => {
() => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
decls: 1,
@ -674,7 +674,7 @@ describe('element discovery', () => {
*/
class ProjectorComp {
static ngFactoryDef = () => new ProjectorComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ProjectorComp,
selectors: [['projector-comp']],
decls: 4,
@ -697,7 +697,7 @@ describe('element discovery', () => {
class ParentComp {
static ngFactoryDef = () => new ParentComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ParentComp,
selectors: [['parent-comp']],
directives: [ProjectorComp],
@ -771,7 +771,7 @@ describe('element discovery', () => {
() => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
decls: 1,
@ -798,7 +798,7 @@ describe('element discovery', () => {
it('should by default monkey-patch the bootstrap component with context details', () => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
decls: 0,
@ -855,7 +855,7 @@ describe('element discovery', () => {
class StructuredComp {
static ngFactoryDef = () => new StructuredComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: StructuredComp,
selectors: [['structured-comp']],
directives: [MyDir1, MyDir2, MyDir3],
@ -933,7 +933,7 @@ describe('element discovery', () => {
class ChildComp {
static ngFactoryDef = () => childComponentInstance = new ChildComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ChildComp,
selectors: [['child-comp']],
decls: 1,
@ -948,7 +948,7 @@ describe('element discovery', () => {
class ParentComp {
static ngFactoryDef = () => new ParentComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ParentComp,
selectors: [['parent-comp']],
directives: [ChildComp, MyDir1, MyDir2],
@ -1011,7 +1011,7 @@ describe('element discovery', () => {
() => {
class ChildComp {
static ngFactoryDef = () => new ChildComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ChildComp,
selectors: [['child-comp']],
decls: 3,
@ -1028,7 +1028,7 @@ describe('element discovery', () => {
class ParentComp {
static ngFactoryDef = () => new ParentComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ParentComp,
selectors: [['parent-comp']],
directives: [ChildComp],
@ -1072,7 +1072,7 @@ describe('sanitization', () => {
it('should sanitize data using the provided sanitization interface', () => {
class SanitizationComp {
static ngFactoryDef = () => new SanitizationComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: SanitizationComp,
selectors: [['sanitize-this']],
decls: 1,
@ -1130,7 +1130,7 @@ describe('sanitization', () => {
class SimpleComp {
static ngFactoryDef = () => new SimpleComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: SimpleComp,
selectors: [['sanitize-this']],
decls: 1,

View File

@ -33,7 +33,7 @@ ivyEnabled && describe('render3 jit', () => {
}
const SomeCmpAny = SomeCmp as any;
expect(SomeCmpAny.ngComponentDef).toBeDefined();
expect(SomeCmpAny.ɵcmp).toBeDefined();
expect(SomeCmpAny.ngFactoryDef() instanceof SomeCmp).toBe(true);
});
@ -198,7 +198,7 @@ ivyEnabled && describe('render3 jit', () => {
})
class Cmp {
}
const cmpDef: ComponentDef<Cmp> = (Cmp as any).ngComponentDef;
const cmpDef: ComponentDef<Cmp> = (Cmp as any).ɵcmp;
expect(cmpDef.directiveDefs).toBeNull();
@ -230,7 +230,7 @@ ivyEnabled && describe('render3 jit', () => {
onChange(event: any): void {}
}
const cmpDef = (Cmp as any).ngComponentDef as ComponentDef<Cmp>;
const cmpDef = (Cmp as any).ɵcmp as ComponentDef<Cmp>;
expect(cmpDef.hostBindings).toBeDefined();
expect(cmpDef.hostBindings !.length).toBe(3);
@ -268,8 +268,8 @@ ivyEnabled && describe('render3 jit', () => {
}
const InputCompAny = InputComp as any;
expect(InputCompAny.ngComponentDef.inputs).toEqual({publicName: 'privateName'});
expect(InputCompAny.ngComponentDef.declaredInputs).toEqual({publicName: 'privateName'});
expect(InputCompAny.ɵcmp.inputs).toEqual({publicName: 'privateName'});
expect(InputCompAny.ɵcmp.declaredInputs).toEqual({publicName: 'privateName'});
});
it('should add @Input properties to a directive', () => {
@ -331,7 +331,7 @@ ivyEnabled && describe('render3 jit', () => {
@ViewChild('foo', {static: false}) foo: ElementRef|undefined;
}
expect((TestComponent as any).ngComponentDef.foo).not.toBeNull();
expect((TestComponent as any).ɵcmp.foo).not.toBeNull();
});
it('should compile ViewChildren query on a component', () => {
@ -340,7 +340,7 @@ ivyEnabled && describe('render3 jit', () => {
@ViewChildren('foo') foos: QueryList<ElementRef>|undefined;
}
expect((TestComponent as any).ngComponentDef.viewQuery).not.toBeNull();
expect((TestComponent as any).ɵcmp.viewQuery).not.toBeNull();
});
});

View File

@ -56,7 +56,7 @@ describe('lifecycles', () => {
}
static ngFactoryDef = () => new Component();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Component,
selectors: [[name]],
decls: decls,

View File

@ -34,7 +34,7 @@ describe('event listeners', () => {
return comp;
}
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComp,
selectors: [['comp']],
decls: 2,
@ -67,7 +67,7 @@ describe('event listeners', () => {
return comp;
}
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyCompWithGlobalListeners,
selectors: [['comp']],
decls: 1,
@ -135,7 +135,7 @@ describe('event listeners', () => {
}
static ngFactoryDef = () => new PreventDefaultComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: PreventDefaultComp,
selectors: [['prevent-default-comp']],
decls: 2,
@ -326,7 +326,7 @@ describe('event listeners', () => {
onClick() { this.counter++; }
static ngFactoryDef = () => new AppComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AppComp,
selectors: [['app-comp']],
decls: 1,
@ -387,7 +387,7 @@ describe('event listeners', () => {
onClick(index: number) { this.counters[index]++; }
static ngFactoryDef = () => new AppComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AppComp,
selectors: [['app-comp']],
decls: 1,
@ -451,7 +451,7 @@ describe('event listeners', () => {
onClick(index: number) { this.counters[index]++; }
static ngFactoryDef = () => new AppComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AppComp,
selectors: [['app-comp']],
decls: 1,
@ -530,7 +530,7 @@ describe('event listeners', () => {
onClick() { events.push('click!'); }
static ngFactoryDef = () => { return new MyComp(); };
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComp,
selectors: [['comp']],
decls: 1,
@ -633,7 +633,7 @@ describe('event listeners', () => {
onClick(a: any, b: any) { this.counter += a + b; }
static ngFactoryDef = () => new MyComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComp,
selectors: [['comp']],
decls: 2,
@ -914,7 +914,7 @@ describe('event listeners', () => {
onClick(comp: any) { this.comp = comp; }
static ngFactoryDef = () => new App();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: App,
selectors: [['app']],
decls: 3,

View File

@ -22,7 +22,7 @@ describe('outputs', () => {
resetStream = new EventEmitter();
static ngFactoryDef = () => buttonToggle = new ButtonToggle();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ButtonToggle,
selectors: [['button-toggle']],
template: function(rf: RenderFlags, ctx: any) {},

View File

@ -423,7 +423,7 @@ describe('providers', () => {
});
});
describe('with directives (order in ngComponentDef.directives matters)', () => {
describe('with directives (order in ɵcmp.directives matters)', () => {
it('should work without providers nor viewProviders in component', () => {
expectProvidersScenario({
parent: {
@ -647,7 +647,7 @@ describe('providers', () => {
});
});
describe('with directives (order in ngComponentDef.directives matters)', () => {
describe('with directives (order in ɵcmp.directives matters)', () => {
it('should work without providers nor viewProviders in component', () => {
expectProvidersScenario({
parent: {
@ -870,7 +870,7 @@ describe('providers', () => {
static ngFactoryDef =
() => { return new Repeated(ɵɵdirectiveInject(String), ɵɵdirectiveInject(Number)); }
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Repeated,
selectors: [['repeated']],
decls: 2,
@ -901,7 +901,7 @@ describe('providers', () => {
})
class ComponentWithProviders {
static ngFactoryDef = () => new ComponentWithProviders();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ComponentWithProviders,
selectors: [['component-with-providers']],
decls: 2,
@ -956,7 +956,7 @@ describe('providers', () => {
static ngFactoryDef =
() => { return new Repeated(ɵɵdirectiveInject(String), ɵɵdirectiveInject(Number)); }
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Repeated,
selectors: [['repeated']],
decls: 2,
@ -990,7 +990,7 @@ describe('providers', () => {
})
class ComponentWithProviders {
static ngFactoryDef = () => new ComponentWithProviders();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ComponentWithProviders,
selectors: [['component-with-providers']],
decls: 2,
@ -1039,7 +1039,7 @@ describe('providers', () => {
constructor(private s: String) {}
static ngFactoryDef = () => new EmbeddedComponent(ɵɵdirectiveInject(String));
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: EmbeddedComponent,
selectors: [['embedded-cmp']],
decls: 1,
@ -1062,7 +1062,7 @@ describe('providers', () => {
static ngFactoryDef = () => hostComponent = new HostComponent(
ɵɵdirectiveInject(ViewContainerRef as any), injectComponentFactoryResolver())
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: HostComponent,
selectors: [['host-cmp']],
decls: 1,
@ -1086,7 +1086,7 @@ describe('providers', () => {
constructor() {}
static ngFactoryDef = () => new AppComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AppComponent,
selectors: [['app-cmp']],
decls: 1,
@ -1248,7 +1248,7 @@ describe('providers', () => {
constructor() {}
static ngFactoryDef = () => new MyComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComponent,
selectors: [['my-cmp']],
decls: 1,
@ -1275,7 +1275,7 @@ describe('providers', () => {
constructor() {}
static ngFactoryDef = () => new AppComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AppComponent,
selectors: [['app-cmp']],
decls: 1,
@ -1340,7 +1340,7 @@ describe('providers', () => {
static ngFactoryDef =
() => { return new MyComponent(ɵɵdirectiveInject(InjectableWithLifeCycleHooks)); }
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: MyComponent,
selectors: [['my-comp']],
decls: 1,
@ -1367,7 +1367,7 @@ describe('providers', () => {
public condition = true;
static ngFactoryDef = () => new App();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: App,
selectors: [['app-cmp']],
decls: 2,
@ -1442,7 +1442,7 @@ function expectProvidersScenario(defs: {
class ViewChildComponent {
static ngFactoryDef = () => testComponentInjection(defs.viewChild, new ViewChildComponent());
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ViewChildComponent,
selectors: [['view-child']],
decls: 1,
@ -1470,7 +1470,7 @@ function expectProvidersScenario(defs: {
static ngFactoryDef =
() => { return testComponentInjection(defs.contentChild, new ContentChildComponent()); }
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ContentChildComponent,
selectors: [['content-child']],
decls: 1,
@ -1501,7 +1501,7 @@ function expectProvidersScenario(defs: {
class ParentComponent {
static ngFactoryDef = () => testComponentInjection(defs.parent, new ParentComponent());
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ParentComponent,
selectors: [['parent']],
decls: 1,
@ -1538,7 +1538,7 @@ function expectProvidersScenario(defs: {
class App {
static ngFactoryDef = () => testComponentInjection(defs.app, new App());
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: App,
selectors: [['app']],
decls: 2,

View File

@ -20,7 +20,7 @@ describe('object literals', () => {
config !: {[key: string]: any};
static ngFactoryDef = function ObjectComp_Factory() { return objectComp = new ObjectComp(); };
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ObjectComp,
selectors: [['object-comp']],
decls: 0,

View File

@ -249,7 +249,7 @@ describe('query', () => {
alias?: Alias;
static ngFactoryDef = function App_Factory() { return new App(); };
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: App,
selectors: [['app']],
decls: 1,
@ -295,7 +295,7 @@ describe('query', () => {
service?: Service;
static ngFactoryDef = function App_Factory() { return new App(); };
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: App,
selectors: [['app']],
decls: 1,
@ -839,7 +839,7 @@ describe('query', () => {
class Child {
static ngFactoryDef = () => childInstance = new Child();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Child,
selectors: [['child']],
decls: 0,
@ -1959,7 +1959,7 @@ describe('query', () => {
texts !: QueryList<TextDirective>;
static ngFactoryDef = () => contentQueryDirective = new ContentQueryDirective();
static ngComponentDef = ɵɵdefineDirective({
static ɵcmp = ɵɵdefineDirective({
type: ContentQueryDirective,
selectors: [['', 'content-query', '']],
contentQueries: (rf: RenderFlags, ctx: any, dirIndex: number) => {
@ -2030,7 +2030,7 @@ describe('query', () => {
texts !: QueryList<TextDirective>;
static ngFactoryDef = () => new ViewQueryComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: ViewQueryComponent,
selectors: [['view-query']],
consts: [['text', 'A'], ['text', 'B'], ['text', 'C'], ['text', 'D'], ['text', 'E']],

View File

@ -375,7 +375,7 @@ export function createComponent(
return class Component {
value: any;
static ngFactoryDef = () => new Component;
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: Component,
selectors: [[name]],
decls: decls,

View File

@ -27,7 +27,7 @@ describe('renderer factory lifecycle', () => {
class SomeComponent {
static ngFactoryDef = () => new SomeComponent;
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: SomeComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['some-component']],
@ -47,7 +47,7 @@ describe('renderer factory lifecycle', () => {
class SomeComponentWhichThrows {
static ngFactoryDef = () => new SomeComponentWhichThrows;
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: SomeComponentWhichThrows,
encapsulation: ViewEncapsulation.None,
selectors: [['some-component-with-Error']],
@ -151,7 +151,7 @@ describe('Renderer2 destruction hooks', () => {
it('should call renderer.destroy for each component destroyed', () => {
class SimpleComponent {
static ngFactoryDef = () => new SimpleComponent;
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: SimpleComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['simple']],

View File

@ -102,7 +102,7 @@ describe('ViewContainerRef', () => {
// TODO(issue/24571): remove '!'.
testDir !: TestDirective;
static ngFactoryDef = () => new TestComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: TestComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['test-cmp']],
@ -174,7 +174,7 @@ describe('ViewContainerRef', () => {
// TODO(issue/24571): remove '!'.
testDir !: TestDirective;
static ngFactoryDef = () => new TestComponent();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: TestComponent,
encapsulation: ViewEncapsulation.None,
selectors: [['test-cmp']],
@ -247,7 +247,7 @@ describe('ViewContainerRef', () => {
ɵɵdirectiveInject(ViewContainerRef as any), injectComponentFactoryResolver());
}
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AppComp,
selectors: [['app-comp']],
decls: 0,
@ -263,7 +263,7 @@ describe('ViewContainerRef', () => {
static ngFactoryDef = () => dynamicComp = new DynamicComp();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: DynamicComp,
selectors: [['dynamic-comp']],
decls: 0,
@ -368,7 +368,7 @@ describe('ViewContainerRef', () => {
static ngFactoryDef = () =>
new AppCmpt(ɵɵdirectiveInject(ViewContainerRef as any), injectComponentFactoryResolver())
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: AppCmpt,
selectors: [['app']],
decls: 0,
@ -436,7 +436,7 @@ describe('ViewContainerRef', () => {
foo !: QueryList<any>;
static ngFactoryDef = () => dynamicComp = new DynamicCompWithViewQueries();
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: DynamicCompWithViewQueries,
selectors: [['dynamic-cmpt-with-view-queries']],
decls: 2,
@ -485,7 +485,7 @@ describe('ViewContainerRef', () => {
static ngFactoryDef = () =>
new CompWithListenerThatDestroysItself(ɵɵdirectiveInject(ChangeDetectorRef as any))
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: CompWithListenerThatDestroysItself,
selectors: [['comp-with-listener-and-on-destroy']],
decls: 2,

View File

@ -9,7 +9,7 @@
import {ɵɵComponentDefWithMeta, ɵɵPipeDefWithMeta as PipeDefWithMeta} from '@angular/core';
declare class SuperComponent {
static ngComponentDef: ɵɵComponentDefWithMeta<SuperComponent, '[super]', never, {}, {}, never>;
static ɵcmp: ɵɵComponentDefWithMeta<SuperComponent, '[super]', never, {}, {}, never>;
}
declare class SubComponent extends SuperComponent {
@ -18,7 +18,7 @@ declare class SubComponent extends SuperComponent {
// would produce type errors when the "strictFunctionTypes" option is enabled.
onlyInSubtype: string;
static ngComponentDef: ɵɵComponentDefWithMeta<SubComponent, '[sub]', never, {}, {}, never>;
static ɵcmp: ɵɵComponentDefWithMeta<SubComponent, '[sub]', never, {}, {}, never>;
}
declare class SuperPipe { static ngPipeDef: PipeDefWithMeta<SuperPipe, 'super'>; }

View File

@ -506,7 +506,7 @@ describe('TestBed', () => {
const getAOTCompiledComponent = () => {
class ComponentClass {
static ngFactoryDef = () => new ComponentClass();
static ngComponentDef = defineComponent({
static ɵcmp = defineComponent({
type: ComponentClass,
selectors: [['comp']],
decls: 1,
@ -616,13 +616,13 @@ describe('TestBed', () => {
{set: {template: `<span someDirective>{{'hello' | somePipe}}</span>`}});
TestBed.createComponent(SomeComponent);
const defBeforeReset = (SomeComponent as any).ngComponentDef;
const defBeforeReset = (SomeComponent as any).ɵcmp;
expect(defBeforeReset.pipeDefs().length).toEqual(1);
expect(defBeforeReset.directiveDefs().length).toEqual(2); // directive + component
TestBed.resetTestingModule();
const defAfterReset = (SomeComponent as any).ngComponentDef;
const defAfterReset = (SomeComponent as any).ɵcmp;
expect(defAfterReset.pipeDefs).toBe(null);
expect(defAfterReset.directiveDefs).toBe(null);
});
@ -654,8 +654,8 @@ describe('TestBed', () => {
});
TestBed.createComponent(ComponentWithNoAnnotations);
expect(ComponentWithNoAnnotations.hasOwnProperty('ngComponentDef')).toBeTruthy();
expect(SomeComponent.hasOwnProperty('ngComponentDef')).toBeTruthy();
expect(ComponentWithNoAnnotations.hasOwnProperty('ɵcmp')).toBeTruthy();
expect(SomeComponent.hasOwnProperty('ɵcmp')).toBeTruthy();
expect(DirectiveWithNoAnnotations.hasOwnProperty('ngDirectiveDef')).toBeTruthy();
expect(SomeDirective.hasOwnProperty('ngDirectiveDef')).toBeTruthy();
@ -666,12 +666,12 @@ describe('TestBed', () => {
TestBed.resetTestingModule();
// ng defs should be removed from classes with no annotations
expect(ComponentWithNoAnnotations.hasOwnProperty('ngComponentDef')).toBeFalsy();
expect(ComponentWithNoAnnotations.hasOwnProperty('ɵcmp')).toBeFalsy();
expect(DirectiveWithNoAnnotations.hasOwnProperty('ngDirectiveDef')).toBeFalsy();
expect(PipeWithNoAnnotations.hasOwnProperty('ngPipeDef')).toBeFalsy();
// ng defs should be preserved on super types
expect(SomeComponent.hasOwnProperty('ngComponentDef')).toBeTruthy();
expect(SomeComponent.hasOwnProperty('ɵcmp')).toBeTruthy();
expect(SomeDirective.hasOwnProperty('ngDirectiveDef')).toBeTruthy();
expect(SomePipe.hasOwnProperty('ngPipeDef')).toBeTruthy();
});
@ -719,8 +719,7 @@ describe('TestBed', () => {
}
TestBed.configureTestingModule({imports: [MyModule]});
const originalResolver =
(ComponentWithProvider as any).ngComponentDef.providersResolver;
const originalResolver = (ComponentWithProvider as any).ɵcmp.providersResolver;
TestBed.overrideProvider(SomeInjectable, {useValue: {id: 'fake'}});
const compiler = TestBed.inject(Compiler);
@ -728,7 +727,7 @@ describe('TestBed', () => {
compiler.compileModuleSync(MyModule);
TestBed.resetTestingModule();
expect((ComponentWithProvider as any).ngComponentDef.providersResolver)
expect((ComponentWithProvider as any).ɵcmp.providersResolver)
.toEqual(originalResolver);
});
});