Skip to content

Commit a8b4a3b

Browse files
authored
fix(52061): Constructor parameters exported as type included in emitted metadata (#52138)
1 parent df6b9e5 commit a8b4a3b

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45812,7 +45812,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4581245812
}
4581345813
const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, location);
4581445814
const resolvedSymbol = valueSymbol && valueSymbol.flags & SymbolFlags.Alias ? resolveAlias(valueSymbol) : valueSymbol;
45815-
isTypeOnly ||= !!valueSymbol?.declarations?.every(isTypeOnlyImportOrExportDeclaration);
45815+
isTypeOnly ||= !!(valueSymbol && getTypeOnlyAliasDeclaration(valueSymbol, SymbolFlags.Value));
4581645816

4581745817
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
4581845818
const typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//// [tests/cases/compiler/decoratorMetadataTypeOnlyExport.ts] ////
2+
3+
//// [a.ts]
4+
class Foo {}
5+
export type { Foo };
6+
7+
//// [b.ts]
8+
import { Foo } from "./a";
9+
10+
const Decorator: ClassDecorator = () => undefined;
11+
12+
@Decorator
13+
class Bar {
14+
constructor(par: Foo) {}
15+
}
16+
17+
18+
//// [a.js]
19+
"use strict";
20+
Object.defineProperty(exports, "__esModule", { value: true });
21+
var Foo = /** @class */ (function () {
22+
function Foo() {
23+
}
24+
return Foo;
25+
}());
26+
//// [b.js]
27+
"use strict";
28+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
29+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31+
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;
32+
return c > 3 && r && Object.defineProperty(target, key, r), r;
33+
};
34+
var __metadata = (this && this.__metadata) || function (k, v) {
35+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
36+
};
37+
Object.defineProperty(exports, "__esModule", { value: true });
38+
var Decorator = function () { return undefined; };
39+
var Bar = /** @class */ (function () {
40+
function Bar(par) {
41+
}
42+
Bar = __decorate([
43+
Decorator,
44+
__metadata("design:paramtypes", [Function])
45+
], Bar);
46+
return Bar;
47+
}());
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/compiler/a.ts ===
2+
class Foo {}
3+
>Foo : Symbol(Foo, Decl(a.ts, 0, 0))
4+
5+
export type { Foo };
6+
>Foo : Symbol(Foo, Decl(a.ts, 1, 13))
7+
8+
=== tests/cases/compiler/b.ts ===
9+
import { Foo } from "./a";
10+
>Foo : Symbol(Foo, Decl(b.ts, 0, 8))
11+
12+
const Decorator: ClassDecorator = () => undefined;
13+
>Decorator : Symbol(Decorator, Decl(b.ts, 2, 5))
14+
>ClassDecorator : Symbol(ClassDecorator, Decl(lib.decorators.legacy.d.ts, --, --))
15+
>undefined : Symbol(undefined)
16+
17+
@Decorator
18+
>Decorator : Symbol(Decorator, Decl(b.ts, 2, 5))
19+
20+
class Bar {
21+
>Bar : Symbol(Bar, Decl(b.ts, 2, 50))
22+
23+
constructor(par: Foo) {}
24+
>par : Symbol(par, Decl(b.ts, 6, 16))
25+
>Foo : Symbol(Foo, Decl(b.ts, 0, 8))
26+
}
27+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/a.ts ===
2+
class Foo {}
3+
>Foo : Foo
4+
5+
export type { Foo };
6+
>Foo : Foo
7+
8+
=== tests/cases/compiler/b.ts ===
9+
import { Foo } from "./a";
10+
>Foo : typeof Foo
11+
12+
const Decorator: ClassDecorator = () => undefined;
13+
>Decorator : ClassDecorator
14+
>() => undefined : () => any
15+
>undefined : undefined
16+
17+
@Decorator
18+
>Decorator : ClassDecorator
19+
20+
class Bar {
21+
>Bar : Bar
22+
23+
constructor(par: Foo) {}
24+
>par : Foo
25+
}
26+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @experimentalDecorators: true
2+
// @emitDecoratorMetadata: true
3+
4+
// @filename: ./a.ts
5+
class Foo {}
6+
export type { Foo };
7+
8+
// @filename: ./b.ts
9+
import { Foo } from "./a";
10+
11+
const Decorator: ClassDecorator = () => undefined;
12+
13+
@Decorator
14+
class Bar {
15+
constructor(par: Foo) {}
16+
}

0 commit comments

Comments
 (0)