Mark all parameters as needed for metadata when one is decorated (#19849)

* Mark all properties as needed for metadata when one is decorated

* Add restarg test
This commit is contained in:
Wesley Wigham
2017-11-09 00:26:33 -08:00
committed by GitHub
parent ceaeffa3ab
commit a1014b2b13
5 changed files with 230 additions and 0 deletions

View File

@@ -20262,6 +20262,10 @@ namespace ts {
case SyntaxKind.Parameter:
markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(<ParameterDeclaration>node));
const containingSignature = (node as ParameterDeclaration).parent;
for (const parameter of containingSignature.parameters) {
markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(parameter));
}
break;
}
}

View File

@@ -0,0 +1,109 @@
//// [tests/cases/compiler/decoratorReferenceOnOtherProperty.ts] ////
//// [yoha.ts]
// https://github.com/Microsoft/TypeScript/issues/19799
export class Yoha {}
//// [index.ts]
import {Yoha} from './yoha';
function foo(...args: any[]) {}
class Bar {
yoha(@foo yoha, bar: Yoha) {}
// ^^^^
}
//// [index2.ts]
import {Yoha} from './yoha';
function foo(...args: any[]) {}
class Bar {
yoha(@foo yoha, ...bar: Yoha[]) {}
// ^^^^
}
//// [yoha.js]
"use strict";
exports.__esModule = true;
// https://github.com/Microsoft/TypeScript/issues/19799
var Yoha = /** @class */ (function () {
function Yoha() {
}
return Yoha;
}());
exports.Yoha = Yoha;
//// [index.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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
exports.__esModule = true;
var yoha_1 = require("./yoha");
function foo() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
}
var Bar = /** @class */ (function () {
function Bar() {
}
Bar.prototype.yoha = function (yoha, bar) { };
__decorate([
__param(0, foo),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, yoha_1.Yoha]),
__metadata("design:returntype", void 0)
], Bar.prototype, "yoha");
return Bar;
}());
//// [index2.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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
exports.__esModule = true;
var yoha_1 = require("./yoha");
function foo() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
}
var Bar = /** @class */ (function () {
function Bar() {
}
Bar.prototype.yoha = function (yoha) {
var bar = [];
for (var _i = 1; _i < arguments.length; _i++) {
bar[_i - 1] = arguments[_i];
}
};
__decorate([
__param(0, foo),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, yoha_1.Yoha]),
__metadata("design:returntype", void 0)
], Bar.prototype, "yoha");
return Bar;
}());

View File

@@ -0,0 +1,46 @@
=== tests/cases/compiler/yoha.ts ===
// https://github.com/Microsoft/TypeScript/issues/19799
export class Yoha {}
>Yoha : Symbol(Yoha, Decl(yoha.ts, 0, 0))
=== tests/cases/compiler/index.ts ===
import {Yoha} from './yoha';
>Yoha : Symbol(Yoha, Decl(index.ts, 0, 8))
function foo(...args: any[]) {}
>foo : Symbol(foo, Decl(index.ts, 0, 28))
>args : Symbol(args, Decl(index.ts, 2, 13))
class Bar {
>Bar : Symbol(Bar, Decl(index.ts, 2, 31))
yoha(@foo yoha, bar: Yoha) {}
>yoha : Symbol(Bar.yoha, Decl(index.ts, 4, 11))
>foo : Symbol(foo, Decl(index.ts, 0, 28))
>yoha : Symbol(yoha, Decl(index.ts, 5, 7))
>bar : Symbol(bar, Decl(index.ts, 5, 17))
>Yoha : Symbol(Yoha, Decl(index.ts, 0, 8))
// ^^^^
}
=== tests/cases/compiler/index2.ts ===
import {Yoha} from './yoha';
>Yoha : Symbol(Yoha, Decl(index2.ts, 0, 8))
function foo(...args: any[]) {}
>foo : Symbol(foo, Decl(index2.ts, 0, 28))
>args : Symbol(args, Decl(index2.ts, 2, 13))
class Bar {
>Bar : Symbol(Bar, Decl(index2.ts, 2, 31))
yoha(@foo yoha, ...bar: Yoha[]) {}
>yoha : Symbol(Bar.yoha, Decl(index2.ts, 4, 11))
>foo : Symbol(foo, Decl(index2.ts, 0, 28))
>yoha : Symbol(yoha, Decl(index2.ts, 5, 7))
>bar : Symbol(bar, Decl(index2.ts, 5, 17))
>Yoha : Symbol(Yoha, Decl(index2.ts, 0, 8))
// ^^^^
}

View File

@@ -0,0 +1,46 @@
=== tests/cases/compiler/yoha.ts ===
// https://github.com/Microsoft/TypeScript/issues/19799
export class Yoha {}
>Yoha : Yoha
=== tests/cases/compiler/index.ts ===
import {Yoha} from './yoha';
>Yoha : typeof Yoha
function foo(...args: any[]) {}
>foo : (...args: any[]) => void
>args : any[]
class Bar {
>Bar : Bar
yoha(@foo yoha, bar: Yoha) {}
>yoha : (yoha: any, bar: Yoha) => void
>foo : (...args: any[]) => void
>yoha : any
>bar : Yoha
>Yoha : Yoha
// ^^^^
}
=== tests/cases/compiler/index2.ts ===
import {Yoha} from './yoha';
>Yoha : typeof Yoha
function foo(...args: any[]) {}
>foo : (...args: any[]) => void
>args : any[]
class Bar {
>Bar : Bar
yoha(@foo yoha, ...bar: Yoha[]) {}
>yoha : (yoha: any, ...bar: Yoha[]) => void
>foo : (...args: any[]) => void
>yoha : any
>bar : Yoha[]
>Yoha : Yoha
// ^^^^
}

View File

@@ -0,0 +1,25 @@
// https://github.com/Microsoft/TypeScript/issues/19799
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @filename: yoha.ts
export class Yoha {}
// @filename: index.ts
import {Yoha} from './yoha';
function foo(...args: any[]) {}
class Bar {
yoha(@foo yoha, bar: Yoha) {}
// ^^^^
}
// @filename: index2.ts
import {Yoha} from './yoha';
function foo(...args: any[]) {}
class Bar {
yoha(@foo yoha, ...bar: Yoha[]) {}
// ^^^^
}