goscript 0.0.13 → 0.0.16

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 (186) hide show
  1. package/LICENSE +2 -1
  2. package/README.md +163 -45
  3. package/builtin/builtin.ts +1169 -178
  4. package/cmd/goscript/cmd_compile.go +2 -2
  5. package/compiler/analysis.go +726 -0
  6. package/compiler/compiler.go +5701 -4
  7. package/compiler/compiler_test.go +104 -0
  8. package/compiler/config.go +3 -3
  9. package/compiler/config_test.go +89 -0
  10. package/compiler/index.ts +1 -1
  11. package/compiler/output.go +26 -0
  12. package/compiler/write-type-spec.go +506 -0
  13. package/compiler/writer.go +11 -0
  14. package/dist/builtin/builtin.d.ts +204 -67
  15. package/dist/builtin/builtin.js +846 -144
  16. package/dist/builtin/builtin.js.map +1 -1
  17. package/dist/compiler/index.d.ts +1 -1
  18. package/go.mod +5 -6
  19. package/go.sum +6 -11
  20. package/package.json +21 -5
  21. package/compiler/compile.go +0 -190
  22. package/compiler/compile_comment.go +0 -41
  23. package/compiler/compile_decls.go +0 -84
  24. package/compiler/compile_expr.go +0 -1022
  25. package/compiler/compile_field.go +0 -110
  26. package/compiler/compile_spec.go +0 -566
  27. package/compiler/compile_stmt.go +0 -1616
  28. package/compiler/context.go +0 -9
  29. package/compiler/file_compiler.go +0 -80
  30. package/compiler/output_path.go +0 -31
  31. package/compiler/pkg_compiler.go +0 -72
  32. package/compiler/types/tokens.go +0 -66
  33. package/compiler/types/types.go +0 -46
  34. package/dist/compliance/tests/array_literal/array_literal.gs.d.ts +0 -1
  35. package/dist/compliance/tests/array_literal/array_literal.gs.js +0 -15
  36. package/dist/compliance/tests/array_literal/array_literal.gs.js.map +0 -1
  37. package/dist/compliance/tests/async_basic/async_basic.gs.d.ts +0 -1
  38. package/dist/compliance/tests/async_basic/async_basic.gs.js +0 -24
  39. package/dist/compliance/tests/async_basic/async_basic.gs.js.map +0 -1
  40. package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.d.ts +0 -1
  41. package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.js +0 -82
  42. package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.js.map +0 -1
  43. package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.d.ts +0 -1
  44. package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.js +0 -16
  45. package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.js.map +0 -1
  46. package/dist/compliance/tests/boolean_logic/boolean_logic.gs.d.ts +0 -1
  47. package/dist/compliance/tests/boolean_logic/boolean_logic.gs.js +0 -14
  48. package/dist/compliance/tests/boolean_logic/boolean_logic.gs.js.map +0 -1
  49. package/dist/compliance/tests/channel_basic/channel_basic.gs.d.ts +0 -1
  50. package/dist/compliance/tests/channel_basic/channel_basic.gs.js +0 -14
  51. package/dist/compliance/tests/channel_basic/channel_basic.gs.js.map +0 -1
  52. package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.d.ts +0 -1
  53. package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.js +0 -27
  54. package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.js.map +0 -1
  55. package/dist/compliance/tests/constants/constants.gs.d.ts +0 -1
  56. package/dist/compliance/tests/constants/constants.gs.js +0 -16
  57. package/dist/compliance/tests/constants/constants.gs.js.map +0 -1
  58. package/dist/compliance/tests/copy_independence/copy_independence.gs.d.ts +0 -1
  59. package/dist/compliance/tests/copy_independence/copy_independence.gs.js +0 -33
  60. package/dist/compliance/tests/copy_independence/copy_independence.gs.js.map +0 -1
  61. package/dist/compliance/tests/defer_statement/defer_statement.gs.d.ts +0 -1
  62. package/dist/compliance/tests/defer_statement/defer_statement.gs.js +0 -75
  63. package/dist/compliance/tests/defer_statement/defer_statement.gs.js.map +0 -1
  64. package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.d.ts +0 -1
  65. package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.js +0 -37
  66. package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.js.map +0 -1
  67. package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.d.ts +0 -1
  68. package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.js +0 -29
  69. package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.js.map +0 -1
  70. package/dist/compliance/tests/float64/float64.gs.d.ts +0 -1
  71. package/dist/compliance/tests/float64/float64.gs.js +0 -24
  72. package/dist/compliance/tests/float64/float64.gs.js.map +0 -1
  73. package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.d.ts +0 -1
  74. package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.js +0 -10
  75. package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.js.map +0 -1
  76. package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.d.ts +0 -1
  77. package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.js +0 -11
  78. package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.js.map +0 -1
  79. package/dist/compliance/tests/for_loop_condition_only/main.gs.d.ts +0 -1
  80. package/dist/compliance/tests/for_loop_condition_only/main.gs.js +0 -10
  81. package/dist/compliance/tests/for_loop_condition_only/main.gs.js.map +0 -1
  82. package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.d.ts +0 -1
  83. package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.js +0 -14
  84. package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.js.map +0 -1
  85. package/dist/compliance/tests/for_range/for_range.gs.d.ts +0 -1
  86. package/dist/compliance/tests/for_range/for_range.gs.js +0 -39
  87. package/dist/compliance/tests/for_range/for_range.gs.js.map +0 -1
  88. package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.d.ts +0 -1
  89. package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.js +0 -15
  90. package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.js.map +0 -1
  91. package/dist/compliance/tests/func_literal/func_literal.gs.d.ts +0 -1
  92. package/dist/compliance/tests/func_literal/func_literal.gs.js +0 -10
  93. package/dist/compliance/tests/func_literal/func_literal.gs.js.map +0 -1
  94. package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.d.ts +0 -12
  95. package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.js +0 -30
  96. package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.js.map +0 -1
  97. package/dist/compliance/tests/if_statement/if_statement.gs.d.ts +0 -1
  98. package/dist/compliance/tests/if_statement/if_statement.gs.js +0 -13
  99. package/dist/compliance/tests/if_statement/if_statement.gs.js.map +0 -1
  100. package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.d.ts +0 -1
  101. package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.js +0 -12
  102. package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.js.map +0 -1
  103. package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.d.ts +0 -1
  104. package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.js +0 -34
  105. package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.js.map +0 -1
  106. package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.d.ts +0 -1
  107. package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.js +0 -32
  108. package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.js.map +0 -1
  109. package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.d.ts +0 -1
  110. package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.js +0 -40
  111. package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.js.map +0 -1
  112. package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.d.ts +0 -1
  113. package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.js +0 -51
  114. package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.js.map +0 -1
  115. package/dist/compliance/tests/map_support/map_support.gs.d.ts +0 -1
  116. package/dist/compliance/tests/map_support/map_support.gs.js +0 -88
  117. package/dist/compliance/tests/map_support/map_support.gs.js.map +0 -1
  118. package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.d.ts +0 -1
  119. package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.js +0 -24
  120. package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.js.map +0 -1
  121. package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.d.ts +0 -1
  122. package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.js +0 -33
  123. package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.js.map +0 -1
  124. package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.d.ts +0 -1
  125. package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.js +0 -22
  126. package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.js.map +0 -1
  127. package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.d.ts +0 -1
  128. package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.js +0 -33
  129. package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.js.map +0 -1
  130. package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.d.ts +0 -1
  131. package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.js +0 -17
  132. package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.js.map +0 -1
  133. package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.d.ts +0 -1
  134. package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.js +0 -29
  135. package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.js.map +0 -1
  136. package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.d.ts +0 -1
  137. package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.js +0 -27
  138. package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.js.map +0 -1
  139. package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.d.ts +0 -1
  140. package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.js +0 -22
  141. package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.js.map +0 -1
  142. package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.d.ts +0 -1
  143. package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.js +0 -20
  144. package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.js.map +0 -1
  145. package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.d.ts +0 -1
  146. package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.js +0 -28
  147. package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.js.map +0 -1
  148. package/dist/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.d.ts +0 -1
  149. package/dist/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.js +0 -30
  150. package/dist/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.js.map +0 -1
  151. package/dist/compliance/tests/select_statement/select_statement.gs.d.ts +0 -1
  152. package/dist/compliance/tests/select_statement/select_statement.gs.js +0 -207
  153. package/dist/compliance/tests/select_statement/select_statement.gs.js.map +0 -1
  154. package/dist/compliance/tests/simple/simple.gs.d.ts +0 -1
  155. package/dist/compliance/tests/simple/simple.gs.js +0 -6
  156. package/dist/compliance/tests/simple/simple.gs.js.map +0 -1
  157. package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.d.ts +0 -1
  158. package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.js +0 -24
  159. package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.js.map +0 -1
  160. package/dist/compliance/tests/slices/slices.gs.d.ts +0 -1
  161. package/dist/compliance/tests/slices/slices.gs.js +0 -294
  162. package/dist/compliance/tests/slices/slices.gs.js.map +0 -1
  163. package/dist/compliance/tests/string_conversion/string_conversion.gs.d.ts +0 -1
  164. package/dist/compliance/tests/string_conversion/string_conversion.gs.js +0 -41
  165. package/dist/compliance/tests/string_conversion/string_conversion.gs.js.map +0 -1
  166. package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.d.ts +0 -1
  167. package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.js +0 -17
  168. package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.js.map +0 -1
  169. package/dist/compliance/tests/struct_embedding/struct_embedding.gs.d.ts +0 -1
  170. package/dist/compliance/tests/struct_embedding/struct_embedding.gs.js +0 -48
  171. package/dist/compliance/tests/struct_embedding/struct_embedding.gs.js.map +0 -1
  172. package/dist/compliance/tests/struct_field_access/struct_field_access.gs.d.ts +0 -1
  173. package/dist/compliance/tests/struct_field_access/struct_field_access.gs.js +0 -19
  174. package/dist/compliance/tests/struct_field_access/struct_field_access.gs.js.map +0 -1
  175. package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.d.ts +0 -1
  176. package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.js +0 -26
  177. package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.js.map +0 -1
  178. package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.d.ts +0 -1
  179. package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.js +0 -30
  180. package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.js.map +0 -1
  181. package/dist/compliance/tests/switch_statement/switch_statement.gs.d.ts +0 -1
  182. package/dist/compliance/tests/switch_statement/switch_statement.gs.js +0 -76
  183. package/dist/compliance/tests/switch_statement/switch_statement.gs.js.map +0 -1
  184. package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.d.ts +0 -1
  185. package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.js +0 -31
  186. package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.js.map +0 -1
@@ -1,45 +1,82 @@
1
1
  /**
2
- * Creates a new slice (TypeScript array) with the specified length and capacity.
3
- * @param len The length of the slice.
4
- * @param cap The capacity of the slice (optional).
5
- * @returns A new TypeScript array representing the slice.
2
+ * GoSliceObject contains metadata for complex slice views
6
3
  */
7
- export declare const makeSlice: <T>(len: number, cap?: number) => Array<T> & {
8
- __capacity?: number;
4
+ interface GoSliceObject<T> {
5
+ backing: T[];
6
+ offset: number;
7
+ length: number;
8
+ capacity: number;
9
+ }
10
+ /**
11
+ * SliceProxy is a proxy object for complex slices
12
+ */
13
+ export type SliceProxy<T> = T[] & {
14
+ __meta__: GoSliceObject<T>;
9
15
  };
10
16
  /**
11
- * Creates a new slice header that shares the backing array.
17
+ * Slice<T> is a union type that is either a plain array or a proxy
18
+ * null represents the nil state.
19
+ */
20
+ export type Slice<T> = T[] | SliceProxy<T> | null;
21
+ export declare function asArray<T>(slice: Slice<T>): T[];
22
+ /**
23
+ * Creates a new slice with the specified length and capacity.
24
+ * @param length The length of the slice.
25
+ * @param capacity The capacity of the slice (optional).
26
+ * @returns A new slice.
27
+ */
28
+ export declare const makeSlice: <T>(length: number, capacity?: number) => Slice<T>;
29
+ /**
30
+ * goSlice creates a slice from s[low:high:max]
12
31
  * Arguments mirror Go semantics; omitted indices are undefined.
13
32
  *
14
- * @param arr The original slice/array produced by makeSlice or another slice
15
- * @param low Starting index (defaults to 0)
16
- * @param high Ending index (defaults to arr.length)
17
- * @param max Capacity limit (defaults to original capacity)
18
- */
19
- export declare const slice: <T>(arr: Array<T> & {
20
- __capacity?: number;
21
- }, low?: number, high?: number, max?: number) => Array<T> & {
22
- __capacity?: number;
23
- };
33
+ * @param s The original slice
34
+ * @param low Starting index (defaults to 0)
35
+ * @param high Ending index (defaults to s.length)
36
+ * @param max Capacity limit (defaults to original capacity)
37
+ */
38
+ export declare const goSlice: <T>(s: Slice<T>, low?: number, high?: number, max?: number) => Slice<T>;
24
39
  /**
25
40
  * Creates a new map (TypeScript Map).
26
41
  * @returns A new TypeScript Map.
27
42
  */
28
43
  export declare const makeMap: <K, V>() => Map<K, V>;
29
44
  /**
30
- * Returns the length of a collection (string, array, or map).
31
- * @param collection The collection to get the length of.
45
+ * Converts a JavaScript array to a Go slice.
46
+ * For multi-dimensional arrays, recursively converts nested arrays to slices.
47
+ * @param arr The JavaScript array to convert
48
+ * @param depth How many levels of nesting to convert (default: 1, use Infinity for all levels)
49
+ * @returns A Go slice containing the same elements
50
+ */
51
+ export declare const arrayToSlice: <T>(arr: T[] | null | undefined, depth?: number) => T[];
52
+ /**
53
+ * Returns the length of a collection (string, array, slice, map, or set).
54
+ * @param obj The collection to get the length of.
32
55
  * @returns The length of the collection.
33
56
  */
34
- export declare const len: <T>(collection: string | Array<T> | Map<unknown, unknown>) => number;
57
+ export declare const len: <T = unknown, V = unknown>(obj: string | Array<T> | Slice<T> | Map<T, V> | Set<T> | null | undefined) => number;
35
58
  /**
36
- * Returns the capacity of a slice (TypeScript array).
37
- * @param slice The slice (TypeScript array).
59
+ * Returns the capacity of a slice.
60
+ * @param obj The slice.
38
61
  * @returns The capacity of the slice.
39
62
  */
40
- export declare const cap: <T>(slice: Array<T> & {
41
- __capacity?: number;
42
- }) => number;
63
+ export declare const cap: <T>(obj: Slice<T>) => number;
64
+ /**
65
+ * Appends elements to a slice.
66
+ * Note: In Go, append can return a new slice if the underlying array is reallocated.
67
+ * This helper emulates that by returning the modified or new slice.
68
+ * @param slice The slice to append to.
69
+ * @param elements The elements to append.
70
+ * @returns The modified or new slice.
71
+ */
72
+ export declare const append: <T>(slice: Slice<T>, ...elements: T[]) => T[];
73
+ /**
74
+ * Copies elements from src to dst.
75
+ * @param dst The destination slice.
76
+ * @param src The source slice.
77
+ * @returns The number of elements copied.
78
+ */
79
+ export declare const copy: <T>(dst: Slice<T>, src: Slice<T>) => number;
43
80
  /**
44
81
  * Represents the Go error type (interface).
45
82
  */
@@ -57,7 +94,27 @@ export declare const stringToRunes: (str: string) => number[];
57
94
  * @param runes The input array of numbers representing Unicode code points.
58
95
  * @returns The resulting string.
59
96
  */
60
- export declare const runesToString: (runes: number[]) => string;
97
+ export declare const runesToString: (runes: Slice<number>) => string;
98
+ /**
99
+ * Converts a number to a byte (uint8) by truncating to the range 0-255.
100
+ * Equivalent to Go's byte() conversion.
101
+ * @param n The number to convert to a byte.
102
+ * @returns The byte value (0-255).
103
+ */
104
+ export declare const byte: (n: number) => number;
105
+ /** Box represents a Go variable which can be referred to by other variables.
106
+ *
107
+ * For example:
108
+ * var myVariable int
109
+ *
110
+ */
111
+ export type Box<T> = {
112
+ value: T;
113
+ };
114
+ /** Wrap a non-null T in a pointer‐box. */
115
+ export declare function box<T>(v: T): Box<T>;
116
+ /** Dereference a pointer‐box, throws on null → simulates Go panic. */
117
+ export declare function unbox<T>(b: Box<T>): T;
61
118
  /**
62
119
  * Gets a value from a map, with a default value if the key doesn't exist.
63
120
  * @param map The map to get from.
@@ -86,53 +143,134 @@ export declare const deleteMapEntry: <K, V>(map: Map<K, V>, key: K) => void;
86
143
  * @returns True if the key exists, false otherwise.
87
144
  */
88
145
  export declare const mapHas: <K, V>(map: Map<K, V>, key: K) => boolean;
89
- /**
90
- * Appends elements to a slice (TypeScript array).
91
- * Note: In Go, append can return a new slice if the underlying array is reallocated.
92
- * This helper emulates that by returning the modified array.
93
- * @param slice The slice (TypeScript array) to append to.
94
- * @param elements The elements to append.
95
- * @returns The modified slice (TypeScript array).
96
- */
97
- export declare const append: <T>(slice: Array<T> & {
98
- __capacity?: number;
99
- }, ...elements: T[]) => Array<T> & {
100
- __capacity?: number;
101
- };
102
146
  /**
103
147
  * Represents the kinds of Go types that can be registered at runtime.
104
148
  */
105
149
  export declare enum TypeKind {
106
- Struct = "struct",
107
- Interface = "interface",
108
150
  Basic = "basic",
109
- Pointer = "pointer",
110
- Slice = "slice",
151
+ Interface = "interface",
152
+ Struct = "struct",
111
153
  Map = "map",
112
- Channel = "channel",
113
- Function = "function"
154
+ Slice = "slice",
155
+ Array = "array",
156
+ Pointer = "pointer",
157
+ Function = "function",
158
+ Channel = "channel"
114
159
  }
115
160
  /**
116
- * Represents type information for a Go type in the runtime.
161
+ * TypeInfo is used for runtime type checking.
162
+ * Can be a registered type (from typeRegistry) or an ad-hoc type description.
163
+ * When used as input to typeAssert, it can be a string (type name) or a structured description.
164
+ */
165
+ /**
166
+ * Base type information shared by all type kinds
117
167
  */
118
- export interface TypeInfo {
119
- name: string;
168
+ export interface BaseTypeInfo {
169
+ name?: string;
120
170
  kind: TypeKind;
121
- zeroValue: any;
122
- methods?: Set<string>;
123
- constructor?: new (...args: any[]) => any;
171
+ zeroValue?: any;
124
172
  }
125
173
  /**
126
- * Registers a type with the runtime type system.
174
+ * Type information for struct types
175
+ */
176
+ export interface StructTypeInfo extends BaseTypeInfo {
177
+ kind: TypeKind.Struct;
178
+ methods: Set<string>;
179
+ ctor?: new (...args: any[]) => any;
180
+ fields?: Set<string>;
181
+ fieldTypes?: Record<string, TypeInfo | string>;
182
+ }
183
+ /**
184
+ * Type information for interface types
185
+ */
186
+ export interface InterfaceTypeInfo extends BaseTypeInfo {
187
+ kind: TypeKind.Interface;
188
+ methods: Set<string>;
189
+ }
190
+ /**
191
+ * Type information for basic types (string, number, boolean)
192
+ */
193
+ export interface BasicTypeInfo extends BaseTypeInfo {
194
+ kind: TypeKind.Basic;
195
+ }
196
+ /**
197
+ * Type information for map types
198
+ */
199
+ export interface MapTypeInfo extends BaseTypeInfo {
200
+ kind: TypeKind.Map;
201
+ keyType?: string | TypeInfo;
202
+ elemType?: string | TypeInfo;
203
+ }
204
+ /**
205
+ * Type information for slice types
206
+ */
207
+ export interface SliceTypeInfo extends BaseTypeInfo {
208
+ kind: TypeKind.Slice;
209
+ elemType?: string | TypeInfo;
210
+ }
211
+ /**
212
+ * Type information for array types
213
+ */
214
+ export interface ArrayTypeInfo extends BaseTypeInfo {
215
+ kind: TypeKind.Array;
216
+ elemType?: string | TypeInfo;
217
+ length: number;
218
+ }
219
+ /**
220
+ * Type information for pointer types
221
+ */
222
+ export interface PointerTypeInfo extends BaseTypeInfo {
223
+ kind: TypeKind.Pointer;
224
+ elemType?: string | TypeInfo;
225
+ }
226
+ /**
227
+ * Type information for function types
228
+ */
229
+ export interface FunctionTypeInfo extends BaseTypeInfo {
230
+ kind: TypeKind.Function;
231
+ params?: (string | TypeInfo)[];
232
+ results?: (string | TypeInfo)[];
233
+ }
234
+ /**
235
+ * Type information for channel types
236
+ */
237
+ export interface ChannelTypeInfo extends BaseTypeInfo {
238
+ kind: TypeKind.Channel;
239
+ elemType?: string | TypeInfo;
240
+ direction?: 'send' | 'receive' | 'both';
241
+ }
242
+ /**
243
+ * Union type representing all possible TypeInfo variants
244
+ */
245
+ export type TypeInfo = StructTypeInfo | InterfaceTypeInfo | BasicTypeInfo | MapTypeInfo | SliceTypeInfo | ArrayTypeInfo | PointerTypeInfo | FunctionTypeInfo | ChannelTypeInfo;
246
+ export declare function isStructTypeInfo(info: TypeInfo): info is StructTypeInfo;
247
+ export declare function isInterfaceTypeInfo(info: TypeInfo): info is InterfaceTypeInfo;
248
+ export declare function isBasicTypeInfo(info: TypeInfo): info is BasicTypeInfo;
249
+ export declare function isMapTypeInfo(info: TypeInfo): info is MapTypeInfo;
250
+ export declare function isSliceTypeInfo(info: TypeInfo): info is SliceTypeInfo;
251
+ export declare function isArrayTypeInfo(info: TypeInfo): info is ArrayTypeInfo;
252
+ export declare function isPointerTypeInfo(info: TypeInfo): info is PointerTypeInfo;
253
+ export declare function isFunctionTypeInfo(info: TypeInfo): info is FunctionTypeInfo;
254
+ export declare function isChannelTypeInfo(info: TypeInfo): info is ChannelTypeInfo;
255
+ /**
256
+ * Registers a struct type with the runtime type system.
127
257
  *
128
258
  * @param name The name of the type.
129
- * @param kind The kind of the type.
130
259
  * @param zeroValue The zero value for the type.
131
- * @param methods Optional set of method names for interfaces.
132
- * @param constructor Optional constructor for structs.
133
- * @returns The type information object for chaining.
260
+ * @param methods Set of method names for the struct.
261
+ * @param ctor Constructor for the struct.
262
+ * @returns The struct type information object.
134
263
  */
135
- export declare const registerType: (name: string, kind: TypeKind, zeroValue: any, methods?: Set<string>, constructor?: new (...args: any[]) => any) => TypeInfo;
264
+ export declare const registerStructType: (name: string, zeroValue: any, methods: Set<string>, ctor: new (...args: any[]) => any) => StructTypeInfo;
265
+ /**
266
+ * Registers an interface type with the runtime type system.
267
+ *
268
+ * @param name The name of the type.
269
+ * @param zeroValue The zero value for the type (usually null).
270
+ * @param methods Set of method names the interface requires.
271
+ * @returns The interface type information object.
272
+ */
273
+ export declare const registerInterfaceType: (name: string, zeroValue: any, methods: Set<string>) => InterfaceTypeInfo;
136
274
  /**
137
275
  * Represents the result of a type assertion.
138
276
  */
@@ -140,14 +278,7 @@ export interface TypeAssertResult<T> {
140
278
  value: T;
141
279
  ok: boolean;
142
280
  }
143
- /**
144
- * Performs a type assertion at runtime.
145
- *
146
- * @param value The value to assert.
147
- * @param typeName The name of the target type.
148
- * @returns An object with the asserted value and whether the assertion succeeded.
149
- */
150
- export declare function typeAssert<T>(value: any, typeName: string): TypeAssertResult<T>;
281
+ export declare function typeAssert<T>(value: any, typeInfo: string | TypeInfo): TypeAssertResult<T>;
151
282
  /**
152
283
  * Represents the result of a channel receive operation with 'ok' value
153
284
  */
@@ -251,7 +382,7 @@ export declare const makeChannel: <T>(bufferSize: number, zeroValue: T) => Chann
251
382
  * Implements the `Disposable` interface for use with `using` declarations.
252
383
  */
253
384
  export declare class DisposableStack implements Disposable {
254
- #private;
385
+ private stack;
255
386
  /**
256
387
  * Adds a function to be executed when the stack is disposed.
257
388
  * @param fn The function to defer.
@@ -271,7 +402,7 @@ export declare class DisposableStack implements Disposable {
271
402
  * Implements the `AsyncDisposable` interface for use with `await using` declarations.
272
403
  */
273
404
  export declare class AsyncDisposableStack implements AsyncDisposable {
274
- #private;
405
+ private stack;
275
406
  /**
276
407
  * Adds a synchronous or asynchronous function to be executed when the stack is disposed.
277
408
  * @param fn The function to defer. Can return void or a Promise<void>.
@@ -283,3 +414,9 @@ export declare class AsyncDisposableStack implements AsyncDisposable {
283
414
  */
284
415
  [Symbol.asyncDispose](): Promise<void>;
285
416
  }
417
+ /**
418
+ * Implementation of Go's built-in println function
419
+ * @param args Arguments to print
420
+ */
421
+ export declare function println(...args: any[]): void;
422
+ export {};