Skip to content

Commit a1014b2

Browse files
authored
Mark all parameters as needed for metadata when one is decorated (microsoft#19849)
* Mark all properties as needed for metadata when one is decorated * Add restarg test
1 parent ceaeffa commit a1014b2

5 files changed

+230
-0
lines changed

src/compiler/checker.ts

+4
Original file line numberDiff line numberDiff line change
@@ -20262,6 +20262,10 @@ namespace ts {
2026220262

2026320263
case SyntaxKind.Parameter:
2026420264
markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(<ParameterDeclaration>node));
20265+
const containingSignature = (node as ParameterDeclaration).parent;
20266+
for (const parameter of containingSignature.parameters) {
20267+
markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(parameter));
20268+
}
2026520269
break;
2026620270
}
2026720271
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//// [tests/cases/compiler/decoratorReferenceOnOtherProperty.ts] ////
2+
3+
//// [yoha.ts]
4+
// https://github.com/Microsoft/TypeScript/issues/19799
5+
export class Yoha {}
6+
7+
//// [index.ts]
8+
import {Yoha} from './yoha';
9+
10+
function foo(...args: any[]) {}
11+
12+
class Bar {
13+
yoha(@foo yoha, bar: Yoha) {}
14+
// ^^^^
15+
}
16+
17+
//// [index2.ts]
18+
import {Yoha} from './yoha';
19+
20+
function foo(...args: any[]) {}
21+
22+
class Bar {
23+
yoha(@foo yoha, ...bar: Yoha[]) {}
24+
// ^^^^
25+
}
26+
27+
//// [yoha.js]
28+
"use strict";
29+
exports.__esModule = true;
30+
// https://github.com/Microsoft/TypeScript/issues/19799
31+
var Yoha = /** @class */ (function () {
32+
function Yoha() {
33+
}
34+
return Yoha;
35+
}());
36+
exports.Yoha = Yoha;
37+
//// [index.js]
38+
"use strict";
39+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
40+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
42+
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;
43+
return c > 3 && r && Object.defineProperty(target, key, r), r;
44+
};
45+
var __metadata = (this && this.__metadata) || function (k, v) {
46+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
47+
};
48+
var __param = (this && this.__param) || function (paramIndex, decorator) {
49+
return function (target, key) { decorator(target, key, paramIndex); }
50+
};
51+
exports.__esModule = true;
52+
var yoha_1 = require("./yoha");
53+
function foo() {
54+
var args = [];
55+
for (var _i = 0; _i < arguments.length; _i++) {
56+
args[_i] = arguments[_i];
57+
}
58+
}
59+
var Bar = /** @class */ (function () {
60+
function Bar() {
61+
}
62+
Bar.prototype.yoha = function (yoha, bar) { };
63+
__decorate([
64+
__param(0, foo),
65+
__metadata("design:type", Function),
66+
__metadata("design:paramtypes", [Object, yoha_1.Yoha]),
67+
__metadata("design:returntype", void 0)
68+
], Bar.prototype, "yoha");
69+
return Bar;
70+
}());
71+
//// [index2.js]
72+
"use strict";
73+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
74+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
75+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
76+
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;
77+
return c > 3 && r && Object.defineProperty(target, key, r), r;
78+
};
79+
var __metadata = (this && this.__metadata) || function (k, v) {
80+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
81+
};
82+
var __param = (this && this.__param) || function (paramIndex, decorator) {
83+
return function (target, key) { decorator(target, key, paramIndex); }
84+
};
85+
exports.__esModule = true;
86+
var yoha_1 = require("./yoha");
87+
function foo() {
88+
var args = [];
89+
for (var _i = 0; _i < arguments.length; _i++) {
90+
args[_i] = arguments[_i];
91+
}
92+
}
93+
var Bar = /** @class */ (function () {
94+
function Bar() {
95+
}
96+
Bar.prototype.yoha = function (yoha) {
97+
var bar = [];
98+
for (var _i = 1; _i < arguments.length; _i++) {
99+
bar[_i - 1] = arguments[_i];
100+
}
101+
};
102+
__decorate([
103+
__param(0, foo),
104+
__metadata("design:type", Function),
105+
__metadata("design:paramtypes", [Object, yoha_1.Yoha]),
106+
__metadata("design:returntype", void 0)
107+
], Bar.prototype, "yoha");
108+
return Bar;
109+
}());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
=== tests/cases/compiler/yoha.ts ===
2+
// https://github.com/Microsoft/TypeScript/issues/19799
3+
export class Yoha {}
4+
>Yoha : Symbol(Yoha, Decl(yoha.ts, 0, 0))
5+
6+
=== tests/cases/compiler/index.ts ===
7+
import {Yoha} from './yoha';
8+
>Yoha : Symbol(Yoha, Decl(index.ts, 0, 8))
9+
10+
function foo(...args: any[]) {}
11+
>foo : Symbol(foo, Decl(index.ts, 0, 28))
12+
>args : Symbol(args, Decl(index.ts, 2, 13))
13+
14+
class Bar {
15+
>Bar : Symbol(Bar, Decl(index.ts, 2, 31))
16+
17+
yoha(@foo yoha, bar: Yoha) {}
18+
>yoha : Symbol(Bar.yoha, Decl(index.ts, 4, 11))
19+
>foo : Symbol(foo, Decl(index.ts, 0, 28))
20+
>yoha : Symbol(yoha, Decl(index.ts, 5, 7))
21+
>bar : Symbol(bar, Decl(index.ts, 5, 17))
22+
>Yoha : Symbol(Yoha, Decl(index.ts, 0, 8))
23+
24+
// ^^^^
25+
}
26+
27+
=== tests/cases/compiler/index2.ts ===
28+
import {Yoha} from './yoha';
29+
>Yoha : Symbol(Yoha, Decl(index2.ts, 0, 8))
30+
31+
function foo(...args: any[]) {}
32+
>foo : Symbol(foo, Decl(index2.ts, 0, 28))
33+
>args : Symbol(args, Decl(index2.ts, 2, 13))
34+
35+
class Bar {
36+
>Bar : Symbol(Bar, Decl(index2.ts, 2, 31))
37+
38+
yoha(@foo yoha, ...bar: Yoha[]) {}
39+
>yoha : Symbol(Bar.yoha, Decl(index2.ts, 4, 11))
40+
>foo : Symbol(foo, Decl(index2.ts, 0, 28))
41+
>yoha : Symbol(yoha, Decl(index2.ts, 5, 7))
42+
>bar : Symbol(bar, Decl(index2.ts, 5, 17))
43+
>Yoha : Symbol(Yoha, Decl(index2.ts, 0, 8))
44+
45+
// ^^^^
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
=== tests/cases/compiler/yoha.ts ===
2+
// https://github.com/Microsoft/TypeScript/issues/19799
3+
export class Yoha {}
4+
>Yoha : Yoha
5+
6+
=== tests/cases/compiler/index.ts ===
7+
import {Yoha} from './yoha';
8+
>Yoha : typeof Yoha
9+
10+
function foo(...args: any[]) {}
11+
>foo : (...args: any[]) => void
12+
>args : any[]
13+
14+
class Bar {
15+
>Bar : Bar
16+
17+
yoha(@foo yoha, bar: Yoha) {}
18+
>yoha : (yoha: any, bar: Yoha) => void
19+
>foo : (...args: any[]) => void
20+
>yoha : any
21+
>bar : Yoha
22+
>Yoha : Yoha
23+
24+
// ^^^^
25+
}
26+
27+
=== tests/cases/compiler/index2.ts ===
28+
import {Yoha} from './yoha';
29+
>Yoha : typeof Yoha
30+
31+
function foo(...args: any[]) {}
32+
>foo : (...args: any[]) => void
33+
>args : any[]
34+
35+
class Bar {
36+
>Bar : Bar
37+
38+
yoha(@foo yoha, ...bar: Yoha[]) {}
39+
>yoha : (yoha: any, ...bar: Yoha[]) => void
40+
>foo : (...args: any[]) => void
41+
>yoha : any
42+
>bar : Yoha[]
43+
>Yoha : Yoha
44+
45+
// ^^^^
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// https://github.com/Microsoft/TypeScript/issues/19799
2+
// @experimentalDecorators: true
3+
// @emitDecoratorMetadata: true
4+
// @filename: yoha.ts
5+
export class Yoha {}
6+
7+
// @filename: index.ts
8+
import {Yoha} from './yoha';
9+
10+
function foo(...args: any[]) {}
11+
12+
class Bar {
13+
yoha(@foo yoha, bar: Yoha) {}
14+
// ^^^^
15+
}
16+
17+
// @filename: index2.ts
18+
import {Yoha} from './yoha';
19+
20+
function foo(...args: any[]) {}
21+
22+
class Bar {
23+
yoha(@foo yoha, ...bar: Yoha[]) {}
24+
// ^^^^
25+
}

0 commit comments

Comments
 (0)