From ffab76d4428211ba33e6f7a6d518618b5cfdef00 Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Mon, 7 Aug 2023 18:13:02 -0700 Subject: [PATCH] chore: only .toString() if dirty (#966) * chore: only .toString() if dirty * Create tricky-cats-fail.md --- .changeset/tricky-cats-fail.md | 5 +++++ packages/processor/plugins/values-replace.js | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/tricky-cats-fail.md diff --git a/.changeset/tricky-cats-fail.md b/.changeset/tricky-cats-fail.md new file mode 100644 index 000000000..c3c43195b --- /dev/null +++ b/.changeset/tricky-cats-fail.md @@ -0,0 +1,5 @@ +--- +"@modular-css/processor": patch +--- + +chore: only .toString() if dirty when replacing `@value` references diff --git a/packages/processor/plugins/values-replace.js b/packages/processor/plugins/values-replace.js index a8e6c6a1c..492aa4d1e 100644 --- a/packages/processor/plugins/values-replace.js +++ b/packages/processor/plugins/values-replace.js @@ -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]) { @@ -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 {