goscript 0.0.37 → 0.0.39

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 (198) hide show
  1. package/compiler/analysis.go +129 -8
  2. package/compiler/compiler.go +4 -1
  3. package/compiler/composite-lit.go +2 -4
  4. package/compiler/expr-call.go +12 -0
  5. package/compiler/lit.go +100 -6
  6. package/compiler/protobuf.go +2 -2
  7. package/compiler/spec-value.go +3 -3
  8. package/compiler/spec.go +6 -3
  9. package/compiler/stmt-assign.go +1 -1
  10. package/dist/gs/builtin/builtin.d.ts +45 -0
  11. package/dist/gs/builtin/builtin.js +197 -0
  12. package/dist/gs/builtin/builtin.js.map +1 -1
  13. package/dist/gs/builtin/slice.js +2 -1
  14. package/dist/gs/builtin/slice.js.map +1 -1
  15. package/dist/gs/bytes/buffer.gs.d.ts +56 -0
  16. package/dist/gs/bytes/buffer.gs.js +611 -0
  17. package/dist/gs/bytes/buffer.gs.js.map +1 -0
  18. package/dist/gs/bytes/bytes.gs.d.ts +78 -0
  19. package/dist/gs/bytes/bytes.gs.js +1011 -0
  20. package/dist/gs/bytes/bytes.gs.js.map +1 -0
  21. package/dist/gs/bytes/index.d.ts +4 -0
  22. package/dist/gs/bytes/index.js +5 -0
  23. package/dist/gs/bytes/index.js.map +1 -0
  24. package/dist/gs/bytes/iter.gs.d.ts +9 -0
  25. package/dist/gs/bytes/iter.gs.js +143 -0
  26. package/dist/gs/bytes/iter.gs.js.map +1 -0
  27. package/dist/gs/bytes/reader.gs.d.ts +34 -0
  28. package/dist/gs/bytes/reader.gs.js +198 -0
  29. package/dist/gs/bytes/reader.gs.js.map +1 -0
  30. package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
  31. package/dist/gs/github.com/pkg/errors/errors.js +182 -23
  32. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
  33. package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
  34. package/dist/gs/github.com/pkg/errors/go113.js +1 -1
  35. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
  36. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
  37. package/dist/gs/github.com/pkg/errors/index.js +3 -3
  38. package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
  39. package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
  40. package/dist/gs/github.com/pkg/errors/stack.js +8 -5
  41. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
  42. package/dist/gs/internal/abi/index.d.ts +20 -0
  43. package/dist/gs/internal/abi/index.js +20 -0
  44. package/dist/gs/internal/abi/index.js.map +1 -0
  45. package/dist/gs/internal/bytealg/index.d.ts +14 -0
  46. package/dist/gs/internal/bytealg/index.js +139 -0
  47. package/dist/gs/internal/bytealg/index.js.map +1 -0
  48. package/dist/gs/internal/byteorder/index.d.ts +1 -1
  49. package/dist/gs/internal/byteorder/index.js +4 -4
  50. package/dist/gs/internal/byteorder/index.js.map +1 -1
  51. package/dist/gs/math/index.d.ts +44 -44
  52. package/dist/gs/math/index.js +44 -44
  53. package/dist/gs/math/index.js.map +1 -1
  54. package/dist/gs/os/index.d.ts +19 -19
  55. package/dist/gs/os/index.js +19 -19
  56. package/dist/gs/os/index.js.map +1 -1
  57. package/dist/gs/reflect/deepequal.d.ts +2 -0
  58. package/dist/gs/reflect/deepequal.js +91 -0
  59. package/dist/gs/reflect/deepequal.js.map +1 -0
  60. package/dist/gs/reflect/index.d.ts +8 -0
  61. package/dist/gs/reflect/index.js +10 -0
  62. package/dist/gs/reflect/index.js.map +1 -0
  63. package/dist/gs/reflect/iter.d.ts +4 -0
  64. package/dist/gs/reflect/iter.js +24 -0
  65. package/dist/gs/reflect/iter.js.map +1 -0
  66. package/dist/gs/reflect/map.d.ts +20 -0
  67. package/dist/gs/reflect/map.js +74 -0
  68. package/dist/gs/reflect/map.js.map +1 -0
  69. package/dist/gs/reflect/swapper.d.ts +2 -0
  70. package/dist/gs/reflect/swapper.js +46 -0
  71. package/dist/gs/reflect/swapper.js.map +1 -0
  72. package/dist/gs/reflect/type.d.ts +134 -0
  73. package/dist/gs/reflect/type.js +825 -0
  74. package/dist/gs/reflect/type.js.map +1 -0
  75. package/dist/gs/reflect/types.d.ts +90 -0
  76. package/dist/gs/reflect/types.js +119 -0
  77. package/dist/gs/reflect/types.js.map +1 -0
  78. package/dist/gs/reflect/value.d.ts +13 -0
  79. package/dist/gs/reflect/value.js +202 -0
  80. package/dist/gs/reflect/value.js.map +1 -0
  81. package/dist/gs/reflect/visiblefields.d.ts +4 -0
  82. package/dist/gs/reflect/visiblefields.js +149 -0
  83. package/dist/gs/reflect/visiblefields.js.map +1 -0
  84. package/dist/gs/strconv/index.d.ts +6 -6
  85. package/dist/gs/strconv/index.js +6 -6
  86. package/dist/gs/strconv/index.js.map +1 -1
  87. package/dist/gs/strings/index.d.ts +1 -1
  88. package/dist/gs/strings/index.js +1 -1
  89. package/dist/gs/strings/index.js.map +1 -1
  90. package/dist/gs/strings/replace.js.map +1 -1
  91. package/dist/gs/sync/atomic/index.d.ts +4 -4
  92. package/dist/gs/sync/atomic/index.js +4 -4
  93. package/dist/gs/sync/atomic/index.js.map +1 -1
  94. package/dist/gs/syscall/index.d.ts +6 -6
  95. package/dist/gs/syscall/index.js +34 -28
  96. package/dist/gs/syscall/index.js.map +1 -1
  97. package/dist/gs/unicode/utf8/utf8.d.ts +1 -1
  98. package/dist/gs/unicode/utf8/utf8.js +4 -2
  99. package/dist/gs/unicode/utf8/utf8.js.map +1 -1
  100. package/dist/gs/unsafe/unsafe.js.map +1 -1
  101. package/gs/builtin/builtin.ts +219 -0
  102. package/gs/builtin/slice.ts +2 -1
  103. package/gs/bytes/buffer.gs.ts +614 -0
  104. package/gs/bytes/bytes.gs.ts +1180 -0
  105. package/gs/bytes/godoc.txt +69 -0
  106. package/gs/bytes/index.ts +69 -0
  107. package/gs/bytes/iter.gs.ts +149 -0
  108. package/gs/bytes/reader.gs.ts +230 -0
  109. package/gs/github.com/pkg/errors/errors.ts +408 -238
  110. package/gs/github.com/pkg/errors/go113.ts +5 -6
  111. package/gs/github.com/pkg/errors/index.ts +12 -3
  112. package/gs/github.com/pkg/errors/stack.ts +107 -105
  113. package/gs/internal/abi/index.ts +37 -0
  114. package/gs/internal/bytealg/index.ts +149 -0
  115. package/gs/internal/byteorder/index.ts +5 -5
  116. package/gs/math/abs.gs.test.ts +1 -1
  117. package/gs/math/acosh.gs.test.ts +4 -2
  118. package/gs/math/asin.gs.test.ts +1 -1
  119. package/gs/math/asinh.gs.test.ts +7 -3
  120. package/gs/math/atan.gs.test.ts +1 -1
  121. package/gs/math/atan2.gs.test.ts +17 -9
  122. package/gs/math/atanh.gs.test.ts +1 -1
  123. package/gs/math/bits.gs.test.ts +1 -1
  124. package/gs/math/cbrt.gs.test.ts +1 -1
  125. package/gs/math/const.gs.test.ts +34 -8
  126. package/gs/math/copysign.gs.test.ts +7 -3
  127. package/gs/math/dim.gs.test.ts +19 -7
  128. package/gs/math/erf.gs.test.ts +1 -1
  129. package/gs/math/erfinv.gs.test.ts +4 -2
  130. package/gs/math/exp.gs.test.ts +1 -1
  131. package/gs/math/expm1.gs.test.ts +6 -4
  132. package/gs/math/floor.gs.test.ts +17 -4
  133. package/gs/math/fma.gs.test.ts +53 -53
  134. package/gs/math/frexp.gs.test.ts +112 -117
  135. package/gs/math/gamma.gs.test.ts +1 -1
  136. package/gs/math/hypot.gs.test.ts +53 -53
  137. package/gs/math/index.ts +80 -44
  138. package/gs/math/j0.gs.test.ts +6 -2
  139. package/gs/math/j1.gs.test.ts +6 -2
  140. package/gs/math/jn.gs.test.ts +9 -5
  141. package/gs/math/ldexp.gs.test.ts +103 -86
  142. package/gs/math/lgamma.gs.test.ts +10 -10
  143. package/gs/math/log.gs.test.ts +1 -1
  144. package/gs/math/log10.gs.test.ts +1 -1
  145. package/gs/math/log1p.gs.test.ts +2 -2
  146. package/gs/math/logb.gs.test.ts +1 -1
  147. package/gs/math/mod.gs.test.ts +2 -2
  148. package/gs/math/modf.gs.test.ts +7 -7
  149. package/gs/math/nextafter.gs.test.ts +9 -7
  150. package/gs/math/pow.gs.test.ts +6 -4
  151. package/gs/math/pow10.gs.test.ts +1 -1
  152. package/gs/math/remainder.gs.test.ts +1 -1
  153. package/gs/math/signbit.gs.test.ts +1 -1
  154. package/gs/math/sin.gs.test.ts +1 -1
  155. package/gs/math/sincos.gs.test.ts +33 -14
  156. package/gs/math/sinh.gs.test.ts +1 -1
  157. package/gs/math/sqrt.gs.test.ts +1 -1
  158. package/gs/math/tan.gs.test.ts +3 -3
  159. package/gs/math/tanh.gs.test.ts +1 -1
  160. package/gs/os/index.ts +128 -19
  161. package/gs/reflect/ANALYSIS.md +278 -0
  162. package/gs/reflect/deepequal.test.ts +41 -0
  163. package/gs/reflect/deepequal.ts +169 -0
  164. package/gs/reflect/function-types.test.ts +146 -0
  165. package/gs/reflect/godoc.txt +67 -0
  166. package/gs/reflect/index.ts +83 -0
  167. package/gs/reflect/iter.ts +44 -0
  168. package/gs/reflect/map.test.ts +30 -0
  169. package/gs/reflect/map.ts +85 -0
  170. package/gs/reflect/swapper.ts +52 -0
  171. package/gs/reflect/type.ts +1016 -0
  172. package/gs/reflect/types.ts +214 -0
  173. package/gs/reflect/value.ts +270 -0
  174. package/gs/reflect/visiblefields.ts +177 -0
  175. package/gs/strconv/index.ts +39 -6
  176. package/gs/strings/index.ts +7 -1
  177. package/gs/strings/replace.ts +1 -9
  178. package/gs/sync/atomic/index.ts +53 -4
  179. package/gs/syscall/index.ts +45 -37
  180. package/gs/unicode/utf8/utf8.ts +8 -5
  181. package/gs/unsafe/unsafe.ts +1 -1
  182. package/package.json +2 -1
  183. package/dist/gs/internal/testlog/index.d.ts +0 -1
  184. package/dist/gs/internal/testlog/index.js +0 -5
  185. package/dist/gs/internal/testlog/index.js.map +0 -1
  186. package/dist/gs/maps/iter.gs.d.ts +0 -7
  187. package/dist/gs/maps/iter.gs.js +0 -65
  188. package/dist/gs/maps/iter.gs.js.map +0 -1
  189. package/dist/gs/maps/maps.gs.d.ts +0 -7
  190. package/dist/gs/maps/maps.gs.js +0 -79
  191. package/dist/gs/maps/maps.gs.js.map +0 -1
  192. package/dist/gs/stringslite/index.d.ts +0 -1
  193. package/dist/gs/stringslite/index.js +0 -2
  194. package/dist/gs/stringslite/index.js.map +0 -1
  195. package/dist/gs/stringslite/strings.d.ts +0 -11
  196. package/dist/gs/stringslite/strings.js +0 -67
  197. package/dist/gs/stringslite/strings.js.map +0 -1
  198. package/gs/internal/testlog/index.ts +0 -7
@@ -1,276 +1,425 @@
1
- import * as $ from "../../../builtin/builtin.js";
2
- import { callers } from "./stack.js";
1
+ import * as $ from '../../../builtin/builtin.js'
2
+ import { callers } from './stack.js'
3
3
 
4
4
  // Type definitions
5
- export type Frame = any; // Simplified frame type
6
- export type StackTrace = Frame[] | null;
7
- export type stack = any; // Simplified stack type
8
- export type uintptr = number;
5
+ export type Frame = any // Simplified frame type
6
+ export type StackTrace = Frame[] | null
7
+ export type stack = any // Simplified stack type
8
+ export type uintptr = number
9
9
 
10
10
  // Simplified fmt functions for basic string formatting
11
11
  const fmt = {
12
12
  Sprintf: (format: string, ...args: any[]): string => {
13
13
  // Basic sprintf implementation for the errors package
14
- let result = format;
15
- let argIndex = 0;
14
+ let result = format
15
+ let argIndex = 0
16
16
  result = result.replace(/%[sdqv%]/g, (match) => {
17
- if (match === '%%') return '%';
18
- if (argIndex >= args.length) return match;
19
- const arg = args[argIndex++];
17
+ if (match === '%%') return '%'
18
+ if (argIndex >= args.length) return match
19
+ const arg = args[argIndex++]
20
20
  switch (match) {
21
- case '%s': return String(arg);
22
- case '%d': return String(Number(arg));
23
- case '%q': return JSON.stringify(String(arg));
24
- case '%v': return String(arg);
25
- default: return match;
21
+ case '%s':
22
+ return String(arg)
23
+ case '%d':
24
+ return String(Number(arg))
25
+ case '%q':
26
+ return JSON.stringify(String(arg))
27
+ case '%v':
28
+ return String(arg)
29
+ default:
30
+ return match
26
31
  }
27
- });
28
- return result;
29
- }
30
- };
32
+ })
33
+ return result
34
+ },
35
+ }
31
36
 
32
37
  // New returns an error with the supplied message.
33
38
  // New also records the stack trace at the point it was called.
34
39
  export function New(message: string): $.GoError {
35
- return new fundamental({msg: message, stack: callers()})
40
+ return new fundamental({ msg: message, stack: callers() })
36
41
  }
37
42
 
38
43
  // Errorf formats according to a format specifier and returns the string
39
44
  // as a value that satisfies error.
40
45
  // Errorf also records the stack trace at the point it was called.
41
46
  export function Errorf(format: string, ...args: any[]): $.GoError {
42
- return new fundamental({msg: fmt.Sprintf(format, ...args), stack: callers()})
47
+ return new fundamental({
48
+ msg: fmt.Sprintf(format, ...args),
49
+ stack: callers(),
50
+ })
43
51
  }
44
52
 
45
53
  class fundamental {
46
- public get msg(): string {
47
- return this._fields.msg.value
48
- }
49
- public set msg(value: string) {
50
- this._fields.msg.value = value
51
- }
52
-
53
- public get stack(): $.VarRef<stack> | null {
54
- return this._fields.stack.value
55
- }
56
- public set stack(value: $.VarRef<stack> | null) {
57
- this._fields.stack.value = value
58
- }
59
-
60
- public _fields: {
61
- msg: $.VarRef<string>;
62
- stack: $.VarRef<$.VarRef<stack> | null>;
63
- }
64
-
65
- constructor(init?: Partial<{msg?: string, stack?: $.VarRef<stack> | null}>) {
66
- this._fields = {
67
- msg: $.varRef(init?.msg ?? ""),
68
- stack: $.varRef(init?.stack ?? null)
69
- }
70
- }
71
-
72
- public clone(): fundamental {
73
- const cloned = new fundamental()
74
- cloned._fields = {
75
- msg: $.varRef(this._fields.msg.value),
76
- stack: $.varRef(this._fields.stack.value)
77
- }
78
- return cloned
79
- }
80
-
81
- public Error(): string {
82
- const f = this
83
- return f!.msg
84
- }
85
-
86
- public StackTrace(): StackTrace {
87
- return null; // Simplified - no stack trace for now
88
- }
89
-
90
- // Register this type with the runtime type system
91
- static __typeInfo = $.registerStructType(
92
- 'fundamental',
93
- new fundamental(),
94
- [{ name: "Error", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }],
95
- fundamental,
96
- {"msg": { kind: $.TypeKind.Basic, name: "string" }, "stack": { kind: $.TypeKind.Pointer, elemType: "stack" }}
97
- );
54
+ public get msg(): string {
55
+ return this._fields.msg.value
56
+ }
57
+ public set msg(value: string) {
58
+ this._fields.msg.value = value
59
+ }
60
+
61
+ public get stack(): $.VarRef<stack> | null {
62
+ return this._fields.stack.value
63
+ }
64
+ public set stack(value: $.VarRef<stack> | null) {
65
+ this._fields.stack.value = value
66
+ }
67
+
68
+ public _fields: {
69
+ msg: $.VarRef<string>
70
+ stack: $.VarRef<$.VarRef<stack> | null>
71
+ }
72
+
73
+ constructor(
74
+ init?: Partial<{ msg?: string; stack?: $.VarRef<stack> | null }>,
75
+ ) {
76
+ this._fields = {
77
+ msg: $.varRef(init?.msg ?? ''),
78
+ stack: $.varRef(init?.stack ?? null),
79
+ }
80
+ }
81
+
82
+ public clone(): fundamental {
83
+ const cloned = new fundamental()
84
+ cloned._fields = {
85
+ msg: $.varRef(this._fields.msg.value),
86
+ stack: $.varRef(this._fields.stack.value),
87
+ }
88
+ return cloned
89
+ }
90
+
91
+ public Error(): string {
92
+ const f = this
93
+ return f!.msg
94
+ }
95
+
96
+ public StackTrace(): StackTrace {
97
+ return null // Simplified - no stack trace for now
98
+ }
99
+
100
+ // Register this type with the runtime type system
101
+ static __typeInfo = $.registerStructType(
102
+ 'fundamental',
103
+ new fundamental(),
104
+ [
105
+ {
106
+ name: 'Error',
107
+ args: [],
108
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
109
+ },
110
+ ],
111
+ fundamental,
112
+ {
113
+ msg: { kind: $.TypeKind.Basic, name: 'string' },
114
+ stack: { kind: $.TypeKind.Pointer, elemType: 'stack' },
115
+ },
116
+ )
98
117
  }
99
118
 
100
119
  // WithStack annotates err with a stack trace at the point WithStack was called.
101
120
  // If err is nil, WithStack returns nil.
102
121
  export function WithStack(err: $.GoError): $.GoError {
103
- if (err == null) {
104
- return null
105
- }
106
- return new withStack({error: err, stack: callers()})
122
+ if (err == null) {
123
+ return null
124
+ }
125
+ return new withStack({ error: err, stack: callers() })
107
126
  }
108
127
 
109
128
  class withStack {
110
- public get error(): $.GoError {
111
- return this._fields.error.value
112
- }
113
- public set error(value: $.GoError) {
114
- this._fields.error.value = value
115
- }
116
-
117
- public get stack(): $.VarRef<stack> | null {
118
- return this._fields.stack.value
119
- }
120
- public set stack(value: $.VarRef<stack> | null) {
121
- this._fields.stack.value = value
122
- }
123
-
124
- public _fields: {
125
- error: $.VarRef<$.GoError>;
126
- stack: $.VarRef<$.VarRef<stack> | null>;
127
- }
128
-
129
- constructor(init?: Partial<{error?: $.GoError, stack?: $.VarRef<stack> | null}>) {
130
- this._fields = {
131
- error: $.varRef(init?.error ?? null),
132
- stack: $.varRef(init?.stack ?? null)
133
- }
134
- }
135
-
136
- public clone(): withStack {
137
- const cloned = new withStack()
138
- cloned._fields = {
139
- error: $.varRef(this._fields.error.value),
140
- stack: $.varRef(this._fields.stack.value)
141
- }
142
- return cloned
143
- }
144
-
145
- public Cause(): $.GoError {
146
- const w = this
147
- return w!.error
148
- }
149
-
150
- // Unwrap provides compatibility for Go 1.13 error chains.
151
- public Unwrap(): $.GoError {
152
- const w = this
153
- return w!.error
154
- }
155
-
156
- public Error(): string {
157
- return this.error?.Error() ?? ""
158
- }
159
-
160
- public StackTrace(): StackTrace {
161
- return null; // Simplified - no stack trace for now
162
- }
163
-
164
- // Register this type with the runtime type system
165
- static __typeInfo = $.registerStructType(
166
- 'withStack',
167
- new withStack(),
168
- [{ name: "Cause", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ 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' } }] }] } }] }],
169
- withStack,
170
- {"error": { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] }, "stack": { kind: $.TypeKind.Pointer, elemType: "stack" }}
171
- );
129
+ public get error(): $.GoError {
130
+ return this._fields.error.value
131
+ }
132
+ public set error(value: $.GoError) {
133
+ this._fields.error.value = value
134
+ }
135
+
136
+ public get stack(): $.VarRef<stack> | null {
137
+ return this._fields.stack.value
138
+ }
139
+ public set stack(value: $.VarRef<stack> | null) {
140
+ this._fields.stack.value = value
141
+ }
142
+
143
+ public _fields: {
144
+ error: $.VarRef<$.GoError>
145
+ stack: $.VarRef<$.VarRef<stack> | null>
146
+ }
147
+
148
+ constructor(
149
+ init?: Partial<{ error?: $.GoError; stack?: $.VarRef<stack> | null }>,
150
+ ) {
151
+ this._fields = {
152
+ error: $.varRef(init?.error ?? null),
153
+ stack: $.varRef(init?.stack ?? null),
154
+ }
155
+ }
156
+
157
+ public clone(): withStack {
158
+ const cloned = new withStack()
159
+ cloned._fields = {
160
+ error: $.varRef(this._fields.error.value),
161
+ stack: $.varRef(this._fields.stack.value),
162
+ }
163
+ return cloned
164
+ }
165
+
166
+ public Cause(): $.GoError {
167
+ const w = this
168
+ return w!.error
169
+ }
170
+
171
+ // Unwrap provides compatibility for Go 1.13 error chains.
172
+ public Unwrap(): $.GoError {
173
+ const w = this
174
+ return w!.error
175
+ }
176
+
177
+ public Error(): string {
178
+ return this.error?.Error() ?? ''
179
+ }
180
+
181
+ public StackTrace(): StackTrace {
182
+ return null // Simplified - no stack trace for now
183
+ }
184
+
185
+ // Register this type with the runtime type system
186
+ static __typeInfo = $.registerStructType(
187
+ 'withStack',
188
+ new withStack(),
189
+ [
190
+ {
191
+ name: 'Cause',
192
+ args: [],
193
+ returns: [
194
+ {
195
+ type: {
196
+ kind: $.TypeKind.Interface,
197
+ name: 'GoError',
198
+ methods: [
199
+ {
200
+ name: 'Error',
201
+ args: [],
202
+ returns: [
203
+ { type: { kind: $.TypeKind.Basic, name: 'string' } },
204
+ ],
205
+ },
206
+ ],
207
+ },
208
+ },
209
+ ],
210
+ },
211
+ {
212
+ name: 'Unwrap',
213
+ args: [],
214
+ returns: [
215
+ {
216
+ type: {
217
+ kind: $.TypeKind.Interface,
218
+ name: 'GoError',
219
+ methods: [
220
+ {
221
+ name: 'Error',
222
+ args: [],
223
+ returns: [
224
+ { type: { kind: $.TypeKind.Basic, name: 'string' } },
225
+ ],
226
+ },
227
+ ],
228
+ },
229
+ },
230
+ ],
231
+ },
232
+ ],
233
+ withStack,
234
+ {
235
+ error: {
236
+ kind: $.TypeKind.Interface,
237
+ name: 'GoError',
238
+ methods: [
239
+ {
240
+ name: 'Error',
241
+ args: [],
242
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
243
+ },
244
+ ],
245
+ },
246
+ stack: { kind: $.TypeKind.Pointer, elemType: 'stack' },
247
+ },
248
+ )
172
249
  }
173
250
 
174
251
  // Wrap returns an error annotating err with a stack trace
175
252
  // at the point Wrap is called, and the supplied message.
176
253
  // If err is nil, Wrap returns nil.
177
254
  export function Wrap(err: $.GoError, message: string): $.GoError {
178
- if (err == null) {
179
- return null
180
- }
181
- const wrappedErr = new withMessage({cause: err, msg: message})
182
- return new withStack({error: wrappedErr, stack: callers()})
255
+ if (err == null) {
256
+ return null
257
+ }
258
+ const wrappedErr = new withMessage({ cause: err, msg: message })
259
+ return new withStack({ error: wrappedErr, stack: callers() })
183
260
  }
184
261
 
185
262
  // Wrapf returns an error annotating err with a stack trace
186
263
  // at the point Wrapf is called, and the format specifier.
187
264
  // If err is nil, Wrapf returns nil.
188
- export function Wrapf(err: $.GoError, format: string, ...args: any[]): $.GoError {
189
- if (err == null) {
190
- return null
191
- }
192
- const wrappedErr = new withMessage({cause: err, msg: fmt.Sprintf(format, ...args)})
193
- return new withStack({error: wrappedErr, stack: callers()})
265
+ export function Wrapf(
266
+ err: $.GoError,
267
+ format: string,
268
+ ...args: any[]
269
+ ): $.GoError {
270
+ if (err == null) {
271
+ return null
272
+ }
273
+ const wrappedErr = new withMessage({
274
+ cause: err,
275
+ msg: fmt.Sprintf(format, ...args),
276
+ })
277
+ return new withStack({ error: wrappedErr, stack: callers() })
194
278
  }
195
279
 
196
280
  // WithMessage annotates err with a new message.
197
281
  // If err is nil, WithMessage returns nil.
198
282
  export function WithMessage(err: $.GoError, message: string): $.GoError {
199
- if (err == null) {
200
- return null
201
- }
202
- return new withMessage({cause: err, msg: message})
283
+ if (err == null) {
284
+ return null
285
+ }
286
+ return new withMessage({ cause: err, msg: message })
203
287
  }
204
288
 
205
289
  // WithMessagef annotates err with the format specifier.
206
290
  // If err is nil, WithMessagef returns nil.
207
- export function WithMessagef(err: $.GoError, format: string, ...args: any[]): $.GoError {
208
- if (err == null) {
209
- return null
210
- }
211
- return new withMessage({cause: err, msg: fmt.Sprintf(format, ...args)})
291
+ export function WithMessagef(
292
+ err: $.GoError,
293
+ format: string,
294
+ ...args: any[]
295
+ ): $.GoError {
296
+ if (err == null) {
297
+ return null
298
+ }
299
+ return new withMessage({ cause: err, msg: fmt.Sprintf(format, ...args) })
212
300
  }
213
301
 
214
302
  class withMessage {
215
- public get cause(): $.GoError {
216
- return this._fields.cause.value
217
- }
218
- public set cause(value: $.GoError) {
219
- this._fields.cause.value = value
220
- }
221
-
222
- public get msg(): string {
223
- return this._fields.msg.value
224
- }
225
- public set msg(value: string) {
226
- this._fields.msg.value = value
227
- }
228
-
229
- public _fields: {
230
- cause: $.VarRef<$.GoError>;
231
- msg: $.VarRef<string>;
232
- }
233
-
234
- constructor(init?: Partial<{cause?: $.GoError, msg?: string}>) {
235
- this._fields = {
236
- cause: $.varRef(init?.cause ?? null),
237
- msg: $.varRef(init?.msg ?? "")
238
- }
239
- }
240
-
241
- public clone(): withMessage {
242
- const cloned = new withMessage()
243
- cloned._fields = {
244
- cause: $.varRef(this._fields.cause.value),
245
- msg: $.varRef(this._fields.msg.value)
246
- }
247
- return cloned
248
- }
249
-
250
- public Error(): string {
251
- const w = this
252
- return w!.msg + ": " + w!.cause!.Error()
253
- }
254
-
255
- public Cause(): $.GoError {
256
- const w = this
257
- return w!.cause
258
- }
259
-
260
- // Unwrap provides compatibility for Go 1.13 error chains.
261
- public Unwrap(): $.GoError {
262
- const w = this
263
- return w!.cause
264
- }
265
-
266
- // Register this type with the runtime type system
267
- static __typeInfo = $.registerStructType(
268
- 'withMessage',
269
- new withMessage(),
270
- [{ name: "Error", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "Cause", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ 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' } }] }] } }] }],
271
- withMessage,
272
- {"cause": { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] }, "msg": { kind: $.TypeKind.Basic, name: "string" }}
273
- );
303
+ public get cause(): $.GoError {
304
+ return this._fields.cause.value
305
+ }
306
+ public set cause(value: $.GoError) {
307
+ this._fields.cause.value = value
308
+ }
309
+
310
+ public get msg(): string {
311
+ return this._fields.msg.value
312
+ }
313
+ public set msg(value: string) {
314
+ this._fields.msg.value = value
315
+ }
316
+
317
+ public _fields: {
318
+ cause: $.VarRef<$.GoError>
319
+ msg: $.VarRef<string>
320
+ }
321
+
322
+ constructor(init?: Partial<{ cause?: $.GoError; msg?: string }>) {
323
+ this._fields = {
324
+ cause: $.varRef(init?.cause ?? null),
325
+ msg: $.varRef(init?.msg ?? ''),
326
+ }
327
+ }
328
+
329
+ public clone(): withMessage {
330
+ const cloned = new withMessage()
331
+ cloned._fields = {
332
+ cause: $.varRef(this._fields.cause.value),
333
+ msg: $.varRef(this._fields.msg.value),
334
+ }
335
+ return cloned
336
+ }
337
+
338
+ public Error(): string {
339
+ const w = this
340
+ return w!.msg + ': ' + w!.cause!.Error()
341
+ }
342
+
343
+ public Cause(): $.GoError {
344
+ const w = this
345
+ return w!.cause
346
+ }
347
+
348
+ // Unwrap provides compatibility for Go 1.13 error chains.
349
+ public Unwrap(): $.GoError {
350
+ const w = this
351
+ return w!.cause
352
+ }
353
+
354
+ // Register this type with the runtime type system
355
+ static __typeInfo = $.registerStructType(
356
+ 'withMessage',
357
+ new withMessage(),
358
+ [
359
+ {
360
+ name: 'Error',
361
+ args: [],
362
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
363
+ },
364
+ {
365
+ name: 'Cause',
366
+ args: [],
367
+ returns: [
368
+ {
369
+ type: {
370
+ kind: $.TypeKind.Interface,
371
+ name: 'GoError',
372
+ methods: [
373
+ {
374
+ name: 'Error',
375
+ args: [],
376
+ returns: [
377
+ { type: { kind: $.TypeKind.Basic, name: 'string' } },
378
+ ],
379
+ },
380
+ ],
381
+ },
382
+ },
383
+ ],
384
+ },
385
+ {
386
+ name: 'Unwrap',
387
+ args: [],
388
+ returns: [
389
+ {
390
+ type: {
391
+ kind: $.TypeKind.Interface,
392
+ name: 'GoError',
393
+ methods: [
394
+ {
395
+ name: 'Error',
396
+ args: [],
397
+ returns: [
398
+ { type: { kind: $.TypeKind.Basic, name: 'string' } },
399
+ ],
400
+ },
401
+ ],
402
+ },
403
+ },
404
+ ],
405
+ },
406
+ ],
407
+ withMessage,
408
+ {
409
+ cause: {
410
+ kind: $.TypeKind.Interface,
411
+ name: 'GoError',
412
+ methods: [
413
+ {
414
+ name: 'Error',
415
+ args: [],
416
+ returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
417
+ },
418
+ ],
419
+ },
420
+ msg: { kind: $.TypeKind.Basic, name: 'string' },
421
+ },
422
+ )
274
423
  }
275
424
 
276
425
  // Cause returns the underlying cause of the error, if possible.
@@ -285,23 +434,44 @@ class withMessage {
285
434
  // be returned. If the error is nil, nil will be returned without further
286
435
  // investigation.
287
436
  export function Cause(err: $.GoError): $.GoError {
288
- type causer = null | {
289
- Cause(): $.GoError
290
- }
291
-
292
- $.registerInterfaceType(
293
- 'causer',
294
- null, // Zero value for interface is null
295
- [{ name: "Cause", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }]
296
- );
297
-
298
- for (; err != null; ) {
299
- let { value: cause, ok: ok } = $.typeAssert<causer>(err, 'causer')
300
- if (!ok) {
301
- break
302
- }
303
- err = cause!.Cause()
304
- }
305
- return err
306
- }
437
+ type causer = null | {
438
+ Cause(): $.GoError
439
+ }
307
440
 
441
+ $.registerInterfaceType(
442
+ 'causer',
443
+ null, // Zero value for interface is null
444
+ [
445
+ {
446
+ name: 'Cause',
447
+ args: [],
448
+ returns: [
449
+ {
450
+ type: {
451
+ kind: $.TypeKind.Interface,
452
+ name: 'GoError',
453
+ methods: [
454
+ {
455
+ name: 'Error',
456
+ args: [],
457
+ returns: [
458
+ { type: { kind: $.TypeKind.Basic, name: 'string' } },
459
+ ],
460
+ },
461
+ ],
462
+ },
463
+ },
464
+ ],
465
+ },
466
+ ],
467
+ )
468
+
469
+ for (; err != null; ) {
470
+ let { value: cause, ok: ok } = $.typeAssert<causer>(err, 'causer')
471
+ if (!ok) {
472
+ break
473
+ }
474
+ err = cause!.Cause()
475
+ }
476
+ return err
477
+ }