mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed transformObjectKeys with mangled identifier generator causing variable shadowing when extracted object variable name matched an existing inner scope variable
This commit is contained in:
@@ -0,0 +1 @@
|
||||
[].forEach(a => a === { a: 1 });
|
||||
@@ -0,0 +1,32 @@
|
||||
import { assert } from 'chai';
|
||||
import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes';
|
||||
import { readFileAsString } from '../../helpers/readFileAsString';
|
||||
import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade';
|
||||
|
||||
//
|
||||
// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1232
|
||||
//
|
||||
describe('Issue #1232', () => {
|
||||
describe('transformObjectKeys should not cause variable shadowing with mangled identifiers', () => {
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/issue1232.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(code, {
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
identifierNamesGenerator: 'mangled',
|
||||
transformObjectKeys: true
|
||||
}).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should not rename extracted object variable to same name as function parameter', () => {
|
||||
const shadowingPattern = /(\w+)\s*===\s*\1[)\s;,]/;
|
||||
|
||||
assert.isFalse(
|
||||
shadowingPattern.test(obfuscatedCode),
|
||||
`Variable shadowing detected in obfuscated code: ${obfuscatedCode}`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user