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.
- package/compiler/expr-call.go +54 -0
- package/compiler/index.ts +1 -1
- package/compiler/stmt-assign.go +14 -0
- package/dist/compiler/index.js +1 -1
- package/dist/compiler/index.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +6 -6
- package/dist/gs/builtin/channel.js +3 -3
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/slice.js +3 -9
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/context/context.js +2 -2
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/internal/oserror/errors.d.ts +1 -1
- package/dist/gs/internal/oserror/errors.js +6 -6
- package/dist/gs/internal/oserror/index.d.ts +1 -1
- package/dist/gs/internal/oserror/index.js +1 -1
- package/dist/gs/internal/oserror/index.js.map +1 -1
- package/dist/gs/io/fs/format.d.ts +1 -1
- package/dist/gs/io/fs/format.js +12 -12
- package/dist/gs/io/fs/format.js.map +1 -1
- package/dist/gs/io/fs/fs.d.ts +2 -2
- package/dist/gs/io/fs/fs.js +258 -36
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/io/fs/glob.d.ts +2 -2
- package/dist/gs/io/fs/glob.js +40 -14
- package/dist/gs/io/fs/glob.js.map +1 -1
- package/dist/gs/io/fs/index.d.ts +8 -8
- package/dist/gs/io/fs/index.js +8 -8
- package/dist/gs/io/fs/readdir.d.ts +2 -2
- package/dist/gs/io/fs/readdir.js +78 -9
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/fs/readfile.d.ts +2 -2
- package/dist/gs/io/fs/readfile.js +31 -13
- package/dist/gs/io/fs/readfile.js.map +1 -1
- package/dist/gs/io/fs/stat.d.ts +2 -2
- package/dist/gs/io/fs/stat.js +25 -2
- package/dist/gs/io/fs/stat.js.map +1 -1
- package/dist/gs/io/fs/sub.d.ts +2 -2
- package/dist/gs/io/fs/sub.js +264 -28
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.d.ts +2 -2
- package/dist/gs/io/fs/walk.js +7 -7
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/iter/iter.js +1 -1
- package/dist/gs/iter/iter.js.map +1 -1
- package/dist/gs/path/index.d.ts +2 -2
- package/dist/gs/path/index.js +2 -2
- package/dist/gs/path/match.d.ts +1 -1
- package/dist/gs/path/match.js +39 -33
- package/dist/gs/path/match.js.map +1 -1
- package/dist/gs/path/path.js +53 -24
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/runtime/runtime.d.ts +3 -3
- package/dist/gs/runtime/runtime.js +3 -3
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +1 -1
- package/dist/gs/strings/builder.js +1 -1
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/strings/clone.js.map +1 -1
- package/dist/gs/strings/compare.js.map +1 -1
- package/dist/gs/strings/replace.js +4 -2
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/strings.js +0 -12
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +5 -5
- package/dist/gs/sync/sync.js +5 -5
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/time/time.d.ts +2 -2
- package/dist/gs/time/time.js +62 -16
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unsafe/unsafe.d.ts +8 -8
- package/dist/gs/unsafe/unsafe.js +8 -8
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/gs/builtin/builtin.ts +1 -1
- package/gs/builtin/channel.ts +6 -6
- package/gs/builtin/slice.ts +3 -9
- package/gs/context/context.ts +2 -2
- package/gs/internal/oserror/errors.ts +7 -8
- package/gs/internal/oserror/index.ts +7 -1
- package/gs/io/fs/format.ts +39 -40
- package/gs/io/fs/fs.ts +446 -222
- package/gs/io/fs/glob.ts +164 -131
- package/gs/io/fs/index.ts +8 -8
- package/gs/io/fs/readdir.ts +188 -106
- package/gs/io/fs/readfile.ts +79 -58
- package/gs/io/fs/stat.ts +49 -25
- package/gs/io/fs/sub.ts +422 -181
- package/gs/io/fs/walk.ts +67 -63
- package/gs/iter/iter.ts +1 -1
- package/gs/path/index.ts +2 -2
- package/gs/path/match.ts +263 -250
- package/gs/path/path.ts +259 -232
- package/gs/runtime/runtime.ts +4 -4
- package/gs/strings/builder.test.ts +0 -1
- package/gs/strings/builder.ts +1 -1
- package/gs/strings/clone.ts +0 -2
- package/gs/strings/compare.ts +0 -2
- package/gs/strings/iter.test.ts +0 -1
- package/gs/strings/replace.test.ts +3 -4
- package/gs/strings/replace.ts +4 -7
- package/gs/strings/strings.test.ts +6 -6
- package/gs/strings/strings.ts +0 -14
- package/gs/sync/sync.ts +5 -5
- package/gs/time/time.ts +86 -29
- package/gs/unsafe/unsafe.ts +8 -8
- package/package.json +1 -1
package/gs/path/path.ts
CHANGED
|
@@ -1,89 +1,112 @@
|
|
|
1
|
-
import * as $ from
|
|
1
|
+
import * as $ from '@goscript/builtin/builtin.js'
|
|
2
2
|
|
|
3
3
|
class lazybuf {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
4
|
+
public get s(): string {
|
|
5
|
+
return this._fields.s.value
|
|
6
|
+
}
|
|
7
|
+
public set s(value: string) {
|
|
8
|
+
this._fields.s.value = value
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public get buf(): Uint8Array | null {
|
|
12
|
+
return this._fields.buf.value
|
|
13
|
+
}
|
|
14
|
+
public set buf(value: Uint8Array | null) {
|
|
15
|
+
this._fields.buf.value = value
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public get w(): number {
|
|
19
|
+
return this._fields.w.value
|
|
20
|
+
}
|
|
21
|
+
public set w(value: number) {
|
|
22
|
+
this._fields.w.value = value
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public _fields: {
|
|
26
|
+
s: $.VarRef<string>
|
|
27
|
+
buf: $.VarRef<Uint8Array | null>
|
|
28
|
+
w: $.VarRef<number>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
constructor(init?: Partial<{ buf?: Uint8Array; s?: string; w?: number }>) {
|
|
32
|
+
this._fields = {
|
|
33
|
+
s: $.varRef(init?.s ?? ''),
|
|
34
|
+
buf: $.varRef(init?.buf ?? null),
|
|
35
|
+
w: $.varRef(init?.w ?? 0),
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public clone(): lazybuf {
|
|
40
|
+
const cloned = new lazybuf()
|
|
41
|
+
cloned._fields = {
|
|
42
|
+
s: $.varRef(this._fields.s.value),
|
|
43
|
+
buf: $.varRef(this._fields.buf.value),
|
|
44
|
+
w: $.varRef(this._fields.w.value),
|
|
45
|
+
}
|
|
46
|
+
return cloned
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public index(i: number): number {
|
|
50
|
+
const b = this
|
|
51
|
+
if (b!.buf != null) {
|
|
52
|
+
return b!.buf![i]
|
|
53
|
+
}
|
|
54
|
+
return $.indexString(b!.s, i)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public append(c: number): void {
|
|
58
|
+
const b = this
|
|
59
|
+
if (b!.buf == null) {
|
|
60
|
+
if (b!.w < $.len(b!.s) && $.indexString(b!.s, b!.w) == c) {
|
|
61
|
+
b!.w++
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
b!.buf = new Uint8Array($.len(b!.s))
|
|
65
|
+
$.copy(b!.buf, $.stringToBytes($.sliceString(b!.s, undefined, b!.w)))
|
|
66
|
+
}
|
|
67
|
+
b!.buf![b!.w] = c
|
|
68
|
+
b!.w++
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public _string(): string {
|
|
72
|
+
const b = this
|
|
73
|
+
if (b!.buf == null) {
|
|
74
|
+
return $.sliceString(b!.s, undefined, b!.w)
|
|
75
|
+
}
|
|
76
|
+
return $.bytesToString(b!.buf.subarray(0, b!.w))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Register this type with the runtime type system
|
|
80
|
+
static __typeInfo = $.registerStructType(
|
|
81
|
+
'lazybuf',
|
|
82
|
+
new lazybuf(),
|
|
83
|
+
[
|
|
84
|
+
{
|
|
85
|
+
name: 'index',
|
|
86
|
+
args: [{ name: 'i', type: { kind: $.TypeKind.Basic, name: 'number' } }],
|
|
87
|
+
returns: [{ type: { kind: $.TypeKind.Basic, name: 'number' } }],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'append',
|
|
91
|
+
args: [{ name: 'c', type: { kind: $.TypeKind.Basic, name: 'number' } }],
|
|
92
|
+
returns: [],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'string',
|
|
96
|
+
args: [],
|
|
97
|
+
returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
lazybuf,
|
|
101
|
+
{
|
|
102
|
+
s: { kind: $.TypeKind.Basic, name: 'string' },
|
|
103
|
+
buf: {
|
|
104
|
+
kind: $.TypeKind.Slice,
|
|
105
|
+
elemType: { kind: $.TypeKind.Basic, name: 'number' },
|
|
106
|
+
},
|
|
107
|
+
w: { kind: $.TypeKind.Basic, name: 'number' },
|
|
108
|
+
},
|
|
109
|
+
)
|
|
87
110
|
}
|
|
88
111
|
|
|
89
112
|
// Clean returns the shortest path name equivalent to path
|
|
@@ -106,100 +129,102 @@ class lazybuf {
|
|
|
106
129
|
// Getting Dot-Dot Right,"
|
|
107
130
|
// https://9p.io/sys/doc/lexnames.html
|
|
108
131
|
export function Clean(path: string): string {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
132
|
+
if (path == '') {
|
|
133
|
+
return '.'
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let rooted = $.indexString(path, 0) == 47
|
|
137
|
+
let n = $.len(path)
|
|
138
|
+
|
|
139
|
+
// Invariants:
|
|
140
|
+
// reading from path; r is index of next byte to process.
|
|
141
|
+
// writing to buf; w is index of next byte to write.
|
|
142
|
+
// dotdot is index in buf where .. must stop, either because
|
|
143
|
+
// it is the leading slash or it is a leading ../../.. prefix.
|
|
144
|
+
let out = new lazybuf({ s: path })
|
|
145
|
+
let r = 0
|
|
146
|
+
let dotdot = 0
|
|
147
|
+
if (rooted) {
|
|
148
|
+
out.append(47)
|
|
149
|
+
r = 1
|
|
150
|
+
dotdot = 1
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// empty path element
|
|
154
|
+
|
|
155
|
+
// . element
|
|
156
|
+
|
|
157
|
+
// .. element: remove to last /
|
|
158
|
+
|
|
159
|
+
// can backtrack
|
|
160
|
+
|
|
161
|
+
// cannot backtrack, but not rooted, so append .. element.
|
|
162
|
+
|
|
163
|
+
// real path element.
|
|
164
|
+
// add slash if needed
|
|
165
|
+
|
|
166
|
+
// copy element
|
|
167
|
+
for (; r < n; ) {
|
|
168
|
+
// empty path element
|
|
169
|
+
|
|
170
|
+
// . element
|
|
171
|
+
|
|
172
|
+
// .. element: remove to last /
|
|
173
|
+
|
|
174
|
+
// can backtrack
|
|
175
|
+
|
|
176
|
+
// cannot backtrack, but not rooted, so append .. element.
|
|
177
|
+
|
|
178
|
+
// real path element.
|
|
179
|
+
// add slash if needed
|
|
180
|
+
|
|
181
|
+
// copy element
|
|
182
|
+
switch (true) {
|
|
183
|
+
case $.indexString(path, r) == 47:
|
|
184
|
+
r++
|
|
185
|
+
break
|
|
186
|
+
case $.indexString(path, r) == 46 &&
|
|
187
|
+
(r + 1 == n || $.indexString(path, r + 1) == 47):
|
|
188
|
+
r++
|
|
189
|
+
break
|
|
190
|
+
case $.indexString(path, r) == 46 &&
|
|
191
|
+
$.indexString(path, r + 1) == 46 &&
|
|
192
|
+
(r + 2 == n || $.indexString(path, r + 2) == 47):
|
|
193
|
+
r += 2
|
|
194
|
+
switch (true) {
|
|
195
|
+
case out.w > dotdot:
|
|
196
|
+
out.w--
|
|
197
|
+
for (; out.w > dotdot && out.index(out.w) != 47; ) {
|
|
198
|
+
out.w--
|
|
199
|
+
}
|
|
200
|
+
break
|
|
201
|
+
case !rooted:
|
|
202
|
+
if (out.w > 0) {
|
|
203
|
+
out.append(47)
|
|
204
|
+
}
|
|
205
|
+
out.append(46)
|
|
206
|
+
out.append(46)
|
|
207
|
+
dotdot = out.w
|
|
208
|
+
break
|
|
209
|
+
}
|
|
210
|
+
break
|
|
211
|
+
default:
|
|
212
|
+
if ((rooted && out.w != 1) || (!rooted && out.w != 0)) {
|
|
213
|
+
out.append(47)
|
|
214
|
+
}
|
|
215
|
+
for (; r < n && $.indexString(path, r) != 47; r++) {
|
|
216
|
+
out.append($.indexString(path, r))
|
|
217
|
+
}
|
|
218
|
+
break
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Turn empty string into "."
|
|
223
|
+
if (out.w == 0) {
|
|
224
|
+
return '.'
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return out._string()
|
|
203
228
|
}
|
|
204
229
|
|
|
205
230
|
// Split splits path immediately following the final slash,
|
|
@@ -208,8 +233,11 @@ export function Clean(path: string): string {
|
|
|
208
233
|
// file set to path.
|
|
209
234
|
// The returned values have the property that path = dir+file.
|
|
210
235
|
export function Split(path: string): [string, string] {
|
|
211
|
-
|
|
212
|
-
|
|
236
|
+
let i = path.lastIndexOf('/')
|
|
237
|
+
return [
|
|
238
|
+
$.sliceString(path, undefined, i + 1),
|
|
239
|
+
$.sliceString(path, i + 1, undefined),
|
|
240
|
+
]
|
|
213
241
|
}
|
|
214
242
|
|
|
215
243
|
// Join joins any number of path elements into a single path,
|
|
@@ -218,29 +246,29 @@ export function Split(path: string): [string, string] {
|
|
|
218
246
|
// empty or all its elements are empty, Join returns
|
|
219
247
|
// an empty string.
|
|
220
248
|
export function Join(...elem: string[]): string {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
249
|
+
let size = 0
|
|
250
|
+
for (let _i = 0; _i < $.len(elem); _i++) {
|
|
251
|
+
const e = elem![_i]
|
|
252
|
+
{
|
|
253
|
+
size += $.len(e)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (size == 0) {
|
|
257
|
+
return ''
|
|
258
|
+
}
|
|
259
|
+
let buf: string[] = []
|
|
260
|
+
for (let _i = 0; _i < $.len(elem); _i++) {
|
|
261
|
+
const e = elem![_i]
|
|
262
|
+
{
|
|
263
|
+
if ($.len(buf) > 0 || e != '') {
|
|
264
|
+
if ($.len(buf) > 0) {
|
|
265
|
+
buf.push('/')
|
|
266
|
+
}
|
|
267
|
+
buf.push(e)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return Clean(buf.join(''))
|
|
244
272
|
}
|
|
245
273
|
|
|
246
274
|
// Ext returns the file name extension used by path.
|
|
@@ -248,12 +276,12 @@ export function Join(...elem: string[]): string {
|
|
|
248
276
|
// in the final slash-separated element of path;
|
|
249
277
|
// it is empty if there is no dot.
|
|
250
278
|
export function Ext(path: string): string {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
279
|
+
for (let i = $.len(path) - 1; i >= 0 && $.indexString(path, i) != 47; i--) {
|
|
280
|
+
if ($.indexString(path, i) == 46) {
|
|
281
|
+
return $.sliceString(path, i, undefined)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return ''
|
|
257
285
|
}
|
|
258
286
|
|
|
259
287
|
// Base returns the last element of path.
|
|
@@ -261,30 +289,30 @@ export function Ext(path: string): string {
|
|
|
261
289
|
// If the path is empty, Base returns ".".
|
|
262
290
|
// If the path consists entirely of slashes, Base returns "/".
|
|
263
291
|
export function Base(path: string): string {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
292
|
+
if (path == '') {
|
|
293
|
+
return '.'
|
|
294
|
+
}
|
|
295
|
+
// Strip trailing slashes.
|
|
296
|
+
for (; $.len(path) > 0 && $.indexString(path, $.len(path) - 1) == 47; ) {
|
|
297
|
+
path = $.sliceString(path, 0, $.len(path) - 1)
|
|
298
|
+
}
|
|
299
|
+
// Find the last element
|
|
300
|
+
{
|
|
301
|
+
let i = path.lastIndexOf('/')
|
|
302
|
+
if (i >= 0) {
|
|
303
|
+
path = $.sliceString(path, i + 1, undefined)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// If empty now, it had only slashes.
|
|
307
|
+
if (path == '') {
|
|
308
|
+
return '/'
|
|
309
|
+
}
|
|
310
|
+
return path
|
|
283
311
|
}
|
|
284
312
|
|
|
285
313
|
// IsAbs reports whether the path is absolute.
|
|
286
314
|
export function IsAbs(path: string): boolean {
|
|
287
|
-
|
|
315
|
+
return $.len(path) > 0 && $.indexString(path, 0) == 47
|
|
288
316
|
}
|
|
289
317
|
|
|
290
318
|
// Dir returns all but the last element of path, typically the path's directory.
|
|
@@ -295,7 +323,6 @@ export function IsAbs(path: string): boolean {
|
|
|
295
323
|
// returns a single slash. In any other case, the returned path does not end in a
|
|
296
324
|
// slash.
|
|
297
325
|
export function Dir(path: string): string {
|
|
298
|
-
|
|
299
|
-
|
|
326
|
+
let [dir] = Split(path)
|
|
327
|
+
return Clean(dir)
|
|
300
328
|
}
|
|
301
|
-
|
package/gs/runtime/runtime.ts
CHANGED
|
@@ -11,7 +11,7 @@ export function Version(): string {
|
|
|
11
11
|
// GOMAXPROCS sets the maximum number of operating system threads
|
|
12
12
|
//
|
|
13
13
|
// JavaScript is single threaded so this always returns 1.
|
|
14
|
-
export function GOMAXPROCS(
|
|
14
|
+
export function GOMAXPROCS(_n: number): number {
|
|
15
15
|
// In a full implementation, we would set the max procs
|
|
16
16
|
// Since JavaScript only supports 1, just return 1.
|
|
17
17
|
return 1
|
|
@@ -69,7 +69,7 @@ export function _decrementGoroutineCount(): void {
|
|
|
69
69
|
|
|
70
70
|
// Caller returns details about the calling goroutine's stack.
|
|
71
71
|
// This is a simplified version for goscript
|
|
72
|
-
export function Caller(
|
|
72
|
+
export function Caller(_skip: number): [number, string, number, boolean] {
|
|
73
73
|
// In JavaScript, we can use Error stack trace, but it's limited
|
|
74
74
|
// Return dummy values for goscript compatibility
|
|
75
75
|
const pc = 0 // program counter (not meaningful in JS)
|
|
@@ -159,8 +159,8 @@ export class PanicError implements Error {
|
|
|
159
159
|
// SetFinalizer sets the finalizer associated with obj to the provided finalizer function.
|
|
160
160
|
// In goscript/TypeScript environment, finalizers are not supported, so this throws an error.
|
|
161
161
|
export function SetFinalizer(
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
_obj: object,
|
|
163
|
+
_finalizer: ((obj: object) => void) | null,
|
|
164
164
|
): void {
|
|
165
165
|
throw new Error(
|
|
166
166
|
'runtime.SetFinalizer is not supported in goscript TypeScript environment',
|
package/gs/strings/builder.ts
CHANGED
package/gs/strings/clone.ts
CHANGED
package/gs/strings/compare.ts
CHANGED
package/gs/strings/iter.test.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as io from '@goscript/io/index.js'
|
|
2
|
+
import { NewReplacer } from './replace.js'
|
|
3
|
+
import * as io from '../io/index.js'
|
|
5
4
|
|
|
6
5
|
describe('strings/Replacer', () => {
|
|
7
6
|
describe('NewReplacer', () => {
|
|
@@ -99,7 +98,7 @@ describe('strings/Replacer', () => {
|
|
|
99
98
|
const r = NewReplacer('hello', 'hi')
|
|
100
99
|
if (r) {
|
|
101
100
|
const errorWriter: io.Writer = {
|
|
102
|
-
Write: (
|
|
101
|
+
Write: (_p: Uint8Array) => {
|
|
103
102
|
return [0, new Error('write error')]
|
|
104
103
|
},
|
|
105
104
|
}
|
package/gs/strings/replace.ts
CHANGED
|
@@ -761,8 +761,6 @@ export function makeGenericReplacer(
|
|
|
761
761
|
return r
|
|
762
762
|
}
|
|
763
763
|
|
|
764
|
-
type appendSliceWriter = Uint8Array
|
|
765
|
-
|
|
766
764
|
class stringWriter {
|
|
767
765
|
public get w(): io.Writer {
|
|
768
766
|
return this._fields.w.value
|
|
@@ -777,7 +775,7 @@ class stringWriter {
|
|
|
777
775
|
|
|
778
776
|
constructor(init?: Partial<{ w?: io.Writer }>) {
|
|
779
777
|
this._fields = {
|
|
780
|
-
w: $.varRef(init
|
|
778
|
+
w: $.varRef(init!.w!),
|
|
781
779
|
}
|
|
782
780
|
}
|
|
783
781
|
|
|
@@ -982,8 +980,6 @@ export function makeSingleStringReplacer(
|
|
|
982
980
|
})
|
|
983
981
|
}
|
|
984
982
|
|
|
985
|
-
type byteReplacer = number[]
|
|
986
|
-
|
|
987
983
|
class byteStringReplacer {
|
|
988
984
|
// replacements contains replacement byte slices indexed by old byte.
|
|
989
985
|
// A nil []byte means that the old byte should not be replaced.
|
|
@@ -1240,6 +1236,9 @@ class byteStringReplacer {
|
|
|
1240
1236
|
if (last != $.len(s)) {
|
|
1241
1237
|
let [nw, err] = sw!.WriteString($.sliceString(s, last, undefined))
|
|
1242
1238
|
n += nw
|
|
1239
|
+
if (err != null) {
|
|
1240
|
+
return [n, err]
|
|
1241
|
+
}
|
|
1243
1242
|
}
|
|
1244
1243
|
return [n, err]
|
|
1245
1244
|
}
|
|
@@ -1298,8 +1297,6 @@ class byteStringReplacer {
|
|
|
1298
1297
|
)
|
|
1299
1298
|
}
|
|
1300
1299
|
|
|
1301
|
-
let countCutOff: number = 8
|
|
1302
|
-
|
|
1303
1300
|
// Helper function to copy bytes
|
|
1304
1301
|
function copy(dst: Uint8Array, src: Uint8Array): number {
|
|
1305
1302
|
const n = Math.min(dst.length, src.length)
|