@travetto/transformer 3.1.0 → 3.1.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/state.ts +11 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/transformer",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "Functionality for AST transformations, with transformer registration, and general utils",
5
5
  "keywords": [
6
6
  "typescript",
package/src/state.ts CHANGED
@@ -295,24 +295,29 @@ export class TransformerState implements State {
295
295
  * @param type
296
296
  */
297
297
  generateUniqueIdentifier(node: ts.Node, type: AnyType): string {
298
- let unique: string;
298
+ let unique: string | undefined;
299
299
  try {
300
300
  // Tie to source location if possible
301
301
  const tgt = DeclarationUtil.getPrimaryDeclarationNode(type.original!);
302
- unique = `${ts.getLineAndCharacterOfPosition(tgt.getSourceFile(), tgt.getStart()).line}_${tgt.getEnd() - tgt.getStart()}`;
303
- if (tgt.getSourceFile().fileName !== this.source.fileName) { // if in same file
304
- unique = `${SystemUtil.naiveHash(tgt.getSourceFile().fileName)}_${unique}`;
302
+ const fileName = tgt.getSourceFile().fileName;
303
+
304
+ if (fileName === this.source.fileName) { // if in same file suffix with location
305
+ unique = `${ts.getLineAndCharacterOfPosition(tgt.getSourceFile(), tgt.getStart()).line}_${tgt.getEnd() - tgt.getStart()}`;
306
+ } else {
307
+ // Otherwise treat it as external and add nothing to it
305
308
  }
306
309
  } catch {
307
310
  // Determine type unique ident
308
- unique = SystemUtil.uuid(type.name ? 5 : 10);
311
+ const imp = this.#resolver.getFileImportName(this.source.fileName);
312
+ unique = `${SystemUtil.naiveHash(`${imp}${type.name ?? 'unknown'}`)}`;
309
313
  }
310
314
  // Otherwise read name with uuid
311
315
  let name = type.name && !type.name.startsWith('_') ? type.name : '';
312
316
  if (!name && hasEscapedName(node)) {
313
317
  name = `${node.name.escapedText}`;
314
318
  }
315
- return `${name}_${unique}`;
319
+ name ||= 'Shape';
320
+ return unique ? `${name}_${unique}` : name;
316
321
  }
317
322
 
318
323
  /**