mdast-util-mdx-jsx
Advanced tools
Comparing version 2.1.4 to 3.0.0
161
index.d.ts
@@ -1,11 +0,13 @@ | ||
import type {Node as MdastNode} from 'unist' | ||
import type {Program} from 'estree-jsx' | ||
import type {Data as HastData, ElementContent, Parent as HastParent} from 'hast' | ||
import type { | ||
Parent as MdastParent, | ||
Literal as MdastLiteral, | ||
BlockContent, | ||
Data as MdastData, | ||
DefinitionContent, | ||
Literal as MdastLiteral, | ||
Node as MdastNode, | ||
Parent as MdastParent, | ||
PhrasingContent | ||
} from 'mdast' | ||
import type {ElementContent, Parent as HastParent} from 'hast' | ||
import type {Program} from 'estree-jsx' | ||
import type {Data, Node} from 'unist' | ||
import type {Tag} from './lib/index.js' | ||
@@ -28,4 +30,3 @@ | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxJsxAttributeValueExpression extends MdastLiteral { | ||
export interface MdxJsxAttributeValueExpression extends Node { | ||
/** | ||
@@ -35,12 +36,26 @@ * Node type. | ||
type: 'mdxJsxAttributeValueExpression' | ||
data?: { | ||
/** | ||
* Program node from estree. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
estree?: Program | null | undefined | ||
} & MdastLiteral['data'] | ||
/** | ||
* Value. | ||
*/ | ||
value: string | ||
/** | ||
* Data associated with the mdast MDX JSX attribute value expression. | ||
*/ | ||
data?: MdxJsxAttributeValueExpressionData | undefined | ||
} | ||
/** | ||
* Info associated with mdast MDX JSX attribute value expression nodes by the | ||
* ecosystem. | ||
*/ | ||
export interface MdxJsxAttributeValueExpressionData extends Data { | ||
/** | ||
* Program node from estree. | ||
*/ | ||
estree?: Program | null | undefined | ||
} | ||
/** | ||
* MDX JSX attribute as an expression. | ||
@@ -53,4 +68,3 @@ * | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxJsxExpressionAttribute extends MdastLiteral { | ||
export interface MdxJsxExpressionAttribute extends Node { | ||
/** | ||
@@ -60,12 +74,26 @@ * Node type. | ||
type: 'mdxJsxExpressionAttribute' | ||
data?: { | ||
/** | ||
* Program node from estree. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
estree?: Program | null | undefined | ||
} & MdastLiteral['data'] | ||
/** | ||
* Value. | ||
*/ | ||
value: string | ||
/** | ||
* Data associated with the mdast MDX JSX expression attributes. | ||
*/ | ||
data?: MdxJsxExpressionAttributeData | undefined | ||
} | ||
/** | ||
* Info associated with mdast MDX JSX expression attribute nodes by the | ||
* ecosystem. | ||
*/ | ||
export interface MdxJsxExpressionAttributeData extends Data { | ||
/** | ||
* Program node from estree. | ||
*/ | ||
estree?: Program | null | undefined | ||
} | ||
/** | ||
* MDX JSX attribute with a key. | ||
@@ -78,4 +106,3 @@ * | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxJsxAttribute extends MdastNode { | ||
export interface MdxJsxAttribute extends Node { | ||
/** | ||
@@ -92,10 +119,18 @@ * Node type. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
value?: MdxJsxAttributeValueExpression | string | null | undefined | ||
/** | ||
* Data associated with the mdast MDX JSX attribute. | ||
*/ | ||
data?: MdxJsxAttributeData | undefined | ||
} | ||
/** | ||
* Info associated with mdast MDX JSX attribute nodes by the | ||
* ecosystem. | ||
*/ | ||
export interface MdxJsxAttributeData extends Data {} | ||
/** | ||
* MDX JSX element node, occurring in flow (block). | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxJsxFlowElement extends MdastParent { | ||
@@ -109,3 +144,2 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
name: string | null | ||
@@ -120,8 +154,17 @@ /** | ||
children: Array<BlockContent | DefinitionContent> | ||
/** | ||
* Data associated with the mdast MDX JSX elements (flow). | ||
*/ | ||
data?: MdxJsxFlowElementData | undefined | ||
} | ||
/** | ||
* Info associated with mdast MDX JSX element (flow) nodes by the | ||
* ecosystem. | ||
*/ | ||
export interface MdxJsxFlowElementData extends MdastData {} | ||
/** | ||
* MDX JSX element node, occurring in text (phrasing). | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxJsxTextElement extends MdastParent { | ||
@@ -135,3 +178,2 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
name: string | null | ||
@@ -146,8 +188,17 @@ /** | ||
children: PhrasingContent[] | ||
/** | ||
* Data associated with the mdast MDX JSX elements (text). | ||
*/ | ||
data?: MdxJsxTextElementData | undefined | ||
} | ||
/** | ||
* Info associated with mdast MDX JSX element (text) nodes by the | ||
* ecosystem. | ||
*/ | ||
export interface MdxJsxTextElementData extends MdastData {} | ||
/** | ||
* MDX JSX element node, occurring in flow (block), for hast. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxJsxFlowElementHast extends HastParent { | ||
@@ -161,3 +212,2 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
name: string | null | ||
@@ -172,8 +222,17 @@ /** | ||
children: ElementContent[] | ||
/** | ||
* Data associated with the hast MDX JSX elements (flow). | ||
*/ | ||
data?: MdxJsxFlowElementHastData | undefined | ||
} | ||
/** | ||
* Info associated with hast MDX JSX element (flow) nodes by the | ||
* ecosystem. | ||
*/ | ||
export interface MdxJsxFlowElementHastData extends HastData {} | ||
/** | ||
* MDX JSX element node, occurring in text (phrasing), for hast. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxJsxTextElementHast extends HastParent { | ||
@@ -187,3 +246,2 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
name: string | null | ||
@@ -198,9 +256,25 @@ /** | ||
children: ElementContent[] | ||
/** | ||
* Data associated with the hast MDX JSX elements (text). | ||
*/ | ||
data?: MdxJsxTextElementHastData | undefined | ||
} | ||
/** | ||
* Info associated with hast MDX JSX element (text) nodes by the | ||
* ecosystem. | ||
*/ | ||
export interface MdxJsxTextElementHastData extends HastData {} | ||
// Add nodes to mdast content. | ||
declare module 'mdast' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface StaticPhrasingContentMap { | ||
interface BlockContentMap { | ||
/** | ||
* MDX JSX element node, occurring in flow (block). | ||
*/ | ||
mdxJsxFlowElement: MdxJsxFlowElement | ||
} | ||
interface PhrasingContentMap { | ||
/** | ||
* MDX JSX element node, occurring in text (phrasing). | ||
@@ -211,4 +285,3 @@ */ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface BlockContentMap { | ||
interface RootContentMap { | ||
/** | ||
@@ -218,2 +291,6 @@ * MDX JSX element node, occurring in flow (block). | ||
mdxJsxFlowElement: MdxJsxFlowElement | ||
/** | ||
* MDX JSX element node, occurring in text (phrasing). | ||
*/ | ||
mdxJsxTextElement: MdxJsxTextElement | ||
} | ||
@@ -224,4 +301,3 @@ } | ||
declare module 'hast' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface RootContentMap { | ||
interface ElementContentMap { | ||
/** | ||
@@ -237,4 +313,3 @@ * MDX JSX element node, occurring in text (phrasing). | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface ElementContentMap { | ||
interface RootContentMap { | ||
/** | ||
@@ -253,3 +328,2 @@ * MDX JSX element node, occurring in text (phrasing). | ||
declare module 'mdast-util-from-markdown' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface CompileData { | ||
@@ -270,3 +344,2 @@ /** | ||
declare module 'mdast-util-to-markdown' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface ConstructNameMap { | ||
@@ -273,0 +346,0 @@ /** |
@@ -19,3 +19,3 @@ /** | ||
* @param {ToMarkdownOptions | null | undefined} [options] | ||
* Configuration. | ||
* Configuration (optional). | ||
* @returns {ToMarkdownExtension} | ||
@@ -27,9 +27,8 @@ * Extension for `mdast-util-to-markdown` to enable MDX JSX. | ||
): ToMarkdownExtension | ||
export type Program = import('estree-jsx').Program | ||
export type CompileContext = import('mdast-util-from-markdown').CompileContext | ||
export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension | ||
export type FromMarkdownHandle = import('mdast-util-from-markdown').Handle | ||
export type Token = import('mdast-util-from-markdown').Token | ||
export type OnEnterError = import('mdast-util-from-markdown').OnEnterError | ||
export type OnExitError = import('mdast-util-from-markdown').OnExitError | ||
export type Token = import('mdast-util-from-markdown').Token | ||
export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle | ||
@@ -39,5 +38,5 @@ export type ToMarkdownExtension = import('mdast-util-to-markdown').Options | ||
export type Tracker = import('mdast-util-to-markdown').Tracker | ||
export type MdxJsxAttribute = import('../index.js').MdxJsxAttribute | ||
export type MdxJsxAttributeValueExpression = | ||
import('../index.js').MdxJsxAttributeValueExpression | ||
export type MdxJsxAttribute = import('../index.js').MdxJsxAttribute | ||
export type MdxJsxExpressionAttribute = | ||
@@ -84,7 +83,7 @@ import('../index.js').MdxJsxExpressionAttribute | ||
/** | ||
* Preferred quote to use around attribute values. | ||
* Preferred quote to use around attribute values (default: `'"'`). | ||
*/ | ||
quote?: '"' | "'" | null | undefined | ||
/** | ||
* Use the other quote if that results in less bytes. | ||
* Use the other quote if that results in less bytes (default: `false`). | ||
*/ | ||
@@ -94,7 +93,7 @@ quoteSmart?: boolean | null | undefined | ||
* Do not use an extra space when closing self-closing elements: `<img/>` | ||
* instead of `<img />`. | ||
* instead of `<img />` (default: `false`). | ||
*/ | ||
tightSelfClosing?: boolean | null | undefined | ||
/** | ||
* Try and wrap syntax at this width. | ||
* Try and wrap syntax at this width (default: `Infinity`). | ||
* | ||
@@ -101,0 +100,0 @@ * When set to a finite number (say, `80`), the formatter will print |
138
lib/index.js
/** | ||
* @typedef {import('estree-jsx').Program} Program | ||
* | ||
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext | ||
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension | ||
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle | ||
* @typedef {import('mdast-util-from-markdown').Token} Token | ||
* @typedef {import('mdast-util-from-markdown').OnEnterError} OnEnterError | ||
* @typedef {import('mdast-util-from-markdown').OnExitError} OnExitError | ||
* @typedef {import('mdast-util-from-markdown').Token} Token | ||
* | ||
@@ -16,4 +14,4 @@ * @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle | ||
* | ||
* @typedef {import('../index.js').MdxJsxAttribute} MdxJsxAttribute | ||
* @typedef {import('../index.js').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression | ||
* @typedef {import('../index.js').MdxJsxAttribute} MdxJsxAttribute | ||
* @typedef {import('../index.js').MdxJsxExpressionAttribute} MdxJsxExpressionAttribute | ||
@@ -46,10 +44,10 @@ * @typedef {import('../index.js').MdxJsxFlowElement} MdxJsxFlowElement | ||
* @property {'"' | "'" | null | undefined} [quote='"'] | ||
* Preferred quote to use around attribute values. | ||
* Preferred quote to use around attribute values (default: `'"'`). | ||
* @property {boolean | null | undefined} [quoteSmart=false] | ||
* Use the other quote if that results in less bytes. | ||
* Use the other quote if that results in less bytes (default: `false`). | ||
* @property {boolean | null | undefined} [tightSelfClosing=false] | ||
* Do not use an extra space when closing self-closing elements: `<img/>` | ||
* instead of `<img />`. | ||
* instead of `<img />` (default: `false`). | ||
* @property {number | null | undefined} [printWidth=Infinity] | ||
* Try and wrap syntax at this width. | ||
* Try and wrap syntax at this width (default: `Infinity`). | ||
* | ||
@@ -63,12 +61,8 @@ * When set to a finite number (say, `80`), the formatter will print | ||
import {ccount} from 'ccount' | ||
import {ok as assert} from 'devlop' | ||
import {parseEntities} from 'parse-entities' | ||
import {stringifyEntitiesLight} from 'stringify-entities' | ||
import {stringifyPosition} from 'unist-util-stringify-position' | ||
import {VFileMessage} from 'vfile-message' | ||
import {stringifyEntitiesLight} from 'stringify-entities' | ||
import {containerPhrasing} from 'mdast-util-to-markdown/lib/util/container-phrasing.js' | ||
import {indentLines} from 'mdast-util-to-markdown/lib/util/indent-lines.js' | ||
import {track} from 'mdast-util-to-markdown/lib/util/track.js' | ||
// To do: next major: use `state`, use utilities from state, rename `safeOptions` to `info`. | ||
const indent = ' ' | ||
@@ -171,4 +165,4 @@ | ||
} | ||
if (!this.getData('mdxJsxTagStack')) this.setData('mdxJsxTagStack', []) | ||
this.setData('mdxJsxTag', tag) | ||
if (!this.data.mdxJsxTagStack) this.data.mdxJsxTagStack = [] | ||
this.data.mdxJsxTag = tag | ||
this.buffer() | ||
@@ -182,3 +176,4 @@ } | ||
function enterMdxJsxTagClosingMarker(token) { | ||
const stack = /** @type {Array<Tag>} */ (this.getData('mdxJsxTagStack')) | ||
const stack = this.data.mdxJsxTagStack | ||
assert(stack, 'expected `mdxJsxTagStack`') | ||
@@ -199,3 +194,4 @@ if (stack.length === 0) { | ||
function enterMdxJsxTagAnyAttribute(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
@@ -216,3 +212,4 @@ if (tag.close) { | ||
function enterMdxJsxTagSelfClosingMarker(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
@@ -233,3 +230,4 @@ if (tag.close) { | ||
function exitMdxJsxTagClosingMarker() { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
tag.close = true | ||
@@ -243,3 +241,4 @@ } | ||
function exitMdxJsxTagNamePrimary(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
tag.name = this.sliceSerialize(token) | ||
@@ -253,3 +252,4 @@ } | ||
function exitMdxJsxTagNameMember(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
tag.name += '.' + this.sliceSerialize(token) | ||
@@ -263,3 +263,4 @@ } | ||
function exitMdxJsxTagNameLocal(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
tag.name += ':' + this.sliceSerialize(token) | ||
@@ -273,3 +274,4 @@ } | ||
function enterMdxJsxTagAttribute(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
enterMdxJsxTagAnyAttribute.call(this, token) | ||
@@ -284,3 +286,4 @@ tag.attributes.push({type: 'mdxJsxAttribute', name: '', value: null}) | ||
function enterMdxJsxTagExpressionAttribute(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
enterMdxJsxTagAnyAttribute.call(this, token) | ||
@@ -296,8 +299,6 @@ tag.attributes.push({type: 'mdxJsxExpressionAttribute', value: ''}) | ||
function exitMdxJsxTagExpressionAttribute(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tail = /** @type {MdxJsxExpressionAttribute} */ ( | ||
tag.attributes[tag.attributes.length - 1] | ||
) | ||
/** @type {Program | undefined} */ | ||
// @ts-expect-error: custom. | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
const tail = tag.attributes[tag.attributes.length - 1] | ||
assert(tail.type === 'mdxJsxExpressionAttribute') | ||
const estree = token.estree | ||
@@ -317,6 +318,6 @@ | ||
function exitMdxJsxTagAttributeNamePrimary(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const node = /** @type {MdxJsxAttribute} */ ( | ||
tag.attributes[tag.attributes.length - 1] | ||
) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
const node = tag.attributes[tag.attributes.length - 1] | ||
assert(node.type === 'mdxJsxAttribute') | ||
node.name = this.sliceSerialize(token) | ||
@@ -330,6 +331,6 @@ } | ||
function exitMdxJsxTagAttributeNameLocal(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const node = /** @type {MdxJsxAttribute} */ ( | ||
tag.attributes[tag.attributes.length - 1] | ||
) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
const node = tag.attributes[tag.attributes.length - 1] | ||
assert(node.type === 'mdxJsxAttribute') | ||
node.name += ':' + this.sliceSerialize(token) | ||
@@ -343,3 +344,4 @@ } | ||
function exitMdxJsxTagAttributeValueLiteral() { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
tag.attributes[tag.attributes.length - 1].value = parseEntities( | ||
@@ -356,10 +358,8 @@ this.resume(), | ||
function exitMdxJsxTagAttributeValueExpression(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tail = /** @type {MdxJsxAttribute} */ ( | ||
tag.attributes[tag.attributes.length - 1] | ||
) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
const tail = tag.attributes[tag.attributes.length - 1] | ||
assert(tail.type === 'mdxJsxAttribute') | ||
/** @type {MdxJsxAttributeValueExpression} */ | ||
const node = {type: 'mdxJsxAttributeValueExpression', value: this.resume()} | ||
/** @type {Program | undefined} */ | ||
// @ts-expect-error: custom. | ||
const estree = token.estree | ||
@@ -379,3 +379,4 @@ | ||
function exitMdxJsxTagSelfClosingMarker() { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
@@ -390,4 +391,6 @@ tag.selfClosing = true | ||
function exitMdxJsxTag(token) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const stack = /** @type {Array<Tag>} */ (this.getData('mdxJsxTagStack')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
const stack = this.data.mdxJsxTagStack | ||
assert(stack, 'expected `mdxJsxTagStack`') | ||
const tail = stack[stack.length - 1] | ||
@@ -442,3 +445,4 @@ | ||
function onErrorRightIsTag(closing, open) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
const place = closing ? ' before the end of `' + closing.type + '`' : '' | ||
@@ -466,3 +470,5 @@ const position = closing | ||
function onErrorLeftIsTag(a, b) { | ||
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag')) | ||
const tag = this.data.mdxJsxTag | ||
assert(tag, 'expected `mdxJsxTag`') | ||
throw new VFileMessage( | ||
@@ -505,3 +511,3 @@ 'Expected the closing tag `' + | ||
* @param {ToMarkdownOptions | null | undefined} [options] | ||
* Configuration. | ||
* Configuration (optional). | ||
* @returns {ToMarkdownExtension} | ||
@@ -548,3 +554,3 @@ * Extension for `mdast-util-to-markdown` to enable MDX JSX. | ||
// eslint-disable-next-line complexity | ||
function mdxElement(node, _, context, safeOptions) { | ||
function mdxElement(node, _, state, info) { | ||
const flow = node.type === 'mdxJsxFlowElement' | ||
@@ -554,10 +560,10 @@ const selfClosing = node.name | ||
: false | ||
const depth = inferDepth(context) | ||
const depth = inferDepth(state) | ||
const currentIndent = createIndent(depth) | ||
const trackerOneLine = track(safeOptions) | ||
const trackerMultiLine = track(safeOptions) | ||
const trackerOneLine = state.createTracker(info) | ||
const trackerMultiLine = state.createTracker(info) | ||
/** @type {Array<string>} */ | ||
const serializedAttributes = [] | ||
const prefix = (flow ? currentIndent : '') + '<' + (node.name || '') | ||
const exit = context.enter(node.type) | ||
const exit = state.enter(node.type) | ||
@@ -591,3 +597,3 @@ trackerOneLine.move(prefix) | ||
if (value === undefined || value === null) { | ||
if (value === null || value === undefined) { | ||
// Empty. | ||
@@ -668,3 +674,7 @@ } else if (typeof value === 'object') { | ||
value += tracker.move( | ||
containerPhrasing(node, context, { | ||
// @ts-expect-error: `containerPhrasing` is typed correctly, but TS | ||
// generates *hardcoded* types, which means that our dynamically added | ||
// directives are not present. | ||
// At some point, TS should fix that, and `from-markdown` should be fine. | ||
state.containerPhrasing(node, { | ||
...tracker.current(), | ||
@@ -678,3 +688,3 @@ before: '>', | ||
value += tracker.move('\n') | ||
value += tracker.move(containerFlow(node, context, tracker.current())) | ||
value += tracker.move(containerFlow(node, state, tracker.current())) | ||
value += tracker.move('\n') | ||
@@ -734,3 +744,3 @@ } | ||
? result | ||
: indentLines(result, function (line, _, blank) { | ||
: state.indentLines(result, function (line, _, blank) { | ||
return (blank ? '' : currentIndent) + line | ||
@@ -757,9 +767,9 @@ }) | ||
* | ||
* @param {State} context | ||
* @param {State} state | ||
* @returns {number} | ||
*/ | ||
function inferDepth(context) { | ||
function inferDepth(state) { | ||
let depth = 0 | ||
for (const x of context.stack) { | ||
for (const x of state.stack) { | ||
if (x === 'mdxJsxFlowElement') { | ||
@@ -766,0 +776,0 @@ depth++ |
{ | ||
"name": "mdast-util-mdx-jsx", | ||
"version": "2.1.4", | ||
"version": "3.0.0", | ||
"description": "mdast extension to parse and serialize MDX or MDX.js JSX", | ||
@@ -31,4 +31,3 @@ "license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
@@ -41,13 +40,14 @@ "lib/", | ||
"@types/estree-jsx": "^1.0.0", | ||
"@types/hast": "^2.0.0", | ||
"@types/mdast": "^3.0.0", | ||
"@types/unist": "^2.0.0", | ||
"@types/hast": "^3.0.0", | ||
"@types/mdast": "^4.0.0", | ||
"@types/unist": "^3.0.0", | ||
"ccount": "^2.0.0", | ||
"mdast-util-from-markdown": "^1.1.0", | ||
"mdast-util-to-markdown": "^1.3.0", | ||
"devlop": "^1.1.0", | ||
"mdast-util-from-markdown": "^2.0.0", | ||
"mdast-util-to-markdown": "^2.0.0", | ||
"parse-entities": "^4.0.0", | ||
"stringify-entities": "^4.0.0", | ||
"unist-util-remove-position": "^4.0.0", | ||
"unist-util-stringify-position": "^3.0.0", | ||
"vfile-message": "^3.0.0" | ||
"unist-util-remove-position": "^5.0.0", | ||
"unist-util-stringify-position": "^4.0.0", | ||
"vfile-message": "^4.0.0" | ||
}, | ||
@@ -57,5 +57,5 @@ "devDependencies": { | ||
"acorn": "^8.0.0", | ||
"c8": "^7.0.0", | ||
"micromark-extension-mdx-jsx": "^1.0.0", | ||
"micromark-extension-mdx-md": "^1.0.0", | ||
"c8": "^8.0.0", | ||
"micromark-extension-mdx-jsx": "^2.0.0", | ||
"micromark-extension-mdx-md": "^2.0.0", | ||
"prettier": "^2.0.0", | ||
@@ -72,20 +72,19 @@ "remark-cli": "^11.0.0", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test-api-prod": "node --conditions production test.js", | ||
"test-api-dev": "node --conditions development test.js", | ||
"test-api": "npm run test-api-dev && npm run test-api-prod", | ||
"test-coverage": "c8 --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"xo": { | ||
"prettier": true | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -96,5 +95,19 @@ }, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"**/*.ts" | ||
], | ||
"rules": { | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/consistent-type-definitions": "off" | ||
} | ||
} | ||
], | ||
"prettier": true | ||
} | ||
} |
@@ -74,3 +74,3 @@ # mdast-util-mdx-jsx | ||
This package is [ESM only][esm]. | ||
In Node.js (version 14.14+ and 16.0+), install with [npm][]: | ||
In Node.js (version 16+), install with [npm][]: | ||
@@ -84,3 +84,3 @@ ```sh | ||
```js | ||
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'https://esm.sh/mdast-util-mdx-jsx@2' | ||
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'https://esm.sh/mdast-util-mdx-jsx@3' | ||
``` | ||
@@ -92,3 +92,3 @@ | ||
<script type="module"> | ||
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'https://esm.sh/mdast-util-mdx-jsx@2?bundle' | ||
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'https://esm.sh/mdast-util-mdx-jsx@3?bundle' | ||
</script> | ||
@@ -116,6 +116,6 @@ ``` | ||
import * as acorn from 'acorn' | ||
import {mdxJsx} from 'micromark-extension-mdx-jsx' | ||
import {fromMarkdown} from 'mdast-util-from-markdown' | ||
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'mdast-util-mdx-jsx' | ||
import {toMarkdown} from 'mdast-util-to-markdown' | ||
import {mdxJsx} from 'micromark-extension-mdx-jsx' | ||
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'mdast-util-mdx-jsx' | ||
@@ -431,3 +431,3 @@ const doc = await fs.readFile('example.mdx') | ||
interface MdxJsxFlowElement <: Parent { | ||
type: "mdxJsxFlowElement" | ||
type: 'mdxJsxFlowElement' | ||
} | ||
@@ -465,3 +465,3 @@ | ||
interface MdxJsxTextElement <: Parent { | ||
type: "mdxJsxTextElement" | ||
type: 'mdxJsxTextElement' | ||
} | ||
@@ -506,7 +506,7 @@ | ||
interface MdxJsxExpressionAttribute <: Literal { | ||
type: "mdxJsxExpressionAttribute" | ||
type: 'mdxJsxExpressionAttribute' | ||
} | ||
interface MdxJsxAttribute <: Node { | ||
type: "mdxJsxAttribute" | ||
type: 'mdxJsxAttribute' | ||
name: string | ||
@@ -517,3 +517,3 @@ value: MdxJsxAttributeValueExpression | string? | ||
interface MdxJsxAttributeValueExpression <: Literal { | ||
type: "mdxJsxAttributeValueExpression" | ||
type: 'mdxJsxAttributeValueExpression' | ||
} | ||
@@ -581,3 +581,3 @@ ``` | ||
visit(tree, (node) => { | ||
visit(tree, function (node) { | ||
// `node` can now be one of the JSX nodes. | ||
@@ -589,10 +589,13 @@ }) | ||
Projects maintained by the unified collective are compatible with all maintained | ||
Projects maintained by the unified collective are compatible with maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 14.14+ and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
This plugin works with `mdast-util-from-markdown` version 1+ and | ||
`mdast-util-to-markdown` version 1+. | ||
When we cut a new major release, we drop support for unmaintained versions of | ||
Node. | ||
This means we try to keep the current release line, `mdast-util-mdx-jsx@^3`, | ||
compatible with Node.js 16. | ||
This utility works with `mdast-util-from-markdown` version 2+ and | ||
`mdast-util-to-markdown` version 2+. | ||
## Related | ||
@@ -633,5 +636,5 @@ | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-mdx-jsx.svg | ||
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-mdx-jsx | ||
[size]: https://bundlephobia.com/result?p=mdast-util-mdx-jsx | ||
[size]: https://bundlejs.com/?q=mdast-util-mdx-jsx | ||
@@ -638,0 +641,0 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56624
1102
719
13
7
+ Addeddevlop@^1.1.0
+ Added@types/hast@3.0.4(transitive)
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/unist@3.0.3(transitive)
+ Addeddevlop@1.1.0(transitive)
+ Addedmdast-util-from-markdown@2.0.2(transitive)
+ Addedmdast-util-phrasing@4.1.0(transitive)
+ Addedmdast-util-to-markdown@2.1.2(transitive)
+ Addedmdast-util-to-string@4.0.0(transitive)
+ Addedmicromark@4.0.0(transitive)
+ Addedmicromark-core-commonmark@2.0.1(transitive)
+ Addedmicromark-factory-destination@2.0.0(transitive)
+ Addedmicromark-factory-label@2.0.0(transitive)
+ Addedmicromark-factory-space@2.0.0(transitive)
+ Addedmicromark-factory-title@2.0.0(transitive)
+ Addedmicromark-factory-whitespace@2.0.0(transitive)
+ Addedmicromark-util-character@2.1.0(transitive)
+ Addedmicromark-util-chunked@2.0.0(transitive)
+ Addedmicromark-util-classify-character@2.0.0(transitive)
+ Addedmicromark-util-combine-extensions@2.0.0(transitive)
+ Addedmicromark-util-decode-numeric-character-reference@2.0.1(transitive)
+ Addedmicromark-util-decode-string@2.0.0(transitive)
+ Addedmicromark-util-encode@2.0.0(transitive)
+ Addedmicromark-util-html-tag-name@2.0.0(transitive)
+ Addedmicromark-util-normalize-identifier@2.0.0(transitive)
+ Addedmicromark-util-resolve-all@2.0.0(transitive)
+ Addedmicromark-util-sanitize-uri@2.0.0(transitive)
+ Addedmicromark-util-subtokenize@2.0.1(transitive)
+ Addedmicromark-util-symbol@2.0.0(transitive)
+ Addedmicromark-util-types@2.0.0(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-remove-position@5.0.0(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedunist-util-visit@5.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(transitive)
+ Addedvfile-message@4.0.2(transitive)
- Removed@types/hast@2.3.10(transitive)
- Removed@types/mdast@3.0.15(transitive)
- Removeddiff@5.2.0(transitive)
- Removedkleur@4.1.5(transitive)
- Removedmdast-util-from-markdown@1.3.1(transitive)
- Removedmdast-util-phrasing@3.0.1(transitive)
- Removedmdast-util-to-markdown@1.5.0(transitive)
- Removedmdast-util-to-string@3.2.0(transitive)
- Removedmicromark@3.2.0(transitive)
- Removedmicromark-core-commonmark@1.1.0(transitive)
- Removedmicromark-factory-destination@1.1.0(transitive)
- Removedmicromark-factory-label@1.1.0(transitive)
- Removedmicromark-factory-space@1.1.0(transitive)
- Removedmicromark-factory-title@1.1.0(transitive)
- Removedmicromark-factory-whitespace@1.1.0(transitive)
- Removedmicromark-util-character@1.2.0(transitive)
- Removedmicromark-util-chunked@1.1.0(transitive)
- Removedmicromark-util-classify-character@1.1.0(transitive)
- Removedmicromark-util-combine-extensions@1.1.0(transitive)
- Removedmicromark-util-decode-numeric-character-reference@1.1.0(transitive)
- Removedmicromark-util-decode-string@1.1.0(transitive)
- Removedmicromark-util-encode@1.1.0(transitive)
- Removedmicromark-util-html-tag-name@1.2.0(transitive)
- Removedmicromark-util-normalize-identifier@1.1.0(transitive)
- Removedmicromark-util-resolve-all@1.1.0(transitive)
- Removedmicromark-util-sanitize-uri@1.2.0(transitive)
- Removedmicromark-util-subtokenize@1.1.0(transitive)
- Removedmicromark-util-symbol@1.1.0(transitive)
- Removedmicromark-util-types@1.1.0(transitive)
- Removedmri@1.2.0(transitive)
- Removedsade@1.8.1(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-remove-position@4.0.2(transitive)
- Removedunist-util-stringify-position@3.0.3(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
- Removeduvu@0.5.6(transitive)
- Removedvfile-message@3.1.4(transitive)
Updated@types/hast@^3.0.0
Updated@types/mdast@^4.0.0
Updated@types/unist@^3.0.0
Updatedvfile-message@^4.0.0