@@ -60,9 +60,6 @@ import {parseEntities} from 'parse-entities'
6060import { stringifyPosition } from 'unist-util-stringify-position'
6161import { VFileMessage } from 'vfile-message'
6262import { stringifyEntitiesLight } from 'stringify-entities'
63- import { containerPhrasing } from 'mdast-util-to-markdown/lib/util/container-phrasing.js'
64- import { indentLines } from 'mdast-util-to-markdown/lib/util/indent-lines.js'
65- import { track } from 'mdast-util-to-markdown/lib/util/track.js'
6663
6764// To do: next major: use `state`, use utilities from state, rename `safeOptions` to `info`.
6865
@@ -163,8 +160,8 @@ export function mdxJsxFromMarkdown() {
163160 start : token . start ,
164161 end : token . end
165162 }
166- if ( ! this . getData ( ' mdxJsxTagStack' ) ) this . setData ( ' mdxJsxTagStack' , [ ] )
167- this . setData ( ' mdxJsxTag' , tag )
163+ if ( ! this . data . mdxJsxTagStack ) this . data . mdxJsxTagStack = [ ]
164+ this . data . mdxJsxTag = tag
168165 this . buffer ( )
169166 }
170167
@@ -173,7 +170,7 @@ export function mdxJsxFromMarkdown() {
173170 * @type {FromMarkdownHandle }
174171 */
175172 function enterMdxJsxTagClosingMarker ( token ) {
176- const stack = /** @type {Array<Tag> } */ ( this . getData ( ' mdxJsxTagStack' ) )
173+ const stack = /** @type {Array<Tag> } */ ( this . data . mdxJsxTagStack )
177174
178175 if ( stack . length === 0 ) {
179176 throw new VFileMessage (
@@ -189,7 +186,7 @@ export function mdxJsxFromMarkdown() {
189186 * @type {FromMarkdownHandle }
190187 */
191188 function enterMdxJsxTagAnyAttribute ( token ) {
192- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
189+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
193190
194191 if ( tag . close ) {
195192 throw new VFileMessage (
@@ -205,7 +202,7 @@ export function mdxJsxFromMarkdown() {
205202 * @type {FromMarkdownHandle }
206203 */
207204 function enterMdxJsxTagSelfClosingMarker ( token ) {
208- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
205+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
209206
210207 if ( tag . close ) {
211208 throw new VFileMessage (
@@ -221,7 +218,7 @@ export function mdxJsxFromMarkdown() {
221218 * @type {FromMarkdownHandle }
222219 */
223220 function exitMdxJsxTagClosingMarker ( ) {
224- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
221+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
225222 tag . close = true
226223 }
227224
@@ -230,7 +227,7 @@ export function mdxJsxFromMarkdown() {
230227 * @type {FromMarkdownHandle }
231228 */
232229 function exitMdxJsxTagNamePrimary ( token ) {
233- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
230+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
234231 tag . name = this . sliceSerialize ( token )
235232 }
236233
@@ -239,7 +236,7 @@ export function mdxJsxFromMarkdown() {
239236 * @type {FromMarkdownHandle }
240237 */
241238 function exitMdxJsxTagNameMember ( token ) {
242- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
239+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
243240 tag . name += '.' + this . sliceSerialize ( token )
244241 }
245242
@@ -248,7 +245,7 @@ export function mdxJsxFromMarkdown() {
248245 * @type {FromMarkdownHandle }
249246 */
250247 function exitMdxJsxTagNameLocal ( token ) {
251- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
248+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
252249 tag . name += ':' + this . sliceSerialize ( token )
253250 }
254251
@@ -257,7 +254,7 @@ export function mdxJsxFromMarkdown() {
257254 * @type {FromMarkdownHandle }
258255 */
259256 function enterMdxJsxTagAttribute ( token ) {
260- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
257+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
261258 enterMdxJsxTagAnyAttribute . call ( this , token )
262259 tag . attributes . push ( { type : 'mdxJsxAttribute' , name : '' , value : null } )
263260 }
@@ -267,7 +264,7 @@ export function mdxJsxFromMarkdown() {
267264 * @type {FromMarkdownHandle }
268265 */
269266 function enterMdxJsxTagExpressionAttribute ( token ) {
270- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
267+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
271268 enterMdxJsxTagAnyAttribute . call ( this , token )
272269 tag . attributes . push ( { type : 'mdxJsxExpressionAttribute' , value : '' } )
273270 this . buffer ( )
@@ -278,7 +275,7 @@ export function mdxJsxFromMarkdown() {
278275 * @type {FromMarkdownHandle }
279276 */
280277 function exitMdxJsxTagExpressionAttribute ( token ) {
281- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
278+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
282279 const tail = /** @type {MdxJsxExpressionAttribute } */ (
283280 tag . attributes [ tag . attributes . length - 1 ]
284281 )
@@ -296,7 +293,7 @@ export function mdxJsxFromMarkdown() {
296293 * @type {FromMarkdownHandle }
297294 */
298295 function exitMdxJsxTagAttributeNamePrimary ( token ) {
299- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
296+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
300297 const node = /** @type {MdxJsxAttribute } */ (
301298 tag . attributes [ tag . attributes . length - 1 ]
302299 )
@@ -308,7 +305,7 @@ export function mdxJsxFromMarkdown() {
308305 * @type {FromMarkdownHandle }
309306 */
310307 function exitMdxJsxTagAttributeNameLocal ( token ) {
311- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
308+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
312309 const node = /** @type {MdxJsxAttribute } */ (
313310 tag . attributes [ tag . attributes . length - 1 ]
314311 )
@@ -320,7 +317,7 @@ export function mdxJsxFromMarkdown() {
320317 * @type {FromMarkdownHandle }
321318 */
322319 function exitMdxJsxTagAttributeValueLiteral ( ) {
323- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
320+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
324321 tag . attributes [ tag . attributes . length - 1 ] . value = parseEntities (
325322 this . resume ( ) ,
326323 { nonTerminated : false }
@@ -332,7 +329,7 @@ export function mdxJsxFromMarkdown() {
332329 * @type {FromMarkdownHandle }
333330 */
334331 function exitMdxJsxTagAttributeValueExpression ( token ) {
335- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
332+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
336333 const tail = /** @type {MdxJsxAttribute } */ (
337334 tag . attributes [ tag . attributes . length - 1 ]
338335 )
@@ -352,7 +349,7 @@ export function mdxJsxFromMarkdown() {
352349 * @type {FromMarkdownHandle }
353350 */
354351 function exitMdxJsxTagSelfClosingMarker ( ) {
355- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
352+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
356353
357354 tag . selfClosing = true
358355 }
@@ -362,8 +359,8 @@ export function mdxJsxFromMarkdown() {
362359 * @type {FromMarkdownHandle }
363360 */
364361 function exitMdxJsxTag ( token ) {
365- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
366- const stack = /** @type {Array<Tag> } */ ( this . getData ( ' mdxJsxTagStack' ) )
362+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
363+ const stack = /** @type {Array<Tag> } */ ( this . data . mdxJsxTagStack )
367364 const tail = stack [ stack . length - 1 ]
368365
369366 if ( tag . close && tail . name !== tag . name ) {
@@ -413,7 +410,7 @@ export function mdxJsxFromMarkdown() {
413410 * @type {OnEnterError }
414411 */
415412 function onErrorRightIsTag ( closing , open ) {
416- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
413+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
417414 const place = closing ? ' before the end of `' + closing . type + '`' : ''
418415 const position = closing
419416 ? { start : closing . start , end : closing . end }
@@ -436,7 +433,7 @@ export function mdxJsxFromMarkdown() {
436433 * @type {OnExitError }
437434 */
438435 function onErrorLeftIsTag ( a , b ) {
439- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
436+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
440437 throw new VFileMessage (
441438 'Expected the closing tag `' +
442439 serializeAbbreviatedTag ( tag ) +
@@ -523,8 +520,8 @@ export function mdxJsxToMarkdown(options) {
523520 : false
524521 const depth = inferDepth ( context )
525522 const currentIndent = createIndent ( depth )
526- const trackerOneLine = track ( safeOptions )
527- const trackerMultiLine = track ( safeOptions )
523+ const trackerOneLine = context . createTracker ( safeOptions )
524+ const trackerMultiLine = context . createTracker ( safeOptions )
528525 /** @type {Array<string> } */
529526 const serializedAttributes = [ ]
530527 const prefix = ( flow ? currentIndent : '' ) + '<' + ( node . name || '' )
@@ -633,7 +630,11 @@ export function mdxJsxToMarkdown(options) {
633630 if ( node . children && node . children . length > 0 ) {
634631 if ( node . type === 'mdxJsxTextElement' ) {
635632 value += tracker . move (
636- containerPhrasing ( node , context , {
633+ // @ts -expect-error: `containerPhrasing` is typed correctly, but TS
634+ // generates *hardcoded* types, which means that our dynamically added
635+ // directives are not present.
636+ // At some point, TS should fix that, and `from-markdown` should be fine.
637+ context . containerPhrasing ( node , {
637638 ...tracker . current ( ) ,
638639 before : '>' ,
639640 after : '<'
@@ -697,7 +698,7 @@ function containerFlow(parent, state, info) {
697698 const serializedChild =
698699 child . type === 'mdxJsxFlowElement'
699700 ? result
700- : indentLines ( result , function ( line , _ , blank ) {
701+ : state . indentLines ( result , function ( line , _ , blank ) {
701702 return ( blank ? '' : currentIndent ) + line
702703 } )
703704
0 commit comments