Skip to content

Commit

Permalink
🦄 refactor: Simplify bin expr for jsfuck decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 16, 2024
1 parent 986825e commit e27b2a3
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,20 @@ public Swc4jAstVisitorResponse visitBinExpr(Swc4jAstBinExpr node) {
(leftType == Swc4jAstType.Bool && rightType == Swc4jAstType.Bool) ||
(leftType == Swc4jAstType.Number && rightType == Swc4jAstType.Bool) ||
(leftType == Swc4jAstType.Number && rightType == Swc4jAstType.Number)) {
double value = left.as(ISwc4jAstCoercionPrimitive.class).asDouble() + right.as(ISwc4jAstCoercionPrimitive.class).asDouble();
double value = left.as(ISwc4jAstCoercionPrimitive.class).asDouble()
+ right.as(ISwc4jAstCoercionPrimitive.class).asDouble();
newNode = Swc4jAstNumber.create(value);
} else if ((leftType == Swc4jAstType.Bool && rightType == Swc4jAstType.ArrayLit) ||
(leftType == Swc4jAstType.ArrayLit && rightType == Swc4jAstType.Bool) ||
(leftType == Swc4jAstType.ArrayLit && rightType == Swc4jAstType.ArrayLit) ||
(leftType == Swc4jAstType.Str && rightType == Swc4jAstType.ArrayLit) ||
(leftType == Swc4jAstType.ArrayLit && rightType == Swc4jAstType.Str) ||
(leftType == Swc4jAstType.Str && rightType == Swc4jAstType.Str)) {
String value = left.as(ISwc4jAstCoercionPrimitive.class).asString() + right.as(ISwc4jAstCoercionPrimitive.class).asString();
newNode = Swc4jAstStr.create(value);
} else if ((leftType == Swc4jAstType.Str && rightType == Swc4jAstType.Number) ||
(leftType == Swc4jAstType.ArrayLit && rightType == Swc4jAstType.Number)) {
String value = left.as(ISwc4jAstCoercionPrimitive.class).asString()
+ right.as(Swc4jAstNumber.class).asString();
newNode = Swc4jAstStr.create(value);
} else if ((leftType == Swc4jAstType.Number && rightType == Swc4jAstType.Str) ||
(leftType == Swc4jAstType.Str && rightType == Swc4jAstType.Str) ||
(leftType == Swc4jAstType.Str && rightType == Swc4jAstType.Number) ||
(leftType == Swc4jAstType.ArrayLit && rightType == Swc4jAstType.Number) ||
(leftType == Swc4jAstType.Number && rightType == Swc4jAstType.Str) ||
(leftType == Swc4jAstType.Number && rightType == Swc4jAstType.ArrayLit)) {
String value = left.as(Swc4jAstNumber.class).asString()
String value = left.as(ISwc4jAstCoercionPrimitive.class).asString()
+ right.as(ISwc4jAstCoercionPrimitive.class).asString();
newNode = Swc4jAstStr.create(value);
}
Expand Down

0 comments on commit e27b2a3

Please sign in to comment.