Ver Fonte

Removed random internal random generation of identifiers prefix

sanex3339 há 7 anos atrás
pai
commit
19ff4cfb1e

+ 1 - 1
README.md

@@ -575,7 +575,7 @@ Available values:
 ### `identifiersPrefix`
 ### `identifiersPrefix`
 Type: `string` Default: `''`
 Type: `string` Default: `''`
 
 
-Sets prefix for all generated identifiers. If prefix sets to `true` - random prefix with length of 6 characters will generated. If prefix sets to `false` or empty string - prefix won't generated.
+Sets prefix for all generated identifiers.
 
 
 Use this option when you want to obfuscate multiple files. This option helps to avoid conflicts between identifiers of these files. Prefix should be different for every file.
 Use this option when you want to obfuscate multiple files. This option helps to avoid conflicts between identifiers of these files. Prefix should be different for every file.
 
 

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/index.js


+ 3 - 5
src/cli/JavaScriptObfuscatorCLI.ts

@@ -18,7 +18,6 @@ import { DEFAULT_PRESET } from '../options/presets/Default';
 import { ArraySanitizer } from './sanitizers/ArraySanitizer';
 import { ArraySanitizer } from './sanitizers/ArraySanitizer';
 import { BooleanSanitizer } from './sanitizers/BooleanSanitizer';
 import { BooleanSanitizer } from './sanitizers/BooleanSanitizer';
 import { IdentifierNamesGeneratorSanitizer } from './sanitizers/IdentifierNamesGeneratorSanitizer';
 import { IdentifierNamesGeneratorSanitizer } from './sanitizers/IdentifierNamesGeneratorSanitizer';
-import { IdentifiersPrefixSanitizer } from './sanitizers/IdentifiersPrefixSanitizer';
 import { ObfuscationTargetSanitizer } from './sanitizers/ObfuscatingTargetSanitizer';
 import { ObfuscationTargetSanitizer } from './sanitizers/ObfuscatingTargetSanitizer';
 import { SourceMapModeSanitizer } from './sanitizers/SourceMapModeSanitizer';
 import { SourceMapModeSanitizer } from './sanitizers/SourceMapModeSanitizer';
 import { StringArrayEncodingSanitizer } from './sanitizers/StringArrayEncodingSanitizer';
 import { StringArrayEncodingSanitizer } from './sanitizers/StringArrayEncodingSanitizer';
@@ -246,9 +245,8 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
                 IdentifierNamesGeneratorSanitizer
                 IdentifierNamesGeneratorSanitizer
             )
             )
             .option(
             .option(
-                '--identifiers-prefix <string|boolean>',
-                'Sets prefix for all generated identifiers.',
-                IdentifiersPrefixSanitizer
+                '--identifiers-prefix <string>',
+                'Sets prefix for all generated identifiers.'
             )
             )
             .option(
             .option(
                 '--log <boolean>', 'Enables logging of the information to the console',
                 '--log <boolean>', 'Enables logging of the information to the console',
@@ -351,7 +349,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
 
 
             this.processSourceCode(sourceCodeData, outputCodePath);
             this.processSourceCode(sourceCodeData, outputCodePath);
         } else {
         } else {
-            sourceCodeData.forEach(({ filePath, content }: IFileData) => {
+            sourceCodeData.forEach(({ filePath, content }: IFileData, index: number) => {
                 const outputCodePath: string = outputPath
                 const outputCodePath: string = outputPath
                     ? path.join(outputPath, filePath)
                     ? path.join(outputPath, filePath)
                     : CLIUtils.getOutputCodePath(filePath);
                     : CLIUtils.getOutputCodePath(filePath);

+ 0 - 21
src/cli/sanitizers/IdentifiersPrefixSanitizer.ts

@@ -1,21 +0,0 @@
-import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
-
-/**
- * @param {string} value
- * @returns {string | boolean}
- * @constructor
- */
-export const IdentifiersPrefixSanitizer: TCLISanitizer = (value: string): string | boolean => {
-    switch (value) {
-        case 'true':
-        case '1':
-            return true;
-
-        case 'false':
-        case '0':
-            return false;
-
-        default:
-            return value;
-    }
-};

+ 0 - 16
src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts

@@ -7,11 +7,6 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 
 @injectable()
 @injectable()
 export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNamesGenerator {
 export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNamesGenerator {
-    /**
-     * @type {string}
-     */
-    protected readonly identifiersPrefix: string;
-
     /**
     /**
      * @type {IOptions}
      * @type {IOptions}
      */
      */
@@ -32,10 +27,6 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
     ) {
     ) {
         this.randomGenerator = randomGenerator;
         this.randomGenerator = randomGenerator;
         this.options = options;
         this.options = options;
-
-        this.identifiersPrefix = this.options.identifiersPrefix === true
-            ? this.randomGenerator.getRandomString(6)
-            : this.options.identifiersPrefix || '';
     }
     }
 
 
     /**
     /**
@@ -47,11 +38,4 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
      * @returns {string}
      * @returns {string}
      */
      */
     public abstract generateWithPrefix (): string;
     public abstract generateWithPrefix (): string;
-
-    /**
-     * @returns {string}
-     */
-    public getPrefix (): string {
-        return this.identifiersPrefix;
-    }
 }
 }

+ 1 - 1
src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts

@@ -56,6 +56,6 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
     public generateWithPrefix (): string {
     public generateWithPrefix (): string {
         const identifierName: string = this.generate();
         const identifierName: string = this.generate();
 
 
-        return `${this.identifiersPrefix}${identifierName}`.replace('__', '_');
+        return `${this.options.identifiersPrefix}${identifierName}`.replace('__', '_');
     }
     }
 }
 }

+ 1 - 1
src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts

@@ -113,7 +113,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
      */
      */
     public generateWithPrefix (): string {
     public generateWithPrefix (): string {
         const prefix: string = this.options.identifiersPrefix ?
         const prefix: string = this.options.identifiersPrefix ?
-            `${this.identifiersPrefix}_`
+            `${this.options.identifiersPrefix}_`
             : '';
             : '';
         const identifierName: string = this.generate();
         const identifierName: string = this.generate();
 
 

+ 0 - 5
src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.d.ts

@@ -8,9 +8,4 @@ export interface IIdentifierNamesGenerator {
      * @returns {string}
      * @returns {string}
      */
      */
     generateWithPrefix (): string;
     generateWithPrefix (): string;
-
-    /**
-     * @returns {string}
-     */
-    getPrefix (): string;
 }
 }

+ 1 - 1
src/interfaces/options/IOptions.d.ts

@@ -15,7 +15,7 @@ export interface IOptions {
     readonly disableConsoleOutput: boolean;
     readonly disableConsoleOutput: boolean;
     readonly domainLock: string[];
     readonly domainLock: string[];
     readonly identifierNamesGenerator: IdentifierNamesGenerator;
     readonly identifierNamesGenerator: IdentifierNamesGenerator;
-    readonly identifiersPrefix: string | boolean;
+    readonly identifiersPrefix: string;
     readonly log: boolean;
     readonly log: boolean;
     readonly renameGlobals: boolean;
     readonly renameGlobals: boolean;
     readonly reservedNames: string[];
     readonly reservedNames: string[];

+ 2 - 4
src/options/Options.ts

@@ -113,12 +113,10 @@ export class Options implements IOptions {
     public readonly identifierNamesGenerator: IdentifierNamesGenerator;
     public readonly identifierNamesGenerator: IdentifierNamesGenerator;
 
 
     /**
     /**
-     * We won't validate this field, because of missing support of multiple types validation in `class-validator`.
-     * Value of this field will transformed to the string in `OptionsNormalizer`
-     *
      * @type {string}
      * @type {string}
      */
      */
-    public readonly identifiersPrefix: string | boolean;
+    @IsString()
+    public readonly identifiersPrefix: string;
 
 
     /**
     /**
      * @type {boolean}
      * @type {boolean}

+ 0 - 2
src/options/OptionsNormalizer.ts

@@ -9,7 +9,6 @@ import { ControlFlowFlatteningThresholdRule } from './normalizer-rules/ControlFl
 import { DeadCodeInjectionRule } from './normalizer-rules/DeadCodeInjectionRule';
 import { DeadCodeInjectionRule } from './normalizer-rules/DeadCodeInjectionRule';
 import { DeadCodeInjectionThresholdRule } from './normalizer-rules/DeadCodeInjectionThresholdRule';
 import { DeadCodeInjectionThresholdRule } from './normalizer-rules/DeadCodeInjectionThresholdRule';
 import { DomainLockRule } from './normalizer-rules/DomainLockRule';
 import { DomainLockRule } from './normalizer-rules/DomainLockRule';
-import { IdentifiersPrefixRule } from './normalizer-rules/IdentifiersPrefixRule';
 import { SelfDefendingRule } from './normalizer-rules/SelfDefendingRule';
 import { SelfDefendingRule } from './normalizer-rules/SelfDefendingRule';
 import { SourceMapBaseUrlRule } from './normalizer-rules/SourceMapBaseUrlRule';
 import { SourceMapBaseUrlRule } from './normalizer-rules/SourceMapBaseUrlRule';
 import { SourceMapFileNameRule } from './normalizer-rules/SourceMapFileNameRule';
 import { SourceMapFileNameRule } from './normalizer-rules/SourceMapFileNameRule';
@@ -27,7 +26,6 @@ export class OptionsNormalizer implements IOptionsNormalizer {
         DeadCodeInjectionRule,
         DeadCodeInjectionRule,
         DeadCodeInjectionThresholdRule,
         DeadCodeInjectionThresholdRule,
         DomainLockRule,
         DomainLockRule,
-        IdentifiersPrefixRule,
         SelfDefendingRule,
         SelfDefendingRule,
         SourceMapBaseUrlRule,
         SourceMapBaseUrlRule,
         SourceMapFileNameRule,
         SourceMapFileNameRule,

+ 0 - 26
src/options/normalizer-rules/IdentifiersPrefixRule.ts

@@ -1,26 +0,0 @@
-import { TOptionsNormalizerRule } from '../../types/options/TOptionsNormalizerRule';
-
-import { IOptions } from '../../interfaces/options/IOptions';
-
-/**
- * @param {IOptions} options
- * @returns {IOptions}
- */
-export const IdentifiersPrefixRule: TOptionsNormalizerRule = (options: IOptions): IOptions => {
-    const { identifiersPrefix }: { identifiersPrefix: string | boolean } = options;
-    const isStringPrefix: boolean = !!identifiersPrefix && typeof identifiersPrefix === 'string';
-    const isRandomPrefix: boolean = identifiersPrefix === true;
-
-    if (isStringPrefix || isRandomPrefix) {
-        return options;
-    }
-
-    const normalizedIdentifiersPrefix: string | boolean = typeof identifiersPrefix === 'number'
-        ? String(identifiersPrefix)
-        : false;
-
-    return {
-        ...options,
-        identifiersPrefix: normalizedIdentifiersPrefix
-    };
-};

+ 1 - 1
src/options/presets/Default.ts

@@ -16,7 +16,7 @@ export const DEFAULT_PRESET: TInputOptions = Object.freeze({
     disableConsoleOutput: false,
     disableConsoleOutput: false,
     domainLock: [],
     domainLock: [],
     identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
     identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
-    identifiersPrefix: false,
+    identifiersPrefix: '',
     log: false,
     log: false,
     renameGlobals: false,
     renameGlobals: false,
     reservedNames: [],
     reservedNames: [],

+ 1 - 1
src/options/presets/NoCustomNodes.ts

@@ -15,7 +15,7 @@ export const NO_ADDITIONAL_NODES_PRESET: TInputOptions = Object.freeze({
     disableConsoleOutput: false,
     disableConsoleOutput: false,
     domainLock: [],
     domainLock: [],
     identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
     identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
-    identifiersPrefix: false,
+    identifiersPrefix: '',
     log: false,
     log: false,
     renameGlobals: false,
     renameGlobals: false,
     reservedNames: [],
     reservedNames: [],

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

@@ -50,15 +50,14 @@ export class StringArrayStorage extends ArrayStorage <string> {
     public initialize (): void {
     public initialize (): void {
         super.initialize();
         super.initialize();
 
 
-        const namePrefix: string = this.identifierNamesGenerator.getPrefix();
         const baseStringArrayName: string = this.identifierNamesGenerator
         const baseStringArrayName: string = this.identifierNamesGenerator
             .generate()
             .generate()
             .slice(0, StringArrayStorage.stringArrayNameLength);
             .slice(0, StringArrayStorage.stringArrayNameLength);
         const baseStringArrayCallsWrapperName: string = this.identifierNamesGenerator
         const baseStringArrayCallsWrapperName: string = this.identifierNamesGenerator
             .generate()
             .generate()
             .slice(0, StringArrayStorage.stringArrayNameLength);
             .slice(0, StringArrayStorage.stringArrayNameLength);
-        const stringArrayName: string = `${namePrefix}${baseStringArrayName}`;
-        const stringArrayCallsWrapperName: string = `${namePrefix}${baseStringArrayCallsWrapperName}`;
+        const stringArrayName: string = `${this.options.identifiersPrefix}${baseStringArrayName}`;
+        const stringArrayCallsWrapperName: string = `${this.options.identifiersPrefix}${baseStringArrayCallsWrapperName}`;
 
 
         this.storageId = `${stringArrayName}|${stringArrayCallsWrapperName}`;
         this.storageId = `${stringArrayName}|${stringArrayCallsWrapperName}`;
     }
     }

+ 0 - 128
test/functional-tests/options/OptionsNormalizer.spec.ts

@@ -176,134 +176,6 @@ describe('OptionsNormalizer', () => {
             });
             });
         });
         });
 
 
-        describe('identifiersPrefixRule', () => {
-            describe('variant #1: string option value', () => {
-                before(() => {
-                    optionsPreset = getNormalizedOptions({
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: 'foo',
-                    });
-
-                    expectedOptionsPreset = {
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: 'foo',
-                    };
-                });
-
-                it('should normalize options preset', () => {
-                    assert.deepEqual(optionsPreset, expectedOptionsPreset);
-                });
-            });
-
-            describe('variant #2: empty string option value', () => {
-                before(() => {
-                    optionsPreset = getNormalizedOptions({
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: '',
-                    });
-
-                    expectedOptionsPreset = {
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: false,
-                    };
-                });
-
-                it('should normalize options preset', () => {
-                    assert.deepEqual(optionsPreset, expectedOptionsPreset);
-                });
-            });
-
-            describe('variant #3: option value is `true`', () => {
-                before(() => {
-                    optionsPreset = getNormalizedOptions({
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: true,
-                    });
-
-                    expectedOptionsPreset = {
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: true,
-                    };
-                });
-
-                it('should normalize options preset', () => {
-                    assert.deepEqual(optionsPreset, expectedOptionsPreset);
-                });
-            });
-
-            describe('variant #4: option value is `false`', () => {
-                before(() => {
-                    optionsPreset = getNormalizedOptions({
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: false,
-                    });
-
-                    expectedOptionsPreset = {
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: false,
-                    };
-                });
-
-                it('should normalize options preset', () => {
-                    assert.deepEqual(optionsPreset, expectedOptionsPreset);
-                });
-            });
-
-            describe('variant #5: option value is object', () => {
-                before(() => {
-                    optionsPreset = getNormalizedOptions({
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: <any>{},
-                    });
-
-                    expectedOptionsPreset = {
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: false,
-                    };
-                });
-
-                it('should normalize options preset', () => {
-                    assert.deepEqual(optionsPreset, expectedOptionsPreset);
-                });
-            });
-
-            describe('variant #6: option value is function', () => {
-                before(() => {
-                    optionsPreset = getNormalizedOptions({
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: <any>{},
-                    });
-
-                    expectedOptionsPreset = {
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: false,
-                    };
-                });
-
-                it('should normalize options preset', () => {
-                    assert.deepEqual(optionsPreset, expectedOptionsPreset);
-                });
-            });
-
-            describe('variant #7: option value is number', () => {
-                before(() => {
-                    optionsPreset = getNormalizedOptions({
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: <any>123,
-                    });
-
-                    expectedOptionsPreset = {
-                        ...DEFAULT_PRESET,
-                        identifiersPrefix: '123',
-                    };
-                });
-
-                it('should normalize options preset', () => {
-                    assert.deepEqual(optionsPreset, expectedOptionsPreset);
-                });
-            });
-        });
-
         describe('selfDefendingRule', () => {
         describe('selfDefendingRule', () => {
             before(() => {
             before(() => {
                 optionsPreset = getNormalizedOptions({
                 optionsPreset = getNormalizedOptions({

+ 0 - 1
test/index.spec.ts

@@ -9,7 +9,6 @@ import './unit-tests/analyzers/stack-trace-analyzer/StackTraceAnalyzer.spec';
 import './unit-tests/cli/sanitizers/ArraySanitizer.spec';
 import './unit-tests/cli/sanitizers/ArraySanitizer.spec';
 import './unit-tests/cli/sanitizers/BooleanSanitizer.spec';
 import './unit-tests/cli/sanitizers/BooleanSanitizer.spec';
 import './unit-tests/cli/sanitizers/IdentifierNamesGeneratorSanitizer.spec';
 import './unit-tests/cli/sanitizers/IdentifierNamesGeneratorSanitizer.spec';
-import './unit-tests/cli/sanitizers/IdentifiersPrefixSanitizer.spec';
 import './unit-tests/cli/sanitizers/ObfuscationTargetSanitizer.spec';
 import './unit-tests/cli/sanitizers/ObfuscationTargetSanitizer.spec';
 import './unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec';
 import './unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec';
 import './unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec';
 import './unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec';

+ 0 - 82
test/unit-tests/cli/sanitizers/IdentifiersPrefixSanitizer.spec.ts

@@ -1,82 +0,0 @@
-import { assert } from 'chai';
-
-import { IdentifiersPrefixSanitizer } from '../../../../src/cli/sanitizers/IdentifiersPrefixSanitizer';
-
-describe('IdentifiersPrefixSanitizer', () => {
-    describe('IdentifiersPrefixSanitizer: TCLISanitizer = (value: string): string | boolean', () => {
-        describe('variant #1: identifiers prefix `true`', () => {
-            const inputValue: string = 'true';
-            const expectedValue: boolean = true;
-
-            let value: boolean | string;
-
-            before(() => {
-                value = IdentifiersPrefixSanitizer(inputValue);
-            });
-
-            it('should sanitize value', () => {
-                assert.equal(value, expectedValue);
-            });
-        });
-
-        describe('variant #2: identifiers prefix `1`', () => {
-            const inputValue: string = '1';
-            const expectedValue: boolean = true;
-
-            let value: boolean | string;
-
-            before(() => {
-                value = IdentifiersPrefixSanitizer(inputValue);
-            });
-
-            it('should sanitize value', () => {
-                assert.equal(value, expectedValue);
-            });
-        });
-
-        describe('variant #3: identifiers prefix `false`', () => {
-            const inputValue: string = 'false';
-            const expectedValue: boolean = false;
-
-            let value: boolean | string;
-
-            before(() => {
-                value = IdentifiersPrefixSanitizer(inputValue);
-            });
-
-            it('should sanitize value', () => {
-                assert.equal(value, expectedValue);
-            });
-        });
-
-        describe('variant #4: identifiers prefix `0`', () => {
-            const inputValue: string = '0';
-            const expectedValue: boolean = false;
-
-            let value: boolean | string;
-
-            before(() => {
-                value = IdentifiersPrefixSanitizer(inputValue);
-            });
-
-            it('should sanitize value', () => {
-                assert.equal(value, expectedValue);
-            });
-        });
-
-        describe('variant #5: string identifiers prefix', () => {
-            const inputValue: string = 'foo';
-            const expectedValue: string = 'foo';
-
-            let value: boolean | string;
-
-            before(() => {
-                value = IdentifiersPrefixSanitizer(inputValue);
-            });
-
-            it('should sanitize value', () => {
-                assert.equal(value, expectedValue);
-            });
-        });
-    });
-});

+ 5 - 57
test/unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec.ts

@@ -36,62 +36,10 @@ describe('HexadecimalIdentifierNamesGenerator', () => {
     });
     });
 
 
     describe('generateWithPrefix (): string', () => {
     describe('generateWithPrefix (): string', () => {
-        describe('Hexadecimal name with prefix', () => {
-            const regExp: RegExp = /^foo_0x(\w){4,6}$/;
-
-            let identifierNamesGenerator: IIdentifierNamesGenerator,
-                hexadecimalIdentifierName: string;
-
-            before(() => {
-                const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
-
-                inversifyContainerFacade.load('', {
-                    identifiersPrefix: 'foo'
-                });
-                identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
-                    ServiceIdentifiers.IIdentifierNamesGenerator,
-                    IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
-                );
-
-                hexadecimalIdentifierName = identifierNamesGenerator.generateWithPrefix();
-            });
-
-            it('should return hexadecimal name with prefix', () => {
-                assert.match(hexadecimalIdentifierName, regExp);
-            })
-        });
-
-        describe('Hexadecimal name with random prefix', () => {
-            const regExp: RegExp = /^(\w){6}_0x(\w){4,6}$/;
-
-            let identifierNamesGenerator: IIdentifierNamesGenerator,
-                hexadecimalIdentifierName: string;
-
-            before(() => {
-                const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
-
-                inversifyContainerFacade.load('', {
-                    identifiersPrefix: true
-                });
-                identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
-                    ServiceIdentifiers.IIdentifierNamesGenerator,
-                    IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
-                );
-
-                hexadecimalIdentifierName = identifierNamesGenerator.generateWithPrefix();
-            });
-
-            it('should return hexadecimal name with prefix', () => {
-                assert.match(hexadecimalIdentifierName, regExp);
-            })
-        });
-    });
-
-    describe('getPrefix (): string', () => {
-        const expectedIdentifierPrefix: string = 'foo';
+        const regExp: RegExp = /^foo_0x(\w){4,6}$/;
 
 
         let identifierNamesGenerator: IIdentifierNamesGenerator,
         let identifierNamesGenerator: IIdentifierNamesGenerator,
-            identifierPrefix: string;
+            hexadecimalIdentifierName: string;
 
 
         before(() => {
         before(() => {
             const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
             const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
@@ -104,11 +52,11 @@ describe('HexadecimalIdentifierNamesGenerator', () => {
                 IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
                 IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
             );
             );
 
 
-            identifierPrefix = identifierNamesGenerator.getPrefix();
+            hexadecimalIdentifierName = identifierNamesGenerator.generateWithPrefix();
         });
         });
 
 
-        it('should return prefix', () => {
-            assert.equal(identifierPrefix, expectedIdentifierPrefix);
+        it('should return hexadecimal name with prefix', () => {
+            assert.match(hexadecimalIdentifierName, regExp);
         })
         })
     });
     });
 });
 });

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

@@ -130,94 +130,8 @@ describe('MangledIdentifierNamesGenerator', () => {
     });
     });
 
 
     describe('generateWithPrefix (): string', () => {
     describe('generateWithPrefix (): string', () => {
-        describe('Mangled name with prefix', () => {
-            let identifierNamesGenerator: IIdentifierNamesGenerator,
-                mangledIdentifierName: string;
-
-            before(() => {
-                const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
-
-                inversifyContainerFacade.load('', {
-                    identifiersPrefix: 'foo'
-                });
-                identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
-                    ServiceIdentifiers.IIdentifierNamesGenerator,
-                    IdentifierNamesGenerator.MangledIdentifierNamesGenerator
-                );
-            });
-
-            describe('variant #1: initial mangled name', () => {
-                const expectedMangledIdentifierName: string = 'foo_a';
-
-                beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
-                });
-
-                it('should return mangled name with prefix', () => {
-                    assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
-                });
-            });
-
-            describe('variant #2: second mangled name', () => {
-                const expectedMangledIdentifierName: string = 'foo_b';
-
-                beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
-                });
-
-                it('should return mangled name with prefix', () => {
-                    assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
-                });
-            });
-        });
-
-        describe('Mangled name with random prefix', () => {
-            let identifierNamesGenerator: IIdentifierNamesGenerator,
-                mangledIdentifierName: string;
-
-            before(() => {
-                const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
-
-                inversifyContainerFacade.load('', {
-                    identifiersPrefix: true
-                });
-                identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
-                    ServiceIdentifiers.IIdentifierNamesGenerator,
-                    IdentifierNamesGenerator.MangledIdentifierNamesGenerator
-                );
-            });
-
-            describe('variant #1: initial mangled name', () => {
-                const expectedMangledIdentifierNameRegExp: RegExp = /(\w){6}_a/;
-
-                beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
-                });
-
-                it('should return mangled name with prefix', () => {
-                    assert.match(mangledIdentifierName, expectedMangledIdentifierNameRegExp);
-                });
-            });
-
-            describe('variant #2: second mangled name', () => {
-                const expectedMangledIdentifierNameRegExp: RegExp = /(\w){6}_b/;
-
-                beforeEach(() => {
-                    mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
-                });
-
-                it('should return mangled name with prefix', () => {
-                    assert.match(mangledIdentifierName, expectedMangledIdentifierNameRegExp);
-                });
-            });
-        });
-    });
-
-    describe('getPrefix (): string', () => {
-        const expectedIdentifierPrefix: string = 'foo';
-
         let identifierNamesGenerator: IIdentifierNamesGenerator,
         let identifierNamesGenerator: IIdentifierNamesGenerator,
-            identifierPrefix: string;
+            mangledIdentifierName: string;
 
 
         before(() => {
         before(() => {
             const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
             const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
@@ -229,12 +143,30 @@ describe('MangledIdentifierNamesGenerator', () => {
                 ServiceIdentifiers.IIdentifierNamesGenerator,
                 ServiceIdentifiers.IIdentifierNamesGenerator,
                 IdentifierNamesGenerator.MangledIdentifierNamesGenerator
                 IdentifierNamesGenerator.MangledIdentifierNamesGenerator
             );
             );
+        });
+
+        describe('variant #1: initial mangled name', () => {
+            const expectedMangledIdentifierName: string = 'foo_a';
+
+            beforeEach(() => {
+                mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
+            });
 
 
-            identifierPrefix = identifierNamesGenerator.getPrefix();
+            it('should return mangled name with prefix', () => {
+                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+            });
         });
         });
 
 
-        it('should return prefix', () => {
-            assert.equal(identifierPrefix, expectedIdentifierPrefix);
-        })
+        describe('variant #2: second mangled name', () => {
+            const expectedMangledIdentifierName: string = 'foo_b';
+
+            beforeEach(() => {
+                mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
+            });
+
+            it('should return mangled name with prefix', () => {
+                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+            });
+        });
     });
     });
 });
 });

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff