Fix @import/@charset loss in CSS concat (closure scoping bug)#98
Merged
Conversation
3 tasks
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the bug shown by the failing test added in PR #97.
The problem:
When concatting CSS,
service.phphoists@charsetand@importrules to the top of the output via a$pre_outputbuffer. The callbacks that collect these rules usedglobal $pre_output-$pre_outputis a local variable insidepage_optimize_build_output(), not a global.In PHP,
global $pre_outputreferences$GLOBALS['pre_output'], which is a completely different variable. So the callbacks were:@importfrom the source buffer ✓$pre_output✗The lifted rules vanished completely.
The fix:
Change both
preg_replace_callbackclosures from:to:
This captures the local
$pre_outputby reference, so hoisted rules actually make it into the output.Testing:
The test from #97 now passes. You can also hit the concat endpoint directly with a CSS file containing
@importand confirm it appears in the response.Example plugin:
example.com/?po_import_test- Note that the rule from b-dep.css is gone completely on trunk, and shows up in this PR. However, there's still an ordering issue (we will fix later).