fix(ngcc): use the correct identifiers when updating typings files (#34254)
Previously the identifiers used in the typings files were the same as those used in the source files. When the typings files and the source files do not match exactly, e.g. when one of them is flattened, while the other is a deep tree, it is possible for identifiers to be renamed. This commit ensures that the correct identifier is used in typings files when the typings file does not export the same name as the source file. Fixes https://github.com/angular/ngcc-validation/pull/608 PR Close #34254
This commit is contained in:

committed by
Kara Erickson

parent
f22a6eb00e
commit
31be29a9f3
@ -9,7 +9,7 @@
|
||||
import {Identifiers} from './identifiers';
|
||||
import * as o from './output/output_ast';
|
||||
import {R3DependencyMetadata, R3FactoryDelegateType, R3FactoryMetadata, R3FactoryTarget, compileFactoryFunction} from './render3/r3_factory';
|
||||
import {mapToMapExpression, typeWithParameters} from './render3/util';
|
||||
import {R3Reference, mapToMapExpression, typeWithParameters} from './render3/util';
|
||||
|
||||
export interface InjectableDef {
|
||||
expression: o.Expression;
|
||||
@ -19,7 +19,7 @@ export interface InjectableDef {
|
||||
|
||||
export interface R3InjectableMetadata {
|
||||
name: string;
|
||||
type: o.Expression;
|
||||
type: R3Reference;
|
||||
internalType: o.Expression;
|
||||
typeArgumentCount: number;
|
||||
providedIn: o.Expression;
|
||||
@ -69,7 +69,7 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
||||
result = compileFactoryFunction(factoryMeta);
|
||||
} else {
|
||||
result = delegateToFactory(
|
||||
meta.type as o.WrappedNodeExpr<any>, meta.useClass as o.WrappedNodeExpr<any>);
|
||||
meta.type.value as o.WrappedNodeExpr<any>, meta.useClass as o.WrappedNodeExpr<any>);
|
||||
}
|
||||
} else if (meta.useFactory !== undefined) {
|
||||
if (meta.userDeps !== undefined) {
|
||||
@ -101,7 +101,7 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
||||
});
|
||||
} else {
|
||||
result = delegateToFactory(
|
||||
meta.type as o.WrappedNodeExpr<any>, meta.internalType as o.WrappedNodeExpr<any>);
|
||||
meta.type.value as o.WrappedNodeExpr<any>, meta.internalType as o.WrappedNodeExpr<any>);
|
||||
}
|
||||
|
||||
const token = meta.internalType;
|
||||
@ -116,7 +116,7 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
|
||||
const expression =
|
||||
o.importExpr(Identifiers.ɵɵdefineInjectable).callFn([mapToMapExpression(injectableProps)]);
|
||||
const type = new o.ExpressionType(o.importExpr(
|
||||
Identifiers.InjectableDef, [typeWithParameters(meta.type, meta.typeArgumentCount)]));
|
||||
Identifiers.InjectableDef, [typeWithParameters(meta.type.type, meta.typeArgumentCount)]));
|
||||
|
||||
return {
|
||||
expression,
|
||||
|
@ -39,7 +39,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
any {
|
||||
const metadata: R3PipeMetadata = {
|
||||
name: facade.name,
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
type: wrapReference(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
typeArgumentCount: facade.typeArgumentCount,
|
||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||
@ -55,7 +55,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
facade: R3InjectableMetadataFacade): any {
|
||||
const {expression, statements} = compileInjectable({
|
||||
name: facade.name,
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
type: wrapReference(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
typeArgumentCount: facade.typeArgumentCount,
|
||||
providedIn: computeProvidedIn(facade.providedIn),
|
||||
@ -74,7 +74,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
facade: R3InjectorMetadataFacade): any {
|
||||
const meta: R3InjectorMetadata = {
|
||||
name: facade.name,
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
type: wrapReference(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||
providers: new WrappedNodeExpr(facade.providers),
|
||||
@ -88,7 +88,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
||||
facade: R3NgModuleMetadataFacade): any {
|
||||
const meta: R3NgModuleMetadata = {
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
type: wrapReference(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
adjacentType: new WrappedNodeExpr(facade.type),
|
||||
bootstrap: facade.bootstrap.map(wrapReference),
|
||||
@ -163,7 +163,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
angularCoreEnv: CoreEnvironment, sourceMapUrl: string, meta: R3FactoryDefMetadataFacade) {
|
||||
const factoryRes = compileFactoryFunction({
|
||||
name: meta.name,
|
||||
type: new WrappedNodeExpr(meta.type),
|
||||
type: wrapReference(meta.type),
|
||||
internalType: new WrappedNodeExpr(meta.type),
|
||||
typeArgumentCount: meta.typeArgumentCount,
|
||||
deps: convertR3DependencyMetadataArray(meta.deps),
|
||||
@ -252,7 +252,7 @@ function convertDirectiveFacadeToMetadata(facade: R3DirectiveMetadataFacade): R3
|
||||
return {
|
||||
...facade as R3DirectiveMetadataFacadeNoPropAndWhitespace,
|
||||
typeSourceSpan: facade.typeSourceSpan,
|
||||
type: new WrappedNodeExpr(facade.type),
|
||||
type: wrapReference(facade.type),
|
||||
internalType: new WrappedNodeExpr(facade.type),
|
||||
deps: convertR3DependencyMetadataArray(facade.deps),
|
||||
host: extractHostBindings(facade.propMetadata, facade.typeSourceSpan, facade.host),
|
||||
|
@ -15,7 +15,7 @@ import * as o from '../output/output_ast';
|
||||
import {Identifiers as R3} from '../render3/r3_identifiers';
|
||||
import {OutputContext} from '../util';
|
||||
|
||||
import {typeWithParameters} from './util';
|
||||
import {R3Reference, typeWithParameters} from './util';
|
||||
import {unsupported} from './view/util';
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ export interface R3ConstructorFactoryMetadata {
|
||||
/**
|
||||
* An expression representing the interface type being constructed.
|
||||
*/
|
||||
type: o.Expression;
|
||||
type: R3Reference;
|
||||
|
||||
/**
|
||||
* An expression representing the constructor type, intended for use within a class definition
|
||||
@ -270,7 +270,7 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3FactoryFn {
|
||||
`${meta.name}_Factory`),
|
||||
statements,
|
||||
type: o.expressionType(
|
||||
o.importExpr(R3.FactoryDef, [typeWithParameters(meta.type, meta.typeArgumentCount)]))
|
||||
o.importExpr(R3.FactoryDef, [typeWithParameters(meta.type.type, meta.typeArgumentCount)]))
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ export interface R3NgModuleMetadata {
|
||||
/**
|
||||
* An expression representing the module type being compiled.
|
||||
*/
|
||||
type: o.Expression;
|
||||
type: R3Reference;
|
||||
|
||||
/**
|
||||
* An expression representing the module type being compiled, intended for use within a class
|
||||
@ -160,7 +160,7 @@ export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
|
||||
|
||||
const expression = o.importExpr(R3.defineNgModule).callFn([mapToMapExpression(definitionMap)]);
|
||||
const type = new o.ExpressionType(o.importExpr(R3.NgModuleDefWithMeta, [
|
||||
new o.ExpressionType(moduleType), tupleTypeOf(declarations), tupleTypeOf(imports),
|
||||
new o.ExpressionType(moduleType.type), tupleTypeOf(declarations), tupleTypeOf(imports),
|
||||
tupleTypeOf(exports)
|
||||
]));
|
||||
|
||||
@ -228,7 +228,7 @@ export interface R3InjectorDef {
|
||||
|
||||
export interface R3InjectorMetadata {
|
||||
name: string;
|
||||
type: o.Expression;
|
||||
type: R3Reference;
|
||||
internalType: o.Expression;
|
||||
deps: R3DependencyMetadata[]|null;
|
||||
providers: o.Expression|null;
|
||||
@ -259,7 +259,7 @@ export function compileInjector(meta: R3InjectorMetadata): R3InjectorDef {
|
||||
|
||||
const expression = o.importExpr(R3.defineInjector).callFn([mapToMapExpression(definitionMap)]);
|
||||
const type =
|
||||
new o.ExpressionType(o.importExpr(R3.InjectorDef, [new o.ExpressionType(meta.type)]));
|
||||
new o.ExpressionType(o.importExpr(R3.InjectorDef, [new o.ExpressionType(meta.type.type)]));
|
||||
return {expression, type, statements: result.statements};
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import {OutputContext, error} from '../util';
|
||||
|
||||
import {R3DependencyMetadata, R3FactoryTarget, compileFactoryFunction, dependenciesFromGlobalMetadata} from './r3_factory';
|
||||
import {Identifiers as R3} from './r3_identifiers';
|
||||
import {typeWithParameters} from './util';
|
||||
import {R3Reference, typeWithParameters, wrapReference} from './util';
|
||||
|
||||
export interface R3PipeMetadata {
|
||||
/**
|
||||
@ -25,7 +25,7 @@ export interface R3PipeMetadata {
|
||||
/**
|
||||
* An expression representing a reference to the pipe itself.
|
||||
*/
|
||||
type: o.Expression;
|
||||
type: R3Reference;
|
||||
|
||||
/**
|
||||
* An expression representing the pipe being compiled, intended for use within a class definition
|
||||
@ -64,14 +64,14 @@ export function compilePipeFromMetadata(metadata: R3PipeMetadata) {
|
||||
definitionMapValues.push({key: 'name', value: o.literal(metadata.pipeName), quoted: false});
|
||||
|
||||
// e.g. `type: MyPipe`
|
||||
definitionMapValues.push({key: 'type', value: metadata.type, quoted: false});
|
||||
definitionMapValues.push({key: 'type', value: metadata.type.value, quoted: false});
|
||||
|
||||
// e.g. `pure: true`
|
||||
definitionMapValues.push({key: 'pure', value: o.literal(metadata.pure), quoted: false});
|
||||
|
||||
const expression = o.importExpr(R3.definePipe).callFn([o.literalMap(definitionMapValues)]);
|
||||
const type = new o.ExpressionType(o.importExpr(R3.PipeDefWithMeta, [
|
||||
typeWithParameters(metadata.type, metadata.typeArgumentCount),
|
||||
typeWithParameters(metadata.type.type, metadata.typeArgumentCount),
|
||||
new o.ExpressionType(new o.LiteralExpr(metadata.pipeName)),
|
||||
]));
|
||||
|
||||
@ -92,7 +92,7 @@ export function compilePipeFromRender2(
|
||||
const type = outputCtx.importExpr(pipe.type.reference);
|
||||
const metadata: R3PipeMetadata = {
|
||||
name,
|
||||
type,
|
||||
type: wrapReference(type),
|
||||
internalType: type,
|
||||
pipeName: pipe.name,
|
||||
typeArgumentCount: 0,
|
||||
|
@ -98,3 +98,8 @@ export function jitOnlyGuardedExpression(expr: o.Expression): o.Expression {
|
||||
/* sourceSpan */ undefined, true);
|
||||
return new o.BinaryOperatorExpr(o.BinaryOperator.And, jitFlagUndefinedOrTrue, expr);
|
||||
}
|
||||
|
||||
export function wrapReference(value: any): R3Reference {
|
||||
const wrapped = new o.WrappedNodeExpr(value);
|
||||
return {value: wrapped, type: wrapped};
|
||||
}
|
@ -12,6 +12,7 @@ import * as o from '../../output/output_ast';
|
||||
import {ParseSourceSpan} from '../../parse_util';
|
||||
import * as t from '../r3_ast';
|
||||
import {R3DependencyMetadata} from '../r3_factory';
|
||||
import {R3Reference} from '../util';
|
||||
|
||||
|
||||
/**
|
||||
@ -26,7 +27,7 @@ export interface R3DirectiveMetadata {
|
||||
/**
|
||||
* An expression representing a reference to the directive itself.
|
||||
*/
|
||||
type: o.Expression;
|
||||
type: R3Reference;
|
||||
|
||||
/**
|
||||
* An expression representing a reference to the directive being compiled, intended for use within
|
||||
|
@ -481,7 +481,7 @@ function createTypeForDef(meta: R3DirectiveMetadata, typeBase: o.ExternalReferen
|
||||
const selectorForType = meta.selector !== null ? meta.selector.replace(/\n/g, '') : null;
|
||||
|
||||
return o.expressionType(o.importExpr(typeBase, [
|
||||
typeWithParameters(meta.type, meta.typeArgumentCount),
|
||||
typeWithParameters(meta.type.type, meta.typeArgumentCount),
|
||||
selectorForType !== null ? stringAsType(selectorForType) : o.NONE_TYPE,
|
||||
meta.exportAs !== null ? stringArrayAsType(meta.exportAs) : o.NONE_TYPE,
|
||||
stringMapAsType(meta.inputs),
|
||||
|
Reference in New Issue
Block a user