mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #572 from javascript-obfuscator/issue-569
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/569
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v0.25.4
|
||||
---
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/569
|
||||
|
||||
v0.25.3
|
||||
---
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/568
|
||||
|
||||
Vendored
+5
-5
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "0.25.3",
|
||||
"version": "0.25.4",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
|
||||
@@ -49,8 +49,8 @@ export class ScopeAnalyzer implements IScopeAnalyzer {
|
||||
enter: (node: ESTree.Node): ESTree.Node => {
|
||||
if (!node.range) {
|
||||
node.range = [
|
||||
ScopeAnalyzer.emptyRangeValue,
|
||||
ScopeAnalyzer.emptyRangeValue
|
||||
node.parentNode?.range?.[0] ?? ScopeAnalyzer.emptyRangeValue,
|
||||
node.parentNode?.range?.[1] ?? ScopeAnalyzer.emptyRangeValue
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -11,6 +11,7 @@ import { NodeAppender } from '../../../node/NodeAppender';
|
||||
import { NodeFactory } from '../../../node/NodeFactory';
|
||||
import { NodeGuards } from '../../../node/NodeGuards';
|
||||
import { NodeStatementUtils } from '../../../node/NodeStatementUtils';
|
||||
import { NodeUtils } from '../../../node/NodeUtils';
|
||||
|
||||
@injectable()
|
||||
export class BasePropertiesExtractor implements IObjectExpressionExtractor {
|
||||
@@ -110,6 +111,7 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor {
|
||||
|
||||
this.filterExtractedObjectExpressionProperties(objectExpressionNode, removablePropertyIds);
|
||||
NodeAppender.insertAfter(hostNodeWithStatements, expressionStatements, hostStatement);
|
||||
NodeUtils.parentizeAst(hostNodeWithStatements);
|
||||
|
||||
return {
|
||||
nodeToReplace: objectExpressionNode,
|
||||
|
||||
@@ -89,10 +89,16 @@ export class NodeUtils {
|
||||
* @returns {T}
|
||||
*/
|
||||
public static parentizeAst <T extends ESTree.Node = ESTree.Node> (astTree: T): T {
|
||||
const parentNode: ESTree.Node | null = astTree.parentNode ?? null;
|
||||
|
||||
estraverse.replace(astTree, {
|
||||
enter: NodeUtils.parentizeNode
|
||||
});
|
||||
|
||||
if (parentNode) {
|
||||
astTree.parentNode = parentNode;
|
||||
}
|
||||
|
||||
return astTree;
|
||||
}
|
||||
|
||||
|
||||
+4
-8
@@ -7,17 +7,13 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
(function(foo){
|
||||
function foo () {
|
||||
|
||||
}
|
||||
|
||||
return new foo();
|
||||
})();
|
||||
(function () {
|
||||
const foo = 'foo';
|
||||
const bar = { [foo]: 'bar' };
|
||||
})();
|
||||
`,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
identifierNamesGenerator: 'mangled',
|
||||
transformObjectKeys: true,
|
||||
compact: false
|
||||
}
|
||||
|
||||
+28
@@ -1792,5 +1792,33 @@ describe('ObjectExpressionKeysTransformer', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #10: computed property key name', () => {
|
||||
const match: string = `` +
|
||||
`const ${variableMatch} *= *'foo';` +
|
||||
`const ${variableMatch} *= *{};` +
|
||||
`${variableMatch}\\[${variableMatch}] *= *'bar';` +
|
||||
`const ${variableMatch} *= *${variableMatch};` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/computed-key-1.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should correctly generate name for the computed key identifier', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
(function () {
|
||||
const foo = 'foo';
|
||||
const bar = { [foo]: 'bar' };
|
||||
})();
|
||||
@@ -282,6 +282,29 @@ describe('NodeUtils', () => {
|
||||
assert.deepEqual(expressionStatementNode2.parentNode, ifStatementBlockStatementNode);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: parentize AST-tree and keep root node parent node', () => {
|
||||
beforeEach(() => {
|
||||
programNode = NodeFactory.programNode([
|
||||
ifStatementNode
|
||||
]);
|
||||
|
||||
ifStatementNode.parentNode = programNode;
|
||||
ifStatementNode = NodeUtils.parentizeAst(ifStatementNode);
|
||||
});
|
||||
|
||||
it('should parentize `ifStatement` node', () => {
|
||||
assert.deepEqual(ifStatementNode.parentNode, programNode);
|
||||
});
|
||||
|
||||
it('should parentize `ifStatement blockStatement` node', () => {
|
||||
assert.deepEqual(ifStatementBlockStatementNode.parentNode, ifStatementNode);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
ifStatementNode.parentNode = undefined;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('parentizeNode', () => {
|
||||
|
||||
Reference in New Issue
Block a user