-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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(css): ensure code is valid after empty css chunk imports are removed (fix #14515) #14517
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I really would like to add test cases, but it seems pretty hard to mock the plugin state for only testing the output hook)
We can maybe refactor this empty chunk replacement logic out as a function to unit test and create snapshots. That we can easily compare how this PR affects it. It may be best to do this step in another PR first so we get a starting snapshot.
3842602
to
1ad178e
Compare
Make sure that minified code that chains `require` calls with the `,` operator will not result in invalid code when removing one of the chained requires. Previously the last require that terminates with a semicolon was removed with the semicolon. This produced invalid code like `require(), /* empty css */const foo =` Now we append either a comma if a next require call was chained, like `require(...), require(css), other` --> `require(...)/* empty css */, other` Or terminate with a semicolon `require(...), require(css); const foo = ...` --> `require(...)/* empty css */; const foo = ...` Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1ad178e
to
3214fa4
Compare
@bluwy Tests updated, you can compare it now :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Yes it looks a lot easier to review now.
@emosheeep I don't think moving the comma to behind will work. It will still be a parse error. Is there a reason the code is Is this only happening in the Vite beta? I'd suggest opening a new issue with a repro so we could look into it. |
Description
Make sure that minified code that chains
require
calls with the,
operator will not result in invalid code when removing one of the chained requires. Previously the last require that terminates with a semicolon was removed with the semicolon. This produced invalid code likerequire(), /* empty css */const foo =
Now we append either a comma if a next require call was chained, like
require(...), require(css), other
-->require(...)/* empty css */, other
Or terminate with a semicolon
require(...), require(css); const foo = ...
-->require(...)/* empty css */; const foo = ...
Additional context
This also fixes a problem where empty chunks were not removed if chained in the middle with
,
.E.g. this like this:
require(...), require(empty chunk), require(...);
(I really would like to add test cases, but it seems pretty hard to mock the plugin state for only testing the output hook)
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).