Repository navigation
Fix two broken mixin examples in README - #179
Merged
Merged
Conversation
The icons function mixin called mixin.replaceWith() for every file, so only the first rule was inserted: replaceWith() does nothing once the node has left the tree. Insert each rule with mixin.before(). The JS version of the @mixin-content example was a syntax error, had no .isIE & selector, and was named isIe while the CSS calls isIE. Return the same rule the CSS mixin defines.
Member
|
Thanks! |
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.
Two examples in the README do not work as shown:
iconsfunction mixin callsmixin.replaceWith(rule)for every file. After the first call the@mixinnode is no longer in the tree, so the next calls do nothing and only the first icon ends up in the output (.icon.icon-back, without.icon.icon-secret). This was reported in Cannot read property 'length' of undefined #67, where the fix wasmixin.parent.insertBefore(mixin, rule), but the README kept the old loop. It now usesmixin.before(rule), which does the same, and postcss-mixins removes the@mixinnode afterwards.@mixin-contentexample, added in chore: Add @mixin-context example #81, is a syntax error (SyntaxError: Unexpected token ':'), and it also had no.isIE &selector and was namedisIewhile the usage below callsisIE. It now returns{ '.isIE &': { '@mixin-content': {} } }, the same shape as in the test "does not throw error on brackets in at-rules inside function mixins".I ran the CSS and JS examples of the README (all but the two with
…placeholders) with postcss-mixins 12.1.2, whoseindex.jsis the same as onmain, and postcss-nested 8.0.1. With this change,icons(withreaddirSyncreturningback.svgandsecret.svg) gives exactly the output shown below it, and the JSisIEmixin gives the same.fooand.isIE .foooutput as the CSS one. Without the.isIE &selector the content stays in.foo, and with the old name it fails withUndefined mixin isIE.