Skip to content

Trivia emitted twice in arrow function #7227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evmar opened this issue Feb 24, 2016 · 1 comment
Closed

Trivia emitted twice in arrow function #7227

evmar opened this issue Feb 24, 2016 · 1 comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@evmar
Copy link
Contributor

evmar commented Feb 24, 2016

Split off from issue #6982. In TypeScript 6b05ad7, which is master as of 19 Feb 2016.

This input:

let x =
/* trivia */ () => 3;

produces the comment twice, with output like:

var x = 
/* trivia */ 
/* trivia */ function () { return 3; }

The end of the call stack at the time of the second emit is (innermost function at the top):

emitFunctionDeclaration (emitter.ts:4537)
emitJavaScriptWorker (emitter.ts:7898)
emitNodeWithoutSourceMap (emitter.ts:7749)
emitNodeWithSourceMap (emitter.ts:7742)
emitNodeConsideringCommentsOption (emitter.ts:7731)

emitNodeConsideringCommentsOption calls emitLeadingComments once before calling emitNodeWithSourceMap (seen here), but then emitFunctionDeclaration (at the bottom of this stack) itself calls emitLeadingComments again on the same node.

The code in emitFunctionDeclaration appears to try to defend against this double-emitting but gets it wrong in this case.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Feb 24, 2016
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Feb 24, 2016
AntonTolmachev pushed a commit to AntonTolmachev/TypeScript that referenced this issue Apr 7, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 13, 2016

This should be fixed in latest.

@mhegazy mhegazy closed this as completed Sep 13, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Sep 13, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.1, Community Sep 13, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants