Skip to content

Commit

Permalink
✨ feat: Support nested minus expression
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Nov 4, 2024
1 parent cccaa21 commit 644517f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public TypeDescription manipulate(JavaFunctionContext functionContext, Swc4jAstU
return new Ts2JavaAstNumber()
.setNegative(true)
.manipulate(functionContext, arg.as(Swc4jAstNumber.class));
case UnaryExpr:
returnType = new Ts2JavaAstUnaryExpr()
.manipulate(functionContext, arg.as(Swc4jAstUnaryExpr.class));
break;
default:
throw new Ts2JavaAstException(
arg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public final class JavaFunctionContext {
private int nextOffset;

public JavaFunctionContext(boolean _static, TypeDescription returnType) {
this._static = _static;
bangCount = 0;
nextOffset = _static ? 0 : 1;
maxOffset = nextOffset;
this.lexicalScopes = SimpleList.of(new JavaLexicalScope(0));
logicalDepth = 0;
logicalLabels = new JavaLogicalLabels();
maxOffset = nextOffset;
nextOffset = _static ? 0 : 1;
this._static = _static;
this.lexicalScopes = SimpleList.of(new JavaLexicalScope(0));
this.returnType = Objects.requireNonNull(returnType);
this.stackManipulations = new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ public void testMinus_II_I() throws Exception {
assertEquals(-5, tsClass.invoke(3, 2));
}

@Test
public void testMinus_I_I() throws Exception {
TsClass tsClass = new TsClass(
"return -(a + (-1));",
int.class,
TsMethodArgument.of("a", int.class));
assertEquals(-2, tsClass.invoke(3));
}

@Test
public void testMinus_Minus_II_I() throws Exception {
TsClass tsClass = new TsClass(
"return -(-(a + b));",
int.class,
TsMethodArgument.of("a", int.class),
TsMethodArgument.of("b", int.class));
assertEquals(5, tsClass.invoke(3, 2));
}

@Test
public void testMod_II_I() throws Exception {
TsClass tsClass = new TsClass(
Expand Down

0 comments on commit 644517f

Please sign in to comment.