goscript 0.0.48 → 0.0.50
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/cmd/goscript/deps.go +1 -4
- package/compiler/analysis.go +1120 -513
- package/compiler/analysis_test.go +113 -4
- package/compiler/compiler.go +88 -124
- package/compiler/decl.go +22 -0
- package/compiler/expr-call-async.go +46 -52
- package/compiler/expr-call-type-conversion.go +144 -59
- package/compiler/expr-call.go +235 -12
- package/compiler/expr.go +5 -82
- package/compiler/gs_dependencies_test.go +60 -1
- package/compiler/spec-value.go +73 -51
- package/compiler/spec.go +337 -151
- package/compiler/stmt-assign.go +7 -4
- package/compiler/stmt.go +250 -81
- package/compiler/type.go +13 -0
- package/dist/gs/builtin/builtin.d.ts +1 -5
- package/dist/gs/builtin/builtin.js +1 -34
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/context/context.d.ts +16 -18
- package/dist/gs/context/context.js +23 -13
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/fmt/fmt.js +22 -4
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/io/fs/fs.d.ts +6 -12
- package/dist/gs/io/fs/fs.js +52 -67
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/os/index.d.ts +2 -1
- package/dist/gs/os/index.js +1 -1
- package/dist/gs/os/index.js.map +1 -1
- package/dist/gs/os/types_js.gs.d.ts +7 -1
- package/dist/gs/os/types_js.gs.js +16 -1
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.js +2 -2
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +3 -3
- package/dist/gs/reflect/index.js +2 -2
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/map.js +2 -2
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +8 -9
- package/dist/gs/reflect/type.js +98 -103
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.d.ts +1 -10
- package/dist/gs/reflect/types.js +3 -26
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/value.js +23 -23
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/reflect/visiblefields.js +3 -3
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/time/time.d.ts +13 -23
- package/dist/gs/time/time.js +57 -75
- package/dist/gs/time/time.js.map +1 -1
- package/gs/builtin/builtin.ts +3 -47
- package/gs/builtin/slice.ts +1 -1
- package/gs/bytes/meta.json +10 -0
- package/gs/context/context.ts +63 -45
- package/gs/fmt/fmt.ts +22 -4
- package/gs/fmt/meta.json +5 -0
- package/gs/internal/meta.json +5 -0
- package/gs/io/fs/fs.ts +58 -73
- package/gs/io/meta.json +9 -0
- package/gs/maps/meta.json +6 -0
- package/gs/math/meta.json +5 -0
- package/gs/os/index.ts +8 -1
- package/gs/os/meta.json +15 -0
- package/gs/os/types_js.gs.ts +22 -1
- package/gs/os/types_unix.gs.ts +2 -2
- package/gs/path/meta.json +6 -0
- package/gs/reflect/function-types.test.ts +10 -10
- package/gs/reflect/index.ts +6 -6
- package/gs/reflect/map.ts +2 -2
- package/gs/reflect/meta.json +5 -0
- package/gs/reflect/type.ts +105 -105
- package/gs/reflect/types.ts +2 -28
- package/gs/reflect/value.ts +23 -23
- package/gs/reflect/visiblefields.ts +3 -3
- package/gs/strconv/meta.json +5 -0
- package/gs/strings/meta.json +9 -0
- package/gs/sync/meta.json +19 -0
- package/gs/time/time.ts +65 -84
- package/package.json +2 -2
- package/dist/gs/builtin/io.d.ts +0 -16
- package/dist/gs/builtin/io.js +0 -15
- package/dist/gs/builtin/io.js.map +0 -1
- package/dist/gs/internal/testlog/index.d.ts +0 -1
- package/dist/gs/internal/testlog/index.js +0 -5
- package/dist/gs/internal/testlog/index.js.map +0 -1
- package/dist/gs/maps/iter.gs.d.ts +0 -7
- package/dist/gs/maps/iter.gs.js +0 -65
- package/dist/gs/maps/iter.gs.js.map +0 -1
- package/dist/gs/maps/maps.gs.d.ts +0 -7
- package/dist/gs/maps/maps.gs.js +0 -79
- package/dist/gs/maps/maps.gs.js.map +0 -1
- package/dist/gs/reflect/abi.d.ts +0 -59
- package/dist/gs/reflect/abi.gs.d.ts +0 -59
- package/dist/gs/reflect/abi.gs.js +0 -79
- package/dist/gs/reflect/abi.gs.js.map +0 -1
- package/dist/gs/reflect/abi.js +0 -79
- package/dist/gs/reflect/abi.js.map +0 -1
- package/dist/gs/reflect/badlinkname.d.ts +0 -52
- package/dist/gs/reflect/badlinkname.gs.d.ts +0 -52
- package/dist/gs/reflect/badlinkname.gs.js +0 -72
- package/dist/gs/reflect/badlinkname.gs.js.map +0 -1
- package/dist/gs/reflect/badlinkname.js +0 -72
- package/dist/gs/reflect/badlinkname.js.map +0 -1
- package/dist/gs/reflect/deepequal.gs.d.ts +0 -25
- package/dist/gs/reflect/deepequal.gs.js +0 -308
- package/dist/gs/reflect/deepequal.gs.js.map +0 -1
- package/dist/gs/reflect/float32reg_generic.gs.d.ts +0 -2
- package/dist/gs/reflect/float32reg_generic.gs.js +0 -10
- package/dist/gs/reflect/float32reg_generic.gs.js.map +0 -1
- package/dist/gs/reflect/index.gs.d.ts +0 -1
- package/dist/gs/reflect/index.gs.js +0 -3
- package/dist/gs/reflect/index.gs.js.map +0 -1
- package/dist/gs/reflect/iter.gs.d.ts +0 -3
- package/dist/gs/reflect/iter.gs.js +0 -24
- package/dist/gs/reflect/iter.gs.js.map +0 -1
- package/dist/gs/reflect/makefunc.gs.d.ts +0 -34
- package/dist/gs/reflect/makefunc.gs.js +0 -288
- package/dist/gs/reflect/makefunc.gs.js.map +0 -1
- package/dist/gs/reflect/map_swiss.gs.d.ts +0 -14
- package/dist/gs/reflect/map_swiss.gs.js +0 -70
- package/dist/gs/reflect/map_swiss.gs.js.map +0 -1
- package/dist/gs/reflect/reflect.gs.d.ts +0 -132
- package/dist/gs/reflect/reflect.gs.js +0 -437
- package/dist/gs/reflect/reflect.gs.js.map +0 -1
- package/dist/gs/reflect/swapper.gs.d.ts +0 -1
- package/dist/gs/reflect/swapper.gs.js +0 -32
- package/dist/gs/reflect/swapper.gs.js.map +0 -1
- package/dist/gs/reflect/type.gs.d.ts +0 -4
- package/dist/gs/reflect/type.gs.js +0 -21
- package/dist/gs/reflect/type.gs.js.map +0 -1
- package/dist/gs/reflect/value.gs.d.ts +0 -4
- package/dist/gs/reflect/value.gs.js +0 -12
- package/dist/gs/reflect/value.gs.js.map +0 -1
- package/dist/gs/reflect/visiblefields.gs.d.ts +0 -3
- package/dist/gs/reflect/visiblefields.gs.js +0 -123
- package/dist/gs/reflect/visiblefields.gs.js.map +0 -1
- package/dist/gs/stringslite/index.d.ts +0 -1
- package/dist/gs/stringslite/index.js +0 -2
- package/dist/gs/stringslite/index.js.map +0 -1
- package/dist/gs/stringslite/strings.d.ts +0 -11
- package/dist/gs/stringslite/strings.js +0 -67
- package/dist/gs/stringslite/strings.js.map +0 -1
- package/gs/bytes/metadata.go +0 -12
- package/gs/fmt/metadata.go +0 -7
- package/gs/internal/metadata.go +0 -7
- package/gs/io/io.go +0 -75
- package/gs/io/metadata.go +0 -11
- package/gs/maps/metadata.go +0 -8
- package/gs/math/metadata.go +0 -7
- package/gs/os/metadata.go +0 -17
- package/gs/path/metadata.go +0 -8
- package/gs/reflect/metadata.go +0 -7
- package/gs/strconv/metadata.go +0 -7
- package/gs/strings/metadata.go +0 -11
- package/gs/sync/metadata.go +0 -7
- package/gs/sync/sync.go +0 -64
package/gs/context/context.ts
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import * as $ from '@goscript/builtin/index.js'
|
|
2
2
|
|
|
3
|
-
export const Canceled =
|
|
4
|
-
Canceled.name = 'CanceledError'
|
|
3
|
+
export const Canceled = $.newError('context canceled')
|
|
5
4
|
|
|
6
|
-
export
|
|
7
|
-
constructor() {
|
|
8
|
-
super('context deadline exceeded')
|
|
9
|
-
this.name = 'DeadlineExceededError'
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export const DeadlineExceeded = new DeadlineExceededError()
|
|
5
|
+
export const DeadlineExceeded = $.newError('context deadline exceeded')
|
|
13
6
|
|
|
14
7
|
// Function types
|
|
15
8
|
export type CancelFunc = () => void
|
|
16
|
-
export type CancelCauseFunc = (cause:
|
|
9
|
+
export type CancelCauseFunc = (cause: $.GoError) => void
|
|
17
10
|
|
|
18
11
|
// Context interface matching Go's context.Context
|
|
19
|
-
export
|
|
12
|
+
export type Context = null | {
|
|
20
13
|
// Deadline returns the time when work done on behalf of this context should be canceled
|
|
21
14
|
Deadline(): [Date | null, boolean]
|
|
22
15
|
|
|
@@ -24,17 +17,20 @@ export interface Context {
|
|
|
24
17
|
Done(): $.Channel<{}>
|
|
25
18
|
|
|
26
19
|
// Err returns a non-nil error value after Done is closed
|
|
27
|
-
Err():
|
|
20
|
+
Err(): $.GoError
|
|
28
21
|
|
|
29
22
|
// Value returns the value associated with this context for key, or null
|
|
30
23
|
Value(key: any): any
|
|
31
24
|
}
|
|
32
25
|
|
|
26
|
+
// ContextNonNil is a non-nil context
|
|
27
|
+
export type ContextNonNil = Exclude<Context, null>
|
|
28
|
+
|
|
33
29
|
// Base implementation for all contexts
|
|
34
|
-
abstract class baseContext implements
|
|
30
|
+
abstract class baseContext implements ContextNonNil {
|
|
35
31
|
abstract Deadline(): [Date | null, boolean]
|
|
36
32
|
abstract Done(): $.Channel<{}>
|
|
37
|
-
abstract Err():
|
|
33
|
+
abstract Err(): $.GoError
|
|
38
34
|
abstract Value(key: any): any
|
|
39
35
|
}
|
|
40
36
|
|
|
@@ -54,7 +50,7 @@ class backgroundContext extends baseContext {
|
|
|
54
50
|
return backgroundContext.neverClosedChannel
|
|
55
51
|
}
|
|
56
52
|
|
|
57
|
-
Err():
|
|
53
|
+
Err(): $.GoError {
|
|
58
54
|
return null
|
|
59
55
|
}
|
|
60
56
|
|
|
@@ -66,14 +62,14 @@ class backgroundContext extends baseContext {
|
|
|
66
62
|
// Value context wraps a parent and adds a key-value pair
|
|
67
63
|
class valueContext extends baseContext {
|
|
68
64
|
constructor(
|
|
69
|
-
private parent:
|
|
65
|
+
private parent: ContextNonNil,
|
|
70
66
|
private key: any,
|
|
71
67
|
private val: any,
|
|
72
68
|
) {
|
|
73
69
|
super()
|
|
74
70
|
}
|
|
75
71
|
|
|
76
|
-
getParent():
|
|
72
|
+
getParent(): ContextNonNil {
|
|
77
73
|
return this.parent
|
|
78
74
|
}
|
|
79
75
|
|
|
@@ -85,7 +81,7 @@ class valueContext extends baseContext {
|
|
|
85
81
|
return this.parent.Done()
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
Err():
|
|
84
|
+
Err(): $.GoError {
|
|
89
85
|
return this.parent.Err()
|
|
90
86
|
}
|
|
91
87
|
|
|
@@ -100,14 +96,14 @@ class valueContext extends baseContext {
|
|
|
100
96
|
// Cancel context that can be canceled
|
|
101
97
|
class cancelContext extends baseContext {
|
|
102
98
|
protected doneChannel: $.Channel<{}>
|
|
103
|
-
protected err:
|
|
104
|
-
protected cause:
|
|
99
|
+
protected err: $.GoError = null
|
|
100
|
+
protected cause: $.GoError = null
|
|
105
101
|
protected children: Set<cancelContext> = new Set()
|
|
106
|
-
protected parent:
|
|
102
|
+
protected parent: ContextNonNil
|
|
107
103
|
protected parentCancelCtx: cancelContext | null = null
|
|
108
104
|
protected removeFromParent: (() => void) | null = null
|
|
109
105
|
|
|
110
|
-
constructor(parent:
|
|
106
|
+
constructor(parent: ContextNonNil) {
|
|
111
107
|
super()
|
|
112
108
|
this.parent = parent
|
|
113
109
|
this.doneChannel = $.makeChannel<{}>(0, {}, 'both')
|
|
@@ -121,7 +117,7 @@ class cancelContext extends baseContext {
|
|
|
121
117
|
return this.doneChannel
|
|
122
118
|
}
|
|
123
119
|
|
|
124
|
-
Err():
|
|
120
|
+
Err(): $.GoError {
|
|
125
121
|
return this.err
|
|
126
122
|
}
|
|
127
123
|
|
|
@@ -129,14 +125,11 @@ class cancelContext extends baseContext {
|
|
|
129
125
|
return this.parent.Value(key)
|
|
130
126
|
}
|
|
131
127
|
|
|
132
|
-
getCause():
|
|
133
|
-
|
|
134
|
-
return this.cause
|
|
135
|
-
}
|
|
136
|
-
return this.err
|
|
128
|
+
getCause(): $.GoError {
|
|
129
|
+
return this.cause ?? this.err
|
|
137
130
|
}
|
|
138
131
|
|
|
139
|
-
cancel(removeFromParent: boolean, err:
|
|
132
|
+
cancel(removeFromParent: boolean, err: $.GoError, cause: $.GoError): void {
|
|
140
133
|
if (this.err !== null) {
|
|
141
134
|
return // Already canceled
|
|
142
135
|
}
|
|
@@ -205,7 +198,7 @@ class timerContext extends cancelContext {
|
|
|
205
198
|
private deadline: Date
|
|
206
199
|
private timer: any
|
|
207
200
|
|
|
208
|
-
constructor(parent:
|
|
201
|
+
constructor(parent: ContextNonNil, deadline: Date) {
|
|
209
202
|
super(parent)
|
|
210
203
|
this.deadline = deadline
|
|
211
204
|
}
|
|
@@ -229,7 +222,7 @@ class timerContext extends cancelContext {
|
|
|
229
222
|
}, duration)
|
|
230
223
|
}
|
|
231
224
|
|
|
232
|
-
cancel(removeFromParent: boolean, err:
|
|
225
|
+
cancel(removeFromParent: boolean, err: $.GoError, cause: $.GoError): void {
|
|
233
226
|
super.cancel(removeFromParent, err, cause)
|
|
234
227
|
if (this.timer) {
|
|
235
228
|
clearTimeout(this.timer)
|
|
@@ -240,7 +233,7 @@ class timerContext extends cancelContext {
|
|
|
240
233
|
|
|
241
234
|
// Without cancel context - inherits values but not cancellation
|
|
242
235
|
class withoutCancelContext extends baseContext {
|
|
243
|
-
constructor(private parent:
|
|
236
|
+
constructor(private parent: ContextNonNil) {
|
|
244
237
|
super()
|
|
245
238
|
}
|
|
246
239
|
|
|
@@ -252,7 +245,7 @@ class withoutCancelContext extends baseContext {
|
|
|
252
245
|
return backgroundContext.getNeverClosedChannel()
|
|
253
246
|
}
|
|
254
247
|
|
|
255
|
-
Err():
|
|
248
|
+
Err(): $.GoError {
|
|
256
249
|
return null
|
|
257
250
|
}
|
|
258
251
|
|
|
@@ -276,7 +269,10 @@ export function TODO(): Context {
|
|
|
276
269
|
}
|
|
277
270
|
|
|
278
271
|
// WithCancel returns a copy of parent with a new Done channel
|
|
279
|
-
export function WithCancel(parent: Context): [
|
|
272
|
+
export function WithCancel(parent: Context): [ContextNonNil, CancelFunc] {
|
|
273
|
+
if (parent === null) {
|
|
274
|
+
throw new Error('cannot create context from nil parent')
|
|
275
|
+
}
|
|
280
276
|
const ctx = new cancelContext(parent)
|
|
281
277
|
ctx.propagateCancel()
|
|
282
278
|
|
|
@@ -289,20 +285,28 @@ export function WithCancel(parent: Context): [Context, CancelFunc] {
|
|
|
289
285
|
}
|
|
290
286
|
|
|
291
287
|
// WithCancelCause returns a copy of parent with a new Done channel and cause recording
|
|
292
|
-
export function WithCancelCause(
|
|
288
|
+
export function WithCancelCause(
|
|
289
|
+
parent: Context,
|
|
290
|
+
): [ContextNonNil, CancelCauseFunc] {
|
|
291
|
+
if (parent === null) {
|
|
292
|
+
throw new Error('cannot create context from nil parent')
|
|
293
|
+
}
|
|
293
294
|
const ctx = new cancelContext(parent)
|
|
294
295
|
ctx.propagateCancel()
|
|
295
296
|
|
|
296
297
|
return [
|
|
297
298
|
ctx,
|
|
298
|
-
(cause:
|
|
299
|
+
(cause: $.GoError) => {
|
|
299
300
|
ctx.cancel(true, Canceled, cause)
|
|
300
301
|
},
|
|
301
302
|
]
|
|
302
303
|
}
|
|
303
304
|
|
|
304
305
|
// WithDeadline returns a copy of parent with the deadline adjusted to be no later than d
|
|
305
|
-
export function WithDeadline(
|
|
306
|
+
export function WithDeadline(
|
|
307
|
+
parent: Context,
|
|
308
|
+
d: Date,
|
|
309
|
+
): [ContextNonNil, CancelFunc] {
|
|
306
310
|
return WithDeadlineCause(parent, d, null)
|
|
307
311
|
}
|
|
308
312
|
|
|
@@ -310,8 +314,11 @@ export function WithDeadline(parent: Context, d: Date): [Context, CancelFunc] {
|
|
|
310
314
|
export function WithDeadlineCause(
|
|
311
315
|
parent: Context,
|
|
312
316
|
d: Date,
|
|
313
|
-
cause:
|
|
314
|
-
): [
|
|
317
|
+
cause: $.GoError,
|
|
318
|
+
): [ContextNonNil, CancelFunc] {
|
|
319
|
+
if (parent === null) {
|
|
320
|
+
throw new Error('cannot create context from nil parent')
|
|
321
|
+
}
|
|
315
322
|
// Check if parent deadline is already earlier
|
|
316
323
|
const [parentDeadline, ok] = parent.Deadline()
|
|
317
324
|
if (ok && parentDeadline && parentDeadline <= d) {
|
|
@@ -335,7 +342,7 @@ export function WithDeadlineCause(
|
|
|
335
342
|
export function WithTimeout(
|
|
336
343
|
parent: Context,
|
|
337
344
|
timeout: number,
|
|
338
|
-
): [
|
|
345
|
+
): [ContextNonNil, CancelFunc] {
|
|
339
346
|
return WithDeadline(parent, new Date(Date.now() + timeout))
|
|
340
347
|
}
|
|
341
348
|
|
|
@@ -343,23 +350,31 @@ export function WithTimeout(
|
|
|
343
350
|
export function WithTimeoutCause(
|
|
344
351
|
parent: Context,
|
|
345
352
|
timeout: number,
|
|
346
|
-
cause:
|
|
347
|
-
): [
|
|
353
|
+
cause: $.GoError,
|
|
354
|
+
): [ContextNonNil, CancelFunc] {
|
|
348
355
|
return WithDeadlineCause(parent, new Date(Date.now() + timeout), cause)
|
|
349
356
|
}
|
|
350
357
|
|
|
351
358
|
// WithValue returns a copy of parent with the value associated with key
|
|
352
|
-
export function WithValue(parent: Context, key: any, val: any):
|
|
359
|
+
export function WithValue(parent: Context, key: any, val: any): ContextNonNil {
|
|
360
|
+
if (parent === null) {
|
|
361
|
+
throw new Error('cannot create context from nil parent')
|
|
362
|
+
}
|
|
353
363
|
return new valueContext(parent, key, val)
|
|
354
364
|
}
|
|
355
365
|
|
|
356
366
|
// WithoutCancel returns a context that inherits values but not cancellation
|
|
357
|
-
export function WithoutCancel(parent: Context):
|
|
367
|
+
export function WithoutCancel(parent: Context): ContextNonNil {
|
|
368
|
+
if (parent === null) {
|
|
369
|
+
throw new Error('cannot create context from nil parent')
|
|
370
|
+
}
|
|
358
371
|
return new withoutCancelContext(parent)
|
|
359
372
|
}
|
|
360
373
|
|
|
361
374
|
// Cause returns the underlying cause of the context's cancellation
|
|
362
|
-
export function Cause(ctx: Context):
|
|
375
|
+
export function Cause(ctx: Context): $.GoError {
|
|
376
|
+
if (!ctx) return null
|
|
377
|
+
|
|
363
378
|
let c = ctx
|
|
364
379
|
// Unwrap value contexts
|
|
365
380
|
while (c instanceof valueContext) {
|
|
@@ -375,6 +390,9 @@ export function Cause(ctx: Context): Error | null {
|
|
|
375
390
|
|
|
376
391
|
// AfterFunc runs f in a separate goroutine after ctx is done
|
|
377
392
|
export function AfterFunc(ctx: Context, f: () => void): () => boolean {
|
|
393
|
+
if (ctx === null) {
|
|
394
|
+
throw new Error('cannot create context from nil parent')
|
|
395
|
+
}
|
|
378
396
|
let stopped = false
|
|
379
397
|
let done = false
|
|
380
398
|
|
package/gs/fmt/fmt.ts
CHANGED
|
@@ -200,10 +200,28 @@ function parseFormat(format: string, args: any[]): string {
|
|
|
200
200
|
// Global stdout simulation for Print functions
|
|
201
201
|
let stdout = {
|
|
202
202
|
write: (data: string) => {
|
|
203
|
-
//
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
// Use process.stdout.write if available (Node.js), otherwise fallback to console.log
|
|
204
|
+
// but we need to avoid adding extra newlines that console.log adds
|
|
205
|
+
if (
|
|
206
|
+
typeof process !== 'undefined' &&
|
|
207
|
+
process.stdout &&
|
|
208
|
+
process.stdout.write
|
|
209
|
+
) {
|
|
210
|
+
process.stdout.write(data)
|
|
211
|
+
} else {
|
|
212
|
+
// In browser environments, we need to use console.log but handle newlines carefully
|
|
213
|
+
// If the data already ends with \n, we should strip it to avoid double newlines
|
|
214
|
+
if (data.endsWith('\n')) {
|
|
215
|
+
console.log(data.slice(0, -1))
|
|
216
|
+
} else {
|
|
217
|
+
// Use console.log without adding newline by using a custom method
|
|
218
|
+
if (console.log) {
|
|
219
|
+
// For data without newlines, we can just print it directly
|
|
220
|
+
// This is a bit of a hack but works for most cases
|
|
221
|
+
console.log(data)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
207
225
|
},
|
|
208
226
|
}
|
|
209
227
|
|
package/gs/io/fs/fs.ts
CHANGED
|
@@ -369,148 +369,133 @@ $.registerInterfaceType(
|
|
|
369
369
|
],
|
|
370
370
|
)
|
|
371
371
|
|
|
372
|
-
export
|
|
373
|
-
constructor(private _value: number) {}
|
|
372
|
+
export type FileMode = number
|
|
374
373
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
return fileModeString(this)
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
static from(value: number): FileMode {
|
|
384
|
-
return new FileMode(value)
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// IsDir reports whether m describes a directory.
|
|
388
|
-
// That is, it tests for the ModeDir bit being set in m.
|
|
389
|
-
IsDir(): boolean {
|
|
390
|
-
return (this._value & ModeDir.valueOf()) != 0
|
|
391
|
-
}
|
|
374
|
+
// IsDir reports whether m describes a directory.
|
|
375
|
+
// That is, it tests for the ModeDir bit being set in m.
|
|
376
|
+
export function FileMode_IsDir(receiver: FileMode): boolean {
|
|
377
|
+
return (receiver & ModeDir) != 0
|
|
378
|
+
}
|
|
392
379
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
380
|
+
// IsRegular reports whether m describes a regular file.
|
|
381
|
+
// That is, it tests that no mode type bits are set.
|
|
382
|
+
export function FileMode_IsRegular(receiver: FileMode): boolean {
|
|
383
|
+
return (receiver & ModeType) == 0
|
|
384
|
+
}
|
|
398
385
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
386
|
+
// Perm returns the Unix permission bits in m (m & ModePerm).
|
|
387
|
+
export function FileMode_Perm(receiver: FileMode): FileMode {
|
|
388
|
+
return (receiver & ModePerm) as FileMode
|
|
389
|
+
}
|
|
403
390
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
391
|
+
// String returns a textual representation of the file mode.
|
|
392
|
+
export function FileMode_String(receiver: FileMode): string {
|
|
393
|
+
return fileModeString(receiver)
|
|
394
|
+
}
|
|
408
395
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
396
|
+
// Type returns type bits in m (m & ModeType).
|
|
397
|
+
export function FileMode_Type(receiver: FileMode): FileMode {
|
|
398
|
+
return ((receiver & ModeType) >>> 0) as FileMode
|
|
413
399
|
}
|
|
414
400
|
|
|
415
401
|
// The single letters are the abbreviations
|
|
416
402
|
// used by the String method's formatting.
|
|
417
403
|
// d: is a directory
|
|
418
|
-
export let ModeDir: FileMode =
|
|
404
|
+
export let ModeDir: FileMode = 2147483648 // 0x80000000
|
|
419
405
|
|
|
420
406
|
// a: append-only
|
|
421
|
-
export let ModeAppend: FileMode =
|
|
407
|
+
export let ModeAppend: FileMode = 1 << 30 // 0x40000000
|
|
422
408
|
|
|
423
409
|
// l: exclusive use
|
|
424
|
-
export let ModeExclusive: FileMode =
|
|
410
|
+
export let ModeExclusive: FileMode = 1 << 29 // 0x20000000
|
|
425
411
|
|
|
426
412
|
// T: temporary file; Plan 9 only
|
|
427
|
-
export let ModeTemporary: FileMode =
|
|
413
|
+
export let ModeTemporary: FileMode = 1 << 28 // 0x10000000
|
|
428
414
|
|
|
429
415
|
// L: symbolic link
|
|
430
|
-
export let ModeSymlink: FileMode =
|
|
416
|
+
export let ModeSymlink: FileMode = 1 << 27 // 0x08000000
|
|
431
417
|
|
|
432
418
|
// D: device file
|
|
433
|
-
export let ModeDevice: FileMode =
|
|
419
|
+
export let ModeDevice: FileMode = 1 << 26 // 0x04000000
|
|
434
420
|
|
|
435
421
|
// p: named pipe (FIFO)
|
|
436
|
-
export let ModeNamedPipe: FileMode =
|
|
422
|
+
export let ModeNamedPipe: FileMode = 1 << 25 // 0x02000000
|
|
437
423
|
|
|
438
424
|
// S: Unix domain socket
|
|
439
|
-
export let ModeSocket: FileMode =
|
|
425
|
+
export let ModeSocket: FileMode = 1 << 24 // 0x01000000
|
|
440
426
|
|
|
441
427
|
// u: setuid
|
|
442
|
-
export let ModeSetuid: FileMode =
|
|
428
|
+
export let ModeSetuid: FileMode = 1 << 23 // 0x00800000
|
|
443
429
|
|
|
444
430
|
// g: setgid
|
|
445
|
-
export let ModeSetgid: FileMode =
|
|
431
|
+
export let ModeSetgid: FileMode = 1 << 22 // 0x00400000
|
|
446
432
|
|
|
447
433
|
// c: Unix character device, when ModeDevice is set
|
|
448
|
-
export let ModeCharDevice: FileMode =
|
|
434
|
+
export let ModeCharDevice: FileMode = 1 << 21 // 0x00200000
|
|
449
435
|
|
|
450
436
|
// t: sticky
|
|
451
|
-
export let ModeSticky: FileMode =
|
|
437
|
+
export let ModeSticky: FileMode = 1 << 20 // 0x00100000
|
|
452
438
|
|
|
453
439
|
// ?: non-regular file; nothing else is known about this file
|
|
454
|
-
export let ModeIrregular: FileMode =
|
|
440
|
+
export let ModeIrregular: FileMode = 1 << 19 // 0x00080000
|
|
455
441
|
|
|
456
442
|
// Mask for the type bits. For regular files, none will be set.
|
|
457
|
-
export let ModeType: FileMode =
|
|
443
|
+
export let ModeType: FileMode = 2401763328
|
|
458
444
|
|
|
459
445
|
// Unix permission bits
|
|
460
|
-
export let ModePerm: FileMode =
|
|
446
|
+
export let ModePerm: FileMode = 0o777
|
|
461
447
|
|
|
462
448
|
// FileMode methods
|
|
463
449
|
export function fileModeString(mode: FileMode): string {
|
|
464
450
|
const buf: string[] = []
|
|
465
|
-
const w = mode
|
|
451
|
+
const w = mode
|
|
466
452
|
|
|
467
453
|
// File type - these are the main type indicators
|
|
468
|
-
if (w & ModeDir
|
|
469
|
-
else if (w & ModeSymlink
|
|
470
|
-
else if (w & ModeNamedPipe
|
|
471
|
-
else if (w & ModeSocket
|
|
472
|
-
else if (w & ModeDevice
|
|
473
|
-
if (w & ModeCharDevice
|
|
454
|
+
if (w & ModeDir) buf.push('d')
|
|
455
|
+
else if (w & ModeSymlink) buf.push('L')
|
|
456
|
+
else if (w & ModeNamedPipe) buf.push('p')
|
|
457
|
+
else if (w & ModeSocket) buf.push('S')
|
|
458
|
+
else if (w & ModeDevice) {
|
|
459
|
+
if (w & ModeCharDevice) buf.push('c')
|
|
474
460
|
else buf.push('D')
|
|
475
|
-
}
|
|
476
|
-
else if (w & ModeIrregular.valueOf()) buf.push('?')
|
|
461
|
+
} else if (w & ModeIrregular) buf.push('?')
|
|
477
462
|
else buf.push('-')
|
|
478
463
|
|
|
479
464
|
// Permission bits
|
|
480
|
-
const perm = w & ModePerm
|
|
465
|
+
const perm = w & ModePerm
|
|
481
466
|
buf.push(perm & 0o400 ? 'r' : '-')
|
|
482
467
|
buf.push(perm & 0o200 ? 'w' : '-')
|
|
483
|
-
|
|
468
|
+
|
|
484
469
|
// Execute/search for user
|
|
485
470
|
if (perm & 0o100) {
|
|
486
|
-
if (w & ModeSetuid
|
|
471
|
+
if (w & ModeSetuid) buf.push('s')
|
|
487
472
|
else buf.push('x')
|
|
488
473
|
} else {
|
|
489
|
-
if (w & ModeSetuid
|
|
474
|
+
if (w & ModeSetuid) buf.push('S')
|
|
490
475
|
else buf.push('-')
|
|
491
476
|
}
|
|
492
|
-
|
|
477
|
+
|
|
493
478
|
buf.push(perm & 0o040 ? 'r' : '-')
|
|
494
479
|
buf.push(perm & 0o020 ? 'w' : '-')
|
|
495
|
-
|
|
480
|
+
|
|
496
481
|
// Execute/search for group
|
|
497
482
|
if (perm & 0o010) {
|
|
498
|
-
if (w & ModeSetgid
|
|
483
|
+
if (w & ModeSetgid) buf.push('s')
|
|
499
484
|
else buf.push('x')
|
|
500
485
|
} else {
|
|
501
|
-
if (w & ModeSetgid
|
|
486
|
+
if (w & ModeSetgid) buf.push('S')
|
|
502
487
|
else buf.push('-')
|
|
503
488
|
}
|
|
504
|
-
|
|
489
|
+
|
|
505
490
|
buf.push(perm & 0o004 ? 'r' : '-')
|
|
506
491
|
buf.push(perm & 0o002 ? 'w' : '-')
|
|
507
|
-
|
|
492
|
+
|
|
508
493
|
// Execute/search for other
|
|
509
494
|
if (perm & 0o001) {
|
|
510
|
-
if (w & ModeSticky
|
|
495
|
+
if (w & ModeSticky) buf.push('t')
|
|
511
496
|
else buf.push('x')
|
|
512
497
|
} else {
|
|
513
|
-
if (w & ModeSticky
|
|
498
|
+
if (w & ModeSticky) buf.push('T')
|
|
514
499
|
else buf.push('-')
|
|
515
500
|
}
|
|
516
501
|
|
|
@@ -518,7 +503,7 @@ export function fileModeString(mode: FileMode): string {
|
|
|
518
503
|
}
|
|
519
504
|
|
|
520
505
|
export function fileModeType(mode: FileMode): FileMode {
|
|
521
|
-
return
|
|
506
|
+
return (mode & ModeType) as FileMode
|
|
522
507
|
}
|
|
523
508
|
|
|
524
509
|
export class PathError {
|
package/gs/io/meta.json
ADDED
package/gs/os/index.ts
CHANGED
|
@@ -107,7 +107,11 @@ export {
|
|
|
107
107
|
DirEntry,
|
|
108
108
|
File,
|
|
109
109
|
FileInfo,
|
|
110
|
-
|
|
110
|
+
FileMode_IsDir,
|
|
111
|
+
FileMode_IsRegular,
|
|
112
|
+
FileMode_Perm,
|
|
113
|
+
FileMode_String,
|
|
114
|
+
FileMode_Type,
|
|
111
115
|
Getpagesize,
|
|
112
116
|
ModeAppend,
|
|
113
117
|
ModeCharDevice,
|
|
@@ -126,3 +130,6 @@ export {
|
|
|
126
130
|
ModeType,
|
|
127
131
|
SameFile,
|
|
128
132
|
} from './types_js.gs.js'
|
|
133
|
+
|
|
134
|
+
// Export FileMode as a type
|
|
135
|
+
export type { FileMode } from './types_js.gs.js'
|
package/gs/os/meta.json
ADDED
package/gs/os/types_js.gs.ts
CHANGED
|
@@ -9,7 +9,7 @@ import * as syscall from "@goscript/syscall/index.js"
|
|
|
9
9
|
// Re-export essential types
|
|
10
10
|
export type Time = time.Time;
|
|
11
11
|
export type FileInfo = fs.FileInfo;
|
|
12
|
-
export
|
|
12
|
+
export type FileMode = fs.FileMode;
|
|
13
13
|
export type DirEntry = fs.DirEntry;
|
|
14
14
|
|
|
15
15
|
// Export runtime values for ES module compatibility
|
|
@@ -202,4 +202,25 @@ export let ModePerm: fs.FileMode = fs.ModePerm
|
|
|
202
202
|
export function SameFile(fi1: fs.FileInfo, fi2: fs.FileInfo): boolean {
|
|
203
203
|
// In JavaScript environment, always return false as we can't compare files
|
|
204
204
|
return false
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// FileMode wrapper functions - re-export from fs module
|
|
208
|
+
export function FileMode_IsDir(receiver: fs.FileMode): boolean {
|
|
209
|
+
return fs.FileMode_IsDir(receiver)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function FileMode_IsRegular(receiver: fs.FileMode): boolean {
|
|
213
|
+
return fs.FileMode_IsRegular(receiver)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function FileMode_Perm(receiver: fs.FileMode): fs.FileMode {
|
|
217
|
+
return fs.FileMode_Perm(receiver)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function FileMode_String(receiver: fs.FileMode): string {
|
|
221
|
+
return fs.FileMode_String(receiver)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function FileMode_Type(receiver: fs.FileMode): fs.FileMode {
|
|
225
|
+
return fs.FileMode_Type(receiver)
|
|
205
226
|
}
|
package/gs/os/types_unix.gs.ts
CHANGED
|
@@ -54,7 +54,7 @@ class fileStat {
|
|
|
54
54
|
this._fields = {
|
|
55
55
|
name: $.varRef(init?.name ?? ""),
|
|
56
56
|
size: $.varRef(init?.size ?? 0),
|
|
57
|
-
mode: $.varRef(init?.mode ??
|
|
57
|
+
mode: $.varRef(init?.mode ?? 0),
|
|
58
58
|
modTime: $.varRef(init?.modTime?.clone() ?? time.Now()),
|
|
59
59
|
sys: $.varRef(init?.sys?.clone() ?? new syscall.Stat_t())
|
|
60
60
|
}
|
|
@@ -79,7 +79,7 @@ class fileStat {
|
|
|
79
79
|
|
|
80
80
|
public IsDir(): boolean {
|
|
81
81
|
const fileStat = this
|
|
82
|
-
return (fileStat!.Mode()
|
|
82
|
+
return (fileStat!.Mode() & fs.ModeDir) !== 0
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
public Size(): number {
|