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:
@ -19,7 +19,7 @@ import {ParseError, ParseSourceSpan, r3JitTypeSourceSpan} from './parse_util';
|
||||
import {R3DependencyMetadata, R3FactoryTarget, R3ResolvedDependencyType, compileFactoryFunction} from './render3/r3_factory';
|
||||
import {R3JitReflector} from './render3/r3_jit';
|
||||
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 {R3DirectiveMetadata, R3QueryMetadata} from './render3/view/api';
|
||||
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):
|
||||
any {
|
||||
const metadata = {
|
||||
const metadata: R3PipeMetadata = {
|
||||
name: facade.name,
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
typeArgumentCount: facade.typeArgumentCount,
|
||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||
pipeName: facade.pipeName,
|
||||
@ -55,6 +56,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
const {expression, statements} = compileInjectable({
|
||||
name: facade.name,
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
typeArgumentCount: facade.typeArgumentCount,
|
||||
providedIn: computeProvidedIn(facade.providedIn),
|
||||
useClass: wrapExpression(facade, USE_CLASS),
|
||||
@ -73,6 +75,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
const meta: R3InjectorMetadata = {
|
||||
name: facade.name,
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||
providers: new WrappedNodeExpr(facade.providers),
|
||||
imports: facade.imports.map(i => new WrappedNodeExpr(i)),
|
||||
@ -86,6 +89,8 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
facade: R3NgModuleMetadataFacade): any {
|
||||
const meta: R3NgModuleMetadata = {
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
adjacentType: new WrappedNodeExpr(facade.type),
|
||||
bootstrap: facade.bootstrap.map(wrapReference),
|
||||
declarations: facade.declarations.map(wrapReference),
|
||||
imports: facade.imports.map(wrapReference),
|
||||
@ -159,6 +164,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
const factoryRes = compileFactoryFunction({
|
||||
name: meta.name,
|
||||
type: new WrappedNodeExpr(meta.type),
|
||||
internalType: new WrappedNodeExpr(meta.type),
|
||||
typeArgumentCount: meta.typeArgumentCount,
|
||||
deps: convertR3DependencyMetadataArray(meta.deps),
|
||||
injectFn: meta.injectFn === 'directiveInject' ? Identifiers.directiveInject :
|
||||
@ -247,6 +253,7 @@ function convertDirectiveFacadeToMetadata(facade: R3DirectiveMetadataFacade): R3
|
||||
...facade as R3DirectiveMetadataFacadeNoPropAndWhitespace,
|
||||
typeSourceSpan: facade.typeSourceSpan,
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||
host: extractHostBindings(facade.propMetadata, facade.typeSourceSpan, facade.host),
|
||||
inputs: {...inputsFromMetadata, ...inputsFromType},
|
||||
|
Reference in New Issue
Block a user