Skip to content

Commit

Permalink
✨ feat: Add create() v11
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Jun 3, 2024
1 parent 6521ae1 commit 9da6fe1
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 1 deletion.
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, ISwc4jAstStmt body) {
return new Swc4jAstLabeledStmt(label, body, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public ISwc4jAstStmt getBody() {
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public Swc4jAstReturnStmt(
setArg(arg);
}

public static Swc4jAstReturnStmt create() {
return create(null);
}

public static Swc4jAstReturnStmt create(ISwc4jAstExpr arg) {
return new Swc4jAstReturnStmt(arg, Swc4jSpan.DUMMY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public Swc4jAstSwitchStmt(
this.cases.forEach(node -> node.setParent(this));
}

public static Swc4jAstSwitchStmt create(ISwc4jAstExpr discriminant) {
return create(discriminant, SimpleList.of());
}

public static Swc4jAstSwitchStmt create(ISwc4jAstExpr discriminant, List<Swc4jAstSwitchCase> cases) {
return new Swc4jAstSwitchStmt(discriminant, cases, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public List<Swc4jAstSwitchCase> getCases() {
return cases;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public Swc4jAstThrowStmt(
setArg(arg);
}

public static Swc4jAstThrowStmt create(ISwc4jAstExpr arg) {
return new Swc4jAstThrowStmt(arg, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public ISwc4jAstExpr getArg() {
return arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ public Swc4jAstTryStmt(
setHandler(handler);
}

public static Swc4jAstTryStmt create(Swc4jAstBlockStmt block) {
return create(block, null, null);
}

public static Swc4jAstTryStmt create(Swc4jAstBlockStmt block, Swc4jAstCatchClause handler) {
return create(block, handler, null);
}

public static Swc4jAstTryStmt create(Swc4jAstBlockStmt block, Swc4jAstBlockStmt finalizer) {
return create(block, null, finalizer);
}

public static Swc4jAstTryStmt create(
Swc4jAstBlockStmt block,
Swc4jAstCatchClause handler,
Swc4jAstBlockStmt finalizer) {
return new Swc4jAstTryStmt(block, handler, finalizer, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public Swc4jAstBlockStmt getBlock() {
return block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ public Swc4jAstTsEnumDecl(
this.members.forEach(node -> node.setParent(this));
}

public static Swc4jAstTsEnumDecl create(Swc4jAstIdent id) {
return create(id, SimpleList.of());
}

public static Swc4jAstTsEnumDecl create(Swc4jAstIdent id, List<Swc4jAstTsEnumMember> members) {
return create(false, id, members);
}

public static Swc4jAstTsEnumDecl create(
boolean declare,
Swc4jAstIdent id,
List<Swc4jAstTsEnumMember> members) {
return create(declare, false, id, members);
}

public static Swc4jAstTsEnumDecl create(
boolean declare,
boolean _const,
Swc4jAstIdent id,
List<Swc4jAstTsEnumMember> members) {
return new Swc4jAstTsEnumDecl(declare, _const, id, members, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(members);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ public Swc4jAstTsInterfaceDecl(
this._extends.forEach(node -> node.setParent(this));
}

public static Swc4jAstTsInterfaceDecl create(Swc4jAstIdent id, Swc4jAstTsInterfaceBody body) {
return create(id, SimpleList.of(), body);
}

public static Swc4jAstTsInterfaceDecl create(
Swc4jAstIdent id,
List<Swc4jAstTsExprWithTypeArgs> _extends,
Swc4jAstTsInterfaceBody body) {
return create(id, null, _extends, body);
}

public static Swc4jAstTsInterfaceDecl create(
Swc4jAstIdent id,
Swc4jAstTsTypeParamDecl typeParams,
List<Swc4jAstTsExprWithTypeArgs> _extends,
Swc4jAstTsInterfaceBody body) {
return create(id, false, typeParams, _extends, body);
}

public static Swc4jAstTsInterfaceDecl create(
Swc4jAstIdent id,
boolean declare,
Swc4jAstTsTypeParamDecl typeParams,
List<Swc4jAstTsExprWithTypeArgs> _extends,
Swc4jAstTsInterfaceBody body) {
return new Swc4jAstTsInterfaceDecl(id, declare, typeParams, _extends, body, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public Swc4jAstTsInterfaceBody getBody() {
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ public Swc4jAstTsModuleDecl(
setId(id);
}

public static Swc4jAstTsModuleDecl create(ISwc4jAstTsModuleName id) {
return create(id, null);
}

public static Swc4jAstTsModuleDecl create(ISwc4jAstTsModuleName id, ISwc4jAstTsNamespaceBody body) {
return create(false, id, body);
}

public static Swc4jAstTsModuleDecl create(
boolean declare,
ISwc4jAstTsModuleName id,
ISwc4jAstTsNamespaceBody body) {
return create(declare, false, id, body);
}

public static Swc4jAstTsModuleDecl create(
boolean declare,
boolean global,
ISwc4jAstTsModuleName id,
ISwc4jAstTsNamespaceBody body) {
return new Swc4jAstTsModuleDecl(declare, global, id, body, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public Optional<ISwc4jAstTsNamespaceBody> getBody() {
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ public Swc4jAstTsTypeAliasDecl(
setTypeParams(typeParams);
}

public static Swc4jAstTsTypeAliasDecl create(Swc4jAstIdent id, ISwc4jAstTsType typeAnn) {
return create(id, null, typeAnn);
}

public static Swc4jAstTsTypeAliasDecl create(
Swc4jAstIdent id,
Swc4jAstTsTypeParamDecl typeParams,
ISwc4jAstTsType typeAnn) {
return create(id, false, typeParams, typeAnn);
}

public static Swc4jAstTsTypeAliasDecl create(
Swc4jAstIdent id,
boolean declare,
Swc4jAstTsTypeParamDecl typeParams,
ISwc4jAstTsType typeAnn) {
return new Swc4jAstTsTypeAliasDecl(id, declare, typeParams, typeAnn, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.of(id, typeAnn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public Swc4jAstUsingDecl(
this.decls.forEach(node -> node.setParent(this));
}

public static Swc4jAstUsingDecl create() {
return create(SimpleList.of());
}

public static Swc4jAstUsingDecl create(List<Swc4jAstVarDeclarator> decls) {
return create(false, decls);
}

public static Swc4jAstUsingDecl create(boolean _await, List<Swc4jAstVarDeclarator> decls) {
return new Swc4jAstUsingDecl(_await, decls, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.copyOf(decls);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public static Swc4jAstVarDeclarator create(ISwc4jAstPat name) {
}

public static Swc4jAstVarDeclarator create(ISwc4jAstPat name, ISwc4jAstExpr init) {
return new Swc4jAstVarDeclarator(name, init, false, Swc4jSpan.DUMMY);
return create(name, init, false);
}

public static Swc4jAstVarDeclarator create(ISwc4jAstPat name, ISwc4jAstExpr init, boolean definite) {
return new Swc4jAstVarDeclarator(name, init, definite, Swc4jSpan.DUMMY);
}

@Override
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, ISwc4jAstStmt body) {
return new Swc4jAstWhileStmt(test, body, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public ISwc4jAstStmt getBody() {
return body;
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, ISwc4jAstStmt body) {
return new Swc4jAstWithStmt(obj, body, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public ISwc4jAstStmt getBody() {
return body;
Expand Down

0 comments on commit 9da6fe1

Please sign in to comment.