8000 Fix bug #360: No Global variable renaming after 2 import declarations by zamotkin · Pull Request #485 · javascript-obfuscator/javascript-obfuscator · GitHub
[go: up one dir, main page]

Skip to content

Fix bug #360: No Global variable renaming after 2 import declarations #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export class ImportDeclarationTransformer extends AbstractNodeTransformer {
.replace(replaceableIdentifier.name, lexicalScopeNode);

replaceableIdentifier.name = newReplaceableIdentifier.name;
NodeMetadata.set(replaceableIdentifier, { renamedIdentifier: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to wrap this line and the line above in the condition

if (replaceableIdentifier.name !== newReplaceableIdentifier.name) {
                replaceableIdentifier.name = newReplaceableIdentifier.name;
                NodeMetadata.set(replaceableIdentifier, { renamedIdentifier: true });
            }

});
}

Expand Down
3 changes: 3 additions & 0 deletions test/functional-tests/issues/fixtures/issue360.js
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ok1 from 'lib1';
import ok2 from 'lib2';
let test = null;
33 changes: 33 additions & 0 deletions test/functional-tests/issues/issue360.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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/360
//
describe('Issue #360', () => {
describe('Correct renaming globals after two imports', () => {
const codeResult: string = 'import c from\'lib1\';import d from\'lib2\';let e=null;';

let obfuscatedCode: string;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/issue360.js');

obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
compact: true,
renameGlobals: true,
identifierNamesGenerator: 'mangled'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to keep the default hexadecimal generator here

}
).getObfuscatedCode();
});

it('should return correct result', () => {
assert.equal(obfuscatedCode, codeResult);
});
});
});
1 change: 1 addition & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import './functional-tests/custom-nodes/string-array-nodes/StringArrayRotateFunc
import './functional-tests/custom-nodes/string-array-nodes/StringArrayNode.spec';
import './functional-tests/issues/issue321.spec';
import './functional-tests/issues/issue355.spec';
import './functional-tests/issues/issue360.spec';
import './functional-tests/issues/issue419.spec';
import './functional-tests/issues/issue424.spec';
import './functional-tests/issues/issue437.spec';
Expand Down
0