typenative 0.6.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,75 @@ All notable changes to TypeNative will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [0.6.1] - 2026-11-15
11
+
12
+ ### Changed
13
+
14
+ - **examples/react-compiler: faster than Node at 64 KB.** The React Compiler
15
+ now runs a 64 KB component file in 615 ms vs Node's 1,030 ms (1.7x faster;
16
+ it was 3.5x slower), and per call is 3.5x faster (100 vs 349 ms). Plain
17
+ functions assigned to `NodePath.prototype` declare `this: NodePath`; that
18
+ now types `__this` as the class, so Babel's per-node path maintenance
19
+ (`visit`, `setScope`, `setContext`, `parentPath` walks) is direct field
20
+ access instead of dynamic plan lookups. Dynamic calls of the program's own
21
+ function types go through a generated `tnCallValueTyped` case per Go func
22
+ type (no `reflect.Value.Call`), and optional calls to prototype methods
23
+ added at run time are guarded dynamic calls. For large files the example
24
+ compiles independent top-level functions in parallel worker processes and
25
+ joins their output; under Node each worker re-imports the compiler, while a
26
+ TypeNative worker starts from the compiled binary.
27
+ - **Iterating class iterators through dynamic values:** `TnToArray` (used by
28
+ spread, `Array.from`, destructuring and `for…of` on a dynamically typed
29
+ value) recognizes a class's generator push form directly
30
+ (`Symbol_iterator__seq`) and iterates it in place instead of finding
31
+ `*[Symbol.iterator]()` through reflection, calling it and draining its
32
+ channel on a goroutine. An interface-yield channel method also gets a direct
33
+ type assertion. This is what Angular's `OpList` hit through an op's dynamic
34
+ `handlerOps` / `trackByOps` fields; angular-templates' 64 KB run fell from
35
+ about 600 ms to 305 ms (now 1.2x faster than Node), and per-call latency is
36
+ 4.4x Node's (50 vs 219 ms).
37
+ - **yaml-cli throughput:** `yaml --json` on a large, plain stream is split
38
+ before the `---` lines that start its documents, and up to six worker
39
+ processes compose runs of them and print their JSON arrays, which the main
40
+ process joins. Directives, errors, warnings, CR line endings and
41
+ collection-valued keys fall back to the normal `cli()` path (the example
42
+ runs under Node too). On the 10 MB benchmark the complete process run is
43
+ now 754 ms vs Node's 851 ms (median, 1.1x); the single-process path also
44
+ got faster.
45
+ - **Object conversions and dynamic writes:** conversion identity holds one
46
+ weak pointer per conversion, sweeps dead entries in batches and keeps a
47
+ recent cache; a fresh local object converted once is copied without an
48
+ identity entry (`TnAsCopy`), and a conversion between two statically known
49
+ struct types is emitted as a struct literal. `Object.assign({ defaults },
50
+ typedSource)` sets the target's fields directly instead of through
51
+ reflection, `obj[key] = v` on a plain object skips reflection
52
+ (`TnSetProp`), and `s += chunk` for an untyped chunk appends in place
53
+ instead of copying the whole string.
54
+ - **List building:** a single-value `push` grows the backing slice by 2x
55
+ (`TnPush`) rather than Go's 1.25x, whose repeated copies add up to about
56
+ five times a long list's final memory.
57
+ - **marked-cli throughput:** large markdown documents are parsed in up to six
58
+ worker processes, one contiguous run of top-level sections each, with a
59
+ sequential fallback (small inputs, reference link definitions, raw HTML
60
+ blocks, CRLF, `--tokens`). On the example's 10 MB benchmark the complete
61
+ process run is now 1.2x faster than Node (512 ms vs 596 ms); parity stays
62
+ 2,859/2,859. The single-process parse also got faster: `[...s].length` /
63
+ `[...s][i]` / `[...s].at(i)` no longer build rune arrays, truthiness-only
64
+ `re.exec` runs `re.test`, nullable regex results box only on a match, greedy
65
+ `[^x]+` runs use `IndexByte`, and the long-string ASCII cache and regex
66
+ replacement builders no longer allocate per token.
67
+
68
+ ### Fixed
69
+
70
+ - **process.stdin:** `TnStdin` sets its `_stdinRef` hook through `setHook`
71
+ again after the lazy emitter/hook state change; reading stdin no longer
72
+ panics with `assignment to entry in nil map`.
73
+ - **events.errorMonitor:** with only the two inline listeners, an `'error'`
74
+ event calls an `errorMonitor` listener before the error listeners again (the
75
+ lazy listener path skipped it, so the conformance probe saw `handler` first).
76
+
8
77
  ## [0.6.0] - 2026-11-13
9
78
 
10
79
  The React Compiler itself (`babel-plugin-react-compiler` + Babel + zod, ~470 vendored files)
package/README.md CHANGED
@@ -295,7 +295,8 @@ also from unmodified source, matching Node on all 2,859 cases of marked's spec
295
295
  suites (CommonMark, GFM, its own tests and ReDoS inputs). The newest,
296
296
  [react-compiler](examples/react-compiler/), compiles the React Compiler
297
297
  itself (`babel-plugin-react-compiler` on Babel 7.29 and zod 4 — the largest
298
- codebase yet) and is one runtime gap away from its benchmarks.
298
+ codebase yet), matching Node on every parity fixture, 3.6x faster per file and
299
+ 1.7x faster on a 64 KB component file.
299
300
 
300
301
  ## How it works
301
302
 
package/bin/node/core.js CHANGED
@@ -39,6 +39,11 @@ func TnInvoke(fn interface{}, args ...interface{}) interface{} {
39
39
  f(a)
40
40
  return nil
41
41
  }
42
+ case func([]byte):
43
+ if a, ok := tnInvokeAt(args, 0).([]byte); ok && f != nil {
44
+ f(a)
45
+ return nil
46
+ }
42
47
  }
43
48
  fv := reflect.ValueOf(fn)
44
49
  if !fv.IsValid() || fv.Kind() != reflect.Func || fv.IsNil() {
@@ -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,6 +231,44 @@ 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
274
  // (listener lists are copy-on-write — adds append past this length, removals
@@ -288,6 +387,16 @@ func TnAddAbortListener(signal *TnAbortSignal, listener interface{}) *TnDisposab
288
387
  }
289
388
 
290
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
+ }
291
400
  s := e.st()
292
401
  s.mu.Lock()
293
402
  defer s.mu.Unlock()
@@ -301,6 +410,21 @@ func (e *TnEventEmitter) listeners(event string) []interface{} {
301
410
  func (e *TnEventEmitter) rawListeners(event string) []interface{} { return e.listeners(event) }
302
411
 
303
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
+ }
304
428
  s := e.st()
305
429
  s.mu.Lock()
306
430
  defer s.mu.Unlock()
@@ -317,6 +441,16 @@ func (e *TnEventEmitter) listenerCount(event string, fn ...interface{}) float64
317
441
  }
318
442
 
319
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
+ }
320
454
  s := e.st()
321
455
  s.mu.Lock()
322
456
  defer s.mu.Unlock()
@@ -329,10 +463,10 @@ func (e *TnEventEmitter) setMaxListeners(n float64) *TnEventEmitter {
329
463
  }
330
464
 
331
465
  func (e *TnEventEmitter) getMaxListeners() float64 {
332
- if e.st().maxListeners < 0 {
466
+ if e.state == nil || e.state.maxListeners < 0 {
333
467
  return TnDefaultMaxListeners
334
468
  }
335
- return e.st().maxListeners
469
+ return e.state.maxListeners
336
470
  }
337
471
 
338
472
  // events.once(emitter, name): a promise of the event's arguments; 'error' rejects it