mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed SyntaxError when obfuscating a class that extends a boolean literal (#1420)
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v5.4.5
|
||||
---
|
||||
* Fixed `SyntaxError` when obfuscating a class that extends a boolean literal (e.g. `class C extends true {}`). Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1131
|
||||
|
||||
v5.4.4
|
||||
---
|
||||
* Fixed `Invalid regular expression` error when obfuscating code that uses ES2025 RegExp pattern modifiers (e.g. `/(?i:abc)/`). Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1410
|
||||
|
||||
@@ -66,6 +66,15 @@ export class BooleanLiteralTransformer extends AbstractNodeTransformer {
|
||||
return literalNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class heritage (`extends`) must be a `LeftHandSideExpression`, so replacing a
|
||||
* boolean literal there with a unary expression (`class Foo extends ![] {}`) would
|
||||
* produce a `SyntaxError`. Keep the original literal in that position.
|
||||
*/
|
||||
if ('superClass' in parentNode && parentNode.superClass === literalNode) {
|
||||
return literalNode;
|
||||
}
|
||||
|
||||
const literalValue: ESTree.SimpleLiteral['value'] = literalNode.value;
|
||||
|
||||
const unaryExpressionNode: ESTree.UnaryExpression = literalValue
|
||||
|
||||
+18
@@ -46,4 +46,22 @@ describe('BooleanLiteralTransformer', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('boolean literal as a class super class', () => {
|
||||
const regExp: RegExp = /^class Foo extends true *{}$/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/super-class-value.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(code, {
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should not transform a boolean literal used as a class heritage to avoid a `SyntaxError`', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
class Foo extends true {}
|
||||
Reference in New Issue
Block a user