gofront 1.8.0 → 1.9.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/README.md +3 -3
- package/package.json +6 -5
- package/src/backend/js/expressions.js +1157 -408
- package/src/backend/js/index.js +327 -153
- package/src/backend/js/natives.js +383 -0
- package/src/backend/js/runtime.js +559 -2552
- package/src/backend/js/statements.js +670 -158
- package/src/backend/js/stdlib/index.js +45 -93
- package/src/backend/js/templ.js +32 -45
- package/src/backend/js/type-info.js +298 -19
- package/src/backend/shared/fixed-float.js +20 -0
- package/src/backend/shared/fmt-types.js +91 -170
- package/src/backend/shared/host-unicode.js +36 -0
- package/src/backend/wasm/boundary.js +490 -965
- package/src/backend/wasm/emit-builtins.js +884 -256
- package/src/backend/wasm/emit-exprs.js +185 -77
- package/src/backend/wasm/emit-maps.js +17 -367
- package/src/backend/wasm/emit-shared.js +4 -1
- package/src/backend/wasm/emit-stmts.js +524 -240
- package/src/backend/wasm/emit.js +176 -38
- package/src/backend/wasm/globals.js +48 -8
- package/src/backend/wasm/glue.js +2 -4
- package/src/backend/wasm/index.js +44 -530
- package/src/backend/wasm/method-expr.js +12 -1
- package/src/backend/wasm/module-emitter.js +299 -770
- package/src/backend/wasm/monomorph.js +139 -8
- package/src/backend/wasm/natives.js +600 -0
- package/src/backend/wasm/prescan.js +5 -153
- package/src/backend/wasm/prune-funcs.js +89 -0
- package/src/backend/wasm/stdlib/index.js +2 -32
- package/src/backend/wasm/types.js +97 -20
- package/src/backend/wasm/variadic.js +9 -4
- package/src/cli/cli-core.js +5 -1
- package/src/cli/test-runner.js +115 -342
- package/src/compiler.js +113 -130
- package/src/lexer/lexer.js +106 -11
- package/src/lexer/templ-lexer.js +61 -18
- package/src/lexer/tokens.js +1 -0
- package/src/link/stdlib.js +355 -132
- package/src/link/type-names.js +204 -0
- package/src/link/wasm.js +30 -6
- package/src/lower/bounds.js +153 -0
- package/src/lower/captures.js +92 -33
- package/src/lower/embedding.js +62 -5
- package/src/lower/errors-as.js +196 -0
- package/src/lower/fmt-formatters.js +929 -0
- package/src/lower/functions.js +225 -7
- package/src/lower/gen-types.js +293 -0
- package/src/lower/index.js +14 -2
- package/src/lower/json-codecs.js +334 -245
- package/src/lower/ownership.js +25 -7
- package/src/lower/reachability.js +69 -51
- package/src/lower/walk.js +12 -0
- package/src/parser/declarations.js +30 -5
- package/src/parser/expressions.js +111 -57
- package/src/parser/statements.js +108 -0
- package/src/parser/templ.js +44 -5
- package/src/parser/types.js +12 -0
- package/src/resolver.js +1 -2
- package/src/typechecker/assignability.js +214 -19
- package/src/typechecker/const-fold.js +70 -27
- package/src/typechecker/constants.js +156 -8
- package/src/typechecker/expressions.js +490 -108
- package/src/typechecker/index.js +346 -42
- package/src/typechecker/init-order.js +136 -40
- package/src/typechecker/operand-text.js +41 -0
- package/src/typechecker/resolve.js +490 -65
- package/src/typechecker/statements.js +288 -27
- package/src/typechecker/stdlib/excluded.js +9 -5
- package/src/typechecker/stdlib/index.js +25 -9
- package/src/typechecker/termination.js +10 -1
- package/src/typechecker/types.js +287 -575
- package/stdlib/bytes/buffer.go +479 -0
- package/stdlib/bytes/bytes.go +1010 -0
- package/stdlib/bytes/reader.go +161 -0
- package/stdlib/context/context.go +115 -0
- package/stdlib/crypto/rand/rand.go +34 -0
- package/stdlib/crypto/sha256/sha256.go +249 -0
- package/stdlib/encoding/base64/base64.go +331 -0
- package/stdlib/encoding/binary/binary.go +332 -0
- package/stdlib/encoding/hex/hex.go +140 -0
- package/stdlib/encoding/json/json.go +62 -0
- package/stdlib/errors/errors.go +174 -0
- package/stdlib/fmt/errors.go +110 -0
- package/stdlib/fmt/format.go +732 -0
- package/stdlib/fmt/print.go +1232 -0
- package/stdlib/gom/gom.go +293 -0
- package/stdlib/html/html.go +251 -0
- package/stdlib/internal/fmtrt/fmtrt.go +163 -0
- package/stdlib/internal/jsonrt/dec.go +171 -38
- package/stdlib/internal/jsonrt/enc.go +186 -36
- package/stdlib/internal/jsonrt/scanner.go +17 -8
- package/stdlib/io/io.go +157 -1
- package/stdlib/maps/maps.go +131 -0
- package/stdlib/math/bits/bits.go +507 -0
- package/stdlib/math/extra.go +16 -14
- package/stdlib/math/math.go +439 -0
- package/stdlib/math/rand/rand.go +297 -0
- package/stdlib/os/os.go +93 -0
- package/stdlib/path/filepath/filepath.go +47 -0
- package/stdlib/path/path.go +394 -0
- package/stdlib/regexp/regexp.go +231 -0
- package/stdlib/slices/slices.go +526 -0
- package/stdlib/slices/sort.go +209 -0
- package/stdlib/slices/zsort_cmp.go +480 -0
- package/stdlib/slices/zsort_ordered.go +482 -0
- package/stdlib/sort/sort.go +391 -452
- package/stdlib/sort/zsort_func.go +480 -0
- package/stdlib/sort/zsort_iface.go +480 -0
- package/stdlib/strconv/float.go +1699 -0
- package/stdlib/strconv/isprint.go +752 -0
- package/stdlib/strconv/quote.go +235 -50
- package/stdlib/strconv/strconv.go +616 -0
- package/stdlib/strings/builder.go +95 -0
- package/stdlib/strings/reader.go +163 -0
- package/stdlib/strings/replacer.go +102 -0
- package/stdlib/strings/strings.go +807 -0
- package/stdlib/sync/sync.go +268 -0
- package/stdlib/testing/async_js.go +61 -0
- package/stdlib/testing/benchmark.go +297 -0
- package/stdlib/testing/testing.go +523 -0
- package/stdlib/time/duration.go +233 -0
- package/stdlib/time/format.go +745 -0
- package/stdlib/time/parse.go +790 -0
- package/stdlib/time/sleep_js.go +63 -0
- package/stdlib/time/time.go +834 -0
- package/stdlib/unicode/unicode.go +141 -3
- package/stdlib/unicode/utf8/utf8.go +464 -0
- package/src/backend/js/fmt-runtime.js +0 -573
- package/src/backend/js/stdlib/base64.js +0 -12
- package/src/backend/js/stdlib/binary.js +0 -102
- package/src/backend/js/stdlib/bits.js +0 -119
- package/src/backend/js/stdlib/builder.js +0 -98
- package/src/backend/js/stdlib/bytes.js +0 -368
- package/src/backend/js/stdlib/errors.js +0 -45
- package/src/backend/js/stdlib/fmt.js +0 -517
- package/src/backend/js/stdlib/gom.js +0 -155
- package/src/backend/js/stdlib/hex.js +0 -17
- package/src/backend/js/stdlib/html.js +0 -20
- package/src/backend/js/stdlib/io.js +0 -137
- package/src/backend/js/stdlib/json.js +0 -1167
- package/src/backend/js/stdlib/maps.js +0 -37
- package/src/backend/js/stdlib/math.js +0 -85
- package/src/backend/js/stdlib/os.js +0 -13
- package/src/backend/js/stdlib/path.js +0 -48
- package/src/backend/js/stdlib/rand.js +0 -32
- package/src/backend/js/stdlib/regexp.js +0 -54
- package/src/backend/js/stdlib/sha256.js +0 -12
- package/src/backend/js/stdlib/shared.js +0 -17
- package/src/backend/js/stdlib/simd.js +0 -34
- package/src/backend/js/stdlib/slices.js +0 -107
- package/src/backend/js/stdlib/sort.js +0 -30
- package/src/backend/js/stdlib/strconv.js +0 -79
- package/src/backend/js/stdlib/strings.js +0 -301
- package/src/backend/js/stdlib/sync.js +0 -13
- package/src/backend/js/stdlib/testing.js +0 -41
- package/src/backend/js/stdlib/time.js +0 -152
- package/src/backend/js/stdlib/unicode.js +0 -25
- package/src/backend/js/stdlib/utf8.js +0 -26
- package/src/backend/wasm/stdlib/bytes.js +0 -6716
- package/src/backend/wasm/stdlib/core.js +0 -10278
- package/src/backend/wasm/stdlib/io.js +0 -3578
- package/src/backend/wasm/stdlib/packages.js +0 -2402
- package/src/backend/wasm/stdlib/pure.js +0 -720
- package/src/backend/wasm/stdlib/time.js +0 -2229
- package/src/typechecker/stdlib/core.js +0 -1079
- package/src/typechecker/stdlib/extended.js +0 -1210
- package/stdlib/bytes/iter.go +0 -192
- package/stdlib/bytes/search.go +0 -240
- package/stdlib/bytes/split.go +0 -218
- package/stdlib/errors/overlay.go +0 -12
- package/stdlib/maps/iter.go +0 -65
- package/stdlib/slices/extra.go +0 -73
- package/stdlib/slices/iter.go +0 -113
- package/stdlib/strings/extra.go +0 -35
- package/stdlib/strings/iter.go +0 -122
- package/stdlib/sync/extra.go +0 -105
- package/stdlib/unicode/utf8/bytes.go +0 -239
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `strings` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const STRINGS_M1 = {
|
|
6
|
-
ToUpper: "toUpperCase",
|
|
7
|
-
ToLower: "toLowerCase",
|
|
8
|
-
TrimSpace: "trim",
|
|
9
|
-
ToTitle: "toUpperCase",
|
|
10
|
-
};
|
|
11
|
-
const STRINGS_M2 = {
|
|
12
|
-
Contains: "includes",
|
|
13
|
-
HasPrefix: "startsWith",
|
|
14
|
-
HasSuffix: "endsWith",
|
|
15
|
-
Index: "indexOf",
|
|
16
|
-
LastIndex: "lastIndexOf",
|
|
17
|
-
Repeat: "repeat",
|
|
18
|
-
Split: "split",
|
|
19
|
-
};
|
|
20
|
-
const STRINGS_DISPATCH = {
|
|
21
|
-
Join: ([a, sep]) => `(${a} ?? []).join(${sep})`,
|
|
22
|
-
Count: ([s, s2]) =>
|
|
23
|
-
`((s, sep) => sep === "" ? s.length + 1 : s.split(sep).length - 1)(${s}, ${s2})`,
|
|
24
|
-
Replace: ([s, s2, s3, n]) =>
|
|
25
|
-
n === undefined
|
|
26
|
-
? `${s}.replace(${s2}, ${s3})`
|
|
27
|
-
: `((str, o, nw, cnt) => { if (cnt < 0) return str.replaceAll(o, nw); let r = ""; let i = 0; for (; cnt > 0; cnt--) { const j = str.indexOf(o, i); if (j < 0) break; r += str.slice(i, j) + nw; i = j + o.length; if (o.length === 0) { if (i >= str.length) break; r += str[i]; i++; } } return r + str.slice(i); })(${s}, ${s2}, ${s3}, ${n})`,
|
|
28
|
-
ReplaceAll: ([s, s2, s3]) => `${s}.replaceAll(${s2}, ${s3})`,
|
|
29
|
-
Trim: ([s, s2]) =>
|
|
30
|
-
`((str, cut) => { const cs = new Set(cut); let i = 0, j = str.length; while (i < j && cs.has(str[i])) i++; while (j > i && cs.has(str[j - 1])) j--; return str.slice(i, j); })(${s}, ${s2})`,
|
|
31
|
-
TrimPrefix: ([s, s2]) =>
|
|
32
|
-
`((s, pre) => s.startsWith(pre) ? s.slice(pre.length) : s)(${s}, ${s2})`,
|
|
33
|
-
TrimSuffix: ([s, s2]) =>
|
|
34
|
-
`((s, suf) => !suf.length || !s.endsWith(suf) ? s : s.slice(0, -suf.length))(${s}, ${s2})`,
|
|
35
|
-
TrimLeft: ([s, s2]) =>
|
|
36
|
-
`((str, cut) => { const cs = new Set(cut); let i = 0; while (i < str.length && cs.has(str[i])) i++; return str.slice(i); })(${s}, ${s2})`,
|
|
37
|
-
TrimRight: ([s, s2]) =>
|
|
38
|
-
`((str, cut) => { const cs = new Set(cut); let j = str.length; while (j > 0 && cs.has(str[j - 1])) j--; return str.slice(0, j); })(${s}, ${s2})`,
|
|
39
|
-
EqualFold: ([s, s2]) => `${s}.toLowerCase() === ${s2}.toLowerCase()`,
|
|
40
|
-
Fields: ([s]) =>
|
|
41
|
-
`(${s}).split(/[ \\t\\n\\v\\f\\r\\u0085\\u00A0\\u1680\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]+/).filter(p => p !== "")`,
|
|
42
|
-
FieldsFunc: ([s, f]) =>
|
|
43
|
-
`((s, fn) => { const res = []; const runes = Array.from(s ?? ""); let cur = ""; for (const ch of runes) { const cp = ch.codePointAt(0); if (fn(cp)) { if (cur.length > 0) { res.push(cur); cur = ""; } } else { cur += ch; } } if (cur.length > 0) res.push(cur); return res; })(${s}, ${f})`,
|
|
44
|
-
Cut: ([s, s2]) =>
|
|
45
|
-
`((s, sep) => { const i = s.indexOf(sep); return i < 0 ? [s, "", false] : [s.slice(0, i), s.slice(i + sep.length), true]; })(${s}, ${s2})`,
|
|
46
|
-
CutPrefix: ([s, s2]) =>
|
|
47
|
-
`((str, pre) => str.startsWith(pre) ? [str.slice(pre.length), true] : [str, false])(${s}, ${s2})`,
|
|
48
|
-
CutSuffix: ([s, s2]) =>
|
|
49
|
-
`((str, suf) => { if (suf === "") return [str, true]; return str.endsWith(suf) ? [str.slice(0, -suf.length), true] : [str, false]; })(${s}, ${s2})`,
|
|
50
|
-
SplitN: ([s, s2, s3]) =>
|
|
51
|
-
`((s, sep, n) => {
|
|
52
|
-
if (n === 0) return null;
|
|
53
|
-
if (n < 0) return sep === "" ? [...s] : s.split(sep);
|
|
54
|
-
if (sep === "") {
|
|
55
|
-
const chars = [...s];
|
|
56
|
-
if (chars.length <= n) return chars;
|
|
57
|
-
const r = chars.slice(0, n - 1);
|
|
58
|
-
r.push(chars.slice(n - 1).join(""));
|
|
59
|
-
return r;
|
|
60
|
-
}
|
|
61
|
-
const r = [];
|
|
62
|
-
let cur = s;
|
|
63
|
-
for (let i = 1; i < n && cur.length; i++) {
|
|
64
|
-
const j = cur.indexOf(sep);
|
|
65
|
-
if (j < 0) break;
|
|
66
|
-
r.push(cur.slice(0, j));
|
|
67
|
-
cur = cur.slice(j + sep.length);
|
|
68
|
-
}
|
|
69
|
-
r.push(cur);
|
|
70
|
-
return r;
|
|
71
|
-
})(${s}, ${s2}, ${s3})`,
|
|
72
|
-
SplitAfter: ([s, s2]) =>
|
|
73
|
-
`((s, sep) => {
|
|
74
|
-
if (sep === "") return [...s];
|
|
75
|
-
const r = [];
|
|
76
|
-
let cur = s;
|
|
77
|
-
while (true) {
|
|
78
|
-
const j = cur.indexOf(sep);
|
|
79
|
-
if (j < 0) { r.push(cur); break; }
|
|
80
|
-
r.push(cur.slice(0, j + sep.length));
|
|
81
|
-
cur = cur.slice(j + sep.length);
|
|
82
|
-
}
|
|
83
|
-
return r;
|
|
84
|
-
})(${s}, ${s2})`,
|
|
85
|
-
SplitAfterN: ([s, s2, s3]) =>
|
|
86
|
-
`((s, sep, n) => {
|
|
87
|
-
if (n === 0) return null;
|
|
88
|
-
if (sep === "") {
|
|
89
|
-
const chars = [...s];
|
|
90
|
-
if (n < 0 || chars.length <= n) return chars;
|
|
91
|
-
const r = chars.slice(0, n - 1);
|
|
92
|
-
r.push(chars.slice(n - 1).join(""));
|
|
93
|
-
return r;
|
|
94
|
-
}
|
|
95
|
-
const r = [];
|
|
96
|
-
let cur = s;
|
|
97
|
-
for (let i = 1; (n < 0 || i < n) && cur.length; i++) {
|
|
98
|
-
const j = cur.indexOf(sep);
|
|
99
|
-
if (j < 0) break;
|
|
100
|
-
r.push(cur.slice(0, j + sep.length));
|
|
101
|
-
cur = cur.slice(j + sep.length);
|
|
102
|
-
}
|
|
103
|
-
r.push(cur);
|
|
104
|
-
return r;
|
|
105
|
-
})(${s}, ${s2}, ${s3})`,
|
|
106
|
-
IndexAny: ([s, s2]) =>
|
|
107
|
-
`((s, chars) => { let m = -1; for (const c of chars) { const i = s.indexOf(c); if (i >= 0 && (m < 0 || i < m)) m = i; } return m; })(${s}, ${s2})`,
|
|
108
|
-
LastIndexAny: ([s, s2]) =>
|
|
109
|
-
`((s, chars) => { let m = -1; for (const c of chars) { const i = s.lastIndexOf(c); if (i > m) m = i; } return m; })(${s}, ${s2})`,
|
|
110
|
-
ContainsAny: ([s, s2]) => `[...(${s2})].some(c => (${s}).includes(c))`,
|
|
111
|
-
ContainsRune: ([s, s2]) => `(${s}).includes(String.fromCodePoint(${s2}))`,
|
|
112
|
-
IndexRune: ([s, s2]) => `(${s}).indexOf(String.fromCodePoint(${s2}))`,
|
|
113
|
-
IndexByte: ([s, s2]) => `(${s}).indexOf(String.fromCharCode(${s2}))`,
|
|
114
|
-
LastIndexByte: ([s, s2]) => `(${s}).lastIndexOf(String.fromCharCode(${s2}))`,
|
|
115
|
-
Map: ([s, s2]) =>
|
|
116
|
-
`((f, s) => { let out = ""; for (const c of s) { const r = f(c.codePointAt(0)); if (r >= 0) out += String.fromCodePoint(r); } return out; })(${s}, ${s2})`,
|
|
117
|
-
Title: ([s]) => `(${s}).replace(/\\b\\w/g, c => c.toUpperCase())`,
|
|
118
|
-
TrimFunc: ([s, s2]) =>
|
|
119
|
-
`((s, f) => {
|
|
120
|
-
let l = 0, r = s.length;
|
|
121
|
-
while (l < r) {
|
|
122
|
-
const cp = s.codePointAt(l);
|
|
123
|
-
if (!f(cp)) break;
|
|
124
|
-
l += cp > 0xFFFF ? 2 : 1;
|
|
125
|
-
}
|
|
126
|
-
while (r > l) {
|
|
127
|
-
let cp, step;
|
|
128
|
-
if (r > 1 && s.charCodeAt(r - 1) >= 0xDC00 && s.charCodeAt(r - 1) <= 0xDFFF &&
|
|
129
|
-
s.charCodeAt(r - 2) >= 0xD800 && s.charCodeAt(r - 2) <= 0xDBFF) {
|
|
130
|
-
cp = s.codePointAt(r - 2);
|
|
131
|
-
step = 2;
|
|
132
|
-
} else {
|
|
133
|
-
cp = s.codePointAt(r - 1);
|
|
134
|
-
step = 1;
|
|
135
|
-
}
|
|
136
|
-
if (!f(cp)) break;
|
|
137
|
-
r -= step;
|
|
138
|
-
}
|
|
139
|
-
return s.slice(l, r);
|
|
140
|
-
})(${s}, ${s2})`,
|
|
141
|
-
TrimLeftFunc: ([s, s2]) =>
|
|
142
|
-
`((s, f) => {
|
|
143
|
-
let l = 0;
|
|
144
|
-
while (l < s.length) {
|
|
145
|
-
const cp = s.codePointAt(l);
|
|
146
|
-
if (!f(cp)) break;
|
|
147
|
-
l += cp > 0xFFFF ? 2 : 1;
|
|
148
|
-
}
|
|
149
|
-
return s.slice(l);
|
|
150
|
-
})(${s}, ${s2})`,
|
|
151
|
-
TrimRightFunc: ([s, s2]) =>
|
|
152
|
-
`((s, f) => {
|
|
153
|
-
let r = s.length;
|
|
154
|
-
while (r > 0) {
|
|
155
|
-
let cp, step;
|
|
156
|
-
if (r > 1 && s.charCodeAt(r - 1) >= 0xDC00 && s.charCodeAt(r - 1) <= 0xDFFF &&
|
|
157
|
-
s.charCodeAt(r - 2) >= 0xD800 && s.charCodeAt(r - 2) <= 0xDBFF) {
|
|
158
|
-
cp = s.codePointAt(r - 2);
|
|
159
|
-
step = 2;
|
|
160
|
-
} else {
|
|
161
|
-
cp = s.codePointAt(r - 1);
|
|
162
|
-
step = 1;
|
|
163
|
-
}
|
|
164
|
-
if (!f(cp)) break;
|
|
165
|
-
r -= step;
|
|
166
|
-
}
|
|
167
|
-
return s.slice(0, r);
|
|
168
|
-
})(${s}, ${s2})`,
|
|
169
|
-
IndexFunc: ([s, s2]) =>
|
|
170
|
-
`((s, f) => { for (let i = 0; i < s.length; i++) { const cp = s.codePointAt(i); if (f(cp)) return i; if (cp > 0xFFFF) i++; } return -1; })(${s}, ${s2})`,
|
|
171
|
-
LastIndexFunc: ([s, s2]) =>
|
|
172
|
-
`((s, f) => { for (let i = s.length - 1; i >= 0; i--) { let cp = s.codePointAt(i); if (i > 0 && s.charCodeAt(i) >= 0xDC00 && s.charCodeAt(i) <= 0xDFFF && s.charCodeAt(i - 1) >= 0xD800 && s.charCodeAt(i - 1) <= 0xDBFF) { cp = s.codePointAt(i - 1); i--; } if (f(cp)) return i; } return -1; })(${s}, ${s2})`,
|
|
173
|
-
ToValidUTF8: ([s, repl]) =>
|
|
174
|
-
`(${s} ? ${s}.replace(/(?:[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF])+/g, ${repl} ?? "") : (${s} ?? ""))`,
|
|
175
|
-
NewReader: ([s]) =>
|
|
176
|
-
`((s) => ({
|
|
177
|
-
_bytes: new TextEncoder().encode(s ?? ""),
|
|
178
|
-
_pos: 0,
|
|
179
|
-
_prevRune: -1,
|
|
180
|
-
Read(p) {
|
|
181
|
-
if (this._pos >= this._bytes.length) return [0, __io_eof];
|
|
182
|
-
const n = Math.min(p.length, this._bytes.length - this._pos);
|
|
183
|
-
for (let i = 0; i < n; i++) p[i] = this._bytes[this._pos + i];
|
|
184
|
-
this._pos += n;
|
|
185
|
-
this._prevRune = -1;
|
|
186
|
-
return [n, null];
|
|
187
|
-
},
|
|
188
|
-
ReadAt(b, off) {
|
|
189
|
-
const o = Number(off);
|
|
190
|
-
if (o < 0) return [0, __error("strings.Reader.ReadAt: negative offset")];
|
|
191
|
-
if (o >= this._bytes.length) return [0, __io_eof];
|
|
192
|
-
const n = Math.min(b.length, this._bytes.length - o);
|
|
193
|
-
for (let i = 0; i < n; i++) b[i] = this._bytes[o + i];
|
|
194
|
-
return [n, n < b.length ? __io_eof : null];
|
|
195
|
-
},
|
|
196
|
-
ReadByte() {
|
|
197
|
-
if (this._pos >= this._bytes.length) return [0, __io_eof];
|
|
198
|
-
this._prevRune = -1;
|
|
199
|
-
return [this._bytes[this._pos++], null];
|
|
200
|
-
},
|
|
201
|
-
UnreadByte() {
|
|
202
|
-
if (this._pos <= 0) return __error("strings.Reader.UnreadByte: at beginning of string");
|
|
203
|
-
this._prevRune = -1;
|
|
204
|
-
this._pos--;
|
|
205
|
-
return null;
|
|
206
|
-
},
|
|
207
|
-
ReadRune() {
|
|
208
|
-
if (this._pos >= this._bytes.length) return [0, 0, __io_eof];
|
|
209
|
-
const rem = this._bytes.subarray(this._pos);
|
|
210
|
-
const str = new TextDecoder().decode(rem);
|
|
211
|
-
const cp = str.codePointAt(0);
|
|
212
|
-
const runeStr = str.slice(0, cp > 0xffff ? 2 : 1);
|
|
213
|
-
const sz = new TextEncoder().encode(runeStr).length;
|
|
214
|
-
this._prevRune = this._pos;
|
|
215
|
-
this._pos += sz;
|
|
216
|
-
return [cp, sz, null];
|
|
217
|
-
},
|
|
218
|
-
UnreadRune() {
|
|
219
|
-
if (this._prevRune === undefined || this._prevRune < 0 || this._prevRune >= this._pos) {
|
|
220
|
-
return __error("strings.Reader.UnreadRune: previous operation was not ReadRune");
|
|
221
|
-
}
|
|
222
|
-
this._pos = this._prevRune;
|
|
223
|
-
this._prevRune = -1;
|
|
224
|
-
return null;
|
|
225
|
-
},
|
|
226
|
-
Seek(offset, whence) {
|
|
227
|
-
const off = BigInt(offset);
|
|
228
|
-
const w = Number(whence);
|
|
229
|
-
let newPos;
|
|
230
|
-
if (w === 0) newPos = off;
|
|
231
|
-
else if (w === 1) newPos = BigInt(this._pos) + off;
|
|
232
|
-
else if (w === 2) newPos = BigInt(this._bytes.length) + off;
|
|
233
|
-
else return [0n, __error("strings.Reader.Seek: invalid whence")];
|
|
234
|
-
if (newPos < 0n) return [0n, __error("strings.Reader.Seek: negative position")];
|
|
235
|
-
this._pos = Number(newPos);
|
|
236
|
-
this._prevRune = -1;
|
|
237
|
-
return [newPos, null];
|
|
238
|
-
},
|
|
239
|
-
Size() { return BigInt(this._bytes.length); },
|
|
240
|
-
WriteTo(w) {
|
|
241
|
-
if (this._pos >= this._bytes.length) return [0, null];
|
|
242
|
-
const rem = this._bytes.subarray(this._pos);
|
|
243
|
-
const [n, err] = w.Write(rem);
|
|
244
|
-
this._pos += n;
|
|
245
|
-
return [n, err];
|
|
246
|
-
},
|
|
247
|
-
Len() { return Math.max(0, this._bytes.length - this._pos); },
|
|
248
|
-
Reset(s2) { this._bytes = new TextEncoder().encode(s2 ?? ""); this._pos = 0; this._prevRune = -1; }
|
|
249
|
-
}))(${s})`,
|
|
250
|
-
NewReplacer: (args) =>
|
|
251
|
-
`((...pairs) => {
|
|
252
|
-
const p = [];
|
|
253
|
-
for (let i = 0; i < pairs.length; i += 2) {
|
|
254
|
-
if (pairs[i] !== undefined && pairs[i+1] !== undefined) {
|
|
255
|
-
p.push([pairs[i], pairs[i+1]]);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
_p: p,
|
|
260
|
-
Replace(s) {
|
|
261
|
-
s = s ?? "";
|
|
262
|
-
if (!this._p || this._p.length === 0 || s === "") return s;
|
|
263
|
-
let out = "";
|
|
264
|
-
let i = 0;
|
|
265
|
-
while (i < s.length) {
|
|
266
|
-
let matched = false;
|
|
267
|
-
for (let k = 0; k < this._p.length; k++) {
|
|
268
|
-
const [oldStr, newStr] = this._p[k];
|
|
269
|
-
if (oldStr.length > 0 && s.startsWith(oldStr, i)) {
|
|
270
|
-
out += newStr;
|
|
271
|
-
i += oldStr.length;
|
|
272
|
-
matched = true;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (!matched) {
|
|
277
|
-
out += s[i];
|
|
278
|
-
i++;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return out;
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
})(${args.join(", ")})`,
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
/** @type {ThisType<CodeGen>} */
|
|
288
|
-
export const stringsMethods = {
|
|
289
|
-
_genStrings(fn, a) {
|
|
290
|
-
if (fn === "NewReader") {
|
|
291
|
-
this.useHelper("ioEOF");
|
|
292
|
-
this.useHelper("error");
|
|
293
|
-
}
|
|
294
|
-
const args = a();
|
|
295
|
-
const [s, s2] = args;
|
|
296
|
-
if (STRINGS_M1[fn]) return `${s}.${STRINGS_M1[fn]}()`;
|
|
297
|
-
if (STRINGS_M2[fn]) return `${s}.${STRINGS_M2[fn]}(${s2})`;
|
|
298
|
-
const gen = STRINGS_DISPATCH[fn];
|
|
299
|
-
return gen ? gen(args) : undefined;
|
|
300
|
-
},
|
|
301
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/backend/js/stdlib/sync.js
|
|
2
|
-
// CodeGen for Go sync package.
|
|
3
|
-
|
|
4
|
-
export const syncMethods = {
|
|
5
|
-
_genSync(fn) {
|
|
6
|
-
this.useHelper("sync");
|
|
7
|
-
if (fn === "Once") return "__sync_once()";
|
|
8
|
-
if (fn === "Mutex") return "__sync_mutex()";
|
|
9
|
-
if (fn === "RWMutex") return "__sync_rwmutex()";
|
|
10
|
-
if (fn === "WaitGroup") return "__sync_waitgroup()";
|
|
11
|
-
return undefined;
|
|
12
|
-
},
|
|
13
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `testing` package and `*testing.T` methods.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
/** @type {ThisType<CodeGen>} */
|
|
6
|
-
export const testingMethods = {
|
|
7
|
-
_genTesting(fn, _a) {
|
|
8
|
-
switch (fn) {
|
|
9
|
-
case "Short":
|
|
10
|
-
return "false";
|
|
11
|
-
case "Verbose":
|
|
12
|
-
return "Boolean(globalThis.__gofront_verbose)";
|
|
13
|
-
case "Testing":
|
|
14
|
-
return "true";
|
|
15
|
-
case "Init":
|
|
16
|
-
return "/* testing.Init */";
|
|
17
|
-
case "Benchmark":
|
|
18
|
-
this.useHelper("testing");
|
|
19
|
-
return `__testing_Benchmark(${_a()[0]})`;
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
_genTestingMethodCall(method, expr) {
|
|
25
|
-
this.useHelper("testing");
|
|
26
|
-
const recv = expr.func.expr;
|
|
27
|
-
const t = this.genExpr(recv);
|
|
28
|
-
const args = expr.args
|
|
29
|
-
.map((a) => (a._spread ? `...${this.genExpr(a)}` : this.genExpr(a)))
|
|
30
|
-
.join(", ");
|
|
31
|
-
if (
|
|
32
|
-
method === "Errorf" ||
|
|
33
|
-
method === "Fatalf" ||
|
|
34
|
-
method === "Logf" ||
|
|
35
|
-
method === "Skipf"
|
|
36
|
-
) {
|
|
37
|
-
this.useHelper("sprintf");
|
|
38
|
-
}
|
|
39
|
-
return `${t}.${method}(${args})`;
|
|
40
|
-
},
|
|
41
|
-
};
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `time` package — `time.Now`, `time.Since`, etc., plus `*Time` methods.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const TIME_METHOD_DISPATCH = {
|
|
6
|
-
Year: (r) => `__timeYear(${r})`,
|
|
7
|
-
Month: (r) => `__timeMonth(${r})`,
|
|
8
|
-
Day: (r) => `__timeDay(${r})`,
|
|
9
|
-
Hour: (r) => `__timeHour(${r})`,
|
|
10
|
-
Minute: (r) => `__timeMinute(${r})`,
|
|
11
|
-
Second: (r) => `__timeSecond(${r})`,
|
|
12
|
-
Weekday: (r) => `__timeWeekday(${r})`,
|
|
13
|
-
Unix: (r) => `Math.floor(${r}._d.getTime() / 1000)`,
|
|
14
|
-
UnixMilli: (r) => `${r}._d.getTime()`,
|
|
15
|
-
Add: (r, a) =>
|
|
16
|
-
`{_d: new Date(${r}._d.getTime() + Math.round(Number(${a[0]}) / 1000000)), _offset: ${r}._offset, _loc: ${r}._loc, _ns: ${r}._ns}`,
|
|
17
|
-
Sub: (r, a) =>
|
|
18
|
-
`Math.round((${r}._d.getTime() - (${a[0]})._d.getTime()) * 1000000)`,
|
|
19
|
-
Before: (r, a) => `(${r}._d < (${a[0]})._d)`,
|
|
20
|
-
After: (r, a) => `(${r}._d > (${a[0]})._d)`,
|
|
21
|
-
Equal: (r, a) =>
|
|
22
|
-
`(${r}._d.getTime() === (${a[0]})._d.getTime() && (${r}._ns || 0) === ((${a[0]})._ns || 0))`,
|
|
23
|
-
IsZero: (r) =>
|
|
24
|
-
`(!${r} || !${r}._d || ${r}._isZero === true || ${r}._d.getTime() === -62135596800000 || (${r}._d.getUTCFullYear() <= 1 && ${r}._d.getUTCMonth() === 0 && ${r}._d.getUTCDate() === 1 && ${r}._d.getUTCHours() === 0 && ${r}._d.getUTCMinutes() === 0 && ${r}._d.getUTCSeconds() === 0 && ${r}._d.getUTCMilliseconds() === 0))`,
|
|
25
|
-
UnixNano: (r) =>
|
|
26
|
-
`(${r}?._d ? Math.round(${r}._d.getTime() * 1000000) + (${r}._ns || 0) : 0)`,
|
|
27
|
-
Nanosecond: (r) =>
|
|
28
|
-
`(${r}?._d ? (typeof ${r}._offset === "number" ? ${r}._d.getUTCMilliseconds() : ${r}._d.getMilliseconds()) * 1000000 + (${r}._ns || 0) : 0)`,
|
|
29
|
-
UTC: (r) =>
|
|
30
|
-
`({_d: ${r}?._d ?? new Date(0), _offset: 0, _loc: null, _ns: ${r}?._ns || 0})`,
|
|
31
|
-
Local: (r) =>
|
|
32
|
-
`({_d: ${r}?._d ?? new Date(0), _offset: undefined, _loc: null, _ns: ${r}?._ns || 0})`,
|
|
33
|
-
AddDate: (r, a) => `__timeAddDate(${r}, ${a[0]}, ${a[1]}, ${a[2]})`,
|
|
34
|
-
Truncate: (r, a) => `__timeTruncate(${r}, ${a[0]})`,
|
|
35
|
-
Round: (r, a) => `__timeRound(${r}, ${a[0]})`,
|
|
36
|
-
Date: (r) => `__timeDate(${r})`,
|
|
37
|
-
Clock: (r) => `__timeClock(${r})`,
|
|
38
|
-
YearDay: (r) => `__timeYearDay(${r})`,
|
|
39
|
-
Compare: (r, a) =>
|
|
40
|
-
`(${r}._d.getTime() < (${a[0]})._d.getTime() ? -1 : (${r}._d.getTime() > (${a[0]})._d.getTime() ? 1 : ((${r}._ns || 0) < ((${a[0]})._ns || 0) ? -1 : ((${r}._ns || 0) > ((${a[0]})._ns || 0) ? 1 : 0))))`,
|
|
41
|
-
ISOWeek: (r) => `__timeISOWeek(${r})`,
|
|
42
|
-
In: (r, a) =>
|
|
43
|
-
`((() => { const _loc = ${a[0]}; const _off = _loc && typeof _loc._offset === "number" ? _loc._offset : 0; return { _d: ${r}._d, _offset: _off, _loc, _ns: ${r}._ns }; })())`,
|
|
44
|
-
Location: (r) =>
|
|
45
|
-
`(${r}._loc ?? (${r}._offset === 0 ? { _name: "UTC", _offset: 0, String() { return "UTC"; } } : { _name: "Local", _offset: -${r}._d.getTimezoneOffset() * 60, String() { return "Local"; } }))`,
|
|
46
|
-
Zone: (r) =>
|
|
47
|
-
`[${r}._loc ? ${r}._loc._name : (${r}._offset === 0 ? "UTC" : "LOCAL"), ${r}._loc ? ${r}._loc._offset : (${r}._offset === 0 ? 0 : -${r}._d.getTimezoneOffset() * 60)]`,
|
|
48
|
-
MarshalJSON: (r) => `__timeMarshalJSON(${r})`,
|
|
49
|
-
UnmarshalJSON: (r, a) => `__timeUnmarshalJSON(${r}, ${a[0]})`,
|
|
50
|
-
MarshalText: (r) => `__timeMarshalText(${r})`,
|
|
51
|
-
UnmarshalText: (r, a) => `__timeUnmarshalText(${r}, ${a[0]})`,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const DURATION_METHOD_DISPATCH = {
|
|
55
|
-
Nanoseconds: (r) => `${r}`,
|
|
56
|
-
Microseconds: (r) => `Math.trunc(Number(${r}) / 1000)`,
|
|
57
|
-
Milliseconds: (r) => `Math.trunc(Number(${r}) / 1000000)`,
|
|
58
|
-
Seconds: (r) => `(Number(${r}) / 1000000000)`,
|
|
59
|
-
Minutes: (r) => `(Number(${r}) / 60000000000)`,
|
|
60
|
-
Hours: (r) => `(Number(${r}) / 3600000000000)`,
|
|
61
|
-
String: (r) => `__durationString(${r})`,
|
|
62
|
-
Truncate: (r, a) => `(${a[0]} <= 0 ? ${r} : ${r} - (${r} % ${a[0]}))`,
|
|
63
|
-
Round: (r, a) => `__durationRound(${r}, ${a[0]})`,
|
|
64
|
-
Abs: (r) => `(${r} >= 0 ? ${r} : -(${r}))`,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const TIME_DISPATCH = {
|
|
68
|
-
Now: () =>
|
|
69
|
-
'(typeof globalThis.__GOFRONT_CLOCK === "function" ? {_d: new Date(globalThis.__GOFRONT_CLOCK())} : {_d: new Date()})',
|
|
70
|
-
Since: (a) =>
|
|
71
|
-
`(Math.round(((typeof globalThis.__GOFRONT_CLOCK === "function" ? globalThis.__GOFRONT_CLOCK() : Date.now()) - (${a[0]})._d.getTime()) * 1000000))`,
|
|
72
|
-
Sleep: (a) => `await new Promise(r => setTimeout(r, ${a[0]} / 1000000))`,
|
|
73
|
-
Unix: (a) =>
|
|
74
|
-
`{_d: new Date(Number(${a[0]}) * 1000 + Math.round(Number(${a[1] || 0}) / 1000000)), _ns: Math.round(Number(${a[1] || 0}) % 1000000)}`,
|
|
75
|
-
UnixMicro: (a) =>
|
|
76
|
-
`{_d: new Date(Math.round(Number(${a[0]}) / 1000)), _ns: Math.round((Number(${a[0]}) % 1000) * 1000)}`,
|
|
77
|
-
UnixMilli: (a) => `{_d: new Date(Number(${a[0]}))}`,
|
|
78
|
-
Date: (a) =>
|
|
79
|
-
`{_d: new Date(${a[0]}, ${a[1]} - 1, ${a[2]}, ${a[3]}, ${a[4]}, ${a[5]}, Math.round(Number(${a[6] || 0}) / 1000000)), _ns: Math.round(Number(${a[6] || 0}) % 1000000)}`,
|
|
80
|
-
ParseDuration: (a) => `__timeParseDuration(${a[0]})`,
|
|
81
|
-
FixedZone: (a) =>
|
|
82
|
-
`({ _name: ${a[0]}, _offset: ${a[1]}, String() { return this._name; } })`,
|
|
83
|
-
AfterFunc: (a) => `__timeAfterFunc(${a[0]}, ${a[1]})`,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/** @type {ThisType<CodeGen>} */
|
|
87
|
-
export const timeMethods = {
|
|
88
|
-
_genTimeMethodCall(method, expr) {
|
|
89
|
-
const recv = expr.func.expr;
|
|
90
|
-
const recvJs = this.genExpr(recv);
|
|
91
|
-
const args = expr.args.map((a) => this.genExpr(a));
|
|
92
|
-
this.useHelper("timeFmt");
|
|
93
|
-
this.useHelper("duration");
|
|
94
|
-
this.useHelper("timeParse");
|
|
95
|
-
if (method === "Format") {
|
|
96
|
-
return `__timeFmt(${recvJs}, ${args[0]})`;
|
|
97
|
-
}
|
|
98
|
-
if (method === "String") {
|
|
99
|
-
return `__timeFmt(${recvJs}, "2006-01-02 15:04:05.999999999 -0700 MST")`;
|
|
100
|
-
}
|
|
101
|
-
const gen = TIME_METHOD_DISPATCH[method];
|
|
102
|
-
return gen ? gen(recvJs, args) : undefined;
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
_genDurationMethodCall(method, expr) {
|
|
106
|
-
const recv = expr.func.expr;
|
|
107
|
-
const recvJs = this.genExpr(recv);
|
|
108
|
-
const args = expr.args.map((a) => this.genExpr(a));
|
|
109
|
-
this.useHelper("duration");
|
|
110
|
-
const gen = DURATION_METHOD_DISPATCH[method];
|
|
111
|
-
return gen ? gen(recvJs, args) : undefined;
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
_genTimeDate(args, expr) {
|
|
115
|
-
this.useHelper("timeFmt");
|
|
116
|
-
const locArg = expr?.args?.[7];
|
|
117
|
-
const isUtc =
|
|
118
|
-
(locArg?.kind === "SelectorExpr" &&
|
|
119
|
-
(locArg.sel?.name === "UTC" || locArg.field === "UTC")) ||
|
|
120
|
-
(locArg?.kind === "Ident" && locArg.name === "UTC") ||
|
|
121
|
-
args[7] === '"UTC"';
|
|
122
|
-
if (isUtc) {
|
|
123
|
-
return `{_d: new Date(Date.UTC(${args[0]}, ${args[1]} - 1, ${args[2]}, ${args[3]}, ${args[4]}, ${args[5]}, Math.floor(Number(${args[6] || 0}) / 1000000))), _offset: 0, _loc: null, _ns: Math.floor(Number(${args[6] || 0}) % 1000000)}`;
|
|
124
|
-
}
|
|
125
|
-
return `((() => { const _loc = ${args[7]}; const _off = _loc && typeof _loc._offset === "number" ? _loc._offset : undefined; const _ms = Math.floor(Number(${args[6] || 0}) / 1000000); const _remNs = Math.floor(Number(${args[6] || 0}) % 1000000); if (_off !== undefined) { const _d = new Date(Date.UTC(${args[0]}, ${args[1]} - 1, ${args[2]}, ${args[3]}, ${args[4]}, ${args[5]}, _ms) - _off * 1000); return { _d, _offset: _off, _loc, _ns: _remNs }; } return { _d: new Date(${args[0]}, ${args[1]} - 1, ${args[2]}, ${args[3]}, ${args[4]}, ${args[5]}, _ms), _offset: undefined, _loc: null, _ns: _remNs }; })())`;
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
_genTime(fn, a, expr) {
|
|
129
|
-
if (fn === "Date") return this._genTimeDate(a(), expr);
|
|
130
|
-
if (fn === "Parse") {
|
|
131
|
-
this.useHelper("timeParse");
|
|
132
|
-
this.useHelper("timeFmt");
|
|
133
|
-
return `__timeParse(${a()[0]}, ${a()[1]})`;
|
|
134
|
-
}
|
|
135
|
-
if (fn === "ParseDuration") {
|
|
136
|
-
this.useHelper("duration");
|
|
137
|
-
return `__timeParseDuration(${a()[0]})`;
|
|
138
|
-
}
|
|
139
|
-
if (fn === "FixedZone") {
|
|
140
|
-
this.useHelper("timeFmt");
|
|
141
|
-
const args = a();
|
|
142
|
-
return `({ _name: ${args[0]}, _offset: ${args[1]}, String() { return this._name; } })`;
|
|
143
|
-
}
|
|
144
|
-
if (fn === "AfterFunc") {
|
|
145
|
-
this.useHelper("timeFmt");
|
|
146
|
-
const args = a();
|
|
147
|
-
return `__timeAfterFunc(${args[0]}, ${args[1]})`;
|
|
148
|
-
}
|
|
149
|
-
const gen = TIME_DISPATCH[fn];
|
|
150
|
-
return gen ? gen(a()) : undefined;
|
|
151
|
-
},
|
|
152
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `unicode` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
/** @type {ThisType<CodeGen>} */
|
|
6
|
-
export const unicodeMethods = {
|
|
7
|
-
_genUnicode(fn, a) {
|
|
8
|
-
const [arg] = a();
|
|
9
|
-
const cp = `String.fromCodePoint(${arg})`;
|
|
10
|
-
const UNICODE_TEST = {
|
|
11
|
-
IsLetter: `/\\p{L}/u.test(${cp})`,
|
|
12
|
-
IsDigit: `/\\p{Nd}/u.test(${cp})`,
|
|
13
|
-
IsSpace: `/[ \\t\\n\\v\\f\\r\\u0085\\u00A0\\u1680\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]/.test(${cp})`,
|
|
14
|
-
IsUpper: `/\\p{Lu}/u.test(${cp})`,
|
|
15
|
-
IsLower: `/\\p{Ll}/u.test(${cp})`,
|
|
16
|
-
IsPunct: `/\\p{P}/u.test(${cp})`,
|
|
17
|
-
IsControl: `/\\p{Cc}/u.test(${cp})`,
|
|
18
|
-
IsPrint: `!/\\p{Cc}/u.test(${cp})`,
|
|
19
|
-
IsGraphic: `!/\\p{Cc}/u.test(${cp})`,
|
|
20
|
-
ToUpper: `${cp}.toUpperCase().codePointAt(0)`,
|
|
21
|
-
ToLower: `${cp}.toLowerCase().codePointAt(0)`,
|
|
22
|
-
};
|
|
23
|
-
return UNICODE_TEST[fn] ?? undefined;
|
|
24
|
-
},
|
|
25
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `unicode/utf8` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const UTF8_DISPATCH = {
|
|
6
|
-
RuneCountInString: (a) => `[...(${a[0]})].length`,
|
|
7
|
-
RuneLen: (a) =>
|
|
8
|
-
`((r) => r < 0 ? -1 : r <= 0x7F ? 1 : r <= 0x7FF ? 2 : r <= 0xFFFF ? (r >= 0xD800 && r <= 0xDFFF ? -1 : 3) : r <= 0x10FFFF ? 4 : -1)(${a[0]})`,
|
|
9
|
-
ValidString: (a) =>
|
|
10
|
-
`/[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/.test(${a[0]}) === false`,
|
|
11
|
-
ValidRune: (a) =>
|
|
12
|
-
`((${a[0]}) >= 0 && (${a[0]}) <= 0x10FFFF && !((${a[0]}) >= 0xD800 && (${a[0]}) <= 0xDFFF))`,
|
|
13
|
-
DecodeRuneInString: (a) =>
|
|
14
|
-
`((s) => { if (!s) return [0xFFFD, 0]; const cp = s.codePointAt(0); return [cp, cp > 0xFFFF ? 2 : 1]; })(${a[0]})`,
|
|
15
|
-
DecodeLastRuneInString: (a) =>
|
|
16
|
-
`((s) => { if (!s) return [0xFFFD, 0]; const i = s.length > 1 && s.charCodeAt(s.length - 1) >= 0xDC00 && s.charCodeAt(s.length - 1) <= 0xDFFF ? s.length - 2 : s.length - 1; const cp = s.codePointAt(i); return [cp, cp > 0xFFFF ? 2 : 1]; })(${a[0]})`,
|
|
17
|
-
FullRuneInString: (a) => `(${a[0]}).length > 0`,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/** @type {ThisType<CodeGen>} */
|
|
21
|
-
export const utf8Methods = {
|
|
22
|
-
_genUtf8(fn, a) {
|
|
23
|
-
const gen = UTF8_DISPATCH[fn];
|
|
24
|
-
return gen ? gen(a()) : undefined;
|
|
25
|
-
},
|
|
26
|
-
};
|