diff --git a/packages/purgecss-from-html/src/index.ts b/packages/purgecss-from-html/src/index.ts index 1e20d016..f27d9cab 100644 --- a/packages/purgecss-from-html/src/index.ts +++ b/packages/purgecss-from-html/src/index.ts @@ -35,7 +35,7 @@ const mergedExtractorResults = ( }; const getSelectorsInElement = ( - element: htmlparser2.Htmlparser2TreeAdapterMap['element'] + element: htmlparser2.Htmlparser2TreeAdapterMap["element"] ): ExtractorResultDetailed => { const result: ExtractorResultDetailed = { attributes: { @@ -63,7 +63,9 @@ const getSelectorsInElement = ( }; const getSelectorsInNodes = ( - node: htmlparser2.Htmlparser2TreeAdapterMap['document'] | htmlparser2.Htmlparser2TreeAdapterMap['element'] + node: + | htmlparser2.Htmlparser2TreeAdapterMap["document"] + | htmlparser2.Htmlparser2TreeAdapterMap["element"] ): ExtractorResultDetailed => { let result: ExtractorResultDetailed = { attributes: { @@ -103,7 +105,7 @@ const getSelectorsInNodes = ( */ const purgecssFromHtml = (content: string): ExtractorResultDetailed => { const tree = parse5.parse(content, { - treeAdapter: htmlparser2.adapter + treeAdapter: htmlparser2.adapter, }); return getSelectorsInNodes(tree); diff --git a/packages/purgecss/__tests__/pseudo-class.test.ts b/packages/purgecss/__tests__/pseudo-class.test.ts index 63819a4c..ef5cd9dc 100644 --- a/packages/purgecss/__tests__/pseudo-class.test.ts +++ b/packages/purgecss/__tests__/pseudo-class.test.ts @@ -100,3 +100,37 @@ describe("pseudo classes", () => { expect(purgedCSS.includes("row:after")).toBe(false); }); }); + +describe(":where pseudo class", () => { + let purgedCSS: string; + beforeAll(async () => { + const resultsPurge = await new PurgeCSS().purge({ + content: [`${ROOT_TEST_EXAMPLES}pseudo-class/where.html`], + css: [`${ROOT_TEST_EXAMPLES}pseudo-class/where.css`], + }); + purgedCSS = resultsPurge[0].css; + }); + + it("removes unused selectors", () => { + expect(purgedCSS.includes(".unused")).toBe(false); + expect(purgedCSS.includes(".root :where(.a) .c {")).toBe(true); + expect(purgedCSS.includes(".root:where(.a) .c {")).toBe(true); + }); +}); + +describe(":is pseudo class", () => { + let purgedCSS: string; + beforeAll(async () => { + const resultsPurge = await new PurgeCSS().purge({ + content: [`${ROOT_TEST_EXAMPLES}pseudo-class/is.html`], + css: [`${ROOT_TEST_EXAMPLES}pseudo-class/is.css`], + }); + purgedCSS = resultsPurge[0].css; + }); + + it("removes unused selectors", () => { + expect(purgedCSS.includes(".unused")).toBe(false); + expect(purgedCSS.includes(".root :is(.a) .c {")).toBe(true); + expect(purgedCSS.includes(".root:is(.a) .c {")).toBe(true); + }); +}); diff --git a/packages/purgecss/__tests__/test_examples/pseudo-class/is.css b/packages/purgecss/__tests__/test_examples/pseudo-class/is.css new file mode 100644 index 00000000..5f22ab8e --- /dev/null +++ b/packages/purgecss/__tests__/test_examples/pseudo-class/is.css @@ -0,0 +1,24 @@ +.root :is(.a, .b) .unused { + color: red; +} + +.root :is(.a, .unused) .c { + color: blue; +} + +.root :is(.a, .b) .c :is(.unused, .unused2) { + color: green; +} + +.root:is(.unused) .c { + color: rebeccapurple; +} + +.root:is(.a) .c { + color: cyan; +} + +.root :is(.unused) .c, +.root :is(.a, .b) .c :is(.unused, .unused2) { + display: flex; +} \ No newline at end of file diff --git a/packages/purgecss/__tests__/test_examples/pseudo-class/is.html b/packages/purgecss/__tests__/test_examples/pseudo-class/is.html new file mode 100644 index 00000000..fd573c34 --- /dev/null +++ b/packages/purgecss/__tests__/test_examples/pseudo-class/is.html @@ -0,0 +1,8 @@ +