Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"checkJs": true,
"allowJs": true,
"target": "ES6",
"strict": true,
"module": "ES6"
}
}
36 changes: 29 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@projectwallace/format-css",
"version": "1.0.6",
"type": "module",
"source": "index.js",
"source": "src/index.js",
"exports": {
"require": "./dist/format.cjs",
"default": "./dist/format.modern.js"
Expand All @@ -13,11 +13,13 @@
"unpkg": "./dist/format.umd.js",
"scripts": {
"build": "microbundle",
"test": "uvu"
"test": "uvu",
"check": "tsc -p src/index.js --noEmit"
},
"devDependencies": {
"@types/css-tree": "^2.3.4",
"microbundle": "^0.15.1",
"typescript": "^5.3.2",
"uvu": "^0.5.6"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/atrules.test.js → src/atrules.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { suite } from 'uvu'
import * as assert from 'uvu/assert'
import { format } from '../index.js'
import { format } from './index.js'

let Atrules = suite('Atrules')

Expand Down
2 changes: 1 addition & 1 deletion test/declarations.js → src/declarations.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { suite } from "uvu";
import * as assert from "uvu/assert";
import { format } from "../index.js";
import { format } from "./index.js";

let Declarations = suite("Declarations");

Expand Down
27 changes: 20 additions & 7 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-expect-error CSSTree imports are always troublesome
import parse from 'css-tree/parser'

/**
Expand All @@ -17,7 +18,7 @@ function indent(size) {
function substr(node, css) {
let loc = node.loc

if (!loc) return ''
if (loc === undefined) return ''

let start = loc.start
let end = loc.end
Expand All @@ -38,8 +39,9 @@ function substr(node, css) {
* @returns A portion of the CSS
*/
function substr_raw(node, css) {
if (!node.loc) return ''
return css.substring(node.loc.start.offset, node.loc.end.offset)
let loc = node.loc
if (!loc) return ''
return css.substring(loc.start.offset, loc.end.offset)
}

/**
Expand Down Expand Up @@ -114,10 +116,11 @@ function print_simple_selector(node, css) {
break
}
case 'SelectorList': {
for (let grandchild of child.children) {
buffer += print_simple_selector(grandchild, css)
for (let selector of child.children) {
// @ts-expect-error This is being problematic, but I don't know hot to fix it
buffer += print_simple_selector(selector, css)

if (grandchild !== child.children.last) {
if (selector !== child.children.last) {
buffer += ', '
}
}
Expand Down Expand Up @@ -153,7 +156,17 @@ function print_simple_selector(node, css) {

if (child.selector !== null) {
// `of .selector`
buffer += ' of ' + print_simple_selector(child.selector, css)
buffer += ' of '

let items = child.selector.children
for (let selector of items) {
if (selector.type === 'Selector') {
if (selector !== items.first) {
buffer += ', '
}
buffer += print_simple_selector(selector, css)
}
}
}
break
}
Expand Down
2 changes: 1 addition & 1 deletion test/rules.test.js → src/rules.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { suite } from "uvu";
import * as assert from "uvu/assert";
import { format } from "../index.js";
import { format } from "./index.js";

let Rules = suite("Rules");

Expand Down
6 changes: 5 additions & 1 deletion test/selectors.test.js → src/selectors.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { suite } from "uvu";
import * as assert from "uvu/assert";
import { format } from "../index.js";
import { format } from "./index.js";

let Selectors = suite("Selectors");

Expand Down Expand Up @@ -82,6 +82,10 @@ Selectors("formats selectors with Nth", () => {
`li:nth-child(-n+3 of li.important) {}`,
`li:nth-child(-1n + 3 of li.important) {}`,
],
[
`li:nth-child(3n of ol li,ul li) {}`,
`li:nth-child(3n of ol li, ul li) {}`
],
[
`p:nth-child(n+8):nth-child(-n+15) {}`,
`p:nth-child(1n + 8):nth-child(-1n + 15) {}`,
Expand Down
2 changes: 1 addition & 1 deletion test/test.js → src/stylesheet.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { suite } from "uvu";
import * as assert from "uvu/assert";
import { format } from "../index.js";
import { format } from "./index.js";

let Stylesheet = suite("Stylesheet");

Expand Down
2 changes: 1 addition & 1 deletion test/values.test.js → src/values.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { suite } from "uvu";
import * as assert from "uvu/assert";
import { format } from "../index.js";
import { format } from "./index.js";

let Values = suite("Values");

Expand Down