New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support jsx dev runtime #2045
Support jsx dev runtime #2045
Changes from 1 commit
5d88053
3ca82dc
1cd4700
7891c37
6085e65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -548,6 +548,56 @@ test('compile', async () => { | |
) | ||
console.log('\nnote: the preceding warning is expected!\n') | ||
|
||
const developmentSourceNode = ( | ||
await run( | ||
compileSync( | ||
{value: '<div />', path: 'path/to/file.js'}, | ||
{development: true} | ||
).value | ||
) | ||
)({}) | ||
assert.equal( | ||
// @ts-expect-error React attaches source information on this property, | ||
// but it’s private and untyped. | ||
developmentSourceNode._source, | ||
{fileName: 'path/to/file.js', lineNumber: 1, columnNumber: 1}, | ||
'should expose source information in the automatic jsx dev runtime' | ||
) | ||
|
||
assert.equal( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe good to move this one next to the jsx tests (L826), in a new test for |
||
compileSync({value: '<X />', path: 'path/to/file.js'}, {development: true}) | ||
.value, | ||
[ | ||
'/*@jsxRuntime automatic @jsxImportSource react*/', | ||
'import {jsxDEV as _jsxDEV} from "react/jsx-dev-runtime";', | ||
'function MDXContent(props = {}) {', | ||
' const {wrapper: MDXLayout} = props.components || ({});', | ||
' return MDXLayout ? _jsxDEV(MDXLayout, Object.assign({}, props, {', | ||
' children: _jsxDEV(_createMdxContent, {}, undefined, false, {', | ||
' fileName: "path/to/file.js"', | ||
' }, this)', | ||
' }), undefined, false, {', | ||
' fileName: "path/to/file.js"', | ||
' }, this) : _createMdxContent();', | ||
' function _createMdxContent() {', | ||
' const {X} = props.components || ({});', | ||
' if (!X) _missingMdxReference("X", true, "1:1-1:6");', | ||
' return _jsxDEV(X, {}, undefined, false, {', | ||
' fileName: "path/to/file.js",', | ||
' lineNumber: 1,', | ||
' columnNumber: 1', | ||
' }, this);', | ||
' }', | ||
'}', | ||
'export default MDXContent;', | ||
'function _missingMdxReference(id, component, place) {', | ||
' throw new Error("Expected " + (component ? "component" : "object") + " `" + id + "` to be defined: you likely forgot to import, pass, or provide it." + (place ? "\\nIt’s referenced in your code at `" + place + "` in `path/to/file.js`" : ""));', | ||
'}', | ||
'' | ||
].join('\n'), | ||
'should support the jsx dev runtime' | ||
) | ||
|
||
try { | ||
renderToStaticMarkup( | ||
React.createElement(await run(compileSync('<X />', {development: true}))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test above uses an undocumented private property of React elements. The test below asserts the generated source code. None of these tests is ideal, but I’m not sure which is worse. I suggest to keep only one of them though.