@travetto/transformer
Advanced tools
Comparing version 3.4.0 to 3.4.1
{ | ||
"name": "@travetto/transformer", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "Functionality for AST transformations, with transformer registration, and general utils", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -299,2 +299,8 @@ import ts from 'typescript'; | ||
let unique: string | undefined; | ||
let name = type.name && !type.name.startsWith('_') ? type.name : ''; | ||
if (!name && hasEscapedName(node)) { | ||
name = `${node.name.escapedText}`; | ||
} | ||
name ||= 'Shape'; | ||
try { | ||
@@ -306,3 +312,17 @@ // Tie to source location if possible | ||
if (fileName === this.source.fileName) { // if in same file suffix with location | ||
unique = `${ts.getLineAndCharacterOfPosition(tgt.getSourceFile(), tgt.getStart()).line}_${tgt.getEnd() - tgt.getStart()}`; | ||
const route: string[] = []; | ||
let child = node; | ||
while (child && !ts.isSourceFile(child)) { | ||
if (ts.isFunctionDeclaration(child) || ts.isMethodDeclaration(child) || ts.isClassDeclaration(child)) { | ||
if (child.name) { | ||
route.push(child.name.getText()); | ||
} | ||
} | ||
child = child.parent; | ||
} | ||
if (!route.length) { // Only filename | ||
route.push(ts.getLineAndCharacterOfPosition(tgt.getSourceFile(), tgt.getStart()).line.toString()); | ||
} | ||
route.unshift(fileName); | ||
unique = SystemUtil.naiveHashString(route.join(':'), 12); | ||
} else { | ||
@@ -314,11 +334,6 @@ // Otherwise treat it as external and add nothing to it | ||
const imp = this.#resolver.getFileImportName(this.source.fileName); | ||
unique = `${SystemUtil.naiveHash(`${imp}${type.name ?? 'unknown'}`)}`; | ||
unique = SystemUtil.naiveHashString(`${imp}${type.name ?? 'unknown'}`, 12); | ||
} | ||
// Otherwise read name with uuid | ||
let name = type.name && !type.name.startsWith('_') ? type.name : ''; | ||
if (!name && hasEscapedName(node)) { | ||
name = `${node.name.escapedText}`; | ||
} | ||
name ||= 'Shape'; | ||
return unique ? `${name}_${unique}` : name; | ||
return unique ? `${name}__${unique}` : name; | ||
} | ||
@@ -325,0 +340,0 @@ |
@@ -31,2 +31,6 @@ import crypto from 'crypto'; | ||
} | ||
static naiveHashString(text: string, length: number): string { | ||
return this.naiveHash(text).toString().padStart(length, '0').substring(0, length); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94426
2380