mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed wrong generation of code that has statements after ReturnStatment when simplify option is enabled
This commit is contained in:
Vendored
-4
@@ -54,8 +54,4 @@ declare module 'estree' {
|
||||
metadata?: LiteralNodeMetadata;
|
||||
'x-verbatim-property'?: escodegen.XVerbatimProperty;
|
||||
}
|
||||
|
||||
interface StaticBlock extends Omit<BlockStatement, 'type'> {
|
||||
type: 'StaticBlock'
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -15,4 +15,9 @@ export interface IIteratedStatementsSimplifyData {
|
||||
* @type {boolean}
|
||||
*/
|
||||
hasReturnStatement: boolean;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
hasStatementsAfterReturnStatement: boolean;
|
||||
}
|
||||
|
||||
+15
-2
@@ -63,9 +63,19 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT
|
||||
const {
|
||||
startIndex,
|
||||
unwrappedExpressions,
|
||||
hasReturnStatement
|
||||
hasReturnStatement,
|
||||
hasStatementsAfterReturnStatement
|
||||
} = this.collectIteratedStatementsSimplifyData(statementNode);
|
||||
|
||||
if (hasStatementsAfterReturnStatement) {
|
||||
return {
|
||||
leadingStatements: statementNode.body,
|
||||
trailingStatement: null,
|
||||
hasReturnStatement: false,
|
||||
hasSingleExpression: false
|
||||
};
|
||||
}
|
||||
|
||||
const leadingStatements: ESTree.Statement[] = this.getLeadingStatements(statementNode, startIndex);
|
||||
|
||||
if (!unwrappedExpressions.length) {
|
||||
@@ -111,6 +121,7 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT
|
||||
const unwrappedExpressions: ESTree.Expression[] = [];
|
||||
|
||||
let hasReturnStatement: boolean = false;
|
||||
let hasStatementsAfterReturnStatement: boolean = false;
|
||||
let startIndex: number | null = null;
|
||||
|
||||
for (let i = statementNodeBodyLength - 1; i >= 0; i--) {
|
||||
@@ -133,6 +144,7 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT
|
||||
) {
|
||||
unwrappedExpressions.unshift(statementBodyStatementNode.argument);
|
||||
hasReturnStatement = true;
|
||||
hasStatementsAfterReturnStatement = i !== statementNodeBodyLength - 1;
|
||||
startIndex = i;
|
||||
continue;
|
||||
}
|
||||
@@ -143,7 +155,8 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT
|
||||
return {
|
||||
startIndex,
|
||||
unwrappedExpressions,
|
||||
hasReturnStatement
|
||||
hasReturnStatement,
|
||||
hasStatementsAfterReturnStatement
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -507,10 +507,8 @@ export class NodeGuards {
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
// TODO: add type guard after @types/estree update
|
||||
public static isStaticBlockNode (node: ESTree.Node): boolean {
|
||||
// TODO: Update @types/estree
|
||||
return (<any>node).type === NodeType.StaticBlock;
|
||||
public static isStaticBlockNode (node: ESTree.Node): node is ESTree.StaticBlock {
|
||||
return node.type === NodeType.StaticBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user