mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Check that arrow is on same line as parameters
This commit is contained in:
@@ -11381,11 +11381,12 @@ module ts {
|
||||
}
|
||||
|
||||
function checkGrammarArrowFunction(node: FunctionLikeDeclaration): boolean {
|
||||
if (node.kind === SyntaxKind.ArrowFunction) {
|
||||
if ((<ArrowFunctionExpression>node).lineTerminatorBeforeArrow) {
|
||||
grammarErrorOnNode(node, Diagnostics.Line_terminator_not_permitted_before_arrow);
|
||||
return true;
|
||||
}
|
||||
if (node.kind === SyntaxKind.ArrowFunction && (<ArrowFunction>node).arrow) {
|
||||
var arrowFunction = <ArrowFunction>node;
|
||||
var sourceFile = getSourceFileOfNode(node);
|
||||
if (getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.arrow, sourceFile)).line !== getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line) {
|
||||
return grammarErrorOnNode(arrowFunction.arrow, Diagnostics.Line_terminator_not_permitted_before_arrow);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+10
-9
@@ -95,6 +95,7 @@ module ts {
|
||||
visitNodes(cbNodes, (<FunctionLikeDeclaration>node).typeParameters) ||
|
||||
visitNodes(cbNodes, (<FunctionLikeDeclaration>node).parameters) ||
|
||||
visitNode(cbNode, (<FunctionLikeDeclaration>node).type) ||
|
||||
visitNode(cbNode, (<ArrowFunction>node).arrow) ||
|
||||
visitNode(cbNode, (<FunctionLikeDeclaration>node).body);
|
||||
case SyntaxKind.TypeReference:
|
||||
return visitNode(cbNode, (<TypeReferenceNode>node).typeName) ||
|
||||
@@ -3006,18 +3007,19 @@ module ts {
|
||||
function parseSimpleArrowFunctionExpression(identifier: Identifier): Expression {
|
||||
Debug.assert(token === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
|
||||
|
||||
let node = <FunctionExpression>createNode(SyntaxKind.ArrowFunction, identifier.pos);
|
||||
let node = <ArrowFunction>createNode(SyntaxKind.ArrowFunction, identifier.pos);
|
||||
|
||||
let parameter = <ParameterDeclaration>createNode(SyntaxKind.Parameter, identifier.pos);
|
||||
parameter.name = identifier;
|
||||
parameter.name = identifier;
|
||||
finishNode(parameter);
|
||||
|
||||
node.parameters = <NodeArray<ParameterDeclaration>>[parameter];
|
||||
node.parameters.pos = parameter.pos;
|
||||
node.parameters.end = parameter.end;
|
||||
|
||||
node.lineTerminatorBeforeArrow = scanner.hasPrecedingLineBreak();
|
||||
parseExpected(SyntaxKind.EqualsGreaterThanToken);
|
||||
if ((node.arrow = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>"))) {
|
||||
node.arrow.parent = node;
|
||||
}
|
||||
node.body = parseArrowFunctionExpressionBody();
|
||||
|
||||
return finishNode(node);
|
||||
@@ -3046,7 +3048,8 @@ module ts {
|
||||
|
||||
// If we have an arrow, then try to parse the body. Even if not, try to parse if we
|
||||
// have an opening brace, just in case we're in an error state.
|
||||
if (parseExpected(SyntaxKind.EqualsGreaterThanToken) || token === SyntaxKind.OpenBraceToken) {
|
||||
if ((arrowFunction.arrow = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>")) || token === SyntaxKind.OpenBraceToken) {
|
||||
arrowFunction.arrow.parent = arrowFunction;
|
||||
arrowFunction.body = parseArrowFunctionExpressionBody();
|
||||
}
|
||||
else {
|
||||
@@ -3141,9 +3144,9 @@ module ts {
|
||||
}
|
||||
|
||||
function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): FunctionExpression {
|
||||
let node = <ArrowFunctionExpression>createNode(SyntaxKind.ArrowFunction);
|
||||
let node = <ArrowFunction>createNode(SyntaxKind.ArrowFunction);
|
||||
// Arrow functions are never generators.
|
||||
//
|
||||
//
|
||||
// If we're speculatively parsing a signature for a parenthesized arrow function, then
|
||||
// we have to have a complete parameter list. Otherwise we might see something like
|
||||
// a => (b => c)
|
||||
@@ -3169,8 +3172,6 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
node.lineTerminatorBeforeArrow = scanner.hasPrecedingLineBreak();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@@ -653,8 +653,8 @@ module ts {
|
||||
body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional
|
||||
}
|
||||
|
||||
export interface ArrowFunctionExpression extends FunctionExpression {
|
||||
lineTerminatorBeforeArrow: boolean;
|
||||
export interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
arrow: Node;
|
||||
}
|
||||
|
||||
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral,
|
||||
|
||||
@@ -553,8 +553,8 @@ declare module "typescript" {
|
||||
name?: Identifier;
|
||||
body: Block | Expression;
|
||||
}
|
||||
interface ArrowFunctionExpression extends FunctionExpression {
|
||||
lineTerminatorBeforeArrow: boolean;
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
arrow: Node;
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
text: string;
|
||||
|
||||
@@ -1669,12 +1669,14 @@ declare module "typescript" {
|
||||
>name : Identifier | LiteralExpression | ComputedPropertyName | BindingPattern
|
||||
>DeclarationName : Identifier | LiteralExpression | ComputedPropertyName | BindingPattern
|
||||
|
||||
questionToken?: Node;
|
||||
|
||||
>questionToken : Node
|
||||
questionToken?: Node;
|
||||
|
||||
>questionToken : Node
|
||||
>Node : Node
|
||||
|
||||
|
||||
initializer: Expression;
|
||||
initializer: Expression;
|
||||
|
||||
>initializer : Expression
|
||||
>Expression : Expression
|
||||
}
|
||||
|
||||
|
||||
@@ -584,8 +584,8 @@ declare module "typescript" {
|
||||
name?: Identifier;
|
||||
body: Block | Expression;
|
||||
}
|
||||
interface ArrowFunctionExpression extends FunctionExpression {
|
||||
lineTerminatorBeforeArrow: boolean;
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
arrow: Node;
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
text: string;
|
||||
|
||||
@@ -1815,12 +1815,14 @@ declare module "typescript" {
|
||||
>name : Identifier | LiteralExpression | ComputedPropertyName | BindingPattern
|
||||
>DeclarationName : Identifier | LiteralExpression | ComputedPropertyName | BindingPattern
|
||||
|
||||
questionToken?: Node;
|
||||
|
||||
>questionToken : Node
|
||||
questionToken?: Node;
|
||||
|
||||
>questionToken : Node
|
||||
>Node : Node
|
||||
|
||||
|
||||
initializer: Expression;
|
||||
initializer: Expression;
|
||||
|
||||
>initializer : Expression
|
||||
>Expression : Expression
|
||||
}
|
||||
|
||||
|
||||
@@ -585,8 +585,8 @@ declare module "typescript" {
|
||||
name?: Identifier;
|
||||
body: Block | Expression;
|
||||
}
|
||||
interface ArrowFunctionExpression extends FunctionExpression {
|
||||
lineTerminatorBeforeArrow: boolean;
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
arrow: Node;
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
text: string;
|
||||
|
||||
@@ -1765,12 +1765,14 @@ declare module "typescript" {
|
||||
>name : Identifier | LiteralExpression | ComputedPropertyName | BindingPattern
|
||||
>DeclarationName : Identifier | LiteralExpression | ComputedPropertyName | BindingPattern
|
||||
|
||||
questionToken?: Node;
|
||||
|
||||
>questionToken : Node
|
||||
questionToken?: Node;
|
||||
|
||||
>questionToken : Node
|
||||
>Node : Node
|
||||
|
||||
|
||||
initializer: Expression;
|
||||
initializer: Expression;
|
||||
|
||||
>initializer : Expression
|
||||
>Expression : Expression
|
||||
}
|
||||
|
||||
|
||||
@@ -622,8 +622,8 @@ declare module "typescript" {
|
||||
name?: Identifier;
|
||||
body: Block | Expression;
|
||||
}
|
||||
interface ArrowFunctionExpression extends FunctionExpression {
|
||||
lineTerminatorBeforeArrow: boolean;
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
arrow: Node;
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
text: string;
|
||||
|
||||
@@ -1938,12 +1938,14 @@ declare module "typescript" {
|
||||
>Block : Block
|
||||
>Expression : Expression
|
||||
}
|
||||
interface ArrowFunctionExpression extends FunctionExpression {
|
||||
>ArrowFunctionExpression : ArrowFunctionExpression
|
||||
>FunctionExpression : FunctionExpression
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
>ArrowFunction : ArrowFunction
|
||||
>Expression : Expression
|
||||
>FunctionLikeDeclaration : FunctionLikeDeclaration
|
||||
|
||||
lineTerminatorBeforeArrow: boolean;
|
||||
>lineTerminatorBeforeArrow : boolean
|
||||
arrow: Node;
|
||||
>arrow : Node
|
||||
>Node : Node
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
>LiteralExpression : LiteralExpression
|
||||
|
||||
@@ -1,101 +1,87 @@
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(1,10): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(3,10): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(5,10): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(7,10): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(9,10): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(11,10): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(13,10): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(15,10): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(19,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(26,40): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(30,20): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(35,17): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(39,20): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(2,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4,7): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(6,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(8,7): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(10,5): error TS1200: Line terminator not permitted before arrow.
|
||||
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 (14 errors) ====
|
||||
var f1 = ()
|
||||
~~
|
||||
=> { }
|
||||
~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f2 = (x: string, y: string) /*
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/ => { }
|
||||
~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f3 = (x: string, y: number, ...rest)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
=> { }
|
||||
~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f4 = (x: string, y: number, ...rest) /*
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/ => { }
|
||||
~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f5 = (...rest)
|
||||
~~~~~~~~~
|
||||
=> { }
|
||||
~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f6 = (...rest) /*
|
||||
~~~~~~~~~~~~
|
||||
*/ => { }
|
||||
~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f7 = (x: string, y: number, z = 10)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
=> { }
|
||||
~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f8 = (x: string, y: number, z = 10) /*
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/ => { }
|
||||
~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
foo(()
|
||||
~~
|
||||
=> true);
|
||||
~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
foo(()
|
||||
~~
|
||||
=> { return false; });
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
|
||||
module m {
|
||||
class City {
|
||||
constructor(x: number, thing = ()
|
||||
~~
|
||||
=> 100) {
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
}
|
||||
|
||||
public m = ()
|
||||
~~
|
||||
=> 2 * 2 * 2
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
}
|
||||
|
||||
export enum Enum {
|
||||
claw = (()
|
||||
~~
|
||||
=> 10)()
|
||||
~~~~~~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
}
|
||||
|
||||
export var v = x
|
||||
~
|
||||
=> new City(Enum.claw);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user