Skip to content

Commit

Permalink
✨ feat: Add create() v6
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 30, 2024
1 parent c2d6ae7 commit fb89255
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public Swc4jAstCatchClause(
setParam(param);
}

public static Swc4jAstCatchClause create(Swc4jAstBlockStmt body) {
return create(null, body);
}

public static Swc4jAstCatchClause create(ISwc4jAstPat param, Swc4jAstBlockStmt body) {
return new Swc4jAstCatchClause(param, body, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public Swc4jAstBlockStmt getBody() {
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public Swc4jAstJsxAttr(
setValue(value);
}

public static Swc4jAstJsxAttr create(ISwc4jAstJsxAttrName name) {
return create(name, null);
}

public static Swc4jAstJsxAttr create(ISwc4jAstJsxAttrName name, ISwc4jAstJsxAttrValue value) {
return new Swc4jAstJsxAttr(name, value, Swc4jSpan.DUMMY);
}

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

public static Swc4jAstJsxClosingElement create(ISwc4jAstJsxElementName name) {
return new Swc4jAstJsxClosingElement(name, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return SimpleList.of(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public Swc4jAstJsxClosingFragment(
super(span);
}

public static Swc4jAstJsxClosingFragment create() {
return new Swc4jAstJsxClosingFragment(Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return EMPTY_CHILD_NODES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ public Swc4jAstJsxOpeningElement(
this.attrs.forEach(node -> node.setParent(this));
}

public static Swc4jAstJsxOpeningElement create(ISwc4jAstJsxElementName name) {
return create(name, SimpleList.of());
}

public static Swc4jAstJsxOpeningElement create(
ISwc4jAstJsxElementName name,
List<ISwc4jAstJsxAttrOrSpread> attrs) {
return create(name, attrs, false);
}

public static Swc4jAstJsxOpeningElement create(
ISwc4jAstJsxElementName name,
List<ISwc4jAstJsxAttrOrSpread> attrs,
boolean selfClosing) {
return create(name, attrs, selfClosing, null);
}

public static Swc4jAstJsxOpeningElement create(
ISwc4jAstJsxElementName name,
List<ISwc4jAstJsxAttrOrSpread> attrs,
boolean selfClosing,
Swc4jAstTsTypeParamInstantiation typeArgs) {
return new Swc4jAstJsxOpeningElement(name, attrs, selfClosing, typeArgs, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public List<ISwc4jAstJsxAttrOrSpread> getAttrs() {
return attrs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public Swc4jAstJsxOpeningFragment(
super(span);
}

public static Swc4jAstJsxOpeningFragment create() {
return new Swc4jAstJsxOpeningFragment(Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return EMPTY_CHILD_NODES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Swc4jAstOptCall
protected ISwc4jAstExpr callee;
@Jni2RustField(componentBox = true)
protected Optional<Swc4jAstTsTypeParamInstantiation> typeArgs;

@Jni2RustMethod
public Swc4jAstOptCall(
ISwc4jAstExpr callee,
Expand All @@ -55,6 +56,21 @@ public Swc4jAstOptCall(
this.args.forEach(node -> node.setParent(this));
}

public static Swc4jAstOptCall create(ISwc4jAstExpr callee) {
return create(callee, SimpleList.of());
}

public static Swc4jAstOptCall create(ISwc4jAstExpr callee, List<Swc4jAstExprOrSpread> args) {
return create(callee, args, null);
}

public static Swc4jAstOptCall create(
ISwc4jAstExpr callee,
List<Swc4jAstExprOrSpread> args,
Swc4jAstTsTypeParamInstantiation typeArgs) {
return new Swc4jAstOptCall(callee, args, typeArgs, Swc4jSpan.DUMMY);
}

@Jni2RustMethod
public List<Swc4jAstExprOrSpread> getArgs() {
return args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public Swc4jAstSwitchCase(
this.cons.forEach(node -> node.setParent(this));
}

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

public static Swc4jAstSwitchCase create(ISwc4jAstExpr test) {
return create(test, SimpleList.of());
}

public static Swc4jAstSwitchCase create(ISwc4jAstExpr test, List<ISwc4jAstStmt> cons) {
return new Swc4jAstSwitchCase(test, cons, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
List<ISwc4jAst> childNodes = SimpleList.copyOf(cons);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public Swc4jAstTplElement(
setTail(tail);
}

public static Swc4jAstTplElement create(boolean tail, String raw) {
return create(tail, null, raw);
}

public static Swc4jAstTplElement create(boolean tail, String cooked, String raw) {
return new Swc4jAstTplElement(tail, cooked, raw, Swc4jSpan.DUMMY);
}

@Override
public List<ISwc4jAst> getChildNodes() {
return EMPTY_CHILD_NODES;
Expand Down

0 comments on commit fb89255

Please sign in to comment.