Skip to content

Commit 0df485c

Browse files
committed
chore: address maintainer review feedback (round 4)
- delete unused tokenizeOursSimple and the now-redundant tokenizer-vs-csstools.mjs (ours already delegates to @csstools/css-tokenizer, so the comparison was circular) - dedupe corpus loading between benchmark.mjs and show-divergences.mjs into scripts/lib/corpus.mjs - drop the type-coverage dependency; strict tsc already covers this and CI never ran the quality script anyway - rename src/lib/type.js to convertUnits.js to stop it reading as a TS-types or CSS-<type> file - document each script's purpose in scripts/README.md
1 parent 4832f6b commit 0df485c

18 files changed

Lines changed: 253 additions & 667 deletions

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
"scripts": {
2525
"lint": "eslint . && tsc",
2626
"test": "node --test",
27-
"test:mutation": "stryker run",
28-
"quality:type-coverage": "type-coverage --at-least 97.5",
29-
"quality": "pnpm quality:type-coverage && pnpm lint"
27+
"test:mutation": "stryker run"
3028
},
3129
"author": "Andy Jansson",
3230
"license": "MIT",
@@ -46,7 +44,6 @@
4644
"fast-check": "^4.7.0",
4745
"postcss": "^8.5.16",
4846
"prettier": "^3.9.5",
49-
"type-coverage": "^2.29.7",
5047
"typescript": "~6.0.3"
5148
},
5249
"dependencies": {

pnpm-lock.yaml

Lines changed: 198 additions & 505 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# scripts/
2+
3+
None of these run in `pnpm test` or CI — run directly with `node scripts/<name>.mjs`.
4+
5+
- **`harvest-github.mjs`** — scrapes real-world `calc()` expressions from
6+
public GitHub into `test/corpus/github/expressions.txt`.
7+
- **`split-corpus.mjs`** — splits that file into `github-pure.txt` (feeds
8+
`benchmark.mjs`/`show-divergences.mjs` below), `preprocessor.txt`, and
9+
`invalid.txt` (the latter two are used by real CI resilience tests).
10+
- **`lib/corpus.mjs`** — shared loader for `github-pure.txt`.
11+
- **`benchmark.mjs`** — times our pipeline against `@csstools/css-calc` over
12+
the pure corpus.
13+
- **`show-divergences.mjs`** — buckets where our output disagrees with
14+
`@csstools/css-calc` over the pure corpus, for manual triage.
15+
- **`tokenizer-compat.mjs`** — shared helpers for diffing token streams
16+
(not runnable on its own); used by `tokenizer-suite.mjs`.
17+
- **`tokenizer-suite.mjs`** — runs the official `@rmenke/css-tokenizer-tests`
18+
corpus through our tokenizer and reports pass/fail per category.
19+
- **`randomizer.mjs`** — long-running fuzzer: generates `calc()` inputs at
20+
increasing depth, compares against `@csstools/css-calc`, logs finds to
21+
`reports/randomizer-finds.jsonl`.

scripts/benchmark.mjs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
// Benchmark: postcss-calc (pratt) vs @csstools/css-calc on the harvested
22
// real-world corpus.
3-
import { readFileSync } from 'node:fs';
4-
import { dirname, join } from 'node:path';
5-
import { fileURLToPath } from 'node:url';
63
import { tokenize } from '../src/lib/tokenizer.js';
74
import { parse } from '../src/lib/parser.js';
85
import { simplify } from '../src/lib/simplify.js';
96
import { serialize } from '../src/lib/serialize.js';
107
import { calc as csstoolsCalc } from '@csstools/css-calc';
11-
const ROOT = dirname(fileURLToPath(import.meta.url));
12-
const CORPUS = join(ROOT, '..', 'test/corpus/github-pure.txt');
13-
const corpus = readFileSync(CORPUS, 'utf8')
14-
.split('\n')
15-
.map((l) => l.trim())
16-
.filter(Boolean);
8+
import { loadCorpus } from './lib/corpus.mjs';
9+
const corpus = loadCorpus();
1710
const ours = (s) => {
1811
try {
1912
return serialize(simplify(parse(tokenize(s))), { precision: false });

scripts/lib/corpus.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Shared corpus loader for the exploratory scripts (benchmark.mjs,
2+
// show-divergences.mjs): reads the harvested real-world calc() corpus and
3+
// splits it into trimmed, non-empty lines.
4+
import { readFileSync } from 'node:fs';
5+
import { dirname, join } from 'node:path';
6+
import { fileURLToPath } from 'node:url';
7+
8+
const ROOT = dirname(fileURLToPath(import.meta.url));
9+
const CORPUS = join(ROOT, '..', '..', 'test/corpus/github-pure.txt');
10+
11+
export function loadCorpus() {
12+
return readFileSync(CORPUS, 'utf8')
13+
.split('\n')
14+
.map((l) => l.trim())
15+
.filter(Boolean);
16+
}

scripts/show-divergences.mjs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
// Bucket github-pure corpus divergences against @csstools/css-calc.
2-
import { readFileSync } from 'node:fs';
3-
import { dirname, join } from 'node:path';
4-
import { fileURLToPath } from 'node:url';
52
import { tokenize } from '../src/lib/tokenizer.js';
63
import { parse } from '../src/lib/parser.js';
74
import { simplify } from '../src/lib/simplify.js';
85
import { serialize } from '../src/lib/serialize.js';
96
import { calc as csstoolsCalc } from '@csstools/css-calc';
10-
const ROOT = dirname(fileURLToPath(import.meta.url));
11-
const CORPUS = join(ROOT, '..', 'test/corpus/github-pure.txt');
12-
const lines = readFileSync(CORPUS, 'utf8')
13-
.split('\n')
14-
.map((l) => l.trim())
15-
.filter(Boolean);
7+
import { loadCorpus } from './lib/corpus.mjs';
8+
const lines = loadCorpus();
169
const ours = (s) => {
1710
try {
1811
return serialize(simplify(parse(tokenize(s))), { precision: 10 });

scripts/tokenizer-compat.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// @rmenke/css-tokenizer-tests JSON) onto one shape and diffs the streams.
33
// Compares decoded values, normalizing the two designed differences:
44
// function-token ≡ ident + `(`, and signed numeric ≡ punct sign + numeric.
5-
import { tokenize as ourTokenize } from '../src/lib/tokenizer.js';
65
const PUNCT_DELIMS = new Set(['+', '-', '*', '/']);
76
export class OutOfSubsetError extends Error {
87
tokenType;
@@ -93,9 +92,6 @@ export function fromOurs(tokens) {
9392
}
9493
return out;
9594
}
96-
export function tokenizeOursSimple(css) {
97-
return fromOurs(ourTokenize(css));
98-
}
9995
const isNumeric = (t) => t.type === 'number' || t.type === 'dimension';
10096
const tokenEq = (a, b) =>
10197
a.type === b.type &&

scripts/tokenizer-vs-csstools.mjs

Lines changed: 0 additions & 123 deletions
This file was deleted.
File renamed without changes.

src/lib/simplify/bucket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// rad/grad/turn, …). Buckets with `base === null` (relative or unknown
66
// units) keep their own slot.
77

8-
const { convert } = require('../type.js');
8+
const { convert } = require('../convertUnits.js');
99

1010
/**
1111
* @typedef {object} UnitBucket
1212
* @property {string} unit
1313
* @property {number} total
14-
* @property {import('../type.js').BaseType | null} base
14+
* @property {import('../convertUnits.js').BaseType | null} base
1515
* @property {number} order
1616
*/
1717

0 commit comments

Comments
 (0)