goscript 0.0.14 → 0.0.17
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/README.md +154 -40
- package/builtin/builtin.ts +1168 -178
- package/compiler/analysis.go +726 -0
- package/compiler/compiler.go +5706 -4
- package/compiler/compiler_test.go +104 -0
- package/compiler/config.go +3 -3
- package/compiler/config_test.go +89 -0
- package/compiler/output.go +26 -0
- package/compiler/write-type-spec.go +506 -0
- package/compiler/writer.go +25 -0
- package/dist/builtin/builtin.d.ts +204 -67
- package/dist/builtin/builtin.js +845 -144
- package/dist/builtin/builtin.js.map +1 -1
- package/go.mod +4 -7
- package/go.sum +6 -11
- package/package.json +4 -3
- package/compiler/compile.go +0 -190
- package/compiler/compile_comment.go +0 -41
- package/compiler/compile_decls.go +0 -84
- package/compiler/compile_expr.go +0 -1022
- package/compiler/compile_field.go +0 -110
- package/compiler/compile_spec.go +0 -566
- package/compiler/compile_stmt.go +0 -1616
- package/compiler/context.go +0 -9
- package/compiler/file_compiler.go +0 -80
- package/compiler/output_path.go +0 -31
- package/compiler/pkg_compiler.go +0 -72
- package/compiler/types/tokens.go +0 -66
- package/compiler/types/types.go +0 -46
- package/dist/compliance/tests/array_literal/array_literal.gs.d.ts +0 -1
- package/dist/compliance/tests/array_literal/array_literal.gs.js +0 -15
- package/dist/compliance/tests/array_literal/array_literal.gs.js.map +0 -1
- package/dist/compliance/tests/async_basic/async_basic.gs.d.ts +0 -1
- package/dist/compliance/tests/async_basic/async_basic.gs.js +0 -24
- package/dist/compliance/tests/async_basic/async_basic.gs.js.map +0 -1
- package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.js +0 -82
- package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.js.map +0 -1
- package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.d.ts +0 -1
- package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.js +0 -16
- package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.js.map +0 -1
- package/dist/compliance/tests/boolean_logic/boolean_logic.gs.d.ts +0 -1
- package/dist/compliance/tests/boolean_logic/boolean_logic.gs.js +0 -14
- package/dist/compliance/tests/boolean_logic/boolean_logic.gs.js.map +0 -1
- package/dist/compliance/tests/channel_basic/channel_basic.gs.d.ts +0 -1
- package/dist/compliance/tests/channel_basic/channel_basic.gs.js +0 -14
- package/dist/compliance/tests/channel_basic/channel_basic.gs.js.map +0 -1
- package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.d.ts +0 -1
- package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.js +0 -27
- package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.js.map +0 -1
- package/dist/compliance/tests/constants/constants.gs.d.ts +0 -1
- package/dist/compliance/tests/constants/constants.gs.js +0 -16
- package/dist/compliance/tests/constants/constants.gs.js.map +0 -1
- package/dist/compliance/tests/copy_independence/copy_independence.gs.d.ts +0 -1
- package/dist/compliance/tests/copy_independence/copy_independence.gs.js +0 -33
- package/dist/compliance/tests/copy_independence/copy_independence.gs.js.map +0 -1
- package/dist/compliance/tests/defer_statement/defer_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/defer_statement/defer_statement.gs.js +0 -75
- package/dist/compliance/tests/defer_statement/defer_statement.gs.js.map +0 -1
- package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.d.ts +0 -1
- package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.js +0 -37
- package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.js.map +0 -1
- package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.d.ts +0 -1
- package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.js +0 -29
- package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.js.map +0 -1
- package/dist/compliance/tests/float64/float64.gs.d.ts +0 -1
- package/dist/compliance/tests/float64/float64.gs.js +0 -24
- package/dist/compliance/tests/float64/float64.gs.js.map +0 -1
- package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.d.ts +0 -1
- package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.js +0 -10
- package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.js.map +0 -1
- package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.d.ts +0 -1
- package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.js +0 -11
- package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.js.map +0 -1
- package/dist/compliance/tests/for_loop_condition_only/main.gs.d.ts +0 -1
- package/dist/compliance/tests/for_loop_condition_only/main.gs.js +0 -10
- package/dist/compliance/tests/for_loop_condition_only/main.gs.js.map +0 -1
- package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.d.ts +0 -1
- package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.js +0 -14
- package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.js.map +0 -1
- package/dist/compliance/tests/for_range/for_range.gs.d.ts +0 -1
- package/dist/compliance/tests/for_range/for_range.gs.js +0 -39
- package/dist/compliance/tests/for_range/for_range.gs.js.map +0 -1
- package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.d.ts +0 -1
- package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.js +0 -15
- package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.js.map +0 -1
- package/dist/compliance/tests/func_literal/func_literal.gs.d.ts +0 -1
- package/dist/compliance/tests/func_literal/func_literal.gs.js +0 -10
- package/dist/compliance/tests/func_literal/func_literal.gs.js.map +0 -1
- package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.d.ts +0 -12
- package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.js +0 -30
- package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.js.map +0 -1
- package/dist/compliance/tests/if_statement/if_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/if_statement/if_statement.gs.js +0 -13
- package/dist/compliance/tests/if_statement/if_statement.gs.js.map +0 -1
- package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.js +0 -12
- package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.js.map +0 -1
- package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.js +0 -34
- package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.js.map +0 -1
- package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.js +0 -32
- package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.js.map +0 -1
- package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.js +0 -40
- package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.js.map +0 -1
- package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.js +0 -51
- package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.js.map +0 -1
- package/dist/compliance/tests/map_support/map_support.gs.d.ts +0 -1
- package/dist/compliance/tests/map_support/map_support.gs.js +0 -88
- package/dist/compliance/tests/map_support/map_support.gs.js.map +0 -1
- package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.d.ts +0 -1
- package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.js +0 -24
- package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.js.map +0 -1
- package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.d.ts +0 -1
- package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.js +0 -33
- package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.js.map +0 -1
- package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.d.ts +0 -1
- package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.js +0 -22
- package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.js.map +0 -1
- package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.d.ts +0 -1
- package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.js +0 -33
- package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.js.map +0 -1
- package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.d.ts +0 -1
- package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.js +0 -17
- package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.js.map +0 -1
- package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.d.ts +0 -1
- package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.js +0 -29
- package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.js.map +0 -1
- package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.d.ts +0 -1
- package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.js +0 -27
- package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.js.map +0 -1
- package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.d.ts +0 -1
- package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.js +0 -22
- package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.js.map +0 -1
- package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.d.ts +0 -1
- package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.js +0 -20
- package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.js.map +0 -1
- package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.d.ts +0 -1
- package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.js +0 -28
- package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.js.map +0 -1
- 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
- package/dist/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.js +0 -30
- 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
- package/dist/compliance/tests/select_statement/select_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/select_statement/select_statement.gs.js +0 -207
- package/dist/compliance/tests/select_statement/select_statement.gs.js.map +0 -1
- package/dist/compliance/tests/simple/simple.gs.d.ts +0 -1
- package/dist/compliance/tests/simple/simple.gs.js +0 -6
- package/dist/compliance/tests/simple/simple.gs.js.map +0 -1
- package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.d.ts +0 -1
- package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.js +0 -24
- package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.js.map +0 -1
- package/dist/compliance/tests/slices/slices.gs.d.ts +0 -1
- package/dist/compliance/tests/slices/slices.gs.js +0 -294
- package/dist/compliance/tests/slices/slices.gs.js.map +0 -1
- package/dist/compliance/tests/string_conversion/string_conversion.gs.d.ts +0 -1
- package/dist/compliance/tests/string_conversion/string_conversion.gs.js +0 -41
- package/dist/compliance/tests/string_conversion/string_conversion.gs.js.map +0 -1
- package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.d.ts +0 -1
- package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.js +0 -17
- package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.js.map +0 -1
- package/dist/compliance/tests/struct_embedding/struct_embedding.gs.d.ts +0 -1
- package/dist/compliance/tests/struct_embedding/struct_embedding.gs.js +0 -48
- package/dist/compliance/tests/struct_embedding/struct_embedding.gs.js.map +0 -1
- package/dist/compliance/tests/struct_field_access/struct_field_access.gs.d.ts +0 -1
- package/dist/compliance/tests/struct_field_access/struct_field_access.gs.js +0 -19
- package/dist/compliance/tests/struct_field_access/struct_field_access.gs.js.map +0 -1
- package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.d.ts +0 -1
- package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.js +0 -26
- package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.js.map +0 -1
- package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.d.ts +0 -1
- package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.js +0 -30
- package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.js.map +0 -1
- package/dist/compliance/tests/switch_statement/switch_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/switch_statement/switch_statement.gs.js +0 -76
- package/dist/compliance/tests/switch_statement/switch_statement.gs.js.map +0 -1
- package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.d.ts +0 -1
- package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.js +0 -31
- package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.js.map +0 -1
|
@@ -1,45 +1,82 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
*
|
|
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
|
|
15
|
-
* @param low
|
|
16
|
-
* @param high Ending index (defaults to
|
|
17
|
-
* @param max
|
|
18
|
-
*/
|
|
19
|
-
export declare const
|
|
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
|
-
*
|
|
31
|
-
*
|
|
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>(
|
|
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
|
|
37
|
-
* @param
|
|
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>(
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
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
|
-
|
|
110
|
-
|
|
151
|
+
Interface = "interface",
|
|
152
|
+
Struct = "struct",
|
|
111
153
|
Map = "map",
|
|
112
|
-
|
|
113
|
-
|
|
154
|
+
Slice = "slice",
|
|
155
|
+
Array = "array",
|
|
156
|
+
Pointer = "pointer",
|
|
157
|
+
Function = "function",
|
|
158
|
+
Channel = "channel"
|
|
114
159
|
}
|
|
115
160
|
/**
|
|
116
|
-
*
|
|
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
|
|
119
|
-
name
|
|
168
|
+
export interface BaseTypeInfo {
|
|
169
|
+
name?: string;
|
|
120
170
|
kind: TypeKind;
|
|
121
|
-
zeroValue
|
|
122
|
-
methods?: Set<string>;
|
|
123
|
-
constructor?: new (...args: any[]) => any;
|
|
171
|
+
zeroValue?: any;
|
|
124
172
|
}
|
|
125
173
|
/**
|
|
126
|
-
*
|
|
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
|
|
132
|
-
* @param
|
|
133
|
-
* @returns The type information object
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 {};
|