@defold-typescript/types 0.20.7 → 0.21.0

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/index.d.ts CHANGED
@@ -81,14 +81,30 @@ export {
81
81
  type Vector3,
82
82
  type Vector4,
83
83
  } from "./src/core-types";
84
- export { examplesHtmlToMarkdown, htmlToCodeText, htmlToDocText } from "./src/doc-comment";
85
- export { type EmitOptions, emitDeclarations } from "./src/emit-dts";
84
+ export {
85
+ examplesHtmlToMarkdown,
86
+ htmlToCodeText,
87
+ htmlToDocText,
88
+ renderDocComment,
89
+ } from "./src/doc-comment";
90
+ export {
91
+ type EmitOptions,
92
+ emitDeclarations,
93
+ TS_IDENTIFIER,
94
+ TS_RESERVED_NAMES,
95
+ } from "./src/emit-dts";
86
96
  export {
87
97
  hashExampleSource,
88
98
  lookupTranslation,
89
99
  type Translation,
90
100
  type TranslationStore,
91
101
  } from "./src/example-store";
102
+ export {
103
+ hasTopLevelUnion,
104
+ luaMultiReturn,
105
+ needsArrayParens,
106
+ varargElementType,
107
+ } from "./src/library-signature";
92
108
  export {
93
109
  defineGuiScript,
94
110
  defineRenderScript,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.20.7",
3
+ "version": "0.21.0",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/api-doc.ts CHANGED
@@ -35,6 +35,12 @@ export interface ApiFunction {
35
35
  parameters: ApiParameter[];
36
36
  returnValues: ApiParameter[];
37
37
  examples?: string;
38
+ /**
39
+ * A pre-rendered generic-parameter clause (`<T extends druid_widget>`) inserted
40
+ * between the name and the `(` at render time. Present only on LuaLS-lowered
41
+ * library functions; engine ref-docs carry no `generics`, so it stays absent.
42
+ */
43
+ generics?: string;
38
44
  }
39
45
 
40
46
  export interface ApiParameter {
@@ -42,6 +48,13 @@ export interface ApiParameter {
42
48
  doc: string;
43
49
  types: string[];
44
50
  isOptional: boolean;
51
+ /**
52
+ * True for a `...` variadic parameter. `parseParameterList` always sets it
53
+ * (`false` when the ref-doc omits `is_vararg`, so engine docs read as before);
54
+ * optional on the interface so hand-built engine `ApiParameter` literals need
55
+ * not spell out `false`.
56
+ */
57
+ isVararg?: boolean;
45
58
  /**
46
59
  * Per-member docs for an object-literal type, extracted as a tree alongside
47
60
  * the flat `types` token (never inside it). Absent for plain-typed params.
@@ -143,6 +156,7 @@ function parseFunction(element: Record<string, unknown>): ApiFunction {
143
156
  parameters: parseParameterList(element.parameters),
144
157
  returnValues: parseParameterList(element.returnvalues),
145
158
  examples: stringOr(element.examples, ""),
159
+ ...(typeof element.generics === "string" ? { generics: element.generics } : {}),
146
160
  };
147
161
  }
148
162
 
@@ -183,6 +197,7 @@ function parseParameterList(raw: unknown): ApiParameter[] {
183
197
  doc: stringOr(item.doc, ""),
184
198
  types: parseStringArray(item.types),
185
199
  isOptional: item.is_optional === "True",
200
+ isVararg: item.is_vararg === "True",
186
201
  ...(Array.isArray(item.fields) ? { fields: parseParameterList(item.fields) } : {}),
187
202
  });
188
203
  }
package/src/index.ts CHANGED
@@ -42,6 +42,8 @@ export {
42
42
  emitDeclarations,
43
43
  emitSymbolSignatures,
44
44
  type SymbolSignature,
45
+ TS_IDENTIFIER,
46
+ TS_RESERVED_NAMES,
45
47
  } from "./emit-dts";
46
48
  export {
47
49
  hashExampleSource,
@@ -49,6 +51,12 @@ export {
49
51
  type Translation,
50
52
  type TranslationStore,
51
53
  } from "./example-store";
54
+ export {
55
+ hasTopLevelUnion,
56
+ luaMultiReturn,
57
+ needsArrayParens,
58
+ varargElementType,
59
+ } from "./library-signature";
52
60
  export {
53
61
  defineGuiScript,
54
62
  defineRenderScript,
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Pure string helpers for rendering variadic parameters and multi-value returns
3
+ * the way the library `.d.ts` emitter does. Shared by the emitter
4
+ * (`packages/library-types`) and the docs-site renderer (`packages/docs-site`),
5
+ * which both depend on `@defold-typescript/types`, so a library `/api` signature
6
+ * cannot drift from the shipped `generated/<ns>.d.ts` for these two shapes — the
7
+ * same anti-drift move the type/name/generic primitives already use.
8
+ */
9
+
10
+ /** True when a top-level `|` (a union) appears in a mapped type, honoring bracket depth. */
11
+ export function hasTopLevelUnion(ts: string): boolean {
12
+ let depth = 0;
13
+ for (let i = 0; i < ts.length; i++) {
14
+ const c = ts[i];
15
+ if (c === "<" || c === "(" || c === "[" || c === "{") depth++;
16
+ else if (c === ">" || c === ")" || c === "]" || c === "}") depth = Math.max(0, depth - 1);
17
+ else if (depth === 0 && c === "|") return true;
18
+ }
19
+ return false;
20
+ }
21
+
22
+ /** An array element needs parentheses when it is a union, a function, or an object. */
23
+ export function needsArrayParens(ts: string): boolean {
24
+ return hasTopLevelUnion(ts) || ts.includes("=>") || ts.startsWith("{");
25
+ }
26
+
27
+ /** A vararg's element type arrayified: `string` -> `string[]`, `a | b` -> `(a | b)[]`. */
28
+ export function varargElementType(mapped: string): string {
29
+ return needsArrayParens(mapped) ? `(${mapped})[]` : `${mapped}[]`;
30
+ }
31
+
32
+ /** Wrap `>1` mapped return tokens in the `LuaMultiReturn<[...]>` tuple form. */
33
+ export function luaMultiReturn(mapped: readonly string[]): string {
34
+ return `LuaMultiReturn<[${mapped.join(", ")}]>`;
35
+ }