Skip to content

[Master] Fix 13602 preserve comment following element in node list#13916

Merged
yuit merged 6 commits into
masterfrom
master-fix13602
Feb 9, 2017
Merged

[Master] Fix 13602 preserve comment following element in node list#13916
yuit merged 6 commits into
masterfrom
master-fix13602

Conversation

@yuit

@yuit yuit commented Feb 7, 2017

Copy link
Copy Markdown
Contributor

@yuit yuit changed the title Master fix13602 [Master] Fix 13602 preserve comment following element in node list Feb 7, 2017
@yuit yuit requested a review from rbuckton February 7, 2017 15:25
@yuit yuit requested a review from mhegazy February 7, 2017 23:02
Comment thread src/compiler/comments.ts Outdated
emitNodeWithComments,
emitBodyWithDetachedComments,
emitTrailingCommentsOfPosition,
emitLeadingComments,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do not expose emitLeadingComments, but rather create an emitLeadingCommentsOfPosition that calls emitLeadingComments with true for isEmittedNode. The isEmittedNode flag only matters for nodes that are not emitted at the top of a file (such as an interface) and shouldn't matter for any of the cases in emitter.ts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should ensure that emitLeadingCommentsOfPosition does nothing if pos is -1.

@yuit yuit Feb 8, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @rbuckton ! 🍰 I was wondering if I should create similar function call like emitTrailingCommentsOfPosition

Comment thread src/compiler/comments.ts Outdated
}

function emitLeadingComments(pos: number, isEmittedNode: boolean) {
if (disabled) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move this into an emitLeadingCommentsOfPosition function that calls emitLeadingComments (see above).

Comment thread src/compiler/emitter.ts Outdated
// ];
if (previousSibling && delimiter && previousSibling.end !== parentNode.end) {
emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement);
if (hasTrailingComma) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are you emitting this twice? Also, statements are never emitted with delimiters, so your isEmittedNode argument will always be true.

if (commentedParameters(1, 2)) {
/*comment1*/
commentedParameters(3, 4);
/*comment2*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be indented similar to /*comment1*/ above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might want to investigate whether it makes sense to emit leading/trailing comments of a position in the emitNodeList function in emitter.ts.

@yuit yuit Feb 8, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure I understand your comment. do you emit leading/trailing comments of each element in node-list?

Comment thread src/compiler/emitter.ts Outdated
// function commentedParameters(
// /* Parameter a */
// a
// /* End of parameter a */ -> this comment doesn't consider to be trailing comment of parameter "a" due to newline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

doesn't consider -> isn't considered

Comment thread src/compiler/emitter.ts Outdated
writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node);
emitBlockStatements(node);
// We have to call emitLeadingComments explicitly here because otherwise leading comments of the close brace token will not be emitted
emitLeadingComments(node.statements.end, /*isEmittedNode*/true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps we should emit leading/trailing comments of the node range in emitNodeList

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

do you mean make a call like this emitLeadingCommentsOfPosition(nodeList.pos)?

}
C.prototype.P = function (ii, j, k) {
for (var i = 0; i < arguments.length; i++) {
// WScript.Echo("param: " + arguments[i]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be indented.

define(["require", "exports", "./foo_0"], function (require, exports, foo) {
"use strict";
if (foo.E1.A === 0) {
// Should cause runtime import - interesting optimization possibility, as gets inlined to 0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be indented.

Comment thread src/compiler/emitter.ts Outdated
// a
// /* End of parameter a */ -> this comment isn't considered to be trailing comment of parameter "a" due to newline
// ,
if (emitLeadingCommentsOfPosition && delimiter && previousSibling.end !== parentNode.end) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There shouldn't be a need to test for the existence of emitLeadingCommentsOfPosition.

@yuit yuit merged commit f7b2062 into master Feb 9, 2017
@yuit yuit deleted the master-fix13602 branch February 9, 2017 20:51
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants