mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed invalid code generation for rest arguments when controlFlowFlattening option is enabled
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/887
This commit is contained in:
@@ -15,6 +15,7 @@ import { initializable } from '../../decorators/Initializable';
|
||||
import { AbstractCustomNode } from '../AbstractCustomNode';
|
||||
import { NodeFactory } from '../../node/NodeFactory';
|
||||
import { NodeUtils } from '../../node/NodeUtils';
|
||||
import { NodeGuards } from '../../node/NodeGuards';
|
||||
|
||||
@injectable()
|
||||
export class CallExpressionFunctionNode extends AbstractCustomNode {
|
||||
@@ -57,11 +58,26 @@ export class CallExpressionFunctionNode extends AbstractCustomNode {
|
||||
*/
|
||||
protected getNodeStructure (): TStatement[] {
|
||||
const calleeIdentifier: ESTree.Identifier = NodeFactory.identifierNode('callee');
|
||||
const params: ESTree.Identifier[] = [];
|
||||
const params: (ESTree.Identifier | ESTree.RestElement)[] = [];
|
||||
const callArguments: (ESTree.Identifier | ESTree.SpreadElement)[] = [];
|
||||
const argumentsLength: number = this.expressionArguments.length;
|
||||
|
||||
for (let i: number = 0; i < argumentsLength; i++) {
|
||||
params.push(NodeFactory.identifierNode(`param${i + 1}`));
|
||||
const argument: ESTree.Expression | ESTree.SpreadElement = this.expressionArguments[i];
|
||||
const isSpreadCallArgument: boolean = NodeGuards.isSpreadElementNode(argument);
|
||||
|
||||
const baseIdentifierNode: ESTree.Identifier = NodeFactory.identifierNode(`param${i + 1}`);
|
||||
|
||||
params.push(
|
||||
isSpreadCallArgument
|
||||
? NodeFactory.restElementNode(baseIdentifierNode)
|
||||
: baseIdentifierNode
|
||||
);
|
||||
callArguments.push(
|
||||
isSpreadCallArgument
|
||||
? NodeFactory.spreadElementNode(baseIdentifierNode)
|
||||
: baseIdentifierNode
|
||||
);
|
||||
}
|
||||
|
||||
const structure: TStatement = NodeFactory.expressionStatementNode(
|
||||
@@ -74,7 +90,7 @@ export class CallExpressionFunctionNode extends AbstractCustomNode {
|
||||
NodeFactory.returnStatementNode(
|
||||
NodeFactory.callExpressionNode(
|
||||
calleeIdentifier,
|
||||
params
|
||||
callArguments
|
||||
)
|
||||
)
|
||||
])
|
||||
|
||||
+25
-1
@@ -317,7 +317,7 @@ export class NodeFactory {
|
||||
* @returns {FunctionExpression}
|
||||
*/
|
||||
public static functionExpressionNode (
|
||||
params: ESTree.Identifier[],
|
||||
params: ESTree.Pattern[],
|
||||
body: ESTree.BlockStatement
|
||||
): ESTree.FunctionExpression {
|
||||
return {
|
||||
@@ -493,6 +493,18 @@ export class NodeFactory {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Pattern} argument
|
||||
* @returns {SpreadElement}
|
||||
*/
|
||||
public static restElementNode (argument: ESTree.Pattern): ESTree.RestElement {
|
||||
return {
|
||||
type: NodeType.RestElement,
|
||||
argument,
|
||||
metadata: { ignoredNode: false }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Expression} argument
|
||||
* @returns {ReturnStatement}
|
||||
@@ -517,6 +529,18 @@ export class NodeFactory {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Expression} argument
|
||||
* @returns {SpreadElement}
|
||||
*/
|
||||
public static spreadElementNode (argument: ESTree.Expression): ESTree.SpreadElement {
|
||||
return {
|
||||
type: NodeType.SpreadElement,
|
||||
argument,
|
||||
metadata: { ignoredNode: false }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Expression} discriminant
|
||||
* @param {SwitchCase[]} cases
|
||||
|
||||
Reference in New Issue
Block a user