Skip to content

Commit 622c329

Browse files
committed
Small fix for Moved Declarations
1 parent 0b8575a commit 622c329

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/transforms/identifier/movedDeclarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default class MovedDeclarations extends Transform {
6666
var assignmentExpression = AssignmentExpression(
6767
"=",
6868
Identifier(varName),
69-
object.declarations[0].init || Identifier("undefined")
69+
object.declarations[0].init || Identifier(varName)
7070
);
7171

7272
if (forInitializeType) {

test/transforms/identifier/movedDeclarations.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,31 @@ test("Variant #8: Work with 'use strict'", async () => {
184184

185185
expect(TEST_OUTPUT).toStrictEqual(true);
186186
});
187+
188+
test("Variant #9: Defined variable without an initializer", async () => {
189+
var code = `
190+
var x;
191+
x = 1;
192+
var y;
193+
y = 2;
194+
TEST_OUTPUT = x + y;
195+
`;
196+
197+
var output1 = await JsConfuser(code, {
198+
target: "node",
199+
movedDeclarations: true,
200+
controlFlowFlattening: true,
201+
duplicateLiteralsRemoval: true,
202+
});
203+
204+
var output2 = await JsConfuser(output1, {
205+
target: "node",
206+
movedDeclarations: true,
207+
controlFlowFlattening: true,
208+
duplicateLiteralsRemoval: true,
209+
});
210+
211+
var TEST_OUTPUT;
212+
eval(output2);
213+
expect(TEST_OUTPUT).toStrictEqual(3);
214+
});

0 commit comments

Comments
 (0)