Skip to content

Commit

Permalink
fix: decompile jsx after unpacking the bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Jan 13, 2024
1 parent de98b60 commit cd26c95
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
22 changes: 7 additions & 15 deletions packages/webcrack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,15 @@ export async function webcrack(
}),
options.mangle && (() => applyTransform(ast, mangle)),
// TODO: Also merge unminify visitor (breaks selfDefending/debugProtection atm)
(options.deobfuscate || options.jsx) &&
(() => {
return applyTransforms(
ast,
[
// Have to run this after unminify to properly detect it
options.deobfuscate ? [selfDefending, debugProtection] : [],
options.jsx ? [jsx, jsxNew] : [],
].flat(),
{ noScope: true },
);
}),
options.deobfuscate &&
(() =>
applyTransforms(ast, [selfDefending, debugProtection], {
noScope: true,
})),
options.deobfuscate && (() => applyTransform(ast, mergeObjectAssignments)),
() => (outputCode = generate(ast)),
// Unpacking modifies the same AST and may result in imports not at top level
// so the code has to be generated before
options.unpack && (() => (bundle = unpackAST(ast, options.mappings(m)))),
options.jsx && (() => applyTransforms(ast, [jsx, jsxNew])),
() => (outputCode = generate(ast)),
].filter(Boolean) as (() => unknown)[];

for (let i = 0; i < stages.length; i++) {
Expand Down
10 changes: 10 additions & 0 deletions packages/webcrack/src/unpack/test/samples/webpack-jsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(window['webpackJsonp'] = window['webpackJsonp'] || []).push([
[1],
[function (module, exports, __webpack_require__) {
__webpack_require__.r(exports);
var r = __webpack_require__(35250);
function f() {
return (0, r.jsx)("p", {});
}
}],
]);
34 changes: 34 additions & 0 deletions packages/webcrack/src/unpack/test/samples/webpack-jsx.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
WebpackBundle {
"chunks": [
WebpackChunk {
"chunkIds": [
"1",
],
"entryIds": [],
"modules": Map {
"0" => WebpackModule {
"ast": import { jsx } from "35250";
function f() {
return <p />;
},
"id": "0",
"isEntry": false,
"path": "0.js",
},
},
},
],
"entryId": "",
"modules": Map {
"0" => WebpackModule {
"ast": import { jsx } from "35250";
function f() {
return <p />;
},
"id": "0",
"isEntry": false,
"path": "0.js",
},
},
"type": "webpack",
}

0 comments on commit cd26c95

Please sign in to comment.