Skip to content

Commit

Permalink
feat: simplify computed property with only literals
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Jun 13, 2024
1 parent c1fa1d6 commit 5f4ab54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/webcrack/src/unminify/test/sequence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,9 @@ test('rearrange assignment', () => {
}
`);
});

// appears in some obfuscator.io forks
test('simplify computed property with only literals', () =>
expectJS(`
Lr[("nnQB", "jcIgN")]();
`).toMatchInlineSnapshot('Lr["jcIgN"]();'));
9 changes: 9 additions & 0 deletions packages/webcrack/src/unminify/transforms/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ export default {
this.changes++;
},
},
MemberExpression: {
exit(path) {
const { property } = path.node;
if (m.sequenceExpression(m.arrayOf(safeLiteral)).match(property)) {
path.get('property').replaceWith(property.expressions.pop()!);
this.changes++;
}
},
},
};
},
} satisfies Transform;

0 comments on commit 5f4ab54

Please sign in to comment.