Skip to content

Commit 30ebfae

Browse files
committed
Refactor code-style
1 parent 8562914 commit 30ebfae

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

index.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
* @typedef {EstreeJsxAttribute['name']} EstreeJsxAttributeName
2929
* @typedef {EstreeJsxElement['children'][number]} EstreeJsxChild
3030
*
31-
* @typedef {import('mdast-util-mdx-jsx').MDXJsxAttributeValueExpression} MDXJsxAttributeValueExpression
32-
* @typedef {import('mdast-util-mdx-jsx').MDXJsxAttribute} MDXJsxAttribute
33-
* @typedef {import('mdast-util-mdx-jsx').MDXJsxExpressionAttribute} MDXJsxExpressionAttribute
34-
* @typedef {import('mdast-util-mdx-jsx').MDXJsxFlowElement} MDXJsxFlowElement
35-
* @typedef {import('mdast-util-mdx-jsx').MDXJsxTextElement} MDXJsxTextElement
31+
* @typedef {import('mdast-util-mdx-jsx').MdxJsxAttributeValueExpression} MDXJsxAttributeValueExpression
32+
* @typedef {import('mdast-util-mdx-jsx').MdxJsxAttribute} MDXJsxAttribute
33+
* @typedef {import('mdast-util-mdx-jsx').MdxJsxExpressionAttribute} MDXJsxExpressionAttribute
34+
* @typedef {import('mdast-util-mdx-jsx').MdxJsxFlowElement} MDXJsxFlowElement
35+
* @typedef {import('mdast-util-mdx-jsx').MdxJsxTextElement} MDXJsxTextElement
3636
*
3737
* @typedef {import('mdast-util-mdx-expression').MDXFlowExpression} MDXFlowExpression
3838
* @typedef {import('mdast-util-mdx-expression').MDXTextExpression} MDXTextExpression
@@ -46,12 +46,12 @@
4646
*
4747
* @typedef Options
4848
* @property {Space} [space='html']
49-
* @property {Object.<string, Handle>} [handlers={}]
49+
* @property {Record<string, Handle>} [handlers={}]
5050
*
5151
* @typedef Context
5252
* @property {typeof html} schema
53-
* @property {Array.<EstreeComment>} comments
54-
* @property {Array.<EstreeDirective|EstreeStatement|EstreeModuleDeclaration>} esm
53+
* @property {Array<EstreeComment>} comments
54+
* @property {Array<EstreeDirective|EstreeStatement|EstreeModuleDeclaration>} esm
5555
* @property {Handle} handle
5656
*/
5757

@@ -229,12 +229,12 @@ function element(node, context) {
229229
}
230230

231231
if (prop === 'style') {
232-
/** @type {Object.<string, string>} */
232+
/** @type {Record<string, string>} */
233233
// @ts-expect-error Assume `value` is then an object.
234234
const styleValue =
235235
typeof value === 'string' ? parseStyle(value, node.tagName) : value
236236

237-
/** @type {Array.<EstreeProperty>} */
237+
/** @type {Array<EstreeProperty>} */
238238
const cssProperties = []
239239
/** @type {string} */
240240
let cssProp
@@ -506,10 +506,10 @@ function mdxJsxElement(node, context) {
506506
*/
507507
function root(node, context) {
508508
const children = all(node, context)
509-
/** @type {Array.<EstreeJsxChild>} */
509+
/** @type {Array<EstreeJsxChild>} */
510510
const cleanChildren = []
511511
let index = -1
512-
/** @type {Array.<EstreeJsxChild>|undefined} */
512+
/** @type {Array<EstreeJsxChild>|undefined} */
513513
let queue
514514

515515
// Remove surrounding whitespace nodes from the fragment.
@@ -555,12 +555,12 @@ function text(node) {
555555
/**
556556
* @param {Parent|MDXJsxFlowElement|MDXJsxTextElement} parent
557557
* @param {Context} context
558-
* @returns {Array.<EstreeJsxChild>}
558+
* @returns {Array<EstreeJsxChild>}
559559
*/
560560
function all(parent, context) {
561561
const children = parent.children || []
562562
let index = -1
563-
/** @type {Array.<EstreeJsxChild>} */
563+
/** @type {Array<EstreeJsxChild>} */
564564
const results = []
565565
// Currently, a warning is triggered by react for *any* white space in
566566
// tables.
@@ -602,7 +602,7 @@ function all(parent, context) {
602602
*/
603603
function inherit(hast, esnode) {
604604
const left = hast.data
605-
/** @type {Object.<string, unknown>|undefined} */
605+
/** @type {Record<string, unknown>|undefined} */
606606
let right
607607
/** @type {string} */
608608
let key
@@ -704,10 +704,10 @@ const createJsxName =
704704
/**
705705
* @param {string} value
706706
* @param {string} tagName
707-
* @returns {Object.<string, string>}
707+
* @returns {Record<string, string>}
708708
*/
709709
function parseStyle(value, tagName) {
710-
/** @type {Object.<string, string>} */
710+
/** @type {Record<string, string>} */
711711
const result = {}
712712

713713
try {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969
"hast-util-from-parse5": "^7.0.0",
7070
"hastscript": "^7.0.0",
7171
"mdast-util-from-markdown": "^1.0.0",
72-
"mdast-util-mdx": "^1.0.0",
72+
"mdast-util-mdx": "^2.0.0",
7373
"mdast-util-to-hast": "^12.0.0",
7474
"micromark-extension-mdxjs": "^1.0.0",
75-
"parse5": "^6.0.0",
75+
"parse5": "^7.0.0",
7676
"prettier": "^2.0.0",
7777
"recast": "^0.21.0",
7878
"remark-cli": "^10.0.0",

test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {fromMarkdown} from 'mdast-util-from-markdown'
2020
import {toHast} from 'mdast-util-to-hast'
2121
import {mdxFromMarkdown} from 'mdast-util-mdx'
2222
import {mdxjs} from 'micromark-extension-mdxjs'
23-
import parse5 from 'parse5'
23+
import * as parse5 from 'parse5'
2424
import recast from 'recast'
2525
import {visit} from 'unist-util-visit'
2626
import {toEstree} from './index.js'
@@ -41,7 +41,7 @@ const passThrough = [
4141
test('hast-util-to-estree', (t) => {
4242
t.throws(
4343
() => {
44-
// @ts-expect-error runtime.
44+
// @ts-expect-error: runtime.
4545
toEstree({})
4646
},
4747
/Cannot handle value `\[object Object]`/,
@@ -285,7 +285,7 @@ test('hast-util-to-estree', (t) => {
285285
tagName: 'a',
286286
properties: {
287287
style: {
288-
// @ts-expect-error: runtime.
288+
// @ts-expect-error: incorrect hast.
289289
WebkitBoxShadow: '0 0 1px 0 tomato',
290290
msBoxShadow: '0 0 1px 0 tomato',
291291
boxShadow: '0 0 1px 0 tomato'
@@ -507,7 +507,7 @@ test('hast-util-to-estree', (t) => {
507507
toEstree(
508508
{
509509
type: 'root',
510-
// @ts-expect-error: runtime.
510+
// @ts-expect-error: custom node.
511511
children: [{type: 'array', value: 'comma,seperated,array'}]
512512
},
513513
{
@@ -910,14 +910,15 @@ test('integration (micromark-extension-mdxjs, mdast-util-mdx)', (t) => {
910910
function transform(doc, clean) {
911911
const mdast = fromMarkdown(doc, {
912912
extensions: [mdxjs()],
913-
mdastExtensions: [mdxFromMarkdown]
913+
mdastExtensions: [mdxFromMarkdown()]
914914
})
915915

916916
const hast = toHast(mdast, {passThrough})
917917

918+
// @ts-expect-error: hush.
918919
if (clean && hast) visit(hast, passThrough, acornClean)
919920

920-
// @ts-expect-error: update.
921+
// @ts-expect-error: it’s a node.
921922
return recastSerialize(toEstree(hast))
922923

923924
/**
@@ -1053,7 +1054,7 @@ test('integration (@babel/plugin-transform-react-jsx, react)', (t) => {
10531054
function transform(doc, transformReactOptions) {
10541055
const mdast = fromMarkdown(doc, {
10551056
extensions: [mdxjs()],
1056-
mdastExtensions: [mdxFromMarkdown]
1057+
mdastExtensions: [mdxFromMarkdown()]
10571058
})
10581059

10591060
const hast = toHast(mdast, {passThrough})
@@ -1145,7 +1146,7 @@ test('integration (@vue/babel-plugin-jsx, Vue 3)', (t) => {
11451146
function transform(doc) {
11461147
const mdast = fromMarkdown(doc, {
11471148
extensions: [mdxjs()],
1148-
mdastExtensions: [mdxFromMarkdown]
1149+
mdastExtensions: [mdxFromMarkdown()]
11491150
})
11501151

11511152
const hast = toHast(mdast, {passThrough})
@@ -1194,7 +1195,7 @@ function acornClean(node) {
11941195
* @returns {Program}
11951196
*/
11961197
function acornParse(doc) {
1197-
/** @type {Array.<Comment>} */
1198+
/** @type {Array<Comment>} */
11981199
const comments = []
11991200
const tree = Parser.extend(jsx()).parse(doc, {
12001201
// @ts-expect-error Acorn.
@@ -1211,7 +1212,7 @@ function acornParse(doc) {
12111212
* @param {Program} tree
12121213
*/
12131214
function recastSerialize(tree) {
1214-
/** @type {Array.<Comment>} */
1215+
/** @type {Array<Comment>} */
12151216
tree.comments = undefined
12161217
return recast.prettyPrint(tree).code
12171218
}

0 commit comments

Comments
 (0)