goscript 0.0.51 → 0.0.53

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 (59) hide show
  1. package/compiler/analysis.go +633 -340
  2. package/compiler/compiler.go +35 -6
  3. package/compiler/expr-call-async.go +82 -209
  4. package/compiler/expr.go +0 -44
  5. package/compiler/stmt-assign.go +0 -6
  6. package/compiler/stmt-select.go +5 -5
  7. package/compiler/type-assert.go +6 -6
  8. package/dist/gs/builtin/builtin.d.ts +0 -1
  9. package/dist/gs/builtin/builtin.js +0 -9
  10. package/dist/gs/builtin/builtin.js.map +1 -1
  11. package/dist/gs/builtin/channel.d.ts +3 -1
  12. package/dist/gs/builtin/channel.js +2 -10
  13. package/dist/gs/builtin/channel.js.map +1 -1
  14. package/dist/gs/context/context.js +2 -2
  15. package/dist/gs/context/context.js.map +1 -1
  16. package/dist/gs/reflect/index.d.ts +8 -8
  17. package/dist/gs/reflect/index.js +6 -6
  18. package/dist/gs/reflect/index.js.map +1 -1
  19. package/dist/gs/reflect/iter.d.ts +1 -1
  20. package/dist/gs/reflect/iter.js +1 -1
  21. package/dist/gs/reflect/iter.js.map +1 -1
  22. package/dist/gs/reflect/swapper.d.ts +1 -1
  23. package/dist/gs/reflect/value.d.ts +1 -2
  24. package/dist/gs/reflect/value.js +1 -3
  25. package/dist/gs/reflect/value.js.map +1 -1
  26. package/dist/gs/runtime/runtime.d.ts +1 -1
  27. package/dist/gs/runtime/runtime.js +1 -1
  28. package/dist/gs/sort/index.d.ts +4 -4
  29. package/dist/gs/sort/index.js +3 -3
  30. package/dist/gs/sort/index.js.map +1 -1
  31. package/dist/gs/strings/index.js +0 -1
  32. package/dist/gs/strings/index.js.map +1 -1
  33. package/dist/gs/time/time.d.ts +2 -2
  34. package/dist/gs/time/time.js +12 -9
  35. package/dist/gs/time/time.js.map +1 -1
  36. package/go.mod +4 -4
  37. package/go.sum +6 -6
  38. package/gs/builtin/builtin.ts +0 -11
  39. package/gs/builtin/channel.ts +23 -7
  40. package/gs/context/context.ts +6 -2
  41. package/gs/context/meta.json +16 -0
  42. package/gs/reflect/index.ts +8 -8
  43. package/gs/reflect/iter.ts +1 -11
  44. package/gs/reflect/swapper.ts +1 -1
  45. package/gs/reflect/value.ts +1 -4
  46. package/gs/runtime/runtime.ts +1 -1
  47. package/gs/sort/index.ts +4 -4
  48. package/gs/strings/index.ts +0 -1
  49. package/gs/syscall/constants.ts +1 -1
  50. package/gs/syscall/env.ts +1 -1
  51. package/gs/syscall/errors.ts +1 -1
  52. package/gs/syscall/fs.ts +1 -1
  53. package/gs/syscall/rawconn.ts +1 -1
  54. package/gs/syscall/types.ts +1 -1
  55. package/gs/time/meta.json +6 -0
  56. package/gs/time/time.ts +16 -13
  57. package/gs/unicode/meta.json +24 -0
  58. package/package.json +1 -1
  59. package/gs/unicode/unicode.go +0 -38
@@ -99,7 +99,7 @@ export interface SelectCase<T> {
99
99
  * @param hasDefault Whether there is a default case
100
100
  * @returns A promise that resolves with the result of the selected case
101
101
  */
102
- export async function selectStatement<T, V=void>(
102
+ export async function selectStatement<T, V = void>(
103
103
  cases: SelectCase<T>[],
104
104
  hasDefault: boolean = false,
105
105
  ): Promise<[boolean, V]> {
@@ -143,7 +143,9 @@ export async function selectStatement<T, V=void>(
143
143
  selectedCase.id,
144
144
  )
145
145
  if (selectedCase.onSelected) {
146
- const handlerResult = await selectedCase.onSelected(result as SelectResult<T>)
146
+ const handlerResult = await selectedCase.onSelected(
147
+ result as SelectResult<T>,
148
+ )
147
149
  return [handlerResult !== undefined, handlerResult as V]
148
150
  }
149
151
  } else {
@@ -265,18 +267,32 @@ export async function chanRecvWithOk<T>(
265
267
  * @param direction Optional direction for the channel. Default is 'both' (bidirectional).
266
268
  * @returns A new channel instance or channel reference.
267
269
  */
268
- export const makeChannel = <T>(
270
+ export function makeChannel<T>(
271
+ bufferSize: number,
272
+ zeroValue: T,
273
+ direction: 'send',
274
+ ): SendOnlyChannelRef<T>
275
+ export function makeChannel<T>(
276
+ bufferSize: number,
277
+ zeroValue: T,
278
+ direction: 'receive',
279
+ ): ReceiveOnlyChannelRef<T>
280
+ export function makeChannel<T>(
281
+ bufferSize: number,
282
+ zeroValue: T,
283
+ direction?: 'both',
284
+ ): Channel<T>
285
+ export function makeChannel<T>(
269
286
  bufferSize: number,
270
287
  zeroValue: T,
271
288
  direction: 'send' | 'receive' | 'both' = 'both',
272
- ): Channel<T> | ChannelRef<T> => {
289
+ ): Channel<T> | ChannelRef<T> {
273
290
  const channel = new BufferedChannel<T>(bufferSize, zeroValue)
274
291
 
275
- // Wrap the channel with the appropriate ChannelRef based on direction
276
292
  if (direction === 'send') {
277
- return new SendOnlyChannelRef<T>(channel) as ChannelRef<T>
293
+ return new SendOnlyChannelRef<T>(channel)
278
294
  } else if (direction === 'receive') {
279
- return new ReceiveOnlyChannelRef<T>(channel) as ChannelRef<T>
295
+ return new ReceiveOnlyChannelRef<T>(channel)
280
296
  } else {
281
297
  return channel
282
298
  }
@@ -343,7 +343,7 @@ export function WithTimeout(
343
343
  parent: Context,
344
344
  timeout: number,
345
345
  ): [ContextNonNil, CancelFunc] {
346
- return WithDeadline(parent, new Date(Date.now() + timeout))
346
+ return WithDeadline(parent, new Date(Date.now() + timeout / 1000000))
347
347
  }
348
348
 
349
349
  // WithTimeoutCause is like WithTimeout but also sets the cause
@@ -352,7 +352,11 @@ export function WithTimeoutCause(
352
352
  timeout: number,
353
353
  cause: $.GoError,
354
354
  ): [ContextNonNil, CancelFunc] {
355
- return WithDeadlineCause(parent, new Date(Date.now() + timeout), cause)
355
+ return WithDeadlineCause(
356
+ parent,
357
+ new Date(Date.now() + timeout / 1000000),
358
+ cause,
359
+ )
356
360
  }
357
361
 
358
362
  // WithValue returns a copy of parent with the value associated with key
@@ -0,0 +1,16 @@
1
+ {
2
+ "asyncMethods": {
3
+ "Background": false,
4
+ "TODO": false,
5
+ "WithCancel": false,
6
+ "WithCancelCause": false,
7
+ "WithDeadline": false,
8
+ "WithDeadlineCause": false,
9
+ "WithTimeout": false,
10
+ "WithTimeoutCause": false,
11
+ "WithValue": false,
12
+ "WithoutCancel": false,
13
+ "Cause": false,
14
+ "AfterFunc": false
15
+ }
16
+ }
@@ -14,9 +14,9 @@ export {
14
14
  RecvDir,
15
15
  SendDir,
16
16
  BothDir,
17
- } from './type'
18
- export type { Type, ChanDir, Kind } from './type'
19
- export { DeepEqual } from './deepequal'
17
+ } from './type.js'
18
+ export type { Type, ChanDir, Kind } from './type.js'
19
+ export { DeepEqual } from './deepequal.js'
20
20
  export {
21
21
  Zero,
22
22
  Copy,
@@ -27,8 +27,8 @@ export {
27
27
  Append,
28
28
  MakeChan,
29
29
  Select,
30
- } from './value'
31
- export { Swapper } from './swapper'
30
+ } from './value.js'
31
+ export { Swapper } from './swapper.js'
32
32
 
33
33
  // Export new types and constants
34
34
  export {
@@ -39,7 +39,7 @@ export {
39
39
  SelectRecv,
40
40
  SelectDefault,
41
41
  bitVector,
42
- } from './types'
42
+ } from './types.js'
43
43
  export type {
44
44
  uintptr,
45
45
  Pointer,
@@ -49,7 +49,7 @@ export type {
49
49
  SliceHeader,
50
50
  StringHeader,
51
51
  MapIter,
52
- } from './types'
52
+ } from './types.js'
53
53
 
54
54
  // Export kind constants
55
55
  export {
@@ -80,4 +80,4 @@ export {
80
80
  String,
81
81
  Struct,
82
82
  UnsafePointer,
83
- } from './type'
83
+ } from './type.js'
@@ -1,20 +1,10 @@
1
- import { Type, Value } from './type.js'
1
+ import { Type, Value, ValueOf } from './type.js'
2
2
  import { uintptr } from './types.js'
3
- import { ValueOf } from './value.js'
4
3
 
5
4
  import * as iter from '@goscript/iter/index.js'
6
5
 
7
6
  export function rangeNum<
8
7
  T extends
9
- | number
10
- | number
11
- | number
12
- | number
13
- | number
14
- | number
15
- | number
16
- | number
17
- | number
18
8
  | number
19
9
  | uintptr,
20
10
  N extends number | number,
@@ -1,4 +1,4 @@
1
- import { ReflectValue } from './types'
1
+ import { ReflectValue } from './types.js'
2
2
 
3
3
  // Swapper returns a function that swaps the elements in the provided slice.
4
4
  // Swapper panics if the provided interface is not a slice.
@@ -1,3 +1,4 @@
1
+ import * as $ from '@goscript/builtin/index.js'
1
2
  import {
2
3
  Array,
3
4
  Bool,
@@ -26,16 +27,12 @@ import {
26
27
  Invalid,
27
28
  } from './type.js'
28
29
  import { ReflectValue, SelectCase, SelectRecv, SelectDefault } from './types.js'
29
- import * as $ from '@goscript/builtin/index.js'
30
30
 
31
31
  interface ChannelObject {
32
32
  _sendQueue?: unknown[]
33
33
  send?: (value: unknown) => void
34
34
  }
35
35
 
36
- // Re-export ValueOf from type.ts for compatibility
37
- export { ValueOf } from './type'
38
-
39
36
  // Zero returns a Value representing the zero value for the specified type.
40
37
  export function Zero(typ: Type): Value {
41
38
  let zeroValue: ReflectValue
@@ -3,7 +3,7 @@ export const GOOS = 'js'
3
3
  export const GOARCH = 'wasm'
4
4
 
5
5
  // Version returns the Go version as a string
6
- export const GOVERSION = 'go1.24.3'
6
+ export const GOVERSION = 'go1.24.4'
7
7
  export function Version(): string {
8
8
  return GOVERSION
9
9
  }
package/gs/sort/index.ts CHANGED
@@ -4,8 +4,8 @@ export {
4
4
  SearchFloat64s,
5
5
  SearchInts,
6
6
  SearchStrings,
7
- } from './search.gs'
8
- export { Slice, SliceIsSorted, SliceStable } from './slice.gs'
7
+ } from './search.gs.js'
8
+ export { Slice, SliceIsSorted, SliceStable } from './slice.gs.js'
9
9
  export {
10
10
  Float64Slice,
11
11
  Float64s,
@@ -20,5 +20,5 @@ export {
20
20
  StringSlice,
21
21
  Strings,
22
22
  StringsAreSorted,
23
- } from './sort.gs'
24
- export type { Interface } from './sort.gs'
23
+ } from './sort.gs.js'
24
+ export type { Interface } from './sort.gs.js'
@@ -9,4 +9,3 @@ export {
9
9
  SplitSeq,
10
10
  SplitAfterSeq,
11
11
  } from './iter.js'
12
- // Clone and Compare are already exported from strings.js, so we don't re-export them
@@ -26,4 +26,4 @@ export const S_IFIFO = 0o010000
26
26
  export const S_IFSOCK = 0o140000
27
27
  export const S_ISUID = 0o004000
28
28
  export const S_ISGID = 0o002000
29
- export const S_ISVTX = 0o001000
29
+ export const S_ISVTX = 0o001000
package/gs/syscall/env.ts CHANGED
@@ -44,4 +44,4 @@ export function Environ(): $.Slice<string> {
44
44
  return $.arrayToSlice(env)
45
45
  }
46
46
  return $.arrayToSlice([])
47
- }
47
+ }
@@ -655,4 +655,4 @@ export const EDQUOT: Errno = {
655
655
  Error: () => 'quota exceeded',
656
656
  Is: (target: $.GoError) => target === EDQUOT,
657
657
  Errno: () => 122,
658
- }
658
+ }
package/gs/syscall/fs.ts CHANGED
@@ -59,4 +59,4 @@ export function Getpagesize(): number {
59
59
  // Return a standard page size for JavaScript environment
60
60
  // Most systems use 4096 bytes as the default page size
61
61
  return 4096
62
- }
62
+ }
@@ -20,4 +20,4 @@ export class StubRawConn implements RawConn {
20
20
  Error: () => 'operation not implemented in JavaScript environment',
21
21
  }
22
22
  }
23
- }
23
+ }
@@ -15,4 +15,4 @@ export interface RawConn {
15
15
  Control(f: (fd: uintptr) => void): $.GoError
16
16
  Read(f: (fd: uintptr) => boolean): $.GoError
17
17
  Write(f: (fd: uintptr) => boolean): $.GoError
18
- }
18
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "dependencies": [],
3
+ "asyncMethods": {
4
+ "Sleep": true
5
+ }
6
+ }
package/gs/time/time.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { makeChannel, ChannelRef, makeChannelRef } from '../builtin/channel.js'
2
+
1
3
  // Time represents a time instant with nanosecond precision
2
4
  export class Time {
3
5
  private _date: globalThis.Date
@@ -590,14 +592,6 @@ export function Duration_multiply(
590
592
  return receiver * multiplier
591
593
  }
592
594
 
593
- // Override multiplication operator for Duration * number
594
- export function multiplyDuration(
595
- duration: Duration,
596
- multiplier: number,
597
- ): Duration {
598
- return duration * multiplier
599
- }
600
-
601
595
  // Location represents a time zone
602
596
  export class Location {
603
597
  private _name: string
@@ -1010,10 +1004,19 @@ export function ParseInLocation(
1010
1004
  return Time.create(date, 0, undefined, loc)
1011
1005
  }
1012
1006
 
1013
- // After waits for the duration to elapse and then returns the current time
1014
- export async function After(d: Duration): Promise<Time> {
1015
- await Sleep(d)
1016
- return Now()
1007
+ // After waits for the duration to elapse and then sends the current time on the returned channel
1008
+ export function After(d: Duration): ChannelRef<Time> {
1009
+ const ms = d / 1000000 // Convert nanoseconds to milliseconds
1010
+
1011
+ // Create a buffered channel with capacity 1
1012
+ const channel = makeChannel(1, new Time(), 'both')
1013
+
1014
+ // Start a timer that will send the current time after the duration
1015
+ setTimeout(async () => {
1016
+ channel.send(Now()).catch(() => {})
1017
+ }, ms)
1018
+
1019
+ return makeChannelRef(channel, 'receive')
1017
1020
  }
1018
1021
 
1019
1022
  // AfterFunc waits for the duration to elapse and then calls f
@@ -1056,6 +1059,6 @@ export function LoadLocationFromTZData(
1056
1059
  name: string,
1057
1060
  _data: Uint8Array,
1058
1061
  ): Location {
1059
- // In a real implementation, this would parse the timezone data
1062
+ // TODO: parse the timezone data
1060
1063
  return new Location(name)
1061
1064
  }
@@ -0,0 +1,24 @@
1
+ {
2
+ "asyncMethods": {
3
+ "IsControl": false,
4
+ "IsDigit": false,
5
+ "IsGraphic": false,
6
+ "IsLetter": false,
7
+ "IsLower": false,
8
+ "IsMark": false,
9
+ "IsNumber": false,
10
+ "IsPrint": false,
11
+ "IsPunct": false,
12
+ "IsSpace": false,
13
+ "IsSymbol": false,
14
+ "IsTitle": false,
15
+ "IsUpper": false,
16
+ "ToLower": false,
17
+ "ToTitle": false,
18
+ "ToUpper": false,
19
+ "SimpleFold": false,
20
+ "In": false,
21
+ "Is": false,
22
+ "IsOneOf": false
23
+ }
24
+ }
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.51",
4
+ "version": "0.0.53",
5
5
  "author": {
6
6
  "name": "Aperture Robotics LLC.",
7
7
  "email": "support@aperture.us",
@@ -1,38 +0,0 @@
1
- package unicode
2
-
3
- import "github.com/aperturerobotics/goscript/compiler"
4
-
5
- // Metadata for unicode package functions
6
- // Most unicode functions are synchronous character operations
7
-
8
- // Character classification functions
9
- var (
10
- IsControlInfo = compiler.FunctionInfo{IsAsync: false}
11
- IsDigitInfo = compiler.FunctionInfo{IsAsync: false}
12
- IsGraphicInfo = compiler.FunctionInfo{IsAsync: false}
13
- IsLetterInfo = compiler.FunctionInfo{IsAsync: false}
14
- IsLowerInfo = compiler.FunctionInfo{IsAsync: false}
15
- IsMarkInfo = compiler.FunctionInfo{IsAsync: false}
16
- IsNumberInfo = compiler.FunctionInfo{IsAsync: false}
17
- IsPrintInfo = compiler.FunctionInfo{IsAsync: false}
18
- IsPunctInfo = compiler.FunctionInfo{IsAsync: false}
19
- IsSpaceInfo = compiler.FunctionInfo{IsAsync: false}
20
- IsSymbolInfo = compiler.FunctionInfo{IsAsync: false}
21
- IsTitleInfo = compiler.FunctionInfo{IsAsync: false}
22
- IsUpperInfo = compiler.FunctionInfo{IsAsync: false}
23
- )
24
-
25
- // Case conversion functions
26
- var (
27
- ToLowerInfo = compiler.FunctionInfo{IsAsync: false}
28
- ToTitleInfo = compiler.FunctionInfo{IsAsync: false}
29
- ToUpperInfo = compiler.FunctionInfo{IsAsync: false}
30
- SimpleFoldInfo = compiler.FunctionInfo{IsAsync: false}
31
- )
32
-
33
- // Category functions
34
- var (
35
- InInfo = compiler.FunctionInfo{IsAsync: false}
36
- IsInfo = compiler.FunctionInfo{IsAsync: false}
37
- IsOneOfInfo = compiler.FunctionInfo{IsAsync: false}
38
- )