-
-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for JSX dev runtime #15
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @typedef {import('xast').Element} Element | ||
* @typedef {import('xast').Root} Root | ||
* @typedef {import('./lib/index.js').XChild} XChild | ||
* @typedef {import('./lib/runtime.js').JSXProps} JSXProps | ||
*/ | ||
|
||
import {jsx} from './jsx-runtime.js' | ||
|
||
export const jsxDEV = | ||
/** | ||
* @type {{ | ||
* (name: null|undefined, props: {children?: XChild}, ...unused: unknown[]): Root | ||
* (name: string, props: JSXProps, ...unused: unknown[]): Element | ||
* }} | ||
*/ | ||
( | ||
function (name, props) { | ||
return jsx(/** @type {string} */ (name), props) | ||
} | ||
) | ||
export {Fragment} from './jsx-runtime.js' | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,10 +38,26 @@ fs.writeFileSync( | |
// @ts-ignore Hush, `2021` is fine. | ||
{sourceType: 'module', ecmaVersion: 2021} | ||
), | ||
{runtime: 'automatic', importSource: '.'} | ||
{runtime: 'automatic', importSource: 'xastscript'} | ||
) | ||
// @ts-expect-error Some bug in `to-js` | ||
).value.replace(/\/jsx-runtime(?=["'])/g, './lib/runtime.js') | ||
).value | ||
) | ||
|
||
fs.writeFileSync( | ||
path.join('test', 'jsx-build-jsx-automatic-development.js'), | ||
toJs( | ||
// @ts-expect-error it’s a program. | ||
buildJsx( | ||
// @ts-expect-error Acorn nodes are assignable to ESTree nodes. | ||
Parser.extend(acornJsx()).parse( | ||
doc.replace(/'name'/, "'jsx (estree-util-build-jsx, automatic)'"), | ||
{sourceType: 'module', ecmaVersion: 2021} | ||
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. This might error (it just did for me on the above ones, see the 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. oh it passes, weird 🤷♂️ well nvm then 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. Yeah I had to resolve some merge conflicts here. Not sure what happened upstream. |
||
), | ||
{runtime: 'automatic', importSource: 'xastscript', development: true} | ||
) | ||
// @ts-expect-error Some bug in `to-js` | ||
).value | ||
) | ||
|
||
fs.writeFileSync( | ||
|
@@ -57,14 +73,25 @@ fs.writeFileSync( | |
fs.writeFileSync( | ||
path.join('test', 'jsx-babel-automatic.js'), | ||
// @ts-expect-error Result always given. | ||
babel | ||
.transformSync(doc.replace(/'name'/, "'jsx (babel, automatic)'"), { | ||
plugins: [ | ||
[ | ||
'@babel/plugin-transform-react-jsx', | ||
{runtime: 'automatic', importSource: '.'} | ||
] | ||
babel.transformSync(doc.replace(/'name'/, "'jsx (babel, automatic)'"), { | ||
plugins: [ | ||
[ | ||
'@babel/plugin-transform-react-jsx', | ||
{runtime: 'automatic', importSource: 'xastscript'} | ||
] | ||
}) | ||
.code.replace(/\/jsx-runtime(?=["'])/g, './lib/runtime.js') | ||
] | ||
}).code | ||
) | ||
|
||
fs.writeFileSync( | ||
path.join('test', 'jsx-babel-automatic-development.js'), | ||
// @ts-expect-error Result always given. | ||
babel.transformSync(doc.replace(/'name'/, "'jsx (babel, automatic)'"), { | ||
plugins: [ | ||
[ | ||
'@babel/plugin-transform-react-jsx', | ||
{runtime: 'automatic', importSource: 'xastscript', development: true} | ||
] | ||
] | ||
}).code | ||
) |
Uh oh!
There was an error while loading. Please reload this page.