Skip to content

Commit 6420110

Browse files
committed
Add support for spread props.
1 parent 38c0223 commit 6420110

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/babel-plugin-transform-jsx-to-tagged-templates/src/index.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ export default function jsxToTaggedTemplatesBabelPlugin({ types: t }, options =
6666

6767
if (open.attributes) {
6868
for (let i = 0; i < open.attributes.length; i++) {
69-
const { name, value } = open.attributes[i];
69+
const attr = open.attributes[i];
7070
raw(' ');
71+
if (t.isJSXSpreadAttribute(attr)) {
72+
raw('...');
73+
expr(attr.argument);
74+
continue;
75+
}
76+
const { name, value } = attr;
7177
raw(name.name);
7278
if (value) {
7379
raw('=');

packages/babel-plugin-transform-jsx-to-tagged-templates/test/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ describe('babel-plugin-transform-jsx-to-tagged-templates', () => {
6262
compile('const Foo = (props, a) => <div a={a} b={"b"} c={{}} d={props.d} e />;')
6363
).toBe('const Foo = (props, a) => html`<div a=${a} b=${"b"} c=${{}} d=${props.d} e/>`;');
6464
});
65+
66+
test('spread', () => {
67+
expect(
68+
compile('const Foo = props => <div {...props} />;')
69+
).toBe('const Foo = props => html`<div ...${props}/>`;');
70+
71+
expect(
72+
compile('(<div {...{}} />);')
73+
).toBe('html`<div ...${{}}/>`;');
74+
75+
expect(
76+
compile('(<div a {...b} c />);')
77+
).toBe('html`<div a ...${b} c/>`;');
78+
});
6579
});
6680

6781
describe('nesting', () => {

0 commit comments

Comments
 (0)