versioned-d.ts-tools 0.3.0 → 0.4.1

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.
@@ -7,7 +7,8 @@ declare enum FieldType {
7
7
  Property = "Property",
8
8
  Method = "Method",
9
9
  Event = "Event",
10
- Enum = "Enum"
10
+ Enum = "Enum",
11
+ Function = "Function"
11
12
  }
12
13
  declare class FieldStruct {
13
14
  declarationString: string;
@@ -39,6 +39,7 @@ const ts = __importStar(require("typescript"));
39
39
  // capturing these because of eccentricities with the compiler ordering
40
40
  let topClass = null;
41
41
  let lastItem = null;
42
+ let globalFunctionsClass = null;
42
43
  var ClassType;
43
44
  (function (ClassType) {
44
45
  ClassType["Class"] = "Class";
@@ -51,6 +52,7 @@ var FieldType;
51
52
  FieldType["Method"] = "Method";
52
53
  FieldType["Event"] = "Event";
53
54
  FieldType["Enum"] = "Enum";
55
+ FieldType["Function"] = "Function";
54
56
  })(FieldType || (FieldType = {}));
55
57
  class FieldStruct {
56
58
  constructor(decString, commentString, fieldType, fieldName) {
@@ -167,8 +169,14 @@ class APISet {
167
169
  !clas.getClassName().endsWith("LoadOptions") &&
168
170
  !clas.getClassName().endsWith("Data")) {
169
171
  const className = clas.getClassName();
170
- output += "|[" + className + "](/"
171
- + relativePath + className.toLowerCase() + ")|";
172
+ // Special handling for <global> - no link
173
+ if (className === "<global>") {
174
+ output += "|*" + className + "*|";
175
+ }
176
+ else {
177
+ output += "|[" + className + "](/"
178
+ + relativePath + className.toLowerCase() + ")|";
179
+ }
172
180
  // Ignore the following:
173
181
  // - String literal overloads.
174
182
  // - `load`, `set`, `track`, `untrack`, and `toJSON` methods
@@ -201,6 +209,14 @@ class APISet {
201
209
  newItemText = newItemText.replace(/\?/g, "");
202
210
  newItemText = newItemText.substring(0, newItemText.indexOf(":"));
203
211
  }
212
+ else if (field.type === FieldType.Function) {
213
+ // For functions, extract just the function signature
214
+ newItemText = newItemText.replace(/export\s+function\s+/g, "");
215
+ // Remove the return type if it exists (everything after the last :)
216
+ if (newItemText.lastIndexOf(":") > newItemText.indexOf(")")) {
217
+ newItemText = newItemText.substring(0, newItemText.lastIndexOf(":"));
218
+ }
219
+ }
204
220
  else {
205
221
  // Remove the return type.
206
222
  newItemText = newItemText.substring(0, newItemText.lastIndexOf(":"));
@@ -262,14 +278,25 @@ function removeAtLink(commentText) {
262
278
  return commentText;
263
279
  }
264
280
  function buildFieldLink(relativePath, className, field) {
281
+ // Special handling for global functions - use a different link format
282
+ if (className === "<global>") {
283
+ let hostName = relativePath.substring(relativePath.indexOf("/api/") + 5, relativePath.lastIndexOf("/"));
284
+ let fileName = relativePath.substring(relativePath.lastIndexOf("/") + 1, relativePath.lastIndexOf("."));
285
+ let anchorPrefix = hostName + "-" + fileName + "-";
286
+ return "/" + relativePath.substring(0, relativePath.lastIndexOf(".")) + "#" + anchorPrefix + field.name.toLowerCase() + "-function";
287
+ }
265
288
  // Build the standard link anchor format based on host.
266
289
  let hostName = relativePath.substring(relativePath.indexOf("/api/") + 5, relativePath.lastIndexOf("/"));
267
290
  let fileName = relativePath.substring(relativePath.lastIndexOf("/") + 1, relativePath.lastIndexOf("."));
268
291
  let anchorPrefix = hostName + "-" + fileName + "-";
269
- let fieldLink = "/" + relativePath + className.toLowerCase() + "#" + anchorPrefix + className.toLowerCase() + "-" + field.name.toLowerCase() + (field.type === FieldType.Method ? "-member(1)" : "-member");
292
+ let fieldLink = "/" + relativePath + className.toLowerCase() + "#" + anchorPrefix + className.toLowerCase() + "-" + field.name.toLowerCase() + ((field.type === FieldType.Method || field.type === FieldType.Function) ? "-member(1)" : "-member");
270
293
  return fieldLink;
271
294
  }
272
295
  function parseDTS(fileName, fileContents) {
296
+ // Reset global state for new parse
297
+ topClass = null;
298
+ lastItem = null;
299
+ globalFunctionsClass = null;
273
300
  const node = ts.createSourceFile(fileName, fileContents, ts.ScriptTarget.ES2015, true);
274
301
  const allClasses = new APISet();
275
302
  parseDTSInternal(node, allClasses);
@@ -286,6 +313,9 @@ function parseDTSInternal(node, allClasses) {
286
313
  case ts.SyntaxKind.EnumDeclaration:
287
314
  parseDTSTopLevelItem(node, allClasses, ClassType.Enum);
288
315
  break;
316
+ case ts.SyntaxKind.FunctionDeclaration:
317
+ parseDTSGlobalFunctionItem(node, allClasses);
318
+ break;
289
319
  case ts.SyntaxKind.PropertySignature:
290
320
  parseDTSFieldItem(node, FieldType.Property);
291
321
  break;
@@ -331,4 +361,15 @@ function parseDTSFieldItem(node, type) {
331
361
  topClass.fields.push(newField);
332
362
  lastItem = newField;
333
363
  }
364
+ function parseDTSGlobalFunctionItem(node, allClasses) {
365
+ // Create a "<global>" class to hold top-level functions if it doesn't exist
366
+ if (globalFunctionsClass === null) {
367
+ globalFunctionsClass = new ClassStruct("<global>", "", ClassType.Interface);
368
+ allClasses.addClass(globalFunctionsClass);
369
+ }
370
+ const functionName = node.name ? node.name.getText() : "anonymous";
371
+ const newFunction = new FieldStruct(node.getText(), "", FieldType.Function, functionName);
372
+ globalFunctionsClass.fields.push(newFunction);
373
+ lastItem = newFunction;
374
+ }
334
375
  //# sourceMappingURL=dts-utilities.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versioned-d.ts-tools",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Tools for managing versioned TypeScript definition files",
5
5
  "main": "dist/index.js",
6
6
  "bin": {