Skip to content

Commit

Permalink
reuse member expressions as the local collection (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
planttheidea committed Dec 18, 2023
1 parent 6607ece commit a6cc882
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
33 changes: 13 additions & 20 deletions __tests__/__fixtures__/complex/jsx/output.js
@@ -1,23 +1,16 @@
import React from 'react';
function List(props) {
return /*#__PURE__*/ React.createElement(
'ul',
null,
(() => {
const _collection = props.items;
const _length = _collection.length;
const _results = Array(_length);
for (let _key = 0, _item; _key < _length; ++_key) {
_item = _collection[_key];
_results[_key] = /*#__PURE__*/ React.createElement(
'li',
{
key: _item.id,
},
_item.value,
);
}
return _results;
})(),
);
const _length = props.items.length;
const _results = Array(_length);
for (let _key = 0, _item; _key < _length; ++_key) {
_item = props.items[_key];
_results[_key] = /*#__PURE__*/ React.createElement(
'li',
{
key: _item.id,
},
_item.value,
);
}
return /*#__PURE__*/ React.createElement('ul', null, _results);
}
2 changes: 1 addition & 1 deletion src/handlers.ts
Expand Up @@ -178,7 +178,7 @@ export function createHandlers(babel: MacroParams['babel']) {

let localCollection = collection.node;

if (!collection.isIdentifier()) {
if (!collection.isIdentifier() && !collection.isMemberExpression()) {
localCollection = getLocalName(path, 'collection');

const localVariable = templates.localVariable({
Expand Down

0 comments on commit a6cc882

Please sign in to comment.