From ae7e85c0f94cc5494bbebccd0f5513d745e5f068 Mon Sep 17 00:00:00 2001 From: kghugo Date: Sat, 21 Aug 2021 13:59:55 +0100 Subject: [PATCH] Fix issue where existing non-class declarations are removed --- src/tokenizer.js | 2 -- src/transformer.js | 6 ++++-- test/tokenizer.spec.js | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/tokenizer.js b/src/tokenizer.js index 0256b07..e483f61 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -43,8 +43,6 @@ const hydrateClassCache = ( tempCache[className], tokenizeRules(rule, declarationCache, next, mediaQueryName) ); - } else { - // TODO: handle other selector } }; diff --git a/src/transformer.js b/src/transformer.js index 92dc629..637f87e 100644 --- a/src/transformer.js +++ b/src/transformer.js @@ -1,6 +1,6 @@ import MagicString from "magic-string"; import { walk } from "svelte/compiler"; -import { assembleRules } from "./helper.js"; +import { assembleRules, getClassName } from "./helper.js"; export default function (code, { dir, base }) { const changeable = new MagicString(code); @@ -17,7 +17,9 @@ export default function (code, { dir, base }) { case "Style": { for (const child of node.children) { if (child.type === "Rule") { - changeable.overwrite(child.start, child.end, ""); + if (getClassName(child)[0]) { + changeable.overwrite(child.start, child.end, ""); + } } } if (node.children.length > 0) { diff --git a/test/tokenizer.spec.js b/test/tokenizer.spec.js index 66df734..f3155e1 100644 --- a/test/tokenizer.spec.js +++ b/test/tokenizer.spec.js @@ -254,6 +254,4 @@ describe("when given a rule that uses id as selector", function () { }) ); }); - - it("should be stored in replicate cache", async () => {}); });