* Generate a name that is unique within the current file and doesn't conflict with any names * in global scope. The name is formed by adding an '_n' suffix to the specified base name, * where n is a positive integer. Note that names generated by makeTempVariableName and *
(baseName, checkFn, optimistic, scoped)
| 114560 | * If `optimistic` is set, the first instance will use 'baseName' verbatim instead of 'baseName_1' |
| 114561 | */ |
| 114562 | function makeUniqueName(baseName, checkFn, optimistic, scoped) { |
| 114563 | if (checkFn === void 0) { checkFn = isUniqueName; } |
| 114564 | if (optimistic) { |
| 114565 | if (checkFn(baseName)) { |
| 114566 | if (scoped) { |
| 114567 | reserveNameInNestedScopes(baseName); |
| 114568 | } |
| 114569 | else { |
| 114570 | generatedNames.add(baseName); |
| 114571 | } |
| 114572 | return baseName; |
| 114573 | } |
| 114574 | } |
| 114575 | // Find the first unique 'name_n', where n is a positive number |
| 114576 | if (baseName.charCodeAt(baseName.length - 1) !== 95 /* CharacterCodes._ */) { |
| 114577 | baseName += "_"; |
| 114578 | } |
| 114579 | var i = 1; |
| 114580 | while (true) { |
| 114581 | var generatedName = baseName + i; |
| 114582 | if (checkFn(generatedName)) { |
| 114583 | if (scoped) { |
| 114584 | reserveNameInNestedScopes(generatedName); |
| 114585 | } |
| 114586 | else { |
| 114587 | generatedNames.add(generatedName); |
| 114588 | } |
| 114589 | return generatedName; |
| 114590 | } |
| 114591 | i++; |
| 114592 | } |
| 114593 | } |
| 114594 | function makeFileLevelOptimisticUniqueName(name) { |
| 114595 | return makeUniqueName(name, isFileLevelUniqueName, /*optimistic*/ true); |
| 114596 | } |
no test coverage detected