Skip to content

Commit 44766b4

Browse files
committed
Make sure arrow function grammar rules can deal with type annotations
1 parent 9d2bb4e commit 44766b4

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,7 +4392,7 @@ module ts {
43924392
}
43934393

43944394
/**
4395-
* Check if a Type was written as a tuple type literal.
4395+
* Check if a Type was written as a tuple type literal.
43964396
* Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
43974397
*/
43984398
function isTupleType(type: Type) : boolean {
@@ -11364,9 +11364,9 @@ module ts {
1136411364
if (node.kind === SyntaxKind.ArrowFunction) {
1136511365
var arrowFunction = <ArrowFunction>node;
1136611366
var sourceFile = getSourceFileOfNode(node);
11367-
var equalsGreaterThanLine = getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.equalsGreaterThanToken, sourceFile)).line;
11368-
var parametersLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line;
11369-
if (equalsGreaterThanLine !== parametersLine) {
11367+
var startLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.pos).line;
11368+
var endLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.end).line;
11369+
if (startLine !== endLine) {
1137011370
return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow);
1137111371
}
1137211372
}

tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(2
1212
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(31,13): error TS1200: Line terminator not permitted before arrow.
1313
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(36,13): error TS1200: Line terminator not permitted before arrow.
1414
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(40,9): error TS1200: Line terminator not permitted before arrow.
15+
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(44,5): error TS1200: Line terminator not permitted before arrow.
1516

1617

17-
==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (14 errors) ====
18+
==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (15 errors) ====
1819
var f1 = ()
1920
=> { }
2021
~~
@@ -84,4 +85,21 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4
8485
~~
8586
!!! error TS1200: Line terminator not permitted before arrow.
8687
}
88+
89+
var func = (a: number): number
90+
=> a;
91+
~~
92+
!!! error TS1200: Line terminator not permitted before arrow.
93+
94+
// Should be valid.
95+
var funk = (a: number
96+
) => a;
97+
98+
// Should be valid.
99+
var funkier = (a: number)
100+
: number => a;
101+
102+
// Should be valid.
103+
var funkiest = (a: number):
104+
number => a;
87105

tests/baselines/reference/disallowLineTerminatorBeforeArrow.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ module m {
4040
export var v = x
4141
=> new City(Enum.claw);
4242
}
43+
44+
var func = (a: number): number
45+
=> a;
46+
47+
// Should be valid.
48+
var funk = (a: number
49+
) => a;
50+
51+
// Should be valid.
52+
var funkier = (a: number)
53+
: number => a;
54+
55+
// Should be valid.
56+
var funkiest = (a: number):
57+
number => a;
4358

4459

4560
//// [disallowLineTerminatorBeforeArrow.js]
@@ -108,3 +123,18 @@ var m;
108123
return new City(Enum.claw);
109124
};
110125
})(m || (m = {}));
126+
var func = function (a) {
127+
return a;
128+
};
129+
// Should be valid.
130+
var funk = function (a) {
131+
return a;
132+
};
133+
// Should be valid.
134+
var funkier = function (a) {
135+
return a;
136+
};
137+
// Should be valid.
138+
var funkiest = function (a) {
139+
return a;
140+
};

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,18 @@ module m {
3939
export var v = x
4040
=> new City(Enum.claw);
4141
}
42+
43+
var func = (a: number): number
44+
=> a;
45+
46+
// Should be valid.
47+
var funk = (a: number
48+
) => a;
49+
50+
// Should be valid.
51+
var funkier = (a: number)
52+
: number => a;
53+
54+
// Should be valid.
55+
var funkiest = (a: number):
56+
number => a;

0 commit comments

Comments
 (0)