Skip to content

Commit

Permalink
fix(map): fix flap map handling
Browse files Browse the repository at this point in the history
using spread in map caused all maps to become flat maps
  • Loading branch information
kollhof committed Mar 29, 2020
1 parent ea01c04 commit 116e327
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lang/iterable/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ export const transform_any = (flatten)=> (node, {transform, unique_ident})=> {
const [item] = params([item_param]);
const [expressions, last_expr] = split_last(node.exprs);

const last_is_spread = (last_expr.type === 'spread');

const yield_value = (
last_expr.type === 'spread'
last_is_spread
? last_expr.right
: last_expr
);

if (last_expr.type === 'spread') {
flatten = true;
}

const items = unique_ident('items');

return generator('map')(items)(
for_of(item, items)(
...expressions.map(block_statement({transform})),
...yield_or_stop(transform(yield_value), unique_ident, flatten)
...yield_or_stop(
transform(yield_value),
unique_ident, flatten || last_is_spread
)
)
);
};
Expand Down

0 comments on commit 116e327

Please sign in to comment.