@travetto/transformer
Advanced tools
Comparing version 3.4.2 to 3.4.3
{ | ||
"name": "@travetto/transformer", | ||
"version": "3.4.2", | ||
"version": "3.4.3", | ||
"description": "Functionality for AST transformations, with transformer registration, and general utils", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -298,3 +298,3 @@ import ts from 'typescript'; | ||
generateUniqueIdentifier(node: ts.Node, type: AnyType): string { | ||
let unique: string | undefined; | ||
let unique: string[] = []; | ||
let name = type.name && !type.name.startsWith('_') ? type.name : ''; | ||
@@ -312,3 +312,2 @@ if (!name && hasEscapedName(node)) { | ||
if (fileName === this.source.fileName) { // if in same file suffix with location | ||
const route: string[] = []; | ||
let child = node; | ||
@@ -318,3 +317,3 @@ while (child && !ts.isSourceFile(child)) { | ||
if (child.name) { | ||
route.push(child.name.getText()); | ||
unique.push(child.name.getText()); | ||
} | ||
@@ -324,7 +323,5 @@ } | ||
} | ||
if (!route.length) { // Only filename | ||
route.push(ts.getLineAndCharacterOfPosition(tgt.getSourceFile(), tgt.getStart()).line.toString()); | ||
if (!unique.length) { // a top level type | ||
unique.push(ts.getLineAndCharacterOfPosition(tgt.getSourceFile(), tgt.getStart()).line.toString()); | ||
} | ||
route.unshift(fileName); | ||
unique = SystemUtil.naiveHashString(route.join(':'), 12); | ||
} else { | ||
@@ -334,8 +331,11 @@ // Otherwise treat it as external and add nothing to it | ||
} catch { | ||
// Determine type unique ident | ||
const imp = this.#resolver.getFileImportName(this.source.fileName); | ||
unique = SystemUtil.naiveHashString(`${imp}${type.name ?? 'unknown'}`, 12); | ||
unique = [type.name ?? 'unknown']; // Type is only unique piece | ||
} | ||
// Otherwise read name with uuid | ||
return unique ? `${name}__${unique}` : name; | ||
if (unique.length) { // Make unique to file | ||
unique.unshift(this.#resolver.getFileImportName(this.source.fileName)); | ||
return `${name}__${SystemUtil.naiveHashString(unique.join(':'), 12)}`; | ||
} else { | ||
return name; | ||
} | ||
} | ||
@@ -342,0 +342,0 @@ |
@@ -1,19 +0,4 @@ | ||
import crypto from 'crypto'; | ||
export class SystemUtil { | ||
/** | ||
* Generate a random UUID | ||
* @param len The length of the uuid to generate | ||
*/ | ||
static uuid(len: number = 32): string { | ||
const bytes = crypto.randomBytes(Math.ceil(len / 2)); | ||
// eslint-disable-next-line no-bitwise | ||
bytes[6] = (bytes[6] & 0x0f) | 0x40; | ||
// eslint-disable-next-line no-bitwise | ||
bytes[8] = (bytes[8] & 0x3f) | 0x80; | ||
return bytes.toString('hex').substring(0, len); | ||
} | ||
/** | ||
* Naive hashing | ||
@@ -20,0 +5,0 @@ */ |
93879
14
2366
6