Skip to content

Commit

Permalink
✨ feat: Add createDefault() to ISwc4jAstStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Jun 9, 2024
1 parent 3b763cc commit d154893
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@
}
)
public interface ISwc4jAstStmt extends ISwc4jAstModuleItem {
static ISwc4jAstStmt createDefault() {
return Swc4jAstEmptyStmt.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public Swc4jAstDoWhileStmt(
setTest(test);
}

public static Swc4jAstDoWhileStmt create(ISwc4jAstExpr test) {
return create(test, ISwc4jAstStmt.createDefault());
}

public static Swc4jAstDoWhileStmt create(ISwc4jAstExpr test, ISwc4jAstStmt body) {
return new Swc4jAstDoWhileStmt(test, body, Swc4jSpan.DUMMY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public Swc4jAstForInStmt(
setRight(right);
}

public static Swc4jAstForInStmt create(ISwc4jAstForHead left, ISwc4jAstExpr right) {
return create(left, right, ISwc4jAstStmt.createDefault());
}

public static Swc4jAstForInStmt create(ISwc4jAstForHead left, ISwc4jAstExpr right, ISwc4jAstStmt body) {
return new Swc4jAstForInStmt(left, right, body, Swc4jSpan.DUMMY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public Swc4jAstForOfStmt(
setRight(right);
}

public static Swc4jAstForOfStmt create(
ISwc4jAstForHead left,
ISwc4jAstExpr right,
ISwc4jAstStmt body) {
public static Swc4jAstForOfStmt create(ISwc4jAstForHead left, ISwc4jAstExpr right) {
return create(false, left, right, ISwc4jAstStmt.createDefault());
}

public static Swc4jAstForOfStmt create(ISwc4jAstForHead left, ISwc4jAstExpr right, ISwc4jAstStmt body) {
return create(false, left, right, body);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public Swc4jAstForStmt(
setUpdate(update);
}

public static Swc4jAstForStmt create() {
return create(ISwc4jAstStmt.createDefault());
}

public static Swc4jAstForStmt create(ISwc4jAstStmt body) {
return create(null, body);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public Swc4jAstIfStmt(
setTest(test);
}

public static Swc4jAstIfStmt create(ISwc4jAstExpr test) {
return create(test, ISwc4jAstStmt.createDefault());
}

public static Swc4jAstIfStmt create(ISwc4jAstExpr test, ISwc4jAstStmt cons) {
return create(test, cons, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public Swc4jAstLabeledStmt(
setLabel(label);
}

public static Swc4jAstLabeledStmt create(Swc4jAstIdent label) {
return create(label, ISwc4jAstStmt.createDefault());
}

public static Swc4jAstLabeledStmt create(Swc4jAstIdent label, ISwc4jAstStmt body) {
return new Swc4jAstLabeledStmt(label, body, Swc4jSpan.DUMMY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public Swc4jAstWhileStmt(
setTest(test);
}

public static Swc4jAstWhileStmt create(ISwc4jAstExpr test) {
return create(test, ISwc4jAstStmt.createDefault());
}

public static Swc4jAstWhileStmt create(ISwc4jAstExpr test, ISwc4jAstStmt body) {
return new Swc4jAstWhileStmt(test, body, Swc4jSpan.DUMMY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public Swc4jAstWithStmt(
setObj(obj);
}

public static Swc4jAstWithStmt create(ISwc4jAstExpr obj) {
return create(obj, ISwc4jAstStmt.createDefault());
}

public static Swc4jAstWithStmt create(ISwc4jAstExpr obj, ISwc4jAstStmt body) {
return new Swc4jAstWithStmt(obj, body, Swc4jSpan.DUMMY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void testWithoutParenthesis() throws Swc4jCoreException {
String code = "if (a) b; else c;";
Swc4jParseOutput output = swc4j.parse(code, tsScriptParseOptions);
Swc4jAstScript script = output.getProgram().as(Swc4jAstScript.class);
System.out.println(script.toDebugString());
Swc4jAstIfStmt ifStmt = assertAst(
script, script.getBody().get(0).as(Swc4jAstIfStmt.class), Swc4jAstType.IfStmt, 0, 17);
Swc4jAstIdent ident = assertAst(
Expand Down

0 comments on commit d154893

Please sign in to comment.