gofront 1.6.1 → 1.8.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 (132) hide show
  1. package/README.md +45 -49
  2. package/package.json +12 -8
  3. package/src/backend/js/expressions.js +1627 -148
  4. package/src/backend/js/fmt-runtime.js +573 -0
  5. package/src/backend/js/index.js +508 -102
  6. package/src/backend/js/runtime.js +1997 -106
  7. package/src/backend/js/statements.js +931 -87
  8. package/src/backend/js/stdlib/bits.js +87 -14
  9. package/src/backend/js/stdlib/builder.js +41 -6
  10. package/src/backend/js/stdlib/bytes.js +253 -7
  11. package/src/backend/js/stdlib/errors.js +7 -1
  12. package/src/backend/js/stdlib/fmt.js +349 -10
  13. package/src/backend/js/stdlib/index.js +19 -2
  14. package/src/backend/js/stdlib/json.js +1167 -0
  15. package/src/backend/js/stdlib/maps.js +0 -8
  16. package/src/backend/js/stdlib/math.js +17 -1
  17. package/src/backend/js/stdlib/simd.js +34 -0
  18. package/src/backend/js/stdlib/slices.js +36 -6
  19. package/src/backend/js/stdlib/strconv.js +10 -5
  20. package/src/backend/js/stdlib/strings.js +83 -4
  21. package/src/backend/js/stdlib/testing.js +7 -0
  22. package/src/backend/js/stdlib/time.js +79 -55
  23. package/src/backend/js/stdlib/unicode.js +1 -1
  24. package/src/backend/js/stdlib/utf8.js +1 -1
  25. package/src/backend/js/templ.js +38 -76
  26. package/src/backend/js/type-info.js +272 -0
  27. package/src/backend/shared/fmt-types.js +188 -0
  28. package/src/backend/wasm/boundary.js +446 -72
  29. package/src/backend/wasm/emit-builtins.js +320 -13
  30. package/src/backend/wasm/emit-exprs.js +1404 -199
  31. package/src/backend/wasm/emit-maps.js +61 -13
  32. package/src/backend/wasm/emit-stmts.js +1359 -164
  33. package/src/backend/wasm/emit.js +518 -74
  34. package/src/backend/wasm/encode.js +128 -13
  35. package/src/backend/wasm/globals.js +452 -0
  36. package/src/backend/wasm/index.js +194 -2489
  37. package/src/backend/wasm/method-expr.js +381 -0
  38. package/src/backend/wasm/module-emitter.js +2240 -0
  39. package/src/backend/wasm/monomorph.js +62 -4
  40. package/src/backend/wasm/optimize.js +4 -2
  41. package/src/backend/wasm/prescan.js +397 -0
  42. package/src/backend/wasm/stdlib/bytes.js +1804 -127
  43. package/src/backend/wasm/stdlib/core.js +1574 -199
  44. package/src/backend/wasm/stdlib/index.js +3 -5
  45. package/src/backend/wasm/stdlib/io.js +1567 -150
  46. package/src/backend/wasm/stdlib/packages.js +2 -0
  47. package/src/backend/wasm/stdlib/simd.js +499 -0
  48. package/src/backend/wasm/stdlib/time.js +1041 -12
  49. package/src/backend/wasm/types.js +221 -15
  50. package/src/backend/wasm/variadic.js +93 -0
  51. package/src/backend/wasm/wat.js +84 -20
  52. package/src/{cli-core.js → cli/cli-core.js} +236 -10
  53. package/src/{test-runner.js → cli/test-runner.js} +332 -39
  54. package/src/{vendor.js → cli/vendor.js} +89 -15
  55. package/src/compiler.js +107 -269
  56. package/src/dts-parser.js +71 -14
  57. package/src/index.js +15 -169
  58. package/src/{lexer.js → lexer/lexer.js} +102 -55
  59. package/src/{tokens.js → lexer/tokens.js} +1 -0
  60. package/src/link/sourcemap.js +97 -0
  61. package/src/link/stdlib.js +515 -0
  62. package/src/link/wasm.js +294 -0
  63. package/src/lower/bounds.js +394 -0
  64. package/src/lower/boxing.js +1 -6
  65. package/src/lower/captures.js +176 -32
  66. package/src/lower/embedding.js +2 -1
  67. package/src/lower/index.js +26 -18
  68. package/src/lower/json-codecs.js +1398 -0
  69. package/src/lower/ownership.js +22 -1
  70. package/src/lower/range.js +86 -1
  71. package/src/lower/reachability.js +132 -0
  72. package/src/parser/declarations.js +58 -13
  73. package/src/parser/expressions.js +29 -7
  74. package/src/parser/index.js +2 -1
  75. package/src/parser/statements.js +37 -22
  76. package/src/parser/struct-tag.js +144 -0
  77. package/src/{templ-parser.js → parser/templ.js} +138 -15
  78. package/src/parser/types.js +130 -13
  79. package/src/resolver.js +22 -1
  80. package/src/typechecker/assignability.js +215 -11
  81. package/src/typechecker/const-fold.js +356 -0
  82. package/src/typechecker/constants.js +256 -0
  83. package/src/typechecker/expressions.js +960 -99
  84. package/src/typechecker/index.js +491 -72
  85. package/src/typechecker/init-order.js +330 -0
  86. package/src/typechecker/resolve.js +596 -52
  87. package/src/typechecker/statements.js +157 -17
  88. package/src/typechecker/stdlib/core.js +333 -55
  89. package/src/typechecker/stdlib/excluded.js +898 -0
  90. package/src/typechecker/stdlib/extended.js +359 -26
  91. package/src/typechecker/{stdlib.js → stdlib/index.js} +6 -4
  92. package/src/typechecker/stdlib/simd.js +123 -0
  93. package/src/typechecker/termination.js +1 -1
  94. package/src/typechecker/types.js +165 -26
  95. package/stdlib/bytes/iter.go +192 -0
  96. package/stdlib/bytes/search.go +240 -0
  97. package/stdlib/bytes/split.go +218 -0
  98. package/stdlib/cmp/cmp.go +65 -0
  99. package/stdlib/encoding/json/errors.go +31 -0
  100. package/stdlib/encoding/json/indent.go +71 -0
  101. package/stdlib/encoding/json/number.go +12 -0
  102. package/stdlib/encoding/json/stream.go +173 -0
  103. package/stdlib/errors/overlay.go +12 -0
  104. package/stdlib/hash/hash.go +53 -0
  105. package/stdlib/internal/jsonrt/dec.go +738 -0
  106. package/stdlib/internal/jsonrt/enc.go +366 -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 +649 -0
  111. package/stdlib/io/io.go +346 -0
  112. package/stdlib/iter/iter.go +18 -0
  113. package/stdlib/maps/iter.go +65 -0
  114. package/stdlib/math/extra.go +270 -0
  115. package/stdlib/slices/extra.go +73 -0
  116. package/stdlib/slices/iter.go +113 -0
  117. package/stdlib/sort/sort.go +561 -0
  118. package/stdlib/strconv/quote.go +341 -0
  119. package/stdlib/strings/extra.go +35 -0
  120. package/stdlib/strings/iter.go +122 -0
  121. package/stdlib/sync/extra.go +105 -0
  122. package/stdlib/unicode/unicode.go +112 -0
  123. package/stdlib/unicode/utf8/bytes.go +239 -0
  124. package/src/backend/wasm/const-fold.js +0 -205
  125. package/src/backend/wasm/emit-stdlib.js +0 -13
  126. /package/src/{asset-manager.js → cli/asset-manager.js} +0 -0
  127. /package/src/{colors.js → cli/colors.js} +0 -0
  128. /package/src/{dev-server.js → cli/dev-server.js} +0 -0
  129. /package/src/{minifier.js → cli/minifier.js} +0 -0
  130. /package/src/{project-config.js → cli/project-config.js} +0 -0
  131. /package/src/{pwa.js → cli/pwa.js} +0 -0
  132. /package/src/{templ-lexer.js → lexer/templ-lexer.js} +0 -0
@@ -0,0 +1,73 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Overlay on the emitter-backed slices package: comparison and repetition
6
+ // members written in Go and merged into the slices namespace. The
7
+ // checker has no core types for type parameters, so these take []E rather
8
+ // than Go's S ~[]E and Repeat returns []E.
9
+ package slices
10
+
11
+ // EqualFunc reports whether two slices are equal using an equality
12
+ // function on each pair of elements. If the lengths are different,
13
+ // EqualFunc returns false. Otherwise, the elements are compared in
14
+ // increasing index order, and the comparison stops at the first index
15
+ // for which eq returns false.
16
+ func EqualFunc[E1, E2 any](s1 []E1, s2 []E2, eq func(E1, E2) bool) bool {
17
+ if len(s1) != len(s2) {
18
+ return false
19
+ }
20
+ for i, v1 := range s1 {
21
+ v2 := s2[i]
22
+ if !eq(v1, v2) {
23
+ return false
24
+ }
25
+ }
26
+ return true
27
+ }
28
+
29
+ // CompareFunc is like Compare but uses a custom comparison function on each
30
+ // pair of elements.
31
+ // The result is the first non-zero result of cmp; if cmp always
32
+ // returns 0 the result is 0 if len(s1) == len(s2), -1 if len(s1) < len(s2),
33
+ // and +1 if len(s1) > len(s2).
34
+ func CompareFunc[E1, E2 any](s1 []E1, s2 []E2, cmp func(E1, E2) int) int {
35
+ for i, v1 := range s1 {
36
+ if i >= len(s2) {
37
+ return +1
38
+ }
39
+ v2 := s2[i]
40
+ if c := cmp(v1, v2); c != 0 {
41
+ return c
42
+ }
43
+ }
44
+ if len(s1) < len(s2) {
45
+ return -1
46
+ }
47
+ return 0
48
+ }
49
+
50
+ // repeatMaxInt is the largest int, as the overflow bound of Repeat.
51
+ const repeatMaxInt = 1<<63 - 1
52
+
53
+ // Repeat returns a new slice that repeats the provided slice the given number of times.
54
+ // The result has length and capacity (len(x) * count).
55
+ // The result is never nil.
56
+ // Repeat panics if count is negative or if the result of (len(x) * count)
57
+ // overflows.
58
+ func Repeat[E any](x []E, count int) []E {
59
+ if count < 0 {
60
+ panic("cannot be negative")
61
+ }
62
+
63
+ if len(x) > 0 && count > repeatMaxInt/len(x) {
64
+ panic("the result of (len(x) * count) overflows")
65
+ }
66
+
67
+ newslice := make([]E, len(x)*count)
68
+ n := copy(newslice, x)
69
+ for n < len(newslice) {
70
+ n += copy(newslice[n:], newslice[:n])
71
+ }
72
+ return newslice
73
+ }
@@ -0,0 +1,113 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Overlay on the emitter-backed slices package: the iterator members are
6
+ // written in Go over iter.Seq and iter.Seq2 and merged into the slices
7
+ // namespace. Unqualified references to emitter members (Sort, SortFunc,
8
+ // SortStableFunc) resolve to the emitter implementation.
9
+ package slices
10
+
11
+ import (
12
+ "cmp"
13
+ "iter"
14
+ )
15
+
16
+ // All returns an iterator over index-value pairs in the slice
17
+ // in the usual order.
18
+ func All[E any](s []E) iter.Seq2[int, E] {
19
+ return func(yield func(int, E) bool) {
20
+ for i, v := range s {
21
+ if !yield(i, v) {
22
+ return
23
+ }
24
+ }
25
+ }
26
+ }
27
+
28
+ // Backward returns an iterator over index-value pairs in the slice,
29
+ // traversing it backward with descending indices.
30
+ func Backward[E any](s []E) iter.Seq2[int, E] {
31
+ return func(yield func(int, E) bool) {
32
+ for i := len(s) - 1; i >= 0; i-- {
33
+ if !yield(i, s[i]) {
34
+ return
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ // Values returns an iterator that yields the slice elements in order.
41
+ func Values[E any](s []E) iter.Seq[E] {
42
+ return func(yield func(E) bool) {
43
+ for _, v := range s {
44
+ if !yield(v) {
45
+ return
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ // AppendSeq appends the values from seq to the slice and
52
+ // returns the extended slice.
53
+ func AppendSeq[E any](s []E, seq iter.Seq[E]) []E {
54
+ for v := range seq {
55
+ s = append(s, v)
56
+ }
57
+ return s
58
+ }
59
+
60
+ // Collect collects values from seq into a new slice and returns it.
61
+ func Collect[E any](seq iter.Seq[E]) []E {
62
+ var s []E
63
+ return AppendSeq(s, seq)
64
+ }
65
+
66
+ // Sorted collects values from seq into a new slice, sorts the slice,
67
+ // and returns it.
68
+ func Sorted[E cmp.Ordered](seq iter.Seq[E]) []E {
69
+ s := Collect(seq)
70
+ Sort(s)
71
+ return s
72
+ }
73
+
74
+ // SortedFunc collects values from seq into a new slice, sorts the slice
75
+ // using the comparison function, and returns it.
76
+ func SortedFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E {
77
+ s := Collect(seq)
78
+ SortFunc(s, cmp)
79
+ return s
80
+ }
81
+
82
+ // SortedStableFunc collects values from seq into a new slice.
83
+ // It then sorts the slice while keeping the original order of equal elements,
84
+ // using the comparison function to compare elements.
85
+ // It returns the new slice.
86
+ func SortedStableFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E {
87
+ s := Collect(seq)
88
+ SortStableFunc(s, cmp)
89
+ return s
90
+ }
91
+
92
+ // Chunk returns an iterator over consecutive sub-slices of up to n elements
93
+ // of s. All but the last sub-slice will have size n. All sub-slices are
94
+ // clipped to have no capacity beyond the length. If s is empty, the sequence
95
+ // is empty: there is no empty slice in the sequence. Chunk panics if n is
96
+ // less than 1.
97
+ func Chunk[E any](s []E, n int) iter.Seq[[]E] {
98
+ if n < 1 {
99
+ panic("cannot be less than 1")
100
+ }
101
+ return func(yield func([]E) bool) {
102
+ for i := 0; i < len(s); i += n {
103
+ // Clamp the last chunk to the slice bound as necessary.
104
+ end := min(n, len(s[i:]))
105
+
106
+ // Set the capacity of each chunk so that appending to a chunk does
107
+ // not modify the original slice.
108
+ if !yield(s[i : i+end : i+end]) {
109
+ return
110
+ }
111
+ }
112
+ }
113
+ }