Skip to content

Commit 15f9f38

Browse files
authored
Breaking: replace linkedom with naive little hand-rolled HTML parser (#21)
1 parent 4c57127 commit 15f9f38

File tree

12 files changed

+149
-272
lines changed

12 files changed

+149
-272
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let coverage = await page.coverage.stopCSSCoverage()
5353
// Now we can process it
5454
import { calculate_coverage } from '@projectwallace/css-code-coverage'
5555

56-
let report = await calculcate_coverage(coverage)
56+
let report = calculcate_coverage(coverage)
5757
```
5858

5959
### Browser devtools

package-lock.json

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

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@playwright/test": "^1.56.0",
4848
"@types/node": "^24.8.1",
4949
"c8": "^10.1.3",
50-
"linkedom": "^0.18.12",
5150
"oxlint": "^1.22.0",
5251
"publint": "^0.3.14",
5352
"tsdown": "^0.15.8",

src/lib/filter-entries.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import { test, expect } from '@playwright/test'
22
import { filter_coverage } from './filter-entries.js'
33

4-
test('filters out JS files', async () => {
4+
test('filters out JS files', () => {
55
let entries = [
66
{
77
url: 'http://example.com/script.js',
88
text: 'console.log("Hello world")',
99
ranges: [{ start: 0, end: 25 }],
1010
},
1111
]
12-
expect(await filter_coverage(entries)).toEqual([])
12+
expect(filter_coverage(entries)).toEqual([])
1313
})
1414

15-
test('keeps files with CSS extension', async () => {
15+
test('keeps files with CSS extension', () => {
1616
let entries = [
1717
{
1818
url: 'http://example.com/styles.css',
1919
text: 'a{color:red}',
2020
ranges: [{ start: 0, end: 13 }],
2121
},
2222
]
23-
expect(await filter_coverage(entries)).toEqual(entries)
23+
expect(filter_coverage(entries)).toEqual(entries)
2424
})
2525

26-
test('keeps extension-less URL with HTML text', async () => {
26+
test('keeps extension-less URL with HTML text', () => {
2727
let entries = [
2828
{
2929
url: 'http://example.com',
@@ -38,16 +38,16 @@ test('keeps extension-less URL with HTML text', async () => {
3838
ranges: [{ start: 0, end: 13 }], // ranges are remapped
3939
},
4040
]
41-
expect(await filter_coverage(entries)).toEqual(expected)
41+
expect(filter_coverage(entries)).toEqual(expected)
4242
})
4343

44-
test('keeps extension-less URL with CSS text (running coverage in vite dev mode)', async () => {
44+
test('keeps extension-less URL with CSS text (running coverage in vite dev mode)', () => {
4545
let entries = [
4646
{
4747
url: 'http://example.com',
4848
text: 'a{color:red;}',
4949
ranges: [{ start: 0, end: 13 }],
5050
},
5151
]
52-
expect(await filter_coverage(entries)).toEqual(entries)
52+
expect(filter_coverage(entries)).toEqual(entries)
5353
})

src/lib/filter-entries.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function is_html(text: string): boolean {
66
return /<\/?(html|body|head|div|span|script|style)/i.test(text)
77
}
88

9-
export async function filter_coverage(coverage: Coverage[]): Promise<Coverage[]> {
9+
export function filter_coverage(coverage: Coverage[]): Coverage[] {
1010
let result = []
1111

1212
for (let entry of coverage) {
@@ -20,7 +20,7 @@ export async function filter_coverage(coverage: Coverage[]): Promise<Coverage[]>
2020
}
2121

2222
if (is_html(entry.text)) {
23-
let { css, ranges } = await remap_html(entry.text, entry.ranges)
23+
let { css, ranges } = remap_html(entry.text, entry.ranges)
2424
result.push({
2525
url: entry.url,
2626
text: css,

0 commit comments

Comments
 (0)