Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Bug fixes / improvements #3

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ let env = {
DEBUG: process.env.DEBUG !== undefined,
}

function sign(bigIntValue) {
return (bigIntValue > 0n) - (bigIntValue < 0n)
}

// ---

// This is used to trigger rebuilds. Just updating the timestamp
Expand Down Expand Up @@ -261,9 +265,7 @@ function generateRules(tailwindConfig, candidates, context) {
}

function buildStylesheet(rules, context) {
let sortedRules = rules.sort(([a], [z]) => {
return Math.sign(Number(a - z))
})
let sortedRules = rules.sort(([a], [z]) => sign(a - z))

let returnValue = {
components: new Set(),
Expand Down Expand Up @@ -1118,13 +1120,7 @@ module.exports = (pluginOptions = {}) => {
if (appliedSelector !== apply.parent.selector) {
siblings.push([
sort,
toPostCssNode(
[
replaceSelector(apply.parent.selector, selector, applyCandidate),
rule,
],
context.postCssNodeCache
),
toPostCssNode([appliedSelector, rule], context.postCssNodeCache),
])
continue
}
Expand All @@ -1138,7 +1134,7 @@ module.exports = (pluginOptions = {}) => {
}

// Inject the rules, sorted, correctly
for (let [sort, sibling] of siblings.sort(([a], [z]) => Math.sign(Number(z - a)))) {
for (let [sort, sibling] of siblings.sort(([a], [z]) => sign(z - a))) {
// `apply.parent` is refering to the node at `.abc` in: .abc { @apply mt-2 }
apply.parent.after(sibling)
}
Expand Down