Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix for #2971, adds missing logic in checkFunctionExpressionBodies #3227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6605,7 +6605,7 @@ module ts {
result.splice(spliceIndex, 0, signature);
}
}

function getSpreadArgumentIndex(args: Expression[]): number {
for (let i = 0; i < args.length; i++) {
if (args[i].kind === SyntaxKind.SpreadElementExpression) {
Expand Down Expand Up @@ -10914,6 +10914,7 @@ module ts {
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
forEach(node.decorators, checkFunctionExpressionBodies);
forEach((<MethodDeclaration>node).parameters, checkFunctionExpressionBodies);
if (isObjectLiteralMethod(node)) {
checkFunctionExpressionOrObjectLiteralMethodBody(<MethodDeclaration>node);
Expand All @@ -10928,6 +10929,7 @@ module ts {
case SyntaxKind.WithStatement:
checkFunctionExpressionBodies((<WithStatement>node).expression);
break;
case SyntaxKind.Decorator:
case SyntaxKind.Parameter:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
Expand Down
21 changes: 21 additions & 0 deletions tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt
Original file line number Diff line number Diff line change
@@ -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() {

}
}
44 changes: 44 additions & 0 deletions tests/baselines/reference/decoratorChecksFunctionBodies.js
Original file line number Diff line number Diff line change
@@ -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;
})();
Original file line number Diff line number Diff line change
@@ -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;
})();
Original file line number Diff line number Diff line change
@@ -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))

// ...
}
}
Original file line number Diff line number Diff line change
@@ -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

// ...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @target:es5

// from #2971
function func(s: string): void {
}

class A {
@(x => {
var a = 3;
func(a);
return x;
})
m() {

}
}
Original file line number Diff line number Diff line change
@@ -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() {
// ...
}
}