Skip to content

Commit

Permalink
Fix #45
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelXF committed Dec 24, 2022
1 parent 47e908e commit 39156df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transforms/opaquePredicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ export default class OpaquePredicates extends Transform {
}

var cloned = clone(expr);
if (object.type == "SwitchCase") {
var matching = Identifier(choice(["undefined", "null"]));
if (object.type == "SwitchCase" && object.test) {
var matching: Node = Identifier(choice(["undefined", "null"]));

var test = object.test;

Expand Down
25 changes: 25 additions & 0 deletions test/transforms/opaquePredicates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,28 @@ it("should append logical expressions", async () => {

expect(output).not.toContain("(test)");
});

// https://github.com/MichaelXF/js-confuser/issues/45
it("should work on default Switch cases", async ()=>{
var code = `
switch (0) {
default:
input(true);
}
`;

var output = await JsConfuser(code, {
target: "browser",
opaquePredicates: true,
});

var value;
function input(valueIn){
value = valueIn;
}

eval(output);

expect(value).toStrictEqual(true);
})

0 comments on commit 39156df

Please sign in to comment.