goscript 0.0.29 → 0.0.31

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/compiler.go +8 -1
  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/glob.ts CHANGED
@@ -1,22 +1,52 @@
1
- import * as $ from "@goscript/builtin/builtin.js";
2
- import { Stat } from "./stat.js";
3
- import { ReadDir } from "./readdir.js";
4
- import { FS } from "./fs.js";
5
-
6
- import * as path from "@goscript/path/index.js"
7
-
8
- export type GlobFS = null | {
9
- // Glob returns the names of all files matching pattern,
10
- // providing an implementation of the top-level
11
- // Glob function.
12
- Glob(pattern: string): [$.Slice<string>, $.GoError]
13
- } & FS
1
+ import * as $ from '@goscript/builtin/builtin.js'
2
+ import { Stat } from './stat.js'
3
+ import { ReadDir } from './readdir.js'
4
+ import { FS } from './fs.js'
5
+
6
+ import * as path from '@goscript/path/index.js'
7
+
8
+ export type GlobFS =
9
+ | null
10
+ | ({
11
+ // Glob returns the names of all files matching pattern,
12
+ // providing an implementation of the top-level
13
+ // Glob function.
14
+ Glob(pattern: string): [$.Slice<string>, $.GoError]
15
+ } & FS)
14
16
 
15
17
  $.registerInterfaceType(
16
18
  'GlobFS',
17
19
  null, // Zero value for interface is null
18
- [{ name: "Glob", args: [{ name: "pattern", type: { kind: $.TypeKind.Basic, name: "string" } }], returns: [{ type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "string" } } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }]
19
- );
20
+ [
21
+ {
22
+ name: 'Glob',
23
+ args: [
24
+ { name: 'pattern', type: { kind: $.TypeKind.Basic, name: 'string' } },
25
+ ],
26
+ returns: [
27
+ {
28
+ type: {
29
+ kind: $.TypeKind.Slice,
30
+ elemType: { kind: $.TypeKind.Basic, name: 'string' },
31
+ },
32
+ },
33
+ {
34
+ type: {
35
+ kind: $.TypeKind.Interface,
36
+ name: 'GoError',
37
+ methods: [
38
+ {
39
+ name: 'Error',
40
+ args: [],
41
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
42
+ },
43
+ ],
44
+ },
45
+ },
46
+ ],
47
+ },
48
+ ],
49
+ )
20
50
 
21
51
  // Glob returns the names of all files matching pattern or nil
22
52
  // if there is no matching file. The syntax of patterns is the same
@@ -31,137 +61,140 @@ $.registerInterfaceType(
31
61
  // Otherwise, Glob uses [ReadDir] to traverse the directory tree
32
62
  // and look for matches for the pattern.
33
63
  export function Glob(fsys: FS, pattern: string): [$.Slice<string>, $.GoError] {
34
- let matches: $.Slice<string> = null
35
- let err: $.GoError = null
36
- {
37
- return globWithLimit(fsys, pattern, 0)
38
- }
64
+ return globWithLimit(fsys, pattern, 0)
39
65
  }
40
66
 
41
- export function globWithLimit(fsys: FS, pattern: string, depth: number): [$.Slice<string>, $.GoError] {
42
- let matches: $.Slice<string> = null
43
- let err: $.GoError = null
44
- {
45
- // This limit is added to prevent stack exhaustion issues. See
46
- // CVE-2022-30630.
47
- let pathSeparatorsLimit: number = 10000
48
- if (depth > 10000) {
49
- return [null, path.ErrBadPattern]
50
- }
51
- {
52
- let { value: fsysTyped, ok: ok } = $.typeAssert<GlobFS>(fsys, 'GlobFS')
53
- if (ok) {
54
- return fsysTyped!.Glob(pattern)
55
- }
56
- }
57
-
58
- // Check pattern is well-formed.
59
- {
60
- let [, err] = path.Match(pattern, "")
61
- if (err != null) {
62
- return [null, err]
63
- }
64
- }
65
- if (!hasMeta(pattern)) {
66
- {
67
- [, err] = Stat(fsys, pattern)
68
- if (err != null) {
69
- return [null, null]
70
- }
71
- }
72
- return [$.arrayToSlice<string>([pattern]), null]
73
- }
74
-
75
- let [dir, file] = path.Split(pattern)
76
- dir = cleanGlobPath(dir)
77
-
78
- if (!hasMeta(dir)) {
79
- return glob(fsys, dir, file, null)
80
- }
81
-
82
- // Prevent infinite recursion. See issue 15879.
83
- if (dir == pattern) {
84
- return [null, path.ErrBadPattern]
85
- }
86
-
87
- let m: $.Slice<string>
88
- [m, err] = globWithLimit(fsys, dir, depth + 1)
89
- if (err != null) {
90
- return [null, err]
91
- }
92
- for (let _i = 0; _i < $.len(m); _i++) {
93
- const d = m![_i]
94
- {
95
- [matches, err] = glob(fsys, d, file, matches)
96
- if (err != null) {
97
- return [matches, err]
98
- }
99
- }
100
- }
101
- return [matches, err]
102
- }
67
+ export function globWithLimit(
68
+ fsys: FS,
69
+ pattern: string,
70
+ depth: number,
71
+ ): [$.Slice<string>, $.GoError] {
72
+ let matches: $.Slice<string> = null
73
+ let err: $.GoError = null
74
+ {
75
+ // This limit is added to prevent stack exhaustion issues. See
76
+ // CVE-2022-30630.
77
+ let pathSeparatorsLimit: number = 10000
78
+ if (depth > pathSeparatorsLimit) {
79
+ return [null, path.ErrBadPattern]
80
+ }
81
+ {
82
+ let { value: fsysTyped, ok: ok } = $.typeAssert<GlobFS>(fsys, 'GlobFS')
83
+ if (ok) {
84
+ return fsysTyped!.Glob(pattern)
85
+ }
86
+ }
87
+
88
+ // Check pattern is well-formed.
89
+ {
90
+ let [, err] = path.Match(pattern, '')
91
+ if (err != null) {
92
+ return [null, err]
93
+ }
94
+ }
95
+ if (!hasMeta(pattern)) {
96
+ {
97
+ ;[, err] = Stat(fsys, pattern)
98
+ if (err != null) {
99
+ return [null, null]
100
+ }
101
+ }
102
+ return [$.arrayToSlice<string>([pattern]), null]
103
+ }
104
+
105
+ let [dir, file] = path.Split(pattern)
106
+ dir = cleanGlobPath(dir)
107
+
108
+ if (!hasMeta(dir)) {
109
+ return glob(fsys, dir, file, null)
110
+ }
111
+
112
+ // Prevent infinite recursion. See issue 15879.
113
+ if (dir == pattern) {
114
+ return [null, path.ErrBadPattern]
115
+ }
116
+
117
+ let m: $.Slice<string>
118
+ ;[m, err] = globWithLimit(fsys, dir, depth + 1)
119
+ if (err != null) {
120
+ return [null, err]
121
+ }
122
+ for (let _i = 0; _i < $.len(m); _i++) {
123
+ const d = m![_i]
124
+ {
125
+ ;[matches, err] = glob(fsys, d, file, matches)
126
+ if (err != null) {
127
+ return [matches, err]
128
+ }
129
+ }
130
+ }
131
+ return [matches, err]
132
+ }
103
133
  }
104
134
 
105
135
  // cleanGlobPath prepares path for glob matching.
106
136
  export function cleanGlobPath(path: string): string {
107
-
108
- // chop off trailing separator
109
- switch (path) {
110
- case "":
111
- return "."
112
- break
113
- default:
114
- return $.sliceString(path, 0, $.len(path) - 1)
115
- break
116
- }
137
+ // chop off trailing separator
138
+ switch (path) {
139
+ case '':
140
+ return '.'
141
+ break
142
+ default:
143
+ return $.sliceString(path, 0, $.len(path) - 1)
144
+ break
145
+ }
117
146
  }
118
147
 
119
148
  // glob searches for files matching pattern in the directory dir
120
149
  // and appends them to matches, returning the updated slice.
121
150
  // If the directory cannot be opened, glob returns the existing matches.
122
151
  // New matches are added in lexicographical order.
123
- export function glob(fs: FS, dir: string, pattern: string, matches: $.Slice<string>): [$.Slice<string>, $.GoError] {
124
- let m: $.Slice<string> = null
125
- let e: $.GoError = null
126
- {
127
- m = matches
128
- let [infos, err] = ReadDir(fs, dir)
129
-
130
- // ignore I/O error
131
- if (err != null) {
132
- return [m, e]
133
- }
134
-
135
- for (let _i = 0; _i < $.len(infos); _i++) {
136
- const info = infos![_i]
137
- {
138
- let n = info!.Name()
139
- let [matched, err] = path.Match(pattern, n)
140
- if (err != null) {
141
- return [m, err]
142
- }
143
- if (matched) {
144
- m = $.append(m, path.Join(dir, n))
145
- }
146
- }
147
- }
148
- return [m, e]
149
- }
152
+ export function glob(
153
+ fs: FS,
154
+ dir: string,
155
+ pattern: string,
156
+ matches: $.Slice<string>,
157
+ ): [$.Slice<string>, $.GoError] {
158
+ let m: $.Slice<string> = null
159
+ let e: $.GoError = null
160
+ {
161
+ m = matches
162
+ let [infos, err] = ReadDir(fs, dir)
163
+
164
+ // ignore I/O error
165
+ if (err != null) {
166
+ return [m, e]
167
+ }
168
+
169
+ for (let _i = 0; _i < $.len(infos); _i++) {
170
+ const info = infos![_i]
171
+ {
172
+ let n = info!.Name()
173
+ let [matched, err] = path.Match(pattern, n)
174
+ if (err != null) {
175
+ return [m, err]
176
+ }
177
+ if (matched) {
178
+ m = $.append(m, path.Join(dir, n))
179
+ }
180
+ }
181
+ }
182
+ return [m, e]
183
+ }
150
184
  }
151
185
 
152
186
  // hasMeta reports whether path contains any of the magic characters
153
187
  // recognized by path.Match.
154
188
  export function hasMeta(path: string): boolean {
155
- for (let i = 0; i < $.len(path); i++) {
156
- switch ($.indexString(path, i)) {
157
- case 42:
158
- case 63:
159
- case 91:
160
- case 92:
161
- return true
162
- break
163
- }
164
- }
165
- return false
189
+ for (let i = 0; i < $.len(path); i++) {
190
+ switch ($.indexString(path, i)) {
191
+ case 42:
192
+ case 63:
193
+ case 91:
194
+ case 92:
195
+ return true
196
+ break
197
+ }
198
+ }
199
+ return false
166
200
  }
167
-
package/gs/io/fs/index.ts CHANGED
@@ -1,8 +1,8 @@
1
- export * from "./format.js"
2
- export * from "./fs.js"
3
- export * from "./glob.js"
4
- export * from "./readdir.js"
5
- export * from "./readfile.js"
6
- export * from "./stat.js"
7
- export * from "./sub.js"
8
- export * from "./walk.js"
1
+ export * from './format.js'
2
+ export * from './fs.js'
3
+ export * from './glob.js'
4
+ export * from './readdir.js'
5
+ export * from './readfile.js'
6
+ export * from './stat.js'
7
+ export * from './sub.js'
8
+ export * from './walk.js'
@@ -1,22 +1,53 @@
1
- import * as $ from "@goscript/builtin/builtin.js";
2
- import { FormatDirEntry } from "./format.js";
3
- import { FS, DirEntry, ReadDirFile, PathError, FileInfo, FileMode, fileModeType } from "./fs.js";
4
-
5
- import * as errors from "@goscript/errors/index.js"
6
-
7
- import * as slices from "@goscript/slices/index.js"
8
-
9
- export type ReadDirFS = null | {
10
- // ReadDir reads the named directory
11
- // and returns a list of directory entries sorted by filename.
12
- ReadDir(name: string): [$.Slice<DirEntry>, $.GoError]
13
- } & FS
1
+ import * as $ from '@goscript/builtin/builtin.js'
2
+ import { FormatDirEntry } from './format.js'
3
+ import {
4
+ FS,
5
+ DirEntry,
6
+ ReadDirFile,
7
+ PathError,
8
+ FileInfo,
9
+ FileMode,
10
+ fileModeType,
11
+ } from './fs.js'
12
+
13
+ import * as errors from '@goscript/errors/index.js'
14
+
15
+ export type ReadDirFS =
16
+ | null
17
+ | ({
18
+ // ReadDir reads the named directory
19
+ // and returns a list of directory entries sorted by filename.
20
+ ReadDir(name: string): [$.Slice<DirEntry>, $.GoError]
21
+ } & FS)
14
22
 
15
23
  $.registerInterfaceType(
16
24
  'ReadDirFS',
17
25
  null, // Zero value for interface is null
18
- [{ name: "ReadDir", args: [{ name: "name", type: { kind: $.TypeKind.Basic, name: "string" } }], returns: [{ type: { kind: $.TypeKind.Slice, elemType: "DirEntry" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }]
19
- );
26
+ [
27
+ {
28
+ name: 'ReadDir',
29
+ args: [
30
+ { name: 'name', type: { kind: $.TypeKind.Basic, name: 'string' } },
31
+ ],
32
+ returns: [
33
+ { type: { kind: $.TypeKind.Slice, elemType: 'DirEntry' } },
34
+ {
35
+ type: {
36
+ kind: $.TypeKind.Interface,
37
+ name: 'GoError',
38
+ methods: [
39
+ {
40
+ name: 'Error',
41
+ args: [],
42
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
43
+ },
44
+ ],
45
+ },
46
+ },
47
+ ],
48
+ },
49
+ ],
50
+ )
20
51
 
21
52
  // ReadDir reads the named directory
22
53
  // and returns a list of directory entries sorted by filename.
@@ -24,103 +55,154 @@ $.registerInterfaceType(
24
55
  // If fs implements [ReadDirFS], ReadDir calls fs.ReadDir.
25
56
  // Otherwise ReadDir calls fs.Open and uses ReadDir and Close
26
57
  // on the returned file.
27
- export function ReadDir(fsys: FS, name: string): [$.Slice<DirEntry>, $.GoError] {
28
- using __defer = new $.DisposableStack();
29
- {
30
- let { value: fsysTyped, ok: ok } = $.typeAssert<ReadDirFS>(fsys, 'ReadDirFS')
31
- if (ok) {
32
- return fsysTyped!.ReadDir(name)
33
- }
34
- }
35
-
36
- let [file, err] = fsys!.Open(name)
37
- if (err != null) {
38
- return [null, err]
39
- }
40
- __defer.defer(() => {
41
- file!.Close()
42
- });
43
-
44
- let { value: dir, ok: ok } = $.typeAssert<ReadDirFile>(file, 'ReadDirFile')
45
- if (!ok) {
46
- return [null, new PathError({Err: errors.New("not implemented"), Op: "readdir", Path: name})]
47
- }
48
-
49
- let list: $.Slice<DirEntry>
50
- [list, err] = dir!.ReadDir(-1)
51
- list!.sort((a: DirEntry, b: DirEntry): number => {
52
- return a!.Name().localeCompare(b!.Name())
53
- })
54
- return [list, err]
58
+ export function ReadDir(
59
+ fsys: FS,
60
+ name: string,
61
+ ): [$.Slice<DirEntry>, $.GoError] {
62
+ using __defer = new $.DisposableStack()
63
+ {
64
+ let { value: fsysTyped, ok: ok } = $.typeAssert<ReadDirFS>(
65
+ fsys,
66
+ 'ReadDirFS',
67
+ )
68
+ if (ok) {
69
+ return fsysTyped!.ReadDir(name)
70
+ }
71
+ }
72
+
73
+ let [file, err] = fsys!.Open(name)
74
+ if (err != null) {
75
+ return [null, err]
76
+ }
77
+ __defer.defer(() => {
78
+ file!.Close()
79
+ })
80
+
81
+ let { value: dir, ok: ok } = $.typeAssert<ReadDirFile>(file, 'ReadDirFile')
82
+ if (!ok) {
83
+ return [
84
+ null,
85
+ new PathError({
86
+ Err: errors.New('not implemented'),
87
+ Op: 'readdir',
88
+ Path: name,
89
+ }),
90
+ ]
91
+ }
92
+
93
+ let list: $.Slice<DirEntry>
94
+ ;[list, err] = dir!.ReadDir(-1)
95
+ list!.sort((a: DirEntry, b: DirEntry): number => {
96
+ return a!.Name().localeCompare(b!.Name())
97
+ })
98
+ return [list, err]
55
99
  }
56
100
 
57
101
  class dirInfo {
58
- public get fileInfo(): FileInfo {
59
- return this._fields.fileInfo.value
60
- }
61
- public set fileInfo(value: FileInfo) {
62
- this._fields.fileInfo.value = value
63
- }
64
-
65
- public _fields: {
66
- fileInfo: $.VarRef<FileInfo>;
67
- }
68
-
69
- constructor(init?: Partial<{fileInfo?: FileInfo}>) {
70
- this._fields = {
71
- fileInfo: $.varRef(init?.fileInfo ?? null)
72
- }
73
- }
74
-
75
- public clone(): dirInfo {
76
- const cloned = new dirInfo()
77
- cloned._fields = {
78
- fileInfo: $.varRef(this._fields.fileInfo.value)
79
- }
80
- return cloned
81
- }
82
-
83
- public IsDir(): boolean {
84
- const di = this
85
- return di.fileInfo!.IsDir()
86
- }
87
-
88
- public Type(): FileMode {
89
- const di = this
90
- return fileModeType(di.fileInfo!.Mode())
91
- }
92
-
93
- public Info(): [FileInfo, $.GoError] {
94
- const di = this
95
- return [di.fileInfo, null]
96
- }
97
-
98
- public Name(): string {
99
- const di = this
100
- return di.fileInfo!.Name()
101
- }
102
-
103
- public String(): string {
104
- const di = this
105
- return FormatDirEntry(di)
106
- }
107
-
108
- // Register this type with the runtime type system
109
- static __typeInfo = $.registerStructType(
110
- 'dirInfo',
111
- new dirInfo(),
112
- [{ name: "IsDir", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "Type", args: [], returns: [{ type: "FileMode" }] }, { name: "Info", args: [], returns: [{ type: "FileInfo" }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Name", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "String", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }],
113
- dirInfo,
114
- {"fileInfo": "FileInfo"}
115
- );
102
+ public get fileInfo(): FileInfo {
103
+ return this._fields.fileInfo.value
104
+ }
105
+ public set fileInfo(value: FileInfo) {
106
+ this._fields.fileInfo.value = value
107
+ }
108
+
109
+ public _fields: {
110
+ fileInfo: $.VarRef<FileInfo>
111
+ }
112
+
113
+ constructor(init?: Partial<{ fileInfo?: FileInfo }>) {
114
+ this._fields = {
115
+ fileInfo: $.varRef(init?.fileInfo ?? null),
116
+ }
117
+ }
118
+
119
+ public clone(): dirInfo {
120
+ const cloned = new dirInfo()
121
+ cloned._fields = {
122
+ fileInfo: $.varRef(this._fields.fileInfo.value),
123
+ }
124
+ return cloned
125
+ }
126
+
127
+ public IsDir(): boolean {
128
+ const di = this
129
+ return di.fileInfo!.IsDir()
130
+ }
131
+
132
+ public Type(): FileMode {
133
+ const di = this
134
+ return fileModeType(di.fileInfo!.Mode())
135
+ }
136
+
137
+ public Info(): [FileInfo, $.GoError] {
138
+ const di = this
139
+ return [di.fileInfo, null]
140
+ }
141
+
142
+ public Name(): string {
143
+ const di = this
144
+ return di.fileInfo!.Name()
145
+ }
146
+
147
+ public String(): string {
148
+ const di = this
149
+ return FormatDirEntry(di)
150
+ }
151
+
152
+ // Register this type with the runtime type system
153
+ static __typeInfo = $.registerStructType(
154
+ 'dirInfo',
155
+ new dirInfo(),
156
+ [
157
+ {
158
+ name: 'IsDir',
159
+ args: [],
160
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'boolean' } }],
161
+ },
162
+ { name: 'Type', args: [], returns: [{ type: 'FileMode' }] },
163
+ {
164
+ name: 'Info',
165
+ args: [],
166
+ returns: [
167
+ { type: 'FileInfo' },
168
+ {
169
+ type: {
170
+ kind: $.TypeKind.Interface,
171
+ name: 'GoError',
172
+ methods: [
173
+ {
174
+ name: 'Error',
175
+ args: [],
176
+ returns: [
177
+ { type: { kind: $.TypeKind.Basic, name: 'string' } },
178
+ ],
179
+ },
180
+ ],
181
+ },
182
+ },
183
+ ],
184
+ },
185
+ {
186
+ name: 'Name',
187
+ args: [],
188
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
189
+ },
190
+ {
191
+ name: 'String',
192
+ args: [],
193
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
194
+ },
195
+ ],
196
+ dirInfo,
197
+ { fileInfo: 'FileInfo' },
198
+ )
116
199
  }
117
200
 
118
201
  // FileInfoToDirEntry returns a [DirEntry] that returns information from info.
119
202
  // If info is nil, FileInfoToDirEntry returns nil.
120
203
  export function FileInfoToDirEntry(info: FileInfo): DirEntry {
121
- if (info == null) {
122
- return null
123
- }
124
- return new dirInfo({fileInfo: info})
204
+ if (info == null) {
205
+ return null
206
+ }
207
+ return new dirInfo({ fileInfo: info })
125
208
  }
126
-