boperators 0.3.0 → 0.3.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.
@@ -1,9 +1,17 @@
1
1
  import { type Node } from "ts-morph";
2
2
  /**
3
- * Strips `import("...").` qualification from a type name as returned by
4
- * ts-morph's `getType().getText()`. Language-server and cross-package contexts
5
- * produce fully-qualified names like `import("/path/to/file").ClassName`, but
6
- * overloads are keyed by short class names.
3
+ * Strips `import("...").` qualification and generic type parameters from a
4
+ * type name as returned by ts-morph's `getType().getText()`.
5
+ *
6
+ * Language-server and cross-package contexts produce fully-qualified names like
7
+ * `import("/path/to/file").ClassName`, and generic classes produce names like
8
+ * `ClassName<T>`. Overloads are keyed by bare class names, so both forms must
9
+ * be stripped.
10
+ *
11
+ * Note: generic stripping cuts at the first `<`, so union/intersection types
12
+ * that themselves contain generic members (e.g. `Foo<T> | Bar`) are reduced to
13
+ * the first segment only. Operator overload parameter types are always single
14
+ * type names, so this does not arise in practice.
7
15
  */
8
16
  export declare function normalizeTypeName(typeName: string): string;
9
17
  /**
@@ -4,13 +4,23 @@ exports.normalizeTypeName = normalizeTypeName;
4
4
  exports.resolveExpressionType = resolveExpressionType;
5
5
  const ts_morph_1 = require("ts-morph");
6
6
  /**
7
- * Strips `import("...").` qualification from a type name as returned by
8
- * ts-morph's `getType().getText()`. Language-server and cross-package contexts
9
- * produce fully-qualified names like `import("/path/to/file").ClassName`, but
10
- * overloads are keyed by short class names.
7
+ * Strips `import("...").` qualification and generic type parameters from a
8
+ * type name as returned by ts-morph's `getType().getText()`.
9
+ *
10
+ * Language-server and cross-package contexts produce fully-qualified names like
11
+ * `import("/path/to/file").ClassName`, and generic classes produce names like
12
+ * `ClassName<T>`. Overloads are keyed by bare class names, so both forms must
13
+ * be stripped.
14
+ *
15
+ * Note: generic stripping cuts at the first `<`, so union/intersection types
16
+ * that themselves contain generic members (e.g. `Foo<T> | Bar`) are reduced to
17
+ * the first segment only. Operator overload parameter types are always single
18
+ * type names, so this does not arise in practice.
11
19
  */
12
20
  function normalizeTypeName(typeName) {
13
- return typeName.replace(/import\("[^"]*"\)\./g, "");
21
+ const withoutImport = typeName.replace(/import\("[^"]*"\)\./g, "");
22
+ const genericIdx = withoutImport.indexOf("<");
23
+ return genericIdx === -1 ? withoutImport : withoutImport.slice(0, genericIdx);
14
24
  }
15
25
  /**
16
26
  * Resolves the effective type name for a node in a binary expression.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boperators",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "license": "MIT",
5
5
  "description": "Operator overloading for TypeScript.",
6
6
  "repository": {