ferrovue 0.12.0 → 0.13.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 +8 -8
- package/dist/attrs.d.ts +4 -0
- package/dist/attrs.js +8 -0
- package/dist/blocks.js +6 -17
- package/dist/calls.js +150 -330
- package/dist/children.js +64 -19
- package/dist/classes.js +2 -5
- package/dist/client.d.ts +1 -1
- package/dist/client.js +2 -2
- package/dist/component.js +76 -23
- package/dist/conditional.d.ts +3 -0
- package/dist/conditional.js +201 -0
- package/dist/conformance.js +4 -10
- package/dist/constants.js +93 -15
- package/dist/dynamic.js +9 -4
- package/dist/enums.d.ts +20 -0
- package/dist/enums.js +126 -13
- package/dist/errors.d.ts +16 -16
- package/dist/errors.js +16 -16
- package/dist/expr.js +241 -772
- package/dist/fallthrough.d.ts +8 -0
- package/dist/fallthrough.js +39 -31
- package/dist/functions.js +3 -1
- package/dist/globals.d.ts +7 -0
- package/dist/globals.js +223 -0
- package/dist/lists.d.ts +7 -2
- package/dist/lists.js +100 -9
- package/dist/logical.d.ts +3 -0
- package/dist/logical.js +215 -0
- package/dist/loops.js +7 -3
- package/dist/members.d.ts +5 -0
- package/dist/members.js +343 -0
- package/dist/model.d.ts +43 -1
- package/dist/model.js +50 -2
- package/dist/narrowing.d.ts +14 -4
- package/dist/narrowing.js +11 -8
- package/dist/numbers.d.ts +2 -0
- package/dist/numbers.js +38 -1
- package/dist/objects.d.ts +2 -0
- package/dist/objects.js +22 -0
- package/dist/operators.d.ts +5 -0
- package/dist/operators.js +186 -0
- package/dist/plugins/head.js +14 -24
- package/dist/plugins/loaders.d.ts +5 -0
- package/dist/plugins/loaders.js +115 -8
- package/dist/plugins/router-link.js +5 -12
- package/dist/plugins/scoped.js +7 -13
- package/dist/plugins/stores.js +2 -2
- package/dist/problems.d.ts +8 -0
- package/dist/problems.js +25 -0
- package/dist/revive.js +6 -2
- package/dist/rust.d.ts +1 -1
- package/dist/rust.js +41 -14
- package/dist/script.d.ts +0 -1
- package/dist/script.js +335 -238
- package/dist/slots.d.ts +2 -0
- package/dist/slots.js +11 -0
- package/dist/ssr.js +3 -2
- package/dist/statements.js +11 -12
- package/dist/strings.d.ts +25 -0
- package/dist/strings.js +240 -1
- package/dist/styles.js +12 -15
- package/dist/template.js +97 -11
- package/dist/testing-browser.js +27 -48
- package/dist/typescript.d.ts +7 -0
- package/dist/typescript.js +162 -4
- package/dist/vite.d.ts +0 -2
- package/dist/vite.js +9 -3
- package/package.json +1 -1
package/dist/calls.js
CHANGED
|
@@ -1,281 +1,146 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BOOL, fail } from "./model.js";
|
|
2
2
|
import { ctx } from "./context.js";
|
|
3
3
|
import { claim } from "./plugin.js";
|
|
4
|
-
import { atom, bare
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { atom, bare } from "./parens.js";
|
|
5
|
+
import { isBoolean, listCall, listMethod, presentLiteral } from "./lists.js";
|
|
6
|
+
import { meet, noArgStringMethod, regexTest, stringMethod, stringsEqual } from "./strings.js";
|
|
7
|
+
import { numberMethod } from "./numbers.js";
|
|
8
8
|
import { boolOf, truthy } from "./narrowing.js";
|
|
9
|
-
import { coerce,
|
|
9
|
+
import { coerce, expr, refuseClientOnly, refuseUnavailable } from "./expr.js";
|
|
10
10
|
import { callFunction } from "./functions.js";
|
|
11
11
|
import { constOf, mapCall } from "./constants.js";
|
|
12
12
|
import { refuseInPlace } from "./objects.js";
|
|
13
|
-
|
|
14
|
-
["toFixed", ["FV0705", 0, "number of digits"]],
|
|
15
|
-
["toPrecision", ["FV0716", 1, "precision"]],
|
|
16
|
-
["toExponential", ["FV0717", 0, "number of digits"]],
|
|
17
|
-
]);
|
|
13
|
+
import { globalCall, mathCall, staticCall } from "./globals.js";
|
|
18
14
|
export function call(s, n) {
|
|
19
|
-
const
|
|
15
|
+
const callee = n.callee;
|
|
16
|
+
if (callee.type === "Identifier")
|
|
17
|
+
return namedCall(s, n);
|
|
18
|
+
if (callee.type === "MemberExpression" && !callee.computed)
|
|
19
|
+
return memberCall(s, n);
|
|
20
|
+
return fail(s.comp, "FV0603", "this call is not supported", n);
|
|
21
|
+
}
|
|
22
|
+
function namedCall(s, n) {
|
|
20
23
|
const callee = n.callee;
|
|
21
24
|
const args = n.arguments;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const a = expr(s, args[0]);
|
|
62
|
-
if (a.ty.k === "str")
|
|
63
|
-
return a;
|
|
64
|
-
if (isNumber(a.ty))
|
|
65
|
-
return { code: `&*fv::core::Js(${bare(asWritten(a).code)}).to_string()`, ty: asciiTy() };
|
|
66
|
-
if (a.ty.k === "bool")
|
|
67
|
-
return { code: `if ${condition(a.code)} { "true" } else { "false" }`, ty: asciiTy() };
|
|
68
|
-
return formatted(comp, [stringOf(comp, a, args[0], "`String()`", "FV0723")], n, "`String()`");
|
|
69
|
-
}
|
|
70
|
-
if ((callee.name === "encodeURIComponent" || callee.name === "encodeURI") && global) {
|
|
71
|
-
const name = `\`${callee.name}()\``;
|
|
72
|
-
if (args.length !== 1)
|
|
73
|
-
return fail(comp, "FV0723", `${name} takes one value`, n);
|
|
74
|
-
const a = expr(s, args[0]);
|
|
75
|
-
if (a.lone)
|
|
76
|
-
fail(comp, "FV0706", `${lonely(name)}; it throws a \`URIError\` on a half`, n);
|
|
77
|
-
const text = a.ty.k === "str" ? a : formatted(comp, [stringOf(comp, a, args[0], name, "FV0723")], n, name);
|
|
78
|
-
return { code: `&*fv::core::js_${callee.name === "encodeURI" ? "encode_uri" : "encode_uri_component"}(${strArg(text.code)})`, ty: STR };
|
|
79
|
-
}
|
|
80
|
-
if (callee.name === "Number" && args.length === 1) {
|
|
81
|
-
const a = expr(s, args[0]);
|
|
82
|
-
if (a.ty.k === "str")
|
|
83
|
-
return { code: `fv::strings::js_number(${strArg(a.code)})`, ty: FLOAT };
|
|
84
|
-
if (isNumber(a.ty))
|
|
85
|
-
return a;
|
|
86
|
-
if (a.ty.k === "bool")
|
|
87
|
-
return { code: `i64::from(${bare(a.code)})`, ty: INT };
|
|
88
|
-
return fail(comp, "FV0701", "`Number()` takes a string, a number or a boolean that is present", n);
|
|
89
|
-
}
|
|
90
|
-
if ((callee.name === "parseInt" && (args.length === 1 || args.length === 2)) || (callee.name === "parseFloat" && args.length === 1)) {
|
|
91
|
-
const a = expr(s, args[0]);
|
|
92
|
-
if (a.ty.k !== "str")
|
|
93
|
-
fail(comp, "FV0702", `\`${callee.name}()\` takes a string`, args[0]);
|
|
94
|
-
if (callee.name === "parseFloat")
|
|
95
|
-
return { code: `fv::strings::js_parse_float(${strArg(a.code)})`, ty: FLOAT };
|
|
96
|
-
const radix = args[1];
|
|
97
|
-
if (radix && !(radix.type === "NumericLiteral" && (radix.value === 10 || radix.value === 16))) {
|
|
98
|
-
fail(comp, "FV0703", "`parseInt()` takes a radix of 10 or 16, written as a literal", radix);
|
|
99
|
-
}
|
|
100
|
-
return { code: `fv::strings::js_parse_int(${strArg(a.code)}, ${radix ? radix.value : 0})`, ty: FLOAT };
|
|
101
|
-
}
|
|
102
|
-
if ((callee.name === "isNaN" || callee.name === "isFinite") && global)
|
|
103
|
-
return numberTest(s, callee.name, args, n, true);
|
|
104
|
-
if (global && BUILTINS.has(callee.name))
|
|
105
|
-
return builtin(s, `${callee.name}()`, n);
|
|
106
|
-
return refuseUnavailable(s, callee.name, n, true);
|
|
25
|
+
const rendered = renderHelperCall(s, callee.name, args, n);
|
|
26
|
+
if (rendered)
|
|
27
|
+
return rendered;
|
|
28
|
+
const own = claim((p) => p.call?.(s, n));
|
|
29
|
+
if (own)
|
|
30
|
+
return own;
|
|
31
|
+
const mine = ownCall(s, callee, args, n);
|
|
32
|
+
if (mine)
|
|
33
|
+
return mine;
|
|
34
|
+
if (isBoolean(s, callee) && args.length === 1)
|
|
35
|
+
return boolOf(truthy(expr(s, args[0])));
|
|
36
|
+
return globalNamedCall(s, callee.name, args, n);
|
|
37
|
+
}
|
|
38
|
+
function globalNamedCall(s, name, args, n) {
|
|
39
|
+
const global = !s.locals.has(name) && !s.setup.has(name);
|
|
40
|
+
const known = globalCall(s, name, args, n, global);
|
|
41
|
+
if (known)
|
|
42
|
+
return known;
|
|
43
|
+
if (global && BUILTINS.has(name))
|
|
44
|
+
return builtin(s, `${name}()`, n);
|
|
45
|
+
return refuseUnavailable(s, name, n, true);
|
|
46
|
+
}
|
|
47
|
+
function renderHelperCall(s, name, args, n) {
|
|
48
|
+
switch (name) {
|
|
49
|
+
case "_ssrLooseEqual":
|
|
50
|
+
return looseEqual(s, args, n);
|
|
51
|
+
case "_ssrIncludeBooleanAttr":
|
|
52
|
+
return includeBooleanAttr(s, args);
|
|
53
|
+
case "_ssrLooseContain":
|
|
54
|
+
return fail(s.comp, "FV0414", "`v-model` over an array", n);
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
function looseEqual(s, args, n) {
|
|
59
|
+
const a = expr(s, args[0]);
|
|
60
|
+
const b = expr(s, args[1]);
|
|
61
|
+
if (a.ty.k === "str" && b.ty.k === "str") {
|
|
62
|
+
meet(s.comp, a, b, "`v-model`", n, "equal");
|
|
63
|
+
return boolOf(stringsEqual(a, b));
|
|
107
64
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return ints ? intFromF64(sign, null) : { code: sign, ty: FLOAT };
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return fail(comp, "FV0704", `\`Math.${method}()\` is supported on numbers as \`max\`, \`min\`, \`abs\`, \`round\`, \`floor\`, \`ceil\`, \`trunc\`, \`sqrt\`, \`sign\` and \`pow\``, n);
|
|
184
|
-
}
|
|
185
|
-
if (callee.object.type === "Identifier" && BUILTINS.has(callee.object.name) && !s.locals.has(callee.object.name) && !s.setup.has(callee.object.name)) {
|
|
186
|
-
return builtin(s, `${callee.object.name}.${method}()`, n);
|
|
187
|
-
}
|
|
188
|
-
if ((method === "sort" || method === "reverse") && callee.object.type === "ArrayExpression") {
|
|
189
|
-
const copy = expr(s, callee.object);
|
|
190
|
-
if (copy.ty.k === "list")
|
|
191
|
-
return listMethod(s, copy, method === "sort" ? "toSorted" : "toReversed", args, n);
|
|
192
|
-
}
|
|
193
|
-
const map = callee.object.type === "Identifier" || callee.object.type === "MemberExpression" ? constOf(s, callee.object) : null;
|
|
194
|
-
if (map?.sym.k === "const" && map.sym.c.k === "map")
|
|
195
|
-
return mapCall(s, map, method, args, n);
|
|
196
|
-
const literal = method === "filter" && args.length === 1 && isBoolean(s, args[0]) && callee.object.type === "ArrayExpression";
|
|
197
|
-
const target = (literal ? presentLiteral(s, callee.object) : null) ?? expr(s, callee.object);
|
|
198
|
-
const typed = claim((p) => p.method?.(s, target, method, args, n));
|
|
199
|
-
if (typed)
|
|
200
|
-
return typed;
|
|
201
|
-
if (target.ty.k === "str") {
|
|
202
|
-
const lone = loneOf(target);
|
|
203
|
-
const same = strTy(isAscii(target.ty));
|
|
204
|
-
switch (args.length === 0 ? method : "") {
|
|
205
|
-
case "trim":
|
|
206
|
-
return { code: `fv::strings::js_trim(${strArg(target.code)})`, ty: same, ...lone };
|
|
207
|
-
case "trimStart":
|
|
208
|
-
return { code: `fv::strings::js_trim_start(${strArg(target.code)})`, ty: same, ...lone };
|
|
209
|
-
case "trimEnd":
|
|
210
|
-
case "trimRight":
|
|
211
|
-
return { code: `fv::strings::js_trim_end(${strArg(target.code)})`, ty: same, ...lone };
|
|
212
|
-
case "trimLeft":
|
|
213
|
-
return { code: `fv::strings::js_trim_start(${strArg(target.code)})`, ty: same, ...lone };
|
|
214
|
-
case "toUpperCase":
|
|
215
|
-
return { code: `&*${receiver(target.code)}.to_uppercase()`, ty: same, ...lone };
|
|
216
|
-
case "toLowerCase":
|
|
217
|
-
return { code: `&*${receiver(target.code)}.to_lowercase()`, ty: same, ...lone };
|
|
218
|
-
case "toString":
|
|
219
|
-
return target;
|
|
220
|
-
}
|
|
221
|
-
const m = stringMethod(s, target, method, args, n);
|
|
222
|
-
if (m)
|
|
223
|
-
return m;
|
|
224
|
-
}
|
|
225
|
-
const digits = isNumber(target.ty) && args.length <= 1 ? DIGITS.get(method) : undefined;
|
|
226
|
-
if (digits) {
|
|
227
|
-
const [code, low, what] = digits;
|
|
228
|
-
const a = args[0];
|
|
229
|
-
const given = a === undefined || (a.type === "Identifier" && a.name === "undefined") ? undefined : a.type === "NumericLiteral" ? Math.trunc(a.value) : NaN;
|
|
230
|
-
if (given !== undefined && !(given >= low && given <= 100))
|
|
231
|
-
fail(comp, code, `\`.${method}()\` takes a literal ${what}, from ${low} to 100`, n);
|
|
232
|
-
const x = bare(asF64(target));
|
|
233
|
-
if (method === "toFixed")
|
|
234
|
-
return { code: `&*fv::core::js_to_fixed(${x}, ${given ?? 0})`, ty: asciiTy() };
|
|
235
|
-
if (method === "toExponential")
|
|
236
|
-
return { code: `&*fv::core::js_to_exponential(${x}, ${given === undefined ? "None" : `Some(${given})`})`, ty: asciiTy() };
|
|
237
|
-
if (given === undefined)
|
|
238
|
-
return { code: `&*fv::core::Js(${bare(asWritten(target).code)}).to_string()`, ty: asciiTy() };
|
|
239
|
-
return { code: `&*fv::core::js_to_precision(${x}, ${given})`, ty: asciiTy() };
|
|
240
|
-
}
|
|
241
|
-
if (isNumber(target.ty) && method === "toString" && args.length === 0) {
|
|
242
|
-
return { code: `&*fv::core::Js(${bare(asWritten(target).code)}).to_string()`, ty: asciiTy() };
|
|
243
|
-
}
|
|
244
|
-
if (target.owned)
|
|
245
|
-
refuseInPlace(comp, `\`.${method}()\``, n);
|
|
246
|
-
if (target.ty.k === "list") {
|
|
247
|
-
const inPlace = target.iter === undefined && !target.lone && (target.ty.of.k === "str" || target.ty.of.k === "int");
|
|
248
|
-
const listed = listMethod(s, target, method, args, n) ?? (inPlace ? null : computedListMethod(s, target, method, args, n));
|
|
249
|
-
if (listed)
|
|
250
|
-
return listed;
|
|
251
|
-
}
|
|
252
|
-
if (target.ty.k === "list" && (target.ty.of.k === "str" || target.ty.of.k === "int")) {
|
|
253
|
-
const of = target.ty.of;
|
|
254
|
-
if (method === "includes" && args.length === 1) {
|
|
255
|
-
const v = expr(s, args[0]);
|
|
256
|
-
if (of.k === "int" && v.ty.k === "float")
|
|
257
|
-
return { code: `${atom(target.code)}.iter().any(|v| ${binary("*v as f64", "==", v.code)})`, ty: BOOL };
|
|
258
|
-
if (!sameTy(v.ty, of))
|
|
259
|
-
fail(comp, "FV0801", "`.includes()` looks for a value of the list's own type", args[0]);
|
|
260
|
-
if (of.k === "int")
|
|
261
|
-
return { code: `${atom(target.code)}.contains(&${operand(v.code, UNARY)})`, ty: BOOL };
|
|
262
|
-
const test = v.code === '""' ? "v.is_empty()" : binary("&**v", "==", v.code);
|
|
263
|
-
return { code: `${atom(target.code)}.iter().any(|v| ${test})`, ty: BOOL };
|
|
264
|
-
}
|
|
265
|
-
if (method === "join" && args.length <= 1) {
|
|
266
|
-
const sep = args.length ? expr(s, args[0]) : { code: '","', ty: STR };
|
|
267
|
-
if (sep.ty.k !== "str")
|
|
268
|
-
fail(comp, "FV0802", "`.join()` takes a string", args[0]);
|
|
269
|
-
const each = of.k === "str" ? `${atom(target.code)}.iter().map(|v| &**v)` : `${atom(target.code)}.iter().map(|v| fv::core::Js(*v).to_string())`;
|
|
270
|
-
return { code: `&*${each}.collect::<Vec<_>>().join(${strArg(sep.code)})`, ty: strTy(writesAscii(target.ty) && isAscii(sep.ty)), ...loneOf(sep) };
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return fail(comp, "FV0602", `\`.${method}()\` is not supported`, n);
|
|
65
|
+
return fail(s.comp, "FV0413", "`v-model` comparison between these types", n);
|
|
66
|
+
}
|
|
67
|
+
function includeBooleanAttr(s, args) {
|
|
68
|
+
const a = expr(s, args[0]);
|
|
69
|
+
if (a.konst !== undefined)
|
|
70
|
+
return a;
|
|
71
|
+
if (a.ty.k === "str")
|
|
72
|
+
return { code: "true", ty: BOOL, konst: true };
|
|
73
|
+
if (a.ty.k === "opt" && a.ty.of.k === "str")
|
|
74
|
+
return { code: `${atom(a.code)}.is_some()`, ty: BOOL };
|
|
75
|
+
return boolOf(truthy(a));
|
|
76
|
+
}
|
|
77
|
+
function memberCall(s, n) {
|
|
78
|
+
const object = n.callee.object;
|
|
79
|
+
const method = n.callee.property.name;
|
|
80
|
+
const args = n.arguments;
|
|
81
|
+
const named = object.type === "Identifier" ? namedObjectCall(s, object.name, method, args, n) : claim((p) => p.call?.(s, n));
|
|
82
|
+
return named ?? methodCall(s, object, method, args, n);
|
|
83
|
+
}
|
|
84
|
+
function namedObjectCall(s, name, method, args, n) {
|
|
85
|
+
const known = staticCall(s, name, method, args, n);
|
|
86
|
+
if (known)
|
|
87
|
+
return known;
|
|
88
|
+
const own = claim((p) => p.call?.(s, n));
|
|
89
|
+
if (own)
|
|
90
|
+
return own;
|
|
91
|
+
const mine = name === "$setup" || name === "_ctx" ? setupCall(s, name, method, args, n) : null;
|
|
92
|
+
if (mine)
|
|
93
|
+
return mine;
|
|
94
|
+
return globalObjectCall(s, name, method, args, n);
|
|
95
|
+
}
|
|
96
|
+
function globalObjectCall(s, name, method, args, n) {
|
|
97
|
+
if (name === "Math")
|
|
98
|
+
return mathCall(s, method, args, n);
|
|
99
|
+
if (BUILTINS.has(name) && !s.locals.has(name) && !s.setup.has(name))
|
|
100
|
+
return builtin(s, `${name}.${method}()`, n);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
function methodCall(s, object, method, args, n) {
|
|
104
|
+
const fixed = literalReceiverCall(s, object, method, args, n);
|
|
105
|
+
if (fixed)
|
|
106
|
+
return fixed;
|
|
107
|
+
const literal = method === "filter" && args.length === 1 && isBoolean(s, args[0]) && object.type === "ArrayExpression";
|
|
108
|
+
const target = (literal ? presentLiteral(s, object) : null) ?? expr(s, object);
|
|
109
|
+
return valueMethod(s, target, method, args, n);
|
|
110
|
+
}
|
|
111
|
+
function literalReceiverCall(s, object, method, args, n) {
|
|
112
|
+
const copied = sortedCopy(s, object, method, args, n);
|
|
113
|
+
if (copied)
|
|
114
|
+
return copied;
|
|
115
|
+
if (object.type === "RegExpLiteral" && method === "test")
|
|
116
|
+
return regexTest(s, object, args, n);
|
|
117
|
+
const map = object.type === "Identifier" || object.type === "MemberExpression" ? constOf(s, object) : null;
|
|
118
|
+
if (map?.sym.k === "const" && map.sym.c.k === "map")
|
|
119
|
+
return mapCall(s, map, method, args, n);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
function sortedCopy(s, object, method, args, n) {
|
|
123
|
+
if ((method !== "sort" && method !== "reverse") || object.type !== "ArrayExpression")
|
|
124
|
+
return null;
|
|
125
|
+
const copy = expr(s, object);
|
|
126
|
+
return copy.ty.k === "list" ? listMethod(s, copy, method === "sort" ? "toSorted" : "toReversed", args, n) : null;
|
|
127
|
+
}
|
|
128
|
+
function valueMethod(s, target, method, args, n) {
|
|
129
|
+
const typed = claim((p) => p.method?.(s, target, method, args, n));
|
|
130
|
+
if (typed)
|
|
131
|
+
return typed;
|
|
132
|
+
if (target.ty.k === "str") {
|
|
133
|
+
const m = (args.length === 0 ? noArgStringMethod(target, method) : null) ?? stringMethod(s, target, method, args, n);
|
|
134
|
+
if (m)
|
|
135
|
+
return m;
|
|
274
136
|
}
|
|
275
|
-
|
|
137
|
+
const numbered = numberMethod(s, target, method, args, n);
|
|
138
|
+
if (numbered)
|
|
139
|
+
return numbered;
|
|
140
|
+
if (target.owned)
|
|
141
|
+
refuseInPlace(s.comp, `\`.${method}()\``, n);
|
|
142
|
+
return listCall(s, target, method, args, n) ?? fail(s.comp, "FV0602", `\`.${method}()\` is not supported`, n);
|
|
276
143
|
}
|
|
277
|
-
const NUMBER_TESTS = new Set(["isNaN", "isFinite", "isInteger", "isSafeInteger"]);
|
|
278
|
-
const ROUNDED_BY_EACH = new Set("acos acosh asin asinh atan atan2 atanh cbrt cos cosh exp expm1 hypot log log10 log1p log2 sin sinh tan tanh".split(" "));
|
|
279
144
|
/** The globals of JavaScript a template may name, which the server translates only some of. */
|
|
280
145
|
export const BUILTINS = new Set("Array BigInt Boolean JSON Map Math Number Object RegExp Set String Symbol console decodeURI decodeURIComponent encodeURI encodeURIComponent isFinite isNaN parseFloat parseInt".split(" "));
|
|
281
146
|
const OF_BUILTINS = {
|
|
@@ -299,74 +164,29 @@ export function builtin(s, what, n) {
|
|
|
299
164
|
const of = OF_BUILTINS[name];
|
|
300
165
|
return fail(s.comp, "FV0633", `\`${what}\` is not supported: ${of ? `of \`${name}\`, the server translates ${of}` : `the server does not translate \`${name}\``}`, n);
|
|
301
166
|
}
|
|
302
|
-
function floatTest(method, x) {
|
|
303
|
-
switch (method) {
|
|
304
|
-
case "isNaN":
|
|
305
|
-
return `${receiver(x)}.is_nan()`;
|
|
306
|
-
case "isFinite":
|
|
307
|
-
return `${receiver(x)}.is_finite()`;
|
|
308
|
-
case "isInteger":
|
|
309
|
-
return `${receiver(x)}.fract() == 0.0`;
|
|
310
|
-
default:
|
|
311
|
-
return /^[\w.]+$/.test(x) ? `${x}.fract() == 0.0 && ${x}.abs() <= 9_007_199_254_740_991.0` : `matches!(${bare(x)}, v if v.fract() == 0.0 && v.abs() <= 9_007_199_254_740_991.0)`;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
function intTest(method, x) {
|
|
315
|
-
if (method === "isSafeInteger")
|
|
316
|
-
return `(-9_007_199_254_740_991..=9_007_199_254_740_991).contains(&${operand(x, UNARY)})`;
|
|
317
|
-
return String(method !== "isNaN");
|
|
318
|
-
}
|
|
319
|
-
function numberTest(s, method, args, n, global) {
|
|
320
|
-
const name = global ? `\`${method}()\`` : `\`Number.${method}()\``;
|
|
321
|
-
if (args.length !== 1)
|
|
322
|
-
return fail(s.comp, "FV0718", `${name} takes one number`, n);
|
|
323
|
-
const v = expr(s, args[0]);
|
|
324
|
-
if (isNumber(v.ty)) {
|
|
325
|
-
if (v.num !== undefined) {
|
|
326
|
-
const konst = Number[method](v.num);
|
|
327
|
-
return { code: String(konst), ty: BOOL, konst };
|
|
328
|
-
}
|
|
329
|
-
return boolOf(v.ty.k === "int" ? intTest(method, v.code) : floatTest(method, v.code));
|
|
330
|
-
}
|
|
331
|
-
if (!global && v.ty.k === "opt" && isNumber(v.ty.of)) {
|
|
332
|
-
const each = v.ty.of.k === "int" ? intTest(method, "v") : floatTest(method, "v");
|
|
333
|
-
if (each === "false")
|
|
334
|
-
return { code: "false", ty: BOOL, konst: false };
|
|
335
|
-
return boolOf(each === "true" ? `${atom(v.code)}.is_some()` : `${atom(v.code)}.is_some_and(|v| ${each})`);
|
|
336
|
-
}
|
|
337
|
-
if (global) {
|
|
338
|
-
return fail(s.comp, "FV0718", `${name} converts its argument as \`Number()\` does, which the server does for a number only: write \`Number.${method}(Number(x))\` for a string, or pass a present number`, args[0]);
|
|
339
|
-
}
|
|
340
|
-
return fail(s.comp, "FV0718", `${name} of ${describeTy(v.ty)}, for which it is \`false\` whatever it holds, since it does not convert its argument: pass a number, present or optional`, args[0]);
|
|
341
|
-
}
|
|
342
167
|
export function isObjectCall(n, method) {
|
|
343
168
|
return (n?.type === "CallExpression" && n.callee.type === "MemberExpression" && !n.callee.computed &&
|
|
344
169
|
n.callee.object.type === "Identifier" && n.callee.object.name === "Object" && n.callee.property.name === method);
|
|
345
170
|
}
|
|
346
|
-
function
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const f = /^([\w:]+)\(v\)$/.exec(each)?.[1];
|
|
366
|
-
return `format!("[{}]", ${items(v)}.map(${f ?? `|v| ${each}`}).collect::<Vec<_>>().join(","))`;
|
|
367
|
-
}
|
|
368
|
-
const w = asWritten(v);
|
|
369
|
-
return one(w.code, w.ty);
|
|
171
|
+
function ownCall(s, callee, args, n) {
|
|
172
|
+
const helper = s.helpers.get(callee.name);
|
|
173
|
+
if (helper)
|
|
174
|
+
return helperCall(s, helper, args, n);
|
|
175
|
+
const fn = s.locals.has(callee.name) ? undefined : s.functions.get(callee.name);
|
|
176
|
+
return fn ? callFunction(s, callee.fvName ?? callee.name, fn, args, n) : null;
|
|
177
|
+
}
|
|
178
|
+
function setupCall(s, of, method, args, n) {
|
|
179
|
+
const helper = s.helpers.get(method);
|
|
180
|
+
if (helper)
|
|
181
|
+
return helperCall(s, helper, args, n);
|
|
182
|
+
const fn = s.functions.get(method);
|
|
183
|
+
if (fn)
|
|
184
|
+
return callFunction(s, method, fn, args, n);
|
|
185
|
+
if (s.clientOnly.has(method))
|
|
186
|
+
return refuseClientOnly(s, method, n, true);
|
|
187
|
+
if (!s.setup.has(method) && !(of === "_ctx" && s.comp.props.fields.some((f) => f.js === method)))
|
|
188
|
+
return refuseUnavailable(s, method, n, true);
|
|
189
|
+
return null;
|
|
370
190
|
}
|
|
371
191
|
export function helperCall(s, name, args, n) {
|
|
372
192
|
const h = ctx.helpers[name];
|