goscript 0.0.30 → 0.0.32

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 (106) hide show
  1. package/compiler/expr-call.go +54 -0
  2. package/compiler/index.ts +1 -1
  3. package/compiler/stmt-assign.go +14 -0
  4. package/dist/compiler/index.js +1 -1
  5. package/dist/compiler/index.js.map +1 -1
  6. package/dist/gs/builtin/channel.d.ts +6 -6
  7. package/dist/gs/builtin/channel.js +3 -3
  8. package/dist/gs/builtin/channel.js.map +1 -1
  9. package/dist/gs/builtin/slice.js +3 -9
  10. package/dist/gs/builtin/slice.js.map +1 -1
  11. package/dist/gs/context/context.js +2 -2
  12. package/dist/gs/context/context.js.map +1 -1
  13. package/dist/gs/internal/oserror/errors.d.ts +1 -1
  14. package/dist/gs/internal/oserror/errors.js +6 -6
  15. package/dist/gs/internal/oserror/index.d.ts +1 -1
  16. package/dist/gs/internal/oserror/index.js +1 -1
  17. package/dist/gs/internal/oserror/index.js.map +1 -1
  18. package/dist/gs/io/fs/format.d.ts +1 -1
  19. package/dist/gs/io/fs/format.js +12 -12
  20. package/dist/gs/io/fs/format.js.map +1 -1
  21. package/dist/gs/io/fs/fs.d.ts +2 -2
  22. package/dist/gs/io/fs/fs.js +258 -36
  23. package/dist/gs/io/fs/fs.js.map +1 -1
  24. package/dist/gs/io/fs/glob.d.ts +2 -2
  25. package/dist/gs/io/fs/glob.js +40 -14
  26. package/dist/gs/io/fs/glob.js.map +1 -1
  27. package/dist/gs/io/fs/index.d.ts +8 -8
  28. package/dist/gs/io/fs/index.js +8 -8
  29. package/dist/gs/io/fs/readdir.d.ts +2 -2
  30. package/dist/gs/io/fs/readdir.js +78 -9
  31. package/dist/gs/io/fs/readdir.js.map +1 -1
  32. package/dist/gs/io/fs/readfile.d.ts +2 -2
  33. package/dist/gs/io/fs/readfile.js +31 -13
  34. package/dist/gs/io/fs/readfile.js.map +1 -1
  35. package/dist/gs/io/fs/stat.d.ts +2 -2
  36. package/dist/gs/io/fs/stat.js +25 -2
  37. package/dist/gs/io/fs/stat.js.map +1 -1
  38. package/dist/gs/io/fs/sub.d.ts +2 -2
  39. package/dist/gs/io/fs/sub.js +264 -28
  40. package/dist/gs/io/fs/sub.js.map +1 -1
  41. package/dist/gs/io/fs/walk.d.ts +2 -2
  42. package/dist/gs/io/fs/walk.js +7 -7
  43. package/dist/gs/io/fs/walk.js.map +1 -1
  44. package/dist/gs/iter/iter.js +1 -1
  45. package/dist/gs/iter/iter.js.map +1 -1
  46. package/dist/gs/path/index.d.ts +2 -2
  47. package/dist/gs/path/index.js +2 -2
  48. package/dist/gs/path/match.d.ts +1 -1
  49. package/dist/gs/path/match.js +39 -33
  50. package/dist/gs/path/match.js.map +1 -1
  51. package/dist/gs/path/path.js +53 -24
  52. package/dist/gs/path/path.js.map +1 -1
  53. package/dist/gs/runtime/runtime.d.ts +3 -3
  54. package/dist/gs/runtime/runtime.js +3 -3
  55. package/dist/gs/runtime/runtime.js.map +1 -1
  56. package/dist/gs/strings/builder.d.ts +1 -1
  57. package/dist/gs/strings/builder.js +1 -1
  58. package/dist/gs/strings/builder.js.map +1 -1
  59. package/dist/gs/strings/clone.js.map +1 -1
  60. package/dist/gs/strings/compare.js.map +1 -1
  61. package/dist/gs/strings/replace.js +4 -2
  62. package/dist/gs/strings/replace.js.map +1 -1
  63. package/dist/gs/strings/strings.js +0 -12
  64. package/dist/gs/strings/strings.js.map +1 -1
  65. package/dist/gs/sync/sync.d.ts +5 -5
  66. package/dist/gs/sync/sync.js +5 -5
  67. package/dist/gs/sync/sync.js.map +1 -1
  68. package/dist/gs/time/time.d.ts +2 -2
  69. package/dist/gs/time/time.js +62 -16
  70. package/dist/gs/time/time.js.map +1 -1
  71. package/dist/gs/unsafe/unsafe.d.ts +8 -8
  72. package/dist/gs/unsafe/unsafe.js +8 -8
  73. package/dist/gs/unsafe/unsafe.js.map +1 -1
  74. package/gs/builtin/builtin.ts +1 -1
  75. package/gs/builtin/channel.ts +6 -6
  76. package/gs/builtin/slice.ts +3 -9
  77. package/gs/context/context.ts +2 -2
  78. package/gs/internal/oserror/errors.ts +7 -8
  79. package/gs/internal/oserror/index.ts +7 -1
  80. package/gs/io/fs/format.ts +39 -40
  81. package/gs/io/fs/fs.ts +446 -222
  82. package/gs/io/fs/glob.ts +164 -131
  83. package/gs/io/fs/index.ts +8 -8
  84. package/gs/io/fs/readdir.ts +188 -106
  85. package/gs/io/fs/readfile.ts +79 -58
  86. package/gs/io/fs/stat.ts +49 -25
  87. package/gs/io/fs/sub.ts +422 -181
  88. package/gs/io/fs/walk.ts +67 -63
  89. package/gs/iter/iter.ts +1 -1
  90. package/gs/path/index.ts +2 -2
  91. package/gs/path/match.ts +263 -250
  92. package/gs/path/path.ts +259 -232
  93. package/gs/runtime/runtime.ts +4 -4
  94. package/gs/strings/builder.test.ts +0 -1
  95. package/gs/strings/builder.ts +1 -1
  96. package/gs/strings/clone.ts +0 -2
  97. package/gs/strings/compare.ts +0 -2
  98. package/gs/strings/iter.test.ts +0 -1
  99. package/gs/strings/replace.test.ts +3 -4
  100. package/gs/strings/replace.ts +4 -7
  101. package/gs/strings/strings.test.ts +6 -6
  102. package/gs/strings/strings.ts +0 -14
  103. package/gs/sync/sync.ts +5 -5
  104. package/gs/time/time.ts +86 -29
  105. package/gs/unsafe/unsafe.ts +8 -8
  106. package/package.json +1 -1
package/gs/io/fs/fs.ts CHANGED
@@ -1,41 +1,64 @@
1
- import * as $ from "@goscript/builtin/builtin.js";
1
+ import * as $ from '@goscript/builtin/builtin.js'
2
2
 
3
- import * as time from "@goscript/time/index.js"
3
+ import * as time from '@goscript/time/index.js'
4
4
 
5
- import * as utf8 from "@goscript/unicode/utf8/index.js"
5
+ import * as utf8 from '@goscript/unicode/utf8/index.js'
6
6
 
7
- import * as oserror from "@goscript/internal/oserror/index.js"
7
+ import * as oserror from '@goscript/internal/oserror/index.js'
8
8
 
9
9
  export type FS = null | {
10
- // Open opens the named file.
11
- // [File.Close] must be called to release any associated resources.
12
- //
13
- // When Open returns an error, it should be of type *PathError
14
- // with the Op field set to "open", the Path field set to name,
15
- // and the Err field describing the problem.
16
- //
17
- // Open should reject attempts to open names that do not satisfy
18
- // ValidPath(name), returning a *PathError with Err set to
19
- // ErrInvalid or ErrNotExist.
20
- //
21
- // Path names passed to open are UTF-8-encoded,
22
- // unrooted, slash-separated sequences of path elements, like "x/y/z".
23
- // Path names must not contain an element that is "." or ".." or the empty string,
24
- // except for the special case that the name "." may be used for the root directory.
25
- // Paths must not start or end with a slash: "/x" and "x/" are invalid.
26
- //
27
- // Note that paths are slash-separated on all systems, even Windows.
28
- // Paths containing other characters such as backslash and colon
29
- // are accepted as valid, but those characters must never be
30
- // interpreted by an [FS] implementation as path element separators.
31
- Open(name: string): [File, $.GoError]
10
+ // Open opens the named file.
11
+ // [File.Close] must be called to release any associated resources.
12
+ //
13
+ // When Open returns an error, it should be of type *PathError
14
+ // with the Op field set to "open", the Path field set to name,
15
+ // and the Err field describing the problem.
16
+ //
17
+ // Open should reject attempts to open names that do not satisfy
18
+ // ValidPath(name), returning a *PathError with Err set to
19
+ // ErrInvalid or ErrNotExist.
20
+ //
21
+ // Path names passed to open are UTF-8-encoded,
22
+ // unrooted, slash-separated sequences of path elements, like "x/y/z".
23
+ // Path names must not contain an element that is "." or ".." or the empty string,
24
+ // except for the special case that the name "." may be used for the root directory.
25
+ // Paths must not start or end with a slash: "/x" and "x/" are invalid.
26
+ //
27
+ // Note that paths are slash-separated on all systems, even Windows.
28
+ // Paths containing other characters such as backslash and colon
29
+ // are accepted as valid, but those characters must never be
30
+ // interpreted by an [FS] implementation as path element separators.
31
+ Open(name: string): [File, $.GoError]
32
32
  }
33
33
 
34
34
  $.registerInterfaceType(
35
35
  'FS',
36
36
  null, // Zero value for interface is null
37
- [{ name: "Open", args: [{ name: "name", type: { kind: $.TypeKind.Basic, name: "string" } }], returns: [{ type: "File" }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }]
38
- );
37
+ [
38
+ {
39
+ name: 'Open',
40
+ args: [
41
+ { name: 'name', type: { kind: $.TypeKind.Basic, name: 'string' } },
42
+ ],
43
+ returns: [
44
+ { type: 'File' },
45
+ {
46
+ type: {
47
+ kind: $.TypeKind.Interface,
48
+ name: 'GoError',
49
+ methods: [
50
+ {
51
+ name: 'Error',
52
+ args: [],
53
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
54
+ },
55
+ ],
56
+ },
57
+ },
58
+ ],
59
+ },
60
+ ],
61
+ )
39
62
 
40
63
  // ValidPath reports whether the given path name
41
64
  // is valid for use in a call to Open.
@@ -51,98 +74,221 @@ $.registerInterfaceType(
51
74
  // are accepted as valid, but those characters must never be
52
75
  // interpreted by an [FS] implementation as path element separators.
53
76
  export function ValidPath(name: string): boolean {
54
- if (!utf8.ValidString(name)) {
55
- return false
56
- }
57
-
58
- // special case
59
- if (name == ".") {
60
- // special case
61
- return true
62
- }
63
-
64
- // Iterate over elements in name, checking each.
65
-
66
- // reached clean ending
67
- for (; ; ) {
68
- let i = 0
69
- for (; i < $.len(name) && $.indexString(name, i) != 47; ) {
70
- i++
71
- }
72
- let elem = $.sliceString(name, undefined, i)
73
- if (elem == "" || elem == "." || elem == "..") {
74
- return false
75
- }
76
-
77
- // reached clean ending
78
- if (i == $.len(name)) {
79
- return true
80
- }
81
- name = $.sliceString(name, i + 1, undefined)
82
- }
77
+ if (!utf8.ValidString(name)) {
78
+ return false
79
+ }
80
+
81
+ // special case
82
+ if (name == '.') {
83
+ // special case
84
+ return true
85
+ }
86
+
87
+ // Iterate over elements in name, checking each.
88
+
89
+ // reached clean ending
90
+ for (;;) {
91
+ let i = 0
92
+ for (; i < $.len(name) && $.indexString(name, i) != 47; ) {
93
+ i++
94
+ }
95
+ let elem = $.sliceString(name, undefined, i)
96
+ if (elem == '' || elem == '.' || elem == '..') {
97
+ return false
98
+ }
99
+
100
+ // reached clean ending
101
+ if (i == $.len(name)) {
102
+ return true
103
+ }
104
+ name = $.sliceString(name, i + 1, undefined)
105
+ }
83
106
  }
84
107
 
85
108
  export type File = null | {
86
- Close(): $.GoError
87
- Read(_p0: Uint8Array): [number, $.GoError]
88
- Stat(): [FileInfo, $.GoError]
109
+ Close(): $.GoError
110
+ Read(_p0: Uint8Array): [number, $.GoError]
111
+ Stat(): [FileInfo, $.GoError]
89
112
  }
90
113
 
91
114
  $.registerInterfaceType(
92
115
  'File',
93
116
  null, // Zero value for interface is null
94
- [{ name: "Close", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Read", args: [{ name: "", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Stat", args: [], returns: [{ type: "FileInfo" }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }]
95
- );
117
+ [
118
+ {
119
+ name: 'Close',
120
+ args: [],
121
+ returns: [
122
+ {
123
+ type: {
124
+ kind: $.TypeKind.Interface,
125
+ name: 'GoError',
126
+ methods: [
127
+ {
128
+ name: 'Error',
129
+ args: [],
130
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
131
+ },
132
+ ],
133
+ },
134
+ },
135
+ ],
136
+ },
137
+ {
138
+ name: 'Read',
139
+ args: [
140
+ {
141
+ name: '',
142
+ type: {
143
+ kind: $.TypeKind.Slice,
144
+ elemType: { kind: $.TypeKind.Basic, name: 'number' },
145
+ },
146
+ },
147
+ ],
148
+ returns: [
149
+ { type: { kind: $.TypeKind.Basic, name: 'number' } },
150
+ {
151
+ type: {
152
+ kind: $.TypeKind.Interface,
153
+ name: 'GoError',
154
+ methods: [
155
+ {
156
+ name: 'Error',
157
+ args: [],
158
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
159
+ },
160
+ ],
161
+ },
162
+ },
163
+ ],
164
+ },
165
+ {
166
+ name: 'Stat',
167
+ args: [],
168
+ returns: [
169
+ { type: 'FileInfo' },
170
+ {
171
+ type: {
172
+ kind: $.TypeKind.Interface,
173
+ name: 'GoError',
174
+ methods: [
175
+ {
176
+ name: 'Error',
177
+ args: [],
178
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
179
+ },
180
+ ],
181
+ },
182
+ },
183
+ ],
184
+ },
185
+ ],
186
+ )
96
187
 
97
188
  export type DirEntry = null | {
98
- // Info returns the FileInfo for the file or subdirectory described by the entry.
99
- // The returned FileInfo may be from the time of the original directory read
100
- // or from the time of the call to Info. If the file has been removed or renamed
101
- // since the directory read, Info may return an error satisfying errors.Is(err, ErrNotExist).
102
- // If the entry denotes a symbolic link, Info reports the information about the link itself,
103
- // not the link's target.
104
- Info(): [FileInfo, $.GoError]
105
- // IsDir reports whether the entry describes a directory.
106
- IsDir(): boolean
107
- // Name returns the name of the file (or subdirectory) described by the entry.
108
- // This name is only the final element of the path (the base name), not the entire path.
109
- // For example, Name would return "hello.go" not "home/gopher/hello.go".
110
- Name(): string
111
- // Type returns the type bits for the entry.
112
- // The type bits are a subset of the usual FileMode bits, those returned by the FileMode.Type method.
113
- Type(): FileMode
189
+ // Info returns the FileInfo for the file or subdirectory described by the entry.
190
+ // The returned FileInfo may be from the time of the original directory read
191
+ // or from the time of the call to Info. If the file has been removed or renamed
192
+ // since the directory read, Info may return an error satisfying errors.Is(err, ErrNotExist).
193
+ // If the entry denotes a symbolic link, Info reports the information about the link itself,
194
+ // not the link's target.
195
+ Info(): [FileInfo, $.GoError]
196
+ // IsDir reports whether the entry describes a directory.
197
+ IsDir(): boolean
198
+ // Name returns the name of the file (or subdirectory) described by the entry.
199
+ // This name is only the final element of the path (the base name), not the entire path.
200
+ // For example, Name would return "hello.go" not "home/gopher/hello.go".
201
+ Name(): string
202
+ // Type returns the type bits for the entry.
203
+ // The type bits are a subset of the usual FileMode bits, those returned by the FileMode.Type method.
204
+ Type(): FileMode
114
205
  }
115
206
 
116
207
  $.registerInterfaceType(
117
208
  'DirEntry',
118
209
  null, // Zero value for interface is null
119
- [{ name: "Info", args: [], returns: [{ type: "FileInfo" }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "IsDir", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "Name", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "Type", args: [], returns: [{ type: "FileMode" }] }]
120
- );
121
-
122
- export type ReadDirFile = null | {
123
- // ReadDir reads the contents of the directory and returns
124
- // a slice of up to n DirEntry values in directory order.
125
- // Subsequent calls on the same file will yield further DirEntry values.
126
- //
127
- // If n > 0, ReadDir returns at most n DirEntry structures.
128
- // In this case, if ReadDir returns an empty slice, it will return
129
- // a non-nil error explaining why.
130
- // At the end of a directory, the error is io.EOF.
131
- // (ReadDir must return io.EOF itself, not an error wrapping io.EOF.)
132
- //
133
- // If n <= 0, ReadDir returns all the DirEntry values from the directory
134
- // in a single slice. In this case, if ReadDir succeeds (reads all the way
135
- // to the end of the directory), it returns the slice and a nil error.
136
- // If it encounters an error before the end of the directory,
137
- // ReadDir returns the DirEntry list read until that point and a non-nil error.
138
- ReadDir(n: number): [$.Slice<DirEntry>, $.GoError]
139
- } & File
210
+ [
211
+ {
212
+ name: 'Info',
213
+ args: [],
214
+ returns: [
215
+ { type: 'FileInfo' },
216
+ {
217
+ type: {
218
+ kind: $.TypeKind.Interface,
219
+ name: 'GoError',
220
+ methods: [
221
+ {
222
+ name: 'Error',
223
+ args: [],
224
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
225
+ },
226
+ ],
227
+ },
228
+ },
229
+ ],
230
+ },
231
+ {
232
+ name: 'IsDir',
233
+ args: [],
234
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'boolean' } }],
235
+ },
236
+ {
237
+ name: 'Name',
238
+ args: [],
239
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
240
+ },
241
+ { name: 'Type', args: [], returns: [{ type: 'FileMode' }] },
242
+ ],
243
+ )
244
+
245
+ export type ReadDirFile =
246
+ | null
247
+ | ({
248
+ // ReadDir reads the contents of the directory and returns
249
+ // a slice of up to n DirEntry values in directory order.
250
+ // Subsequent calls on the same file will yield further DirEntry values.
251
+ //
252
+ // If n > 0, ReadDir returns at most n DirEntry structures.
253
+ // In this case, if ReadDir returns an empty slice, it will return
254
+ // a non-nil error explaining why.
255
+ // At the end of a directory, the error is io.EOF.
256
+ // (ReadDir must return io.EOF itself, not an error wrapping io.EOF.)
257
+ //
258
+ // If n <= 0, ReadDir returns all the DirEntry values from the directory
259
+ // in a single slice. In this case, if ReadDir succeeds (reads all the way
260
+ // to the end of the directory), it returns the slice and a nil error.
261
+ // If it encounters an error before the end of the directory,
262
+ // ReadDir returns the DirEntry list read until that point and a non-nil error.
263
+ ReadDir(n: number): [$.Slice<DirEntry>, $.GoError]
264
+ } & File)
140
265
 
141
266
  $.registerInterfaceType(
142
267
  'ReadDirFile',
143
268
  null, // Zero value for interface is null
144
- [{ name: "ReadDir", args: [{ name: "n", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Slice, elemType: "DirEntry" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }]
145
- );
269
+ [
270
+ {
271
+ name: 'ReadDir',
272
+ args: [{ name: 'n', type: { kind: $.TypeKind.Basic, name: 'number' } }],
273
+ returns: [
274
+ { type: { kind: $.TypeKind.Slice, elemType: 'DirEntry' } },
275
+ {
276
+ type: {
277
+ kind: $.TypeKind.Interface,
278
+ name: 'GoError',
279
+ methods: [
280
+ {
281
+ name: 'Error',
282
+ args: [],
283
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
284
+ },
285
+ ],
286
+ },
287
+ },
288
+ ],
289
+ },
290
+ ],
291
+ )
146
292
 
147
293
  // "invalid argument"
148
294
  export let ErrInvalid: $.GoError = errInvalid()
@@ -160,47 +306,70 @@ export let ErrNotExist: $.GoError = errNotExist()
160
306
  export let ErrClosed: $.GoError = errClosed()
161
307
 
162
308
  export function errInvalid(): $.GoError {
163
- return oserror.ErrInvalid
309
+ return oserror.ErrInvalid
164
310
  }
165
311
 
166
312
  export function errPermission(): $.GoError {
167
- return oserror.ErrPermission
313
+ return oserror.ErrPermission
168
314
  }
169
315
 
170
316
  export function errExist(): $.GoError {
171
- return oserror.ErrExist
317
+ return oserror.ErrExist
172
318
  }
173
319
 
174
320
  export function errNotExist(): $.GoError {
175
- return oserror.ErrNotExist
321
+ return oserror.ErrNotExist
176
322
  }
177
323
 
178
324
  export function errClosed(): $.GoError {
179
- return oserror.ErrClosed
325
+ return oserror.ErrClosed
180
326
  }
181
327
 
182
328
  export type FileInfo = null | {
183
- // abbreviation for Mode().IsDir()
184
- IsDir(): boolean
185
- // modification time
186
- ModTime(): time.Time
187
- // file mode bits
188
- Mode(): FileMode
189
- // base name of the file
190
- Name(): string
191
- // length in bytes for regular files; system-dependent for others
192
- Size(): number
193
- // underlying data source (can return nil)
194
- Sys(): null | any
329
+ // abbreviation for Mode().IsDir()
330
+ IsDir(): boolean
331
+ // modification time
332
+ ModTime(): time.Time
333
+ // file mode bits
334
+ Mode(): FileMode
335
+ // base name of the file
336
+ Name(): string
337
+ // length in bytes for regular files; system-dependent for others
338
+ Size(): number
339
+ // underlying data source (can return nil)
340
+ Sys(): null | any
195
341
  }
196
342
 
197
343
  $.registerInterfaceType(
198
344
  'FileInfo',
199
345
  null, // Zero value for interface is null
200
- [{ name: "IsDir", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "ModTime", args: [], returns: [{ type: "Time" }] }, { name: "Mode", args: [], returns: [{ type: "FileMode" }] }, { name: "Name", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "Size", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Sys", args: [], returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }] }]
201
- );
202
-
203
- export type FileMode = number;
346
+ [
347
+ {
348
+ name: 'IsDir',
349
+ args: [],
350
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'boolean' } }],
351
+ },
352
+ { name: 'ModTime', args: [], returns: [{ type: 'Time' }] },
353
+ { name: 'Mode', args: [], returns: [{ type: 'FileMode' }] },
354
+ {
355
+ name: 'Name',
356
+ args: [],
357
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
358
+ },
359
+ {
360
+ name: 'Size',
361
+ args: [],
362
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'number' } }],
363
+ },
364
+ {
365
+ name: 'Sys',
366
+ args: [],
367
+ returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }],
368
+ },
369
+ ],
370
+ )
371
+
372
+ export type FileMode = number
204
373
 
205
374
  // The single letters are the abbreviations
206
375
  // used by the String method's formatting.
@@ -244,116 +413,171 @@ export let ModeSticky: FileMode = 0
244
413
  export let ModeIrregular: FileMode = 0
245
414
 
246
415
  // Mask for the type bits. For regular files, none will be set.
247
- export let ModeType: FileMode = ((((((2147483648 | 134217728) | 33554432) | 16777216) | 67108864) | 2097152) | 524288)
416
+ export let ModeType: FileMode =
417
+ 2147483648 | 134217728 | 33554432 | 16777216 | 67108864 | 2097152 | 524288
248
418
 
249
419
  // Unix permission bits
250
420
  export let ModePerm: FileMode = 0o777
251
421
 
252
422
  // FileMode methods
253
423
  export function fileModeString(mode: FileMode): string {
254
- const buf: string[] = []
255
-
256
- // File type
257
- if (mode & ModeDir) buf.push("d")
258
- else if (mode & ModeSymlink) buf.push("L")
259
- else if (mode & ModeDevice) buf.push("D")
260
- else if (mode & ModeNamedPipe) buf.push("p")
261
- else if (mode & ModeSocket) buf.push("S")
262
- else if (mode & ModeCharDevice) buf.push("c")
263
- else if (mode & ModeIrregular) buf.push("?")
264
- else buf.push("-")
265
-
266
- // Permission bits
267
- const perm = mode & ModePerm
268
- buf.push((perm & 0o400) ? "r" : "-")
269
- buf.push((perm & 0o200) ? "w" : "-")
270
- buf.push((perm & 0o100) ? "x" : "-")
271
- buf.push((perm & 0o040) ? "r" : "-")
272
- buf.push((perm & 0o020) ? "w" : "-")
273
- buf.push((perm & 0o010) ? "x" : "-")
274
- buf.push((perm & 0o004) ? "r" : "-")
275
- buf.push((perm & 0o002) ? "w" : "-")
276
- buf.push((perm & 0o001) ? "x" : "-")
277
-
278
- return buf.join("")
424
+ const buf: string[] = []
425
+
426
+ // File type
427
+ if (mode & ModeDir) buf.push('d')
428
+ else if (mode & ModeSymlink) buf.push('L')
429
+ else if (mode & ModeDevice) buf.push('D')
430
+ else if (mode & ModeNamedPipe) buf.push('p')
431
+ else if (mode & ModeSocket) buf.push('S')
432
+ else if (mode & ModeCharDevice) buf.push('c')
433
+ else if (mode & ModeIrregular) buf.push('?')
434
+ else buf.push('-')
435
+
436
+ // Permission bits
437
+ const perm = mode & ModePerm
438
+ buf.push(perm & 0o400 ? 'r' : '-')
439
+ buf.push(perm & 0o200 ? 'w' : '-')
440
+ buf.push(perm & 0o100 ? 'x' : '-')
441
+ buf.push(perm & 0o040 ? 'r' : '-')
442
+ buf.push(perm & 0o020 ? 'w' : '-')
443
+ buf.push(perm & 0o010 ? 'x' : '-')
444
+ buf.push(perm & 0o004 ? 'r' : '-')
445
+ buf.push(perm & 0o002 ? 'w' : '-')
446
+ buf.push(perm & 0o001 ? 'x' : '-')
447
+
448
+ return buf.join('')
279
449
  }
280
450
 
281
451
  export function fileModeType(mode: FileMode): FileMode {
282
- return mode & ModeType
452
+ return mode & ModeType
283
453
  }
284
454
 
285
455
  export class PathError {
286
- public get Op(): string {
287
- return this._fields.Op.value
288
- }
289
- public set Op(value: string) {
290
- this._fields.Op.value = value
291
- }
292
-
293
- public get Path(): string {
294
- return this._fields.Path.value
295
- }
296
- public set Path(value: string) {
297
- this._fields.Path.value = value
298
- }
299
-
300
- public get Err(): $.GoError {
301
- return this._fields.Err.value
302
- }
303
- public set Err(value: $.GoError) {
304
- this._fields.Err.value = value
305
- }
306
-
307
- public _fields: {
308
- Op: $.VarRef<string>;
309
- Path: $.VarRef<string>;
310
- Err: $.VarRef<$.GoError>;
311
- }
312
-
313
- constructor(init?: Partial<{Err?: $.GoError, Op?: string, Path?: string}>) {
314
- this._fields = {
315
- Op: $.varRef(init?.Op ?? ""),
316
- Path: $.varRef(init?.Path ?? ""),
317
- Err: $.varRef(init?.Err ?? null)
318
- }
319
- }
320
-
321
- public clone(): PathError {
322
- const cloned = new PathError()
323
- cloned._fields = {
324
- Op: $.varRef(this._fields.Op.value),
325
- Path: $.varRef(this._fields.Path.value),
326
- Err: $.varRef(this._fields.Err.value)
327
- }
328
- return cloned
329
- }
330
-
331
- public Error(): string {
332
- const e = this
333
- return e!.Op + " " + e!.Path + ": " + e!.Err!.Error()
334
- }
335
-
336
- public Unwrap(): $.GoError {
337
- const e = this
338
- return e!.Err
339
- }
340
-
341
- // Timeout reports whether this error represents a timeout.
342
- public Timeout(): boolean {
343
- const e = this
344
- let { value: t, ok: ok } = $.typeAssert<null | {
345
- Timeout(): boolean
346
- }>(e!.Err, {kind: $.TypeKind.Interface, methods: [{ name: 'Timeout', args: [], returns: [{ type: {kind: $.TypeKind.Basic, name: 'boolean'} }] }]})
347
- return ok && t!.Timeout()
348
- }
349
-
350
- // Register this type with the runtime type system
351
- static __typeInfo = $.registerStructType(
352
- 'PathError',
353
- new PathError(),
354
- [{ name: "Error", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "Unwrap", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Timeout", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }],
355
- PathError,
356
- {"Op": { kind: $.TypeKind.Basic, name: "string" }, "Path": { kind: $.TypeKind.Basic, name: "string" }, "Err": { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] }}
357
- );
456
+ public get Op(): string {
457
+ return this._fields.Op.value
458
+ }
459
+ public set Op(value: string) {
460
+ this._fields.Op.value = value
461
+ }
462
+
463
+ public get Path(): string {
464
+ return this._fields.Path.value
465
+ }
466
+ public set Path(value: string) {
467
+ this._fields.Path.value = value
468
+ }
469
+
470
+ public get Err(): $.GoError {
471
+ return this._fields.Err.value
472
+ }
473
+ public set Err(value: $.GoError) {
474
+ this._fields.Err.value = value
475
+ }
476
+
477
+ public _fields: {
478
+ Op: $.VarRef<string>
479
+ Path: $.VarRef<string>
480
+ Err: $.VarRef<$.GoError>
481
+ }
482
+
483
+ constructor(init?: Partial<{ Err?: $.GoError; Op?: string; Path?: string }>) {
484
+ this._fields = {
485
+ Op: $.varRef(init?.Op ?? ''),
486
+ Path: $.varRef(init?.Path ?? ''),
487
+ Err: $.varRef(init?.Err ?? null),
488
+ }
489
+ }
490
+
491
+ public clone(): PathError {
492
+ const cloned = new PathError()
493
+ cloned._fields = {
494
+ Op: $.varRef(this._fields.Op.value),
495
+ Path: $.varRef(this._fields.Path.value),
496
+ Err: $.varRef(this._fields.Err.value),
497
+ }
498
+ return cloned
499
+ }
500
+
501
+ public Error(): string {
502
+ const e = this
503
+ return e!.Op + ' ' + e!.Path + ': ' + e!.Err!.Error()
504
+ }
505
+
506
+ public Unwrap(): $.GoError {
507
+ const e = this
508
+ return e!.Err
509
+ }
510
+
511
+ // Timeout reports whether this error represents a timeout.
512
+ public Timeout(): boolean {
513
+ const e = this
514
+ let { value: t, ok: ok } = $.typeAssert<null | {
515
+ Timeout(): boolean
516
+ }>(e!.Err, {
517
+ kind: $.TypeKind.Interface,
518
+ methods: [
519
+ {
520
+ name: 'Timeout',
521
+ args: [],
522
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'boolean' } }],
523
+ },
524
+ ],
525
+ })
526
+ return ok && t!.Timeout()
527
+ }
528
+
529
+ // Register this type with the runtime type system
530
+ static __typeInfo = $.registerStructType(
531
+ 'PathError',
532
+ new PathError(),
533
+ [
534
+ {
535
+ name: 'Error',
536
+ args: [],
537
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
538
+ },
539
+ {
540
+ name: 'Unwrap',
541
+ args: [],
542
+ returns: [
543
+ {
544
+ type: {
545
+ kind: $.TypeKind.Interface,
546
+ name: 'GoError',
547
+ methods: [
548
+ {
549
+ name: 'Error',
550
+ args: [],
551
+ returns: [
552
+ { type: { kind: $.TypeKind.Basic, name: 'string' } },
553
+ ],
554
+ },
555
+ ],
556
+ },
557
+ },
558
+ ],
559
+ },
560
+ {
561
+ name: 'Timeout',
562
+ args: [],
563
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'boolean' } }],
564
+ },
565
+ ],
566
+ PathError,
567
+ {
568
+ Op: { kind: $.TypeKind.Basic, name: 'string' },
569
+ Path: { kind: $.TypeKind.Basic, name: 'string' },
570
+ Err: {
571
+ kind: $.TypeKind.Interface,
572
+ name: 'GoError',
573
+ methods: [
574
+ {
575
+ name: 'Error',
576
+ args: [],
577
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
578
+ },
579
+ ],
580
+ },
581
+ },
582
+ )
358
583
  }
359
-