From d15489321058565bcfad2fcc78c17ff85940cdf0 Mon Sep 17 00:00:00 2001 From: Sam Cao Date: Sun, 9 Jun 2024 10:56:57 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Add=20createDefault()=20to?= =?UTF-8?q?=20ISwc4jAstStmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javet/swc4j/ast/interfaces/ISwc4jAstStmt.java | 3 +++ .../javet/swc4j/ast/stmt/Swc4jAstDoWhileStmt.java | 4 ++++ .../caoccao/javet/swc4j/ast/stmt/Swc4jAstForInStmt.java | 4 ++++ .../caoccao/javet/swc4j/ast/stmt/Swc4jAstForOfStmt.java | 9 +++++---- .../caoccao/javet/swc4j/ast/stmt/Swc4jAstForStmt.java | 4 ++++ .../com/caoccao/javet/swc4j/ast/stmt/Swc4jAstIfStmt.java | 4 ++++ .../javet/swc4j/ast/stmt/Swc4jAstLabeledStmt.java | 4 ++++ .../caoccao/javet/swc4j/ast/stmt/Swc4jAstWhileStmt.java | 4 ++++ .../caoccao/javet/swc4j/ast/stmt/Swc4jAstWithStmt.java | 4 ++++ .../caoccao/javet/swc4j/ast/stmt/TestSwc4jAstIfStmt.java | 1 - 10 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/interfaces/ISwc4jAstStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/interfaces/ISwc4jAstStmt.java index ca102eb3..e82e42e5 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/interfaces/ISwc4jAstStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/interfaces/ISwc4jAstStmt.java @@ -44,4 +44,7 @@ } ) public interface ISwc4jAstStmt extends ISwc4jAstModuleItem { + static ISwc4jAstStmt createDefault() { + return Swc4jAstEmptyStmt.create(); + } } diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstDoWhileStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstDoWhileStmt.java index 054f61dc..18be801a 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstDoWhileStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstDoWhileStmt.java @@ -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); } diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForInStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForInStmt.java index bb211be6..7d28211e 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForInStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForInStmt.java @@ -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); } diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForOfStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForOfStmt.java index 5d093310..33c49ee0 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForOfStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForOfStmt.java @@ -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); } diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForStmt.java index e716c853..64399673 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstForStmt.java @@ -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); } diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstIfStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstIfStmt.java index f1eeea02..350d2e2f 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstIfStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstIfStmt.java @@ -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); } diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstLabeledStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstLabeledStmt.java index d36f8eb5..a7247eb0 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstLabeledStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstLabeledStmt.java @@ -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); } diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstWhileStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstWhileStmt.java index 34f209e7..1dc367d7 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstWhileStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstWhileStmt.java @@ -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); } diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstWithStmt.java b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstWithStmt.java index 95345f25..f98cbb54 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstWithStmt.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/stmt/Swc4jAstWithStmt.java @@ -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); } diff --git a/src/test/java/com/caoccao/javet/swc4j/ast/stmt/TestSwc4jAstIfStmt.java b/src/test/java/com/caoccao/javet/swc4j/ast/stmt/TestSwc4jAstIfStmt.java index baf9631d..89e97605 100644 --- a/src/test/java/com/caoccao/javet/swc4j/ast/stmt/TestSwc4jAstIfStmt.java +++ b/src/test/java/com/caoccao/javet/swc4j/ast/stmt/TestSwc4jAstIfStmt.java @@ -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(