Skip to content

Commit 5486f05

Browse files
test(css): strictly type the new block-contents walk tests
Annotate the visitor arrays and cast the `VisitorMap` / visitor params, matching the strict test-suite typing introduced on main (#21147), so the two added `as: "block-contents"` tests pass `tsc -p tsconfig.types.test.json`. https://claude.ai/code/session_01RtuVwAXk4wSAPE85d8qadX
1 parent cbdd90e commit 5486f05

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

test/walkCssTokensParser.unittest.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,21 @@ describe("walkCssTokens — SourceProcessor", () => {
408408
});
409409

410410
it('as: "block-contents" walks a block\'s contents (style attribute)', () => {
411+
/** @type {string[]} */
411412
const names = [];
413+
/** @type {string[]} */
412414
const urls = [];
413415
new SourceProcessor()
414-
.use({
415-
[NodeType.Declaration]: (n) => names.push(n.name),
416-
[NodeType.Url]: (n) => urls.push(n.value)
417-
})
416+
.use(
417+
/** @type {import("../lib/css/walkCssTokens").VisitorMap} */ ({
418+
[NodeType.Declaration]: (
419+
/** @type {import("../lib/css/walkCssTokens").Declaration} */ n
420+
) => names.push(n.name),
421+
[NodeType.Url]: (
422+
/** @type {import("../lib/css/walkCssTokens").UrlToken} */ n
423+
) => urls.push(n.value)
424+
})
425+
)
418426
.process("color: red; background: url(a.png)", {
419427
as: "block-contents"
420428
});
@@ -423,9 +431,16 @@ describe("walkCssTokens — SourceProcessor", () => {
423431
});
424432

425433
it('the default "stylesheet" mode treats a top-level declaration as a parse error', () => {
434+
/** @type {string[]} */
426435
const names = [];
427436
new SourceProcessor()
428-
.use({ [NodeType.Declaration]: (n) => names.push(n.name) })
437+
.use(
438+
/** @type {import("../lib/css/walkCssTokens").VisitorMap} */ ({
439+
[NodeType.Declaration]: (
440+
/** @type {import("../lib/css/walkCssTokens").Declaration} */ n
441+
) => names.push(n.name)
442+
})
443+
)
429444
.process("color: red; background: url(a.png)");
430445
expect(names).toEqual([]);
431446
});

0 commit comments

Comments
 (0)