refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371) (#23383)
Ivy definition looks something like this: ``` class MyService { static ngInjectableDef = defineInjectable({ … }); } ``` Here the argument to `defineInjectable` is well known public contract which needs to be honored in backward compatible way between versions. The type of the return value of `defineInjectable` on the other hand is private and can change shape drastically between versions without effecting backwards compatibility of libraries publish to NPM. To our users it is effectively an opaque token. For this reson why declare the return value of `defineInjectable` as `never`. PR Close #23383
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, ContentChild, Directive, Injectable, Injector, InjectorDef, Input, NgModule, NgModuleFactory, NgModuleRef, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjector} from '../../../src/core';
|
||||
import {Component, ContentChild, Directive, Injectable, Injector, Input, NgModule, NgModuleFactory, NgModuleRef, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjector} from '../../../src/core';
|
||||
import * as r3 from '../../../src/render3/index';
|
||||
|
||||
const details_elided = {
|
||||
|
@ -8,8 +8,11 @@
|
||||
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
|
||||
import * as $r3$ from '../../../src/core_render3_private_export';
|
||||
import {ComponentDef} from '../../../src/render3/interfaces/definition';
|
||||
import {renderComponent, toHtml} from '../render_util';
|
||||
|
||||
|
||||
|
||||
/// See: `normative.md`
|
||||
describe('components & directives', () => {
|
||||
type $RenderFlags$ = $r3$.ɵRenderFlags;
|
||||
@ -76,8 +79,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyComponent.ngComponentDef.directiveDefs =
|
||||
[ChildComponent.ngComponentDef, SomeDirective.ngDirectiveDef];
|
||||
(MyComponent.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(ChildComponent.ngComponentDef as ComponentDef<any>), SomeDirective.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyComponent)).toEqual('<child some-directive="">child-view</child>!');
|
||||
@ -126,7 +129,7 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [HostBindingDir.ngDirectiveDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [HostBindingDir.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<div hostbindingdir="" id="some id"></div>`);
|
||||
@ -177,7 +180,7 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [HostListenerDir.ngDirectiveDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [HostListenerDir.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<button hostlistenerdir="">Click</button>`);
|
||||
@ -222,7 +225,7 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [HostAttributeDir.ngDirectiveDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [HostAttributeDir.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<div hostattributedir="" role="listbox"></div>`);
|
||||
@ -270,7 +273,7 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [HostBindingDir.ngDirectiveDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [HostBindingDir.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<div aria-label="some label" hostbindingdir=""></div>`);
|
||||
@ -333,7 +336,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [MyComp.ngComponentDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(MyComp.ngComponentDef as ComponentDef<any>)];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<my-comp>some name</my-comp>`);
|
||||
@ -463,7 +467,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [MyArrayComp.ngComponentDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(MyArrayComp.ngComponentDef as ComponentDef<any>)];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<my-array-comp>Nancy Bess</my-array-comp>`);
|
||||
@ -507,7 +512,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [MyArrayComp.ngComponentDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(MyArrayComp.ngComponentDef as ComponentDef<any>)];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<my-array-comp>NANCY Bess</my-array-comp>`);
|
||||
@ -567,7 +573,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [MyComp.ngComponentDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(MyComp.ngComponentDef as ComponentDef<any>)];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<my-comp>3</my-comp>`);
|
||||
@ -609,7 +616,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [MyArrayComp.ngComponentDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(MyArrayComp.ngComponentDef as ComponentDef<any>)];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<my-array-comp>Nancy Bess</my-array-comp>`);
|
||||
@ -721,7 +729,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [MyComp.ngComponentDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(MyComp.ngComponentDef as ComponentDef<any>)];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<my-comp>start-abcde-middle-fghi-end</my-comp>`);
|
||||
@ -795,7 +804,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [ObjectComp.ngComponentDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(ObjectComp.ngComponentDef as ComponentDef<any>)];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<object-comp><p>500</p><p>slide</p></object-comp>`);
|
||||
@ -882,7 +892,8 @@ describe('components & directives', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE (done by defineNgModule)
|
||||
MyApp.ngComponentDef.directiveDefs = [NestedComp.ngComponentDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[(NestedComp.ngComponentDef as ComponentDef<any>)];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
expect(renderComp(MyApp))
|
||||
|
@ -7,10 +7,13 @@
|
||||
*/
|
||||
|
||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
|
||||
import * as $r3$ from '../../../src/core_render3_private_export';
|
||||
import {ComponentDef} from '../../../src/render3/interfaces/definition';
|
||||
import {ComponentFixture, renderComponent, toHtml} from '../render_util';
|
||||
|
||||
|
||||
/// See: `normative.md`
|
||||
describe('elements', () => {
|
||||
// Saving type as $any$, etc to simplify testing for compiler, as types aren't saved
|
||||
@ -103,7 +106,7 @@ describe('elements', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE
|
||||
LocalRefComp.ngComponentDef.directiveDefs = () => [Dir.ngDirectiveDef];
|
||||
(LocalRefComp.ngComponentDef as ComponentDef<any>).directiveDefs = () => [Dir.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
const fixture = new ComponentFixture(LocalRefComp);
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, INJECTOR, Inject, InjectFlags, Injectable, InjectableDef, Injector, InjectorDef, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, SkipSelf, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, defineInjectable, defineInjector, inject} from '../../../src/core';
|
||||
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, INJECTOR, Inject, InjectFlags, Injectable, Injector, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, SkipSelf, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, defineInjectable, defineInjector, inject} from '../../../src/core';
|
||||
import * as $r3$ from '../../../src/core_render3_private_export';
|
||||
import {renderComponent, toHtml} from '../render_util';
|
||||
|
||||
|
@ -8,8 +8,10 @@
|
||||
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
|
||||
import * as $r3$ from '../../../src/core_render3_private_export';
|
||||
import {ComponentDef} from '../../../src/render3/interfaces/definition';
|
||||
import {renderComponent, toHtml} from '../render_util';
|
||||
|
||||
|
||||
/// See: `normative.md`
|
||||
describe('lifecycle hooks', () => {
|
||||
let events: string[] = [];
|
||||
@ -83,7 +85,7 @@ describe('lifecycle hooks', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE
|
||||
SimpleLayout.ngComponentDef.directiveDefs = [LifecycleComp.ngComponentDef];
|
||||
(SimpleLayout.ngComponentDef as ComponentDef<any>).directiveDefs = [LifecycleComp.ngComponentDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
it('should gen hooks with a few simple components', () => {
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, ContentChild, Directive, Injectable, InjectableDef, InjectorDef, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjectable, defineInjector} from '../../../src/core';
|
||||
import {Component, ContentChild, Directive, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjectable, defineInjector} from '../../../src/core';
|
||||
import * as r3 from '../../../src/render3/index';
|
||||
|
||||
|
||||
|
@ -8,8 +8,10 @@
|
||||
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
|
||||
import * as $r3$ from '../../../src/core_render3_private_export';
|
||||
import {ComponentDef} from '../../../src/render3/interfaces/definition';
|
||||
import {containerEl, renderComponent, toHtml} from '../render_util';
|
||||
|
||||
|
||||
/// See: `normative.md`
|
||||
describe('pipes', () => {
|
||||
type $any$ = any;
|
||||
@ -96,7 +98,8 @@ describe('pipes', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE
|
||||
MyApp.ngComponentDef.pipeDefs = () => [MyPurePipe.ngPipeDef, MyPipe.ngPipeDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).pipeDefs =
|
||||
() => [MyPurePipe.ngPipeDef, MyPipe.ngPipeDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
let myApp: MyApp = renderComponent(MyApp);
|
||||
@ -189,8 +192,8 @@ describe('pipes', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE
|
||||
MyApp.ngComponentDef.directiveDefs = [OneTimeIf.ngDirectiveDef];
|
||||
MyApp.ngComponentDef.pipeDefs = [MyPurePipe.ngPipeDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs = [OneTimeIf.ngDirectiveDef];
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).pipeDefs = [MyPurePipe.ngPipeDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
let myApp: MyApp = renderComponent(MyApp);
|
||||
|
@ -8,8 +8,10 @@
|
||||
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
|
||||
import * as $r3$ from '../../../src/core_render3_private_export';
|
||||
import {ComponentDef} from '../../../src/render3/interfaces/definition';
|
||||
import {renderComponent, toHtml} from '../render_util';
|
||||
|
||||
|
||||
/// See: `normative.md`
|
||||
describe('queries', () => {
|
||||
type $RenderFlags$ = $r3$.ɵRenderFlags;
|
||||
@ -70,7 +72,8 @@ describe('queries', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE
|
||||
ViewQueryComponent.ngComponentDef.directiveDefs = [SomeDirective.ngDirectiveDef];
|
||||
(ViewQueryComponent.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[SomeDirective.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
const viewQueryComp = renderComponent(ViewQueryComponent);
|
||||
@ -154,7 +157,7 @@ describe('queries', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE
|
||||
MyApp.ngComponentDef.directiveDefs =
|
||||
(MyApp.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[ContentQueryComponent.ngComponentDef, SomeDirective.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {NgForOf, NgForOfContext} from '@angular/common';
|
||||
import {Component, ContentChild, Directive, EventEmitter, Injectable, InjectableDef, InjectorDef, Input, NgModule, OnDestroy, Optional, Output, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjectable, defineInjector} from '@angular/core';
|
||||
import {Component, ContentChild, Directive, EventEmitter, Injectable, Input, NgModule, OnDestroy, Optional, Output, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, defineInjectable, defineInjector} from '@angular/core';
|
||||
import {withBody} from '@angular/core/testing';
|
||||
|
||||
import * as r3 from '../../../src/render3/index';
|
||||
@ -96,7 +96,7 @@ class ToDoAppComponent {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE
|
||||
ToDoAppComponent.ngComponentDef.directiveDefs = () =>
|
||||
(ToDoAppComponent.ngComponentDef as r3.ComponentDef<any>).directiveDefs = () =>
|
||||
[ToDoItemComponent.ngComponentDef, (NgForOf as r3.DirectiveType<NgForOf<any>>).ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
|
@ -8,8 +8,10 @@
|
||||
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Injectable, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '../../../src/core';
|
||||
import * as $r3$ from '../../../src/core_render3_private_export';
|
||||
import {ComponentDef} from '../../../src/render3/interfaces/definition';
|
||||
import {renderComponent, toHtml} from '../render_util';
|
||||
|
||||
|
||||
/// See: `normative.md`
|
||||
describe('template variables', () => {
|
||||
type $any$ = any;
|
||||
@ -123,7 +125,8 @@ describe('template variables', () => {
|
||||
}
|
||||
|
||||
// NON-NORMATIVE
|
||||
MyComponent.ngComponentDef.directiveDefs = [ForOfDirective.ngDirectiveDef];
|
||||
(MyComponent.ngComponentDef as ComponentDef<any>).directiveDefs =
|
||||
[ForOfDirective.ngDirectiveDef];
|
||||
// /NON-NORMATIVE
|
||||
|
||||
// TODO(chuckj): update when the changes to enable ngForOf lands.
|
||||
|
Reference in New Issue
Block a user