Skip to content

Commit

Permalink
chore: only .toString() if dirty (#966)
Browse files Browse the repository at this point in the history
* chore: only .toString() if dirty

* Create tricky-cats-fail.md
  • Loading branch information
tivac authored Aug 8, 2023
1 parent 880b5a2 commit ffab76d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tricky-cats-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@modular-css/processor": patch
---

chore: only .toString() if dirty when replacing `@value` references
7 changes: 6 additions & 1 deletion packages/processor/plugins/values-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = () => ({
const replacer = (prop) =>
(thing) => {
const parsed = value(thing[prop]);
let modified = false;

parsed.walk((node) => {
if(node.type !== "word" || !values[node.value]) {
Expand All @@ -47,9 +48,13 @@ module.exports = () => ({

// Replace any value instances
node.value = current.value;

modified = true;
});

thing[prop] = parsed.toString();
if(modified) {
thing[prop] = parsed.toString();
}
};

return {
Expand Down

0 comments on commit ffab76d

Please sign in to comment.