Skip to content

Commit

Permalink
✨ feat: Replace constructor for member expr
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 18, 2024
1 parent 2d489b4 commit d95b2a1
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
public class Swc4jAstMemberExpr
extends Swc4jAst
implements ISwc4jAstExpr, ISwc4jAstOptChainBase, ISwc4jAstSimpleAssignTarget {
public static final String CONSTRUCTOR = "constructor";
public static final String FUNCTION = "Function";
@Jni2RustField(box = true)
protected ISwc4jAstExpr obj;
protected ISwc4jAstMemberProp prop;
Expand Down Expand Up @@ -77,6 +79,31 @@ public Optional<ISwc4jAst> eval() {
}
}
break;
case MemberExpr:
if (prop.getType() == Swc4jAstType.ComputedPropName) {
Swc4jAstComputedPropName computedPropName = prop.as(Swc4jAstComputedPropName.class);
ISwc4jAstExpr expr = computedPropName.getExpr().unParenExpr();
if (expr.getType() == Swc4jAstType.Str) {
setProp(Swc4jAstIdent.create(expr.as(Swc4jAstStr.class).getValue()));
}
}
if (prop.getType() == Swc4jAstType.Ident) {
if (CONSTRUCTOR.equals(prop.as(Swc4jAstIdent.class).getSym())) {
Swc4jAstMemberExpr childMemberExpr = obj.as(Swc4jAstMemberExpr.class);
if (childMemberExpr.getObj().getType() == Swc4jAstType.ArrayLit
&& childMemberExpr.getProp().getType() == Swc4jAstType.ComputedPropName) {
Swc4jAstComputedPropName childComputedPropName = childMemberExpr.getProp().as(Swc4jAstComputedPropName.class);
ISwc4jAstExpr childExpr = childComputedPropName.getExpr().unParenExpr();
if (childExpr.getType() == Swc4jAstType.Str) {
Swc4jAstStr childStr = childExpr.as(Swc4jAstStr.class);
if (Swc4jAstArrayLit.ARRAY_FUNCTION_SET.contains(childStr.getValue())) {
return Optional.of(Swc4jAstIdent.create(FUNCTION));
}
}
}
}
}
break;
case Str:
if (prop.getType() == Swc4jAstType.ComputedPropName) {
Swc4jAstComputedPropName computedPropName = prop.as(Swc4jAstComputedPropName.class);
Expand Down

0 comments on commit d95b2a1

Please sign in to comment.