-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/transforms/react): New jsx transform (#1408)
swc_ecma_transforms_react: - Implement new jsx transform. (#1103, denoland/deno#7993)
- Loading branch information
Showing
438 changed files
with
3,057 additions
and
103 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,19 @@ authors = ["강동윤 <[email protected]>"] | |
description = "rust port of babel and closure compiler." | ||
documentation = "https://swc.rs/rustdoc/swc_ecma_transforms_react/" | ||
edition = "2018" | ||
include = ["Cargo.toml", "src/**/*.rs"] | ||
license = "Apache-2.0/MIT" | ||
name = "swc_ecma_transforms_react" | ||
repository = "https://github.com/swc-project/swc.git" | ||
version = "0.5.1" | ||
version = "0.6.0" | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
dashmap = "4.0.1" | ||
once_cell = "1.5.2" | ||
regex = "1.4.2" | ||
serde = {version = "1.0.118", features = ["derive"]} | ||
string_enum = {version = "0.3", path = "../../../macros/string_enum"} | ||
swc_atoms = {version = "0.2", path = "../../../atoms"} | ||
swc_common = {version = "0.10", path = "../../../common"} | ||
swc_ecma_ast = {version = "0.38.0", path = "../../ast"} | ||
|
@@ -26,3 +28,4 @@ swc_ecma_visit = {version = "0.24.0", path = "../../visit"} | |
swc_ecma_transforms_compat = {version = "0.5.0", path = "../compat/"} | ||
swc_ecma_transforms_module = {version = "0.5.0", path = "../module"} | ||
swc_ecma_transforms_testing = {version = "0.4.0", path = "../testing/"} | ||
testing = {version = "0.10.2", path = "../../../testing"} |
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 @@ | ||
*.js |
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
npx tsc scripts/patch-options.ts | ||
node scripts/patch-options.js |
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,57 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
async function* walk(dir: string): AsyncGenerator<string> { | ||
for await (const d of await fs.promises.opendir(dir)) { | ||
const entry = path.join(dir, d.name); | ||
if (d.isDirectory()) yield* walk(entry); | ||
else if (d.isFile()) yield entry; | ||
} | ||
} | ||
|
||
// Then, use it with a simple async for loop | ||
async function main() { | ||
// TODO: Generalize path | ||
for await (const f of walk('src/jsx/fixture')) { | ||
if (!f.endsWith('.json')) { | ||
continue | ||
} | ||
const obj = JSON.parse(await fs.promises.readFile(f, { encoding: 'utf-8' })); | ||
const dir = path.dirname(f); | ||
|
||
if (obj.throws) { | ||
await fs.promises.writeFile(path.join(dir, "output.stderr"), obj.throws); | ||
} | ||
|
||
|
||
console.log(f); | ||
if (obj.plugins) { | ||
if (obj.plugins.includes('transform-react-jsx')) { | ||
const newObj = { | ||
...obj, | ||
}; | ||
delete newObj.sourceType | ||
delete newObj.plugins; | ||
await fs.promises.writeFile(f, JSON.stringify(newObj), { encoding: 'utf-8' }); | ||
continue | ||
} | ||
|
||
for (const [plugin, config] of obj.plugins) { | ||
if (plugin === 'transform-react-jsx') { | ||
console.log(plugin, config); | ||
const newObj = { | ||
...obj, | ||
...config, | ||
}; | ||
delete newObj.sourceType | ||
delete newObj.plugins; | ||
await fs.promises.writeFile(f, JSON.stringify(newObj), { encoding: 'utf-8' }); | ||
break | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
main() |
10 changes: 10 additions & 0 deletions
10
...ransforms/react/src/jsx/fixture/autoImport/.after-polyfills-script-not-supported/input.js
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 @@ | ||
// https://github.com/babel/babel/issues/12522 | ||
|
||
require('react-app-polyfill/ie11'); | ||
require('react-app-polyfill/stable'); | ||
const ReactDOM = require('react-dom'); | ||
|
||
ReactDOM.render( | ||
<p>Hello, World!</p>, | ||
document.getElementById('root') | ||
); |
1 change: 1 addition & 0 deletions
1
...forms/react/src/jsx/fixture/autoImport/.after-polyfills-script-not-supported/options.json
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 @@ | ||
{"runtime":"automatic"} |
12 changes: 12 additions & 0 deletions
12
...ansforms/react/src/jsx/fixture/autoImport/.after-polyfills-script-not-supported/output.js
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,12 @@ | ||
var _reactJsxRuntime = require("react/jsx-runtime"); | ||
|
||
// https://github.com/babel/babel/issues/12522 | ||
require('react-app-polyfill/ie11'); | ||
|
||
require('react-app-polyfill/stable'); | ||
|
||
const ReactDOM = require('react-dom'); | ||
|
||
ReactDOM.render( /*#__PURE__*/_reactJsxRuntime.jsx("p", { | ||
children: "Hello, World!" | ||
}), document.getElementById('root')); |
10 changes: 10 additions & 0 deletions
10
...ransforms/react/src/jsx/fixture/autoImport/.auto-import-react-source-type-script/input.js
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 @@ | ||
var x = ( | ||
<> | ||
<div> | ||
<div key="1" /> | ||
<div key="2" meow="wolf" /> | ||
<div key="3" /> | ||
<div {...props} key="4" /> | ||
</div> | ||
</> | ||
); |
1 change: 1 addition & 0 deletions
1
...forms/react/src/jsx/fixture/autoImport/.auto-import-react-source-type-script/options.json
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 @@ | ||
{"runtime":"automatic"} |
13 changes: 13 additions & 0 deletions
13
...ansforms/react/src/jsx/fixture/autoImport/.auto-import-react-source-type-script/output.js
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,13 @@ | ||
var _react = require("react"); | ||
|
||
var _reactJsxRuntime = require("react/jsx-runtime"); | ||
|
||
var x = /*#__PURE__*/_reactJsxRuntime.jsx(_reactJsxRuntime.Fragment, { | ||
children: /*#__PURE__*/_reactJsxRuntime.jsxs("div", { | ||
children: [/*#__PURE__*/_reactJsxRuntime.jsx("div", {}, "1"), /*#__PURE__*/_reactJsxRuntime.jsx("div", { | ||
meow: "wolf" | ||
}, "2"), /*#__PURE__*/_reactJsxRuntime.jsx("div", {}, "3"), /*#__PURE__*/_react.createElement("div", { ...props, | ||
key: "4" | ||
})] | ||
}) | ||
}); |
15 changes: 15 additions & 0 deletions
15
ecmascript/transforms/react/src/jsx/fixture/autoImport/.complicated-scope-script/input.js
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,15 @@ | ||
const Bar = () => { | ||
const Foo = () => { | ||
const Component = ({thing, ..._react}) => { | ||
if (!thing) { | ||
var _react2 = "something useless"; | ||
var b = _react3(); | ||
var c = _react5(); | ||
var jsx = 1; | ||
var _jsx = 2; | ||
return <div />; | ||
}; | ||
return <span />; | ||
}; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...script/transforms/react/src/jsx/fixture/autoImport/.complicated-scope-script/options.json
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 @@ | ||
{"runtime":"automatic"} |
25 changes: 25 additions & 0 deletions
25
ecmascript/transforms/react/src/jsx/fixture/autoImport/.complicated-scope-script/output.js
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,25 @@ | ||
var _reactJsxRuntime = require("react/jsx-runtime"); | ||
|
||
const Bar = () => { | ||
const Foo = () => { | ||
const Component = ({ | ||
thing, | ||
..._react | ||
}) => { | ||
if (!thing) { | ||
var _react2 = "something useless"; | ||
|
||
var b = _react3(); | ||
|
||
var c = _react5(); | ||
|
||
var jsx = 1; | ||
var _jsx = 2; | ||
return /*#__PURE__*/_reactJsxRuntime.jsx("div", {}); | ||
} | ||
|
||
; | ||
return /*#__PURE__*/_reactJsxRuntime.jsx("span", {}); | ||
}; | ||
}; | ||
}; |
11 changes: 11 additions & 0 deletions
11
ecmascript/transforms/react/src/jsx/fixture/autoImport/after-polyfills-2/input.mjs
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,11 @@ | ||
// https://github.com/babel/babel/issues/12522 | ||
|
||
ReactDOM.render( | ||
<p>Hello, World!</p>, | ||
document.getElementById('root') | ||
); | ||
|
||
// Imports are hoisted, so this is still ok | ||
import 'react-app-polyfill/ie11'; | ||
import 'react-app-polyfill/stable'; | ||
import ReactDOM from 'react-dom'; |
9 changes: 9 additions & 0 deletions
9
ecmascript/transforms/react/src/jsx/fixture/autoImport/after-polyfills-2/output.mjs
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,9 @@ | ||
// https://github.com/babel/babel/issues/12522 | ||
ReactDOM.render( /*#__PURE__*/_jsx("p", { | ||
children: "Hello, World!" | ||
}), document.getElementById('root')); // Imports are hoisted, so this is still ok | ||
|
||
import 'react-app-polyfill/ie11'; | ||
import 'react-app-polyfill/stable'; | ||
import ReactDOM from 'react-dom'; | ||
import { jsx as _jsx } from "react/jsx-runtime"; |
10 changes: 10 additions & 0 deletions
10
...ipt/transforms/react/src/jsx/fixture/autoImport/after-polyfills-compiled-to-cjs/input.mjs
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 @@ | ||
// https://github.com/babel/babel/issues/12522 | ||
|
||
import 'react-app-polyfill/ie11'; | ||
import 'react-app-polyfill/stable'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
ReactDOM.render( | ||
<p>Hello, World!</p>, | ||
document.getElementById('root') | ||
); |
1 change: 1 addition & 0 deletions
1
.../transforms/react/src/jsx/fixture/autoImport/after-polyfills-compiled-to-cjs/options.json
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 @@ | ||
{"runtime":"automatic"} |
16 changes: 16 additions & 0 deletions
16
...ipt/transforms/react/src/jsx/fixture/autoImport/after-polyfills-compiled-to-cjs/output.js
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,16 @@ | ||
"use strict"; | ||
|
||
require("react-app-polyfill/ie11"); | ||
|
||
require("react-app-polyfill/stable"); | ||
|
||
var _reactDom = _interopRequireDefault(require("react-dom")); | ||
|
||
var _jsxRuntime = require("react/jsx-runtime"); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
// https://github.com/babel/babel/issues/12522 | ||
_reactDom.default.render( /*#__PURE__*/(0, _jsxRuntime.jsx)("p", { | ||
children: "Hello, World!" | ||
}), document.getElementById('root')); |
10 changes: 10 additions & 0 deletions
10
ecmascript/transforms/react/src/jsx/fixture/autoImport/after-polyfills/input.mjs
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 @@ | ||
// https://github.com/babel/babel/issues/12522 | ||
|
||
import 'react-app-polyfill/ie11'; | ||
import 'react-app-polyfill/stable'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
ReactDOM.render( | ||
<p>Hello, World!</p>, | ||
document.getElementById('root') | ||
); |
8 changes: 8 additions & 0 deletions
8
ecmascript/transforms/react/src/jsx/fixture/autoImport/after-polyfills/output.mjs
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,8 @@ | ||
// https://github.com/babel/babel/issues/12522 | ||
import 'react-app-polyfill/ie11'; | ||
import 'react-app-polyfill/stable'; | ||
import ReactDOM from 'react-dom'; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
ReactDOM.render( /*#__PURE__*/_jsx("p", { | ||
children: "Hello, World!" | ||
}), document.getElementById('root')); |
Oops, something went wrong.