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,
|
||||
|
||||
Reference in New Issue
Block a user