gofront 1.7.0 → 1.9.0

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 (194) hide show
  1. package/README.md +14 -14
  2. package/package.json +10 -38
  3. package/src/backend/js/expressions.js +2060 -389
  4. package/src/backend/js/index.js +586 -174
  5. package/src/backend/js/natives.js +383 -0
  6. package/src/backend/js/runtime.js +936 -1644
  7. package/src/backend/js/statements.js +1349 -132
  8. package/src/backend/js/stdlib/index.js +51 -94
  9. package/src/backend/js/templ.js +67 -118
  10. package/src/backend/js/type-info.js +436 -0
  11. package/src/backend/shared/fixed-float.js +20 -0
  12. package/src/backend/shared/fmt-types.js +80 -0
  13. package/src/backend/shared/host-unicode.js +36 -0
  14. package/src/backend/wasm/boundary.js +753 -872
  15. package/src/backend/wasm/emit-builtins.js +914 -237
  16. package/src/backend/wasm/emit-exprs.js +1456 -195
  17. package/src/backend/wasm/emit-maps.js +78 -380
  18. package/src/backend/wasm/emit-stmts.js +1659 -214
  19. package/src/backend/wasm/emit.js +614 -88
  20. package/src/backend/wasm/encode.js +43 -13
  21. package/src/backend/wasm/globals.js +491 -0
  22. package/src/backend/wasm/glue.js +2 -4
  23. package/src/backend/wasm/index.js +406 -3195
  24. package/src/backend/wasm/method-expr.js +392 -0
  25. package/src/backend/wasm/module-emitter.js +1615 -0
  26. package/src/backend/wasm/monomorph.js +164 -9
  27. package/src/backend/wasm/natives.js +596 -0
  28. package/src/backend/wasm/prescan.js +249 -0
  29. package/src/backend/wasm/prune-funcs.js +89 -0
  30. package/src/backend/wasm/stdlib/index.js +2 -37
  31. package/src/backend/wasm/stdlib/simd.js +293 -28
  32. package/src/backend/wasm/types.js +260 -27
  33. package/src/backend/wasm/variadic.js +93 -0
  34. package/src/backend/wasm/wat.js +47 -20
  35. package/src/{cli-core.js → cli/cli-core.js} +241 -11
  36. package/src/{test-runner.js → cli/test-runner.js} +188 -122
  37. package/src/{vendor.js → cli/vendor.js} +3 -4
  38. package/src/compiler.js +202 -386
  39. package/src/index.js +15 -169
  40. package/src/{lexer.js → lexer/lexer.js} +203 -62
  41. package/src/{templ-lexer.js → lexer/templ-lexer.js} +61 -18
  42. package/src/{tokens.js → lexer/tokens.js} +2 -0
  43. package/src/link/sourcemap.js +97 -0
  44. package/src/link/stdlib.js +737 -0
  45. package/src/link/type-names.js +148 -0
  46. package/src/link/wasm.js +318 -0
  47. package/src/lower/bounds.js +547 -0
  48. package/src/lower/boxing.js +1 -1
  49. package/src/lower/captures.js +267 -64
  50. package/src/lower/embedding.js +32 -3
  51. package/src/lower/errors-as.js +196 -0
  52. package/src/lower/fmt-formatters.js +905 -0
  53. package/src/lower/functions.js +2 -0
  54. package/src/lower/gen-types.js +274 -0
  55. package/src/lower/index.js +33 -19
  56. package/src/lower/json-codecs.js +1379 -0
  57. package/src/lower/ownership.js +47 -8
  58. package/src/lower/range.js +86 -1
  59. package/src/lower/reachability.js +150 -0
  60. package/src/lower/walk.js +12 -0
  61. package/src/parser/declarations.js +83 -15
  62. package/src/parser/expressions.js +110 -18
  63. package/src/parser/index.js +2 -1
  64. package/src/parser/statements.js +38 -22
  65. package/src/{templ-parser.js → parser/templ.js} +179 -17
  66. package/src/parser/types.js +70 -9
  67. package/src/resolver.js +21 -1
  68. package/src/typechecker/assignability.js +291 -19
  69. package/src/typechecker/const-fold.js +399 -0
  70. package/src/typechecker/constants.js +282 -0
  71. package/src/typechecker/expressions.js +1220 -183
  72. package/src/typechecker/index.js +659 -92
  73. package/src/typechecker/init-order.js +426 -0
  74. package/src/typechecker/operand-text.js +40 -0
  75. package/src/typechecker/resolve.js +613 -62
  76. package/src/typechecker/statements.js +212 -20
  77. package/src/typechecker/stdlib/excluded.js +902 -0
  78. package/src/typechecker/stdlib/index.js +38 -0
  79. package/src/typechecker/stdlib/simd.js +65 -15
  80. package/src/typechecker/termination.js +11 -2
  81. package/src/typechecker/types.js +268 -514
  82. package/stdlib/bytes/buffer.go +479 -0
  83. package/stdlib/bytes/bytes.go +1010 -0
  84. package/stdlib/bytes/reader.go +161 -0
  85. package/stdlib/cmp/cmp.go +65 -0
  86. package/stdlib/context/context.go +115 -0
  87. package/stdlib/crypto/rand/rand.go +34 -0
  88. package/stdlib/crypto/sha256/sha256.go +249 -0
  89. package/stdlib/encoding/base64/base64.go +331 -0
  90. package/stdlib/encoding/binary/binary.go +332 -0
  91. package/stdlib/encoding/hex/hex.go +140 -0
  92. package/stdlib/encoding/json/errors.go +31 -0
  93. package/stdlib/encoding/json/indent.go +71 -0
  94. package/stdlib/encoding/json/json.go +62 -0
  95. package/stdlib/encoding/json/number.go +12 -0
  96. package/stdlib/encoding/json/stream.go +173 -0
  97. package/stdlib/errors/errors.go +174 -0
  98. package/stdlib/fmt/errors.go +110 -0
  99. package/stdlib/fmt/format.go +732 -0
  100. package/stdlib/fmt/print.go +1232 -0
  101. package/stdlib/gom/gom.go +293 -0
  102. package/stdlib/hash/hash.go +53 -0
  103. package/stdlib/html/html.go +251 -0
  104. package/stdlib/internal/fmtrt/fmtrt.go +163 -0
  105. package/stdlib/internal/jsonrt/dec.go +871 -0
  106. package/stdlib/internal/jsonrt/enc.go +516 -0
  107. package/stdlib/internal/jsonrt/indent.go +135 -0
  108. package/stdlib/internal/jsonrt/number.go +27 -0
  109. package/stdlib/internal/jsonrt/reader.go +73 -0
  110. package/stdlib/internal/jsonrt/scanner.go +658 -0
  111. package/stdlib/io/io.go +502 -0
  112. package/stdlib/iter/iter.go +18 -0
  113. package/stdlib/maps/maps.go +131 -0
  114. package/stdlib/math/bits/bits.go +507 -0
  115. package/stdlib/math/extra.go +272 -0
  116. package/stdlib/math/math.go +439 -0
  117. package/stdlib/math/rand/rand.go +297 -0
  118. package/stdlib/os/os.go +93 -0
  119. package/stdlib/path/filepath/filepath.go +47 -0
  120. package/stdlib/path/path.go +394 -0
  121. package/stdlib/regexp/regexp.go +231 -0
  122. package/stdlib/slices/slices.go +526 -0
  123. package/stdlib/slices/sort.go +209 -0
  124. package/stdlib/slices/zsort_cmp.go +480 -0
  125. package/stdlib/slices/zsort_ordered.go +482 -0
  126. package/stdlib/sort/sort.go +500 -0
  127. package/stdlib/sort/zsort_func.go +480 -0
  128. package/stdlib/sort/zsort_iface.go +480 -0
  129. package/stdlib/strconv/float.go +1699 -0
  130. package/stdlib/strconv/isprint.go +752 -0
  131. package/stdlib/strconv/quote.go +526 -0
  132. package/stdlib/strconv/strconv.go +616 -0
  133. package/stdlib/strings/builder.go +95 -0
  134. package/stdlib/strings/reader.go +163 -0
  135. package/stdlib/strings/replacer.go +102 -0
  136. package/stdlib/strings/strings.go +807 -0
  137. package/stdlib/sync/sync.go +268 -0
  138. package/stdlib/testing/async_js.go +61 -0
  139. package/stdlib/testing/benchmark.go +297 -0
  140. package/stdlib/testing/testing.go +523 -0
  141. package/stdlib/time/duration.go +233 -0
  142. package/stdlib/time/format.go +745 -0
  143. package/stdlib/time/parse.go +790 -0
  144. package/stdlib/time/sleep_js.go +63 -0
  145. package/stdlib/time/time.go +834 -0
  146. package/stdlib/unicode/unicode.go +250 -0
  147. package/stdlib/unicode/utf8/utf8.go +464 -0
  148. package/src/backend/js/stdlib/base64.js +0 -12
  149. package/src/backend/js/stdlib/binary.js +0 -102
  150. package/src/backend/js/stdlib/bits.js +0 -46
  151. package/src/backend/js/stdlib/builder.js +0 -63
  152. package/src/backend/js/stdlib/bytes.js +0 -122
  153. package/src/backend/js/stdlib/errors.js +0 -44
  154. package/src/backend/js/stdlib/fmt.js +0 -178
  155. package/src/backend/js/stdlib/gom.js +0 -155
  156. package/src/backend/js/stdlib/hex.js +0 -17
  157. package/src/backend/js/stdlib/html.js +0 -20
  158. package/src/backend/js/stdlib/io.js +0 -137
  159. package/src/backend/js/stdlib/json.js +0 -972
  160. package/src/backend/js/stdlib/maps.js +0 -45
  161. package/src/backend/js/stdlib/math.js +0 -69
  162. package/src/backend/js/stdlib/os.js +0 -13
  163. package/src/backend/js/stdlib/path.js +0 -48
  164. package/src/backend/js/stdlib/rand.js +0 -32
  165. package/src/backend/js/stdlib/regexp.js +0 -54
  166. package/src/backend/js/stdlib/sha256.js +0 -12
  167. package/src/backend/js/stdlib/shared.js +0 -17
  168. package/src/backend/js/stdlib/simd.js +0 -24
  169. package/src/backend/js/stdlib/slices.js +0 -77
  170. package/src/backend/js/stdlib/sort.js +0 -30
  171. package/src/backend/js/stdlib/strconv.js +0 -74
  172. package/src/backend/js/stdlib/strings.js +0 -222
  173. package/src/backend/js/stdlib/sync.js +0 -13
  174. package/src/backend/js/stdlib/testing.js +0 -34
  175. package/src/backend/js/stdlib/time.js +0 -128
  176. package/src/backend/js/stdlib/unicode.js +0 -25
  177. package/src/backend/js/stdlib/utf8.js +0 -26
  178. package/src/backend/wasm/const-fold.js +0 -205
  179. package/src/backend/wasm/emit-stdlib.js +0 -13
  180. package/src/backend/wasm/stdlib/bytes.js +0 -5039
  181. package/src/backend/wasm/stdlib/core.js +0 -8903
  182. package/src/backend/wasm/stdlib/io.js +0 -2161
  183. package/src/backend/wasm/stdlib/packages.js +0 -2400
  184. package/src/backend/wasm/stdlib/pure.js +0 -720
  185. package/src/backend/wasm/stdlib/time.js +0 -1200
  186. package/src/typechecker/stdlib/core.js +0 -801
  187. package/src/typechecker/stdlib/extended.js +0 -914
  188. package/src/typechecker/stdlib.js +0 -22
  189. /package/src/{asset-manager.js → cli/asset-manager.js} +0 -0
  190. /package/src/{colors.js → cli/colors.js} +0 -0
  191. /package/src/{dev-server.js → cli/dev-server.js} +0 -0
  192. /package/src/{minifier.js → cli/minifier.js} +0 -0
  193. /package/src/{project-config.js → cli/project-config.js} +0 -0
  194. /package/src/{pwa.js → cli/pwa.js} +0 -0
@@ -0,0 +1,163 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Overlay on the emitter-backed strings package: Reader written in Go over the
6
+ // real package's algorithm. GoFront strings are host strings whose indexes
7
+ // are not UTF-8 byte offsets, so the Reader holds the UTF-8 bytes of the
8
+ // string it was created from.
9
+ package strings
10
+
11
+ import (
12
+ "errors"
13
+ "io"
14
+ "unicode/utf8"
15
+ )
16
+
17
+ // A Reader implements the [io.Reader], [io.ReaderAt], [io.WriterTo], [io.Seeker],
18
+ // [io.ByteScanner], and [io.RuneScanner] interfaces by reading from
19
+ // a string.
20
+ // Unlike a [Buffer], a Reader is read-only and supports seeking.
21
+ // The zero value for Reader operates like a Reader of an empty string.
22
+ type Reader struct {
23
+ s []byte
24
+ i int64 // current reading index
25
+ prevRune int // index of previous rune; or < 0
26
+ }
27
+
28
+ // Len returns the number of bytes of the unread portion of the
29
+ // string.
30
+ func (r *Reader) Len() int {
31
+ if r.i >= int64(len(r.s)) {
32
+ return 0
33
+ }
34
+ return int(int64(len(r.s)) - r.i)
35
+ }
36
+
37
+ // Size returns the original length of the underlying string.
38
+ // Size is the number of bytes available for reading via [Reader.ReadAt].
39
+ // The result is unaffected by any method calls except [Reader.Reset].
40
+ func (r *Reader) Size() int64 { return int64(len(r.s)) }
41
+
42
+ // Read implements the [io.Reader] interface.
43
+ func (r *Reader) Read(b []byte) (n int, err error) {
44
+ if r.i >= int64(len(r.s)) {
45
+ return 0, io.EOF
46
+ }
47
+ r.prevRune = -1
48
+ n = copy(b, r.s[r.i:])
49
+ r.i += int64(n)
50
+ return
51
+ }
52
+
53
+ // ReadAt implements the [io.ReaderAt] interface.
54
+ func (r *Reader) ReadAt(b []byte, off int64) (n int, err error) {
55
+ // cannot modify state - see io.ReaderAt
56
+ if off < 0 {
57
+ return 0, errors.New("strings.Reader.ReadAt: negative offset")
58
+ }
59
+ if off >= int64(len(r.s)) {
60
+ return 0, io.EOF
61
+ }
62
+ n = copy(b, r.s[off:])
63
+ if n < len(b) {
64
+ err = io.EOF
65
+ }
66
+ return
67
+ }
68
+
69
+ // ReadByte implements the [io.ByteReader] interface.
70
+ func (r *Reader) ReadByte() (byte, error) {
71
+ r.prevRune = -1
72
+ if r.i >= int64(len(r.s)) {
73
+ return 0, io.EOF
74
+ }
75
+ b := r.s[r.i]
76
+ r.i++
77
+ return b, nil
78
+ }
79
+
80
+ // UnreadByte complements [Reader.ReadByte] in implementing the [io.ByteScanner] interface.
81
+ func (r *Reader) UnreadByte() error {
82
+ if r.i <= 0 {
83
+ return errors.New("strings.Reader.UnreadByte: at beginning of string")
84
+ }
85
+ r.prevRune = -1
86
+ r.i--
87
+ return nil
88
+ }
89
+
90
+ // ReadRune implements the [io.RuneReader] interface.
91
+ func (r *Reader) ReadRune() (ch rune, size int, err error) {
92
+ if r.i >= int64(len(r.s)) {
93
+ r.prevRune = -1
94
+ return 0, 0, io.EOF
95
+ }
96
+ r.prevRune = int(r.i)
97
+ if c := r.s[r.i]; c < utf8.RuneSelf {
98
+ r.i++
99
+ return rune(c), 1, nil
100
+ }
101
+ ch, size = utf8.DecodeRune(r.s[r.i:])
102
+ r.i += int64(size)
103
+ return
104
+ }
105
+
106
+ // UnreadRune complements [Reader.ReadRune] in implementing the [io.RuneScanner] interface.
107
+ func (r *Reader) UnreadRune() error {
108
+ if r.i <= 0 {
109
+ return errors.New("strings.Reader.UnreadRune: at beginning of string")
110
+ }
111
+ if r.prevRune < 0 {
112
+ return errors.New("strings.Reader.UnreadRune: previous operation was not ReadRune")
113
+ }
114
+ r.i = int64(r.prevRune)
115
+ r.prevRune = -1
116
+ return nil
117
+ }
118
+
119
+ // Seek implements the [io.Seeker] interface.
120
+ func (r *Reader) Seek(offset int64, whence int) (int64, error) {
121
+ r.prevRune = -1
122
+ var abs int64
123
+ switch whence {
124
+ case io.SeekStart:
125
+ abs = offset
126
+ case io.SeekCurrent:
127
+ abs = r.i + offset
128
+ case io.SeekEnd:
129
+ abs = int64(len(r.s)) + offset
130
+ default:
131
+ return 0, errors.New("strings.Reader.Seek: invalid whence")
132
+ }
133
+ if abs < 0 {
134
+ return 0, errors.New("strings.Reader.Seek: negative position")
135
+ }
136
+ r.i = abs
137
+ return abs, nil
138
+ }
139
+
140
+ // WriteTo implements the [io.WriterTo] interface.
141
+ func (r *Reader) WriteTo(w io.Writer) (n int64, err error) {
142
+ r.prevRune = -1
143
+ if r.i >= int64(len(r.s)) {
144
+ return 0, nil
145
+ }
146
+ b := r.s[r.i:]
147
+ m, err := w.Write(b)
148
+ if m > len(b) {
149
+ panic("strings.Reader.WriteTo: invalid Write count")
150
+ }
151
+ r.i += int64(m)
152
+ n = int64(m)
153
+ if m != len(b) && err == nil {
154
+ err = io.ErrShortWrite
155
+ }
156
+ return
157
+ }
158
+
159
+ // Reset resets the [Reader] to be reading from s.
160
+ func (r *Reader) Reset(s string) { *r = Reader{[]byte(s), 0, -1} }
161
+
162
+ // NewReader returns a new [Reader] reading from s.
163
+ func NewReader(s string) *Reader { return &Reader{[]byte(s), 0, -1} }
@@ -0,0 +1,102 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Overlay on the emitter-backed strings package: Replacer written in Go.
6
+ // Replacements run in the order they appear in the target string without
7
+ // overlapping, and the old strings are tried in argument order, with an
8
+ // empty old string never matching twice at the same position, as in Go's
9
+ // generic replacer.
10
+ package strings
11
+
12
+ import "io"
13
+
14
+ // Replacer replaces a list of strings with replacements.
15
+ // It is safe for concurrent use by multiple goroutines.
16
+ type Replacer struct {
17
+ oldnew []string
18
+ }
19
+
20
+ // NewReplacer returns a new Replacer from a list of old, new string
21
+ // pairs. It panics if given an odd number of arguments.
22
+ func NewReplacer(oldnew ...string) *Replacer {
23
+ if len(oldnew)%2 == 1 {
24
+ panic("strings.NewReplacer: odd argument count")
25
+ }
26
+ return &Replacer{oldnew: append([]string(nil), oldnew...)}
27
+ }
28
+
29
+ // match returns the replacement chosen at the start of s and the length of
30
+ // the old string it replaces; the first old string in argument order that is
31
+ // a prefix of s wins, and an empty one is skipped when skipEmpty is set.
32
+ func (r *Replacer) match(s string, skipEmpty bool) (val string, keylen int, ok bool) {
33
+ for i := 0; i < len(r.oldnew); i += 2 {
34
+ old := r.oldnew[i]
35
+ if skipEmpty && len(old) == 0 {
36
+ continue
37
+ }
38
+ if len(old) <= len(s) && s[:len(old)] == old {
39
+ return r.oldnew[i+1], len(old), true
40
+ }
41
+ }
42
+ return "", 0, false
43
+ }
44
+
45
+ // Replace returns a copy of s with all replacements performed.
46
+ func (r *Replacer) Replace(s string) string {
47
+ var out []byte
48
+ changed := false
49
+ last := 0
50
+ prevMatchEmpty := false
51
+ for i := 0; i <= len(s); {
52
+ val, keylen, ok := r.match(s[i:], prevMatchEmpty)
53
+ prevMatchEmpty = ok && keylen == 0
54
+ if ok {
55
+ changed = true
56
+ out = append(out, s[last:i]...)
57
+ out = append(out, val...)
58
+ i += keylen
59
+ last = i
60
+ continue
61
+ }
62
+ i++
63
+ }
64
+ if !changed {
65
+ return s
66
+ }
67
+ out = append(out, s[last:]...)
68
+ return string(out)
69
+ }
70
+
71
+ // WriteString writes s to w with all replacements performed.
72
+ func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error) {
73
+ last := 0
74
+ prevMatchEmpty := false
75
+ for i := 0; i <= len(s); {
76
+ val, keylen, ok := r.match(s[i:], prevMatchEmpty)
77
+ prevMatchEmpty = ok && keylen == 0
78
+ if ok {
79
+ var wn int
80
+ wn, err = io.WriteString(w, s[last:i])
81
+ n += wn
82
+ if err != nil {
83
+ return
84
+ }
85
+ wn, err = io.WriteString(w, val)
86
+ n += wn
87
+ if err != nil {
88
+ return
89
+ }
90
+ i += keylen
91
+ last = i
92
+ continue
93
+ }
94
+ i++
95
+ }
96
+ if last != len(s) {
97
+ var wn int
98
+ wn, err = io.WriteString(w, s[last:])
99
+ n += wn
100
+ }
101
+ return
102
+ }