Skip to content

Commit 94b4f3a

Browse files
committed
feat: merge static and dynamic class / style attributes into array
1 parent bf59811 commit 94b4f3a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/babel-plugin-jsx/src/buildProps.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,12 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
272272
attributeValue || t.booleanLiteral(true),
273273
));
274274
}
275-
mergeArgs.push(t.objectExpression(dedupeProperties(properties)));
276-
properties = [];
277275
} else {
276+
if (properties.length) {
277+
mergeArgs.push(t.objectExpression(dedupeProperties(properties)));
278+
properties = [];
279+
}
280+
278281
// JSXSpreadAttribute
279282
hasDynamicKeys = true;
280283
transformJSXSpreadAttribute(
@@ -313,6 +316,9 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
313316
let propsExpression: t.Expression | t.ObjectProperty | t.Literal = t.nullLiteral();
314317

315318
if (mergeArgs.length) {
319+
if (properties.length) {
320+
mergeArgs.push(t.objectExpression(dedupeProperties(properties)));
321+
}
316322
if (mergeArgs.length > 1) {
317323
propsExpression = t.callExpression(
318324
createIdentifier(state, 'mergeProps'),
@@ -322,6 +328,8 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
322328
// single no need for a mergeProps call
323329
propsExpression = mergeArgs[0];
324330
}
331+
} else if (properties.length) {
332+
propsExpression = t.objectExpression(dedupeProperties(properties));
325333
}
326334

327335
return {

0 commit comments

Comments
 (0)