Skip to content

Commit

Permalink
Update @types/mdast, mdast utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 11, 2023
1 parent 85900da commit dcdaf4c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export interface MdxjsEsmHast extends HastLiteral {

// Add nodes to mdast content.
declare module 'mdast' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface RootContentMap {
/**
* MDX ESM.
*/
mdxjsEsm: MdxjsEsm
}

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface FrontmatterContentMap {
/**
Expand Down
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ function enterMdxjsEsm(token) {
*/
function exitMdxjsEsm(token) {
const value = this.resume()
const node = /** @type {MdxjsEsm} */ (this.exit(token))
const node = /** @type {MdxjsEsm} */ (this.stack[this.stack.length - 1])

this.exit(token)

const estree = token.estree

node.value = value
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@
],
"dependencies": {
"@types/estree-jsx": "^1.0.0",
"@types/hast": "^2.0.0",
"@types/mdast": "^3.0.0",
"mdast-util-from-markdown": "^1.0.0",
"mdast-util-to-markdown": "^1.0.0"
"@types/hast": "^3.0.0",
"@types/mdast": "^4.0.0",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-to-markdown": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"acorn": "^8.0.0",
"c8": "^7.0.0",
"micromark-extension-mdxjs-esm": "^1.0.0",
"c8": "^8.0.0",
"micromark-extension-mdxjs-esm": "^2.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unist-util-remove-position": "^4.0.0",
"unist-util-remove-position": "^5.0.0",
"xo": "^0.54.0"
},
"scripts": {
Expand Down
23 changes: 11 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ test('mdxjsEsmFromMarkdown', () => {
'should support ESM'
)

let tree = fromMarkdown('import a from "b"\nexport var c = ""\n\nd', {
extensions: [mdxjsEsm({acorn, addResult: true})],
mdastExtensions: [mdxjsEsmFromMarkdown]
})

removePosition(tree, {force: true})

// Cheap clone to remove non-JSON values.
tree = JSON.parse(JSON.stringify(tree))

assert.deepEqual(
// Cheap clone to remove non-JSON values.
JSON.parse(
JSON.stringify(
removePosition(
fromMarkdown('import a from "b"\nexport var c = ""\n\nd', {
extensions: [mdxjsEsm({acorn, addResult: true})],
mdastExtensions: [mdxjsEsmFromMarkdown]
}),
true
)
)
),
tree,
{
type: 'root',
children: [
Expand Down

0 comments on commit dcdaf4c

Please sign in to comment.