Skip to content

Commit

Permalink
fix: clone strings when inlining simple array
Browse files Browse the repository at this point in the history
previously it resulted in 2x `require(\"vm\")(\"8\")`
  • Loading branch information
j4k0xb committed Sep 20, 2024
1 parent a32252a commit c11a872
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/webcrack/src/ast-utils/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function inlineArrayElements(
const property = memberPath.node.property as t.NumericLiteral;
const index = property.value;
const replacement = array.elements[index]!;
memberPath.replaceWith(replacement);
memberPath.replaceWith(t.cloneNode(replacement));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ console[arr[0]](arr[1]);
// ignore mutable array
const arr2 = ['log', 'Hello, World!'];
arr2[0] = 'warn';
console[arr2[0]](arr2[1]);
console[arr2[0]](arr2[1]);

const arr3 = ["requ", "m", "0x2649a392", "ire", "8", "v"];
const vm = eval(arr3[0] + arr3[3] + "(\"" + arr3[5] + "" + arr3[1] + "\")");
const v8 = eval(arr3[0] + arr3[3] + "(\"" + arr3[5] + "" + arr3[4] + "\")");
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ console.log("Hello, World!");
// ignore mutable array
const arr2 = ["log", "Hello, World!"];
arr2[0] = "warn";
console[arr2[0]](arr2[1]);
console[arr2[0]](arr2[1]);
const vm = eval("require(\"vm\")");
const v8 = eval("require(\"v8\")");

0 comments on commit c11a872

Please sign in to comment.