diff --git a/jsx-dev-runtime.js b/jsx-dev-runtime.js new file mode 100644 index 0000000..dccba61 --- /dev/null +++ b/jsx-dev-runtime.js @@ -0,0 +1,20 @@ +/** + * @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 {Fragment} from './jsx-runtime.js' + +// eslint-disable-next-line unicorn/prefer-export-from +export const jsxDEV = + /** + * @type {{ + * (name: null|undefined, props: {children?: XChild}, ...unused: unknown[]): Root + * (name: string, props: JSXProps, ...unused: unknown[]): Element + * }} + */ + (jsx) diff --git a/package.json b/package.json index 3678641..5d62812 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,15 @@ "lib/", "index.d.ts", "index.js", + "jsx-dev-runtime.d.ts", + "jsx-dev-runtime.js", "jsx-runtime.d.ts", "jsx-runtime.js" ], "exports": { ".": "./index.js", "./index.js": "./index.js", + "./jsx-dev-runtime": "./jsx-dev-runtime.js", "./jsx-runtime": "./jsx-runtime.js" }, "dependencies": { diff --git a/script/generate-jsx.js b/script/generate-jsx.js index 8484b87..4411102 100644 --- a/script/generate-jsx.js +++ b/script/generate-jsx.js @@ -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} + ), + {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 ) diff --git a/test-d/automatic.tsx b/test-d/automatic.tsx index dc3f4e8..61f11e8 100644 --- a/test-d/automatic.tsx +++ b/test-d/automatic.tsx @@ -1,5 +1,5 @@ /* @jsxRuntime automatic */ -/* @jsxImportSource .. */ +/* @jsxImportSource xastscript */ import {expectType, expectError} from 'tsd' import type {Root, Element} from 'xast' diff --git a/tsconfig.json b/tsconfig.json index ec45143..ab14bdd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,8 +11,7 @@ "compilerOptions": { "target": "ES2020", "lib": ["ES2020"], - "module": "ES2020", - "moduleResolution": "node", + "module": "Node16", "allowJs": true, "checkJs": true, "declaration": true,