From a1014b2b13f6662205876046e1c2c01d9d3367ed Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 9 Nov 2017 00:26:33 -0800 Subject: [PATCH] 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 --- src/compiler/checker.ts | 4 + .../decoratorReferenceOnOtherProperty.js | 109 ++++++++++++++++++ .../decoratorReferenceOnOtherProperty.symbols | 46 ++++++++ .../decoratorReferenceOnOtherProperty.types | 46 ++++++++ .../decoratorReferenceOnOtherProperty.ts | 25 ++++ 5 files changed, 230 insertions(+) create mode 100644 tests/baselines/reference/decoratorReferenceOnOtherProperty.js create mode 100644 tests/baselines/reference/decoratorReferenceOnOtherProperty.symbols create mode 100644 tests/baselines/reference/decoratorReferenceOnOtherProperty.types create mode 100644 tests/cases/compiler/decoratorReferenceOnOtherProperty.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f619805628a..a9aaa77fa74 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20262,6 +20262,10 @@ namespace ts { case SyntaxKind.Parameter: markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(node)); + const containingSignature = (node as ParameterDeclaration).parent; + for (const parameter of containingSignature.parameters) { + markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(parameter)); + } break; } } diff --git a/tests/baselines/reference/decoratorReferenceOnOtherProperty.js b/tests/baselines/reference/decoratorReferenceOnOtherProperty.js new file mode 100644 index 00000000000..6313f339ba9 --- /dev/null +++ b/tests/baselines/reference/decoratorReferenceOnOtherProperty.js @@ -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; +}()); diff --git a/tests/baselines/reference/decoratorReferenceOnOtherProperty.symbols b/tests/baselines/reference/decoratorReferenceOnOtherProperty.symbols new file mode 100644 index 00000000000..619e2afe4e9 --- /dev/null +++ b/tests/baselines/reference/decoratorReferenceOnOtherProperty.symbols @@ -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)) + + // ^^^^ +} diff --git a/tests/baselines/reference/decoratorReferenceOnOtherProperty.types b/tests/baselines/reference/decoratorReferenceOnOtherProperty.types new file mode 100644 index 00000000000..5994657aa31 --- /dev/null +++ b/tests/baselines/reference/decoratorReferenceOnOtherProperty.types @@ -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 + + // ^^^^ +} diff --git a/tests/cases/compiler/decoratorReferenceOnOtherProperty.ts b/tests/cases/compiler/decoratorReferenceOnOtherProperty.ts new file mode 100644 index 00000000000..c7465471ed8 --- /dev/null +++ b/tests/cases/compiler/decoratorReferenceOnOtherProperty.ts @@ -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[]) {} + // ^^^^ +} \ No newline at end of file