@travetto/transformer 3.4.1 → 3.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/transformer",
3
- "version": "3.4.1",
3
+ "version": "3.4.3",
4
4
  "description": "Functionality for AST transformations, with transformer registration, and general utils",
5
5
  "keywords": [
6
6
  "typescript",
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "@travetto/manifest": "^3.4.0",
28
28
  "tslib": "^2.6.2",
29
- "typescript": "^5.2.2"
29
+ "typescript": "^5.3.2"
30
30
  },
31
31
  "travetto": {
32
32
  "displayName": "Transformation",
package/src/state.ts CHANGED
@@ -295,7 +295,7 @@ export class TransformerState implements State {
295
295
  * @param type
296
296
  */
297
297
  generateUniqueIdentifier(node: ts.Node, type: AnyType): string {
298
- let unique: string | undefined;
298
+ let unique: string[] = [];
299
299
  let name = type.name && !type.name.startsWith('_') ? type.name : '';
300
300
  if (!name && hasEscapedName(node)) {
301
301
  name = `${node.name.escapedText}`;
@@ -308,31 +308,31 @@ export class TransformerState implements State {
308
308
  const fileName = tgt.getSourceFile().fileName;
309
309
 
310
310
  if (fileName === this.source.fileName) { // if in same file suffix with location
311
- const route: string[] = [];
312
311
  let child = node;
313
312
  while (child && !ts.isSourceFile(child)) {
314
313
  if (ts.isFunctionDeclaration(child) || ts.isMethodDeclaration(child) || ts.isClassDeclaration(child)) {
315
314
  if (child.name) {
316
- route.push(child.name.getText());
315
+ unique.push(child.name.getText());
317
316
  }
318
317
  }
319
318
  child = child.parent;
320
319
  }
321
- if (!route.length) { // Only filename
322
- route.push(ts.getLineAndCharacterOfPosition(tgt.getSourceFile(), tgt.getStart()).line.toString());
320
+ if (!unique.length) { // a top level type
321
+ unique.push(ts.getLineAndCharacterOfPosition(tgt.getSourceFile(), tgt.getStart()).line.toString());
323
322
  }
324
- route.unshift(fileName);
325
- unique = SystemUtil.naiveHashString(route.join(':'), 12);
326
323
  } else {
327
324
  // Otherwise treat it as external and add nothing to it
328
325
  }
329
326
  } catch {
330
- // Determine type unique ident
331
- const imp = this.#resolver.getFileImportName(this.source.fileName);
332
- unique = SystemUtil.naiveHashString(`${imp}${type.name ?? 'unknown'}`, 12);
327
+ unique = [type.name ?? 'unknown']; // Type is only unique piece
328
+ }
329
+
330
+ if (unique.length) { // Make unique to file
331
+ unique.unshift(this.#resolver.getFileImportName(this.source.fileName));
332
+ return `${name}__${SystemUtil.naiveHashString(unique.join(':'), 12)}`;
333
+ } else {
334
+ return name;
333
335
  }
334
- // Otherwise read name with uuid
335
- return unique ? `${name}__${unique}` : name;
336
336
  }
337
337
 
338
338
  /**
@@ -1,20 +1,5 @@
1
- import crypto from 'crypto';
2
-
3
1
  export class SystemUtil {
4
2
 
5
- /**
6
- * Generate a random UUID
7
- * @param len The length of the uuid to generate
8
- */
9
- static uuid(len: number = 32): string {
10
- const bytes = crypto.randomBytes(Math.ceil(len / 2));
11
- // eslint-disable-next-line no-bitwise
12
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
13
- // eslint-disable-next-line no-bitwise
14
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
15
- return bytes.toString('hex').substring(0, len);
16
- }
17
-
18
3
  /**
19
4
  * Naive hashing
20
5
  */