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

Fix multiline dynamic import comments #6025

Merged
merged 1 commit into from Apr 2, 2019

Conversation

Projects
None yet
4 participants
@noahsug
Copy link
Contributor

noahsug commented Apr 2, 2019

Fixes #4617

Trying to keep dynamic imports as a single unit (#2288) and not allowing comments to be attached to dynamic imports (#2748) was causing weird behavior when comments existed on a different line than the argument. This often comes up when using webpack's magic comments.

I also removed tests/import_then/ in favor of the existing tests/dynamic_import/.

// Input
import(
  /* Hello */
  'something'
  /* Hello */
)
import(
  'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
)

// Output (Prettier stable)
import(/* Hello */
"something");
/* Hello */
import('myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename');


// Output (Prettier master)
import(
  /* Hello */
  'something'
  /* Hello */
)
import(
  'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
);

Note: this is still an issue for require and define, but I imagine multiline comments are much less popular in those methods.

  • I’ve added tests to confirm my change works.
  • (If the change is user-facing) I’ve added my changes to the CHANGELOG.unreleased.md file following the template.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@noahsug noahsug changed the title Multiline dynamic import comments Fix multiline dynamic import comments Apr 2, 2019

@noahsug

This comment has been minimized.

Copy link
Contributor Author

noahsug commented Apr 2, 2019

I ran this on Airbnb's codebase as an integration test and confirmed that everything looks good

@vjeux

This comment has been minimized.

Copy link
Collaborator

vjeux commented Apr 2, 2019

Thanks a lot for fixing this and the great test coverage + docs! I’ve also seen this be really annoying for webpack comments.

@vjeux vjeux merged commit 0b07e10 into prettier:master Apr 2, 2019

3 checks passed

codecov/patch 100% of diff hit (target 80%)
Details
codecov/project 94.41% (+0%) compared to 1e471a0
Details
deploy/netlify Deploy preview ready!
Details

@ikatyang ikatyang added this to the 1.17 milestone Apr 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.