refactor(ivy): split `type` into `type`, `internalType` and `adjacentType` (#33533)
When compiling an Angular decorator (e.g. Directive), @angular/compiler generates an 'expression' to be added as a static definition field on the class, a 'type' which will be added for that field to the .d.ts file, and a statement adjacent to the class that calls `setClassMetadata()`. Previously, the same WrappedNodeExpr of the class' ts.Identifier was used within each of this situations. In the ngtsc case, this is proper. In the ngcc case, if the class being compiled is within an ES5 IIFE, the outer name of the class may have changed. Thus, the class has both an inner and outer name. The outer name should continue to be used elsewhere in the compiler and in 'type'. The 'expression' will live within the IIFE, the `internalType` should be used. The adjacent statement will also live within the IIFE, the `adjacentType` should be used. This commit introduces `ReflectionHost.getInternalNameOfClass()` and `ReflectionHost.getAdjacentNameOfClass()`, which the compiler can use to query for the correct name to use. PR Close #33533
This commit is contained in:
parent
d9a38928f5
commit
8d0de89ece
|
@ -274,6 +274,7 @@ export function extractDirectiveMetadata(
|
||||||
outputs: {...outputsFromMeta, ...outputsFromFields}, queries, viewQueries, selector,
|
outputs: {...outputsFromMeta, ...outputsFromFields}, queries, viewQueries, selector,
|
||||||
fullInheritance: !!(flags & HandlerFlags.FULL_INHERITANCE),
|
fullInheritance: !!(flags & HandlerFlags.FULL_INHERITANCE),
|
||||||
type: new WrappedNodeExpr(clazz.name),
|
type: new WrappedNodeExpr(clazz.name),
|
||||||
|
internalType: new WrappedNodeExpr(reflector.getInternalNameOfClass(clazz)),
|
||||||
typeArgumentCount: reflector.getGenericArityOfClass(clazz) || 0,
|
typeArgumentCount: reflector.getGenericArityOfClass(clazz) || 0,
|
||||||
typeSourceSpan: EMPTY_SOURCE_SPAN, usesInheritance, exportAs, providers
|
typeSourceSpan: EMPTY_SOURCE_SPAN, usesInheritance, exportAs, providers
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,6 +81,7 @@ export class InjectableDecoratorHandler implements
|
||||||
const factoryRes = compileNgFactoryDefField({
|
const factoryRes = compileNgFactoryDefField({
|
||||||
name: meta.name,
|
name: meta.name,
|
||||||
type: meta.type,
|
type: meta.type,
|
||||||
|
internalType: meta.internalType,
|
||||||
typeArgumentCount: meta.typeArgumentCount,
|
typeArgumentCount: meta.typeArgumentCount,
|
||||||
deps: analysis.ctorDeps,
|
deps: analysis.ctorDeps,
|
||||||
injectFn: Identifiers.inject,
|
injectFn: Identifiers.inject,
|
||||||
|
@ -114,6 +115,7 @@ function extractInjectableMetadata(
|
||||||
reflector: ReflectionHost): R3InjectableMetadata {
|
reflector: ReflectionHost): R3InjectableMetadata {
|
||||||
const name = clazz.name.text;
|
const name = clazz.name.text;
|
||||||
const type = new WrappedNodeExpr(clazz.name);
|
const type = new WrappedNodeExpr(clazz.name);
|
||||||
|
const internalType = new WrappedNodeExpr(reflector.getInternalNameOfClass(clazz));
|
||||||
const typeArgumentCount = reflector.getGenericArityOfClass(clazz) || 0;
|
const typeArgumentCount = reflector.getGenericArityOfClass(clazz) || 0;
|
||||||
if (decorator.args === null) {
|
if (decorator.args === null) {
|
||||||
throw new FatalDiagnosticError(
|
throw new FatalDiagnosticError(
|
||||||
|
@ -125,6 +127,7 @@ function extractInjectableMetadata(
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
typeArgumentCount,
|
typeArgumentCount,
|
||||||
|
internalType,
|
||||||
providedIn: new LiteralExpr(null),
|
providedIn: new LiteralExpr(null),
|
||||||
};
|
};
|
||||||
} else if (decorator.args.length === 1) {
|
} else if (decorator.args.length === 1) {
|
||||||
|
@ -159,6 +162,7 @@ function extractInjectableMetadata(
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
typeArgumentCount,
|
typeArgumentCount,
|
||||||
|
internalType,
|
||||||
providedIn,
|
providedIn,
|
||||||
useValue: new WrappedNodeExpr(unwrapForwardRef(meta.get('useValue') !, reflector)),
|
useValue: new WrappedNodeExpr(unwrapForwardRef(meta.get('useValue') !, reflector)),
|
||||||
};
|
};
|
||||||
|
@ -167,6 +171,7 @@ function extractInjectableMetadata(
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
typeArgumentCount,
|
typeArgumentCount,
|
||||||
|
internalType,
|
||||||
providedIn,
|
providedIn,
|
||||||
useExisting: new WrappedNodeExpr(unwrapForwardRef(meta.get('useExisting') !, reflector)),
|
useExisting: new WrappedNodeExpr(unwrapForwardRef(meta.get('useExisting') !, reflector)),
|
||||||
};
|
};
|
||||||
|
@ -175,6 +180,7 @@ function extractInjectableMetadata(
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
typeArgumentCount,
|
typeArgumentCount,
|
||||||
|
internalType,
|
||||||
providedIn,
|
providedIn,
|
||||||
useClass: new WrappedNodeExpr(unwrapForwardRef(meta.get('useClass') !, reflector)),
|
useClass: new WrappedNodeExpr(unwrapForwardRef(meta.get('useClass') !, reflector)),
|
||||||
userDeps,
|
userDeps,
|
||||||
|
@ -186,11 +192,12 @@ function extractInjectableMetadata(
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
typeArgumentCount,
|
typeArgumentCount,
|
||||||
|
internalType,
|
||||||
providedIn,
|
providedIn,
|
||||||
useFactory: factory, userDeps,
|
useFactory: factory, userDeps,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {name, type, typeArgumentCount, providedIn};
|
return {name, type, typeArgumentCount, internalType, providedIn};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new FatalDiagnosticError(
|
throw new FatalDiagnosticError(
|
||||||
|
|
|
@ -28,7 +28,7 @@ export function generateSetClassMetadataCall(
|
||||||
if (!reflection.isClass(clazz)) {
|
if (!reflection.isClass(clazz)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const id = ts.updateIdentifier(clazz.name);
|
const id = ts.updateIdentifier(reflection.getAdjacentNameOfClass(clazz));
|
||||||
|
|
||||||
// Reflect over the class decorators. If none are present, or those that are aren't from
|
// Reflect over the class decorators. If none are present, or those that are aren't from
|
||||||
// Angular, then return null. Otherwise, turn them into metadata.
|
// Angular, then return null. Otherwise, turn them into metadata.
|
||||||
|
|
|
@ -198,6 +198,8 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||||
|
|
||||||
const ngModuleDef: R3NgModuleMetadata = {
|
const ngModuleDef: R3NgModuleMetadata = {
|
||||||
type: new WrappedNodeExpr(node.name),
|
type: new WrappedNodeExpr(node.name),
|
||||||
|
internalType: new WrappedNodeExpr(this.reflector.getInternalNameOfClass(node)),
|
||||||
|
adjacentType: new WrappedNodeExpr(this.reflector.getAdjacentNameOfClass(node)),
|
||||||
bootstrap,
|
bootstrap,
|
||||||
declarations,
|
declarations,
|
||||||
exports,
|
exports,
|
||||||
|
@ -227,6 +229,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||||
const ngInjectorDef: R3InjectorMetadata = {
|
const ngInjectorDef: R3InjectorMetadata = {
|
||||||
name,
|
name,
|
||||||
type: new WrappedNodeExpr(node.name),
|
type: new WrappedNodeExpr(node.name),
|
||||||
|
internalType: new WrappedNodeExpr(this.reflector.getInternalNameOfClass(node)),
|
||||||
deps: getValidConstructorDependencies(
|
deps: getValidConstructorDependencies(
|
||||||
node, this.reflector, this.defaultImportRecorder, this.isCore),
|
node, this.reflector, this.defaultImportRecorder, this.isCore),
|
||||||
providers,
|
providers,
|
||||||
|
|
|
@ -51,6 +51,7 @@ export class PipeDecoratorHandler implements DecoratorHandler<PipeHandlerData, D
|
||||||
analyze(clazz: ClassDeclaration, decorator: Decorator): AnalysisOutput<PipeHandlerData> {
|
analyze(clazz: ClassDeclaration, decorator: Decorator): AnalysisOutput<PipeHandlerData> {
|
||||||
const name = clazz.name.text;
|
const name = clazz.name.text;
|
||||||
const type = new WrappedNodeExpr(clazz.name);
|
const type = new WrappedNodeExpr(clazz.name);
|
||||||
|
const internalType = new WrappedNodeExpr(this.reflector.getInternalNameOfClass(clazz));
|
||||||
if (decorator.args === null) {
|
if (decorator.args === null) {
|
||||||
throw new FatalDiagnosticError(
|
throw new FatalDiagnosticError(
|
||||||
ErrorCode.DECORATOR_NOT_CALLED, Decorator.nodeForError(decorator),
|
ErrorCode.DECORATOR_NOT_CALLED, Decorator.nodeForError(decorator),
|
||||||
|
@ -97,6 +98,7 @@ export class PipeDecoratorHandler implements DecoratorHandler<PipeHandlerData, D
|
||||||
meta: {
|
meta: {
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
|
internalType,
|
||||||
typeArgumentCount: this.reflector.getGenericArityOfClass(clazz) || 0, pipeName,
|
typeArgumentCount: this.reflector.getGenericArityOfClass(clazz) || 0, pipeName,
|
||||||
deps: getValidConstructorDependencies(
|
deps: getValidConstructorDependencies(
|
||||||
clazz, this.reflector, this.defaultImportRecorder, this.isCore),
|
clazz, this.reflector, this.defaultImportRecorder, this.isCore),
|
||||||
|
|
|
@ -622,4 +622,24 @@ export interface ReflectionHost {
|
||||||
* `ts.Program` as the input declaration.
|
* `ts.Program` as the input declaration.
|
||||||
*/
|
*/
|
||||||
getDtsDeclaration(declaration: ts.Declaration): ts.Declaration|null;
|
getDtsDeclaration(declaration: ts.Declaration): ts.Declaration|null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a `ts.Identifier` for a given `ClassDeclaration` which can be used to refer to the class
|
||||||
|
* within its definition (such as in static fields).
|
||||||
|
*
|
||||||
|
* This can differ from `clazz.name` when ngcc runs over ES5 code, since the class may have a
|
||||||
|
* different name within its IIFE wrapper than it does externally.
|
||||||
|
*/
|
||||||
|
getInternalNameOfClass(clazz: ClassDeclaration): ts.Identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a `ts.Identifier` for a given `ClassDeclaration` which can be used to refer to the class
|
||||||
|
* from statements that are "adjacent", and conceptually tightly bound, to the class but not
|
||||||
|
* actually inside it.
|
||||||
|
*
|
||||||
|
* Similar to `getInternalNameOfClass()`, this name can differ from `clazz.name` when ngcc runs
|
||||||
|
* over ES5 code, since these "adjacent" statements need to exist in the IIFE where the class may
|
||||||
|
* have a different name than it does externally.
|
||||||
|
*/
|
||||||
|
getAdjacentNameOfClass(clazz: ClassDeclaration): ts.Identifier;
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,9 @@ export class TypeScriptReflectionHost implements ReflectionHost {
|
||||||
|
|
||||||
getDtsDeclaration(_: ts.Declaration): ts.Declaration|null { return null; }
|
getDtsDeclaration(_: ts.Declaration): ts.Declaration|null { return null; }
|
||||||
|
|
||||||
|
getInternalNameOfClass(clazz: ClassDeclaration): ts.Identifier { return clazz.name; }
|
||||||
|
|
||||||
|
getAdjacentNameOfClass(clazz: ClassDeclaration): ts.Identifier { return clazz.name; }
|
||||||
|
|
||||||
protected getDirectImportOfIdentifier(id: ts.Identifier): Import|null {
|
protected getDirectImportOfIdentifier(id: ts.Identifier): Import|null {
|
||||||
const symbol = this.checker.getSymbolAtLocation(id);
|
const symbol = this.checker.getSymbolAtLocation(id);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {Identifiers} from './identifiers';
|
import {Identifiers} from './identifiers';
|
||||||
import * as o from './output/output_ast';
|
import * as o from './output/output_ast';
|
||||||
import {R3DependencyMetadata, R3FactoryDelegateType, R3FactoryTarget, compileFactoryFunction} from './render3/r3_factory';
|
import {R3DependencyMetadata, R3FactoryDelegateType, R3FactoryMetadata, R3FactoryTarget, compileFactoryFunction} from './render3/r3_factory';
|
||||||
import {mapToMapExpression, typeWithParameters} from './render3/util';
|
import {mapToMapExpression, typeWithParameters} from './render3/util';
|
||||||
|
|
||||||
export interface InjectableDef {
|
export interface InjectableDef {
|
||||||
|
@ -20,6 +20,7 @@ export interface InjectableDef {
|
||||||
export interface R3InjectableMetadata {
|
export interface R3InjectableMetadata {
|
||||||
name: string;
|
name: string;
|
||||||
type: o.Expression;
|
type: o.Expression;
|
||||||
|
internalType: o.Expression;
|
||||||
typeArgumentCount: number;
|
typeArgumentCount: number;
|
||||||
providedIn: o.Expression;
|
providedIn: o.Expression;
|
||||||
useClass?: o.Expression;
|
useClass?: o.Expression;
|
||||||
|
@ -32,9 +33,10 @@ export interface R3InjectableMetadata {
|
||||||
export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
||||||
let result: {factory: o.Expression, statements: o.Statement[]}|null = null;
|
let result: {factory: o.Expression, statements: o.Statement[]}|null = null;
|
||||||
|
|
||||||
const factoryMeta = {
|
const factoryMeta: R3FactoryMetadata = {
|
||||||
name: meta.name,
|
name: meta.name,
|
||||||
type: meta.type,
|
type: meta.type,
|
||||||
|
internalType: meta.internalType,
|
||||||
typeArgumentCount: meta.typeArgumentCount,
|
typeArgumentCount: meta.typeArgumentCount,
|
||||||
deps: [],
|
deps: [],
|
||||||
injectFn: Identifiers.inject,
|
injectFn: Identifiers.inject,
|
||||||
|
@ -49,7 +51,7 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
||||||
// A special case exists for useClass: Type where Type is the injectable type itself and no
|
// A special case exists for useClass: Type where Type is the injectable type itself and no
|
||||||
// deps are specified, in which case 'useClass' is effectively ignored.
|
// deps are specified, in which case 'useClass' is effectively ignored.
|
||||||
|
|
||||||
const useClassOnSelf = meta.useClass.isEquivalent(meta.type);
|
const useClassOnSelf = meta.useClass.isEquivalent(meta.internalType);
|
||||||
let deps: R3DependencyMetadata[]|undefined = undefined;
|
let deps: R3DependencyMetadata[]|undefined = undefined;
|
||||||
if (meta.userDeps !== undefined) {
|
if (meta.userDeps !== undefined) {
|
||||||
deps = meta.userDeps;
|
deps = meta.userDeps;
|
||||||
|
@ -97,10 +99,10 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
||||||
expression: o.importExpr(Identifiers.inject).callFn([meta.useExisting]),
|
expression: o.importExpr(Identifiers.inject).callFn([meta.useExisting]),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
result = delegateToFactory(meta.type);
|
result = delegateToFactory(meta.internalType);
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = meta.type;
|
const token = meta.internalType;
|
||||||
const providedIn = meta.providedIn;
|
const providedIn = meta.providedIn;
|
||||||
|
|
||||||
const expression = o.importExpr(Identifiers.ɵɵdefineInjectable).callFn([mapToMapExpression(
|
const expression = o.importExpr(Identifiers.ɵɵdefineInjectable).callFn([mapToMapExpression(
|
||||||
|
@ -118,7 +120,7 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
||||||
function delegateToFactory(type: o.Expression) {
|
function delegateToFactory(type: o.Expression) {
|
||||||
return {
|
return {
|
||||||
statements: [],
|
statements: [],
|
||||||
// () => meta.type.ɵfac(t)
|
// () => type.ɵfac(t)
|
||||||
factory: o.fn([new o.FnParam('t', o.DYNAMIC_TYPE)], [new o.ReturnStatement(type.callMethod(
|
factory: o.fn([new o.FnParam('t', o.DYNAMIC_TYPE)], [new o.ReturnStatement(type.callMethod(
|
||||||
'ɵfac', [o.variable('t')]))])
|
'ɵfac', [o.variable('t')]))])
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ import {ParseError, ParseSourceSpan, r3JitTypeSourceSpan} from './parse_util';
|
||||||
import {R3DependencyMetadata, R3FactoryTarget, R3ResolvedDependencyType, compileFactoryFunction} from './render3/r3_factory';
|
import {R3DependencyMetadata, R3FactoryTarget, R3ResolvedDependencyType, compileFactoryFunction} from './render3/r3_factory';
|
||||||
import {R3JitReflector} from './render3/r3_jit';
|
import {R3JitReflector} from './render3/r3_jit';
|
||||||
import {R3InjectorMetadata, R3NgModuleMetadata, compileInjector, compileNgModule} from './render3/r3_module_compiler';
|
import {R3InjectorMetadata, R3NgModuleMetadata, compileInjector, compileNgModule} from './render3/r3_module_compiler';
|
||||||
import {compilePipeFromMetadata} from './render3/r3_pipe_compiler';
|
import {R3PipeMetadata, compilePipeFromMetadata} from './render3/r3_pipe_compiler';
|
||||||
import {R3Reference} from './render3/util';
|
import {R3Reference} from './render3/util';
|
||||||
import {R3DirectiveMetadata, R3QueryMetadata} from './render3/view/api';
|
import {R3DirectiveMetadata, R3QueryMetadata} from './render3/view/api';
|
||||||
import {ParsedHostBindings, compileComponentFromMetadata, compileDirectiveFromMetadata, parseHostBindings, verifyHostBindings} from './render3/view/compiler';
|
import {ParsedHostBindings, compileComponentFromMetadata, compileDirectiveFromMetadata, parseHostBindings, verifyHostBindings} from './render3/view/compiler';
|
||||||
|
@ -37,9 +37,10 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||||
|
|
||||||
compilePipe(angularCoreEnv: CoreEnvironment, sourceMapUrl: string, facade: R3PipeMetadataFacade):
|
compilePipe(angularCoreEnv: CoreEnvironment, sourceMapUrl: string, facade: R3PipeMetadataFacade):
|
||||||
any {
|
any {
|
||||||
const metadata = {
|
const metadata: R3PipeMetadata = {
|
||||||
name: facade.name,
|
name: facade.name,
|
||||||
type: new WrappedNodeExpr(facade.type),
|
type: new WrappedNodeExpr(facade.type),
|
||||||
|
internalType: new WrappedNodeExpr(facade.type),
|
||||||
typeArgumentCount: facade.typeArgumentCount,
|
typeArgumentCount: facade.typeArgumentCount,
|
||||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||||
pipeName: facade.pipeName,
|
pipeName: facade.pipeName,
|
||||||
|
@ -55,6 +56,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||||
const {expression, statements} = compileInjectable({
|
const {expression, statements} = compileInjectable({
|
||||||
name: facade.name,
|
name: facade.name,
|
||||||
type: new WrappedNodeExpr(facade.type),
|
type: new WrappedNodeExpr(facade.type),
|
||||||
|
internalType: new WrappedNodeExpr(facade.type),
|
||||||
typeArgumentCount: facade.typeArgumentCount,
|
typeArgumentCount: facade.typeArgumentCount,
|
||||||
providedIn: computeProvidedIn(facade.providedIn),
|
providedIn: computeProvidedIn(facade.providedIn),
|
||||||
useClass: wrapExpression(facade, USE_CLASS),
|
useClass: wrapExpression(facade, USE_CLASS),
|
||||||
|
@ -73,6 +75,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||||
const meta: R3InjectorMetadata = {
|
const meta: R3InjectorMetadata = {
|
||||||
name: facade.name,
|
name: facade.name,
|
||||||
type: new WrappedNodeExpr(facade.type),
|
type: new WrappedNodeExpr(facade.type),
|
||||||
|
internalType: new WrappedNodeExpr(facade.type),
|
||||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||||
providers: new WrappedNodeExpr(facade.providers),
|
providers: new WrappedNodeExpr(facade.providers),
|
||||||
imports: facade.imports.map(i => new WrappedNodeExpr(i)),
|
imports: facade.imports.map(i => new WrappedNodeExpr(i)),
|
||||||
|
@ -86,6 +89,8 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||||
facade: R3NgModuleMetadataFacade): any {
|
facade: R3NgModuleMetadataFacade): any {
|
||||||
const meta: R3NgModuleMetadata = {
|
const meta: R3NgModuleMetadata = {
|
||||||
type: new WrappedNodeExpr(facade.type),
|
type: new WrappedNodeExpr(facade.type),
|
||||||
|
internalType: new WrappedNodeExpr(facade.type),
|
||||||
|
adjacentType: new WrappedNodeExpr(facade.type),
|
||||||
bootstrap: facade.bootstrap.map(wrapReference),
|
bootstrap: facade.bootstrap.map(wrapReference),
|
||||||
declarations: facade.declarations.map(wrapReference),
|
declarations: facade.declarations.map(wrapReference),
|
||||||
imports: facade.imports.map(wrapReference),
|
imports: facade.imports.map(wrapReference),
|
||||||
|
@ -159,6 +164,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||||
const factoryRes = compileFactoryFunction({
|
const factoryRes = compileFactoryFunction({
|
||||||
name: meta.name,
|
name: meta.name,
|
||||||
type: new WrappedNodeExpr(meta.type),
|
type: new WrappedNodeExpr(meta.type),
|
||||||
|
internalType: new WrappedNodeExpr(meta.type),
|
||||||
typeArgumentCount: meta.typeArgumentCount,
|
typeArgumentCount: meta.typeArgumentCount,
|
||||||
deps: convertR3DependencyMetadataArray(meta.deps),
|
deps: convertR3DependencyMetadataArray(meta.deps),
|
||||||
injectFn: meta.injectFn === 'directiveInject' ? Identifiers.directiveInject :
|
injectFn: meta.injectFn === 'directiveInject' ? Identifiers.directiveInject :
|
||||||
|
@ -247,6 +253,7 @@ function convertDirectiveFacadeToMetadata(facade: R3DirectiveMetadataFacade): R3
|
||||||
...facade as R3DirectiveMetadataFacadeNoPropAndWhitespace,
|
...facade as R3DirectiveMetadataFacadeNoPropAndWhitespace,
|
||||||
typeSourceSpan: facade.typeSourceSpan,
|
typeSourceSpan: facade.typeSourceSpan,
|
||||||
type: new WrappedNodeExpr(facade.type),
|
type: new WrappedNodeExpr(facade.type),
|
||||||
|
internalType: new WrappedNodeExpr(facade.type),
|
||||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||||
host: extractHostBindings(facade.propMetadata, facade.typeSourceSpan, facade.host),
|
host: extractHostBindings(facade.propMetadata, facade.typeSourceSpan, facade.host),
|
||||||
inputs: {...inputsFromMetadata, ...inputsFromType},
|
inputs: {...inputsFromMetadata, ...inputsFromType},
|
||||||
|
|
|
@ -30,14 +30,19 @@ export interface R3ConstructorFactoryMetadata {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An expression representing the function (or constructor) which will instantiate the requested
|
* An expression representing the interface type being constructed.
|
||||||
* type.
|
|
||||||
*
|
|
||||||
* This could be a reference to a constructor type, or to a user-defined factory function. The
|
|
||||||
* `useNew` property determines whether it will be called as a constructor or not.
|
|
||||||
*/
|
*/
|
||||||
type: o.Expression;
|
type: o.Expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An expression representing the constructor type, intended for use within a class definition
|
||||||
|
* itself.
|
||||||
|
*
|
||||||
|
* This can differ from the outer `type` if the class is being compiled by ngcc and is inside
|
||||||
|
* an IIFE structure that uses a different name internally.
|
||||||
|
*/
|
||||||
|
internalType: o.Expression;
|
||||||
|
|
||||||
/** Number of arguments for the `type`. */
|
/** Number of arguments for the `type`. */
|
||||||
typeArgumentCount: number;
|
typeArgumentCount: number;
|
||||||
|
|
||||||
|
@ -176,8 +181,9 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3FactoryFn {
|
||||||
// parameter provided by the user (t) if specified, or the current type if not. If there is a
|
// parameter provided by the user (t) if specified, or the current type if not. If there is a
|
||||||
// delegated factory (which is used to create the current type) then this is only the type-to-
|
// delegated factory (which is used to create the current type) then this is only the type-to-
|
||||||
// create parameter (t).
|
// create parameter (t).
|
||||||
const typeForCtor =
|
const typeForCtor = !isDelegatedMetadata(meta) ?
|
||||||
!isDelegatedMetadata(meta) ? new o.BinaryOperatorExpr(o.BinaryOperator.Or, t, meta.type) : t;
|
new o.BinaryOperatorExpr(o.BinaryOperator.Or, t, meta.internalType) :
|
||||||
|
t;
|
||||||
|
|
||||||
let ctorExpr: o.Expression|null = null;
|
let ctorExpr: o.Expression|null = null;
|
||||||
if (meta.deps !== null) {
|
if (meta.deps !== null) {
|
||||||
|
@ -191,9 +197,8 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3FactoryFn {
|
||||||
const baseFactory = o.variable(`ɵ${meta.name}_BaseFactory`);
|
const baseFactory = o.variable(`ɵ${meta.name}_BaseFactory`);
|
||||||
const getInheritedFactory = o.importExpr(R3.getInheritedFactory);
|
const getInheritedFactory = o.importExpr(R3.getInheritedFactory);
|
||||||
const baseFactoryStmt =
|
const baseFactoryStmt =
|
||||||
baseFactory.set(getInheritedFactory.callFn([meta.type])).toDeclStmt(o.INFERRED_TYPE, [
|
baseFactory.set(getInheritedFactory.callFn([meta.internalType]))
|
||||||
o.StmtModifier.Exported, o.StmtModifier.Final
|
.toDeclStmt(o.INFERRED_TYPE, [o.StmtModifier.Exported, o.StmtModifier.Final]);
|
||||||
]);
|
|
||||||
statements.push(baseFactoryStmt);
|
statements.push(baseFactoryStmt);
|
||||||
|
|
||||||
// There is no constructor, use the base class' factory to construct typeForCtor.
|
// There is no constructor, use the base class' factory to construct typeForCtor.
|
||||||
|
@ -220,7 +225,7 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3FactoryFn {
|
||||||
if (isDelegatedMetadata(meta) && meta.delegateType === R3FactoryDelegateType.Factory) {
|
if (isDelegatedMetadata(meta) && meta.delegateType === R3FactoryDelegateType.Factory) {
|
||||||
const delegateFactory = o.variable(`ɵ${meta.name}_BaseFactory`);
|
const delegateFactory = o.variable(`ɵ${meta.name}_BaseFactory`);
|
||||||
const getFactoryOf = o.importExpr(R3.getFactoryOf);
|
const getFactoryOf = o.importExpr(R3.getFactoryOf);
|
||||||
if (meta.delegate.isEquivalent(meta.type)) {
|
if (meta.delegate.isEquivalent(meta.internalType)) {
|
||||||
throw new Error(`Illegal state: compiling factory that delegates to itself`);
|
throw new Error(`Illegal state: compiling factory that delegates to itself`);
|
||||||
}
|
}
|
||||||
const delegateFactoryStmt =
|
const delegateFactoryStmt =
|
||||||
|
|
|
@ -31,6 +31,24 @@ export interface R3NgModuleMetadata {
|
||||||
*/
|
*/
|
||||||
type: o.Expression;
|
type: o.Expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An expression representing the module type being compiled, intended for use within a class
|
||||||
|
* definition itself.
|
||||||
|
*
|
||||||
|
* This can differ from the outer `type` if the class is being compiled by ngcc and is inside
|
||||||
|
* an IIFE structure that uses a different name internally.
|
||||||
|
*/
|
||||||
|
internalType: o.Expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An expression intended for use by statements that are adjacent (i.e. tightly coupled) to but
|
||||||
|
* not internal to a class definition.
|
||||||
|
*
|
||||||
|
* This can differ from the outer `type` if the class is being compiled by ngcc and is inside
|
||||||
|
* an IIFE structure that uses a different name internally.
|
||||||
|
*/
|
||||||
|
adjacentType: o.Expression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of expressions representing the bootstrap components specified by the module.
|
* An array of expressions representing the bootstrap components specified by the module.
|
||||||
*/
|
*/
|
||||||
|
@ -77,6 +95,7 @@ export interface R3NgModuleMetadata {
|
||||||
*/
|
*/
|
||||||
export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
|
export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
|
||||||
const {
|
const {
|
||||||
|
internalType,
|
||||||
type: moduleType,
|
type: moduleType,
|
||||||
bootstrap,
|
bootstrap,
|
||||||
declarations,
|
declarations,
|
||||||
|
@ -90,7 +109,7 @@ export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
|
||||||
|
|
||||||
const additionalStatements: o.Statement[] = [];
|
const additionalStatements: o.Statement[] = [];
|
||||||
const definitionMap = {
|
const definitionMap = {
|
||||||
type: moduleType
|
type: internalType
|
||||||
} as{
|
} as{
|
||||||
type: o.Expression,
|
type: o.Expression,
|
||||||
bootstrap: o.Expression,
|
bootstrap: o.Expression,
|
||||||
|
@ -156,7 +175,7 @@ export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
|
||||||
* symbols to become tree-shakeable.
|
* symbols to become tree-shakeable.
|
||||||
*/
|
*/
|
||||||
function generateSetNgModuleScopeCall(meta: R3NgModuleMetadata): o.Statement|null {
|
function generateSetNgModuleScopeCall(meta: R3NgModuleMetadata): o.Statement|null {
|
||||||
const {type: moduleType, declarations, imports, exports, containsForwardDecls} = meta;
|
const {adjacentType: moduleType, declarations, imports, exports, containsForwardDecls} = meta;
|
||||||
|
|
||||||
const scopeMap = {} as{
|
const scopeMap = {} as{
|
||||||
declarations: o.Expression,
|
declarations: o.Expression,
|
||||||
|
@ -198,6 +217,7 @@ export interface R3InjectorDef {
|
||||||
export interface R3InjectorMetadata {
|
export interface R3InjectorMetadata {
|
||||||
name: string;
|
name: string;
|
||||||
type: o.Expression;
|
type: o.Expression;
|
||||||
|
internalType: o.Expression;
|
||||||
deps: R3DependencyMetadata[]|null;
|
deps: R3DependencyMetadata[]|null;
|
||||||
providers: o.Expression|null;
|
providers: o.Expression|null;
|
||||||
imports: o.Expression[];
|
imports: o.Expression[];
|
||||||
|
@ -207,6 +227,7 @@ export function compileInjector(meta: R3InjectorMetadata): R3InjectorDef {
|
||||||
const result = compileFactoryFunction({
|
const result = compileFactoryFunction({
|
||||||
name: meta.name,
|
name: meta.name,
|
||||||
type: meta.type,
|
type: meta.type,
|
||||||
|
internalType: meta.internalType,
|
||||||
typeArgumentCount: 0,
|
typeArgumentCount: 0,
|
||||||
deps: meta.deps,
|
deps: meta.deps,
|
||||||
injectFn: R3.inject,
|
injectFn: R3.inject,
|
||||||
|
|
|
@ -27,6 +27,15 @@ export interface R3PipeMetadata {
|
||||||
*/
|
*/
|
||||||
type: o.Expression;
|
type: o.Expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An expression representing the pipe being compiled, intended for use within a class definition
|
||||||
|
* itself.
|
||||||
|
*
|
||||||
|
* This can differ from the outer `type` if the class is being compiled by ngcc and is inside an
|
||||||
|
* IIFE structure that uses a different name internally.
|
||||||
|
*/
|
||||||
|
internalType: o.Expression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of generic type parameters of the type itself.
|
* Number of generic type parameters of the type itself.
|
||||||
*/
|
*/
|
||||||
|
@ -80,10 +89,12 @@ export function compilePipeFromRender2(
|
||||||
return error(`Cannot resolve the name of ${pipe.type}`);
|
return error(`Cannot resolve the name of ${pipe.type}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const type = outputCtx.importExpr(pipe.type.reference);
|
||||||
const metadata: R3PipeMetadata = {
|
const metadata: R3PipeMetadata = {
|
||||||
name,
|
name,
|
||||||
|
type,
|
||||||
|
internalType: type,
|
||||||
pipeName: pipe.name,
|
pipeName: pipe.name,
|
||||||
type: outputCtx.importExpr(pipe.type.reference),
|
|
||||||
typeArgumentCount: 0,
|
typeArgumentCount: 0,
|
||||||
deps: dependenciesFromGlobalMetadata(pipe.type, outputCtx, reflector),
|
deps: dependenciesFromGlobalMetadata(pipe.type, outputCtx, reflector),
|
||||||
pure: pipe.pure,
|
pure: pipe.pure,
|
||||||
|
|
|
@ -28,6 +28,15 @@ export interface R3DirectiveMetadata {
|
||||||
*/
|
*/
|
||||||
type: o.Expression;
|
type: o.Expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An expression representing a reference to the directive being compiled, intended for use within
|
||||||
|
* a class definition itself.
|
||||||
|
*
|
||||||
|
* This can differ from the outer `type` if the class is being compiled by ngcc and is inside
|
||||||
|
* an IIFE structure that uses a different name internally.
|
||||||
|
*/
|
||||||
|
internalType: o.Expression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of generic type parameters of the type itself.
|
* Number of generic type parameters of the type itself.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -45,7 +45,7 @@ function baseDirectiveFields(
|
||||||
const selectors = core.parseSelectorToR3Selector(meta.selector);
|
const selectors = core.parseSelectorToR3Selector(meta.selector);
|
||||||
|
|
||||||
// e.g. `type: MyDirective`
|
// e.g. `type: MyDirective`
|
||||||
definitionMap.set('type', meta.type);
|
definitionMap.set('type', meta.internalType);
|
||||||
|
|
||||||
// e.g. `selectors: [['', 'someDir', '']]`
|
// e.g. `selectors: [['', 'someDir', '']]`
|
||||||
if (selectors.length > 0) {
|
if (selectors.length > 0) {
|
||||||
|
|
Loading…
Reference in New Issue