typenative 0.5.0 → 0.6.1

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 (149) hide show
  1. package/.github/workflows/ci.yml +2 -2
  2. package/.github/workflows/npm-publish-github-packages.yml +2 -2
  3. package/CHANGELOG.md +339 -0
  4. package/CONTRIBUTION.md +2 -1
  5. package/README.md +16 -7
  6. package/bin/cli.js +1 -0
  7. package/bin/index.js +62 -3
  8. package/bin/main.js +1 -0
  9. package/bin/node/core.js +46 -0
  10. package/bin/node/events.js +154 -15
  11. package/bin/node/http.js +1265 -127
  12. package/bin/node/process.js +13 -0
  13. package/bin/node/punycode.js +2 -2
  14. package/bin/node/stream.js +56 -7
  15. package/bin/node/stream_web.js +2 -2
  16. package/bin/node/timers.js +4 -2
  17. package/bin/node/url.js +28 -3
  18. package/bin/parse-node.js +2 -2
  19. package/bin/regex_vm.js +2105 -0
  20. package/bin/transpiler.js +17970 -4419
  21. package/bin/typecheck-node.js +2 -1
  22. package/bin/version.js +1 -1
  23. package/conformance.md +57 -15
  24. package/examples/README.md +50 -28
  25. package/examples/angular-templates/README.md +141 -0
  26. package/examples/angular-templates/bench.mjs +173 -0
  27. package/examples/angular-templates/dom-type-globals.d.ts +21 -0
  28. package/examples/angular-templates/dom-type-stubs.ts +21 -0
  29. package/examples/angular-templates/main.ts +135 -0
  30. package/examples/angular-templates/parity.mjs +157 -0
  31. package/examples/angular-templates/run-node.mjs +69 -0
  32. package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
  33. package/examples/desktop-notes/README.md +11 -13
  34. package/examples/dupe-finder/README.md +7 -5
  35. package/examples/fibonacci/README.md +7 -7
  36. package/examples/hello-world/README.md +6 -6
  37. package/examples/json-server/README.md +22 -18
  38. package/examples/mandelbrot-png/README.md +11 -13
  39. package/examples/marked-cli/README.md +60 -44
  40. package/examples/marked-cli/main.ts +122 -4
  41. package/examples/openai-chat/README.md +148 -0
  42. package/examples/openai-chat/bench.mjs +175 -0
  43. package/examples/openai-chat/main.ts +488 -0
  44. package/examples/react-compiler/README.md +185 -0
  45. package/examples/react-compiler/bench.mjs +181 -0
  46. package/examples/react-compiler/main.ts +324 -0
  47. package/examples/react-compiler/parity.mjs +362 -0
  48. package/examples/react-compiler/run-node.mjs +90 -0
  49. package/examples/react-compiler/vendor/babel/LICENSE +22 -0
  50. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
  51. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
  52. package/examples/react-compiler/vendor/charcodes/package.json +25 -0
  53. package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
  54. package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
  55. package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
  56. package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
  57. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
  58. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
  59. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
  60. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
  61. package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
  62. package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
  63. package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
  64. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
  65. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
  66. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
  67. package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
  68. package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
  69. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
  70. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
  71. package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
  72. package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
  73. package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
  74. package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
  75. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
  76. package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
  77. package/examples/react-compiler/vendor/zod/LICENSE +21 -0
  78. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
  79. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
  80. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
  81. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
  82. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
  83. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
  84. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
  85. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
  86. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
  87. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
  88. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
  89. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
  90. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
  91. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
  92. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
  93. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
  94. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
  95. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
  96. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
  97. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
  98. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
  99. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
  100. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
  101. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
  102. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
  103. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
  104. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
  105. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
  106. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
  107. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
  108. package/examples/react-compiler/vendor.mjs +688 -0
  109. package/examples/todo-cli/README.md +9 -9
  110. package/examples/yaml-cli/README.md +50 -34
  111. package/examples/yaml-cli/main.ts +236 -14
  112. package/package.json +8 -5
  113. package/performance/README.md +196 -0
  114. package/performance/any-dynamic.ts +21 -0
  115. package/performance/any-record-view.ts +20 -0
  116. package/performance/arr-hof.ts +21 -0
  117. package/performance/arr-push-index.ts +15 -0
  118. package/performance/arr-sort.ts +21 -0
  119. package/performance/async-await.ts +24 -0
  120. package/performance/class-dispatch.ts +52 -0
  121. package/performance/events-emit.ts +27 -0
  122. package/performance/exc-throw-rare.ts +25 -0
  123. package/performance/exc-try-catch.ts +26 -0
  124. package/performance/fn-closures.ts +29 -0
  125. package/performance/fn-recursion-tree.ts +31 -0
  126. package/performance/gen-for-of.ts +46 -0
  127. package/performance/json-roundtrip.ts +27 -0
  128. package/performance/map-delete.ts +24 -0
  129. package/performance/map-string-keys.ts +22 -0
  130. package/performance/num-arith-loop.ts +14 -0
  131. package/performance/num-bitwise.ts +21 -0
  132. package/performance/num-mod-int.ts +16 -0
  133. package/performance/num-to-string.ts +16 -0
  134. package/performance/obj-alloc.ts +32 -0
  135. package/performance/regex-exec.ts +29 -0
  136. package/performance/regex-site.ts +28 -0
  137. package/performance/set-ops.ts +20 -0
  138. package/performance/str-char-scan.ts +35 -0
  139. package/performance/str-concat-plus.ts +18 -0
  140. package/performance/str-concat.ts +24 -0
  141. package/performance/str-short-scan.ts +26 -0
  142. package/performance/str-split-join.ts +23 -0
  143. package/performance/str-template.ts +16 -0
  144. package/performance/union-switch.ts +57 -0
  145. package/tsparser/check.go +2 -1
  146. package/tsparser/main.go +1 -0
  147. package/types/typenative-npm.d.ts +3 -2
  148. package/types/typenative.d.ts +42 -12
  149. package/ROUND2-HANDOFF.md +0 -200
@@ -26,6 +26,10 @@ var TnCaptureRejections = false
26
26
  // EventEmitter: embeddable (class X extends EventEmitter), state allocated lazily
27
27
  type TnEventEmitter struct {
28
28
  state *tnEmitterState
29
+ ev0 string
30
+ fn0 interface{}
31
+ ev1 string
32
+ fn1 interface{}
29
33
  }
30
34
 
31
35
  // Anything that embeds an EventEmitter (events.once(emitter, …) accepts subclasses)
@@ -36,10 +40,10 @@ type tnEmitterLike interface {
36
40
  var TnDefaultMaxListeners = 10.0
37
41
 
38
42
  func TnNewEventEmitter(options ...interface{}) *TnEventEmitter {
39
- e := &TnEventEmitter{state: &tnEmitterState{events: map[string][]*tnListener{}, maxListeners: -1, warned: map[string]bool{}, captureRejections: TnCaptureRejections}}
43
+ e := &TnEventEmitter{}
40
44
  if len(options) > 0 && options[0] != nil {
41
45
  if b, ok := TnGetValue(options[0], "captureRejections").(bool); ok {
42
- e.state.captureRejections = b
46
+ e.st().captureRejections = b
43
47
  }
44
48
  }
45
49
  return e
@@ -49,7 +53,20 @@ func (e *TnEventEmitter) tnEmitter() *TnEventEmitter { return e }
49
53
 
50
54
  func (e *TnEventEmitter) st() *tnEmitterState {
51
55
  if e.state == nil {
52
- e.state = &tnEmitterState{events: map[string][]*tnListener{}, maxListeners: -1, warned: map[string]bool{}, captureRejections: TnCaptureRejections}
56
+ s := &tnEmitterState{events: map[string][]*tnListener{}, maxListeners: -1, captureRejections: TnCaptureRejections}
57
+ if e.fn0 != nil {
58
+ s.order = append(s.order, e.ev0)
59
+ s.events[e.ev0] = []*tnListener{{fn: e.fn0}}
60
+ e.ev0, e.fn0 = "", nil
61
+ }
62
+ if e.fn1 != nil {
63
+ if _, ok := s.events[e.ev1]; !ok {
64
+ s.order = append(s.order, e.ev1)
65
+ }
66
+ s.events[e.ev1] = append(s.events[e.ev1], &tnListener{fn: e.fn1})
67
+ e.ev1, e.fn1 = "", nil
68
+ }
69
+ e.state = s
53
70
  }
54
71
  return e.state
55
72
  }
@@ -84,6 +101,16 @@ func (e *TnEventEmitter) prependOnceListener(event string, fn interface{}) *TnEv
84
101
  }
85
102
 
86
103
  func (e *TnEventEmitter) add(event string, fn interface{}, prepend bool, once bool) *TnEventEmitter {
104
+ if e.state == nil && !prepend && !once && !TnCaptureRejections && event != "newListener" {
105
+ if e.fn0 == nil {
106
+ e.ev0, e.fn0 = event, fn
107
+ return e
108
+ }
109
+ if e.fn1 == nil {
110
+ e.ev1, e.fn1 = event, fn
111
+ return e
112
+ }
113
+ }
87
114
  s := e.st()
88
115
  if len(s.events["newListener"]) > 0 {
89
116
  e.emit("newListener", event, fn)
@@ -105,6 +132,9 @@ func (e *TnEventEmitter) add(event string, fn interface{}, prepend bool, once bo
105
132
  }
106
133
  warn := max > 0 && float64(count) > max && !s.warned[event]
107
134
  if warn {
135
+ if s.warned == nil {
136
+ s.warned = map[string]bool{}
137
+ }
108
138
  s.warned[event] = true
109
139
  }
110
140
  s.mu.Unlock()
@@ -115,6 +145,22 @@ func (e *TnEventEmitter) add(event string, fn interface{}, prepend bool, once bo
115
145
  }
116
146
 
117
147
  func (e *TnEventEmitter) removeListener(event string, fn interface{}) *TnEventEmitter {
148
+ if e.state == nil {
149
+ if e.fn0 == nil && e.fn1 == nil {
150
+ return e
151
+ }
152
+ id := tnFuncID(fn)
153
+ if e.fn1 != nil && e.ev1 == event && tnFuncID(e.fn1) == id {
154
+ e.ev1, e.fn1 = "", nil
155
+ return e
156
+ }
157
+ if e.fn0 != nil && e.ev0 == event && tnFuncID(e.fn0) == id {
158
+ e.ev0, e.fn0 = e.ev1, e.fn1
159
+ e.ev1, e.fn1 = "", nil
160
+ return e
161
+ }
162
+ return e
163
+ }
118
164
  s := e.st()
119
165
  s.mu.Lock()
120
166
  list := s.events[event]
@@ -157,6 +203,21 @@ func (e *TnEventEmitter) setListeners(event string, list []*tnListener) {
157
203
  }
158
204
 
159
205
  func (e *TnEventEmitter) removeAllListeners(event ...string) *TnEventEmitter {
206
+ if e.state == nil {
207
+ if len(event) == 0 {
208
+ e.ev0, e.fn0 = "", nil
209
+ e.ev1, e.fn1 = "", nil
210
+ return e
211
+ }
212
+ if e.fn1 != nil && e.ev1 == event[0] {
213
+ e.ev1, e.fn1 = "", nil
214
+ }
215
+ if e.fn0 != nil && e.ev0 == event[0] {
216
+ e.ev0, e.fn0 = e.ev1, e.fn1
217
+ e.ev1, e.fn1 = "", nil
218
+ }
219
+ return e
220
+ }
160
221
  s := e.st()
161
222
  s.mu.Lock()
162
223
  if len(event) > 0 {
@@ -170,22 +231,65 @@ func (e *TnEventEmitter) removeAllListeners(event ...string) *TnEventEmitter {
170
231
  }
171
232
 
172
233
  func (e *TnEventEmitter) emit(event string, args ...interface{}) bool {
234
+ if e.state == nil {
235
+ var f0, f1 interface{}
236
+ if e.fn0 != nil && e.ev0 == event {
237
+ f0 = e.fn0
238
+ }
239
+ if e.fn1 != nil && e.ev1 == event {
240
+ f1 = e.fn1
241
+ }
242
+ // events.errorMonitor sees an 'error' before the error listeners,
243
+ // whatever their registration order
244
+ if event == "error" {
245
+ if e.fn0 != nil && e.ev0 == TnErrorMonitor {
246
+ TnInvoke(e.fn0, args...)
247
+ }
248
+ if e.fn1 != nil && e.ev1 == TnErrorMonitor {
249
+ TnInvoke(e.fn1, args...)
250
+ }
251
+ }
252
+ if f0 == nil && f1 == nil {
253
+ if event == "error" {
254
+ if len(args) > 0 {
255
+ if _, ok := args[0].(error); ok {
256
+ panic(args[0])
257
+ }
258
+ panic(TnNodeError("Error", "ERR_UNHANDLED_ERROR", "Unhandled error. ("+fmt.Sprint(args[0])+")"))
259
+ }
260
+ panic(TnNodeError("Error", "ERR_UNHANDLED_ERROR", "Unhandled error."))
261
+ }
262
+ return false
263
+ }
264
+ if f0 != nil {
265
+ TnInvoke(f0, args...)
266
+ }
267
+ if f1 != nil {
268
+ TnInvoke(f1, args...)
269
+ }
270
+ return true
271
+ }
173
272
  s := e.st()
174
273
  s.mu.Lock()
175
- list := append([]*tnListener{}, s.events[event]...)
274
+ // (listener lists are copy-on-write — adds append past this length, removals
275
+ // build a new slice — so the list as it is now is the emit's snapshot)
276
+ list := s.events[event]
176
277
  // once listeners are removed before they run
177
- kept := []*tnListener{}
178
- for _, l := range s.events[event] {
179
- if !l.once {
180
- kept = append(kept, l)
278
+ for i, l := range list {
279
+ if l.once {
280
+ kept := append([]*tnListener{}, list[:i]...)
281
+ for _, rest := range list[i+1:] {
282
+ if !rest.once {
283
+ kept = append(kept, rest)
284
+ }
285
+ }
286
+ e.setListeners(event, kept)
287
+ break
181
288
  }
182
289
  }
183
- if len(kept) != len(s.events[event]) {
184
- e.setListeners(event, kept)
185
- }
186
- monitors := []*tnListener{}
290
+ var monitors []*tnListener
187
291
  if event == "error" {
188
- monitors = append(monitors, s.events[TnErrorMonitor]...)
292
+ monitors = s.events[TnErrorMonitor]
189
293
  }
190
294
  capture := s.captureRejections
191
295
  s.mu.Unlock()
@@ -283,6 +387,16 @@ func TnAddAbortListener(signal *TnAbortSignal, listener interface{}) *TnDisposab
283
387
  }
284
388
 
285
389
  func (e *TnEventEmitter) listeners(event string) []interface{} {
390
+ if e.state == nil {
391
+ out := []interface{}{}
392
+ if e.fn0 != nil && e.ev0 == event {
393
+ out = append(out, e.fn0)
394
+ }
395
+ if e.fn1 != nil && e.ev1 == event {
396
+ out = append(out, e.fn1)
397
+ }
398
+ return out
399
+ }
286
400
  s := e.st()
287
401
  s.mu.Lock()
288
402
  defer s.mu.Unlock()
@@ -296,6 +410,21 @@ func (e *TnEventEmitter) listeners(event string) []interface{} {
296
410
  func (e *TnEventEmitter) rawListeners(event string) []interface{} { return e.listeners(event) }
297
411
 
298
412
  func (e *TnEventEmitter) listenerCount(event string, fn ...interface{}) float64 {
413
+ if e.state == nil {
414
+ n := 0
415
+ wantFilter := len(fn) > 0 && fn[0] != nil
416
+ var wantID uintptr
417
+ if wantFilter {
418
+ wantID = tnFuncID(fn[0])
419
+ }
420
+ if e.fn0 != nil && e.ev0 == event && (!wantFilter || tnFuncID(e.fn0) == wantID) {
421
+ n++
422
+ }
423
+ if e.fn1 != nil && e.ev1 == event && (!wantFilter || tnFuncID(e.fn1) == wantID) {
424
+ n++
425
+ }
426
+ return float64(n)
427
+ }
299
428
  s := e.st()
300
429
  s.mu.Lock()
301
430
  defer s.mu.Unlock()
@@ -312,6 +441,16 @@ func (e *TnEventEmitter) listenerCount(event string, fn ...interface{}) float64
312
441
  }
313
442
 
314
443
  func (e *TnEventEmitter) eventNames() []string {
444
+ if e.state == nil {
445
+ out := []string{}
446
+ if e.fn0 != nil {
447
+ out = append(out, e.ev0)
448
+ }
449
+ if e.fn1 != nil && (e.fn0 == nil || e.ev1 != e.ev0) {
450
+ out = append(out, e.ev1)
451
+ }
452
+ return out
453
+ }
315
454
  s := e.st()
316
455
  s.mu.Lock()
317
456
  defer s.mu.Unlock()
@@ -324,10 +463,10 @@ func (e *TnEventEmitter) setMaxListeners(n float64) *TnEventEmitter {
324
463
  }
325
464
 
326
465
  func (e *TnEventEmitter) getMaxListeners() float64 {
327
- if e.st().maxListeners < 0 {
466
+ if e.state == nil || e.state.maxListeners < 0 {
328
467
  return TnDefaultMaxListeners
329
468
  }
330
- return e.st().maxListeners
469
+ return e.state.maxListeners
331
470
  }
332
471
 
333
472
  // events.once(emitter, name): a promise of the event's arguments; 'error' rejects it