瀏覽代碼

Add prefix only for variables with global declaration

sanex3339 7 年之前
父節點
當前提交
cf94be2285
共有 27 個文件被更改,包括 132 次插入91 次删除
  1. 0 0
      dist/index.js
  2. 1 1
      package.json
  3. 1 1
      src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts
  4. 1 1
      src/custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup.ts
  5. 2 2
      src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts
  6. 1 1
      src/custom-nodes/domain-lock-nodes/DomainLockNode.ts
  7. 1 1
      src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts
  8. 1 1
      src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts
  9. 1 1
      src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts
  10. 2 2
      src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts
  11. 6 2
      src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts
  12. 21 8
      src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts
  13. 14 6
      src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts
  14. 6 2
      src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.d.ts
  15. 3 2
      src/interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer.d.ts
  16. 1 1
      src/node-transformers/obfuscating-transformers/CatchClauseTransformer.ts
  17. 8 3
      src/node-transformers/obfuscating-transformers/ClassDeclarationTransformer.ts
  18. 8 3
      src/node-transformers/obfuscating-transformers/FunctionDeclarationTransformer.ts
  19. 2 2
      src/node-transformers/obfuscating-transformers/FunctionTransformer.ts
  20. 1 1
      src/node-transformers/obfuscating-transformers/LabeledStatementTransformer.ts
  21. 8 3
      src/node-transformers/obfuscating-transformers/VariableDeclarationTransformer.ts
  22. 7 2
      src/node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer.ts
  23. 9 2
      src/storages/string-array/StringArrayStorage.ts
  24. 5 6
      test/dev/dev.ts
  25. 9 24
      test/unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec.ts
  26. 10 10
      test/unit-tests/generators/identifier-names-generators/MangledlIdentifierNamesGenerator.spec.ts
  27. 3 3
      yarn.lock

文件差異過大導致無法顯示
+ 0 - 0
dist/index.js


+ 1 - 1
package.json

@@ -63,7 +63,7 @@
     "mocha": "5.0.0",
     "pre-commit": "1.2.2",
     "rimraf": "2.6.2",
-    "sinon": "4.1.6",
+    "sinon": "4.2.0",
     "threads": "0.10.1",
     "ts-node": "4.1.0",
     "tslint": "5.9.1",

+ 1 - 1
src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts

@@ -64,7 +64,7 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
             : GlobalVariableNoEvalTemplate();
 
         return format(ConsoleOutputDisableExpressionTemplate(), {
-            consoleLogDisableFunctionName: this.identifierNamesGenerator.generate(6),
+            consoleLogDisableFunctionName: this.identifierNamesGenerator.generate(),
             globalVariableTemplate,
             singleNodeCallControllerFunctionName: this.callsControllerFunctionName
         });

+ 1 - 1
src/custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup.ts

@@ -92,7 +92,7 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate(6);
+        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
 
         const consoleOutputDisableExpressionNode: ICustomNode = this.customNodeFactory(CustomNode.ConsoleOutputDisableExpressionNode);
         const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);

+ 2 - 2
src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts

@@ -105,8 +105,8 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const debugProtectionFunctionName: string = this.identifierNamesGenerator.generate(6);
-        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate(6);
+        const debugProtectionFunctionName: string = this.identifierNamesGenerator.generate();
+        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
 
         const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionNode);
         const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionCallNode);

+ 1 - 1
src/custom-nodes/domain-lock-nodes/DomainLockNode.ts

@@ -79,7 +79,7 @@ export class DomainLockNode extends AbstractCustomNode {
             : GlobalVariableNoEvalTemplate();
 
         return format(DomainLockNodeTemplate(), {
-            domainLockFunctionName: this.identifierNamesGenerator.generate(6),
+            domainLockFunctionName: this.identifierNamesGenerator.generate(),
             diff: diff,
             domains: hiddenDomainsString,
             globalVariableTemplate,

+ 1 - 1
src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts

@@ -92,7 +92,7 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate(6);
+        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
 
         const domainLockNode: ICustomNode = this.customNodeFactory(CustomNode.DomainLockNode);
         const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);

+ 1 - 1
src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts

@@ -71,7 +71,7 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
     protected getTemplate (): string {
         return JavaScriptObfuscator.obfuscate(
             format(SelfDefendingTemplate(this.escapeSequenceEncoder), {
-                selfDefendingFunctionName: this.identifierNamesGenerator.generate(6),
+                selfDefendingFunctionName: this.identifierNamesGenerator.generate(),
                 singleNodeCallControllerFunctionName: this.callsControllerFunctionName
             }),
             {

+ 1 - 1
src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts

@@ -92,7 +92,7 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate(6);
+        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
 
         const selfDefendingUnicodeNode: ICustomNode = this.customNodeFactory(CustomNode.SelfDefendingUnicodeNode);
         const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);

+ 2 - 2
src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts

@@ -82,8 +82,8 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
      * @returns {string}
      */
     protected getTemplate (): string {
-        const timesName: string = this.identifierNamesGenerator.generate(6);
-        const whileFunctionName: string = this.identifierNamesGenerator.generate(6);
+        const timesName: string = this.identifierNamesGenerator.generate();
+        const whileFunctionName: string = this.identifierNamesGenerator.generate();
 
         let code: string = '';
 

+ 6 - 2
src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts

@@ -39,8 +39,12 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
     }
 
     /**
-     * @param {number} length
      * @returns {string}
      */
-    public abstract generate (length: number): string;
+    public abstract generate (): string;
+
+    /**
+     * @returns {string}
+     */
+    public abstract generateWithPrefix (): string;
 }

+ 21 - 8
src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts

@@ -9,6 +9,11 @@ import { Utils } from '../../utils/Utils';
 
 @injectable()
 export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {
+    /**
+     * @type {number}
+     */
+    private static baseIdentifierNameLength: number = 6;
+
     /**
      * @type {Set<string>}
      */
@@ -26,23 +31,31 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
     }
 
     /**
-     * @param {number} length
      * @returns {string}
      */
-    public generate (length: number): string {
-        const prefix: string = `${this.identifiersPrefix}_${Utils.hexadecimalPrefix}`;
+    public generate (): string {
         const rangeMinInteger: number = 10000;
         const rangeMaxInteger: number = 99999999;
         const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger);
         const hexadecimalNumber: string = Utils.decToHex(randomInteger);
-        const randomVariableName: string = `${prefix}${hexadecimalNumber.substr(0, length)}`;
+        const baseIdentifierName: string = hexadecimalNumber.substr(0, HexadecimalIdentifierNamesGenerator.baseIdentifierNameLength);
+        const identifierName: string = `_${Utils.hexadecimalPrefix}${baseIdentifierName}`;
 
-        if (this.randomVariableNameSet.has(randomVariableName)) {
-            return this.generate(length);
+        if (this.randomVariableNameSet.has(identifierName)) {
+            return this.generate();
         }
 
-        this.randomVariableNameSet.add(randomVariableName);
+        this.randomVariableNameSet.add(identifierName);
+
+        return identifierName;
+    }
+
+    /**
+     * @returns {string}
+     */
+    public generateWithPrefix (): string {
+        const identifierName: string = this.generate();
 
-        return randomVariableName;
+        return `${this.identifiersPrefix}${identifierName}`.replace('__', '_');
     }
 }

+ 14 - 6
src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts

@@ -98,17 +98,25 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
     }
 
     /**
-     * @param {number} length
      * @returns {string}
      */
-    public generate (length: number): string {
+    public generate (): string {
+        const identifierName: string = MangledIdentifierNamesGenerator.generateNewMangledName(this.previousMangledName);
+
+        this.previousMangledName = identifierName;
+
+        return identifierName;
+    }
+
+    /**
+     * @returns {string}
+     */
+    public generateWithPrefix (): string {
         const prefix: string = this.options.identifiersPrefix ?
             `${this.identifiersPrefix}_`
             : '';
-        const newName: string = MangledIdentifierNamesGenerator.generateNewMangledName(this.previousMangledName);
-
-        this.previousMangledName = newName;
+        const identifierName: string = this.generate();
 
-        return `${prefix}${newName}`;
+        return `${prefix}${identifierName}`;
     }
 }

+ 6 - 2
src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.d.ts

@@ -1,7 +1,11 @@
 export interface IIdentifierNamesGenerator {
     /**
-     * @param {number} length
      * @returns {string}
      */
-    generate (length: number): string;
+    generate (): string;
+
+    /**
+     * @returns {string}
+     */
+    generateWithPrefix (): string;
 }

+ 3 - 2
src/interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer.d.ts

@@ -4,8 +4,9 @@ import { IObfuscatingReplacer } from './IObfuscatingReplacer';
 
 export interface IIdentifierObfuscatingReplacer extends IObfuscatingReplacer <ESTree.Identifier> {
     /**
-     * @param nodeValue
+     * @param {string} nodeValue
+     * @param isGlobalDeclaration
      * @param {number} nodeIdentifier
      */
-    storeNames (nodeValue: any, nodeIdentifier: number): void;
+    storeNames (nodeValue: string, isGlobalDeclaration: boolean, nodeIdentifier: number): void;
 }

+ 1 - 1
src/node-transformers/obfuscating-transformers/CatchClauseTransformer.ts

@@ -90,7 +90,7 @@ export class CatchClauseTransformer extends AbstractNodeTransformer {
      */
     private storeCatchClauseParam (catchClauseNode: ESTree.CatchClause, nodeIdentifier: number): void {
         if (NodeGuards.isIdentifierNode(catchClauseNode.param)) {
-            this.identifierObfuscatingReplacer.storeNames(catchClauseNode.param.name, nodeIdentifier);
+            this.identifierObfuscatingReplacer.storeNames(catchClauseNode.param.name, false, nodeIdentifier);
         }
     }
 

+ 8 - 3
src/node-transformers/obfuscating-transformers/ClassDeclarationTransformer.ts

@@ -93,7 +93,7 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
             return classDeclarationNode;
         }
 
-        this.storeClassName(classDeclarationNode, nodeIdentifier);
+        this.storeClassName(classDeclarationNode, isGlobalDeclaration, nodeIdentifier);
 
         // check for cached identifiers for current scope node. If exist - loop through them.
         if (this.replaceableIdentifiers.has(blockScopeNode)) {
@@ -107,10 +107,15 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
 
     /**
      * @param {ClassDeclaration} classDeclarationNode
+     * @param {boolean} isGlobalDeclaration
      * @param {number} nodeIdentifier
      */
-    private storeClassName (classDeclarationNode: ESTree.ClassDeclaration, nodeIdentifier: number): void {
-        this.identifierObfuscatingReplacer.storeNames(classDeclarationNode.id.name, nodeIdentifier);
+    private storeClassName (
+        classDeclarationNode: ESTree.ClassDeclaration,
+        isGlobalDeclaration: boolean,
+        nodeIdentifier: number
+    ): void {
+        this.identifierObfuscatingReplacer.storeNames(classDeclarationNode.id.name, isGlobalDeclaration, nodeIdentifier);
     }
 
     /**

+ 8 - 3
src/node-transformers/obfuscating-transformers/FunctionDeclarationTransformer.ts

@@ -95,7 +95,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
             return functionDeclarationNode;
         }
 
-        this.storeFunctionName(functionDeclarationNode, nodeIdentifier);
+        this.storeFunctionName(functionDeclarationNode, isGlobalDeclaration, nodeIdentifier);
 
         // check for cached identifiers for current scope node. If exist - loop through them.
         if (this.replaceableIdentifiers.has(blockScopeNode)) {
@@ -109,10 +109,15 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
 
     /**
      * @param {FunctionDeclaration} functionDeclarationNode
+     * @param {boolean} isGlobalDeclaration
      * @param {number} nodeIdentifier
      */
-    private storeFunctionName (functionDeclarationNode: ESTree.FunctionDeclaration, nodeIdentifier: number): void {
-        this.identifierObfuscatingReplacer.storeNames(functionDeclarationNode.id.name, nodeIdentifier);
+    private storeFunctionName (
+        functionDeclarationNode: ESTree.FunctionDeclaration,
+        isGlobalDeclaration: boolean,
+        nodeIdentifier: number
+    ): void {
+        this.identifierObfuscatingReplacer.storeNames(functionDeclarationNode.id.name, isGlobalDeclaration, nodeIdentifier);
     }
 
     /**

+ 2 - 2
src/node-transformers/obfuscating-transformers/FunctionTransformer.ts

@@ -104,13 +104,13 @@ export class FunctionTransformer extends AbstractNodeTransformer {
                 estraverse.traverse(paramsNode, {
                     enter: (node: ESTree.Node): any => {
                         if (NodeGuards.isAssignmentPatternNode(node) && NodeGuards.isIdentifierNode(node.left)) {
-                            this.identifierObfuscatingReplacer.storeNames(node.left.name, nodeIdentifier);
+                            this.identifierObfuscatingReplacer.storeNames(node.left.name, false, nodeIdentifier);
 
                             return estraverse.VisitorOption.Skip;
                         }
 
                         if (NodeGuards.isIdentifierNode(node)) {
-                            this.identifierObfuscatingReplacer.storeNames(node.name, nodeIdentifier);
+                            this.identifierObfuscatingReplacer.storeNames(node.name, false, nodeIdentifier);
                         }
                     }
                 });

+ 1 - 1
src/node-transformers/obfuscating-transformers/LabeledStatementTransformer.ts

@@ -98,7 +98,7 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer {
      */
     private storeLabeledStatementName (labeledStatementNode: ESTree.LabeledStatement, nodeIdentifier: number): void {
         this.identifierObfuscatingReplacer
-            .storeNames(labeledStatementNode.label.name, nodeIdentifier);
+            .storeNames(labeledStatementNode.label.name, false, nodeIdentifier);
     }
 
     /**

+ 8 - 3
src/node-transformers/obfuscating-transformers/VariableDeclarationTransformer.ts

@@ -100,7 +100,7 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
             ? blockScopeNode
             : parentNode;
 
-        this.storeVariableNames(variableDeclarationNode, nodeIdentifier);
+        this.storeVariableNames(variableDeclarationNode, isGlobalDeclaration, nodeIdentifier);
 
         // check for cached identifiers for current scope node. If exist - loop through them.
         if (this.replaceableIdentifiers.has(scopeNode)) {
@@ -114,11 +114,16 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
 
     /**
      * @param {VariableDeclaration} variableDeclarationNode
+     * @param {boolean} isGlobalDeclaration
      * @param {number} nodeIdentifier
      */
-    private storeVariableNames (variableDeclarationNode: ESTree.VariableDeclaration, nodeIdentifier: number): void {
+    private storeVariableNames (
+        variableDeclarationNode: ESTree.VariableDeclaration,
+        isGlobalDeclaration: boolean,
+        nodeIdentifier: number
+    ): void {
         this.traverseDeclarationIdentifiers(variableDeclarationNode, (identifierNode: ESTree.Identifier) => {
-            this.identifierObfuscatingReplacer.storeNames(identifierNode.name, nodeIdentifier);
+            this.identifierObfuscatingReplacer.storeNames(identifierNode.name, isGlobalDeclaration, nodeIdentifier);
         });
     }
 

+ 7 - 2
src/node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer.ts

@@ -58,14 +58,19 @@ export class BaseIdentifierObfuscatingReplacer extends AbstractObfuscatingReplac
      * Reserved names will be ignored.
      *
      * @param {string} nodeName
+     * @param {boolean} isGlobalDeclaration
      * @param {number} nodeIdentifier
      */
-    public storeNames (nodeName: string, nodeIdentifier: number): void {
+    public storeNames (nodeName: string, isGlobalDeclaration: boolean, nodeIdentifier: number): void {
         if (this.isReservedName(nodeName)) {
             return;
         }
 
-        this.namesMap.set(`${nodeName}-${String(nodeIdentifier)}`, this.identifierNamesGenerator.generate(6));
+        const identifierName: string = isGlobalDeclaration
+            ? this.identifierNamesGenerator.generateWithPrefix()
+            : this.identifierNamesGenerator.generate();
+
+        this.namesMap.set(`${nodeName}-${String(nodeIdentifier)}`, identifierName);
     }
 
     /**

+ 9 - 2
src/storages/string-array/StringArrayStorage.ts

@@ -12,6 +12,11 @@ import { ArrayStorage } from '../ArrayStorage';
 
 @injectable()
 export class StringArrayStorage extends ArrayStorage <string> {
+    /**
+     * @type {number}
+     */
+    private static readonly stringArrayNameLength: number = 7;
+
     /**
      * @type {IArrayUtils}
      */
@@ -45,8 +50,10 @@ export class StringArrayStorage extends ArrayStorage <string> {
     public initialize (): void {
         super.initialize();
 
-        const stringArrayName: string = this.identifierNamesGenerator.generate(4);
-        const stringArrayCallsWrapperName: string = this.identifierNamesGenerator.generate(4);
+        const stringArrayName: string = this.identifierNamesGenerator
+            .generateWithPrefix().slice(0, StringArrayStorage.stringArrayNameLength);
+        const stringArrayCallsWrapperName: string = this.identifierNamesGenerator
+            .generateWithPrefix().slice(0, StringArrayStorage.stringArrayNameLength);
 
         this.storageId = `${stringArrayName}|${stringArrayCallsWrapperName}`;
     }

+ 5 - 6
test/dev/dev.ts

@@ -6,19 +6,18 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
 
     let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
         `
+        var bar = 1;
+        var baz = 2;
         (function(){
-            function foo () {
-                eval('var s = 1;');
-            }
-        
-            foo();
+            var bark = bar + baz;
         })();
         `,
         {
             ...NO_ADDITIONAL_NODES_PRESET,
             compact: false,
             identifiersPrefix: 'foo',
-            identifierNamesGenerator: 'mangled'
+            identifierNamesGenerator: 'mangled',
+            renameGlobals: true
         }
     ).getObfuscatedCode();
 

+ 9 - 24
test/unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec.ts

@@ -12,7 +12,7 @@ import { IdentifierNamesGenerator } from '../../../../src/enums/generators/ident
 import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
 
 describe('HexadecimalIdentifierNamesGenerator', () => {
-    describe('generate (length: number): string', () => {
+    describe('generate (length: number, attachPrefix: boolean): string', () => {
         describe('Hexadecimal name without prefix', () => {
             let identifierNamesGenerator: IIdentifierNamesGenerator,
                 hexadecimalIdentifierName: string,
@@ -25,30 +25,15 @@ describe('HexadecimalIdentifierNamesGenerator', () => {
                 identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
                     ServiceIdentifiers.IIdentifierNamesGenerator,
                     IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
-                )
-            });
-
-            describe('variant #1: hexadecimal name with length `4`', () => {
-                before(() => {
-                    hexadecimalIdentifierName = identifierNamesGenerator.generate(4);
-                    regExp = /^_0x(\w){4}$/;
-                });
+                );
 
-                it('should return hexadecimal name', () => {
-                    assert.match(hexadecimalIdentifierName, regExp);
-                })
+                hexadecimalIdentifierName = identifierNamesGenerator.generate();
+                regExp = /^_0x(\w){4,6}$/;
             });
 
-            describe('variant #2: hexadecimal name with length `6`', () => {
-                before(() => {
-                    hexadecimalIdentifierName = identifierNamesGenerator.generate(6);
-                    regExp = /^_0x(\w){4,6}$/;
-                });
-
-                it('should return hexadecimal name', () => {
-                    assert.match(hexadecimalIdentifierName, regExp);
-                })
-            });
+            it('should return hexadecimal name', () => {
+                assert.match(hexadecimalIdentifierName, regExp);
+            })
         });
 
         describe('Hexadecimal name with prefix', () => {
@@ -68,7 +53,7 @@ describe('HexadecimalIdentifierNamesGenerator', () => {
                     IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
                 );
 
-                hexadecimalIdentifierName = identifierNamesGenerator.generate(6);
+                hexadecimalIdentifierName = identifierNamesGenerator.generateWithPrefix();
             });
 
             it('should return hexadecimal name with prefix', () => {
@@ -93,7 +78,7 @@ describe('HexadecimalIdentifierNamesGenerator', () => {
                     IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
                 );
 
-                hexadecimalIdentifierName = identifierNamesGenerator.generate(6);
+                hexadecimalIdentifierName = identifierNamesGenerator.generateWithPrefix();
             });
 
             it('should return hexadecimal name with prefix', () => {

+ 10 - 10
test/unit-tests/generators/identifier-names-generators/MangledlIdentifierNamesGenerator.spec.ts

@@ -31,7 +31,7 @@ describe('MangledIdentifierNamesGenerator', () => {
                 const expectedMangledIdentifierName: string = 'a';
 
                 beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generate(4);
+                    mangledIdentifierName = identifierNamesGenerator.generate();
                 });
 
                 it('should return mangled name', () => {
@@ -45,7 +45,7 @@ describe('MangledIdentifierNamesGenerator', () => {
 
                 beforeEach(() => {
                     for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
-                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                        mangledIdentifierName = identifierNamesGenerator.generate();
                     }
                 });
 
@@ -60,7 +60,7 @@ describe('MangledIdentifierNamesGenerator', () => {
 
                 beforeEach(() => {
                     for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
-                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                        mangledIdentifierName = identifierNamesGenerator.generate();
                     }
                 });
 
@@ -75,7 +75,7 @@ describe('MangledIdentifierNamesGenerator', () => {
 
                 beforeEach(() => {
                     for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
-                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                        mangledIdentifierName = identifierNamesGenerator.generate();
                     }
                 });
 
@@ -90,7 +90,7 @@ describe('MangledIdentifierNamesGenerator', () => {
 
                 beforeEach(() => {
                     for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
-                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                        mangledIdentifierName = identifierNamesGenerator.generate();
                     }
                 });
 
@@ -110,7 +110,7 @@ describe('MangledIdentifierNamesGenerator', () => {
 
                 beforeEach(() => {
                     for (let i: number = 0; i <= expectedMangledIdentifierPosition2; i++) {
-                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                        mangledIdentifierName = identifierNamesGenerator.generate();
 
                         if (i === expectedMangledIdentifierPosition1) {
                             mangledIdentifierName1 = mangledIdentifierName;
@@ -150,7 +150,7 @@ describe('MangledIdentifierNamesGenerator', () => {
                 const expectedMangledIdentifierName: string = 'foo_a';
 
                 beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generate(4);
+                    mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
                 });
 
                 it('should return mangled name with prefix', () => {
@@ -162,7 +162,7 @@ describe('MangledIdentifierNamesGenerator', () => {
                 const expectedMangledIdentifierName: string = 'foo_b';
 
                 beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generate(4);
+                    mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
                 });
 
                 it('should return mangled name with prefix', () => {
@@ -191,7 +191,7 @@ describe('MangledIdentifierNamesGenerator', () => {
                 const expectedMangledIdentifierNameRegExp: RegExp = /(\w){6}_a/;
 
                 beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generate(4);
+                    mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
                 });
 
                 it('should return mangled name with prefix', () => {
@@ -203,7 +203,7 @@ describe('MangledIdentifierNamesGenerator', () => {
                 const expectedMangledIdentifierNameRegExp: RegExp = /(\w){6}_b/;
 
                 beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generate(4);
+                    mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
                 });
 
                 it('should return mangled name with prefix', () => {

+ 3 - 3
yarn.lock

@@ -3329,9 +3329,9 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
   version "3.0.2"
   resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
 
-sinon@4.1.6:
-  version "4.1.6"
-  resolved "https://registry.yarnpkg.com/sinon/-/sinon-4.1.6.tgz#9cb346bddb180d68a804429ffe14978d7fafd629"
+sinon@4.2.0:
+  version "4.2.0"
+  resolved "https://registry.yarnpkg.com/sinon/-/sinon-4.2.0.tgz#3b7c0d2289a80d2d84c4685f2ec130b7ab9af621"
   dependencies:
     diff "^3.1.0"
     formatio "1.2.0"

部分文件因文件數量過多而無法顯示