Skip to content

Commit

Permalink
add types, testing and CI (#24)
Browse files Browse the repository at this point in the history
closes #14 
closes #19

---------

Co-authored-by: Bjorn van Beek @b-vb
  • Loading branch information
bartveneman authored Dec 13, 2023
1 parent e64c64e commit bfd235b
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 160 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ jobs:
with:
node-version: 18
cache: "npm"
- run: npm install --ignore-scripts --no-audit
- run: npm test
- name: Install dependencies
run: npm install --ignore-scripts --no-audit
- name: Run unit tests
run: npm test
- name: Test types
run: npm run check
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-expect-error Typing of css-tree is incomplete
import parse from 'css-tree/parser'

const NEWLINE = '\n'
Expand Down Expand Up @@ -117,7 +118,9 @@ function print_simple_selector(node, css) {
}
case 'SelectorList': {
for (let grandchild of child.children) {
buffer += print_simple_selector(grandchild, css)
if (grandchild.type === 'Selector') {
buffer += print_simple_selector(grandchild, css)
}

if (grandchild !== child.children.last) {
buffer += ', '
Expand Down Expand Up @@ -155,6 +158,7 @@ function print_simple_selector(node, css) {

if (child.selector !== null) {
// `of .selector`
// @ts-expect-error Typing of child.selector is SelectorList, which doesn't seem to be correct
buffer += ' of ' + print_simple_selector(child.selector, css)
}
break
Expand Down Expand Up @@ -302,7 +306,7 @@ function print_declaration(node, indent_level, css) {
}

/**
* @param {import('css-tree').List} children
* @param {import('css-tree').List<import('css-tree').CssNode>} children
* @param {number} indent_level
* @param {string} css
*/
Expand Down Expand Up @@ -383,13 +387,14 @@ function print_unknown(node, indent_level, css) {
}

/**
* @param {import('css-tree').StyleSheet} node
* @param {import('css-tree').CssNode} node
* @param {number} indent_level
* @param {string} css
* @returns {string} A formatted Stylesheet
*/
function print(node, indent_level = 0, css) {
let buffer = ''
// @ts-expect-error Property 'children' does not exist on type 'AnPlusB', but we're never using that
let children = node.children

for (let child of children) {
Expand Down
Loading

0 comments on commit bfd235b

Please sign in to comment.