goscript 0.0.28 → 0.0.30

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 (74) hide show
  1. package/compiler/analysis.go +41 -2
  2. package/compiler/compiler.go +8 -1
  3. package/compiler/expr-call.go +87 -15
  4. package/compiler/expr-selector.go +100 -0
  5. package/compiler/spec-value.go +79 -8
  6. package/compiler/spec.go +236 -0
  7. package/dist/gs/builtin/builtin.d.ts +1 -0
  8. package/dist/gs/builtin/builtin.js +11 -0
  9. package/dist/gs/builtin/builtin.js.map +1 -1
  10. package/dist/gs/internal/oserror/errors.d.ts +6 -0
  11. package/dist/gs/internal/oserror/errors.js +7 -0
  12. package/dist/gs/internal/oserror/errors.js.map +1 -0
  13. package/dist/gs/internal/oserror/index.d.ts +1 -0
  14. package/dist/gs/internal/oserror/index.js +2 -0
  15. package/dist/gs/internal/oserror/index.js.map +1 -0
  16. package/dist/gs/io/fs/format.d.ts +3 -0
  17. package/dist/gs/io/fs/format.js +56 -0
  18. package/dist/gs/io/fs/format.js.map +1 -0
  19. package/dist/gs/io/fs/fs.d.ts +79 -0
  20. package/dist/gs/io/fs/fs.js +200 -0
  21. package/dist/gs/io/fs/fs.js.map +1 -0
  22. package/dist/gs/io/fs/glob.d.ts +10 -0
  23. package/dist/gs/io/fs/glob.js +141 -0
  24. package/dist/gs/io/fs/glob.js.map +1 -0
  25. package/dist/gs/io/fs/index.d.ts +8 -0
  26. package/dist/gs/io/fs/index.js +9 -0
  27. package/dist/gs/io/fs/index.js.map +1 -0
  28. package/dist/gs/io/fs/readdir.d.ts +7 -0
  29. package/dist/gs/io/fs/readdir.js +152 -0
  30. package/dist/gs/io/fs/readdir.js.map +1 -0
  31. package/dist/gs/io/fs/readfile.d.ts +6 -0
  32. package/dist/gs/io/fs/readfile.js +118 -0
  33. package/dist/gs/io/fs/readfile.js.map +1 -0
  34. package/dist/gs/io/fs/stat.d.ts +6 -0
  35. package/dist/gs/io/fs/stat.js +87 -0
  36. package/dist/gs/io/fs/stat.js.map +1 -0
  37. package/dist/gs/io/fs/sub.d.ts +6 -0
  38. package/dist/gs/io/fs/sub.js +172 -0
  39. package/dist/gs/io/fs/sub.js.map +1 -0
  40. package/dist/gs/io/fs/walk.d.ts +7 -0
  41. package/dist/gs/io/fs/walk.js +76 -0
  42. package/dist/gs/io/fs/walk.js.map +1 -0
  43. package/dist/gs/path/index.d.ts +2 -0
  44. package/dist/gs/path/index.js +3 -0
  45. package/dist/gs/path/index.js.map +1 -0
  46. package/dist/gs/path/match.d.ts +6 -0
  47. package/dist/gs/path/match.js +281 -0
  48. package/dist/gs/path/match.js.map +1 -0
  49. package/dist/gs/path/path.d.ts +7 -0
  50. package/dist/gs/path/path.js +256 -0
  51. package/dist/gs/path/path.js.map +1 -0
  52. package/dist/gs/time/time.d.ts +11 -2
  53. package/dist/gs/time/time.js +337 -12
  54. package/dist/gs/time/time.js.map +1 -1
  55. package/gs/builtin/builtin.ts +13 -0
  56. package/gs/internal/oserror/errors.ts +14 -0
  57. package/gs/internal/oserror/index.ts +1 -0
  58. package/gs/io/fs/format.ts +65 -0
  59. package/gs/io/fs/fs.ts +359 -0
  60. package/gs/io/fs/glob.ts +167 -0
  61. package/gs/io/fs/godoc.txt +35 -0
  62. package/gs/io/fs/index.ts +8 -0
  63. package/gs/io/fs/readdir.ts +126 -0
  64. package/gs/io/fs/readfile.ts +77 -0
  65. package/gs/io/fs/stat.ts +38 -0
  66. package/gs/io/fs/sub.ts +208 -0
  67. package/gs/io/fs/walk.ts +89 -0
  68. package/gs/path/index.ts +2 -0
  69. package/gs/path/match.ts +307 -0
  70. package/gs/path/path.ts +301 -0
  71. package/gs/strings/reader.test.ts +0 -1
  72. package/gs/time/time.ts +325 -12
  73. package/package.json +1 -1
  74. package/gs/time/godoc.md +0 -116
@@ -0,0 +1,76 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { FileInfoToDirEntry, ReadDir } from "./readdir.js";
3
+ import { Stat } from "./stat.js";
4
+ import * as errors from "@goscript/errors/index.js";
5
+ import * as path from "@goscript/path/index.js";
6
+ export let SkipDir = errors.New("skip this directory");
7
+ export let SkipAll = errors.New("skip everything and stop the walk");
8
+ // walkDir recursively descends path, calling walkDirFn.
9
+ export function walkDir(fsys, name, d, walkDirFn) {
10
+ // Successfully skipped directory.
11
+ {
12
+ let err = walkDirFn(name, d, null);
13
+ if (err != null || !d.IsDir()) {
14
+ // Successfully skipped directory.
15
+ if (err == SkipDir && d.IsDir()) {
16
+ // Successfully skipped directory.
17
+ err = null;
18
+ }
19
+ return err;
20
+ }
21
+ }
22
+ let [dirs, err] = ReadDir(fsys, name);
23
+ // Second call, to report ReadDir error.
24
+ if (err != null) {
25
+ // Second call, to report ReadDir error.
26
+ err = walkDirFn(name, d, err);
27
+ if (err != null) {
28
+ if (err == SkipDir && d.IsDir()) {
29
+ err = null;
30
+ }
31
+ return err;
32
+ }
33
+ }
34
+ for (let _i = 0; _i < $.len(dirs); _i++) {
35
+ const d1 = dirs[_i];
36
+ {
37
+ let name1 = path.Join(name, d1.Name());
38
+ {
39
+ let err = walkDir(fsys, name1, d1, walkDirFn);
40
+ if (err != null) {
41
+ if (err == SkipDir) {
42
+ break;
43
+ }
44
+ return err;
45
+ }
46
+ }
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ // WalkDir walks the file tree rooted at root, calling fn for each file or
52
+ // directory in the tree, including root.
53
+ //
54
+ // All errors that arise visiting files and directories are filtered by fn:
55
+ // see the [fs.WalkDirFunc] documentation for details.
56
+ //
57
+ // The files are walked in lexical order, which makes the output deterministic
58
+ // but requires WalkDir to read an entire directory into memory before proceeding
59
+ // to walk that directory.
60
+ //
61
+ // WalkDir does not follow symbolic links found in directories,
62
+ // but if root itself is a symbolic link, its target will be walked.
63
+ export function WalkDir(fsys, root, fn) {
64
+ let [info, err] = Stat(fsys, root);
65
+ if (err != null) {
66
+ err = fn(root, null, err);
67
+ }
68
+ else {
69
+ err = walkDir(fsys, root, FileInfoToDirEntry(info), fn);
70
+ }
71
+ if (err == SkipDir || err == SkipAll) {
72
+ return null;
73
+ }
74
+ return err;
75
+ }
76
+ //# sourceMappingURL=walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.js","sourceRoot":"","sources":["../../../../gs/io/fs/walk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,8BAA8B,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAA;AAEnD,OAAO,KAAK,IAAI,MAAM,yBAAyB,CAAA;AAE/C,MAAM,CAAC,IAAI,OAAO,GAAc,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;AAEjE,MAAM,CAAC,IAAI,OAAO,GAAc,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAA;AAI/E,wDAAwD;AACxD,MAAM,UAAU,OAAO,CAAC,IAAQ,EAAE,IAAY,EAAE,CAAW,EAAE,SAAsB;IAElF,kCAAkC;IAClC,CAAC;QACA,IAAI,GAAG,GAAG,SAAU,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;QACnC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,CAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YAEhC,kCAAkC;YAClC,IAAI,GAAG,IAAI,OAAO,IAAI,CAAE,CAAC,KAAK,EAAE,EAAE,CAAC;gBAClC,kCAAkC;gBAClC,GAAG,GAAG,IAAI,CAAA;YACX,CAAC;YACD,OAAO,GAAG,CAAA;QACX,CAAC;IACF,CAAC;IAED,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAErC,wCAAwC;IACxC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC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,IAAI,EAAE,CAAC;QACjB,GAAG,GAAG,EAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;IAC3B,CAAC;SAAM,CAAC;QACP,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IACxD,CAAC;IACD,IAAI,GAAG,IAAI,OAAO,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;QACtC,OAAO,IAAI,CAAA;IACZ,CAAC;IACD,OAAO,GAAG,CAAA;AACX,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ErrBadPattern, Match } from "./match.js";
2
+ export { Base, Clean, Dir, Ext, IsAbs, Join, Split } from "./path.js";
@@ -0,0 +1,3 @@
1
+ export { ErrBadPattern, Match } from "./match.js";
2
+ export { Base, Clean, Dir, Ext, IsAbs, Join, Split } from "./path.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../gs/path/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA"}
@@ -0,0 +1,6 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ export declare let ErrBadPattern: $.GoError;
3
+ export declare function Match(pattern: string, name: string): [boolean, $.GoError];
4
+ export declare function scanChunk(pattern: string): [boolean, string, string];
5
+ export declare function matchChunk(chunk: string, s: string): [string, boolean, $.GoError];
6
+ export declare function getEsc(chunk: string): [number, string, $.GoError];
@@ -0,0 +1,281 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import * as errors from "@goscript/errors/index.js";
3
+ import * as utf8 from "@goscript/unicode/utf8/index.js";
4
+ export let ErrBadPattern = errors.New("syntax error in pattern");
5
+ // Match reports whether name matches the shell pattern.
6
+ // The pattern syntax is:
7
+ //
8
+ // pattern:
9
+ // { term }
10
+ // term:
11
+ // '*' matches any sequence of non-/ characters
12
+ // '?' matches any single non-/ character
13
+ // '[' [ '^' ] { character-range } ']'
14
+ // character class (must be non-empty)
15
+ // c matches character c (c != '*', '?', '\\', '[')
16
+ // '\\' c matches character c
17
+ //
18
+ // character-range:
19
+ // c matches character c (c != '\\', '-', ']')
20
+ // '\\' c matches character c
21
+ // lo '-' hi matches character c for lo <= c <= hi
22
+ //
23
+ // Match requires pattern to match all of name, not just a substring.
24
+ // The only possible returned error is [ErrBadPattern], when pattern
25
+ // is malformed.
26
+ export function Match(pattern, name) {
27
+ let matched = false;
28
+ let err = null;
29
+ {
30
+ // Trailing * matches rest of string unless it has a /.
31
+ // Look for match at current position.
32
+ // if we're the last chunk, make sure we've exhausted the name
33
+ // otherwise we'll give a false result even if we could still match
34
+ // using the star
35
+ // Look for match skipping i+1 bytes.
36
+ // Cannot skip /.
37
+ // if we're the last chunk, make sure we exhausted the name
38
+ // Before returning false with no error,
39
+ // check that the remainder of the pattern is syntactically valid.
40
+ Pattern: for (; $.len(pattern) > 0;) {
41
+ let star = false;
42
+ let chunk = "";
43
+ let rest = "";
44
+ let scanResult = scanChunk(pattern);
45
+ star = scanResult[0];
46
+ chunk = scanResult[1];
47
+ rest = scanResult[2];
48
+ pattern = rest;
49
+ // Trailing * matches rest of string unless it has a /.
50
+ if (star && chunk == "") {
51
+ // Trailing * matches rest of string unless it has a /.
52
+ return [name.indexOf("/") < 0, null];
53
+ }
54
+ // Look for match at current position.
55
+ let [t, ok, err] = matchChunk(chunk, name);
56
+ // if we're the last chunk, make sure we've exhausted the name
57
+ // otherwise we'll give a false result even if we could still match
58
+ // using the star
59
+ if (ok && ($.len(t) == 0 || $.len(pattern) > 0)) {
60
+ name = t;
61
+ continue;
62
+ }
63
+ if (err != null) {
64
+ return [false, err];
65
+ }
66
+ // Look for match skipping i+1 bytes.
67
+ // Cannot skip /.
68
+ // if we're the last chunk, make sure we exhausted the name
69
+ if (star) {
70
+ // Look for match skipping i+1 bytes.
71
+ // Cannot skip /.
72
+ // if we're the last chunk, make sure we exhausted the name
73
+ for (let i = 0; i < $.len(name) && $.indexString(name, i) != 47; i++) {
74
+ let [t, ok, err] = matchChunk(chunk, $.sliceString(name, i, undefined));
75
+ // if we're the last chunk, make sure we exhausted the name
76
+ if (ok) {
77
+ // if we're the last chunk, make sure we exhausted the name
78
+ if ($.len(pattern) == 0 && $.len(t) > 0) {
79
+ continue;
80
+ }
81
+ name = t;
82
+ continue Pattern;
83
+ }
84
+ if (err != null) {
85
+ return [false, err];
86
+ }
87
+ }
88
+ }
89
+ // Before returning false with no error,
90
+ // check that the remainder of the pattern is syntactically valid.
91
+ for (; $.len(pattern) > 0;) {
92
+ let star2 = false;
93
+ let chunk2 = "";
94
+ let rest2 = "";
95
+ let scanResult2 = scanChunk(pattern);
96
+ star2 = scanResult2[0];
97
+ chunk2 = scanResult2[1];
98
+ rest2 = scanResult2[2];
99
+ pattern = rest2;
100
+ {
101
+ let [, , err] = matchChunk(chunk2, "");
102
+ if (err != null) {
103
+ return [false, err];
104
+ }
105
+ }
106
+ }
107
+ return [false, null];
108
+ }
109
+ return [$.len(name) == 0, null];
110
+ }
111
+ }
112
+ // scanChunk gets the next segment of pattern, which is a non-star string
113
+ // possibly preceded by a star.
114
+ export function scanChunk(pattern) {
115
+ let star = false;
116
+ let chunk = "";
117
+ let rest = "";
118
+ {
119
+ for (; $.len(pattern) > 0 && $.indexString(pattern, 0) == 42;) {
120
+ pattern = $.sliceString(pattern, 1, undefined);
121
+ star = true;
122
+ }
123
+ let inrange = false;
124
+ let i = 0;
125
+ // error check handled in matchChunk: bad pattern.
126
+ Scan: for (i = 0; i < $.len(pattern); i++) {
127
+ // error check handled in matchChunk: bad pattern.
128
+ switch ($.indexString(pattern, i)) {
129
+ case 92:
130
+ if (i + 1 < $.len(pattern)) {
131
+ i++;
132
+ }
133
+ break;
134
+ case 91:
135
+ inrange = true;
136
+ break;
137
+ case 93:
138
+ inrange = false;
139
+ break;
140
+ case 42:
141
+ if (!inrange) {
142
+ break Scan;
143
+ }
144
+ break;
145
+ }
146
+ }
147
+ return [star, $.sliceString(pattern, 0, i), $.sliceString(pattern, i, undefined)];
148
+ }
149
+ }
150
+ // matchChunk checks whether chunk matches the beginning of s.
151
+ // If so, it returns the remainder of s (after the match).
152
+ // Chunk is all single-character operators: literals, char classes, and ?.
153
+ export function matchChunk(chunk, s) {
154
+ let rest = "";
155
+ let ok = false;
156
+ let err = null;
157
+ {
158
+ // failed records whether the match has failed.
159
+ // After the match fails, the loop continues on processing chunk,
160
+ // checking that the pattern is well-formed but no longer reading s.
161
+ let failed = false;
162
+ // character class
163
+ // possibly negated
164
+ // parse all ranges
165
+ for (; $.len(chunk) > 0;) {
166
+ if (!failed && $.len(s) == 0) {
167
+ failed = true;
168
+ }
169
+ // character class
170
+ // possibly negated
171
+ // parse all ranges
172
+ switch ($.indexString(chunk, 0)) {
173
+ case 91:
174
+ let r = 0;
175
+ if (!failed) {
176
+ let n = 0;
177
+ let decoded = utf8.DecodeRuneInString(s);
178
+ r = decoded[0];
179
+ n = decoded[1];
180
+ s = $.sliceString(s, n, undefined);
181
+ }
182
+ chunk = $.sliceString(chunk, 1, undefined);
183
+ let negated = false;
184
+ if ($.len(chunk) > 0 && $.indexString(chunk, 0) == 94) {
185
+ negated = true;
186
+ chunk = $.sliceString(chunk, 1, undefined);
187
+ }
188
+ let match = false;
189
+ let nrange = 0;
190
+ for (;;) {
191
+ if ($.len(chunk) > 0 && $.indexString(chunk, 0) == 93 && nrange > 0) {
192
+ chunk = $.sliceString(chunk, 1, undefined);
193
+ break;
194
+ }
195
+ let lo = 0;
196
+ let hi = 0;
197
+ {
198
+ let escResult = getEsc(chunk);
199
+ lo = escResult[0];
200
+ chunk = escResult[1];
201
+ err = escResult[2];
202
+ if (err != null) {
203
+ return ["", false, err];
204
+ }
205
+ }
206
+ hi = lo;
207
+ if ($.indexString(chunk, 0) == 45) {
208
+ {
209
+ let escResult2 = getEsc($.sliceString(chunk, 1, undefined));
210
+ hi = escResult2[0];
211
+ chunk = escResult2[1];
212
+ err = escResult2[2];
213
+ if (err != null) {
214
+ return ["", false, err];
215
+ }
216
+ }
217
+ }
218
+ if (lo <= r && r <= hi) {
219
+ match = true;
220
+ }
221
+ nrange++;
222
+ }
223
+ if (match == negated) {
224
+ failed = true;
225
+ }
226
+ break;
227
+ case 63:
228
+ if (!failed) {
229
+ if ($.indexString(s, 0) == 47) {
230
+ failed = true;
231
+ }
232
+ let [, n] = utf8.DecodeRuneInString(s);
233
+ s = $.sliceString(s, n, undefined);
234
+ }
235
+ chunk = $.sliceString(chunk, 1, undefined);
236
+ break;
237
+ case 92:
238
+ chunk = $.sliceString(chunk, 1, undefined);
239
+ if ($.len(chunk) == 0) {
240
+ return ["", false, ErrBadPattern];
241
+ }
242
+ // unhandled branch statement token: fallthrough
243
+ break;
244
+ default:
245
+ if (!failed) {
246
+ if ($.indexString(chunk, 0) != $.indexString(s, 0)) {
247
+ failed = true;
248
+ }
249
+ s = $.sliceString(s, 1, undefined);
250
+ }
251
+ chunk = $.sliceString(chunk, 1, undefined);
252
+ break;
253
+ }
254
+ }
255
+ if (failed) {
256
+ return ["", false, null];
257
+ }
258
+ return [s, true, null];
259
+ }
260
+ }
261
+ export function getEsc(chunk) {
262
+ if ($.len(chunk) == 0 || $.indexString(chunk, 0) == 45 || $.indexString(chunk, 0) == 93) {
263
+ return [0, "", ErrBadPattern];
264
+ }
265
+ if ($.indexString(chunk, 0) == 92) {
266
+ chunk = $.sliceString(chunk, 1, undefined);
267
+ if ($.len(chunk) == 0) {
268
+ return [0, "", ErrBadPattern];
269
+ }
270
+ }
271
+ let [r, n] = utf8.DecodeRuneInString(chunk);
272
+ if (r == utf8.RuneError && n == 1) {
273
+ return [0, "", ErrBadPattern];
274
+ }
275
+ chunk = $.sliceString(chunk, n, undefined);
276
+ if ($.len(chunk) == 0 || $.indexString(chunk, 0) != 45 || $.len(chunk) == 1) {
277
+ return [r, chunk, null];
278
+ }
279
+ return [r, chunk, null];
280
+ }
281
+ //# sourceMappingURL=match.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.js","sourceRoot":"","sources":["../../../gs/path/match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,8BAA8B,CAAC;AAElD,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAA;AAEnD,OAAO,KAAK,IAAI,MAAM,iCAAiC,CAAA;AAEvD,MAAM,CAAC,IAAI,aAAa,GAAc,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAA;AAE3E,wDAAwD;AACxD,yBAAyB;AACzB,EAAE;AACF,WAAW;AACX,YAAY;AACZ,QAAQ;AACR,wDAAwD;AACxD,kDAAkD;AAClD,uCAAuC;AACvC,mDAAmD;AACnD,8DAA8D;AAC9D,mCAAmC;AACnC,EAAE;AACF,mBAAmB;AACnB,yDAAyD;AACzD,mCAAmC;AACnC,qDAAqD;AACrD,EAAE;AACF,qEAAqE;AACrE,oEAAoE;AACpE,gBAAgB;AAChB,MAAM,UAAU,KAAK,CAAC,OAAe,EAAE,IAAY;IAClD,IAAI,OAAO,GAAY,KAAK,CAAA;IAC5B,IAAI,GAAG,GAAc,IAAI,CAAA;IACzB,CAAC;QAEA,uDAAuD;QAEvD,sCAAsC;QAEtC,8DAA8D;QAC9D,mEAAmE;QACnE,iBAAiB;QAEjB,qCAAqC;QACrC,iBAAiB;QAEjB,2DAA2D;QAE3D,wCAAwC;QACxC,kEAAkE;QAClE,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAI,CAAC;YACtC,IAAI,IAAI,GAAY,KAAK,CAAA;YACzB,IAAI,KAAK,GAAW,EAAE,CAAA;YACtB,IAAI,IAAI,GAAW,EAAE,CAAA;YACrB,IAAI,UAAU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ACD,IAAI,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACnC,KAAK,GAAG,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,aAAa,CAAC,CAAA;QAC9B,CAAC;IACF,CAAC;IACD,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAC3C,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,aAAa,CAAC,CAAA;IAC9B,CAAC;IACD,KAAK,GAAG,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IAC1C,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7E,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;IACxB,CAAC;IACD,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;AACxB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare function Clean(path: string): string;
2
+ export declare function Split(path: string): [string, string];
3
+ export declare function Join(...elem: string[]): string;
4
+ export declare function Ext(path: string): string;
5
+ export declare function Base(path: string): string;
6
+ export declare function IsAbs(path: string): boolean;
7
+ export declare function Dir(path: string): string;
@@ -0,0 +1,256 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ class lazybuf {
3
+ get s() {
4
+ return this._fields.s.value;
5
+ }
6
+ set s(value) {
7
+ this._fields.s.value = value;
8
+ }
9
+ get buf() {
10
+ return this._fields.buf.value;
11
+ }
12
+ set buf(value) {
13
+ this._fields.buf.value = value;
14
+ }
15
+ get w() {
16
+ return this._fields.w.value;
17
+ }
18
+ set w(value) {
19
+ this._fields.w.value = value;
20
+ }
21
+ _fields;
22
+ constructor(init) {
23
+ this._fields = {
24
+ s: $.varRef(init?.s ?? ""),
25
+ buf: $.varRef(init?.buf ?? null),
26
+ w: $.varRef(init?.w ?? 0)
27
+ };
28
+ }
29
+ clone() {
30
+ const cloned = new lazybuf();
31
+ cloned._fields = {
32
+ s: $.varRef(this._fields.s.value),
33
+ buf: $.varRef(this._fields.buf.value),
34
+ w: $.varRef(this._fields.w.value)
35
+ };
36
+ return cloned;
37
+ }
38
+ index(i) {
39
+ const b = this;
40
+ if (b.buf != null) {
41
+ return b.buf[i];
42
+ }
43
+ return $.indexString(b.s, i);
44
+ }
45
+ append(c) {
46
+ const b = this;
47
+ if (b.buf == null) {
48
+ if (b.w < $.len(b.s) && $.indexString(b.s, b.w) == c) {
49
+ b.w++;
50
+ return;
51
+ }
52
+ b.buf = new Uint8Array($.len(b.s));
53
+ $.copy(b.buf, $.stringToBytes($.sliceString(b.s, undefined, b.w)));
54
+ }
55
+ b.buf[b.w] = c;
56
+ b.w++;
57
+ }
58
+ _string() {
59
+ const b = this;
60
+ if (b.buf == null) {
61
+ return $.sliceString(b.s, undefined, b.w);
62
+ }
63
+ return $.bytesToString(b.buf.subarray(0, b.w));
64
+ }
65
+ // Register this type with the runtime type system
66
+ static __typeInfo = $.registerStructType('lazybuf', new lazybuf(), [{ name: "index", args: [{ name: "i", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "append", args: [{ name: "c", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [] }, { name: "string", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }], lazybuf, { "s": { kind: $.TypeKind.Basic, name: "string" }, "buf": { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } }, "w": { kind: $.TypeKind.Basic, name: "number" } });
67
+ }
68
+ // Clean returns the shortest path name equivalent to path
69
+ // by purely lexical processing. It applies the following rules
70
+ // iteratively until no further processing can be done:
71
+ //
72
+ // 1. Replace multiple slashes with a single slash.
73
+ // 2. Eliminate each . path name element (the current directory).
74
+ // 3. Eliminate each inner .. path name element (the parent directory)
75
+ // along with the non-.. element that precedes it.
76
+ // 4. Eliminate .. elements that begin a rooted path:
77
+ // that is, replace "/.." by "/" at the beginning of a path.
78
+ //
79
+ // The returned path ends in a slash only if it is the root "/".
80
+ //
81
+ // If the result of this process is an empty string, Clean
82
+ // returns the string ".".
83
+ //
84
+ // See also Rob Pike, "Lexical File Names in Plan 9 or
85
+ // Getting Dot-Dot Right,"
86
+ // https://9p.io/sys/doc/lexnames.html
87
+ export function Clean(path) {
88
+ if (path == "") {
89
+ return ".";
90
+ }
91
+ let rooted = $.indexString(path, 0) == 47;
92
+ let n = $.len(path);
93
+ // Invariants:
94
+ // reading from path; r is index of next byte to process.
95
+ // writing to buf; w is index of next byte to write.
96
+ // dotdot is index in buf where .. must stop, either because
97
+ // it is the leading slash or it is a leading ../../.. prefix.
98
+ let out = new lazybuf({ s: path });
99
+ let r = 0;
100
+ let dotdot = 0;
101
+ if (rooted) {
102
+ out.append(47);
103
+ r = 1;
104
+ dotdot = 1;
105
+ }
106
+ // empty path element
107
+ // . element
108
+ // .. element: remove to last /
109
+ // can backtrack
110
+ // cannot backtrack, but not rooted, so append .. element.
111
+ // real path element.
112
+ // add slash if needed
113
+ // copy element
114
+ for (; r < n;) {
115
+ // empty path element
116
+ // . element
117
+ // .. element: remove to last /
118
+ // can backtrack
119
+ // cannot backtrack, but not rooted, so append .. element.
120
+ // real path element.
121
+ // add slash if needed
122
+ // copy element
123
+ switch (true) {
124
+ case $.indexString(path, r) == 47:
125
+ r++;
126
+ break;
127
+ case $.indexString(path, r) == 46 && (r + 1 == n || $.indexString(path, r + 1) == 47):
128
+ r++;
129
+ break;
130
+ case $.indexString(path, r) == 46 && $.indexString(path, r + 1) == 46 && (r + 2 == n || $.indexString(path, r + 2) == 47):
131
+ r += 2;
132
+ switch (true) {
133
+ case out.w > dotdot:
134
+ out.w--;
135
+ for (; out.w > dotdot && out.index(out.w) != 47;) {
136
+ out.w--;
137
+ }
138
+ break;
139
+ case !rooted:
140
+ if (out.w > 0) {
141
+ out.append(47);
142
+ }
143
+ out.append(46);
144
+ out.append(46);
145
+ dotdot = out.w;
146
+ break;
147
+ }
148
+ break;
149
+ default:
150
+ if (rooted && out.w != 1 || !rooted && out.w != 0) {
151
+ out.append(47);
152
+ }
153
+ for (; r < n && $.indexString(path, r) != 47; r++) {
154
+ out.append($.indexString(path, r));
155
+ }
156
+ break;
157
+ }
158
+ }
159
+ // Turn empty string into "."
160
+ if (out.w == 0) {
161
+ return ".";
162
+ }
163
+ return out._string();
164
+ }
165
+ // Split splits path immediately following the final slash,
166
+ // separating it into a directory and file name component.
167
+ // If there is no slash in path, Split returns an empty dir and
168
+ // file set to path.
169
+ // The returned values have the property that path = dir+file.
170
+ export function Split(path) {
171
+ let i = path.lastIndexOf("/");
172
+ return [$.sliceString(path, undefined, i + 1), $.sliceString(path, i + 1, undefined)];
173
+ }
174
+ // Join joins any number of path elements into a single path,
175
+ // separating them with slashes. Empty elements are ignored.
176
+ // The result is Cleaned. However, if the argument list is
177
+ // empty or all its elements are empty, Join returns
178
+ // an empty string.
179
+ export function Join(...elem) {
180
+ let size = 0;
181
+ for (let _i = 0; _i < $.len(elem); _i++) {
182
+ const e = elem[_i];
183
+ {
184
+ size += $.len(e);
185
+ }
186
+ }
187
+ if (size == 0) {
188
+ return "";
189
+ }
190
+ let buf = [];
191
+ for (let _i = 0; _i < $.len(elem); _i++) {
192
+ const e = elem[_i];
193
+ {
194
+ if ($.len(buf) > 0 || e != "") {
195
+ if ($.len(buf) > 0) {
196
+ buf.push("/");
197
+ }
198
+ buf.push(e);
199
+ }
200
+ }
201
+ }
202
+ return Clean(buf.join(""));
203
+ }
204
+ // Ext returns the file name extension used by path.
205
+ // The extension is the suffix beginning at the final dot
206
+ // in the final slash-separated element of path;
207
+ // it is empty if there is no dot.
208
+ export function Ext(path) {
209
+ for (let i = $.len(path) - 1; i >= 0 && $.indexString(path, i) != 47; i--) {
210
+ if ($.indexString(path, i) == 46) {
211
+ return $.sliceString(path, i, undefined);
212
+ }
213
+ }
214
+ return "";
215
+ }
216
+ // Base returns the last element of path.
217
+ // Trailing slashes are removed before extracting the last element.
218
+ // If the path is empty, Base returns ".".
219
+ // If the path consists entirely of slashes, Base returns "/".
220
+ export function Base(path) {
221
+ if (path == "") {
222
+ return ".";
223
+ }
224
+ // Strip trailing slashes.
225
+ for (; $.len(path) > 0 && $.indexString(path, $.len(path) - 1) == 47;) {
226
+ path = $.sliceString(path, 0, $.len(path) - 1);
227
+ }
228
+ // Find the last element
229
+ {
230
+ let i = path.lastIndexOf("/");
231
+ if (i >= 0) {
232
+ path = $.sliceString(path, i + 1, undefined);
233
+ }
234
+ }
235
+ // If empty now, it had only slashes.
236
+ if (path == "") {
237
+ return "/";
238
+ }
239
+ return path;
240
+ }
241
+ // IsAbs reports whether the path is absolute.
242
+ export function IsAbs(path) {
243
+ return $.len(path) > 0 && $.indexString(path, 0) == 47;
244
+ }
245
+ // Dir returns all but the last element of path, typically the path's directory.
246
+ // After dropping the final element using [Split], the path is Cleaned and trailing
247
+ // slashes are removed.
248
+ // If the path is empty, Dir returns ".".
249
+ // If the path consists entirely of slashes followed by non-slash bytes, Dir
250
+ // returns a single slash. In any other case, the returned path does not end in a
251
+ // slash.
252
+ export function Dir(path) {
253
+ let [dir,] = Split(path);
254
+ return Clean(dir);
255
+ }
256
+ //# sourceMappingURL=path.js.map