gofront 1.7.0 → 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.
- package/README.md +13 -13
- package/package.json +8 -37
- package/src/backend/js/expressions.js +1341 -148
- package/src/backend/js/fmt-runtime.js +573 -0
- package/src/backend/js/index.js +375 -57
- package/src/backend/js/runtime.js +1460 -133
- package/src/backend/js/statements.js +900 -86
- package/src/backend/js/stdlib/bits.js +87 -14
- package/src/backend/js/stdlib/builder.js +41 -6
- package/src/backend/js/stdlib/bytes.js +253 -7
- package/src/backend/js/stdlib/errors.js +2 -1
- package/src/backend/js/stdlib/fmt.js +349 -10
- package/src/backend/js/stdlib/index.js +8 -3
- package/src/backend/js/stdlib/json.js +247 -52
- package/src/backend/js/stdlib/maps.js +0 -8
- package/src/backend/js/stdlib/math.js +17 -1
- package/src/backend/js/stdlib/simd.js +10 -0
- package/src/backend/js/stdlib/slices.js +36 -6
- package/src/backend/js/stdlib/strconv.js +10 -5
- package/src/backend/js/stdlib/strings.js +83 -4
- package/src/backend/js/stdlib/testing.js +7 -0
- package/src/backend/js/stdlib/time.js +79 -55
- package/src/backend/js/stdlib/unicode.js +1 -1
- package/src/backend/js/stdlib/utf8.js +1 -1
- package/src/backend/js/templ.js +38 -76
- package/src/backend/js/type-info.js +272 -0
- package/src/backend/shared/fmt-types.js +188 -0
- package/src/backend/wasm/boundary.js +436 -80
- package/src/backend/wasm/emit-builtins.js +303 -13
- package/src/backend/wasm/emit-exprs.js +1397 -203
- package/src/backend/wasm/emit-maps.js +61 -13
- package/src/backend/wasm/emit-stmts.js +1359 -164
- package/src/backend/wasm/emit.js +512 -77
- package/src/backend/wasm/encode.js +43 -13
- package/src/backend/wasm/globals.js +452 -0
- package/src/backend/wasm/index.js +194 -2489
- package/src/backend/wasm/method-expr.js +381 -0
- package/src/backend/wasm/module-emitter.js +2240 -0
- package/src/backend/wasm/monomorph.js +62 -4
- package/src/backend/wasm/prescan.js +397 -0
- package/src/backend/wasm/stdlib/bytes.js +1804 -127
- package/src/backend/wasm/stdlib/core.js +1574 -199
- package/src/backend/wasm/stdlib/index.js +0 -5
- package/src/backend/wasm/stdlib/io.js +1567 -150
- package/src/backend/wasm/stdlib/packages.js +2 -0
- package/src/backend/wasm/stdlib/simd.js +293 -28
- package/src/backend/wasm/stdlib/time.js +1041 -12
- package/src/backend/wasm/types.js +200 -15
- package/src/backend/wasm/variadic.js +93 -0
- package/src/backend/wasm/wat.js +47 -20
- package/src/{cli-core.js → cli/cli-core.js} +236 -10
- package/src/{test-runner.js → cli/test-runner.js} +332 -39
- package/src/{vendor.js → cli/vendor.js} +3 -4
- package/src/compiler.js +107 -269
- package/src/index.js +15 -169
- package/src/{lexer.js → lexer/lexer.js} +102 -55
- package/src/{tokens.js → lexer/tokens.js} +1 -0
- package/src/link/sourcemap.js +97 -0
- package/src/link/stdlib.js +515 -0
- package/src/link/wasm.js +294 -0
- package/src/lower/bounds.js +394 -0
- package/src/lower/boxing.js +1 -1
- package/src/lower/captures.js +176 -32
- package/src/lower/index.js +26 -18
- package/src/lower/json-codecs.js +1398 -0
- package/src/lower/ownership.js +22 -1
- package/src/lower/range.js +86 -1
- package/src/lower/reachability.js +132 -0
- package/src/parser/declarations.js +58 -13
- package/src/parser/expressions.js +29 -7
- package/src/parser/index.js +2 -1
- package/src/parser/statements.js +37 -22
- package/src/{templ-parser.js → parser/templ.js} +138 -15
- package/src/parser/types.js +69 -9
- package/src/resolver.js +22 -1
- package/src/typechecker/assignability.js +176 -17
- package/src/typechecker/const-fold.js +356 -0
- package/src/typechecker/constants.js +256 -0
- package/src/typechecker/expressions.js +931 -122
- package/src/typechecker/index.js +459 -67
- package/src/typechecker/init-order.js +330 -0
- package/src/typechecker/resolve.js +451 -56
- package/src/typechecker/statements.js +90 -9
- package/src/typechecker/stdlib/core.js +333 -55
- package/src/typechecker/stdlib/excluded.js +898 -0
- package/src/typechecker/stdlib/extended.js +322 -26
- package/src/typechecker/{stdlib.js → stdlib/index.js} +5 -5
- package/src/typechecker/stdlib/simd.js +65 -15
- package/src/typechecker/termination.js +1 -1
- package/src/typechecker/types.js +149 -25
- package/stdlib/bytes/iter.go +192 -0
- package/stdlib/bytes/search.go +240 -0
- package/stdlib/bytes/split.go +218 -0
- package/stdlib/cmp/cmp.go +65 -0
- package/stdlib/encoding/json/errors.go +31 -0
- package/stdlib/encoding/json/indent.go +71 -0
- package/stdlib/encoding/json/number.go +12 -0
- package/stdlib/encoding/json/stream.go +173 -0
- package/stdlib/errors/overlay.go +12 -0
- package/stdlib/hash/hash.go +53 -0
- package/stdlib/internal/jsonrt/dec.go +738 -0
- package/stdlib/internal/jsonrt/enc.go +366 -0
- package/stdlib/internal/jsonrt/indent.go +135 -0
- package/stdlib/internal/jsonrt/number.go +27 -0
- package/stdlib/internal/jsonrt/reader.go +73 -0
- package/stdlib/internal/jsonrt/scanner.go +649 -0
- package/stdlib/io/io.go +346 -0
- package/stdlib/iter/iter.go +18 -0
- package/stdlib/maps/iter.go +65 -0
- package/stdlib/math/extra.go +270 -0
- package/stdlib/slices/extra.go +73 -0
- package/stdlib/slices/iter.go +113 -0
- package/stdlib/sort/sort.go +561 -0
- package/stdlib/strconv/quote.go +341 -0
- package/stdlib/strings/extra.go +35 -0
- package/stdlib/strings/iter.go +122 -0
- package/stdlib/sync/extra.go +105 -0
- package/stdlib/unicode/unicode.go +112 -0
- package/stdlib/unicode/utf8/bytes.go +239 -0
- package/src/backend/wasm/const-fold.js +0 -205
- package/src/backend/wasm/emit-stdlib.js +0 -13
- /package/src/{asset-manager.js → cli/asset-manager.js} +0 -0
- /package/src/{colors.js → cli/colors.js} +0 -0
- /package/src/{dev-server.js → cli/dev-server.js} +0 -0
- /package/src/{minifier.js → cli/minifier.js} +0 -0
- /package/src/{project-config.js → cli/project-config.js} +0 -0
- /package/src/{pwa.js → cli/pwa.js} +0 -0
- /package/src/{templ-lexer.js → lexer/templ-lexer.js} +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
//go:build gofront
|
|
2
|
+
|
|
3
|
+
//gofront:target both
|
|
4
|
+
|
|
5
|
+
package json
|
|
6
|
+
|
|
7
|
+
import (
|
|
8
|
+
"bytes"
|
|
9
|
+
"internal/jsonrt"
|
|
10
|
+
"io"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
// An Encoder writes JSON values to an output stream.
|
|
14
|
+
type Encoder struct {
|
|
15
|
+
w io.Writer
|
|
16
|
+
err error
|
|
17
|
+
prefix string
|
|
18
|
+
indent string
|
|
19
|
+
escapeHTML bool
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// NewEncoder returns a new encoder that writes to w.
|
|
23
|
+
func NewEncoder(w io.Writer) *Encoder {
|
|
24
|
+
return &Encoder{w: w, escapeHTML: true}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// SetIndent instructs the encoder to format each subsequent encoded
|
|
28
|
+
// value as if indented by the package-level function Indent.
|
|
29
|
+
// Calling SetIndent("", "") turns off indentation.
|
|
30
|
+
func (enc *Encoder) SetIndent(prefix, indent string) {
|
|
31
|
+
enc.prefix = prefix
|
|
32
|
+
enc.indent = indent
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// SetEscapeHTML specifies whether problematic HTML characters
|
|
36
|
+
// should be escaped inside JSON-quoted strings.
|
|
37
|
+
// The default behavior is true.
|
|
38
|
+
func (enc *Encoder) SetEscapeHTML(on bool) {
|
|
39
|
+
enc.escapeHTML = on
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Err returns the first error the encoder encountered, if any.
|
|
43
|
+
func (enc *Encoder) Err() error {
|
|
44
|
+
return enc.err
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// EscapeHTML returns whether HTML escaping is enabled.
|
|
48
|
+
func (enc *Encoder) EscapeHTML() bool {
|
|
49
|
+
return enc.escapeHTML
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// EncodeRaw formats b with indentation if configured and writes it to the output stream.
|
|
53
|
+
func (enc *Encoder) EncodeRaw(b []byte) error {
|
|
54
|
+
if enc.err != nil {
|
|
55
|
+
return enc.err
|
|
56
|
+
}
|
|
57
|
+
if enc.indent != "" || enc.prefix != "" {
|
|
58
|
+
var buf bytes.Buffer
|
|
59
|
+
if err := Indent(&buf, b, enc.prefix, enc.indent); err != nil {
|
|
60
|
+
return err
|
|
61
|
+
}
|
|
62
|
+
b = buf.Bytes()
|
|
63
|
+
}
|
|
64
|
+
b = append(b, '\n')
|
|
65
|
+
if _, err := enc.w.Write(b); err != nil {
|
|
66
|
+
enc.err = err
|
|
67
|
+
return err
|
|
68
|
+
}
|
|
69
|
+
return nil
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Encode writes the JSON encoding of v to the stream, followed by a newline character.
|
|
73
|
+
func (enc *Encoder) Encode(v any) error {
|
|
74
|
+
if enc.err != nil {
|
|
75
|
+
return enc.err
|
|
76
|
+
}
|
|
77
|
+
return enc.EncodeRaw(nil)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// A Decoder reads and decodes JSON values from an input stream.
|
|
81
|
+
type Decoder struct {
|
|
82
|
+
r *jsonrt.Reader
|
|
83
|
+
useNumber bool
|
|
84
|
+
disallowUnknownFields bool
|
|
85
|
+
offset int64
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// NewDecoder returns a new decoder that reads from r.
|
|
89
|
+
func NewDecoder(r io.Reader) *Decoder {
|
|
90
|
+
return &Decoder{r: jsonrt.NewReader(r)}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// UseNumber causes the Decoder to unmarshal a number into an interface{} as a
|
|
94
|
+
// Number instead of as a float64.
|
|
95
|
+
func (dec *Decoder) UseNumber() {
|
|
96
|
+
dec.useNumber = true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// DisallowUnknownFields causes the Decoder to return an error when the destination
|
|
100
|
+
// is a struct and the input contains object keys which do not match any
|
|
101
|
+
// non-ignored, exported fields in the destination.
|
|
102
|
+
func (dec *Decoder) DisallowUnknownFields() {
|
|
103
|
+
dec.disallowUnknownFields = true
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// InputOffset returns the input stream byte offset of the current decoder position.
|
|
107
|
+
// The offset gives the location of the end of the most recently returned token
|
|
108
|
+
// and the beginning of the immediately following token.
|
|
109
|
+
func (dec *Decoder) InputOffset() int64 {
|
|
110
|
+
return dec.offset
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Buffered returns a reader of the data remaining in the Decoder's
|
|
114
|
+
// buffer. The reader is valid until the next call to Decode.
|
|
115
|
+
func (dec *Decoder) Buffered() io.Reader {
|
|
116
|
+
p := dec.r.Buffered()
|
|
117
|
+
if len(p) > 0 {
|
|
118
|
+
return bytes.NewReader(p)
|
|
119
|
+
}
|
|
120
|
+
return bytes.NewReader(nil)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// More reports whether there is another element in the current array
|
|
124
|
+
// or object being parsed, or whether there is another value in the stream.
|
|
125
|
+
func (dec *Decoder) More() bool {
|
|
126
|
+
for {
|
|
127
|
+
b, err := dec.r.ReadByte()
|
|
128
|
+
if err != nil {
|
|
129
|
+
return false
|
|
130
|
+
}
|
|
131
|
+
if isSpace(b) {
|
|
132
|
+
dec.offset++
|
|
133
|
+
continue
|
|
134
|
+
}
|
|
135
|
+
dec.r.UnreadByte()
|
|
136
|
+
if b == ']' || b == '}' {
|
|
137
|
+
return false
|
|
138
|
+
}
|
|
139
|
+
return true
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ScanNext consumes whitespace, scans the next JSON value, and updates dec.offset.
|
|
144
|
+
func (dec *Decoder) ScanNext() ([]byte, error) {
|
|
145
|
+
data, skipped, err := jsonrt.ScanNext(dec.r)
|
|
146
|
+
dec.offset += skipped
|
|
147
|
+
if err != nil {
|
|
148
|
+
return nil, err
|
|
149
|
+
}
|
|
150
|
+
dec.offset += int64(len(data))
|
|
151
|
+
return data, nil
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// SetupDec configures a jsonrt.Dec with this decoder's options.
|
|
155
|
+
func (dec *Decoder) SetupDec(d *jsonrt.Dec) {
|
|
156
|
+
d.UseNumber = dec.useNumber
|
|
157
|
+
d.DisallowUnknownFields = dec.disallowUnknownFields
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
func isSpace(c byte) bool {
|
|
161
|
+
return c <= ' ' && (c == ' ' || c == '\t' || c == '\r' || c == '\n')
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Decode reads the next JSON-encoded value from its input and stores it in the
|
|
165
|
+
// value pointed to by v.
|
|
166
|
+
func (dec *Decoder) Decode(v any) error {
|
|
167
|
+
data, err := dec.ScanNext()
|
|
168
|
+
if err != nil {
|
|
169
|
+
return err
|
|
170
|
+
}
|
|
171
|
+
_ = data
|
|
172
|
+
return nil
|
|
173
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//go:build gofront
|
|
2
|
+
|
|
3
|
+
//gofront:target both
|
|
4
|
+
|
|
5
|
+
// Overlay on the emitter-backed errors package: these members are written
|
|
6
|
+
// in Go and merged into the errors namespace. Unqualified references to
|
|
7
|
+
// emitter members (New) resolve to the emitter implementation.
|
|
8
|
+
package errors
|
|
9
|
+
|
|
10
|
+
// ErrUnsupported indicates that a requested operation cannot be performed,
|
|
11
|
+
// because it is unsupported.
|
|
12
|
+
var ErrUnsupported = New("unsupported operation")
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//go:build gofront
|
|
2
|
+
|
|
3
|
+
//gofront:target both
|
|
4
|
+
|
|
5
|
+
// Package hash provides interfaces for hash functions.
|
|
6
|
+
package hash
|
|
7
|
+
|
|
8
|
+
import "io"
|
|
9
|
+
|
|
10
|
+
// Hash is the common interface implemented by all hash functions.
|
|
11
|
+
type Hash interface {
|
|
12
|
+
io.Writer
|
|
13
|
+
|
|
14
|
+
// Sum appends the current hash to b and returns the resulting slice.
|
|
15
|
+
// It does not change the underlying hash state.
|
|
16
|
+
Sum(b []byte) []byte
|
|
17
|
+
|
|
18
|
+
// Reset resets the Hash to its initial state.
|
|
19
|
+
Reset()
|
|
20
|
+
|
|
21
|
+
// Size returns the number of bytes Sum will return.
|
|
22
|
+
Size() int
|
|
23
|
+
|
|
24
|
+
// BlockSize returns the hash's underlying block size.
|
|
25
|
+
BlockSize() int
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Hash32 is the common interface implemented by all 32-bit hash functions.
|
|
29
|
+
type Hash32 interface {
|
|
30
|
+
Hash
|
|
31
|
+
Sum32() uint32
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Hash64 is the common interface implemented by all 64-bit hash functions.
|
|
35
|
+
type Hash64 interface {
|
|
36
|
+
Hash
|
|
37
|
+
Sum64() uint64
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// A Cloner is a hash function whose state can be cloned, returning a value with
|
|
41
|
+
// equivalent and independent state.
|
|
42
|
+
type Cloner interface {
|
|
43
|
+
Hash
|
|
44
|
+
Clone() (Cloner, error)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// XOF (extendable output function) is a hash function with arbitrary or unlimited output length.
|
|
48
|
+
type XOF interface {
|
|
49
|
+
io.Writer
|
|
50
|
+
Read(p []byte) (n int, err error)
|
|
51
|
+
Reset()
|
|
52
|
+
BlockSize() int
|
|
53
|
+
}
|