1/** 2 * @fileoverview A class of identifiers generator for code path segments. 3 * 4 * Each rule uses the identifier of code path segments to store additional 5 * information of the code path. 6 * 7 * @author Toru Nagashima 8 */ 9 10"use strict"; 11 12//------------------------------------------------------------------------------ 13// Public Interface 14//------------------------------------------------------------------------------ 15 16/** 17 * A generator for unique ids. 18 */ 19class IdGenerator { 20 21 // eslint-disable-next-line jsdoc/require-description 22 /** 23 * @param {string} prefix Optional. A prefix of generated ids. 24 */ 25 constructor(prefix) { 26 this.prefix = String(prefix); 27 this.n = 0; 28 } 29 30 /** 31 * Generates id. 32 * @returns {string} A generated id. 33 */ 34 next() { 35 this.n = 1 + this.n | 0; 36 37 /* istanbul ignore if */ 38 if (this.n < 0) { 39 this.n = 1; 40 } 41 42 return this.prefix + this.n; 43 } 44} 45 46module.exports = IdGenerator; 47