Skip to content

Commit 3d6e345

Browse files
committed
Fix #103
1 parent 1ecd311 commit 3d6e345

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/transforms/dispatcher.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ export default class Dispatcher extends Transform {
157157
return "EXIT";
158158
}
159159
}
160+
161+
// Avoid functions with function expressions as they have a different scope
162+
if (
163+
(oo.type === "FunctionExpression" ||
164+
oo.type === "ArrowFunctionExpression") &&
165+
pp.find((x) => x == o.params)
166+
) {
167+
illegalFnNames.add(name);
168+
return "EXIT";
169+
}
160170
});
161171

162172
functionDeclarations[name] = [o, p];

test/transforms/dispatcher.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,30 @@ test("Variant #16: Don't change functions that use 'eval'", async () => {
373373

374374
expect(TEST_OUTPUT).toStrictEqual(2);
375375
});
376+
377+
// https://github.com/MichaelXF/js-confuser/issues/103
378+
test("Variant #17: Don't break default parameter, function expression", async () => {
379+
var output = await JsConfuser(
380+
`
381+
var X = "Correct Value";
382+
383+
function printX(
384+
getX = function () {
385+
return X;
386+
}
387+
) {
388+
var X = "Incorrect Value";
389+
390+
TEST_OUTPUT = getX();
391+
}
392+
393+
printX();
394+
`,
395+
{ target: "node", dispatcher: true }
396+
);
397+
398+
var TEST_OUTPUT;
399+
eval(output);
400+
401+
expect(TEST_OUTPUT).toStrictEqual("Correct Value");
402+
});

0 commit comments

Comments
 (0)