-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDX files are compiled to JavaScript and support source maps. They can be debugged.
- Loading branch information
1 parent
6d6760b
commit df4fdd2
Showing
7 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"vscode-mdx": patch | ||
--- | ||
|
||
Add support for breakpoints. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{/** | ||
* @typedef Step | ||
* @property {React.ReactNode} description | ||
* @property {boolean} [optional] | ||
*/} | ||
|
||
{/** | ||
* @typedef ExampleProps | ||
* @property {string} [reference] | ||
*/} | ||
|
||
# Debugging | ||
|
||
This fixture workspace contains some code to test if breakpoints work as expected. | ||
You can try this using Visual Studio Code. | ||
|
||
{/** @type {Step[]} */} | ||
export const steps = [ | ||
{ | ||
description: 'Open Visual Studio Code' | ||
}, | ||
{ | ||
description: 'Grab some coffee', | ||
optional: true | ||
}, | ||
{ | ||
description: 'Set some breakpoints in this document' | ||
}, | ||
{ | ||
description: 'Open the Visual Studio Code JavaScript Debug Terminal' | ||
}, | ||
{ | ||
description: 'Navigate to the directory containing this document' | ||
}, | ||
{ | ||
description: <>Run <code>./run.mjs</code></> | ||
} | ||
] | ||
|
||
<ul>{steps.map((step, index) => { | ||
const shouldRender = !step.optional | ||
|
||
if(shouldRender) { | ||
return <li key={index}>{step.description}</li> | ||
} | ||
})}</ul> | ||
|
||
{/** | ||
* @param {ExampleProps} props | ||
*/} | ||
export function Example({reference}) { | ||
debugger | ||
let string | ||
if (reference) { | ||
string = 'For example, see ' + reference | ||
} else { | ||
string = 'No example reference given' | ||
} | ||
|
||
return 'For example, see ' + reference | ||
} | ||
|
||
It works in custom components too. | ||
Also `debugger` expressions work. | ||
<Example reference="this example" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {createLoader} from '@mdx-js/node-loader' | ||
import {SourceMapGenerator} from 'source-map' | ||
|
||
export const {load} = createLoader({SourceMapGenerator}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env node | ||
import {register} from 'node:module' | ||
import {renderToStaticMarkup} from 'react-dom/server' | ||
import React from 'react' | ||
|
||
register('./loader.mjs', import.meta.url) | ||
|
||
const module = await import('./example.mdx') | ||
|
||
console.log(renderToStaticMarkup(React.createElement(module.default))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters