Make sure arrow function grammar rules can deal with type annotations

This commit is contained in:
Caitlin Potter
2015-03-14 19:51:42 -04:00
parent 3dc5faf707
commit 10925c1e9b
4 changed files with 155 additions and 11 deletions
+4 -4
View File
@@ -4412,7 +4412,7 @@ module ts {
}
/**
* Check if a Type was written as a tuple type literal.
* Check if a Type was written as a tuple type literal.
* Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
*/
function isTupleType(type: Type) : boolean {
@@ -11384,9 +11384,9 @@ module ts {
if (node.kind === SyntaxKind.ArrowFunction) {
var arrowFunction = <ArrowFunction>node;
var sourceFile = getSourceFileOfNode(node);
var equalsGreaterThanLine = getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.equalsGreaterThanToken, sourceFile)).line;
var parametersLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line;
if (equalsGreaterThanLine !== parametersLine) {
var startLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.pos).line;
var endLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.end).line;
if (startLine !== endLine) {
return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow);
}
}
@@ -6,15 +6,19 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(1
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(12,7): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(14,5): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(16,7): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(20,5): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,5): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(27,13): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(31,13): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(36,13): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(40,9): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(18,5): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,5): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(23,8): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(26,8): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(52,5): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(54,5): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(59,13): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(63,13): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(68,13): error TS1200: Line terminator not permitted before arrow.
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(72,9): error TS1200: Line terminator not permitted before arrow.
==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (14 errors) ====
==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (18 errors) ====
var f1 = ()
=> { }
~~
@@ -47,6 +51,46 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4
*/ => { }
~~
!!! error TS1200: Line terminator not permitted before arrow.
var f9 = (a: number): number
=> a;
~~
!!! error TS1200: Line terminator not permitted before arrow.
var f10 = (a: number) :
number
=> a
~~
!!! error TS1200: Line terminator not permitted before arrow.
var f11 = (a: number): number /*
*/ => a;
~~
!!! error TS1200: Line terminator not permitted before arrow.
var f12 = (a: number) :
number /*
*/ => a
~~
!!! error TS1200: Line terminator not permitted before arrow.
// Should be valid.
var f11 = (a: number
) => a;
// Should be valid.
var f12 = (a: number)
: number => a;
// Should be valid.
var f13 = (a: number):
number => a;
// Should be valid.
var f14 = () /* */ => {}
// Should be valid.
var f15 = (a: number): number /* */ => a
// Should be valid.
var f16 = (a: number, b = 10):
number /* */ => a + b;
function foo(func: () => boolean) { }
foo(()
@@ -15,6 +15,38 @@ var f7 = (x: string, y: number, z = 10)
=> { }
var f8 = (x: string, y: number, z = 10) /*
*/ => { }
var f9 = (a: number): number
=> a;
var f10 = (a: number) :
number
=> a
var f11 = (a: number): number /*
*/ => a;
var f12 = (a: number) :
number /*
*/ => a
// Should be valid.
var f11 = (a: number
) => a;
// Should be valid.
var f12 = (a: number)
: number => a;
// Should be valid.
var f13 = (a: number):
number => a;
// Should be valid.
var f14 = () /* */ => {}
// Should be valid.
var f15 = (a: number): number /* */ => a
// Should be valid.
var f16 = (a: number, b = 10):
number /* */ => a + b;
function foo(func: () => boolean) { }
foo(()
@@ -77,6 +109,42 @@ var f7 = function (x, y, z) {
var f8 = function (x, y, z) {
if (z === void 0) { z = 10; }
};
var f9 = function (a) {
return a;
};
var f10 = function (a) {
return a;
};
var f11 = function (a) {
return a;
};
var f12 = function (a) {
return a;
};
// Should be valid.
var f11 = function (a) {
return a;
};
// Should be valid.
var f12 = function (a) {
return a;
};
// Should be valid.
var f13 = function (a) {
return a;
};
// Should be valid.
var f14 = function () {
};
// Should be valid.
var f15 = function (a) {
return a;
};
// Should be valid.
var f16 = function (a, b) {
if (b === void 0) { b = 10; }
return a + b;
};
function foo(func) {
}
foo(function () {
@@ -14,6 +14,38 @@ var f7 = (x: string, y: number, z = 10)
=> { }
var f8 = (x: string, y: number, z = 10) /*
*/ => { }
var f9 = (a: number): number
=> a;
var f10 = (a: number) :
number
=> a
var f11 = (a: number): number /*
*/ => a;
var f12 = (a: number) :
number /*
*/ => a
// Should be valid.
var f11 = (a: number
) => a;
// Should be valid.
var f12 = (a: number)
: number => a;
// Should be valid.
var f13 = (a: number):
number => a;
// Should be valid.
var f14 = () /* */ => {}
// Should be valid.
var f15 = (a: number): number /* */ => a
// Should be valid.
var f16 = (a: number, b = 10):
number /* */ => a + b;
function foo(func: () => boolean) { }
foo(()