Skip to content

Commit

Permalink
fixed support for JSX fragments
Browse files Browse the repository at this point in the history
turns out 5467bc6 was insufficient
  • Loading branch information
FND committed Jan 8, 2020
1 parent b76dbfe commit 3e9a3cd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/bundle/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/test_jsx/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")));

}());
5 changes: 4 additions & 1 deletion test/cli/test_jsx/faucet.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 4 additions & 2 deletions test/cli/test_jsx/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import MyComponent from "./component"
let el = <MyComponent type="dummy">
<my-element>
lorem ipsum
<mark>666</mark>
dolor sit amet
<>
<mark>666</mark>
dolor sit amet
</>
</my-element>
</MyComponent>
4 changes: 2 additions & 2 deletions test/unit/expected/virtual_bundle_jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})));
}))));
9 changes: 7 additions & 2 deletions test/unit/test_virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand All @@ -49,7 +52,9 @@ import createElement from "my-lib/elements";
console.log(<List>
<Button label={UTIL} />
<Button type="reset" label={MYLIB} />
<>
<Button type="reset" label={MYLIB} />
</>
</List>);
`);
assertSame(error, undefined);
Expand Down

0 comments on commit 3e9a3cd

Please sign in to comment.