From e76f920e75f002041e1c53a3fda0fad1bf93c16e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 19 May 2015 22:07:45 -0700 Subject: [PATCH] Added tests --- .../decoratorChecksFunctionBodies.errors.txt | 21 ++++++++ .../decoratorChecksFunctionBodies.js | 44 +++++++++++++++ ...ratorInstantiateModulesInFunctionBodies.js | 53 +++++++++++++++++++ ...InstantiateModulesInFunctionBodies.symbols | 34 ++++++++++++ ...orInstantiateModulesInFunctionBodies.types | 40 ++++++++++++++ .../class/decoratorChecksFunctionBodies.ts | 16 ++++++ ...ratorInstantiateModulesInFunctionBodies.ts | 22 ++++++++ 7 files changed, 230 insertions(+) create mode 100644 tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt create mode 100644 tests/baselines/reference/decoratorChecksFunctionBodies.js create mode 100644 tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js create mode 100644 tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols create mode 100644 tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types create mode 100644 tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts create mode 100644 tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts diff --git a/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt b/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt new file mode 100644 index 00000000000..c8166b538fd --- /dev/null +++ b/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts(9,14): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. + + +==== tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts (1 errors) ==== + + // from #2971 + function func(s: string): void { + } + + class A { + @(x => { + var a = 3; + func(a); + ~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. + return x; + }) + m() { + + } + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorChecksFunctionBodies.js b/tests/baselines/reference/decoratorChecksFunctionBodies.js new file mode 100644 index 00000000000..020bc775aea --- /dev/null +++ b/tests/baselines/reference/decoratorChecksFunctionBodies.js @@ -0,0 +1,44 @@ +//// [decoratorChecksFunctionBodies.ts] + +// from #2971 +function func(s: string): void { +} + +class A { + @(x => { + var a = 3; + func(a); + return x; + }) + m() { + + } +} + +//// [decoratorChecksFunctionBodies.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +// from #2971 +function func(s) { +} +var A = (function () { + function A() { + } + A.prototype.m = function () { + }; + Object.defineProperty(A.prototype, "m", + __decorate([ + (function (x) { + var a = 3; + func(a); + return x; + }) + ], A.prototype, "m", Object.getOwnPropertyDescriptor(A.prototype, "m"))); + return A; +})(); diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js new file mode 100644 index 00000000000..313d77fa5ce --- /dev/null +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js @@ -0,0 +1,53 @@ +//// [tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts] //// + +//// [a.ts] + +// from #3108 +export var test = 'abc'; + +//// [b.ts] +import { test } from './a'; + +function filter(handler: any) { + return function (target: any) { + // ... + }; +} + +class Wat { + @filter(() => test == 'abc') + static whatever() { + // ... + } +} + +//// [a.js] +// from #3108 +exports.test = 'abc'; +//// [b.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +var a_1 = require('./a'); +function filter(handler) { + return function (target) { + // ... + }; +} +var Wat = (function () { + function Wat() { + } + Wat.whatever = function () { + // ... + }; + Object.defineProperty(Wat, "whatever", + __decorate([ + filter(function () { return a_1.test == 'abc'; }) + ], Wat, "whatever", Object.getOwnPropertyDescriptor(Wat, "whatever"))); + return Wat; +})(); diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols new file mode 100644 index 00000000000..5088e740a57 --- /dev/null +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +// from #3108 +export var test = 'abc'; +>test : Symbol(test, Decl(a.ts, 2, 10)) + +=== tests/cases/conformance/decorators/class/b.ts === +import { test } from './a'; +>test : Symbol(test, Decl(b.ts, 0, 8)) + +function filter(handler: any) { +>filter : Symbol(filter, Decl(b.ts, 0, 27)) +>handler : Symbol(handler, Decl(b.ts, 2, 16)) + + return function (target: any) { +>target : Symbol(target, Decl(b.ts, 3, 21)) + + // ... + }; +} + +class Wat { +>Wat : Symbol(Wat, Decl(b.ts, 6, 1)) + + @filter(() => test == 'abc') +>filter : Symbol(filter, Decl(b.ts, 0, 27)) +>test : Symbol(test, Decl(b.ts, 0, 8)) + + static whatever() { +>whatever : Symbol(Wat.whatever, Decl(b.ts, 8, 11)) + + // ... + } +} diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types new file mode 100644 index 00000000000..18d993af9bb --- /dev/null +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types @@ -0,0 +1,40 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +// from #3108 +export var test = 'abc'; +>test : string +>'abc' : string + +=== tests/cases/conformance/decorators/class/b.ts === +import { test } from './a'; +>test : string + +function filter(handler: any) { +>filter : (handler: any) => (target: any) => void +>handler : any + + return function (target: any) { +>function (target: any) { // ... } : (target: any) => void +>target : any + + // ... + }; +} + +class Wat { +>Wat : Wat + + @filter(() => test == 'abc') +>filter(() => test == 'abc') : (target: any) => void +>filter : (handler: any) => (target: any) => void +>() => test == 'abc' : () => boolean +>test == 'abc' : boolean +>test : string +>'abc' : string + + static whatever() { +>whatever : () => void + + // ... + } +} diff --git a/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts b/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts new file mode 100644 index 00000000000..31f5fe82551 --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts @@ -0,0 +1,16 @@ +// @target:es5 + +// from #2971 +function func(s: string): void { +} + +class A { + @(x => { + var a = 3; + func(a); + return x; + }) + m() { + + } +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts b/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts new file mode 100644 index 00000000000..7fa7ab8dd84 --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts @@ -0,0 +1,22 @@ +// @target:es5 +// @module:commonjs +// @filename: a.ts + +// from #3108 +export var test = 'abc'; + +// @filename: b.ts +import { test } from './a'; + +function filter(handler: any) { + return function (target: any) { + // ... + }; +} + +class Wat { + @filter(() => test == 'abc') + static whatever() { + // ... + } +} \ No newline at end of file