fix(ivy): remove metadata from *Def and introduce *DefWithMeta types (#26203)
Previously in Ivy, metadata for directives/components/modules/etc was carried in .d.ts files inside type information encoded on the DirectiveDef, ComponentDef, NgModuleDef, etc types of Ivy definition fields. This works well, but has the side effect of complicating Ivy's runtime code as these extra generic type parameters had to be specified as <any> throughout the codebase. *DefInternal types were introduced previously to mitigate this issue, but that's the wrong way to solve the problem. This commit returns *Def types to their original form, with no metadata attached. Instead, new *DefWithMeta types are introduced that alias the plain definition types and add extra generic parameters. This way the only code that needs to deal with the extra metadata parameters is the compiler code that reads and writes them - the existence of this metadata is transparent to the runtime, as it should be. PR Close #26203
This commit is contained in:

committed by
Jason Aden

parent
b0070dfb9a
commit
79466baef8
@ -9,22 +9,22 @@
|
||||
import {Type} from '../../type';
|
||||
import {fillProperties} from '../../util/property';
|
||||
import {EMPTY, EMPTY_ARRAY} from '../definition';
|
||||
import {ComponentDefInternal, ComponentTemplate, DirectiveDefFeature, DirectiveDefInternal, RenderFlags} from '../interfaces/definition';
|
||||
import {ComponentDef, ComponentTemplate, DirectiveDef, DirectiveDefFeature, RenderFlags} from '../interfaces/definition';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Determines if a definition is a {@link ComponentDefInternal} or a {@link DirectiveDefInternal}
|
||||
* Determines if a definition is a {@link ComponentDef} or a {@link DirectiveDef}
|
||||
* @param definition The definition to examine
|
||||
*/
|
||||
function isComponentDef<T>(definition: ComponentDefInternal<T>| DirectiveDefInternal<T>):
|
||||
definition is ComponentDefInternal<T> {
|
||||
const def = definition as ComponentDefInternal<T>;
|
||||
function isComponentDef<T>(definition: ComponentDef<T>| DirectiveDef<T>):
|
||||
definition is ComponentDef<T> {
|
||||
const def = definition as ComponentDef<T>;
|
||||
return typeof def.template === 'function';
|
||||
}
|
||||
|
||||
function getSuperType(type: Type<any>): Type<any>&
|
||||
{ngComponentDef?: ComponentDefInternal<any>, ngDirectiveDef?: DirectiveDefInternal<any>} {
|
||||
{ngComponentDef?: ComponentDef<any>, ngDirectiveDef?: DirectiveDef<any>} {
|
||||
return Object.getPrototypeOf(type.prototype).constructor;
|
||||
}
|
||||
|
||||
@ -32,12 +32,11 @@ function getSuperType(type: Type<any>): Type<any>&
|
||||
* Merges the definition from a super class to a sub class.
|
||||
* @param definition The definition that is a SubClass of another directive of component
|
||||
*/
|
||||
export function InheritDefinitionFeature(
|
||||
definition: DirectiveDefInternal<any>| ComponentDefInternal<any>): void {
|
||||
export function InheritDefinitionFeature(definition: DirectiveDef<any>| ComponentDef<any>): void {
|
||||
let superType = getSuperType(definition.type);
|
||||
|
||||
while (superType) {
|
||||
let superDef: DirectiveDefInternal<any>|ComponentDefInternal<any>|undefined = undefined;
|
||||
let superDef: DirectiveDef<any>|ComponentDef<any>|undefined = undefined;
|
||||
if (isComponentDef(definition)) {
|
||||
// Don't use getComponentDef/getDirectiveDef. This logic relies on inheritance.
|
||||
superDef = superType.ngComponentDef || superType.ngDirectiveDef;
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {SimpleChange} from '../../change_detection/change_detection_util';
|
||||
import {OnChanges, SimpleChanges} from '../../metadata/lifecycle_hooks';
|
||||
import {DirectiveDefInternal} from '../interfaces/definition';
|
||||
import {DirectiveDef} from '../interfaces/definition';
|
||||
|
||||
const PRIVATE_PREFIX = '__ngOnChanges_';
|
||||
|
||||
@ -38,7 +38,7 @@ type OnChangesExpando = OnChanges & {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function NgOnChangesFeature<T>(definition: DirectiveDefInternal<T>): void {
|
||||
export function NgOnChangesFeature<T>(definition: DirectiveDef<T>): void {
|
||||
const declaredToMinifiedInputs = definition.declaredInputs;
|
||||
const proto = definition.type.prototype;
|
||||
for (const declaredName in declaredToMinifiedInputs) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {diPublic} from '../di';
|
||||
import {DirectiveDefInternal} from '../interfaces/definition';
|
||||
import {DirectiveDef} from '../interfaces/definition';
|
||||
|
||||
/**
|
||||
* This feature publishes the directive (or component) into the DI system, making it visible to
|
||||
@ -14,6 +14,6 @@ import {DirectiveDefInternal} from '../interfaces/definition';
|
||||
*
|
||||
* @param definition
|
||||
*/
|
||||
export function PublicFeature<T>(definition: DirectiveDefInternal<T>) {
|
||||
export function PublicFeature<T>(definition: DirectiveDef<T>) {
|
||||
definition.diPublic = diPublic;
|
||||
}
|
||||
|
Reference in New Issue
Block a user