From 3e9a3cd2693bd660996cf6101138151ea5e4f55b Mon Sep 17 00:00:00 2001 From: FND Date: Tue, 7 Jan 2020 13:41:12 +0100 Subject: [PATCH] fixed support for JSX fragments turns out 5467bc6efd21b76831744ab7877aec5b6a468970 was insufficient --- lib/bundle/babel.js | 6 +++--- test/cli/test_jsx/expected.js | 2 +- test/cli/test_jsx/faucet.config.js | 5 ++++- test/cli/test_jsx/src/index.jsx | 6 ++++-- test/unit/expected/virtual_bundle_jsx.js | 4 ++-- test/unit/test_virtual.js | 9 +++++++-- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/bundle/babel.js b/lib/bundle/babel.js index e730823..c9f9001 100644 --- a/lib/bundle/babel.js +++ b/lib/bundle/babel.js @@ -31,9 +31,9 @@ module.exports = function generateTranspiler({ esnext, jsx, exclude }, { browser if(jsx) { extensions.push(".jsx"); - let { pragma } = jsx; - let options = pragma ? { pragma } : {}; - plugins.push(["@babel/plugin-transform-react-jsx", options]); + let { pragma, pragmaFrag } = jsx; + plugins.push(["@babel/plugin-transform-react-jsx", + { pragma, pragmaFrag }]); } if(plugins.length) { diff --git a/test/cli/test_jsx/expected.js b/test/cli/test_jsx/expected.js index 27a9125..3359619 100644 --- a/test/cli/test_jsx/expected.js +++ b/test/cli/test_jsx/expected.js @@ -13,6 +13,6 @@ var MyComponent = function MyComponent() { var el = createElement(MyComponent, { type: "dummy" -}, createElement("my-element", null, "lorem ipsum", createElement("mark", null, "666"), "dolor sit amet")); +}, createElement("my-element", null, "lorem ipsum", createElement(Fragment, null, createElement("mark", null, "666"), "dolor sit amet"))); }()); diff --git a/test/cli/test_jsx/faucet.config.js b/test/cli/test_jsx/faucet.config.js index 8a6ce7c..0951c8f 100644 --- a/test/cli/test_jsx/faucet.config.js +++ b/test/cli/test_jsx/faucet.config.js @@ -7,7 +7,10 @@ module.exports = { source: "./src/index.jsx", target: "./dist/bundle.js", esnext: true, - jsx: { pragma: "createElement" } + jsx: { + pragma: "createElement", + fragment: "Fragment" + } }], plugins: { js: { diff --git a/test/cli/test_jsx/src/index.jsx b/test/cli/test_jsx/src/index.jsx index ca7f6ae..ed64103 100644 --- a/test/cli/test_jsx/src/index.jsx +++ b/test/cli/test_jsx/src/index.jsx @@ -3,7 +3,9 @@ import MyComponent from "./component" let el = lorem ipsum - 666 - dolor sit amet + <> + 666 + dolor sit amet + diff --git a/test/unit/expected/virtual_bundle_jsx.js b/test/unit/expected/virtual_bundle_jsx.js index 0b45228..368d0ab 100644 --- a/test/unit/expected/virtual_bundle_jsx.js +++ b/test/unit/expected/virtual_bundle_jsx.js @@ -22,7 +22,7 @@ function List(_, ...children) { console.log(createElement(List, null, createElement(Button, { label: UTIL -}), createElement(Button, { +}), createElement(Fragment, null, createElement(Button, { type: "reset", label: MYLIB -}))); +})))); diff --git a/test/unit/test_virtual.js b/test/unit/test_virtual.js index 7e4827b..cffe6f9 100644 --- a/test/unit/test_virtual.js +++ b/test/unit/test_virtual.js @@ -38,7 +38,10 @@ console.log(UTIL + MYLIB); it("should support JSX", async () => { let bundle = new VirtualBundle(FIXTURES_DIR, { format: "CommonJS", - jsx: { pragma: "createElement" } + jsx: { + pragma: "createElement", + fragment: "Fragment" + } }, DEFAULT_OPTIONS); let { code, error } = await bundle.compile(` @@ -49,7 +52,9 @@ import createElement from "my-lib/elements"; console.log(