Skip to content

Commit bc55caa

Browse files
committedAug 3, 2021
Add JSDoc based types
1 parent 727b687 commit bc55caa

34 files changed

+267
-277
lines changed
 

‎.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
node_modules/
21
coverage/
2+
node_modules/
3+
packages/remark/*.d.ts
4+
packages/remark-cli/*.d.ts
5+
packages/remark-parse/lib/*.d.ts
6+
packages/remark-parse/test.d.ts
7+
packages/remark-stringify/lib/*.d.ts
8+
packages/remark-stringify/test.d.ts
9+
script/**/*.d.ts
10+
test/**/*.d.ts
311
.DS_Store
412
*.log
513
yarn.lock

‎package.json

+14-7
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,32 @@
1111
},
1212
"type": "module",
1313
"devDependencies": {
14+
"@types/mdast": "^3.0.0",
15+
"@types/tape": "^4.0.0",
1416
"c8": "^7.0.0",
1517
"camelcase": "^6.0.0",
16-
"dtslint": "^4.0.0",
1718
"execa": "^5.0.0",
1819
"lerna": "^4.0.0",
1920
"mdast-util-assert": "^4.0.0",
2021
"mdast-util-gfm": "^1.0.0",
2122
"micromark-extension-gfm": "^1.0.0",
2223
"prettier": "^2.0.0",
2324
"remark-preset-wooorm": "^8.0.0",
25+
"rimraf": "^3.0.0",
2426
"tape": "^5.0.0",
27+
"type-coverage": "^2.0.0",
2528
"typescript": "^4.0.0",
2629
"unified": "^10.0.0",
2730
"unist-util-remove-position": "^4.0.0",
2831
"xo": "^0.39.0"
2932
},
3033
"scripts": {
3134
"postinstall": "lerna bootstrap --no-ci",
35+
"build": "lerna run build && rimraf \"*.d.ts\" \"{test,script}/**/*.d.ts\" && tsc && type-coverage",
3236
"format": "./packages/remark-cli/cli.js . -qfo && prettier . -w --loglevel warn && xo --fix",
33-
"test-api": "node --conditions development test/index.js && lerna run test",
37+
"test-api": "lerna run test && node --conditions development test/index.js",
3438
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
35-
"test": "npm run format && npm run test-coverage"
39+
"test": "npm run build && npm run format && npm run test-coverage"
3640
},
3741
"prettier": {
3842
"tabWidth": 2,
@@ -43,14 +47,17 @@
4347
"trailingComma": "none"
4448
},
4549
"xo": {
46-
"prettier": true,
47-
"ignores": [
48-
"**/types"
49-
]
50+
"prettier": true
5051
},
5152
"remarkConfig": {
5253
"plugins": [
5354
"preset-wooorm"
5455
]
56+
},
57+
"typeCoverage": {
58+
"atLeast": 100,
59+
"detail": true,
60+
"strict": true,
61+
"ignoreCatch": true
5562
}
5663
}

‎packages/remark-cli/cli.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const extensions = [
2121
]
2222

2323
args({
24+
// @ts-expect-error: fine.
2425
processor: remark,
2526
name: proc.name,
2627
description: cli.description,

‎packages/remark-cli/package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@
3535
"unified-args": "^9.0.0"
3636
},
3737
"scripts": {
38+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
3839
"test": "node --conditions development test.js"
3940
},
40-
"xo": false
41+
"xo": false,
42+
"typeCoverage": {
43+
"atLeast": 100,
44+
"detail": true,
45+
"strict": true,
46+
"ignoreCatch": true
47+
}
4148
}

‎packages/remark-cli/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import url from 'url'
1+
import {URL, fileURLToPath} from 'url'
22
import execa from 'execa'
33
import test from 'tape'
44

55
test('remark-cli', (t) => {
66
t.plan(2)
77

88
t.test('should show help on `--help`', (t) => {
9-
const bin = url.fileURLToPath(new URL('./cli.js', import.meta.url))
9+
const bin = fileURLToPath(new URL('./cli.js', import.meta.url))
1010

1111
t.plan(1)
1212

@@ -63,7 +63,7 @@ test('remark-cli', (t) => {
6363
})
6464

6565
t.test('should show version on `--version`', (t) => {
66-
const bin = url.fileURLToPath(new URL('./cli.js', import.meta.url))
66+
const bin = fileURLToPath(new URL('./cli.js', import.meta.url))
6767

6868
t.plan(2)
6969

‎packages/remark-cli/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["*.js"]
4+
}

‎packages/remark-parse/index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This wrapper exists because JS in TS can’t export a `@type` of a function.
2+
import type {Options} from './lib/index.js'
3+
import type {Root} from 'mdast'
4+
import type {Plugin} from 'unified'
5+
declare const remarkParse: Plugin<[Options?] | void[], string, Root>
6+
export default remarkParse
7+
export type {Options}

‎packages/remark-parse/index.js

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
import {fromMarkdown} from 'mdast-util-from-markdown'
1+
import remarkParse from './lib/index.js'
22

3-
export default function remarkParse(options) {
4-
this.Parser = (doc) => {
5-
return fromMarkdown(
6-
doc,
7-
Object.assign({}, this.data('settings'), options, {
8-
// Note: these options are not in the readme.
9-
// The goal is for them to be set by plugins on `data` instead of being
10-
// passed by users.
11-
extensions: this.data('micromarkExtensions') || [],
12-
mdastExtensions: this.data('fromMarkdownExtensions') || []
13-
})
14-
)
15-
}
16-
}
3+
export default remarkParse

‎packages/remark-parse/lib/index.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @typedef {import('mdast').Root} Root
3+
* @typedef {import('mdast-util-from-markdown').Options} Options
4+
*/
5+
6+
import {fromMarkdown} from 'mdast-util-from-markdown'
7+
8+
/** @type {import('unified').Plugin<[Options?] | void[], string, Root>} */
9+
export default function remarkParse(options) {
10+
/** @type {import('unified').ParserFunction<Root>} */
11+
const parser = (doc) => {
12+
// Assume options.
13+
const settings = /** @type {Options} */ (this.data('settings'))
14+
15+
return fromMarkdown(
16+
doc,
17+
Object.assign({}, settings, options, {
18+
// Note: these options are not in the readme.
19+
// The goal is for them to be set by plugins on `data` instead of being
20+
// passed by users.
21+
extensions: this.data('micromarkExtensions') || [],
22+
mdastExtensions: this.data('fromMarkdownExtensions') || []
23+
})
24+
)
25+
}
26+
27+
Object.assign(this, {Parser: parser})
28+
}

‎packages/remark-parse/package.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,26 @@
3434
"sideEffects": false,
3535
"type": "module",
3636
"main": "index.js",
37+
"types": "index.d.ts",
3738
"files": [
39+
"lib/",
40+
"index.d.ts",
3841
"index.js"
3942
],
4043
"dependencies": {
41-
"mdast-util-from-markdown": "^1.0.0"
44+
"@types/mdast": "^3.0.0",
45+
"mdast-util-from-markdown": "^1.0.0",
46+
"unified": "^10.0.0"
4247
},
4348
"scripts": {
44-
"test": "node --conditions development test.js"
49+
"test": "node --conditions development test.js",
50+
"build": "rimraf \"test.d.ts\" \"lib/**/*.d.ts\" && tsc && type-coverage"
4551
},
46-
"xo": false
52+
"xo": false,
53+
"typeCoverage": {
54+
"atLeast": 100,
55+
"detail": true,
56+
"strict": true,
57+
"ignoreCatch": true
58+
}
4759
}

‎packages/remark-parse/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["lib/**/*.js", "test.js"]
4+
}

‎packages/remark-parse/types/index.d.ts

-14
This file was deleted.

‎packages/remark-parse/types/test.ts

-7
This file was deleted.

‎packages/remark-parse/types/tsconfig.json

-10
This file was deleted.

‎packages/remark-parse/types/tslint.json

-14
This file was deleted.

‎packages/remark-stringify/index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This wrapper exists because JS in TS can’t export a `@type` of a function.
2+
import type {Options} from './lib/index.js'
3+
import type {Root} from 'mdast'
4+
import type {Plugin} from 'unified'
5+
declare const remarkStringify: Plugin<[Options?] | void[], Root, string>
6+
export default remarkStringify
7+
export type {Options}

‎packages/remark-stringify/index.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
import {toMarkdown} from 'mdast-util-to-markdown'
1+
import remarkStringify from './lib/index.js'
22

3-
export default function remarkStringify(options) {
4-
this.Compiler = (tree) => {
5-
return toMarkdown(
6-
tree,
7-
Object.assign({}, this.data('settings'), options, {
8-
// Note: this option is not in the readme.
9-
// The goal is for it to be set by plugins on `data` instead of being
10-
// passed by users.
11-
extensions: this.data('toMarkdownExtensions') || []
12-
})
13-
)
14-
}
15-
}
3+
export default remarkStringify
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @typedef {import('mdast').Root|import('mdast').Content} Node
3+
* @typedef {import('mdast-util-to-markdown').Options} Options
4+
*/
5+
6+
import {toMarkdown} from 'mdast-util-to-markdown'
7+
8+
/** @type {import('unified').Plugin<[Options]|void[], Node, string>} */
9+
export default function remarkStringify(options) {
10+
/** @type {import('unified').CompilerFunction<Node, string>} */
11+
const compiler = (tree) => {
12+
// Assume options.
13+
const settings = /** @type {Options} */ (this.data('settings'))
14+
15+
return toMarkdown(
16+
tree,
17+
Object.assign({}, settings, options, {
18+
// Note: this option is not in the readme.
19+
// The goal is for it to be set by plugins on `data` instead of being
20+
// passed by users.
21+
extensions: this.data('toMarkdownExtensions') || []
22+
})
23+
)
24+
}
25+
26+
Object.assign(this, {Compiler: compiler})
27+
}

‎packages/remark-stringify/package.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,26 @@
3434
"sideEffects": false,
3535
"type": "module",
3636
"main": "index.js",
37+
"types": "index.d.ts",
3738
"files": [
39+
"lib/",
40+
"index.d.ts",
3841
"index.js"
3942
],
4043
"dependencies": {
41-
"mdast-util-to-markdown": "^1.0.0"
44+
"@types/mdast": "^3.0.0",
45+
"mdast-util-to-markdown": "^1.0.0",
46+
"unified": "^10.0.0"
4247
},
4348
"scripts": {
44-
"test": "node --conditions development test.js"
49+
"test": "node --conditions development test.js",
50+
"build": "rimraf \"test.d.ts\" \"lib/**/*.d.ts\" && tsc && type-coverage"
4551
},
46-
"xo": false
52+
"xo": false,
53+
"typeCoverage": {
54+
"atLeast": 100,
55+
"detail": true,
56+
"strict": true,
57+
"ignoreCatch": true
58+
}
4759
}

‎packages/remark-stringify/test.js

+52-34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* @typedef {import('mdast').Root} Root
3+
* @typedef {import('mdast').Content} Content
4+
* @typedef {import('mdast').BlockContent} BlockContent
5+
* @typedef {import('./index.js').Options} Options
6+
*/
7+
18
import test from 'tape'
29
import {unified} from 'unified'
310
import {gfmToMarkdown} from 'mdast-util-gfm'
@@ -19,6 +26,7 @@ test('remarkStringify', (t) => {
1926

2027
t.throws(
2128
() => {
29+
// @ts-expect-error: not a node.
2230
unified().use(remarkStringify).stringify(false)
2331
},
2432
/false/,
@@ -27,6 +35,7 @@ test('remarkStringify', (t) => {
2735

2836
t.throws(
2937
() => {
38+
// @ts-expect-error: not a known node.
3039
unified().use(remarkStringify).stringify({type: 'unicorn'})
3140
},
3241
/unicorn/,
@@ -38,7 +47,12 @@ test('remarkStringify', (t) => {
3847
unified()
3948
.use(remarkStringify)
4049
.data('settings', {bullet: true})
41-
.stringify({type: 'listItem'})
50+
.stringify({
51+
type: 'root',
52+
children: [
53+
{type: 'list', children: [{type: 'listItem', children: []}]}
54+
]
55+
})
4256
},
4357
/options\.bullet/,
4458
'should throw when `options.bullet` is not a valid list bullet'
@@ -49,7 +63,12 @@ test('remarkStringify', (t) => {
4963
unified()
5064
.use(remarkStringify)
5165
.data('settings', {listItemIndent: 'foo'})
52-
.stringify({type: 'listItem'})
66+
.stringify({
67+
type: 'root',
68+
children: [
69+
{type: 'list', children: [{type: 'listItem', children: []}]}
70+
]
71+
})
5372
},
5473
/options\.listItemIndent/,
5574
'should throw when `options.listItemIndent` is not a valid constant'
@@ -60,7 +79,7 @@ test('remarkStringify', (t) => {
6079
unified()
6180
.use(remarkStringify)
6281
.data('settings', {rule: true})
63-
.stringify({type: 'thematicBreak'})
82+
.stringify({type: 'root', children: [{type: 'thematicBreak'}]})
6483
},
6584
/options\.rule/,
6685
'should throw when `options.rule` is not a valid horizontal rule bullet'
@@ -71,7 +90,7 @@ test('remarkStringify', (t) => {
7190
unified()
7291
.use(remarkStringify)
7392
.data('settings', {ruleRepetition: 1})
74-
.stringify({type: 'thematicBreak'})
93+
.stringify({type: 'root', children: [{type: 'thematicBreak'}]})
7594
},
7695
/options\.ruleRepetition/,
7796
'should throw when `options.ruleRepetition` is too low'
@@ -82,7 +101,7 @@ test('remarkStringify', (t) => {
82101
unified()
83102
.use(remarkStringify)
84103
.data('settings', {ruleRepetition: true})
85-
.stringify({type: 'thematicBreak'})
104+
.stringify({type: 'root', children: [{type: 'thematicBreak'}]})
86105
},
87106
/options\.ruleRepetition/,
88107
'should throw when `options.ruleRepetition` is not a number'
@@ -93,7 +112,7 @@ test('remarkStringify', (t) => {
93112
unified()
94113
.use(remarkStringify)
95114
.data('settings', {emphasis: '-'})
96-
.stringify({type: 'emphasis'})
115+
.stringify({type: 'root', children: [{type: 'emphasis', children: []}]})
97116
},
98117
/options\.emphasis/,
99118
'should throw when `options.emphasis` is not a valid emphasis marker'
@@ -104,7 +123,7 @@ test('remarkStringify', (t) => {
104123
unified()
105124
.use(remarkStringify)
106125
.data('settings', {strong: '-'})
107-
.stringify({type: 'strong'})
126+
.stringify({type: 'root', children: [{type: 'strong', children: []}]})
108127
},
109128
/options\.strong/,
110129
'should throw when `options.strong` is not a valid emphasis marker'
@@ -115,7 +134,7 @@ test('remarkStringify', (t) => {
115134
unified()
116135
.use(remarkStringify)
117136
.data('settings', {fence: '-'})
118-
.stringify({type: 'code'})
137+
.stringify({type: 'root', children: [{type: 'code', value: ''}]})
119138
},
120139
/options\.fence/,
121140
'should throw when `options.fence` is not a valid fence marker'
@@ -248,13 +267,10 @@ test('remarkStringify', (t) => {
248267
)
249268

250269
t.end()
251-
252-
function toString(value) {
253-
return String(unified().use(remarkStringify).stringify(value))
254-
}
255270
})
256271

257272
t.test('should support optional list item fields', (t) => {
273+
/** @type {BlockContent[]} */
258274
const children = [
259275
{type: 'paragraph', children: [{type: 'text', value: 'alpha'}]},
260276
{
@@ -284,20 +300,12 @@ test('remarkStringify', (t) => {
284300
)
285301

286302
t.end()
287-
288-
function toString(value) {
289-
return String(unified().use(remarkStringify).stringify(value))
290-
}
291303
})
292304

293305
t.test('should support empty list items', (t) => {
294306
t.equal(toString({type: 'listItem', children: []}), '*\n')
295307

296308
t.end()
297-
298-
function toString(value) {
299-
return String(unified().use(remarkStringify).stringify(value))
300-
}
301309
})
302310

303311
t.test('should process references with casing properly', (t) => {
@@ -340,23 +348,25 @@ test('remarkStringify', (t) => {
340348
toString({
341349
type: 'linkReference',
342350
identifier: 'a',
351+
referenceType: 'full',
343352
children: [{type: 'text', value: 'b'}]
344353
}),
345354
'[b][a]\n',
346355
'link reference'
347356
)
348357

349358
t.equal(
350-
toString({type: 'imageReference', identifier: 'a', alt: 'b'}),
359+
toString({
360+
type: 'imageReference',
361+
referenceType: 'full',
362+
identifier: 'a',
363+
alt: 'b'
364+
}),
351365
'![b][a]\n',
352366
'image reference'
353367
)
354368

355369
t.end()
356-
357-
function toString(value) {
358-
return String(unified().use(remarkStringify).stringify(value))
359-
}
360370
})
361371

362372
t.test('should stringify mailto links properly', (t) => {
@@ -407,12 +417,12 @@ test('stringify escapes', (t) => {
407417
t.equal(toString('a&amp;b'), 'a\\&amp;b\n', 'entities')
408418
t.equal(toString('a]b'), 'a]b\n', '`]`')
409419
t.equal(
410-
toString({type: 'link', children: [{type: 'text', value: 'a]b'}]}),
420+
toString({type: 'link', url: '', children: [{type: 'text', value: 'a]b'}]}),
411421
'[a\\]b]()\n',
412422
'`]` (in links)'
413423
)
414424
t.equal(
415-
toString({type: 'image', alt: 'a]b'}),
425+
toString({type: 'image', url: '', alt: 'a]b'}),
416426
'![a\\]b]()\n',
417427
'`]` (in images)'
418428
)
@@ -456,7 +466,7 @@ test('stringify escapes', (t) => {
456466
type: 'paragraph',
457467
children: [
458468
{type: 'text', value: '!'},
459-
{type: 'link', children: [{type: 'text', value: 'a'}]}
469+
{type: 'link', url: '', children: [{type: 'text', value: 'a'}]}
460470
]
461471
}),
462472
'\\![a]()\n',
@@ -549,7 +559,7 @@ test('extensions', (t) => {
549559
{
550560
type: 'list',
551561
ordered: false,
552-
start: null,
562+
start: undefined,
553563
spread: false,
554564
children: [
555565
{
@@ -602,11 +612,19 @@ test('extensions', (t) => {
602612
t.end()
603613
})
604614

615+
/**
616+
* @param {Root|Content|string} value
617+
* @param {Options} [options]
618+
* @returns {string}
619+
*/
605620
function toString(value, options) {
606-
const tree =
607-
typeof value === 'string'
608-
? {type: 'paragraph', children: [{type: 'text', value}]}
609-
: value
621+
if (typeof value === 'string') {
622+
value = {type: 'paragraph', children: [{type: 'text', value}]}
623+
}
624+
625+
if (value.type !== 'root') {
626+
value = {type: 'root', children: [value]}
627+
}
610628

611-
return unified().use(remarkStringify, options).stringify(tree)
629+
return unified().use(remarkStringify, options).stringify(value)
612630
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["lib/**/*.js", "test.js"]
4+
}

‎packages/remark-stringify/types/index.d.ts

-14
This file was deleted.

‎packages/remark-stringify/types/test.ts

-37
This file was deleted.

‎packages/remark-stringify/types/tsconfig.json

-10
This file was deleted.

‎packages/remark-stringify/types/tslint.json

-14
This file was deleted.

‎packages/remark/package.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"sideEffects": false,
3333
"type": "module",
3434
"main": "index.js",
35+
"types": "index.d.ts",
3536
"files": [
37+
"index.d.ts",
3638
"index.js"
3739
],
3840
"dependencies": {
@@ -41,7 +43,14 @@
4143
"unified": "^10.0.0"
4244
},
4345
"scripts": {
44-
"test": "node --conditions development test.js"
46+
"test": "node --conditions development test.js",
47+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
4548
},
46-
"xo": false
49+
"xo": false,
50+
"typeCoverage": {
51+
"atLeast": 100,
52+
"detail": true,
53+
"strict": true,
54+
"ignoreCatch": true
55+
}
4756
}

‎packages/remark/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["*.js"]
4+
}

‎packages/remark/types/index.d.ts

-19
This file was deleted.

‎packages/remark/types/test.ts

-21
This file was deleted.

‎packages/remark/types/tsconfig.json

-10
This file was deleted.

‎packages/remark/types/tslint.json

-15
This file was deleted.

‎script/regenerate-fixtures.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
/** @typedef {import('mdast').Root} Root */
2+
13
import fs from 'fs'
24
import path from 'path'
35
import {remark} from '../packages/remark/index.js'
46
import {fixtures} from '../test/fixtures/index.js'
57

68
const base = path.join('test', 'fixtures', 'tree')
9+
/** @type {string[]} */
710
const generated = []
811
let index = -1
912

1013
while (++index < fixtures.length) {
1114
const fixture = fixtures[index]
1215
const stem = path.basename(fixture.name, path.extname(fixture.name))
1316
const input = fixture.input
17+
/** @type {Root} */
1418
let result
1519

1620
try {

‎test/fixtures/index.js

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @typedef {import('mdast').Root} Root */
2+
13
import fs from 'fs'
24
import path from 'path'
35
import camelcase from 'camelcase'
@@ -12,9 +14,10 @@ const defaults = {
1214
incrementListMarker: true,
1315
listItemIndent: 'tab',
1416
quote: '"',
17+
resourceLink: false,
1518
rule: '*',
16-
ruleSpaces: true,
1719
ruleRepetition: 3,
20+
ruleSpaces: true,
1821
setext: false,
1922
strong: '*',
2023
tightDefinitions: false
@@ -32,10 +35,11 @@ export const fixtures = fs
3235
fs.readFileSync(path.join('test', 'fixtures', 'input', basename))
3336
)
3437
const treePath = path.join('test', 'fixtures', 'tree', stem + '.json')
38+
/** @type {Root|undefined} */
3539
let tree
3640

3741
if (fs.existsSync(treePath)) {
38-
tree = JSON.parse(fs.readFileSync(treePath))
42+
tree = JSON.parse(String(fs.readFileSync(treePath)))
3943
}
4044

4145
return {
@@ -47,21 +51,29 @@ export const fixtures = fs
4751
}
4852
})
4953

50-
// Parse options from a filename.
54+
/**
55+
* Parse options from a filename.
56+
*
57+
* @param {string} name
58+
*/
5159
function parseOptions(name) {
5260
const parts = name.split('.')
53-
const length = parts.length
54-
const options = {stringify: Object.assign({}, defaults)}
61+
const options = {
62+
/** @type {boolean|undefined} */
63+
output: undefined,
64+
/** @type {Record<string, string|number|boolean>} */
65+
stringify: Object.assign({}, defaults)
66+
}
5567
let index = -1
5668

57-
while (++index < length) {
69+
while (++index < parts.length) {
5870
const part = parts[index].split('=')
5971
const augmented = augment(part[0], part.slice(1).join('='))
6072
const key = augmented.key
6173
const value = augmented.value
6274

6375
if (key === 'output') {
64-
options[key] = value
76+
options[key] = Boolean(value)
6577
} else if (key in defaults && value !== options.stringify[key]) {
6678
options.stringify[key] = value
6779
}
@@ -70,8 +82,16 @@ function parseOptions(name) {
7082
return options
7183
}
7284

73-
// Parse a `string` `value` into a javascript value.
74-
function augment(key, value) {
85+
/**
86+
* Parse a `string` `value` into a javascript value.
87+
*
88+
* @param {string} key
89+
* @param {string} input
90+
*/
91+
function augment(key, input) {
92+
/** @type {string|boolean|number} */
93+
let value = input
94+
7595
if (!value) {
7696
value = key.slice(0, 2) !== 'no'
7797

‎tsconfig.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"include": ["script/**/*.js", "test/**/*.js"],
3+
"compilerOptions": {
4+
"target": "ES2020",
5+
"lib": ["ES2020"],
6+
"module": "ES2020",
7+
"moduleResolution": "node",
8+
"resolveJsonModule": true,
9+
"allowJs": true,
10+
"checkJs": true,
11+
"declaration": true,
12+
"emitDeclarationOnly": true,
13+
"allowSyntheticDefaultImports": true,
14+
"skipLibCheck": true,
15+
"strict": true
16+
}
17+
}

0 commit comments

Comments
 (0)
Please sign in to comment.