mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Renamed ScopeIdentifiersTraverser methods, interfaces and types to more concrete variable traverse
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
import { TScopeIdentifiersTraverserCallback } from '../../types/node/TScopeIdentifiersTraverserCallback';
|
||||
import { TScopeIdentifiersTraverserVariableCallback } from '../../types/node/TScopeIdentifiersTraverserVariableCallback';
|
||||
|
||||
export interface IScopeIdentifiersTraverser {
|
||||
/**
|
||||
* @param {Program} programNode
|
||||
* @param {Node | null} parentNode
|
||||
* @param {TScopeIdentifiersTraverserCallback} callback
|
||||
* @param {TScopeIdentifiersTraverserVariableCallback} callback
|
||||
*/
|
||||
traverse (
|
||||
traverseScopeVariables (
|
||||
programNode: ESTree.Program,
|
||||
parentNode: ESTree.Node | null,
|
||||
callback: TScopeIdentifiersTraverserCallback
|
||||
callback: TScopeIdentifiersTraverserVariableCallback
|
||||
): void;
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import * as eslintScope from 'eslint-scope';
|
||||
|
||||
import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
|
||||
|
||||
export interface IScopeIdentifiersTraverserCallbackData {
|
||||
export interface IScopeIdentifiersTraverserVariableCallbackData {
|
||||
isGlobalDeclaration: boolean;
|
||||
isBubblingDeclaration: boolean;
|
||||
rootScope: eslintScope.Scope;
|
||||
@@ -12,7 +12,7 @@ import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transforme
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
||||
import { IScopeIdentifiersTraverser } from '../../interfaces/node/IScopeIdentifiersTraverser';
|
||||
import { IScopeIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserCallbackData';
|
||||
import { IScopeIdentifiersTraverserVariableCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserVariableCallbackData';
|
||||
import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
|
||||
|
||||
import { IdentifierObfuscatingReplacer } from '../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer';
|
||||
@@ -89,10 +89,10 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
|
||||
* @returns {NodeGuards}
|
||||
*/
|
||||
public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node {
|
||||
this.scopeIdentifiersTraverser.traverse(
|
||||
this.scopeIdentifiersTraverser.traverseScopeVariables(
|
||||
programNode,
|
||||
parentNode,
|
||||
(data: IScopeIdentifiersTraverserCallbackData) => {
|
||||
(data: IScopeIdentifiersTraverserVariableCallbackData) => {
|
||||
const {
|
||||
isGlobalDeclaration,
|
||||
variable,
|
||||
|
||||
@@ -9,7 +9,7 @@ import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transforme
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
||||
import { IScopeIdentifiersTraverser } from '../../interfaces/node/IScopeIdentifiersTraverser';
|
||||
import { IScopeIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserCallbackData';
|
||||
import { IScopeIdentifiersTraverserVariableCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserVariableCallbackData';
|
||||
import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
|
||||
|
||||
import { NodeTransformer } from '../../enums/node-transformers/NodeTransformer';
|
||||
@@ -93,7 +93,7 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer {
|
||||
* @returns {NodeGuards}
|
||||
*/
|
||||
public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node {
|
||||
this.scopeIdentifiersTraverser.traverse(
|
||||
this.scopeIdentifiersTraverser.traverseScopeVariables(
|
||||
programNode,
|
||||
parentNode,
|
||||
this.preserveScopeVariableIdentifiers
|
||||
@@ -103,9 +103,9 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {IScopeIdentifiersTraverserCallbackData} data
|
||||
* @param {IScopeIdentifiersTraverserVariableCallbackData} data
|
||||
*/
|
||||
private preserveScopeVariableIdentifiers (data: IScopeIdentifiersTraverserCallbackData): void {
|
||||
private preserveScopeVariableIdentifiers (data: IScopeIdentifiersTraverserVariableCallbackData): void {
|
||||
const {
|
||||
isGlobalDeclaration,
|
||||
isBubblingDeclaration,
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as eslintScope from 'eslint-scope';
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
import { TNodeWithLexicalScope } from '../types/node/TNodeWithLexicalScope';
|
||||
import { TScopeIdentifiersTraverserCallback } from '../types/node/TScopeIdentifiersTraverserCallback';
|
||||
import { TScopeIdentifiersTraverserVariableCallback } from '../types/node/TScopeIdentifiersTraverserVariableCallback';
|
||||
|
||||
import { IScopeAnalyzer } from '../interfaces/analyzers/scope-analyzer/IScopeAnalyzer';
|
||||
import { IScopeIdentifiersTraverser } from '../interfaces/node/IScopeIdentifiersTraverser';
|
||||
@@ -47,29 +47,29 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser {
|
||||
/**
|
||||
* @param {Program} programNode
|
||||
* @param {Node | null} parentNode
|
||||
* @param {TScopeIdentifiersTraverserCallback} callback
|
||||
* @param {TScopeIdentifiersTraverserVariableCallback} callback
|
||||
*/
|
||||
public traverse (
|
||||
public traverseScopeVariables (
|
||||
programNode: ESTree.Program,
|
||||
parentNode: ESTree.Node | null,
|
||||
callback: TScopeIdentifiersTraverserCallback
|
||||
callback: TScopeIdentifiersTraverserVariableCallback
|
||||
): void {
|
||||
this.scopeAnalyzer.analyze(programNode);
|
||||
|
||||
const globalScope: eslintScope.Scope = this.scopeAnalyzer.acquireScope(programNode);
|
||||
|
||||
this.traverseScopeVariables(globalScope, globalScope, callback);
|
||||
this.traverseScopeVariablesRecursive(globalScope, globalScope, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Scope} rootScope
|
||||
* @param {Scope} currentScope
|
||||
* @param {TScopeIdentifiersTraverserCallback} callback
|
||||
* @param {TScopeIdentifiersTraverserVariableCallback} callback
|
||||
*/
|
||||
private traverseScopeVariables (
|
||||
private traverseScopeVariablesRecursive (
|
||||
rootScope: eslintScope.Scope,
|
||||
currentScope: eslintScope.Scope,
|
||||
callback: TScopeIdentifiersTraverserCallback
|
||||
callback: TScopeIdentifiersTraverserVariableCallback
|
||||
): void {
|
||||
const variableScope: eslintScope.Scope = currentScope.variableScope;
|
||||
const variableLexicalScopeNode: TNodeWithLexicalScope | null = NodeGuards.isNodeWithBlockLexicalScope(variableScope.block)
|
||||
@@ -105,7 +105,7 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser {
|
||||
}
|
||||
|
||||
for (const childScope of currentScope.childScopes) {
|
||||
this.traverseScopeVariables(rootScope, childScope, callback);
|
||||
this.traverseScopeVariablesRecursive(rootScope, childScope, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { IScopeIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserCallbackData';
|
||||
|
||||
export type TScopeIdentifiersTraverserCallback = (data: IScopeIdentifiersTraverserCallbackData) => void;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { IScopeIdentifiersTraverserVariableCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserVariableCallbackData';
|
||||
|
||||
export type TScopeIdentifiersTraverserVariableCallback = (data: IScopeIdentifiersTraverserVariableCallbackData) => void;
|
||||
Reference in New Issue
Block a user