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(commonjs): Exclude multi-line template strings from indent #1229

Merged
merged 1 commit into from Aug 5, 2022

Conversation

simonbuchan
Copy link
Contributor

Rollup Plugin Name: commonjs

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

Fixes #1228

This excludes template literal elements (the string-ey bits) that include newlines from the two cases of MagicString.indent() used in commonjs.

E.g.:

export default `
foo
bar
`

in some cases could be transformed to:

export default `
\tfoo
\tbar
\t`

@simonbuchan
Copy link
Contributor Author

Note, one thing to look into is if it's actually OK to include gathering the TemplateElement ranges in the same walk as everything else - it does skip some branches, but it seemed to be safe from what I could see.

@simonbuchan
Copy link
Contributor Author

As a comment, the current husky seems broken with a recent pnpm - it tries to run using pnpx --no-install, which doesn't work. Is this known? I had to edit my .git/hooks/husky.sh.

Copy link
Collaborator

@shellscape shellscape 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 to me, nice work. We like to wait until one more maintainer approves before merge.

@shellscape shellscape changed the title [commonjs] Exclude multi-line template strings from indent. fix(commonjs): Exclude multi-line template strings from indent Aug 2, 2022
Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Great work and thanks a lot for taking up on this so quickly, these kind of contributions really move the project forward!

Note, one thing to look into is if it's actually OK to include gathering the TemplateElement ranges in the same walk as everything else - it does skip some branches, but it seemed to be safe from what I could see

I agree, at least I saw no obvious omissions. These walks are rather expensive, so using the existing walk is a good thing. If we find we missed something, I would think we should rather replace the skipping logic with an adapted logic that just skips most of the switch statement except the TemplateElement logic.

I think this is good to be merged.

@lukastaegert lukastaegert merged commit 54c1a7c into rollup:master Aug 5, 2022
@simonbuchan simonbuchan deleted the fix-1128 branch August 5, 2022 08:38
@simonbuchan
Copy link
Contributor Author

Thanks! Feels good to get a fix into such a cool project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[commonjs] strictRequires indent with \t modifies multi-line string values.
3 participants