goscript 0.0.43 → 0.0.45
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/compiler/analysis.go +98 -0
- package/compiler/composite-lit.go +17 -0
- package/compiler/decl.go +13 -4
- package/compiler/spec-struct.go +30 -23
- package/compiler/spec.go +29 -7
- package/dist/gs/builtin/errors.js +1 -1
- package/dist/gs/builtin/slice.js +2 -1
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.js +0 -15
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/fmt/index.d.ts +2 -1
- package/dist/gs/fmt/index.js.map +1 -1
- package/dist/gs/os/error.gs.d.ts +1 -1
- package/dist/gs/os/error.gs.js +1 -1
- package/dist/gs/os/error.gs.js.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +1 -1
- package/dist/gs/path/filepath/path.js +1 -1
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/time/time.js +11 -3
- package/dist/gs/time/time.js.map +1 -1
- package/gs/builtin/builtin.ts +1 -1
- package/gs/builtin/errors.ts +2 -2
- package/gs/builtin/slice.ts +24 -8
- package/gs/builtin/type.ts +0 -16
- package/gs/fmt/fmt.ts +12 -3
- package/gs/fmt/index.ts +4 -0
- package/gs/os/error.gs.ts +1 -1
- package/gs/path/filepath/path.test.ts +2 -2
- package/gs/path/filepath/path.ts +3 -10
- package/gs/reflect/value.ts +10 -2
- package/gs/time/time.ts +52 -17
- package/package.json +1 -1
package/gs/reflect/value.ts
CHANGED
|
@@ -210,11 +210,19 @@ export function MakeChan(typ: Type, buffer: number): Value {
|
|
|
210
210
|
export function Select(cases: $.Slice<SelectCase>): [number, Value, boolean] {
|
|
211
211
|
// Extract the backing array from the GoScript slice
|
|
212
212
|
let selectCases: SelectCase[] = []
|
|
213
|
-
|
|
213
|
+
|
|
214
214
|
if (cases && typeof cases === 'object') {
|
|
215
215
|
if ('__meta__' in cases) {
|
|
216
216
|
// This is a GoScript SliceProxy, extract the backing array
|
|
217
|
-
const meta = (
|
|
217
|
+
const meta = (
|
|
218
|
+
cases as {
|
|
219
|
+
__meta__?: {
|
|
220
|
+
backing?: SelectCase[]
|
|
221
|
+
offset?: number
|
|
222
|
+
length?: number
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
).__meta__
|
|
218
226
|
if (meta && meta.backing) {
|
|
219
227
|
const offset = meta.offset ?? 0
|
|
220
228
|
const length = meta.length ?? meta.backing.length
|
package/gs/time/time.ts
CHANGED
|
@@ -34,7 +34,9 @@ export class Time {
|
|
|
34
34
|
|
|
35
35
|
// UnixMicro returns t as a Unix time, the number of microseconds elapsed since January 1, 1970 UTC
|
|
36
36
|
public UnixMicro(): number {
|
|
37
|
-
return
|
|
37
|
+
return (
|
|
38
|
+
Math.floor(this._date.getTime() * 1000) + Math.floor(this._nsec / 1000)
|
|
39
|
+
)
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
// UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC
|
|
@@ -656,7 +658,15 @@ export enum Weekday {
|
|
|
656
658
|
|
|
657
659
|
// WeekdayString returns the string representation of a Weekday
|
|
658
660
|
export function WeekdayString(w: Weekday): string {
|
|
659
|
-
const names = [
|
|
661
|
+
const names = [
|
|
662
|
+
'Sunday',
|
|
663
|
+
'Monday',
|
|
664
|
+
'Tuesday',
|
|
665
|
+
'Wednesday',
|
|
666
|
+
'Thursday',
|
|
667
|
+
'Friday',
|
|
668
|
+
'Saturday',
|
|
669
|
+
]
|
|
660
670
|
return names[w] || 'Unknown'
|
|
661
671
|
}
|
|
662
672
|
|
|
@@ -712,7 +722,7 @@ export class Timer {
|
|
|
712
722
|
this._duration = duration
|
|
713
723
|
this._callback = callback
|
|
714
724
|
const ms = duration.valueOf() / 1000000 // Convert nanoseconds to milliseconds
|
|
715
|
-
|
|
725
|
+
|
|
716
726
|
if (callback) {
|
|
717
727
|
this._timeout = setTimeout(callback, ms)
|
|
718
728
|
} else {
|
|
@@ -775,10 +785,10 @@ export class Ticker {
|
|
|
775
785
|
}
|
|
776
786
|
|
|
777
787
|
// Channel returns an async iterator that yields time values
|
|
778
|
-
public async*
|
|
788
|
+
public async *Channel(): AsyncIterableIterator<Time> {
|
|
779
789
|
const ms = this._duration.valueOf() / 1000000
|
|
780
790
|
while (!this._stopped) {
|
|
781
|
-
await new Promise(resolve => setTimeout(resolve, ms))
|
|
791
|
+
await new Promise((resolve) => setTimeout(resolve, ms))
|
|
782
792
|
if (!this._stopped) {
|
|
783
793
|
yield Now()
|
|
784
794
|
}
|
|
@@ -925,15 +935,15 @@ export function UnixNano(nsec: number): Time {
|
|
|
925
935
|
export function ParseDuration(s: string): Duration {
|
|
926
936
|
const regex = /^([+-]?)(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)$/
|
|
927
937
|
const match = s.match(regex)
|
|
928
|
-
|
|
938
|
+
|
|
929
939
|
if (!match) {
|
|
930
940
|
throw new Error(`time: invalid duration "${s}"`)
|
|
931
941
|
}
|
|
932
|
-
|
|
942
|
+
|
|
933
943
|
const [, sign, valueStr, unit] = match
|
|
934
944
|
let value = parseFloat(valueStr)
|
|
935
945
|
if (sign === '-') value = -value
|
|
936
|
-
|
|
946
|
+
|
|
937
947
|
let nanoseconds: number
|
|
938
948
|
switch (unit) {
|
|
939
949
|
case 'ns':
|
|
@@ -958,7 +968,7 @@ export function ParseDuration(s: string): Duration {
|
|
|
958
968
|
default:
|
|
959
969
|
throw new Error(`time: unknown unit "${unit}" in duration "${s}"`)
|
|
960
970
|
}
|
|
961
|
-
|
|
971
|
+
|
|
962
972
|
return new Duration(Math.floor(nanoseconds))
|
|
963
973
|
}
|
|
964
974
|
|
|
@@ -968,31 +978,53 @@ export function Parse(layout: string, value: string): Time {
|
|
|
968
978
|
}
|
|
969
979
|
|
|
970
980
|
// ParseInLocation is like Parse but differs in two important ways
|
|
971
|
-
export function ParseInLocation(
|
|
981
|
+
export function ParseInLocation(
|
|
982
|
+
layout: string,
|
|
983
|
+
value: string,
|
|
984
|
+
loc: Location,
|
|
985
|
+
): Time {
|
|
972
986
|
// This is a simplified implementation
|
|
973
987
|
// A full implementation would need to parse according to the layout format
|
|
974
|
-
|
|
988
|
+
|
|
975
989
|
// Handle common layouts
|
|
976
990
|
if (layout === RFC3339 || layout === '2006-01-02T15:04:05Z07:00') {
|
|
977
991
|
const date = new globalThis.Date(value)
|
|
978
992
|
if (isNaN(date.getTime())) {
|
|
979
|
-
throw new ParseError(
|
|
993
|
+
throw new ParseError(
|
|
994
|
+
layout,
|
|
995
|
+
value,
|
|
996
|
+
'',
|
|
997
|
+
'',
|
|
998
|
+
`parsing time "${value}" as "${layout}": cannot parse`,
|
|
999
|
+
)
|
|
980
1000
|
}
|
|
981
1001
|
return new Time(date, 0, undefined, loc)
|
|
982
1002
|
}
|
|
983
|
-
|
|
1003
|
+
|
|
984
1004
|
if (layout === DateTime || layout === '2006-01-02 15:04:05') {
|
|
985
1005
|
const date = new globalThis.Date(value)
|
|
986
1006
|
if (isNaN(date.getTime())) {
|
|
987
|
-
throw new ParseError(
|
|
1007
|
+
throw new ParseError(
|
|
1008
|
+
layout,
|
|
1009
|
+
value,
|
|
1010
|
+
'',
|
|
1011
|
+
'',
|
|
1012
|
+
`parsing time "${value}" as "${layout}": cannot parse`,
|
|
1013
|
+
)
|
|
988
1014
|
}
|
|
989
1015
|
return new Time(date, 0, undefined, loc)
|
|
990
1016
|
}
|
|
991
|
-
|
|
1017
|
+
|
|
992
1018
|
// Fallback to standard Date parsing
|
|
993
1019
|
const date = new globalThis.Date(value)
|
|
994
1020
|
if (isNaN(date.getTime())) {
|
|
995
|
-
throw new ParseError(
|
|
1021
|
+
throw new ParseError(
|
|
1022
|
+
layout,
|
|
1023
|
+
value,
|
|
1024
|
+
'',
|
|
1025
|
+
'',
|
|
1026
|
+
`parsing time "${value}" as "${layout}": cannot parse`,
|
|
1027
|
+
)
|
|
996
1028
|
}
|
|
997
1029
|
return new Time(date, 0, undefined, loc)
|
|
998
1030
|
}
|
|
@@ -1039,7 +1071,10 @@ export function LoadLocation(name: string): Location {
|
|
|
1039
1071
|
|
|
1040
1072
|
// LoadLocationFromTZData returns a Location with the given name
|
|
1041
1073
|
// This is a simplified implementation
|
|
1042
|
-
export function LoadLocationFromTZData(
|
|
1074
|
+
export function LoadLocationFromTZData(
|
|
1075
|
+
name: string,
|
|
1076
|
+
_data: Uint8Array,
|
|
1077
|
+
): Location {
|
|
1043
1078
|
// In a real implementation, this would parse the timezone data
|
|
1044
1079
|
return new Location(name)
|
|
1045
1080
|
}
|