Skip to content

Commit 10925c1

Browse files
committed
Make sure arrow function grammar rules can deal with type annotations
1 parent 3dc5faf commit 10925c1

File tree

4 files changed

+155
-11
lines changed

4 files changed

+155
-11
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4412,7 +4412,7 @@ module ts {
44124412
}
44134413

44144414
/**
4415-
* Check if a Type was written as a tuple type literal.
4415+
* Check if a Type was written as a tuple type literal.
44164416
* Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
44174417
*/
44184418
function isTupleType(type: Type) : boolean {
@@ -11384,9 +11384,9 @@ module ts {
1138411384
if (node.kind === SyntaxKind.ArrowFunction) {
1138511385
var arrowFunction = <ArrowFunction>node;
1138611386
var sourceFile = getSourceFileOfNode(node);
11387-
var equalsGreaterThanLine = getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.equalsGreaterThanToken, sourceFile)).line;
11388-
var parametersLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line;
11389-
if (equalsGreaterThanLine !== parametersLine) {
11387+
var startLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.pos).line;
11388+
var endLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.end).line;
11389+
if (startLine !== endLine) {
1139011390
return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow);
1139111391
}
1139211392
}

tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(1
66
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(12,7): error TS1200: Line terminator not permitted before arrow.
77
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(14,5): error TS1200: Line terminator not permitted before arrow.
88
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(16,7): error TS1200: Line terminator not permitted before arrow.
9-
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(20,5): error TS1200: Line terminator not permitted before arrow.
10-
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,5): error TS1200: Line terminator not permitted before arrow.
11-
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(27,13): error TS1200: Line terminator not permitted before arrow.
12-
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(31,13): error TS1200: Line terminator not permitted before arrow.
13-
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(36,13): error TS1200: Line terminator not permitted before arrow.
14-
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(40,9): error TS1200: Line terminator not permitted before arrow.
9+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(18,5): error TS1200: Line terminator not permitted before arrow.
10+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,5): error TS1200: Line terminator not permitted before arrow.
11+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(23,8): error TS1200: Line terminator not permitted before arrow.
12+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(26,8): error TS1200: Line terminator not permitted before arrow.
13+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(52,5): error TS1200: Line terminator not permitted before arrow.
14+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(54,5): error TS1200: Line terminator not permitted before arrow.
15+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(59,13): error TS1200: Line terminator not permitted before arrow.
16+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(63,13): error TS1200: Line terminator not permitted before arrow.
17+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(68,13): error TS1200: Line terminator not permitted before arrow.
18+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(72,9): error TS1200: Line terminator not permitted before arrow.
1519

1620

17-
==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (14 errors) ====
21+
==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (18 errors) ====
1822
var f1 = ()
1923
=> { }
2024
~~
@@ -47,6 +51,46 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4
4751
*/ => { }
4852
~~
4953
!!! error TS1200: Line terminator not permitted before arrow.
54+
var f9 = (a: number): number
55+
=> a;
56+
~~
57+
!!! error TS1200: Line terminator not permitted before arrow.
58+
var f10 = (a: number) :
59+
number
60+
=> a
61+
~~
62+
!!! error TS1200: Line terminator not permitted before arrow.
63+
var f11 = (a: number): number /*
64+
*/ => a;
65+
~~
66+
!!! error TS1200: Line terminator not permitted before arrow.
67+
var f12 = (a: number) :
68+
number /*
69+
*/ => a
70+
~~
71+
!!! error TS1200: Line terminator not permitted before arrow.
72+
73+
// Should be valid.
74+
var f11 = (a: number
75+
) => a;
76+
77+
// Should be valid.
78+
var f12 = (a: number)
79+
: number => a;
80+
81+
// Should be valid.
82+
var f13 = (a: number):
83+
number => a;
84+
85+
// Should be valid.
86+
var f14 = () /* */ => {}
87+
88+
// Should be valid.
89+
var f15 = (a: number): number /* */ => a
90+
91+
// Should be valid.
92+
var f16 = (a: number, b = 10):
93+
number /* */ => a + b;
5094

5195
function foo(func: () => boolean) { }
5296
foo(()

tests/baselines/reference/disallowLineTerminatorBeforeArrow.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,38 @@ var f7 = (x: string, y: number, z = 10)
1515
=> { }
1616
var f8 = (x: string, y: number, z = 10) /*
1717
*/ => { }
18+
var f9 = (a: number): number
19+
=> a;
20+
var f10 = (a: number) :
21+
number
22+
=> a
23+
var f11 = (a: number): number /*
24+
*/ => a;
25+
var f12 = (a: number) :
26+
number /*
27+
*/ => a
28+
29+
// Should be valid.
30+
var f11 = (a: number
31+
) => a;
32+
33+
// Should be valid.
34+
var f12 = (a: number)
35+
: number => a;
36+
37+
// Should be valid.
38+
var f13 = (a: number):
39+
number => a;
40+
41+
// Should be valid.
42+
var f14 = () /* */ => {}
43+
44+
// Should be valid.
45+
var f15 = (a: number): number /* */ => a
46+
47+
// Should be valid.
48+
var f16 = (a: number, b = 10):
49+
number /* */ => a + b;
1850

1951
function foo(func: () => boolean) { }
2052
foo(()
@@ -77,6 +109,42 @@ var f7 = function (x, y, z) {
77109
var f8 = function (x, y, z) {
78110
if (z === void 0) { z = 10; }
79111
};
112+
var f9 = function (a) {
113+
return a;
114+
};
115+
var f10 = function (a) {
116+
return a;
117+
};
118+
var f11 = function (a) {
119+
return a;
120+
};
121+
var f12 = function (a) {
122+
return a;
123+
};
124+
// Should be valid.
125+
var f11 = function (a) {
126+
return a;
127+
};
128+
// Should be valid.
129+
var f12 = function (a) {
130+
return a;
131+
};
132+
// Should be valid.
133+
var f13 = function (a) {
134+
return a;
135+
};
136+
// Should be valid.
137+
var f14 = function () {
138+
};
139+
// Should be valid.
140+
var f15 = function (a) {
141+
return a;
142+
};
143+
// Should be valid.
144+
var f16 = function (a, b) {
145+
if (b === void 0) { b = 10; }
146+
return a + b;
147+
};
80148
function foo(func) {
81149
}
82150
foo(function () {

tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,38 @@ var f7 = (x: string, y: number, z = 10)
1414
=> { }
1515
var f8 = (x: string, y: number, z = 10) /*
1616
*/ => { }
17+
var f9 = (a: number): number
18+
=> a;
19+
var f10 = (a: number) :
20+
number
21+
=> a
22+
var f11 = (a: number): number /*
23+
*/ => a;
24+
var f12 = (a: number) :
25+
number /*
26+
*/ => a
27+
28+
// Should be valid.
29+
var f11 = (a: number
30+
) => a;
31+
32+
// Should be valid.
33+
var f12 = (a: number)
34+
: number => a;
35+
36+
// Should be valid.
37+
var f13 = (a: number):
38+
number => a;
39+
40+
// Should be valid.
41+
var f14 = () /* */ => {}
42+
43+
// Should be valid.
44+
var f15 = (a: number): number /* */ => a
45+
46+
// Should be valid.
47+
var f16 = (a: number, b = 10):
48+
number /* */ => a + b;
1749

1850
function foo(func: () => boolean) { }
1951
foo(()

0 commit comments

Comments
 (0)