|
@@ -6,12 +6,11 @@ import * as ESTree from 'estree';
|
|
|
|
|
|
import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
|
|
import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
|
|
|
|
|
|
-import { IIdentifierNamesCacheStorage } from '../../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
|
|
|
|
-import { IIdentifierReplacer } from '../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer';
|
|
|
|
import { IOptions } from '../../interfaces/options/IOptions';
|
|
import { IOptions } from '../../interfaces/options/IOptions';
|
|
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
|
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
|
import { IScopeIdentifiersTraverser } from '../../interfaces/node/IScopeIdentifiersTraverser';
|
|
import { IScopeIdentifiersTraverser } from '../../interfaces/node/IScopeIdentifiersTraverser';
|
|
import { IScopeThroughIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeThroughIdentifiersTraverserCallbackData';
|
|
import { IScopeThroughIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeThroughIdentifiersTraverserCallbackData';
|
|
|
|
+import { IThroughIdentifierReplacer } from '../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer';
|
|
import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
|
|
import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
|
|
|
|
|
|
import { NodeTransformationStage } from '../../enums/node-transformers/NodeTransformationStage';
|
|
import { NodeTransformationStage } from '../../enums/node-transformers/NodeTransformationStage';
|
|
@@ -25,41 +24,31 @@ import { NodeGuards } from '../../node/NodeGuards';
|
|
@injectable()
|
|
@injectable()
|
|
export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer {
|
|
export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer {
|
|
/**
|
|
/**
|
|
- * @type {IIdentifierNamesCacheStorage}
|
|
|
|
- */
|
|
|
|
- protected readonly identifierNamesCacheStorage: IIdentifierNamesCacheStorage;
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @type {IIdentifierReplacer}
|
|
|
|
|
|
+ * @type {IScopeIdentifiersTraverser}
|
|
*/
|
|
*/
|
|
- protected readonly identifierReplacer: IIdentifierReplacer;
|
|
|
|
|
|
+ protected readonly scopeIdentifiersTraverser: IScopeIdentifiersTraverser;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @type {IScopeIdentifiersTraverser}
|
|
|
|
|
|
+ * @type {IThroughIdentifierReplacer}
|
|
*/
|
|
*/
|
|
- protected readonly scopeIdentifiersTraverser: IScopeIdentifiersTraverser;
|
|
|
|
|
|
+ protected readonly throughIdentifierReplacer: IThroughIdentifierReplacer;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param {IIdentifierReplacer} identifierReplacer
|
|
|
|
- * @param {IRandomGenerator} randomGenerator
|
|
|
|
|
|
+ * @param {IThroughIdentifierReplacer} throughIdentifierReplacer
|
|
* @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser
|
|
* @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser
|
|
- * @param {IIdentifierNamesCacheStorage} identifierNamesCacheStorage
|
|
|
|
|
|
+ * @param {IRandomGenerator} randomGenerator
|
|
* @param {IOptions} options
|
|
* @param {IOptions} options
|
|
*/
|
|
*/
|
|
public constructor (
|
|
public constructor (
|
|
- @inject(ServiceIdentifiers.IIdentifierReplacer) identifierReplacer: IIdentifierReplacer,
|
|
|
|
|
|
+ @inject(ServiceIdentifiers.IThroughIdentifierReplacer) throughIdentifierReplacer: IThroughIdentifierReplacer,
|
|
|
|
+ @inject(ServiceIdentifiers.IScopeIdentifiersTraverser) scopeIdentifiersTraverser: IScopeIdentifiersTraverser,
|
|
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
|
|
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
|
|
- @inject(ServiceIdentifiers.IScopeIdentifiersTraverser)
|
|
|
|
- scopeIdentifiersTraverser: IScopeIdentifiersTraverser,
|
|
|
|
- @inject(ServiceIdentifiers.IIdentifierNamesCacheStorage)
|
|
|
|
- identifierNamesCacheStorage: IIdentifierNamesCacheStorage,
|
|
|
|
@inject(ServiceIdentifiers.IOptions) options: IOptions
|
|
@inject(ServiceIdentifiers.IOptions) options: IOptions
|
|
) {
|
|
) {
|
|
super(randomGenerator, options);
|
|
super(randomGenerator, options);
|
|
|
|
|
|
- this.identifierReplacer = identifierReplacer;
|
|
|
|
|
|
+ this.throughIdentifierReplacer = throughIdentifierReplacer;
|
|
this.scopeIdentifiersTraverser = scopeIdentifiersTraverser;
|
|
this.scopeIdentifiersTraverser = scopeIdentifiersTraverser;
|
|
- this.identifierNamesCacheStorage = identifierNamesCacheStorage;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -93,15 +82,13 @@ export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer
|
|
parentNode,
|
|
parentNode,
|
|
(data: IScopeThroughIdentifiersTraverserCallbackData) => {
|
|
(data: IScopeThroughIdentifiersTraverserCallbackData) => {
|
|
const {
|
|
const {
|
|
- isGlobalDeclaration,
|
|
|
|
reference,
|
|
reference,
|
|
variableLexicalScopeNode
|
|
variableLexicalScopeNode
|
|
} = data;
|
|
} = data;
|
|
|
|
|
|
this.transformScopeThroughIdentifiers(
|
|
this.transformScopeThroughIdentifiers(
|
|
reference,
|
|
reference,
|
|
- variableLexicalScopeNode,
|
|
|
|
- isGlobalDeclaration
|
|
|
|
|
|
+ variableLexicalScopeNode
|
|
);
|
|
);
|
|
}
|
|
}
|
|
);
|
|
);
|
|
@@ -112,12 +99,10 @@ export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer
|
|
/**
|
|
/**
|
|
* @param {Reference} reference
|
|
* @param {Reference} reference
|
|
* @param {TNodeWithLexicalScope} lexicalScopeNode
|
|
* @param {TNodeWithLexicalScope} lexicalScopeNode
|
|
- * @param {boolean} isGlobalDeclaration
|
|
|
|
*/
|
|
*/
|
|
protected transformScopeThroughIdentifiers (
|
|
protected transformScopeThroughIdentifiers (
|
|
reference: eslintScope.Reference,
|
|
reference: eslintScope.Reference,
|
|
- lexicalScopeNode: TNodeWithLexicalScope,
|
|
|
|
- isGlobalDeclaration: boolean
|
|
|
|
|
|
+ lexicalScopeNode: TNodeWithLexicalScope
|
|
): void {
|
|
): void {
|
|
if (reference.resolved) {
|
|
if (reference.resolved) {
|
|
return;
|
|
return;
|
|
@@ -125,35 +110,28 @@ export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer
|
|
|
|
|
|
const identifier: ESTree.Identifier = reference.identifier;
|
|
const identifier: ESTree.Identifier = reference.identifier;
|
|
|
|
|
|
- this.storeIdentifierName(identifier, lexicalScopeNode, isGlobalDeclaration);
|
|
|
|
- this.replaceIdentifierName(identifier, lexicalScopeNode, reference);
|
|
|
|
|
|
+ this.storeIdentifierName(identifier);
|
|
|
|
+ this.replaceIdentifierName(identifier, reference);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {Identifier} identifierNode
|
|
* @param {Identifier} identifierNode
|
|
- * @param {TNodeWithLexicalScope} lexicalScopeNode
|
|
|
|
- * @param {boolean} isGlobalDeclaration
|
|
|
|
*/
|
|
*/
|
|
protected storeIdentifierName (
|
|
protected storeIdentifierName (
|
|
- identifierNode: ESTree.Identifier,
|
|
|
|
- lexicalScopeNode: TNodeWithLexicalScope,
|
|
|
|
- isGlobalDeclaration: boolean
|
|
|
|
|
|
+ identifierNode: ESTree.Identifier
|
|
): void {
|
|
): void {
|
|
- this.identifierReplacer.storeThroughName(identifierNode, lexicalScopeNode);
|
|
|
|
|
|
+ this.throughIdentifierReplacer.store(identifierNode);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {Identifier} identifierNode
|
|
* @param {Identifier} identifierNode
|
|
- * @param {TNodeWithLexicalScope} lexicalScopeNode
|
|
|
|
* @param {Variable} reference
|
|
* @param {Variable} reference
|
|
*/
|
|
*/
|
|
protected replaceIdentifierName (
|
|
protected replaceIdentifierName (
|
|
identifierNode: ESTree.Identifier,
|
|
identifierNode: ESTree.Identifier,
|
|
- lexicalScopeNode: TNodeWithLexicalScope,
|
|
|
|
reference: eslintScope.Reference
|
|
reference: eslintScope.Reference
|
|
): void {
|
|
): void {
|
|
- const newIdentifier: ESTree.Identifier = this.identifierReplacer
|
|
|
|
- .replace(identifierNode, lexicalScopeNode);
|
|
|
|
|
|
+ const newIdentifier: ESTree.Identifier = this.throughIdentifierReplacer.replace(identifierNode);
|
|
|
|
|
|
// rename of identifier
|
|
// rename of identifier
|
|
reference.identifier.name = newIdentifier.name;
|
|
reference.identifier.name = newIdentifier.name;
|