Added missing @initializable() decorators

This commit is contained in:
sanex3339
2017-07-25 11:44:48 +03:00
parent 88fc60e496
commit fdbce57232
3 changed files with 8068 additions and 15 deletions
+8047 -1
View File
File diff suppressed because one or more lines are too long
@@ -9,11 +9,14 @@ import { IOptions } from '../interfaces/options/IOptions';
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
import { IVisitor } from '../interfaces/IVisitor';
import { initializable } from '../decorators/Initializable';
@injectable()
export abstract class AbstractNodeTransformer implements INodeTransformer, IInitializable {
/**
* @type {number}
*/
@initializable()
protected nodeIdentifier: number;
/**
+18 -14
View File
@@ -7,9 +7,11 @@ import { Chance } from 'chance';
import { IInitializable } from '../interfaces/IInitializable';
import { IOptions } from '../interfaces/options/IOptions';
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
import { ISourceCode } from '../interfaces/ISourceCode';
import { initializable } from '../decorators/Initializable';
import { Utils } from './Utils';
import { ISourceCode } from '../interfaces/ISourceCode';
@injectable()
export class RandomGenerator implements IRandomGenerator, IInitializable {
@@ -31,6 +33,7 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
/**
* @type {number}
*/
@initializable()
public seed: number;
/**
@@ -46,6 +49,7 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
/**
* @type {Chance.Chance | Chance.SeededChance}
*/
@initializable()
private randomGenerator: Chance.Chance | Chance.SeededChance;
/**
@@ -71,8 +75,20 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
return Math.floor(Math.random() * (max - min + 1) + min);
};
/**
* We need to add numbers from md5 hash of source code to input seed to prevent same String Array name
* for different bundles with same seed
*
* @returns {number}
*/
const getSeed: () => number = (): number => {
const md5Hash: string = md5(this.sourceCode.getSourceCode());
return this.seed + Number(md5Hash.replace(/\D/g, ''));
};
this.seed = this.options.seed !== 0 ? this.options.seed : getRandomInteger(0, 999999999);
this.randomGenerator = new Chance(this.getSeed());
this.randomGenerator = new Chance(getSeed());
console.log(`seed is ${this.seed}`);
}
@@ -145,16 +161,4 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
return randomVariableName;
}
/**
* We need to add numbers from md5 hash of source code to input seed to prevent same String Array name
* for different bundles with same seed
*
* @returns {number}
*/
private getSeed (): number {
const md5Hash: string = md5(this.sourceCode.getSourceCode());
return this.seed + Number(md5Hash.replace(/\D/g, ''));
}
}