Skip to content

Commit 165c809

Browse files
committed
Simplify Babel plugin by removing object flattening
1 parent 5944ac0 commit 165c809

File tree

1 file changed

+1
-32
lines changed

1 file changed

+1
-32
lines changed

packages/babel-plugin-htm/index.mjs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,8 @@ export default function htmBabelPlugin({ types: t }, options = {}) {
6161
return t.callExpression(pragma, [tag, props, children]);
6262
}
6363

64-
function findNextNode(args, start) {
65-
for (let i = start; i < args.length; i++) {
66-
if (t.isNode(args[i])) {
67-
return i;
68-
}
69-
}
70-
return args.length;
71-
}
72-
73-
function flattenSpread(args) {
74-
const flattened = [];
75-
for (let i = 0; i < args.length; i++) {
76-
if (t.isNode(args[i])) {
77-
flattened.push(args[i]);
78-
}
79-
else {
80-
const start = i;
81-
const end = findNextNode(args, start + 1);
82-
flattened.push(Object.assign(...args.slice(start, end)));
83-
i = end - 1;
84-
}
85-
}
86-
return flattened;
87-
}
88-
8964
function spreadNode(args, state) {
90-
args = flattenSpread(args);
91-
92-
// Case 'Object.assign(x)' can be collapsed to 'x'.
93-
if (args.length === 1) {
94-
return propsNode(args[0]);
95-
}
96-
// Case 'Object.assign({}, x)', can be collapsed to 'x'.
65+
// 'Object.assign({}, x)', can be collapsed to 'x'.
9766
if (args.length === 2 && !t.isNode(args[0]) && Object.keys(args[0]).length === 0) {
9867
return propsNode(args[1]);
9968
}

0 commit comments

Comments
 (0)