fix(52061): Constructor parameters exported as type included in emitted metadata (#52138)

This commit is contained in:
Oleksandr T
2023-02-14 22:03:54 +02:00
committed by GitHub
parent df6b9e5754
commit a8b4a3b637
5 changed files with 117 additions and 1 deletions

View File

@@ -45812,7 +45812,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, location);
const resolvedSymbol = valueSymbol && valueSymbol.flags & SymbolFlags.Alias ? resolveAlias(valueSymbol) : valueSymbol;
isTypeOnly ||= !!valueSymbol?.declarations?.every(isTypeOnlyImportOrExportDeclaration);
isTypeOnly ||= !!(valueSymbol && getTypeOnlyAliasDeclaration(valueSymbol, SymbolFlags.Value));
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
const typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);

View File

@@ -0,0 +1,47 @@
//// [tests/cases/compiler/decoratorMetadataTypeOnlyExport.ts] ////
//// [a.ts]
class Foo {}
export type { Foo };
//// [b.ts]
import { Foo } from "./a";
const Decorator: ClassDecorator = () => undefined;
@Decorator
class Bar {
constructor(par: Foo) {}
}
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Foo = /** @class */ (function () {
function Foo() {
}
return Foo;
}());
//// [b.js]
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var Decorator = function () { return undefined; };
var Bar = /** @class */ (function () {
function Bar(par) {
}
Bar = __decorate([
Decorator,
__metadata("design:paramtypes", [Function])
], Bar);
return Bar;
}());

View File

@@ -0,0 +1,27 @@
=== tests/cases/compiler/a.ts ===
class Foo {}
>Foo : Symbol(Foo, Decl(a.ts, 0, 0))
export type { Foo };
>Foo : Symbol(Foo, Decl(a.ts, 1, 13))
=== tests/cases/compiler/b.ts ===
import { Foo } from "./a";
>Foo : Symbol(Foo, Decl(b.ts, 0, 8))
const Decorator: ClassDecorator = () => undefined;
>Decorator : Symbol(Decorator, Decl(b.ts, 2, 5))
>ClassDecorator : Symbol(ClassDecorator, Decl(lib.decorators.legacy.d.ts, --, --))
>undefined : Symbol(undefined)
@Decorator
>Decorator : Symbol(Decorator, Decl(b.ts, 2, 5))
class Bar {
>Bar : Symbol(Bar, Decl(b.ts, 2, 50))
constructor(par: Foo) {}
>par : Symbol(par, Decl(b.ts, 6, 16))
>Foo : Symbol(Foo, Decl(b.ts, 0, 8))
}

View File

@@ -0,0 +1,26 @@
=== tests/cases/compiler/a.ts ===
class Foo {}
>Foo : Foo
export type { Foo };
>Foo : Foo
=== tests/cases/compiler/b.ts ===
import { Foo } from "./a";
>Foo : typeof Foo
const Decorator: ClassDecorator = () => undefined;
>Decorator : ClassDecorator
>() => undefined : () => any
>undefined : undefined
@Decorator
>Decorator : ClassDecorator
class Bar {
>Bar : Bar
constructor(par: Foo) {}
>par : Foo
}

View File

@@ -0,0 +1,16 @@
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @filename: ./a.ts
class Foo {}
export type { Foo };
// @filename: ./b.ts
import { Foo } from "./a";
const Decorator: ClassDecorator = () => undefined;
@Decorator
class Bar {
constructor(par: Foo) {}
}