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
Merged

Fix multiline dynamic import comments #6025

merged 1 commit into from Apr 2, 2019

Conversation

noahsug
Copy link
Contributor

@noahsug 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
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
Copy link
Contributor

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
@ikatyang ikatyang added this to the 1.17 milestone Apr 12, 2019
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 11, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 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.

Webpack magic comments in import() statements look ugly and potentially break
4 participants