Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: syntax-tree/xastscript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.0.1
Choose a base ref
...
head repository: syntax-tree/xastscript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.1.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Sep 8, 2022

  1. Add support for JSX dev runtime

    Closes Gh-15.
    
    Reviewed-by: Christian Murphy <[email protected]>
    Reviewed-by: Titus Wormer <[email protected]>
    remcohaszing authored Sep 8, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d0b4c88 View commit details
  2. 3.1.0

    wooorm committed Sep 8, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    5c051ea View commit details
Showing with 64 additions and 15 deletions.
  1. +20 −0 jsx-dev-runtime.js
  2. +4 −1 package.json
  3. +38 −11 script/generate-jsx.js
  4. +1 −1 test-d/automatic.tsx
  5. +1 −2 tsconfig.json
20 changes: 20 additions & 0 deletions jsx-dev-runtime.js
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xastscript",
"version": "3.0.1",
"version": "3.1.0",
"description": "xast utility to create trees",
"license": "MIT",
"keywords": [
@@ -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": {
49 changes: 38 additions & 11 deletions script/generate-jsx.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}
),
{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
)
2 changes: 1 addition & 1 deletion test-d/automatic.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @jsxRuntime automatic */
/* @jsxImportSource .. */
/* @jsxImportSource xastscript */

import {expectType, expectError} from 'tsd'
import type {Root, Element} from 'xast'
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"module": "Node16",
"allowJs": true,
"checkJs": true,
"declaration": true,