typenative 0.6.0 → 0.6.2
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 +93 -0
- package/README.md +2 -1
- package/bin/node/core.js +5 -0
- package/bin/node/events.js +139 -5
- package/bin/node/http.js +1265 -127
- package/bin/node/stream.js +56 -7
- package/bin/node/stream_web.js +2 -2
- package/bin/node/url.js +27 -2
- package/bin/regex_vm.js +50 -2
- package/bin/transpiler.js +1365 -184
- package/bin/version.js +1 -1
- package/examples/README.md +28 -29
- package/examples/angular-templates/README.md +22 -20
- package/examples/json-server/README.md +16 -13
- package/examples/marked-cli/README.md +37 -22
- package/examples/marked-cli/main.ts +122 -4
- package/examples/react-compiler/README.md +56 -41
- package/examples/react-compiler/main.ts +173 -7
- package/examples/react-compiler/run-node.mjs +2 -0
- package/examples/yaml-cli/README.md +36 -30
- package/examples/yaml-cli/main.ts +236 -14
- package/package.json +1 -1
- package/performance/README.md +1 -0
- package/tsparser/go.mod +1 -1
- package/tsparser/go.sum +2 -2
package/bin/node/stream.js
CHANGED
|
@@ -86,7 +86,7 @@ func tnStreamOption(options interface{}, key string) interface{} {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
func tnNewStreamBase(options []interface{}) *TnStream {
|
|
89
|
-
s := &TnStream{flowing: -1, decodeStrings: true,
|
|
89
|
+
s := &TnStream{flowing: -1, decodeStrings: true, asyncCtx: TnAsyncSnapshot()}
|
|
90
90
|
if len(options) > 0 && options[0] != nil {
|
|
91
91
|
s.options = options[0]
|
|
92
92
|
if b, ok := tnStreamOption(s.options, "objectMode").(bool); ok {
|
|
@@ -100,7 +100,7 @@ func tnNewStreamBase(options []interface{}) *TnStream {
|
|
|
100
100
|
}
|
|
101
101
|
for _, name := range []string{"read", "write", "transform", "flush", "final", "destroy"} {
|
|
102
102
|
if fn := tnStreamOption(s.options, name); fn != nil && reflect.ValueOf(fn).Kind() == reflect.Func && !reflect.ValueOf(fn).IsNil() {
|
|
103
|
-
s.
|
|
103
|
+
s.setHook("_"+name, fn)
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -229,7 +229,24 @@ func (s *TnStream) flow() {
|
|
|
229
229
|
for s.flowing == 1 && len(s.queue) > 0 {
|
|
230
230
|
chunk := s.queue[0]
|
|
231
231
|
s.queue = s.queue[1:]
|
|
232
|
-
s.
|
|
232
|
+
if s.state == nil {
|
|
233
|
+
if s.fn0 != nil && s.ev0 == "data" {
|
|
234
|
+
if f, ok := s.fn0.(func(interface{})); ok {
|
|
235
|
+
f(chunk)
|
|
236
|
+
} else {
|
|
237
|
+
TnInvoke(s.fn0, chunk)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if s.fn1 != nil && s.ev1 == "data" {
|
|
241
|
+
if f, ok := s.fn1.(func(interface{})); ok {
|
|
242
|
+
f(chunk)
|
|
243
|
+
} else {
|
|
244
|
+
TnInvoke(s.fn1, chunk)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
s.emit("data", chunk)
|
|
249
|
+
}
|
|
233
250
|
}
|
|
234
251
|
if len(s.queue) == 0 && s.readEnded {
|
|
235
252
|
s.emitEnd()
|
|
@@ -286,9 +303,31 @@ func (s *TnStream) emitEnd() {
|
|
|
286
303
|
return
|
|
287
304
|
}
|
|
288
305
|
s.endEmitted = true
|
|
289
|
-
s.
|
|
306
|
+
if s.state == nil {
|
|
307
|
+
if s.fn0 != nil && s.ev0 == "end" {
|
|
308
|
+
if f, ok := s.fn0.(func()); ok {
|
|
309
|
+
f()
|
|
310
|
+
} else {
|
|
311
|
+
TnInvoke(s.fn0)
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if s.fn1 != nil && s.ev1 == "end" {
|
|
315
|
+
if f, ok := s.fn1.(func()); ok {
|
|
316
|
+
f()
|
|
317
|
+
} else {
|
|
318
|
+
TnInvoke(s.fn1)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
s.emit("end")
|
|
323
|
+
}
|
|
290
324
|
if !s.writableSide || s.finished {
|
|
291
|
-
s.
|
|
325
|
+
if s.listenerCount("close") == 0 {
|
|
326
|
+
s.closed = true
|
|
327
|
+
s.releaseHandle()
|
|
328
|
+
} else {
|
|
329
|
+
s.emitClose()
|
|
330
|
+
}
|
|
292
331
|
}
|
|
293
332
|
}
|
|
294
333
|
|
|
@@ -592,6 +631,11 @@ func (s *TnStream) processWrites() {
|
|
|
592
631
|
}
|
|
593
632
|
s.post(s.processWrites)
|
|
594
633
|
}
|
|
634
|
+
if s.sink == nil && s.tnSelf != nil {
|
|
635
|
+
if init, ok := s.tnSelf.(interface{ tnInitSink() }); ok {
|
|
636
|
+
init.tnInitSink()
|
|
637
|
+
}
|
|
638
|
+
}
|
|
595
639
|
switch {
|
|
596
640
|
case s.sink != nil:
|
|
597
641
|
s.sink(req.chunk, func(err interface{}) { done(err) })
|
|
@@ -706,6 +750,11 @@ func (s *TnStream) finish() {
|
|
|
706
750
|
TnInvoke(fn, complete)
|
|
707
751
|
return
|
|
708
752
|
}
|
|
753
|
+
if s.sinkFinal == nil && s.tnSelf != nil {
|
|
754
|
+
if init, ok := s.tnSelf.(interface{ tnInitSink() }); ok {
|
|
755
|
+
init.tnInitSink()
|
|
756
|
+
}
|
|
757
|
+
}
|
|
709
758
|
if s.sinkFinal != nil {
|
|
710
759
|
s.sinkFinal(func(err interface{}) { complete(err) })
|
|
711
760
|
return
|
|
@@ -1065,7 +1114,7 @@ func TnStdin() *TnStream {
|
|
|
1065
1114
|
}
|
|
1066
1115
|
}()
|
|
1067
1116
|
}
|
|
1068
|
-
s.
|
|
1117
|
+
s.setHook("_stdinRef", func(flowing bool) {
|
|
1069
1118
|
if flowing && !refHeld && !s.readEnded {
|
|
1070
1119
|
refHeld = true
|
|
1071
1120
|
TnLoopRef()
|
|
@@ -1073,7 +1122,7 @@ func TnStdin() *TnStream {
|
|
|
1073
1122
|
refHeld = false
|
|
1074
1123
|
TnLoopUnref()
|
|
1075
1124
|
}
|
|
1076
|
-
}
|
|
1125
|
+
})
|
|
1077
1126
|
return s
|
|
1078
1127
|
}`;
|
|
1079
1128
|
const fileStreamHelper = `// fs.createReadStream / createWriteStream
|
package/bin/node/stream_web.js
CHANGED
|
@@ -1758,7 +1758,7 @@ func TnDuplexFromWeb(pair interface{}, options ...interface{}) *TnStream {
|
|
|
1758
1758
|
r.on("data", func(chunk interface{}) { d.push(chunk) })
|
|
1759
1759
|
r.TnEventEmitter.once("end", func() { d.push(nil) })
|
|
1760
1760
|
r.TnEventEmitter.once("error", func(err interface{}) { d.destroy(err) })
|
|
1761
|
-
d.
|
|
1761
|
+
d.setHook("_read", func(size float64) {})
|
|
1762
1762
|
return d
|
|
1763
1763
|
}
|
|
1764
1764
|
|
|
@@ -1804,7 +1804,7 @@ func TnCompose(streams ...interface{}) *TnStream {
|
|
|
1804
1804
|
}
|
|
1805
1805
|
}
|
|
1806
1806
|
if last.readableSide {
|
|
1807
|
-
d.
|
|
1807
|
+
d.setHook("_read", func(size float64) {})
|
|
1808
1808
|
last.on("data", func(chunk interface{}) { d.push(chunk) })
|
|
1809
1809
|
last.TnEventEmitter.once("end", func() { d.push(nil) })
|
|
1810
1810
|
}
|
package/bin/node/url.js
CHANGED
|
@@ -44,7 +44,19 @@ func tnInvalidURL(input string) *TnError {
|
|
|
44
44
|
|
|
45
45
|
// Percent-encodes the bytes of s that are in the set (C0 controls and non-ASCII always)
|
|
46
46
|
func tnPercentEncode(s string, set string) string {
|
|
47
|
+
need := false
|
|
48
|
+
for i := 0; i < len(s); i++ {
|
|
49
|
+
c := s[i]
|
|
50
|
+
if c < 0x20 || c > 0x7E || strings.IndexByte(set, c) >= 0 {
|
|
51
|
+
need = true
|
|
52
|
+
break
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if !need {
|
|
56
|
+
return s
|
|
57
|
+
}
|
|
47
58
|
var sb strings.Builder
|
|
59
|
+
sb.Grow(len(s) + 8)
|
|
48
60
|
for i := 0; i < len(s); i++ {
|
|
49
61
|
c := s[i]
|
|
50
62
|
if c < 0x20 || c > 0x7E || strings.IndexByte(set, c) >= 0 {
|
|
@@ -69,6 +81,9 @@ func (u *TnURL) special() bool {
|
|
|
69
81
|
|
|
70
82
|
// RFC 3986 remove_dot_segments on a "/"-separated path
|
|
71
83
|
func tnRemoveDotSegments(path string) string {
|
|
84
|
+
if strings.IndexByte(path, '.') < 0 && strings.IndexByte(path, '%') < 0 {
|
|
85
|
+
return path
|
|
86
|
+
}
|
|
72
87
|
segments := strings.Split(path, "/")
|
|
73
88
|
out := []string{}
|
|
74
89
|
for i, seg := range segments {
|
|
@@ -228,7 +243,9 @@ func tnCopyURL(b *TnURL) *TnURL {
|
|
|
228
243
|
}
|
|
229
244
|
|
|
230
245
|
func tnParseURLString(input string, base *TnURL) (*TnURL, bool) {
|
|
231
|
-
input
|
|
246
|
+
if len(input) > 0 && (input[0] <= 0x20 || input[len(input)-1] <= 0x20) {
|
|
247
|
+
input = strings.TrimFunc(input, func(r rune) bool { return r <= 0x20 })
|
|
248
|
+
}
|
|
232
249
|
if strings.ContainsAny(input, "\\t\\n\\r") {
|
|
233
250
|
input = tnURLStrip.Replace(input)
|
|
234
251
|
}
|
|
@@ -347,6 +364,8 @@ func tnResolveRelative(input string, query string, hasQuery bool, fragment strin
|
|
|
347
364
|
return u, true
|
|
348
365
|
}
|
|
349
366
|
|
|
367
|
+
var tnURLBaseCache sync.Map
|
|
368
|
+
|
|
350
369
|
func tnURLBase(base []interface{}) (*TnURL, bool, string) {
|
|
351
370
|
if len(base) == 0 || base[0] == nil {
|
|
352
371
|
return nil, true, ""
|
|
@@ -355,7 +374,13 @@ func tnURLBase(base []interface{}) (*TnURL, bool, string) {
|
|
|
355
374
|
case *TnURL:
|
|
356
375
|
return b, true, ""
|
|
357
376
|
case string:
|
|
377
|
+
if cached, ok := tnURLBaseCache.Load(b); ok {
|
|
378
|
+
return cached.(*TnURL), true, b
|
|
379
|
+
}
|
|
358
380
|
parsed, ok := tnParseURLString(b, nil)
|
|
381
|
+
if ok && len(b) <= 128 {
|
|
382
|
+
tnURLBaseCache.Store(b, parsed)
|
|
383
|
+
}
|
|
359
384
|
return parsed, ok, b
|
|
360
385
|
}
|
|
361
386
|
s := fmt.Sprint(base[0])
|
|
@@ -827,7 +852,7 @@ func TnDomainToUnicode(domain string) string {
|
|
|
827
852
|
}`;
|
|
828
853
|
export function registerUrl(r) {
|
|
829
854
|
defineModule(r, 'url');
|
|
830
|
-
defineHelper(r, 'nodeUrl', ['encoding/hex', 'fmt', 'net/url', 'path/filepath', 'reflect', 'runtime', 'sort', 'strconv', 'strings', 'unicode/utf16', 'unsafe'], ['error', 'dynamic', 'punycode', 'pathToFileURL', 'nodeInvoke'], urlHelper);
|
|
855
|
+
defineHelper(r, 'nodeUrl', ['encoding/hex', 'fmt', 'net/url', 'path/filepath', 'reflect', 'runtime', 'sort', 'strconv', 'strings', 'sync', 'unicode/utf16', 'unsafe'], ['error', 'dynamic', 'punycode', 'pathToFileURL', 'nodeInvoke'], urlHelper);
|
|
831
856
|
defineClass(r, 'url.URL', '*TnURL', 'class', 'toString=string; toJSON=string', '', 'href=string; protocol=string; username=string; password=string; host=string; hostname=string; port=string; pathname=string; search=string; hash=string; origin=string; searchParams=*TnURLSearchParams', 'href; protocol; username; password; host; hostname; port; pathname; search; hash');
|
|
832
857
|
defineClass(r, 'url.URLSearchParams', '*TnURLSearchParams', 'class', 'append=; set=; delete=; get=*string; getAll=[]string; has=bool; sort=; toString=string; keys=[]string; values=[]string; entries=[][]string; forEach=', '', 'size=float64', '');
|
|
833
858
|
r.iterators['*TnURLSearchParams'] = 'entries';
|
package/bin/regex_vm.js
CHANGED
|
@@ -188,7 +188,7 @@ func (m *tnRxMatcher) groups(n int, lo int, hi int) []string {
|
|
|
188
188
|
s := m.s
|
|
189
189
|
// (capped at their hidden slots: an append moves them out of the chunk)
|
|
190
190
|
if len(m.chunk) < n+2 {
|
|
191
|
-
m.chunk = make([]string, max(n+2,
|
|
191
|
+
m.chunk = make([]string, max(n+2, 4096))
|
|
192
192
|
}
|
|
193
193
|
groups := m.chunk[:n:n+2]
|
|
194
194
|
m.chunk = m.chunk[n+2:]
|
|
@@ -442,6 +442,34 @@ vm:
|
|
|
442
442
|
}
|
|
443
443
|
case tnRxRepGreedy:
|
|
444
444
|
set, count := in.set, 0
|
|
445
|
+
// (everything but one ASCII byte — [^\\n]+ and the like — is a
|
|
446
|
+
// byte scan, not a rune-by-rune one)
|
|
447
|
+
if in.neg && in.max < 0 {
|
|
448
|
+
start := pos
|
|
449
|
+
for pos < len(s) {
|
|
450
|
+
i := strings.IndexByte(s[pos:], in.c)
|
|
451
|
+
if i < 0 {
|
|
452
|
+
pos = len(s)
|
|
453
|
+
break
|
|
454
|
+
}
|
|
455
|
+
if i == 0 {
|
|
456
|
+
break
|
|
457
|
+
}
|
|
458
|
+
pos += i
|
|
459
|
+
}
|
|
460
|
+
count = pos - start
|
|
461
|
+
if count > 0 && !tnStrIsASCII(s[start:pos]) {
|
|
462
|
+
count = utf8.RuneCountInString(s[start:pos])
|
|
463
|
+
}
|
|
464
|
+
if count >= int(in.min) {
|
|
465
|
+
if extra := count - int(in.min); extra > 0 && !in.possessive {
|
|
466
|
+
st = append(st, tnRxFrame{kind: tnRxGreedy, pc: pc, pos: pos, n: extra})
|
|
467
|
+
}
|
|
468
|
+
pc++
|
|
469
|
+
continue
|
|
470
|
+
}
|
|
471
|
+
break
|
|
472
|
+
}
|
|
445
473
|
for pos < len(s) && (in.max < 0 || count < int(in.max)) {
|
|
446
474
|
if c := s[pos]; c < utf8.RuneSelf {
|
|
447
475
|
if !set.ascii[c] {
|
|
@@ -767,6 +795,21 @@ func (c *tnRxCompiler) setOf(n *tnBtNode) *tnRxCharSet {
|
|
|
767
795
|
return set
|
|
768
796
|
}
|
|
769
797
|
|
|
798
|
+
// A set matching every byte but one (all runes but that ASCII byte), which a
|
|
799
|
+
// run can find with IndexByte instead of testing byte by byte
|
|
800
|
+
func tnRxExcludedByte(set *tnRxCharSet) (byte, bool) {
|
|
801
|
+
if !set.high {
|
|
802
|
+
return 0, false
|
|
803
|
+
}
|
|
804
|
+
excluded, count := 0, 0
|
|
805
|
+
for b, in := range set.ascii {
|
|
806
|
+
if !in {
|
|
807
|
+
excluded, count = b, count+1
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return byte(excluded), count == 1
|
|
811
|
+
}
|
|
812
|
+
|
|
770
813
|
func tnBtIsSingle(n *tnBtNode) bool {
|
|
771
814
|
return n.op == "char" || n.op == "any" || n.op == "class"
|
|
772
815
|
}
|
|
@@ -1069,10 +1112,15 @@ func (c *tnRxCompiler) rep(n *tnBtNode, tail []*tnBtNode, end bool) {
|
|
|
1069
1112
|
return
|
|
1070
1113
|
}
|
|
1071
1114
|
if tnBtIsSingle(n.child) {
|
|
1072
|
-
|
|
1115
|
+
set := c.setOf(n.child)
|
|
1116
|
+
in := tnRxInst{op: tnRxRepGreedy, greedy: n.greedy, set: set, min: int32(n.min), max: int32(n.max), next: -1}
|
|
1073
1117
|
if !n.greedy {
|
|
1074
1118
|
in.op = tnRxRepLazy
|
|
1075
1119
|
}
|
|
1120
|
+
// (a run of everything but one ASCII byte: found with IndexByte)
|
|
1121
|
+
if ex, ok := tnRxExcludedByte(set); ok {
|
|
1122
|
+
in.neg, in.c = true, ex
|
|
1123
|
+
}
|
|
1076
1124
|
c.repHints(&in, tail, end)
|
|
1077
1125
|
next := in.next
|
|
1078
1126
|
at := c.emit(in)
|