Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Mar 8, 2018

Sequel to #22404, ensures that we don't use replaceNode even for arrow functions.

@ghost ghost requested review from amcasey and sandersn March 8, 2018 19:53
}
if (returnTypeNode && !decl.type) changes.insertTypeAnnotation(sourceFile, decl, returnTypeNode);
}
if (needParens) changes.insertNodeAfter(sourceFile, first(decl.parameters), createToken(SyntaxKind.CloseParenToken));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think last might be clearer, even though they should return the same result.

const lparen = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile)!.pos;
this.insertNodesAt(sourceFile, lparen, typeParameters, { prefix: "<", suffix: ">" });
// If no `(`, is an arrow function `x => x`, so use the pos of the first parameter
const start = (findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile) || first(node.parameters)).pos;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be interesting to add a test capturing the difference between full-start and start.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like .getStart() works better. We are removing trivia (see annotateWithTypeFromJSDoc9.5.ts) but the type parameter is now flush with the open parenthesis instead of before the space.

@ghost ghost merged commit 0f47c8a into master Mar 9, 2018
@ghost ghost deleted the arrow branch March 9, 2018 00:32
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant