Skip to content

Preserve method comments in JS->ES6 conversion. #16697

Merged
RyanCavanaugh merged 3 commits into
microsoft:masterfrom
RyanCavanaugh:preserveMethodComments
Jun 29, 2017
Merged

Preserve method comments in JS->ES6 conversion. #16697
RyanCavanaugh merged 3 commits into
microsoft:masterfrom
RyanCavanaugh:preserveMethodComments

Conversation

@RyanCavanaugh
Copy link
Copy Markdown
Member

Fixes #16622

cc @rbuckton

if (isSourceFileJavaScript(sourceFile)) {
return;
}
return createProperty(/*decorators*/ undefined, modifiers, memberDeclaration.name, /*questionToken*/ undefined,
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.

Should we copy comments for properties as well?

@RyanCavanaugh
Copy link
Copy Markdown
Member Author

@rbuckton review latest rev?

Copy link
Copy Markdown
Contributor

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

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

Can you add tests for the arrow and property declaration cases?

bodyBlock = createBlock([createReturn(expression)]);
}
return createMethod(/*decorators*/ undefined, modifiers, /*asteriskToken*/ undefined, memberDeclaration.name, /*questionToken*/ undefined,
const method = createMethod(/*decorators*/ undefined, modifiers, /*asteriskToken*/ undefined, memberDeclaration.name, /*questionToken*/ undefined,
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.

Can you add a test for this?

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.

Not related to comments, but do we preserve the binding to the this of the outer scope if the arrow contains a this? What happens if we refactor:

function C() {}
C.prototype.x = () => this;

return;
}
return createProperty(/*decorators*/ undefined, modifiers, memberDeclaration.name, /*questionToken*/ undefined,
const prop = createProperty(/*decorators*/ undefined, modifiers, memberDeclaration.name, /*questionToken*/ undefined,
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.

Can you add a test for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

That only hits the code path on L167. It doesn't cover the cases on L186 and L189.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is actually currently unreachable since this refactor doesn't light up in non-JS files

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.

Fair point regarding the property declaration, but arrow functions are still fair game.

Copy link
Copy Markdown
Contributor

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

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

Looks good, just one question.

bodyBlock = createBlock([createReturn(expression)]);
}
return createMethod(/*decorators*/ undefined, modifiers, /*asteriskToken*/ undefined, memberDeclaration.name, /*questionToken*/ undefined,
const method = createMethod(/*decorators*/ undefined, modifiers, /*asteriskToken*/ undefined, memberDeclaration.name, /*questionToken*/ undefined,
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.

Not related to comments, but do we preserve the binding to the this of the outer scope if the arrow contains a this? What happens if we refactor:

function C() {}
C.prototype.x = () => this;

@RyanCavanaugh
Copy link
Copy Markdown
Member Author

We don't preserve arrow functions' this during refactors. I think the assumption is that people are mostly writing things like fn.prototype.bar = () => 10; (obviously we could syntactically distinguish the two but it seems like an odd thing to write). Since arrow functions and classes landed in the same ES version I don't expect to see much of this.

@RyanCavanaugh
Copy link
Copy Markdown
Member Author

Thanks!

@RyanCavanaugh RyanCavanaugh merged commit ec00bb9 into microsoft:master Jun 29, 2017
@rbuckton
Copy link
Copy Markdown
Contributor

Can you merge this into release-2.4?

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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