Skip to content

Commit

Permalink
✨ feat: ES2015 transform spread v4
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 22, 2024
1 parent 4819962 commit 5385e8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public Swc4jAstVisitorResponse visitArrayLit(Swc4jAstArrayLit node) {
if (optionalExprOrSpread.map(e -> e.getSpread().isPresent()).orElse(false)) {
break;
} else {
Swc4jAstExprOrSpread elem = Swc4jAstExprOrSpread.create(optionalExprOrSpread.get().getExpr());
elem.setParent(objArrayLit);
objArrayLit.getElems().add(Optional.of(elem));
Optional<Swc4jAstExprOrSpread> elem = optionalExprOrSpread
.map(e -> Swc4jAstExprOrSpread.create(e.getExpr()));
elem.ifPresent(e -> e.setParent(objArrayLit));
objArrayLit.getElems().add(elem);
startIndex = i + 1;
}
}
Expand Down Expand Up @@ -86,12 +87,12 @@ public Swc4jAstVisitorResponse visitArrayLit(Swc4jAstArrayLit node) {
if (objArrayLit == null) {
objArrayLit = Swc4jAstArrayLit.create();
}
Swc4jAstExprOrSpread elem = null;
if (optionalExprOrSpread.isPresent()) {
elem = Swc4jAstExprOrSpread.create(optionalExprOrSpread.get().getExpr());
elem.setParent(objArrayLit);
Optional<Swc4jAstExprOrSpread> elem = optionalExprOrSpread
.map(e -> Swc4jAstExprOrSpread.create(e.getExpr()));
if (elem.isPresent()) {
elem.get().setParent(objArrayLit);
}
objArrayLit.getElems().add(Optional.ofNullable(elem));
objArrayLit.getElems().add(elem);
}
}
if (objArrayLit != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public void testArrayLit() {
"const a=[1,2];const b=[3,4];JSON.stringify([\"x\",\"y\"].concat(a,b));",
"const a = [1,2]; const b = [3,4]; JSON.stringify([...a, ...[...a, ...b], ...b]);",
"const a=[1,2];const b=[3,4];JSON.stringify(a.concat(a.concat(b),b));",
"const a = [1,2]; const b = [3,4]; JSON.stringify([,,...a, ...b]);",
"const a=[1,2];const b=[3,4];JSON.stringify([,,].concat(a,b));",
"const a = [1,2]; const b = [3,4]; JSON.stringify([,,...a,,, ...b]);",
"const a=[1,2];const b=[3,4];JSON.stringify([,,].concat(a,[,,],b));",
"const a = [1,2]; JSON.stringify([...a]);",
"const a=[1,2];JSON.stringify(a);"));
}
Expand Down

0 comments on commit 5385e8f

Please sign in to comment.