Skip to content

Commit

Permalink
✨ feat: Add create() v8
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 31, 2024
1 parent 634d4f0 commit b31272a
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public Swc4jAstImportDefaultSpecifier(
setLocal(local);
}

public static Swc4jAstImportDefaultSpecifier create(Swc4jAstIdent local) {
return new Swc4jAstImportDefaultSpecifier(local, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(local);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ public Swc4jAstImportNamedSpecifier(
setTypeOnly(typeOnly);
}

public static Swc4jAstImportNamedSpecifier create(Swc4jAstIdent local) {
return create(local, null);
}

public static Swc4jAstImportNamedSpecifier create(
Swc4jAstIdent local,
ISwc4jAstModuleExportName imported) {
return create(local, imported, false);
}

public static Swc4jAstImportNamedSpecifier create(
Swc4jAstIdent local,
ISwc4jAstModuleExportName imported,
boolean typeOnly) {
return new Swc4jAstImportNamedSpecifier(local, imported, typeOnly, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.of(local);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public Swc4jAstImportStarAsSpecifier(
setLocal(local);
}

public static Swc4jAstImportStarAsSpecifier create(Swc4jAstIdent local) {
return new Swc4jAstImportStarAsSpecifier(local, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(local);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ public Swc4jAstNamedExport(
this.specifiers.forEach(node -> node.setParent(this));
}

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

public static Swc4jAstNamedExport create(List<ISwc4jAstExportSpecifier> specifiers) {
return create(specifiers, null);
}

public static Swc4jAstNamedExport create(List<ISwc4jAstExportSpecifier> specifiers, Swc4jAstStr src) {
return create(specifiers, src, false);
}

public static Swc4jAstNamedExport create(
List<ISwc4jAstExportSpecifier> specifiers,
Swc4jAstStr src,
boolean typeOnly) {
return create(specifiers, src, typeOnly, null);
}

public static Swc4jAstNamedExport create(
List<ISwc4jAstExportSpecifier> specifiers,
Swc4jAstStr src,
boolean typeOnly,
Swc4jAstObjectLit with) {
return new Swc4jAstNamedExport(specifiers, src, typeOnly, with, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(specifiers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public Swc4jAstTsExportAssignment(
setExpr(expr);
}

public static Swc4jAstTsExportAssignment create(ISwc4jAstExpr expr) {
return new Swc4jAstTsExportAssignment(expr, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(expr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public Swc4jAstTsExternalModuleRef(
setExpr(expr);
}

public static Swc4jAstTsExternalModuleRef create(Swc4jAstStr expr) {
return new Swc4jAstTsExternalModuleRef(expr, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(expr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ public Swc4jAstTsImportEqualsDecl(
setTypeOnly(typeOnly);
}

public static Swc4jAstTsImportEqualsDecl create(
Swc4jAstIdent id,
ISwc4jAstTsModuleRef moduleRef) {
return create(false, id, moduleRef);
}

public static Swc4jAstTsImportEqualsDecl create(
boolean export,
Swc4jAstIdent id,
ISwc4jAstTsModuleRef moduleRef) {
return create(export, false, id, moduleRef);
}

public static Swc4jAstTsImportEqualsDecl create(
boolean export,
boolean typeOnly,
Swc4jAstIdent id,
ISwc4jAstTsModuleRef moduleRef) {
return new Swc4jAstTsImportEqualsDecl(export, typeOnly, id, moduleRef, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(id, moduleRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public Swc4jAstTsModuleBlock(
this.body.forEach(node -> node.setParent(this));
}

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

public static Swc4jAstTsModuleBlock create(List<ISwc4jAstModuleItem> body) {
return new Swc4jAstTsModuleBlock(body, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public List<ISwc4jAstModuleItem> getBody() {
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ public Swc4jAstTsNamespaceDecl(
setId(id);
}

public static Swc4jAstTsNamespaceDecl create(
Swc4jAstIdent id,
ISwc4jAstTsNamespaceBody body) {
return create(false, id, body);
}

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

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

@Jni2RustMethod
public ISwc4jAstTsNamespaceBody getBody() {
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public Swc4jAstTsNamespaceExportDecl(
setId(id);
}

public static Swc4jAstTsNamespaceExportDecl create(Swc4jAstIdent id) {
return new Swc4jAstTsNamespaceExportDecl(id, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(id);
Expand Down

0 comments on commit b31272a

Please sign in to comment.