mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Support for class static blocks
This commit is contained in:
Vendored
+5
@@ -3,6 +3,7 @@
|
||||
import * as acorn from 'acorn';
|
||||
import * as escodegen from '@javascript-obfuscator/escodegen';
|
||||
import * as eslintScope from 'eslint-scope';
|
||||
import { BlockStatement } from 'estree';
|
||||
|
||||
declare module 'estree' {
|
||||
/**
|
||||
@@ -53,4 +54,8 @@ declare module 'estree' {
|
||||
metadata?: LiteralNodeMetadata;
|
||||
'x-verbatim-property'?: escodegen.XVerbatimProperty;
|
||||
}
|
||||
|
||||
interface StaticBlock extends Omit<BlockStatement, 'type'> {
|
||||
type: 'StaticBlock'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ export enum NodeType {
|
||||
ReturnStatement = 'ReturnStatement',
|
||||
SequenceExpression = 'SequenceExpression',
|
||||
SpreadElement = 'SpreadElement',
|
||||
StaticBlock = 'StaticBlock',
|
||||
Super = 'Super',
|
||||
SwitchCase = 'SwitchCase',
|
||||
SwitchStatement = 'SwitchStatement',
|
||||
|
||||
@@ -544,6 +544,18 @@ export class NodeFactory {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Statement[]} body
|
||||
* @returns {StaticBlock}
|
||||
*/
|
||||
public static staticBlockNode (body: ESTree.Statement[] = []): ESTree.StaticBlock {
|
||||
return {
|
||||
type: NodeType.StaticBlock,
|
||||
body,
|
||||
metadata: { ignoredNode: false }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Expression} discriminant
|
||||
* @param {SwitchCase[]} cases
|
||||
|
||||
+14
-1
@@ -365,7 +365,9 @@ export class NodeGuards {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isNodeWithBlockLexicalScope (node: ESTree.Node): node is TNodeWithLexicalScope {
|
||||
return NodeGuards.isNodeWithLexicalScope(node) || NodeGuards.isBlockStatementNode(node);
|
||||
return NodeGuards.isNodeWithLexicalScope(node)
|
||||
|| NodeGuards.isBlockStatementNode(node)
|
||||
|| NodeGuards.isStaticBlockNode(node);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,6 +419,7 @@ export class NodeGuards {
|
||||
public static isNodeWithStatements (node: ESTree.Node): node is TNodeWithStatements {
|
||||
return NodeGuards.isProgramNode(node)
|
||||
|| NodeGuards.isBlockStatementNode(node)
|
||||
|| NodeGuards.isStaticBlockNode(node)
|
||||
|| NodeGuards.isSwitchCaseNode(node);
|
||||
}
|
||||
|
||||
@@ -500,6 +503,16 @@ export class NodeGuards {
|
||||
return node.type === NodeType.SpreadElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
|
||||
Reference in New Issue
Block a user