goscript 0.0.84 → 0.1.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.
Files changed (188) hide show
  1. package/README.md +13 -1
  2. package/cmd/goscript/cmd_compile.go +70 -69
  3. package/cmd/goscript/cmd_compile_test.go +79 -0
  4. package/cmd/goscript/main.go +10 -5
  5. package/compiler/compile-request.go +218 -0
  6. package/compiler/compiler.go +16 -1336
  7. package/compiler/compliance_test.go +196 -0
  8. package/compiler/config.go +6 -13
  9. package/compiler/diagnostic.go +70 -0
  10. package/compiler/index.test.ts +28 -28
  11. package/compiler/index.ts +40 -72
  12. package/compiler/lowered-program.go +132 -0
  13. package/compiler/lowering.go +3576 -0
  14. package/compiler/override-registry.go +422 -0
  15. package/compiler/override-registry_test.go +207 -0
  16. package/compiler/package-graph.go +231 -0
  17. package/compiler/package-graph_test.go +281 -0
  18. package/compiler/result.go +13 -0
  19. package/compiler/runtime-contract.go +279 -0
  20. package/compiler/runtime-contract_test.go +90 -0
  21. package/compiler/semantic-model-types.go +110 -0
  22. package/compiler/semantic-model.go +922 -0
  23. package/compiler/semantic-model_test.go +416 -0
  24. package/compiler/service.go +133 -0
  25. package/compiler/skeleton_test.go +1145 -0
  26. package/compiler/typescript-emitter.go +663 -0
  27. package/compiler/wasm/compile.go +2 -3
  28. package/compiler/wasm/compile_test.go +29 -0
  29. package/compiler/wasm_api.go +10 -159
  30. package/dist/compiler/index.d.ts +1 -3
  31. package/dist/compiler/index.js +31 -55
  32. package/dist/compiler/index.js.map +1 -1
  33. package/dist/gs/builtin/builtin.d.ts +13 -0
  34. package/dist/gs/builtin/builtin.js +23 -0
  35. package/dist/gs/builtin/builtin.js.map +1 -1
  36. package/dist/gs/builtin/channel.d.ts +3 -3
  37. package/dist/gs/builtin/channel.js.map +1 -1
  38. package/dist/gs/builtin/hostio.d.ts +15 -1
  39. package/dist/gs/builtin/hostio.js +134 -49
  40. package/dist/gs/builtin/hostio.js.map +1 -1
  41. package/dist/gs/builtin/index.d.ts +1 -0
  42. package/dist/gs/builtin/index.js +1 -0
  43. package/dist/gs/builtin/index.js.map +1 -1
  44. package/dist/gs/builtin/slice.d.ts +1 -1
  45. package/dist/gs/builtin/slice.js.map +1 -1
  46. package/dist/gs/builtin/type.d.ts +11 -0
  47. package/dist/gs/builtin/type.js +55 -1
  48. package/dist/gs/builtin/type.js.map +1 -1
  49. package/dist/gs/bytes/buffer.gs.js.map +1 -1
  50. package/dist/gs/bytes/bytes.gs.js.map +1 -1
  51. package/dist/gs/bytes/reader.gs.js.map +1 -1
  52. package/dist/gs/context/context.js.map +1 -1
  53. package/dist/gs/crypto/rand/index.d.ts +5 -0
  54. package/dist/gs/crypto/rand/index.js +77 -0
  55. package/dist/gs/crypto/rand/index.js.map +1 -0
  56. package/dist/gs/encoding/json/index.d.ts +3 -0
  57. package/dist/gs/encoding/json/index.js +160 -0
  58. package/dist/gs/encoding/json/index.js.map +1 -0
  59. package/dist/gs/fmt/fmt.js.map +1 -1
  60. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +1 -1
  61. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +1 -1
  62. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
  63. package/dist/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.js.map +1 -1
  64. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
  65. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
  66. package/dist/gs/go/scanner/index.d.ts +29 -0
  67. package/dist/gs/go/scanner/index.js +120 -0
  68. package/dist/gs/go/scanner/index.js.map +1 -0
  69. package/dist/gs/go/token/index.d.ts +31 -0
  70. package/dist/gs/go/token/index.js +82 -0
  71. package/dist/gs/go/token/index.js.map +1 -0
  72. package/dist/gs/internal/abi/index.js.map +1 -1
  73. package/dist/gs/io/fs/fs.js.map +1 -1
  74. package/dist/gs/io/fs/readdir.js.map +1 -1
  75. package/dist/gs/io/fs/readfile.js.map +1 -1
  76. package/dist/gs/io/fs/stat.js.map +1 -1
  77. package/dist/gs/io/fs/sub.js.map +1 -1
  78. package/dist/gs/io/io.js.map +1 -1
  79. package/dist/gs/os/dir_unix.gs.js.map +1 -1
  80. package/dist/gs/os/error.gs.js +2 -4
  81. package/dist/gs/os/error.gs.js.map +1 -1
  82. package/dist/gs/os/exec.gs.js.map +1 -1
  83. package/dist/gs/os/exec_posix.gs.js.map +1 -1
  84. package/dist/gs/os/rawconn_js.gs.js.map +1 -1
  85. package/dist/gs/os/root_js.gs.js.map +1 -1
  86. package/dist/gs/os/tempfile.gs.js +66 -9
  87. package/dist/gs/os/tempfile.gs.js.map +1 -1
  88. package/dist/gs/os/types.gs.js.map +1 -1
  89. package/dist/gs/os/types_js.gs.js +9 -9
  90. package/dist/gs/os/types_js.gs.js.map +1 -1
  91. package/dist/gs/os/types_unix.gs.js.map +1 -1
  92. package/dist/gs/path/filepath/match.js.map +1 -1
  93. package/dist/gs/path/match.js.map +1 -1
  94. package/dist/gs/path/path.js.map +1 -1
  95. package/dist/gs/reflect/index.d.ts +2 -2
  96. package/dist/gs/reflect/index.js +1 -1
  97. package/dist/gs/reflect/index.js.map +1 -1
  98. package/dist/gs/reflect/map.js.map +1 -1
  99. package/dist/gs/reflect/type.d.ts +2 -1
  100. package/dist/gs/reflect/type.js +85 -14
  101. package/dist/gs/reflect/type.js.map +1 -1
  102. package/dist/gs/reflect/types.js.map +1 -1
  103. package/dist/gs/reflect/visiblefields.js.map +1 -1
  104. package/dist/gs/runtime/runtime.js.map +1 -1
  105. package/dist/gs/sort/sort.gs.js.map +1 -1
  106. package/dist/gs/strconv/atoi.gs.js.map +1 -1
  107. package/dist/gs/strconv/quote.gs.js.map +1 -1
  108. package/dist/gs/strings/builder.js.map +1 -1
  109. package/dist/gs/strings/reader.js.map +1 -1
  110. package/dist/gs/strings/replace.js.map +1 -1
  111. package/dist/gs/sync/atomic/type.gs.js.map +1 -1
  112. package/dist/gs/sync/atomic/value.gs.js.map +1 -1
  113. package/dist/gs/sync/sync.d.ts +1 -0
  114. package/dist/gs/sync/sync.js +12 -0
  115. package/dist/gs/sync/sync.js.map +1 -1
  116. package/dist/gs/time/time.js.map +1 -1
  117. package/dist/gs/unicode/unicode.js.map +1 -1
  118. package/go.mod +2 -2
  119. package/gs/builtin/builtin.ts +27 -0
  120. package/gs/builtin/hostio.test.ts +177 -0
  121. package/gs/builtin/hostio.ts +171 -56
  122. package/gs/builtin/index.ts +1 -0
  123. package/gs/builtin/runtime-contract.test.ts +230 -0
  124. package/gs/builtin/type.ts +84 -1
  125. package/gs/crypto/rand/index.test.ts +32 -0
  126. package/gs/crypto/rand/index.ts +90 -0
  127. package/gs/crypto/rand/meta.json +5 -0
  128. package/gs/encoding/json/index.test.ts +65 -0
  129. package/gs/encoding/json/index.ts +186 -0
  130. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +23 -0
  131. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +3 -1
  132. package/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/meta.json +3 -1
  133. package/gs/go/scanner/index.test.ts +50 -0
  134. package/gs/go/scanner/index.ts +157 -0
  135. package/gs/go/token/index.test.ts +21 -0
  136. package/gs/go/token/index.ts +120 -0
  137. package/gs/os/file_unix_js.test.ts +50 -0
  138. package/gs/os/meta.json +1 -2
  139. package/gs/os/tempfile.gs.test.ts +85 -0
  140. package/gs/os/tempfile.gs.ts +71 -11
  141. package/gs/os/types_js.gs.ts +9 -9
  142. package/gs/reflect/index.ts +1 -1
  143. package/gs/reflect/type.ts +106 -17
  144. package/gs/reflect/typefor.test.ts +75 -0
  145. package/gs/sync/sync.test.ts +24 -0
  146. package/gs/sync/sync.ts +12 -0
  147. package/package.json +13 -13
  148. package/compiler/analysis.go +0 -3475
  149. package/compiler/analysis_test.go +0 -338
  150. package/compiler/assignment.go +0 -580
  151. package/compiler/builtin_test.go +0 -92
  152. package/compiler/code-writer.go +0 -115
  153. package/compiler/compiler_test.go +0 -149
  154. package/compiler/composite-lit.go +0 -779
  155. package/compiler/config_test.go +0 -62
  156. package/compiler/constraint.go +0 -86
  157. package/compiler/decl.go +0 -801
  158. package/compiler/expr-call-async.go +0 -188
  159. package/compiler/expr-call-builtins.go +0 -208
  160. package/compiler/expr-call-helpers.go +0 -382
  161. package/compiler/expr-call-make.go +0 -318
  162. package/compiler/expr-call-type-conversion.go +0 -520
  163. package/compiler/expr-call.go +0 -413
  164. package/compiler/expr-selector.go +0 -343
  165. package/compiler/expr-star.go +0 -82
  166. package/compiler/expr-type.go +0 -442
  167. package/compiler/expr-value.go +0 -89
  168. package/compiler/expr.go +0 -773
  169. package/compiler/field.go +0 -183
  170. package/compiler/gs_dependencies_test.go +0 -298
  171. package/compiler/lit.go +0 -322
  172. package/compiler/output.go +0 -72
  173. package/compiler/primitive.go +0 -149
  174. package/compiler/protobuf.go +0 -697
  175. package/compiler/sanitize.go +0 -100
  176. package/compiler/spec-struct.go +0 -995
  177. package/compiler/spec-value.go +0 -540
  178. package/compiler/spec.go +0 -725
  179. package/compiler/stmt-assign.go +0 -664
  180. package/compiler/stmt-for.go +0 -266
  181. package/compiler/stmt-range.go +0 -475
  182. package/compiler/stmt-select.go +0 -262
  183. package/compiler/stmt-type-switch.go +0 -147
  184. package/compiler/stmt.go +0 -1308
  185. package/compiler/type-assert.go +0 -386
  186. package/compiler/type-info.go +0 -156
  187. package/compiler/type-utils.go +0 -207
  188. package/compiler/type.go +0 -892
@@ -8,8 +8,8 @@ import * as syscall from "@goscript/syscall/index.js"
8
8
  import {
9
9
  DenoFileLike,
10
10
  DenoStream,
11
+ getHostRuntime,
11
12
  HostUnsupportedError,
12
- hostRuntime,
13
13
  NodeFSModule,
14
14
  resetHostRuntimeForTests,
15
15
  } from "@goscript/builtin/hostio.js"
@@ -33,23 +33,23 @@ export function newHostError(err: unknown): $.GoError {
33
33
  }
34
34
 
35
35
  export function getNodeFS(): NodeFSModule | null {
36
- return hostRuntime.nodeFS
36
+ return getHostRuntime().nodeFS
37
37
  }
38
38
 
39
39
  export function getDeno(): any | null {
40
- return hostRuntime.deno
40
+ return getHostRuntime().deno
41
41
  }
42
42
 
43
43
  export function getPlatform(): string {
44
- return hostRuntime.platform
44
+ return getHostRuntime().platform
45
45
  }
46
46
 
47
47
  export function getEnv(name: string): string {
48
- return hostRuntime.getEnv(name)
48
+ return getHostRuntime().getEnv(name)
49
49
  }
50
50
 
51
51
  export function getDenoStream(fd: number): DenoStream | null {
52
- return hostRuntime.getStdioHandle(fd)
52
+ return getHostRuntime().getStdioHandle(fd)
53
53
  }
54
54
 
55
55
  function readFD(fd: number, b: Uint8Array): [number, $.GoError] {
@@ -58,7 +58,7 @@ function readFD(fd: number, b: Uint8Array): [number, $.GoError] {
58
58
  }
59
59
 
60
60
  try {
61
- const n = hostRuntime.readFD(fd, b)
61
+ const n = getHostRuntime().readFD(fd, b)
62
62
  if (n === null || n === 0) {
63
63
  return [0, io.EOF]
64
64
  }
@@ -77,7 +77,7 @@ function writeFD(fd: number, b: Uint8Array): [number, $.GoError] {
77
77
  }
78
78
 
79
79
  try {
80
- return [hostRuntime.writeFD(fd, b), null]
80
+ return [getHostRuntime().writeFD(fd, b), null]
81
81
  } catch (err) {
82
82
  if (err instanceof HostUnsupportedError) {
83
83
  return [0, ErrUnimplemented]
@@ -192,7 +192,7 @@ export function createFileInfo(name: string, stat: HostStatLike): fs.FileInfo {
192
192
  export function createHostFile(name: string, fd: number = -1, handle: DenoFileLike | null = null): File {
193
193
  return new File({
194
194
  fd,
195
- file: new file({ handle: handle ?? hostRuntime.getStdioHandle(fd), path: name }),
195
+ file: new file({ handle: handle ?? getHostRuntime().getStdioHandle(fd), path: name }),
196
196
  name,
197
197
  })
198
198
  }
@@ -47,7 +47,6 @@ export {
47
47
  } from './types.js'
48
48
  export type {
49
49
  uintptr,
50
- Pointer,
51
50
  Method,
52
51
  SelectDir,
53
52
  SliceHeader,
@@ -80,6 +79,7 @@ export {
80
79
  Interface,
81
80
  Map,
82
81
  Ptr,
82
+ Pointer,
83
83
  Slice,
84
84
  String,
85
85
  Struct,
@@ -167,6 +167,7 @@ export const Func: Kind = 19
167
167
  export const Interface: Kind = 20
168
168
  export const Map: Kind = 21
169
169
  export const Ptr: Kind = 22
170
+ export const Pointer: Kind = Ptr
170
171
  export const Slice: Kind = 23
171
172
  export const String: Kind = 24
172
173
  export const Struct: Kind = 25
@@ -1945,22 +1946,7 @@ function getTypeOf(value: ReflectValue): Type {
1945
1946
  typeInfo.params &&
1946
1947
  typeInfo.results
1947
1948
  ) {
1948
- // Build proper function signature from type info
1949
- const paramTypes = typeInfo.params
1950
- .map((p: any) => (typeof p === 'string' ? p : p.name || 'any'))
1951
- .join(', ')
1952
- const resultTypes = typeInfo.results.map((r: any) =>
1953
- typeof r === 'string' ? r : r.name || 'any',
1954
- )
1955
-
1956
- let signature = `func(${paramTypes})`
1957
- if (resultTypes.length === 1) {
1958
- signature += ` ${resultTypes[0]}`
1959
- } else if (resultTypes.length > 1) {
1960
- signature += ` (${resultTypes.join(', ')})`
1961
- }
1962
-
1963
- return new FunctionType(signature)
1949
+ return functionTypeFromInfo(typeInfo)
1964
1950
  }
1965
1951
  }
1966
1952
 
@@ -2180,10 +2166,113 @@ export function ChanOf(dir: ChanDir, t: Type): Type {
2180
2166
  return new ChannelType(t, dir)
2181
2167
  }
2182
2168
 
2183
- export function TypeFor(): Type {
2169
+ export function TypeFor(typeArgs?: $.GenericTypeArgs): Type {
2170
+ const descriptor = typeArgs?.T
2171
+ if (descriptor?.type) {
2172
+ return typeFromTypeInfo(descriptor.type)
2173
+ }
2174
+ if (descriptor?.methods) {
2175
+ const methods = Object.keys(descriptor.methods)
2176
+ if (methods.length !== 0) {
2177
+ return new InterfaceType(
2178
+ `interface { ${methods.map((method) => method + '()').join('; ')} }`,
2179
+ )
2180
+ }
2181
+ }
2182
+ if (descriptor?.zero) {
2183
+ return getTypeOf(descriptor.zero())
2184
+ }
2184
2185
  return new InterfaceType('interface{}')
2185
2186
  }
2186
2187
 
2188
+ function typeFromTypeInfo(info: $.TypeInfo | string): Type {
2189
+ if (typeof info === 'string') {
2190
+ const registered = builtinGetTypeByName(info)
2191
+ if (registered) {
2192
+ return typeFromTypeInfo(registered)
2193
+ }
2194
+ return StructType.createTypeFromFieldInfo(info)
2195
+ }
2196
+ switch (info.kind) {
2197
+ case $.TypeKind.Array:
2198
+ return new ArrayType(
2199
+ typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }),
2200
+ info.length,
2201
+ )
2202
+ case $.TypeKind.Channel:
2203
+ return new ChannelType(
2204
+ typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }),
2205
+ chanDirFromTypeInfo(info.direction),
2206
+ )
2207
+ case $.TypeKind.Function:
2208
+ return functionTypeFromInfo(info)
2209
+ case $.TypeKind.Interface:
2210
+ return interfaceTypeFromInfo(info)
2211
+ case $.TypeKind.Map:
2212
+ return new MapType(
2213
+ typeFromTypeInfo(info.keyType ?? { kind: $.TypeKind.Basic, name: 'unknown' }),
2214
+ typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }),
2215
+ )
2216
+ case $.TypeKind.Pointer:
2217
+ return new PointerType(
2218
+ typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }),
2219
+ )
2220
+ default:
2221
+ return StructType.createTypeFromFieldInfo(info)
2222
+ }
2223
+ }
2224
+
2225
+ function functionTypeFromInfo(info: $.FunctionTypeInfo): Type {
2226
+ if (info.name) {
2227
+ return new FunctionType(info.name)
2228
+ }
2229
+ const params = info.params ?? []
2230
+ const paramTypes = params.map((param, index) => {
2231
+ const typeName = functionSignatureTypeName(param)
2232
+ if (!info.isVariadic || index !== params.length - 1) {
2233
+ return typeName
2234
+ }
2235
+ if (typeName.startsWith('[]')) {
2236
+ return '...' + typeName.slice(2)
2237
+ }
2238
+ return '...' + typeName
2239
+ })
2240
+ const resultTypes = (info.results ?? []).map(functionSignatureTypeName)
2241
+ let signature = `func(${paramTypes.join(', ')})`
2242
+ if (resultTypes.length === 1) {
2243
+ signature += ` ${resultTypes[0]}`
2244
+ }
2245
+ if (resultTypes.length > 1) {
2246
+ signature += ` (${resultTypes.join(', ')})`
2247
+ }
2248
+ return new FunctionType(signature)
2249
+ }
2250
+
2251
+ function functionSignatureTypeName(info: $.TypeInfo | string): string {
2252
+ return typeFromTypeInfo(info).String()
2253
+ }
2254
+
2255
+ function interfaceTypeFromInfo(info: $.InterfaceTypeInfo): Type {
2256
+ if (info.methods.length === 0) {
2257
+ return new InterfaceType('interface{}', info.name)
2258
+ }
2259
+ return new InterfaceType(
2260
+ `interface { ${info.methods.map((method) => method.name + '()').join('; ')} }`,
2261
+ info.name,
2262
+ )
2263
+ }
2264
+
2265
+ function chanDirFromTypeInfo(direction?: 'send' | 'receive' | 'both'): ChanDir {
2266
+ switch (direction) {
2267
+ case 'send':
2268
+ return SendDir
2269
+ case 'receive':
2270
+ return RecvDir
2271
+ default:
2272
+ return BothDir
2273
+ }
2274
+ }
2275
+
2187
2276
  /**
2188
2277
  * getInterfaceTypeByName looks up a registered interface type by name
2189
2278
  * and returns a Type for it. Returns an interface{} type if not found.
@@ -0,0 +1,75 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import {
3
+ TypeKind,
4
+ registerInterfaceType,
5
+ registerStructType,
6
+ } from '../builtin/index.js'
7
+ import { Int, Struct, TypeFor } from './type.js'
8
+
9
+ describe('TypeFor', () => {
10
+ it('uses generic runtime type descriptors', () => {
11
+ const intType = TypeFor({
12
+ T: {
13
+ type: { kind: TypeKind.Basic, name: 'int' },
14
+ zero: () => 0,
15
+ },
16
+ })
17
+
18
+ expect(intType.String()).toBe('int')
19
+ expect(intType.Kind()).toBe(Int)
20
+ })
21
+
22
+ it('formats literal interface methods from type metadata', () => {
23
+ const ifaceType = TypeFor({
24
+ T: {
25
+ type: {
26
+ kind: TypeKind.Interface,
27
+ methods: [{ name: 'SomeMethod', args: [], returns: [] }],
28
+ },
29
+ zero: () => null,
30
+ },
31
+ })
32
+
33
+ expect(ifaceType.String()).toBe('interface { SomeMethod() }')
34
+ })
35
+
36
+ it('formats unnamed function signatures from type metadata', () => {
37
+ const fnType = TypeFor({
38
+ T: {
39
+ type: {
40
+ kind: TypeKind.Function,
41
+ params: [{ kind: TypeKind.Basic, name: 'int' }],
42
+ results: [{ kind: TypeKind.Basic, name: 'string' }],
43
+ },
44
+ zero: () => null,
45
+ },
46
+ })
47
+
48
+ expect(fnType.String()).toBe('func(int) string')
49
+ })
50
+
51
+ it('resolves registered type names from descriptors', () => {
52
+ class RegisteredStruct {}
53
+ registerStructType(
54
+ 'main.RegisteredStruct',
55
+ new RegisteredStruct(),
56
+ [],
57
+ RegisteredStruct,
58
+ {},
59
+ )
60
+ registerInterfaceType('main.RegisteredInterface', null, [
61
+ { name: 'SomeMethod', args: [], returns: [] },
62
+ ])
63
+
64
+ const structType = TypeFor({
65
+ T: { type: 'main.RegisteredStruct', zero: () => new RegisteredStruct() },
66
+ })
67
+ const ifaceType = TypeFor({
68
+ T: { type: 'main.RegisteredInterface', zero: () => null },
69
+ })
70
+
71
+ expect(structType.String()).toBe('main.RegisteredStruct')
72
+ expect(structType.Kind()).toBe(Struct)
73
+ expect(ifaceType.String()).toBe('interface { SomeMethod() }')
74
+ })
75
+ })
@@ -0,0 +1,24 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { WaitGroup } from './sync.js'
4
+
5
+ describe('sync.WaitGroup', () => {
6
+ it('Go tracks scheduled work and unblocks Wait after completion', async () => {
7
+ const wg = new WaitGroup()
8
+ const events: string[] = []
9
+
10
+ wg.Go(async () => {
11
+ events.push('worker start')
12
+ await Promise.resolve()
13
+ events.push('worker done')
14
+ })
15
+
16
+ const wait = wg.Wait().then(() => {
17
+ events.push('wait done')
18
+ })
19
+
20
+ expect(events).toEqual([])
21
+ await wait
22
+ expect(events).toEqual(['worker start', 'worker done', 'wait done'])
23
+ })
24
+ })
package/gs/sync/sync.ts CHANGED
@@ -193,6 +193,18 @@ export class WaitGroup {
193
193
  this.Add(-1)
194
194
  }
195
195
 
196
+ // Go calls f in a new goroutine and adds that task to the WaitGroup.
197
+ public Go(f: () => void | Promise<void>): void {
198
+ this.Add(1)
199
+ queueMicrotask(async () => {
200
+ try {
201
+ await f()
202
+ } finally {
203
+ this.Done()
204
+ }
205
+ })
206
+ }
207
+
196
208
  // Wait blocks until the WaitGroup counter is zero
197
209
  public async Wait(): Promise<void> {
198
210
  if (this._counter === 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "goscript",
3
3
  "description": "Go to TypeScript transpiler",
4
- "version": "0.0.84",
4
+ "version": "0.1.0",
5
5
  "author": {
6
6
  "name": "Aperture Robotics LLC.",
7
7
  "email": "support@aperture.us",
@@ -42,27 +42,27 @@
42
42
  }
43
43
  },
44
44
  "scripts": {
45
- "build": "npm run build:updategover && tsc -p tsconfig.build.json",
46
- "build:updategover": "node -e \"const fs = require('fs'); const { execSync } = require('child_process'); const goVersion = execSync('go mod edit -json', { encoding: 'utf8' }); const goData = JSON.parse(goVersion); const version = goData.Go; const runtimePath = 'gs/runtime/runtime.ts'; const content = fs.readFileSync(runtimePath, 'utf8'); const updatedContent = content.replace(/export const GOVERSION = 'go[^']*'/, \\`export const GOVERSION = 'go\\${version}'\\`); fs.writeFileSync(runtimePath, updatedContent);\"",
47
- "prepublishOnly": "npm run build",
45
+ "build": "bun run build:updategover && tsgo -p tsconfig.build.json",
46
+ "build:updategover": "bun run scripts/update-go-version.ts",
47
+ "prepublishOnly": "bun run build",
48
48
  "example": "cd ./example/simple && bash run.bash",
49
- "test": "npm run test:go && npm run test:js",
49
+ "test": "bun run test:go && bun run test:js",
50
50
  "test:go": "go test ./...",
51
- "test:js": "npm run typecheck && vitest run",
51
+ "test:js": "bun run typecheck && vitest run",
52
52
  "test:browser": "bun run scripts/generate-browser-tests.ts && vitest run --config vitest.browser.config.ts",
53
53
  "test:browser:ui": "bun run scripts/generate-browser-tests.ts && vitest --config vitest.browser.config.ts --ui",
54
54
  "typecheck": "tsgo --noEmit -p tsconfig.build.json",
55
- "format": "npm run format:go && npm run format:js && npm run format:config",
55
+ "format": "bun run format:go && bun run format:js && bun run format:config",
56
56
  "format:config": "prettier --write tsconfig.json package.json",
57
57
  "format:go": "gofumpt -w .",
58
58
  "format:js": "prettier --write './{src,gs,example}/**/(*.ts|*.tsx|*.html|*.css|*.scss)'",
59
- "release": "npm run release:version && npm run release:commit",
60
- "release:minor": "npm run release:version:minor && npm run release:commit",
61
- "release:version": "npm version patch -m \"release: v%s\" --no-git-tag-version",
62
- "release:version:minor": "npm version minor -m \"release: v%s\" --no-git-tag-version",
63
- "release:commit": "git reset && git add package.json && git commit -s -m \"release: v$(node -p \"require('./package.json').version\")\" && git tag v$(node -p \"require('./package.json').version\")",
59
+ "release": "bun run release:version && bun run release:commit",
60
+ "release:minor": "bun run release:version:minor && bun run release:commit",
61
+ "release:version": "bun run scripts/bump-version.ts patch",
62
+ "release:version:minor": "bun run scripts/bump-version.ts minor",
63
+ "release:commit": "git reset && git add package.json && git commit -s -m \"release: v$(bun -p \"require('./package.json').version\")\" && git tag v$(bun -p \"require('./package.json').version\")",
64
64
  "release:publish": "git push && git push --tags",
65
- "lint": "npm run lint:go && npm run lint:js",
65
+ "lint": "bun run lint:go && bun run lint:js",
66
66
  "lint:go": "golangci-lint run .",
67
67
  "lint:js": "eslint -c eslint.config.mjs ./",
68
68
  "lint:js:fix": "eslint -c eslint.config.mjs ./ --fix",