Skip to content

Commit b79b73a

Browse files
authored
Miscellaneous cleaning tasks (#1915)
Reviewed-by: Christian Murphy <[email protected]>
1 parent 4ca2299 commit b79b73a

33 files changed

+101
-90
lines changed

docs/community/contribute.server.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ This produces the website in `public/`.
9393

9494
### Release
9595

96-
{/* To do: update release guidelines */}
97-
9896
To release a new version, do:
9997

10098
1. update `version`s of packages with a patch, minor, or major (make sure to
@@ -123,7 +121,7 @@ To release a new version, do:
123121
* [Using pull requests](https://help.github.com/articles/about-pull-requests/)
124122
* [GitHub help](https://help.github.com)
125123

126-
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
124+
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
127125

128126
[unit-test]: https://twitter.com/sindresorhus/status/579306280495357953
129127

docs/community/support.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Here are some tips:
4545
messages in them, please also provide those as text
4646
* The more time you put into asking your question, the better we can help you
4747

48-
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
48+
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
4949

5050
[rubberduck]: https://rubberduckdebugging.com
5151

packages/esbuild/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"prepack": "npm run build",
5959
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
6060
"test-api": "uvu test \"\\.js$\"",
61-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
61+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
6262
"test": "npm run build && npm run test-coverage"
6363
},
6464
"xo": false,

packages/esbuild/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ abide by its terms.
196196

197197
[support]: https://mdxjs.com/community/support/
198198

199-
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
199+
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
200200

201201
[mit]: https://github.com/mdx-js/mdx/blob/main/packages/esbuild/license
202202

packages/esbuild/test/index.test.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,28 @@ test('@mdx-js/esbuild', async () => {
240240
* @param {VFile} file
241241
*/
242242
(tree, file) => {
243+
const esm = tree.children[0] // Export
244+
// @ts-expect-error To do: mdast-util-mdx should probably also extend hast?
245+
assert.ok(esm && esm.type === 'mdxjsEsm')
246+
const eol = tree.children[1] // EOL between both, no position.
247+
assert.ok(eol && eol.type === 'text')
248+
assert.ok(!eol.position)
249+
const head = tree.children[2] // Heading
250+
assert.ok(head && head.type === 'element')
251+
assert.ok(head.position)
252+
const text = head.children[0] // Text in heading
253+
assert.ok(text && text.type === 'text')
254+
const jsx = head.children[1] // JSX in heading
255+
// @ts-expect-error To do: mdast-util-mdx should probably also extend hast?
256+
assert.ok(jsx && jsx.type === 'mdxJsxTextElement')
257+
console.log(head)
243258
file.message('1')
244-
file.message('2', tree.children[1]) // EOL between both, no position.
259+
file.message('2', eol)
245260
file.message('3', tree)
246-
file.message('4', tree.children[0]) // Export
247-
// @ts-expect-error: fine.
248-
file.message('5', tree.children[2].children[0]) // Text in heading
249-
// @ts-expect-error: fine.
250-
file.message('6', tree.children[2].children[1]) // Expression in heading
251-
// @ts-expect-error: fine.
252-
file.message('7', tree.children[2].position.end).fatal = true // End of heading
261+
file.message('4', esm)
262+
file.message('5', text) // Text in heading
263+
file.message('6', jsx) // JSX in heading
264+
file.message('7', head.position.end).fatal = true // End of heading
253265
}
254266
]
255267
})

packages/loader/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"prepack": "npm run build",
6868
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" && tsc && type-coverage",
6969
"test-api": "uvu test \"\\.js$\"",
70-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
70+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
7171
"test": "npm run build && npm run test-coverage"
7272
},
7373
"xo": false,

packages/loader/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ abide by its terms.
183183

184184
[support]: https://mdxjs.com/community/support/
185185

186-
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
186+
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
187187

188188
[mit]: https://github.com/mdx-js/mdx/blob/main/packages/loader/license
189189

packages/loader/test/index.test.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test('@mdx-js/loader', async () => {
2929

3030
// React.
3131
await promisify(webpack)({
32-
// @ts-expect-error context does not exist on the webpack options types.
32+
// @ts-expect-error To do: webpack types miss support for `context`.
3333
context: fileURLToPath(base),
3434
entry: './webpack.mdx',
3535
mode: 'none',
@@ -49,14 +49,13 @@ test('@mdx-js/loader', async () => {
4949
})
5050

5151
// One for ESM loading CJS, one for webpack.
52-
const ContentReact = /** @type {MDXContent} */ (
53-
/* @ts-expect-error file is dynamically generated */
54-
// type-coverage:ignore-next-line
55-
(await import('./react.cjs')).default.default
52+
const modReact = /** @type {{default: {default: MDXContent}}} */ (
53+
// @ts-expect-error file is dynamically generated
54+
await import('./react.cjs')
5655
)
5756

5857
assert.equal(
59-
renderToStaticMarkup(React.createElement(ContentReact)),
58+
renderToStaticMarkup(React.createElement(modReact.default.default)),
6059
'<h1>Hello, World!</h1>',
6160
'should compile (react)'
6261
)
@@ -65,7 +64,7 @@ test('@mdx-js/loader', async () => {
6564

6665
// Preact and source maps
6766
await promisify(webpack)({
68-
// @ts-expect-error context does not exist on the webpack options types.
67+
// @ts-expect-error To do: webpack types miss support for `context`.
6968
context: fileURLToPath(base),
7069
entry: './webpack.mdx',
7170
mode: 'development',
@@ -91,14 +90,13 @@ test('@mdx-js/loader', async () => {
9190
})
9291

9392
// One for ESM loading CJS, one for webpack.
94-
const ContentPreact = /** @type {PreactComponent} */ (
95-
/* @ts-expect-error file is dynamically generated */
96-
// type-coverage:ignore-next-line
97-
(await import('./preact.cjs')).default.default
93+
const modPreact = /** @type {{default: {default: PreactComponent}}} */ (
94+
// @ts-expect-error file is dynamically generated.
95+
await import('./preact.cjs')
9896
)
9997

10098
assert.equal(
101-
render(h(ContentPreact, {})),
99+
render(h(modPreact.default.default, {})),
102100
'<h1>Hello, World!</h1>',
103101
'should compile (preact)'
104102
)
@@ -113,7 +111,7 @@ test('@mdx-js/loader', async () => {
113111

114112
// Vue.
115113
await promisify(webpack)({
116-
// @ts-expect-error context does not exist on the webpack options types.
114+
// @ts-expect-error To do: webpack types miss support for `context`.
117115
context: fileURLToPath(base),
118116
entry: './webpack.mdx',
119117
mode: 'none',
@@ -143,15 +141,14 @@ test('@mdx-js/loader', async () => {
143141
})
144142

145143
// One for ESM loading CJS, one for webpack.
146-
const ContentVue = /** @type {VueComponent} */ (
147-
/* @ts-expect-error file is dynamically generated */
148-
// type-coverage:ignore-next-line
149-
(await import('./vue.cjs')).default.default
144+
const modVue = /** @type {{default: {default: VueComponent}}} */ (
145+
// @ts-expect-error file is dynamically generated
146+
await import('./vue.cjs')
150147
)
151148

152149
const vueResult = await serverRenderer.renderToString(
153150
vue.createSSRApp({
154-
components: {Content: ContentVue},
151+
components: {Content: modVue.default.default},
155152
template: '<Content />'
156153
})
157154
)

packages/mdx/lib/core.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export function createProcessor(options = {}) {
8686
}
8787
}
8888

89-
// @ts-expect-error allowed in `compile`, but not here.
89+
// @ts-expect-error runtime exception for disallowed field here, which is
90+
// allowed in `compile`.
9091
if (format === 'detect') {
9192
throw new Error(
9293
"Incorrect `format: 'detect'`: `createProcessor` can support either `md` or `mdx`; it does not support detecting the format"

packages/mdx/lib/node-types.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// List of node types made by `mdast-util-mdx`, which have to be passed
2-
// through untouched from the mdast tree to the hast tree.
1+
/**
2+
* List of node types made by `mdast-util-mdx`, which have to be passed
3+
* through untouched from the mdast tree to the hast tree.
4+
*/
35
export const nodeTypes = [
46
'mdxFlowExpression',
57
'mdxJsxFlowElement',

packages/mdx/lib/plugin/recma-stringify.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
* in.
2929
*/
3030

31-
// @ts-expect-error baseGenerator is not yet exported by astring typings
32-
import {baseGenerator, generate} from 'astring'
31+
import {GENERATOR, generate} from 'astring'
3332

3433
/**
3534
* A plugin that adds an esast compiler: a small wrapper around `astring` to add
@@ -51,24 +50,26 @@ export function recmaStringify(options = {}) {
5150
sourceMap = new SourceMapGenerator({file: file.path || 'unknown.mdx'})
5251
}
5352

53+
const generator = {
54+
...GENERATOR,
55+
JSXAttribute,
56+
JSXClosingElement,
57+
JSXClosingFragment,
58+
JSXElement,
59+
JSXEmptyExpression,
60+
JSXExpressionContainer,
61+
JSXFragment,
62+
JSXIdentifier,
63+
JSXMemberExpression,
64+
JSXNamespacedName,
65+
JSXOpeningElement,
66+
JSXOpeningFragment,
67+
JSXSpreadAttribute,
68+
JSXText
69+
}
70+
5471
const result = generate(tree, {
55-
generator: {
56-
...baseGenerator,
57-
JSXAttribute,
58-
JSXClosingElement,
59-
JSXClosingFragment,
60-
JSXElement,
61-
JSXEmptyExpression,
62-
JSXExpressionContainer,
63-
JSXFragment,
64-
JSXIdentifier,
65-
JSXMemberExpression,
66-
JSXNamespacedName,
67-
JSXOpeningElement,
68-
JSXOpeningFragment,
69-
JSXSpreadAttribute,
70-
JSXText
71-
},
72+
generator,
7273
comments: true,
7374
sourceMap
7475
})

packages/mdx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"prepack": "npm run build",
8686
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
8787
"test-api": "uvu test \"^(compile|evaluate)\\.js$\"",
88-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
88+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
8989
"test": "npm run build && npm run test-coverage"
9090
},
9191
"xo": false,

packages/mdx/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ abide by its terms.
10351035

10361036
[support]: https://mdxjs.com/community/support/
10371037

1038-
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
1038+
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
10391039

10401040
[mit]: https://github.com/mdx-js/mdx/blob/main/packages/mdx/license
10411041

packages/mdx/test/compile.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,13 @@ test('compile', async () => {
160160
'should support the automatic runtime (`@jsxRuntime`)'
161161
)
162162

163-
// console.log(
164-
// '\nnote: the next deprecation is expected (preact is missing an export map)\n'
165-
// )
166-
//
167-
// To do: re-enable when `preact/compat` has a correct export map.
168-
// assert.equal(
169-
// render(
170-
// h(await run(compileSync('?', {jsxImportSource: 'preact/compat'})), {})
171-
// ),
172-
// '<p>?</p>',
173-
// 'should support an import source (`@jsxImportSource`)'
174-
// )
163+
assert.equal(
164+
render(
165+
h(await run(compileSync('?', {jsxImportSource: 'preact/compat'})), {})
166+
),
167+
'<p>?</p>',
168+
'should support an import source (`@jsxImportSource`)'
169+
)
175170

176171
assert.equal(
177172
render(

packages/mdx/test/evaluate.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ test('evaluate', async () => {
179179
'should support an `export class` (1)'
180180
)
181181

182-
// @ts-expect-error TODO figure out how to narrow class type in JSDoc typescript
183-
assert.equal(new mod.A().b, 1, 'should support an `export class` (2)')
182+
const A = /** @type {new () => {b: number}} */ (mod.A)
183+
const a = new A()
184+
assert.equal(a.b, 1, 'should support an `export class` (2)')
184185

185186
mod = await evaluate('export const a = 1\nexport {a as b}\n\n{a}', runtime)
186187

packages/node-loader/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"prepack": "npm run build",
5151
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
5252
"test-api": "node --no-warnings --experimental-loader=./test/react-18-node-loader.js ../../node_modules/uvu/bin.js test \"\\.js$\"",
53-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
53+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
5454
"test": "npm run build && npm run test-coverage"
5555
},
5656
"xo": false,

packages/node-loader/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ abide by its terms.
181181

182182
[support]: https://mdxjs.com/community/support/
183183

184-
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
184+
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
185185

186186
[mit]: https://github.com/mdx-js/mdx/blob/main/packages/node-loader/license
187187

packages/preact/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"prepack": "npm run build",
5757
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"index.d.ts\" && tsc && type-coverage",
5858
"test-api": "node --no-warnings --experimental-loader=../../script/jsx-loader.js ../../node_modules/uvu/bin.js test \"\\.jsx?$\"",
59-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
59+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
6060
"test": "npm run build && npm run test-coverage"
6161
},
6262
"xo": false,

packages/preact/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ abide by its terms.
212212

213213
[support]: https://mdxjs.com/community/support/
214214

215-
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
215+
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
216216

217217
[mit]: https://github.com/mdx-js/mdx/blob/main/packages/preact/license
218218

packages/preact/test/test.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ test('should support `withComponents`', async () => {
131131
})
132132
const With = withMDXComponents((props) => props.children)
133133

134-
// To do: should this use the `h2` component too?
134+
// Bug: this should use the `h2` component too, logically?
135+
// As `withMDXComponents` is deprecated, and it would probably be a breaking
136+
// change, we can just remove it later.
135137
assert.equal(
136138
render(
137139
<MDXProvider

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"prepack": "npm run build",
5959
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"index.d.ts\" && tsc && type-coverage",
6060
"test-api": "node --no-warnings --experimental-loader=../../script/jsx-loader.js ../../node_modules/uvu/bin.js test \"\\.jsx?$\"",
61-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
61+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
6262
"test": "npm run build && npm run test-coverage"
6363
},
6464
"xo": false,

packages/react/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ abide by its terms.
212212

213213
[support]: https://mdxjs.com/community/support/
214214

215-
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
215+
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
216216

217217
[mit]: https://github.com/mdx-js/mdx/blob/main/packages/react/license
218218

packages/react/test/test.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ test('should support `withComponents`', async () => {
129129
})
130130
const With = withMDXComponents((props) => props.children)
131131

132-
// To do: should this use the `h2` component too?
132+
// Bug: this should use the `h2` component too, logically?
133+
// As `withMDXComponents` is deprecated, and it would probably be a breaking
134+
// change, we can just remove it later.
133135
assert.equal(
134136
renderToString(
135137
<MDXProvider

packages/register/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"#1": "to do when TS supports CJS: `build: rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage`",
5252
"#2": "to do: re-enable when `deasync` is built on Node 17",
5353
"#test-api": "uvu -r index.cjs test \"\\.c?js$\"",
54-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
54+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
5555
"test": "npm run test-coverage"
5656
},
5757
"xo": false,

0 commit comments

Comments
 (0)