Skip to content

Commit f6bfe88

Browse files
blikblumjviide
authored andcommitted
Fix fragments when last root child is an expression
1 parent 89e066f commit f6bfe88

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/babel-plugin-transform-jsx-to-htm/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default function jsxToHtmBabelPlugin({ types: t }, options = {}) {
181181
processChildren(node, name, isFragment);
182182

183183
if (isRoot) {
184-
commit();
184+
commit(true);
185185
const template = t.templateLiteral(quasis, expressions);
186186
const replacement = t.taggedTemplateExpression(tag, template);
187187
path.replaceWith(replacement);

test/babel-transform-jsx.test.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ describe('babel-plugin-transform-jsx-to-htm', () => {
113113
compile(`<><div>Foo</div><div>Bar</div></>`)
114114
).toBe('html`<div>Foo</div><div>Bar</div>`;');
115115
});
116+
117+
test('root expressions', () => {
118+
expect(
119+
compile(`<React.Fragment>{Foo}{Bar}</React.Fragment>`)
120+
).toBe('html`${Foo}${Bar}`;');
121+
});
116122
});
117123

118124
describe('props', () => {

0 commit comments

Comments
 (0)