Skip to content
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

Handle closure compiler type cast syntax correctly #2484

Merged
merged 3 commits into from Jul 25, 2017

Conversation

yangsu
Copy link
Contributor

@yangsu yangsu commented Jul 15, 2017

Fixes #1445

src/comments.js Outdated
@@ -990,6 +995,12 @@ function printComments(path, print, options, needsSemi) {
const text = options.originalText;
if (util.hasNewline(text, util.skipNewline(text, util.locEnd(comment)))) {
leadingParts.push(hardline);
} else if (util.isClosureCompilerTypeCastComment(text, comment)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this can instead be handled in fast-path.js's needsParens function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. Could you look into it? If that works that would be cleaner.

@azz
Copy link
Member

azz commented Jul 15, 2017

Any idea how this will play with flow comment types?

src/util.js Outdated
// Syntax example: var x = /** @type {string} */ (fruit);
return (
isBlockComment(comment) &&
comment.value.match(/^\*\s+@type\s+{[^}]+}\s+$/) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

probably want to use \s* instead of \s+ and add some inside of {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. that's what i meant to use.

@vjeux
Copy link
Contributor

vjeux commented Jul 15, 2017

Thanks for working on it!

@yangsu
Copy link
Contributor Author

yangsu commented Jul 16, 2017

@azz I tested a few variations of the flow comment type syntax and it seems that the changes I made to how comments are attached behave correctly.

src/util.js Outdated
// Syntax example: var x = /** @type {string} */ (fruit);
return (
node.comments &&
node.comments.every(
Copy link
Member

Choose a reason for hiding this comment

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

Should this be every or some?

@codecov
Copy link

codecov bot commented Jul 16, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@f0e2072). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2484   +/-   ##
=========================================
  Coverage          ?   94.98%           
=========================================
  Files             ?       24           
  Lines             ?     3291           
  Branches          ?      867           
=========================================
  Hits              ?     3126           
  Misses            ?      150           
  Partials          ?       15
Impacted Files Coverage Δ
src/util.js 90.62% <100%> (ø)
src/fast-path.js 96.68% <100%> (ø)
src/comments.js 94.28% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f0e2072...0c592ab. Read the comment docs.

@vjeux
Copy link
Contributor

vjeux commented Jul 16, 2017

@azz didn't you disable codecov comments?

@azz
Copy link
Member

azz commented Jul 16, 2017

@vjeux I certainly did... Maybe needs rebase?

@yangsu yangsu force-pushed the support-closure-type-cast-syntax branch from 0c592ab to f5b43ae Compare July 17, 2017 00:13
@yangsu
Copy link
Contributor Author

yangsu commented Jul 17, 2017

Thank you for your comments @azz @vjeux. Any other concerns?

@yangsu yangsu force-pushed the support-closure-type-cast-syntax branch from f5b43ae to bbbb1cf Compare July 21, 2017 21:43
@yangsu
Copy link
Contributor Author

yangsu commented Jul 24, 2017

Ping @azz @vjeux

@vjeux
Copy link
Contributor

vjeux commented Jul 25, 2017 via email

@azz azz merged commit 26842e4 into prettier:master Jul 25, 2017
@azz
Copy link
Member

azz commented Jul 25, 2017

Heh, your comment appeared right as I clicked the merge button.

@yangsu yangsu deleted the support-closure-type-cast-syntax branch July 25, 2017 16:56
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants