diff --git a/src/lib/index.ts b/src/lib/index.ts index bc7eecd..5d3ef74 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -24,6 +24,7 @@ import { type StyleSheet, type CSSNode, is_type_selector, + is_universal_selector, is_combinator, is_pseudo_class_selector, is_pseudo_element_selector, @@ -187,7 +188,13 @@ function print_simple_selector( is_first: boolean = false, ): string { if (is_type_selector(node)) { - return node.name.toLowerCase() + let prefix = node.namespace === null ? '' : node.namespace.toLowerCase() + '|' + return prefix + node.name.toLowerCase() + } + + if (is_universal_selector(node)) { + let prefix = node.namespace === null ? '' : node.namespace.toLowerCase() + '|' + return prefix + '*' } if (is_combinator(node)) { diff --git a/test/selectors.test.ts b/test/selectors.test.ts index fadf762..79c0834 100644 --- a/test/selectors.test.ts +++ b/test/selectors.test.ts @@ -260,3 +260,17 @@ test('handles syntax errors', () => { let expected = `test {}` expect(actual).toEqual(expected) }) + +test.each([ + [`ns|div {}`, `ns|div {}`], + [`NS|div {}`, `ns|div {}`], + [`*|div {}`, `*|div {}`], + [`|div {}`, `|div {}`], + [`ns|* {}`, `ns|* {}`], + [`*|* {}`, `*|* {}`], + [`|* {}`, `|* {}`], + [`ns|div, ns|span {}`, `ns|div,\nns|span {}`], +])('formats namespace selectors: %s', (css, expected) => { + let actual = format(css) + expect(actual).toEqual(expected) +})