@yuneta/gobj-ui 7.26.44 → 7.26.46
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 +160 -20
- package/dist/gobj-ui.cjs.js +326 -37
- package/dist/gobj-ui.es.js +327 -39
- package/index.js +1 -0
- package/package.json +1 -1
- package/scripts/check-markup-strings.mjs +4 -1
- package/scripts/validate-locales.mjs +709 -178
- package/src/c_yui_form.js +116 -50
- package/src/c_yui_node.js +3 -1
- package/src/c_yui_schema_editor.js +3 -0
- package/src/c_yui_shell.js +113 -12
- package/src/c_yui_window.js +44 -5
- package/src/form_table_edits_ask.wiring.test.js +11 -2
- package/src/form_table_rows.wiring.test.js +284 -9
- package/src/form_time_cell_editor.js +143 -0
- package/src/form_time_cell_editor.test.js +116 -0
- package/src/i18n_key_functions.js +2 -2
- package/src/i18n_key_functions.test.js +45 -7
- package/src/node_nav_events.wiring.test.js +6 -0
- package/src/schema_editor_diagram_click.wiring.test.js +28 -0
- package/src/shell_escape_taken.wiring.test.js +34 -0
- package/src/shell_focus_trap.js +47 -1
- package/src/shell_focus_trap.test.js +95 -0
- package/src/shell_modals.js +2 -2
- package/src/shell_stop_overlays.wiring.test.js +143 -0
- package/src/tabulator_edit_internals.test.js +50 -0
- package/src/window_dialog.wiring.test.js +80 -1
- package/src/window_rect_rounding.wiring.test.js +45 -0
|
@@ -61,7 +61,11 @@
|
|
|
61
61
|
* name, an alias of one (`const translate = t`, a `.bind()`,
|
|
62
62
|
* a destructuring, `const {t: tt} = i18next` or a parameter
|
|
63
63
|
* `{t: tt}`, a re-export), called `t?.(k)`, `t.call(x, k)` or
|
|
64
|
-
* `t.apply(x, [k])
|
|
64
|
+
* `t.apply(x, [k])` (`t["call"](x, k)` too, a computed
|
|
65
|
+
* `["bind"]`, a name a const gives, `t[M]`, or a template;
|
|
66
|
+
* and a spread of an array the source writes out,
|
|
67
|
+
* `t(...["k"])`, `t.apply(x, KEYS)` with KEYS a const
|
|
68
|
+
* array); an array there is i18next's list of
|
|
65
69
|
* fallback keys, each one a key (`t([k, "fallback"])`). A
|
|
66
70
|
* `.bind()` that binds a key (`const tk = t.bind(null, k)`)
|
|
67
71
|
* hands t() that key, read where the bind is written, and
|
|
@@ -237,9 +241,12 @@
|
|
|
237
241
|
* alias of (a parameter `translate`, a `let` alias,
|
|
238
242
|
* `i18next.getFixedT()`), or called by what is no name of it --
|
|
239
243
|
* `(0, t)(k)`, `[t][0](k)`, `Reflect.apply(t, x, [k])`,
|
|
240
|
-
* `Function.prototype.call.call(t, x, k)
|
|
241
|
-
*
|
|
242
|
-
*
|
|
244
|
+
* `Function.prototype.call.call(t, x, k)`, a computed name the
|
|
245
|
+
* reader does not follow to one string --; a key in a spread of
|
|
246
|
+
* what is no array the source writes out (`t(...args)`); a
|
|
247
|
+
* parameter a closure returns (`const inner = () => key;
|
|
248
|
+
* t(inner())`: the search for the functions that forward a key
|
|
249
|
+
* does not see it); a translator
|
|
243
250
|
* handed to a function (`{t: t}`, `yui_tabulator_lang(t)`: it
|
|
244
251
|
* calls it with keys of its own), or to any method but those
|
|
245
252
|
* above (`keys.reduce(t)`, `keys.sort(t)`, an alias of a method,
|
|
@@ -248,10 +255,10 @@
|
|
|
248
255
|
* label`: the reader reads the literals of a `let`, not what it
|
|
249
256
|
* translates), or returned by a function (`{i18n:
|
|
250
257
|
* label_of(x)}`); a key function reached through a parameter, a
|
|
251
|
-
* `let` given more than one value, a computed member
|
|
252
|
-
* (`API[name](...)`); a data-i18n* attribute written
|
|
253
|
-
* alias of `dataset`, by Object.assign() into it, or
|
|
254
|
-
* `let`; an export of a `let`; a published list mutated through a
|
|
258
|
+
* `let` given more than one value, a computed member named by
|
|
259
|
+
* no const (`API[name](...)`); a data-i18n* attribute written
|
|
260
|
+
* through an alias of `dataset`, by Object.assign() into it, or
|
|
261
|
+
* named by a `let`; an export of a `let`; a published list mutated through a
|
|
255
262
|
* function it is handed to, or by
|
|
256
263
|
* `Array.prototype.push.call(X_I18N_KEYS, k)`; a module of a
|
|
257
264
|
* package (gobj-js, i18next); what is written into a const table
|
|
@@ -259,13 +266,19 @@
|
|
|
259
266
|
* gobj_create().
|
|
260
267
|
*
|
|
261
268
|
* Where the reader GIVES UP on a value it says so, with the file
|
|
262
|
-
* and the line
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
+
* and the line of the READ (and the place it went past), and
|
|
270
|
+
* that fails: a value read through more than MAX_DEPTH (24)
|
|
271
|
+
* steps -- each const, alias, call, property, element and branch
|
|
272
|
+
* of ?: / || / ?? is one --, a const that leads back to itself,
|
|
273
|
+
* an expression that can take more than MAX_VALUES (10000)
|
|
274
|
+
* values -- a key behind it would go unasked. Up to 7.26.42 it
|
|
275
|
+
* stopped there in silence, and a chain of consts that doubles at
|
|
276
|
+
* every link died with a RangeError naming no file. A const is
|
|
277
|
+
* read once, wherever it is read, and keeps the steps it took, so
|
|
278
|
+
* the verdict does not depend on what was read first. A chain of
|
|
279
|
+
* aliases of a function or of a published list is followed to its
|
|
280
|
+
* end, and is a give-up only when a translator, a key function or
|
|
281
|
+
* a list can be there.
|
|
269
282
|
|
|
270
283
|
* Options (paths relative to the app's directory):
|
|
271
284
|
*
|
|
@@ -360,12 +373,20 @@ function violation_count()
|
|
|
360
373
|
}
|
|
361
374
|
|
|
362
375
|
/***************************************************************
|
|
363
|
-
* A fatal problem of the setup, not a violation: said, exit 1
|
|
376
|
+
* A fatal problem of the setup, not a violation: said, exit 1. It
|
|
377
|
+
* ends the run by throwing Abort (caught where the script runs main()),
|
|
378
|
+
* never by process.exit(): what was written before it to a pipe may
|
|
379
|
+
* still be on its way, and process.exit() drops it.
|
|
364
380
|
***************************************************************/
|
|
381
|
+
class Abort extends Error
|
|
382
|
+
{
|
|
383
|
+
}
|
|
384
|
+
|
|
365
385
|
function abort(msg)
|
|
366
386
|
{
|
|
367
387
|
process.stderr.write(`validate-locales: ${msg}\n`);
|
|
368
|
-
process.
|
|
388
|
+
process.exitCode = 1;
|
|
389
|
+
throw new Abort(msg);
|
|
369
390
|
}
|
|
370
391
|
|
|
371
392
|
/***************************************************************
|
|
@@ -384,8 +405,10 @@ let acorn_parse;
|
|
|
384
405
|
try {
|
|
385
406
|
({parse: acorn_parse} = await import("acorn"));
|
|
386
407
|
} catch(e) {
|
|
387
|
-
|
|
388
|
-
|
|
408
|
+
/* Nothing was said before: exit at once, the module cannot load */
|
|
409
|
+
process.stderr.write(`validate-locales: cannot load acorn (${e.message}): it is a dependency of ` +
|
|
410
|
+
`@yuneta/gobj-ui, so the install is incomplete: run npm install\n`);
|
|
411
|
+
process.exit(1);
|
|
389
412
|
}
|
|
390
413
|
|
|
391
414
|
/***************************************************************
|
|
@@ -774,8 +797,11 @@ async function main()
|
|
|
774
797
|
}
|
|
775
798
|
|
|
776
799
|
if(errors > 0) {
|
|
800
|
+
/* exitCode, not process.exit(): a long list written to a pipe is
|
|
801
|
+
* still on its way, and up to gobj-ui 7.26.44 it was cut short */
|
|
777
802
|
process.stderr.write(`validate-locales: ${errors} violation(s), see above\n`);
|
|
778
|
-
process.
|
|
803
|
+
process.exitCode = 1;
|
|
804
|
+
return;
|
|
779
805
|
}
|
|
780
806
|
|
|
781
807
|
let n_keys = ref_plain.size + bases.size;
|
|
@@ -968,20 +994,20 @@ function iteration_call(call, scope)
|
|
|
968
994
|
if(c.type !== "MemberExpression") {
|
|
969
995
|
return null;
|
|
970
996
|
}
|
|
971
|
-
let name =
|
|
997
|
+
let name = member_name(c, scope);
|
|
972
998
|
if(ITERATION_METHODS.has(name)) {
|
|
973
999
|
let cb = call.arguments[0];
|
|
974
1000
|
return (cb && cb.type !== "SpreadElement")? {method: name, receiver: c.object, callback: cb, form: ""} : null;
|
|
975
1001
|
}
|
|
976
1002
|
if(name === "call" || name === "apply") {
|
|
977
1003
|
let inner = unchain(c.object);
|
|
978
|
-
let method = (inner.type === "MemberExpression")?
|
|
1004
|
+
let method = (inner.type === "MemberExpression")? member_name(inner, scope) : null;
|
|
979
1005
|
if(!ITERATION_METHODS.has(method)) {
|
|
980
1006
|
return null;
|
|
981
1007
|
}
|
|
982
|
-
let receiver = call.arguments
|
|
983
|
-
let
|
|
984
|
-
let cb = (name === "call")? rest : (
|
|
1008
|
+
let [receiver, rest] = written_args(call.arguments, scope);
|
|
1009
|
+
let listed = (name === "apply" && rest && rest.type !== "SpreadElement")? written_elements(rest, scope) : null;
|
|
1010
|
+
let cb = (name === "call")? rest : (listed? listed[0] : null);
|
|
985
1011
|
if(!receiver || receiver.type === "SpreadElement" || !cb || cb.type === "SpreadElement") {
|
|
986
1012
|
return null;
|
|
987
1013
|
}
|
|
@@ -1769,18 +1795,48 @@ const TRANSLATOR = Object.freeze({kind: "t", name: "t"});
|
|
|
1769
1795
|
* an object, a function of a package
|
|
1770
1796
|
* the reader does not read
|
|
1771
1797
|
***************************************************************/
|
|
1772
|
-
function callee_of(node, scope
|
|
1798
|
+
function callee_of(node, scope)
|
|
1799
|
+
{
|
|
1800
|
+
return from_read(node, scope, () => {
|
|
1801
|
+
let far = {past: null, lost: null, seen: new Set()};
|
|
1802
|
+
let r = callee_at(node, scope, 0, far);
|
|
1803
|
+
if(far.lost) {
|
|
1804
|
+
give_up(far.lost.node, far.lost.scope, far.lost.why);
|
|
1805
|
+
return null;
|
|
1806
|
+
}
|
|
1807
|
+
if(far.past && may_translate(r)) {
|
|
1808
|
+
give_up(far.past.node, far.past.scope, GIVE_UP_DEEP);
|
|
1809
|
+
return null;
|
|
1810
|
+
}
|
|
1811
|
+
return r;
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
/* Can a callee (callee_of()) be a translator, or a key function of a
|
|
1816
|
+
* table -- a function of the library? */
|
|
1817
|
+
function may_translate(r)
|
|
1818
|
+
{
|
|
1819
|
+
return !!r && (r.kind === "t" || TRANSLATOR_NAMES.has(r.name) || lib_module_of(r.url) !== null);
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
/* callee_of() `depth` steps down: past MAX_DEPTH it goes on, to see
|
|
1823
|
+
* what the chain ends in (`far.past`: where it went past); past
|
|
1824
|
+
* MAX_FOLLOW, or round a cycle, the end is not known (`far.lost`) */
|
|
1825
|
+
function callee_at(node, scope, depth, far)
|
|
1773
1826
|
{
|
|
1774
1827
|
if(!node) {
|
|
1775
1828
|
return null;
|
|
1776
1829
|
}
|
|
1777
|
-
if(depth > MAX_DEPTH) {
|
|
1778
|
-
|
|
1830
|
+
if(depth > MAX_DEPTH && !far.past) {
|
|
1831
|
+
far.past = {node, scope};
|
|
1832
|
+
}
|
|
1833
|
+
if(depth > MAX_FOLLOW) {
|
|
1834
|
+
far.lost = far.lost || {node, scope, why: GIVE_UP_DEEP};
|
|
1779
1835
|
return null;
|
|
1780
1836
|
}
|
|
1781
1837
|
switch(node.type) {
|
|
1782
1838
|
case "ChainExpression":
|
|
1783
|
-
return
|
|
1839
|
+
return callee_at(node.expression, scope, depth + 1, far);
|
|
1784
1840
|
|
|
1785
1841
|
case "Identifier": {
|
|
1786
1842
|
let named = TRANSLATOR_NAMES.has(node.name)? TRANSLATOR : null;
|
|
@@ -1799,13 +1855,20 @@ function callee_of(node, scope, depth = 0)
|
|
|
1799
1855
|
if(FUNCTION_RE.test(b.init.type)) {
|
|
1800
1856
|
return {kind: "fn", fn: b.init, scope: b.scope, name: b.name, url: url_of(b.scope)};
|
|
1801
1857
|
}
|
|
1802
|
-
|
|
1858
|
+
if(far.seen.has(b.init)) {
|
|
1859
|
+
far.lost = far.lost || {node: b.init, scope: b.scope, why: GIVE_UP_CYCLE};
|
|
1860
|
+
return null;
|
|
1861
|
+
}
|
|
1862
|
+
far.seen.add(b.init);
|
|
1863
|
+
let r = callee_at(b.init, b.scope, depth + 1, far);
|
|
1864
|
+
far.seen.delete(b.init);
|
|
1865
|
+
return r || named;
|
|
1803
1866
|
case "var": {
|
|
1804
1867
|
let fn = var_function(b);
|
|
1805
1868
|
return fn? {kind: "fn", fn, scope: b.scope, name: b.name, url: url_of(b.scope)} : named;
|
|
1806
1869
|
}
|
|
1807
1870
|
case "import":
|
|
1808
|
-
return exported_callee(import_target(b), depth) || named;
|
|
1871
|
+
return exported_callee(import_target(b), depth, far) || named;
|
|
1809
1872
|
case "param":
|
|
1810
1873
|
/* `function f({t: tt})` is `opts.t`, the same member */
|
|
1811
1874
|
return /\.(?:t|tr)$/.test(b.path)? TRANSLATOR : named;
|
|
@@ -1815,7 +1878,7 @@ function callee_of(node, scope, depth = 0)
|
|
|
1815
1878
|
}
|
|
1816
1879
|
|
|
1817
1880
|
case "MemberExpression": {
|
|
1818
|
-
let step =
|
|
1881
|
+
let step = {prop: member_name(node, scope), computed: !!node.computed};
|
|
1819
1882
|
if(step.prop === null) {
|
|
1820
1883
|
return null;
|
|
1821
1884
|
}
|
|
@@ -1825,7 +1888,7 @@ function callee_of(node, scope, depth = 0)
|
|
|
1825
1888
|
if(b && b.kind === "import" && b.imported === "*") {
|
|
1826
1889
|
let ns = import_target(b);
|
|
1827
1890
|
if(ns && ns.kind === "namespace") {
|
|
1828
|
-
let r = exported_callee(module_export(ns.url, step.prop), depth);
|
|
1891
|
+
let r = exported_callee(module_export(ns.url, step.prop), depth, far);
|
|
1829
1892
|
if(r) {
|
|
1830
1893
|
return r;
|
|
1831
1894
|
}
|
|
@@ -1843,7 +1906,7 @@ function callee_of(node, scope, depth = 0)
|
|
|
1843
1906
|
let p = map.init.properties.find((q) => q.type === "Property" && prop_name(q) === step.prop
|
|
1844
1907
|
&& q.kind === "init" && !q.computed);
|
|
1845
1908
|
if(p) {
|
|
1846
|
-
let r =
|
|
1909
|
+
let r = callee_at(p.value, [...map.scope, map.init, p], depth + 1, far);
|
|
1847
1910
|
if(r) {
|
|
1848
1911
|
return r;
|
|
1849
1912
|
}
|
|
@@ -1857,18 +1920,19 @@ function callee_of(node, scope, depth = 0)
|
|
|
1857
1920
|
/* f.bind(x) is f; f.bind(x, a, ...) is f with its first arguments
|
|
1858
1921
|
* BOUND, so what a call of it is handed comes after them */
|
|
1859
1922
|
let c = node.callee;
|
|
1860
|
-
if(c.type !== "MemberExpression" || c
|
|
1861
|
-
|| c.property.name !== "bind") {
|
|
1923
|
+
if(c.type !== "MemberExpression" || member_name(c, scope) !== "bind") {
|
|
1862
1924
|
return null;
|
|
1863
1925
|
}
|
|
1864
|
-
let inner =
|
|
1865
|
-
let
|
|
1866
|
-
|
|
1926
|
+
let inner = callee_at(c.object, scope, depth + 1, far);
|
|
1927
|
+
let given = written_args(node.arguments, scope);
|
|
1928
|
+
let hidden = is_spread(given[0]); // `f.bind(...X)`: what it binds is not known
|
|
1929
|
+
let taken = given.slice(1);
|
|
1930
|
+
if(!inner || (taken.length === 0 && !hidden)) {
|
|
1867
1931
|
return inner;
|
|
1868
1932
|
}
|
|
1869
1933
|
return Object.assign({}, inner, {
|
|
1870
1934
|
bound: (inner.bound || 0) + taken.length,
|
|
1871
|
-
bound_spread: !!inner.bound_spread || taken.some(
|
|
1935
|
+
bound_spread: !!inner.bound_spread || hidden || taken.some(is_spread)
|
|
1872
1936
|
});
|
|
1873
1937
|
}
|
|
1874
1938
|
|
|
@@ -1881,7 +1945,7 @@ function callee_of(node, scope, depth = 0)
|
|
|
1881
1945
|
* What an export (module_export()) is as a callee: a function, the
|
|
1882
1946
|
* i18next `t`, or a const that is an alias of one
|
|
1883
1947
|
***************************************************************/
|
|
1884
|
-
function exported_callee(x, depth)
|
|
1948
|
+
function exported_callee(x, depth, far)
|
|
1885
1949
|
{
|
|
1886
1950
|
if(!x) {
|
|
1887
1951
|
return null;
|
|
@@ -1893,7 +1957,14 @@ function exported_callee(x, depth)
|
|
|
1893
1957
|
return (x.source === "i18next" && x.imported === "t")? TRANSLATOR : null;
|
|
1894
1958
|
}
|
|
1895
1959
|
if(x.kind === "const" && x.steps.length === 0) {
|
|
1896
|
-
|
|
1960
|
+
if(far.seen.has(x.init)) {
|
|
1961
|
+
far.lost = far.lost || {node: x.init, scope: x.scope, why: GIVE_UP_CYCLE};
|
|
1962
|
+
return null;
|
|
1963
|
+
}
|
|
1964
|
+
far.seen.add(x.init);
|
|
1965
|
+
let r = callee_at(x.init, x.scope, depth + 1, far);
|
|
1966
|
+
far.seen.delete(x.init);
|
|
1967
|
+
return r;
|
|
1897
1968
|
}
|
|
1898
1969
|
return null;
|
|
1899
1970
|
}
|
|
@@ -1942,22 +2013,23 @@ function call_target(call, scope)
|
|
|
1942
2013
|
}
|
|
1943
2014
|
let r = null;
|
|
1944
2015
|
let callee = call.callee;
|
|
1945
|
-
let method = (callee.type === "MemberExpression"
|
|
1946
|
-
callee.property.name : null;
|
|
2016
|
+
let method = (callee.type === "MemberExpression")? member_name(callee, scope) : null;
|
|
1947
2017
|
if(method === "call" || method === "apply") {
|
|
1948
2018
|
let inner = callee_of(callee.object, scope);
|
|
1949
2019
|
if(inner) {
|
|
1950
|
-
let
|
|
2020
|
+
let given = written_args(call.arguments, scope);
|
|
2021
|
+
let hidden = is_spread(given[0]); // `f.call(...X)`: where its arguments start is not known
|
|
2022
|
+
let args = hidden? [given[0]] : given.slice(1);
|
|
1951
2023
|
if(method === "apply") {
|
|
1952
|
-
let list =
|
|
1953
|
-
args = !list? [] : (list
|
|
2024
|
+
let list = given[1];
|
|
2025
|
+
args = (hidden || is_spread(list))? null : !list? [] : written_elements(list, scope);
|
|
1954
2026
|
}
|
|
1955
2027
|
r = {target: inner, args};
|
|
1956
2028
|
}
|
|
1957
2029
|
}
|
|
1958
2030
|
if(!r) {
|
|
1959
2031
|
let target = callee_of(callee, scope);
|
|
1960
|
-
r = target? {target, args: call.arguments} : null;
|
|
2032
|
+
r = target? {target, args: written_args(call.arguments, scope)} : null;
|
|
1961
2033
|
}
|
|
1962
2034
|
if(r && r.target.bound) {
|
|
1963
2035
|
/* Up to 7.26.41 the bound arguments were not counted: what a call of
|
|
@@ -1987,15 +2059,19 @@ function call_target(call, scope)
|
|
|
1987
2059
|
function bind_kind(call, scope, table = I18N_KEY_FUNCTIONS)
|
|
1988
2060
|
{
|
|
1989
2061
|
let c = call.callee;
|
|
1990
|
-
if(c.type !== "MemberExpression" || c
|
|
1991
|
-
|
|
2062
|
+
if(c.type !== "MemberExpression" || member_name(c, scope) !== "bind") {
|
|
2063
|
+
return null;
|
|
2064
|
+
}
|
|
2065
|
+
let given = written_args(call.arguments, scope);
|
|
2066
|
+
let hidden = is_spread(given[0]);
|
|
2067
|
+
if(given.length < 2 && !hidden) {
|
|
1992
2068
|
return null;
|
|
1993
2069
|
}
|
|
1994
2070
|
let inner = callee_of(c.object, scope);
|
|
1995
2071
|
if(!inner) {
|
|
1996
2072
|
return null;
|
|
1997
2073
|
}
|
|
1998
|
-
let args = inner.bound_spread? null : [...new Array(inner.bound || 0).fill(null), ...
|
|
2074
|
+
let args = (inner.bound_spread || hidden)? null : [...new Array(inner.bound || 0).fill(null), ...given.slice(1)];
|
|
1999
2075
|
if(inner.kind === "t") {
|
|
2000
2076
|
return {kind: "t", target: inner, args};
|
|
2001
2077
|
}
|
|
@@ -2039,7 +2115,8 @@ function call_kind(call, scope, table = I18N_KEY_FUNCTIONS)
|
|
|
2039
2115
|
let fns = module? key_fn_index(table).by_module.get(module) : null;
|
|
2040
2116
|
let entry = (fns && call.callee.type === "Identifier" && !binding_of(call.callee.name, scope))?
|
|
2041
2117
|
(fns.get(call.callee.name) || null) : null;
|
|
2042
|
-
return entry? {kind: "key", entry, target: {kind: "unbound", name: entry.name},
|
|
2118
|
+
return entry? {kind: "key", entry, target: {kind: "unbound", name: entry.name},
|
|
2119
|
+
args: written_args(call.arguments, scope)} : null;
|
|
2043
2120
|
}
|
|
2044
2121
|
let {target, args} = r;
|
|
2045
2122
|
if(target.kind === "t") {
|
|
@@ -2093,6 +2170,9 @@ function is_translated_text(n, scope, depth = 0)
|
|
|
2093
2170
|
if(!n) {
|
|
2094
2171
|
return false;
|
|
2095
2172
|
}
|
|
2173
|
+
if(READ_AT.length === 0) {
|
|
2174
|
+
return from_read(n, scope, () => is_translated_text(n, scope, depth));
|
|
2175
|
+
}
|
|
2096
2176
|
if(depth > MAX_DEPTH) {
|
|
2097
2177
|
give_up(n, scope, GIVE_UP_DEEP);
|
|
2098
2178
|
return false;
|
|
@@ -2182,7 +2262,7 @@ function translator_callback(call, scope)
|
|
|
2182
2262
|
{how: "elements", method: it.method, form: it.form, receiver: it.receiver, arg: it.callback} : null;
|
|
2183
2263
|
}
|
|
2184
2264
|
let c = (call.callee.type === "ChainExpression")? call.callee.expression : call.callee;
|
|
2185
|
-
let method = (c.type === "MemberExpression")?
|
|
2265
|
+
let method = (c.type === "MemberExpression")? member_name(c, scope) : null;
|
|
2186
2266
|
if(SETTLE_METHODS.has(method)) {
|
|
2187
2267
|
let arg = call.arguments.find(is_translator);
|
|
2188
2268
|
return arg? {how: "settled", method, arg} : null;
|
|
@@ -2206,17 +2286,23 @@ function is_key_function(target)
|
|
|
2206
2286
|
***************************/
|
|
2207
2287
|
|
|
2208
2288
|
|
|
2209
|
-
/* How
|
|
2210
|
-
*
|
|
2211
|
-
*
|
|
2212
|
-
*
|
|
2289
|
+
/* How many STEPS a value is read through (a cycle stops here too), and
|
|
2290
|
+
* how many values one expression may take. Past either the reader GIVES
|
|
2291
|
+
* UP, and says so (give_up()): a key behind a value it does not follow
|
|
2292
|
+
* would go unasked, and the build say OK */
|
|
2213
2293
|
const MAX_DEPTH = 24;
|
|
2214
2294
|
const MAX_VALUES = 10000;
|
|
2215
2295
|
|
|
2296
|
+
/* How far an alias of a FUNCTION (callee_of()) or of a published list
|
|
2297
|
+
* (list_mutations()) is followed past MAX_DEPTH, to see what it ends
|
|
2298
|
+
* in: only an end that can be a translator, a key function or a list
|
|
2299
|
+
* makes the reader give up. Past this, the end is not known */
|
|
2300
|
+
const MAX_FOLLOW = 1000;
|
|
2301
|
+
|
|
2216
2302
|
/***************************************************************
|
|
2217
|
-
* Where the reader GAVE UP on a value:
|
|
2218
|
-
* MAX_DEPTH, a const that leads back to itself, an expression
|
|
2219
|
-
* can take more than MAX_VALUES values. A key behind it would go
|
|
2303
|
+
* Where the reader GAVE UP on a value: one read through more than
|
|
2304
|
+
* MAX_DEPTH steps, a const that leads back to itself, an expression
|
|
2305
|
+
* that can take more than MAX_VALUES values. A key behind it would go
|
|
2220
2306
|
* unasked, so it is a violation, with the file and the line
|
|
2221
2307
|
* (collect_used_keys(); the library's own test holds the library to
|
|
2222
2308
|
* none). Up to 7.26.42 the reader stopped there in silence: a chain
|
|
@@ -2224,43 +2310,186 @@ const MAX_VALUES = 10000;
|
|
|
2224
2310
|
* that doubles at every step (`{...O, ...O}`) grew without end and
|
|
2225
2311
|
* died with a RangeError naming no file.
|
|
2226
2312
|
*
|
|
2313
|
+
* It is said at the place the value is READ (READ_AT, the outermost
|
|
2314
|
+
* read in progress), with the node it went past: up to gobj-ui
|
|
2315
|
+
* 7.26.44 it was said at the deepest link only, which can be in
|
|
2316
|
+
* another file than the read that needed it.
|
|
2317
|
+
*
|
|
2227
2318
|
* `node` is the value it gave up on, `scope` the chain of its
|
|
2228
2319
|
* ancestors (the first one, the module: where it is said).
|
|
2229
2320
|
***************************************************************/
|
|
2230
|
-
const GAVE_UP = new Map(); //
|
|
2321
|
+
const GAVE_UP = new Map(); // the read -> {node, scope, why, past: {node, scope} | null}
|
|
2322
|
+
const READ_AT = []; // the reads in progress, the outermost first: {node, scope}
|
|
2231
2323
|
|
|
2232
|
-
const GIVE_UP_DEEP = `it is more than ${MAX_DEPTH} steps
|
|
2233
|
-
`
|
|
2324
|
+
const GIVE_UP_DEEP = `it is read through more than ${MAX_DEPTH} steps (each const, alias, call, ` +
|
|
2325
|
+
`property, element and branch of ?: / || / ?? it goes through is one): shorten the chain`;
|
|
2234
2326
|
const GIVE_UP_CYCLE = `it is a const that leads back to itself: break the cycle`;
|
|
2235
2327
|
const GIVE_UP_MANY = `it can take more than ${MAX_VALUES} values: split it`;
|
|
2236
2328
|
|
|
2237
2329
|
function give_up(node, scope, why)
|
|
2238
2330
|
{
|
|
2239
|
-
|
|
2240
|
-
|
|
2331
|
+
let read = READ_AT[0] || {node, scope};
|
|
2332
|
+
if(read.node && !GAVE_UP.has(read.node)) {
|
|
2333
|
+
/* A scope may be a walker's own chain, which goes on changing: copied */
|
|
2334
|
+
GAVE_UP.set(read.node, {node: read.node, scope: [...(read.scope || [])], why,
|
|
2335
|
+
past: (node && node !== read.node)? {node, scope: [...(scope || [])]} : null});
|
|
2241
2336
|
}
|
|
2242
2337
|
}
|
|
2243
2338
|
|
|
2244
|
-
/*
|
|
2245
|
-
*
|
|
2339
|
+
/* Run a read, as the READ every give_up() inside it is said at --
|
|
2340
|
+
* when no read is in progress already */
|
|
2341
|
+
function from_read(node, scope, fn)
|
|
2342
|
+
{
|
|
2343
|
+
if(READ_AT.length > 0) {
|
|
2344
|
+
return fn();
|
|
2345
|
+
}
|
|
2346
|
+
READ_AT.push({node, scope});
|
|
2347
|
+
try {
|
|
2348
|
+
return fn();
|
|
2349
|
+
} finally {
|
|
2350
|
+
READ_AT.pop();
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
/* Where the reader gave up so far -- on reads of one parsed file, when
|
|
2355
|
+
* it is given: [{url, line, text, why, past: {url, line, text} | null}] */
|
|
2246
2356
|
function gave_up(ast = null)
|
|
2247
2357
|
{
|
|
2248
|
-
let
|
|
2249
|
-
for(let {node, scope, why} of GAVE_UP.values()) {
|
|
2358
|
+
let where = (node, scope) => {
|
|
2250
2359
|
let program = (scope.length > 0 && typeof scope[0].code === "string")? scope[0] : null;
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
}
|
|
2254
|
-
out.push({
|
|
2360
|
+
return {
|
|
2361
|
+
program,
|
|
2255
2362
|
url: program? (PROGRAM_URL.get(program) || null) : null,
|
|
2256
2363
|
line: program? line_of(program, node.start) : 0,
|
|
2257
|
-
text: program? program.code.slice(node.start, node.end).replace(/\s+/g, " ").slice(0, 80) : ""
|
|
2258
|
-
|
|
2259
|
-
|
|
2364
|
+
text: program? program.code.slice(node.start, node.end).replace(/\s+/g, " ").slice(0, 80) : ""
|
|
2365
|
+
};
|
|
2366
|
+
};
|
|
2367
|
+
let out = [];
|
|
2368
|
+
for(let {node, scope, why, past} of GAVE_UP.values()) {
|
|
2369
|
+
let at = where(node, scope);
|
|
2370
|
+
if(ast && at.program !== ast) {
|
|
2371
|
+
continue;
|
|
2372
|
+
}
|
|
2373
|
+
let beyond = past? where(past.node, past.scope) : null;
|
|
2374
|
+
out.push({url: at.url, line: at.line, text: at.text, why,
|
|
2375
|
+
past: beyond? {url: beyond.url, line: beyond.line, text: beyond.text} : null});
|
|
2260
2376
|
}
|
|
2261
2377
|
return out;
|
|
2262
2378
|
}
|
|
2263
2379
|
|
|
2380
|
+
/***************************************************************
|
|
2381
|
+
* The DEPTH of a read of expand(), and the values kept for reuse.
|
|
2382
|
+
*
|
|
2383
|
+
* A read counts its steps from the place the value is read: a const,
|
|
2384
|
+
* a property, an element, the returns of a function called, each
|
|
2385
|
+
* read ONCE and kept, keep the steps they took beside their values
|
|
2386
|
+
* (`steps`), so a later read of them takes those steps again from
|
|
2387
|
+
* where it stands. The verdict on a read is the same whatever was
|
|
2388
|
+
* read before it: up to gobj-ui 7.26.44 a const kept the values of
|
|
2389
|
+
* its FIRST read, cut at the depth that read had reached, so `t(J16);
|
|
2390
|
+
* t(K10)` failed and `t(K10); t(J16)` passed. A read that goes past
|
|
2391
|
+
* MAX_DEPTH is given up as a whole (TooDeep unwinds it to its
|
|
2392
|
+
* outermost frame), and no value read on the way is kept: each is
|
|
2393
|
+
* kept only when it was read to its end.
|
|
2394
|
+
*
|
|
2395
|
+
* The place it went past is the same whatever was read before, too:
|
|
2396
|
+
* the first node reached at step MAX_DEPTH + 1 -- a kept read hands
|
|
2397
|
+
* on, for each of its steps, the first node it reached there (up to
|
|
2398
|
+
* gobj-ui 7.26.45 the place was the kept read itself, so `past K10`
|
|
2399
|
+
* or `past K2` depended on what had been read first).
|
|
2400
|
+
***************************************************************/
|
|
2401
|
+
const FRAMES = []; // the reads in progress, outermost first: {max, at}
|
|
2402
|
+
|
|
2403
|
+
class TooDeep
|
|
2404
|
+
{
|
|
2405
|
+
constructor(node, scope)
|
|
2406
|
+
{
|
|
2407
|
+
this.node = node;
|
|
2408
|
+
this.scope = scope;
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
/* A step of the read in progress at `depth`: the first one there is
|
|
2413
|
+
* kept in `at[depth]`. Of its scope only the module is kept, which is
|
|
2414
|
+
* all gave_up() reads -- and a walker's own chain goes on changing */
|
|
2415
|
+
function note_step(depth, node, scope)
|
|
2416
|
+
{
|
|
2417
|
+
let frame = FRAMES[FRAMES.length - 1];
|
|
2418
|
+
if(frame && depth > frame.max) {
|
|
2419
|
+
for(let d = frame.max + 1; d <= depth; d++) {
|
|
2420
|
+
frame.at[d] = {node, scope: (scope || []).slice(0, 1)};
|
|
2421
|
+
}
|
|
2422
|
+
frame.max = depth;
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
/* Is a step past MAX_DEPTH? Inside a read it unwinds the read (TooDeep);
|
|
2427
|
+
* outside one, it is given up here and the caller stops: true */
|
|
2428
|
+
function too_deep(depth, node, scope)
|
|
2429
|
+
{
|
|
2430
|
+
note_step(depth, node, scope);
|
|
2431
|
+
if(depth <= MAX_DEPTH) {
|
|
2432
|
+
return false;
|
|
2433
|
+
}
|
|
2434
|
+
if(FRAMES.length > 0) {
|
|
2435
|
+
throw new TooDeep(node, scope);
|
|
2436
|
+
}
|
|
2437
|
+
give_up(node, scope, GIVE_UP_DEEP);
|
|
2438
|
+
return true;
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
/* The OUTERMOST read of expand(): the one a TooDeep unwinds to, given
|
|
2442
|
+
* up there (`fallback()` is what it answers then) */
|
|
2443
|
+
function outermost_read(node, scope, fn, fallback)
|
|
2444
|
+
{
|
|
2445
|
+
return from_read(node, scope, () => {
|
|
2446
|
+
FRAMES.push({max: 0, at: []});
|
|
2447
|
+
try {
|
|
2448
|
+
return fn();
|
|
2449
|
+
} catch(e) {
|
|
2450
|
+
if(!(e instanceof TooDeep)) {
|
|
2451
|
+
throw e;
|
|
2452
|
+
}
|
|
2453
|
+
give_up(e.node, e.scope, GIVE_UP_DEEP);
|
|
2454
|
+
return fallback();
|
|
2455
|
+
} finally {
|
|
2456
|
+
FRAMES.pop();
|
|
2457
|
+
}
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
/* What `compute()` answers for `key` of `cache`, read once and kept
|
|
2462
|
+
* with its steps, read at `depth` by `node` (in `scope`) */
|
|
2463
|
+
function kept_values(cache, key, depth, node, scope, compute, fallback)
|
|
2464
|
+
{
|
|
2465
|
+
if(FRAMES.length === 0) {
|
|
2466
|
+
return outermost_read(node, scope, () => kept_values(cache, key, depth, node, scope, compute, fallback),
|
|
2467
|
+
fallback);
|
|
2468
|
+
}
|
|
2469
|
+
let known = cache.get(key);
|
|
2470
|
+
if(known) {
|
|
2471
|
+
let top = FRAMES[FRAMES.length - 1];
|
|
2472
|
+
for(let i = Math.max(0, top.max - depth); i < known.steps.length; i++) {
|
|
2473
|
+
too_deep(depth + 1 + i, known.steps[i].node, known.steps[i].scope);
|
|
2474
|
+
}
|
|
2475
|
+
return known.values;
|
|
2476
|
+
}
|
|
2477
|
+
let frame = {max: depth, at: []};
|
|
2478
|
+
FRAMES.push(frame);
|
|
2479
|
+
let values;
|
|
2480
|
+
try {
|
|
2481
|
+
values = compute();
|
|
2482
|
+
} finally {
|
|
2483
|
+
FRAMES.pop();
|
|
2484
|
+
}
|
|
2485
|
+
let steps = frame.at.slice(depth + 1, frame.max + 1);
|
|
2486
|
+
for(let i = 0; i < steps.length; i++) {
|
|
2487
|
+
note_step(depth + 1 + i, steps[i].node, steps[i].scope);
|
|
2488
|
+
}
|
|
2489
|
+
cache.set(key, {values, steps});
|
|
2490
|
+
return values;
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2264
2493
|
/***************************************************************
|
|
2265
2494
|
* The values an expression can take, as far as the source writes
|
|
2266
2495
|
* them out. Each is one of
|
|
@@ -2325,10 +2554,15 @@ function gave_up(ast = null)
|
|
|
2325
2554
|
***************************************************************/
|
|
2326
2555
|
function expand(node, ctx, depth = 0)
|
|
2327
2556
|
{
|
|
2557
|
+
let unknown = () => [{kind: "unknown", node, scope: ctx.scope, via: ctx.off? ctx.via : [...ctx.via, node],
|
|
2558
|
+
off: ctx.off}];
|
|
2559
|
+
if(FRAMES.length === 0) {
|
|
2560
|
+
return outermost_read(node, ctx.scope, () => expand(node, ctx, depth), unknown);
|
|
2561
|
+
}
|
|
2328
2562
|
let out = expand_node(node, ctx, depth);
|
|
2329
2563
|
if(out.length > MAX_VALUES) {
|
|
2330
2564
|
give_up(node, ctx.scope, GIVE_UP_MANY);
|
|
2331
|
-
return
|
|
2565
|
+
return unknown();
|
|
2332
2566
|
}
|
|
2333
2567
|
return out;
|
|
2334
2568
|
}
|
|
@@ -2341,8 +2575,7 @@ function expand_node(node, ctx, depth)
|
|
|
2341
2575
|
let via = ctx.off? ctx.via : [...ctx.via, node];
|
|
2342
2576
|
let here = {scope: ctx.scope, via: via, off: ctx.off};
|
|
2343
2577
|
let item = (kind, extra) => Object.assign({kind, node, scope: ctx.scope, via, off: ctx.off}, extra);
|
|
2344
|
-
if(depth
|
|
2345
|
-
give_up(node, ctx.scope, GIVE_UP_DEEP);
|
|
2578
|
+
if(too_deep(depth, node, ctx.scope)) {
|
|
2346
2579
|
return [item("unknown")];
|
|
2347
2580
|
}
|
|
2348
2581
|
|
|
@@ -2374,7 +2607,7 @@ function expand_node(node, ctx, depth)
|
|
|
2374
2607
|
return [item("unknown")];
|
|
2375
2608
|
}
|
|
2376
2609
|
if(b.kind === "const") {
|
|
2377
|
-
return const_values(b, node, via, depth);
|
|
2610
|
+
return const_values(b, node, ctx.scope, via, depth);
|
|
2378
2611
|
}
|
|
2379
2612
|
if(b.kind === "each") {
|
|
2380
2613
|
let out = elements_of(b.of, {scope: b.scope, via: via, off: true}, depth + 1);
|
|
@@ -2396,7 +2629,7 @@ function expand_node(node, ctx, depth)
|
|
|
2396
2629
|
if(b.kind === "import") {
|
|
2397
2630
|
let x = import_target(b);
|
|
2398
2631
|
if(x && x.kind === "const") {
|
|
2399
|
-
return const_values(x, node, via, depth);
|
|
2632
|
+
return const_values(x, node, ctx.scope, via, depth);
|
|
2400
2633
|
}
|
|
2401
2634
|
}
|
|
2402
2635
|
return [item("unknown", {binding: b})];
|
|
@@ -2423,7 +2656,7 @@ function expand_node(node, ctx, depth)
|
|
|
2423
2656
|
&& node.arguments.length === 1 && binding_of("String", ctx.scope) === null) {
|
|
2424
2657
|
return expand(node.arguments[0], here, depth + 1);
|
|
2425
2658
|
}
|
|
2426
|
-
let r = local_call_values(node, ctx, via);
|
|
2659
|
+
let r = local_call_values(node, ctx, via, depth);
|
|
2427
2660
|
if(r && r.items) {
|
|
2428
2661
|
return r.items;
|
|
2429
2662
|
}
|
|
@@ -2446,37 +2679,42 @@ function expand_node(node, ctx, depth)
|
|
|
2446
2679
|
* The values of a const (a binding of binding_of(), or a const
|
|
2447
2680
|
* module_export() found in another module): its value read where it
|
|
2448
2681
|
* is declared, the steps a destructuring reads from it, its default.
|
|
2682
|
+
* `node` reads it, in `scope`, at `depth`.
|
|
2449
2683
|
*
|
|
2450
|
-
* Its value is read ONCE, without repeats, and kept
|
|
2451
|
-
* where it is declared, so what
|
|
2452
|
-
*
|
|
2453
|
-
*
|
|
2454
|
-
* declaration). Up to 7.26.42 a const
|
|
2455
|
-
* so `const O1 = c()? O0 : {...O0,
|
|
2456
|
-
* times as long at every link (eleven
|
|
2457
|
-
* values until a RangeError. A const met
|
|
2458
|
-
* being read leads back to itself: the reader
|
|
2459
|
-
* (give_up()).
|
|
2684
|
+
* Its value is read ONCE, without repeats, and kept with the steps it
|
|
2685
|
+
* took (kept_values()): a const is read where it is declared, so what
|
|
2686
|
+
* it holds is the same wherever it is read -- only `via`, the place it
|
|
2687
|
+
* is read from, differs, and it is the same for every value (the
|
|
2688
|
+
* reader leaves the place for the declaration). Up to 7.26.42 a const
|
|
2689
|
+
* was read again at every read, so `const O1 = c()? O0 : {...O0,
|
|
2690
|
+
* ...O0}`, chained, took three times as long at every link (eleven
|
|
2691
|
+
* links, 906 ms) and grew its values until a RangeError. A const met
|
|
2692
|
+
* again while its value is being read leads back to itself: the reader
|
|
2693
|
+
* gives up on it (give_up()).
|
|
2460
2694
|
***************************************************************/
|
|
2461
|
-
const CONST_VALUES = new WeakMap(); // the init of a const ->
|
|
2695
|
+
const CONST_VALUES = new WeakMap(); // the init of a const -> {values, steps}, `via` left out
|
|
2462
2696
|
const CONST_READING = new Set(); // the inits being read
|
|
2463
2697
|
|
|
2464
|
-
function const_values(b, node, via, depth)
|
|
2698
|
+
function const_values(b, node, scope, via, depth)
|
|
2465
2699
|
{
|
|
2466
2700
|
let ctx = {scope: b.scope, via: via, off: true};
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2701
|
+
let unknown = () => [{kind: "unknown", node: b.init, scope: b.scope, via, off: true}];
|
|
2702
|
+
if(!CONST_VALUES.has(b.init) && CONST_READING.has(b.init)) {
|
|
2703
|
+
give_up(b.init, b.scope, GIVE_UP_CYCLE);
|
|
2704
|
+
return unknown();
|
|
2705
|
+
}
|
|
2706
|
+
let values = kept_values(CONST_VALUES, b.init, depth, node, scope, () => {
|
|
2472
2707
|
CONST_READING.add(b.init);
|
|
2473
2708
|
try {
|
|
2474
|
-
|
|
2709
|
+
return unique_values(expand(b.init, {scope: b.scope, via: [], off: true}, depth + 1));
|
|
2475
2710
|
} finally {
|
|
2476
2711
|
CONST_READING.delete(b.init);
|
|
2477
2712
|
}
|
|
2713
|
+
}, () => null);
|
|
2714
|
+
if(values === null) {
|
|
2715
|
+
return unknown();
|
|
2478
2716
|
}
|
|
2479
|
-
let out =
|
|
2717
|
+
let out = values.map((v) => Object.assign({}, v, {via}));
|
|
2480
2718
|
for(let step of b.steps || []) {
|
|
2481
2719
|
out = out.flatMap((o) => step_values(o, step, node, depth + 1));
|
|
2482
2720
|
}
|
|
@@ -2517,7 +2755,7 @@ function member_values(node, step, ctx, via, item, depth)
|
|
|
2517
2755
|
let ns = import_target(b);
|
|
2518
2756
|
let x = (ns && ns.kind === "namespace")? module_export(ns.url, step.prop) : null;
|
|
2519
2757
|
if(x && x.kind === "const") {
|
|
2520
|
-
return const_values(x, node, via, depth);
|
|
2758
|
+
return const_values(x, node, ctx.scope, via, depth);
|
|
2521
2759
|
}
|
|
2522
2760
|
return [item("unknown")];
|
|
2523
2761
|
}
|
|
@@ -2542,13 +2780,13 @@ const KNOWN = new Set(["key", "nothing", "dom"]);
|
|
|
2542
2780
|
* does not read, an async function, a generator, a
|
|
2543
2781
|
* function being read already (a recursion)
|
|
2544
2782
|
***************************************************************/
|
|
2545
|
-
function local_call_values(call, ctx, via)
|
|
2783
|
+
function local_call_values(call, ctx, via, depth = 0)
|
|
2546
2784
|
{
|
|
2547
2785
|
let c = call_kind(call, ctx.scope);
|
|
2548
2786
|
if(!c || !c.target || c.target.kind !== "fn") {
|
|
2549
2787
|
return null;
|
|
2550
2788
|
}
|
|
2551
|
-
let r = fn_returns(c.target);
|
|
2789
|
+
let r = fn_returns(c.target, call, ctx.scope, depth);
|
|
2552
2790
|
if(!r) {
|
|
2553
2791
|
return null;
|
|
2554
2792
|
}
|
|
@@ -2575,47 +2813,48 @@ function local_call_values(call, ctx, via)
|
|
|
2575
2813
|
* of it, `label_of(n)` calling itself in two branches took more
|
|
2576
2814
|
* than two minutes, and in three it never ended (REV-CLOUD V22).
|
|
2577
2815
|
* A function that is not a plain one (async, a generator) is not
|
|
2578
|
-
* followed.
|
|
2816
|
+
* followed. A call is a step of the read that makes it, and the
|
|
2817
|
+
* returns are read one step further (kept_values(): the steps they
|
|
2818
|
+
* take are kept with them); up to gobj-ui 7.26.44 a call started
|
|
2819
|
+
* the count again, so thirty nested calls were read through.
|
|
2820
|
+
* `call` makes it, in `scope`, at `depth`.
|
|
2579
2821
|
***************************************************************/
|
|
2580
|
-
const FN_RETURNS = new WeakMap();
|
|
2822
|
+
const FN_RETURNS = new WeakMap(); // a function -> {values: {items, complete, keys}, steps}
|
|
2581
2823
|
const FN_READING = new Set();
|
|
2582
2824
|
|
|
2583
|
-
function fn_returns(target)
|
|
2825
|
+
function fn_returns(target, call, scope, depth)
|
|
2584
2826
|
{
|
|
2585
2827
|
let fn = target.fn;
|
|
2586
|
-
if(FN_RETURNS.has(fn)) {
|
|
2587
|
-
return FN_RETURNS.get(fn);
|
|
2588
|
-
}
|
|
2589
|
-
if(FN_READING.has(fn) || fn.async || fn.generator) {
|
|
2828
|
+
if(!FN_RETURNS.has(fn) && (FN_READING.has(fn) || fn.async || fn.generator)) {
|
|
2590
2829
|
return null;
|
|
2591
2830
|
}
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
let
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
let leaves = items.map(classify);
|
|
2603
|
-
let keys = new Set();
|
|
2604
|
-
for(let l of leaves) {
|
|
2605
|
-
if(l.kind === "key") {
|
|
2606
|
-
keys.add(l.value);
|
|
2831
|
+
return kept_values(FN_RETURNS, fn, depth, call, scope, () => {
|
|
2832
|
+
FN_READING.add(fn);
|
|
2833
|
+
let items = [];
|
|
2834
|
+
try {
|
|
2835
|
+
for(let r of returned_values(fn)) {
|
|
2836
|
+
let values = expand(r.node, {scope: [...target.scope, fn, ...r.path], via: [], off: true}, depth + 1);
|
|
2837
|
+
items = unique_values(items.concat(values));
|
|
2838
|
+
}
|
|
2839
|
+
} finally {
|
|
2840
|
+
FN_READING.delete(fn);
|
|
2607
2841
|
}
|
|
2608
|
-
|
|
2609
|
-
|
|
2842
|
+
let leaves = items.map(classify);
|
|
2843
|
+
let keys = new Set();
|
|
2844
|
+
for(let l of leaves) {
|
|
2845
|
+
if(l.kind === "key") {
|
|
2846
|
+
keys.add(l.value);
|
|
2847
|
+
}
|
|
2848
|
+
for(let k of l.partial || []) {
|
|
2849
|
+
keys.add(k);
|
|
2850
|
+
}
|
|
2610
2851
|
}
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
};
|
|
2617
|
-
FN_RETURNS.set(fn, result);
|
|
2618
|
-
return result;
|
|
2852
|
+
return {
|
|
2853
|
+
items: items,
|
|
2854
|
+
complete: leaves.length > 0 && leaves.every((l) => KNOWN.has(l.kind)),
|
|
2855
|
+
keys: [...keys]
|
|
2856
|
+
};
|
|
2857
|
+
}, () => null);
|
|
2619
2858
|
}
|
|
2620
2859
|
|
|
2621
2860
|
/***************************************************************
|
|
@@ -2663,10 +2902,105 @@ function member_step(node)
|
|
|
2663
2902
|
name = node.property.name;
|
|
2664
2903
|
} else if(node.computed && node.property.type === "Literal") {
|
|
2665
2904
|
name = String(node.property.value);
|
|
2905
|
+
} else if(node.computed && static_string(node.property) !== null) {
|
|
2906
|
+
name = static_string(node.property); // x[`a`]
|
|
2666
2907
|
}
|
|
2667
2908
|
return {prop: name, computed: !!node.computed};
|
|
2668
2909
|
}
|
|
2669
2910
|
|
|
2911
|
+
/***************************************************************
|
|
2912
|
+
* The name of the METHOD a member names: member_step()'s, or the one
|
|
2913
|
+
* string a computed name is when the reader follows it to one -- `t[M]`
|
|
2914
|
+
* with `const M = "call"` (an import of one, a chain of them). Up to
|
|
2915
|
+
* gobj-ui 7.26.45 such a `.call` / `.apply` / `.bind` / `.map`, and
|
|
2916
|
+
* `i18next[T]`, were not read. Only for names of methods: a property
|
|
2917
|
+
* read by a computed name reads every property it may be.
|
|
2918
|
+
***************************************************************/
|
|
2919
|
+
function member_name(node, scope)
|
|
2920
|
+
{
|
|
2921
|
+
let name = member_step(node).prop;
|
|
2922
|
+
if(name !== null || !node.computed || !scope
|
|
2923
|
+
|| (node.property.type !== "Identifier" && node.property.type !== "MemberExpression")) {
|
|
2924
|
+
return name;
|
|
2925
|
+
}
|
|
2926
|
+
let {keys, complete} = static_keys(node.property, scope);
|
|
2927
|
+
return (complete && keys.length === 1)? keys[0] : null;
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
/***************************************************************
|
|
2931
|
+
* The arguments of a call as the callee receives them, a SPREAD of an
|
|
2932
|
+
* array the source writes out read as its elements: `t(...["k"])`,
|
|
2933
|
+
* `t(...KEYS)` with `const KEYS = ["k"]`. A spread of anything else
|
|
2934
|
+
* stays where it is: no position from it on is known. Up to gobj-ui
|
|
2935
|
+
* 7.26.45 every spread did.
|
|
2936
|
+
***************************************************************/
|
|
2937
|
+
function written_args(list, scope)
|
|
2938
|
+
{
|
|
2939
|
+
let out = [];
|
|
2940
|
+
for(let i = 0; i < list.length; i++) {
|
|
2941
|
+
let a = list[i];
|
|
2942
|
+
if(a && a.type === "SpreadElement") {
|
|
2943
|
+
let elements = written_elements(a.argument, scope);
|
|
2944
|
+
if(elements === null) {
|
|
2945
|
+
return [...out, ...list.slice(i)];
|
|
2946
|
+
}
|
|
2947
|
+
out.push(...elements);
|
|
2948
|
+
} else {
|
|
2949
|
+
out.push(a);
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
return out;
|
|
2953
|
+
}
|
|
2954
|
+
|
|
2955
|
+
/***************************************************************
|
|
2956
|
+
* The elements of an array the source writes out, or null: an array
|
|
2957
|
+
* literal (its spreads read by written_args(), a hole is an argument
|
|
2958
|
+
* not given), or a const bound to one with no spread and no hole --
|
|
2959
|
+
* its elements read THROUGH it, as `X[0]`, `X[1]`... (element_ref()),
|
|
2960
|
+
* so each is read where the const is declared.
|
|
2961
|
+
***************************************************************/
|
|
2962
|
+
function written_elements(n, scope)
|
|
2963
|
+
{
|
|
2964
|
+
if(!n) {
|
|
2965
|
+
return null;
|
|
2966
|
+
}
|
|
2967
|
+
if(n.type === "ArrayExpression") {
|
|
2968
|
+
return written_args(n.elements, scope);
|
|
2969
|
+
}
|
|
2970
|
+
if(n.type !== "Identifier") {
|
|
2971
|
+
return null;
|
|
2972
|
+
}
|
|
2973
|
+
let b = binding_of(n.name, scope);
|
|
2974
|
+
if(!b || b.kind !== "const" || b.steps.length > 0 || !b.init || b.init.type !== "ArrayExpression"
|
|
2975
|
+
|| b.init.elements.some((e) => e === null || e.type === "SpreadElement")) {
|
|
2976
|
+
return null;
|
|
2977
|
+
}
|
|
2978
|
+
return b.init.elements.map((e, i) => element_ref(n, i));
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2981
|
+
function is_spread(n)
|
|
2982
|
+
{
|
|
2983
|
+
return !!n && n.type === "SpreadElement";
|
|
2984
|
+
}
|
|
2985
|
+
|
|
2986
|
+
/* `X[i]` for the name X, a node of no source (at the place of X), made
|
|
2987
|
+
* once: what is said about it is said once */
|
|
2988
|
+
const ELEMENT_REFS = new WeakMap(); // an Identifier -> [its X[i]]
|
|
2989
|
+
|
|
2990
|
+
function element_ref(n, i)
|
|
2991
|
+
{
|
|
2992
|
+
if(!ELEMENT_REFS.has(n)) {
|
|
2993
|
+
ELEMENT_REFS.set(n, []);
|
|
2994
|
+
}
|
|
2995
|
+
let refs = ELEMENT_REFS.get(n);
|
|
2996
|
+
if(!refs[i]) {
|
|
2997
|
+
refs[i] = {type: "MemberExpression", object: n, computed: true, optional: false,
|
|
2998
|
+
property: {type: "Literal", value: i, raw: String(i), start: n.start, end: n.end},
|
|
2999
|
+
start: n.start, end: n.end};
|
|
3000
|
+
}
|
|
3001
|
+
return refs[i];
|
|
3002
|
+
}
|
|
3003
|
+
|
|
2670
3004
|
/***************************************************************
|
|
2671
3005
|
* The var_root of what is read one step further from something read
|
|
2672
3006
|
* from a `let` / `var` (null when it was not)
|
|
@@ -2756,10 +3090,11 @@ function assigned_properties(o, step, depth)
|
|
|
2756
3090
|
*
|
|
2757
3091
|
* An object reached from a declaration (`o.off`: every value it
|
|
2758
3092
|
* gives carries the same `via`) is read once per property, without
|
|
2759
|
-
* repeats, and kept -- as a const is
|
|
2760
|
-
* same object twice, `{...O, ...O}`,
|
|
3093
|
+
* repeats, and kept with the steps it took -- as a const is
|
|
3094
|
+
* (const_values()): a spread of the same object twice, `{...O, ...O}`,
|
|
3095
|
+
* gives its values once.
|
|
2761
3096
|
***************************************************************/
|
|
2762
|
-
const PROPERTY_VALUES = new WeakMap(); // an object literal -> Map(property ->
|
|
3097
|
+
const PROPERTY_VALUES = new WeakMap(); // an object literal -> Map(property -> {values, steps}, `via` left out)
|
|
2763
3098
|
|
|
2764
3099
|
function property_values(o, name, depth)
|
|
2765
3100
|
{
|
|
@@ -2771,11 +3106,11 @@ function property_values(o, name, depth)
|
|
|
2771
3106
|
known = new Map();
|
|
2772
3107
|
PROPERTY_VALUES.set(o.node, known);
|
|
2773
3108
|
}
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
return
|
|
3109
|
+
let bare = Object.assign({}, o, {via: []});
|
|
3110
|
+
let values = kept_values(known, name, depth, o.node, o.scope,
|
|
3111
|
+
() => capped(bare, unique_values(property_values_of(bare, name, depth))),
|
|
3112
|
+
() => [Object.assign({}, bare, {kind: "unknown", binding: null, var_root: null})]);
|
|
3113
|
+
return values.map((v) => Object.assign({}, v, {via: o.via}));
|
|
2779
3114
|
}
|
|
2780
3115
|
|
|
2781
3116
|
/* The values of a value, or the reader giving up on it when they are
|
|
@@ -2854,10 +3189,11 @@ function elements_of(node, ctx, depth)
|
|
|
2854
3189
|
* element of a rest parameter is another parameter: no position can
|
|
2855
3190
|
* name one, and the reader cannot follow it. The elements of an array
|
|
2856
3191
|
* literal (or of a `.map()` of one) reached from a declaration are
|
|
2857
|
-
* read once, without repeats, and kept
|
|
2858
|
-
* object are (property_values()): `[...A, ...A]`
|
|
3192
|
+
* read once, without repeats, and kept with the steps they took, as
|
|
3193
|
+
* the properties of an object are (property_values()): `[...A, ...A]`
|
|
3194
|
+
* gives A's once.
|
|
2859
3195
|
***************************************************************/
|
|
2860
|
-
const ELEMENT_VALUES = new WeakMap(); // an array literal or a .map() ->
|
|
3196
|
+
const ELEMENT_VALUES = new WeakMap(); // an array literal or a .map() -> {values, steps}, `via` left out
|
|
2861
3197
|
|
|
2862
3198
|
function element_values(v, depth)
|
|
2863
3199
|
{
|
|
@@ -2868,11 +3204,11 @@ function element_values(v, depth)
|
|
|
2868
3204
|
if(!v.off) {
|
|
2869
3205
|
return capped(v, element_values_of(v, depth));
|
|
2870
3206
|
}
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
return
|
|
3207
|
+
let bare = Object.assign({}, v, {via: []});
|
|
3208
|
+
let values = kept_values(ELEMENT_VALUES, v.node, depth, v.node, v.scope,
|
|
3209
|
+
() => capped(bare, unique_values(element_values_of(bare, depth))),
|
|
3210
|
+
() => [Object.assign({}, bare, {kind: "unknown", binding: null, var_root: null})]);
|
|
3211
|
+
return values.map((x) => Object.assign({}, x, {via: v.via}));
|
|
2876
3212
|
}
|
|
2877
3213
|
|
|
2878
3214
|
function element_values_of(v, depth)
|
|
@@ -3159,6 +3495,9 @@ function values_at(call, path, scope = [], args = call.arguments, fallbacks = nu
|
|
|
3159
3495
|
if(!arg) {
|
|
3160
3496
|
return [];
|
|
3161
3497
|
}
|
|
3498
|
+
if(READ_AT.length === 0) {
|
|
3499
|
+
return from_read(arg, call_scope, () => values_at(call, path, scope, args, fallbacks));
|
|
3500
|
+
}
|
|
3162
3501
|
|
|
3163
3502
|
let ctx = {scope: call_scope, via: [call], off: false};
|
|
3164
3503
|
let cur = first[2]? elements_of(arg, ctx, 0) : expand(arg, ctx);
|
|
@@ -3340,8 +3679,7 @@ function assigned_values(binding, members = false)
|
|
|
3340
3679
|
let b = binding_of(id.name, chain);
|
|
3341
3680
|
return !!b && b.kind === "var" && b.declarators[0] === first;
|
|
3342
3681
|
};
|
|
3343
|
-
|
|
3344
|
-
let chain = [...ancestors, n];
|
|
3682
|
+
let visit = (n, chain) => {
|
|
3345
3683
|
let into = (node) => (members? steps_to(node, (id) => is_it(id, chain)) : null);
|
|
3346
3684
|
/* `n` writes `target` with a value the reader does not read */
|
|
3347
3685
|
let opaque_write = (target) => {
|
|
@@ -3455,10 +3793,109 @@ function assigned_values(binding, members = false)
|
|
|
3455
3793
|
default:
|
|
3456
3794
|
break;
|
|
3457
3795
|
}
|
|
3458
|
-
}
|
|
3796
|
+
};
|
|
3797
|
+
let sites = write_sites(root);
|
|
3798
|
+
let named = sites.by_name.get(binding.name) || [];
|
|
3799
|
+
let prefix = binding.scope.slice(0, -1);
|
|
3800
|
+
for(let i = 0, j = 0; i < named.length || j < sites.evals.length;) {
|
|
3801
|
+
let take_named = j >= sites.evals.length || (i < named.length && named[i].order < sites.evals[j].order);
|
|
3802
|
+
let site = take_named? named[i++] : sites.evals[j++];
|
|
3803
|
+
visit(site.n, prefix.concat(site.chain));
|
|
3804
|
+
}
|
|
3459
3805
|
return {values, unknown};
|
|
3460
3806
|
}
|
|
3461
3807
|
|
|
3808
|
+
/***************************************************************
|
|
3809
|
+
* The nodes of a scope that can WRITE a variable, by the name of
|
|
3810
|
+
* the variable a write is rooted at (`k = v`, `k.a = v`, `[k] = v`,
|
|
3811
|
+
* `k++`, `k.push(v)`, `Object.assign(k, v)`, `for(k of v)`, a
|
|
3812
|
+
* declarator of `k`), and every direct `eval()`, which can write
|
|
3813
|
+
* any: the only nodes assigned_values() reads. Found in ONE walk of
|
|
3814
|
+
* the scope, and kept: up to gobj-ui 7.26.44 the scope was walked
|
|
3815
|
+
* again for every variable read in it, so a module of 1600 `let`s
|
|
3816
|
+
* took 4 s, and twice as many four times as long.
|
|
3817
|
+
*
|
|
3818
|
+
* -> {by_name: Map(name -> [site]), evals: [site]}, each list in
|
|
3819
|
+
* the order of the source; site: {n, chain, order}, `chain`
|
|
3820
|
+
* the nodes from the scope to `n`, both included
|
|
3821
|
+
***************************************************************/
|
|
3822
|
+
const WRITE_SITES = new WeakMap(); // a scope -> its write sites
|
|
3823
|
+
|
|
3824
|
+
function write_sites(root)
|
|
3825
|
+
{
|
|
3826
|
+
let known = WRITE_SITES.get(root);
|
|
3827
|
+
if(known) {
|
|
3828
|
+
return known;
|
|
3829
|
+
}
|
|
3830
|
+
let by_name = new Map();
|
|
3831
|
+
let evals = [];
|
|
3832
|
+
let order = 0;
|
|
3833
|
+
let base_name = (target) => {
|
|
3834
|
+
while(target && target.type === "MemberExpression") {
|
|
3835
|
+
target = target.object;
|
|
3836
|
+
}
|
|
3837
|
+
return (target && target.type === "Identifier")? target.name : null;
|
|
3838
|
+
};
|
|
3839
|
+
walk(root, (n, ancestors) => {
|
|
3840
|
+
let names = [];
|
|
3841
|
+
switch(n.type) {
|
|
3842
|
+
case "VariableDeclarator":
|
|
3843
|
+
pattern_names(n.id, names);
|
|
3844
|
+
break;
|
|
3845
|
+
case "AssignmentExpression":
|
|
3846
|
+
if(n.left.type === "Identifier" || n.left.type === "MemberExpression") {
|
|
3847
|
+
names.push(base_name(n.left));
|
|
3848
|
+
} else {
|
|
3849
|
+
names.push(...write_targets(n.left).map(base_name));
|
|
3850
|
+
}
|
|
3851
|
+
break;
|
|
3852
|
+
case "UpdateExpression":
|
|
3853
|
+
names.push(base_name(n.argument));
|
|
3854
|
+
break;
|
|
3855
|
+
case "CallExpression": {
|
|
3856
|
+
if(n.callee.type === "Identifier" && n.callee.name === "eval" && !n.optional) {
|
|
3857
|
+
evals.push({n, chain: [...ancestors, n], order: order++});
|
|
3858
|
+
return;
|
|
3859
|
+
}
|
|
3860
|
+
let c = n.callee;
|
|
3861
|
+
if(c.type === "MemberExpression" && !c.computed && c.property.type === "Identifier"
|
|
3862
|
+
&& ELEMENT_WRITERS.has(c.property.name)) {
|
|
3863
|
+
names.push(base_name(c.object));
|
|
3864
|
+
} else if(is_object_call(n, "assign") && n.arguments.length > 0) {
|
|
3865
|
+
names.push(base_name(n.arguments[0]));
|
|
3866
|
+
}
|
|
3867
|
+
break;
|
|
3868
|
+
}
|
|
3869
|
+
case "ForOfStatement":
|
|
3870
|
+
case "ForInStatement":
|
|
3871
|
+
if(n.left.type === "VariableDeclaration") {
|
|
3872
|
+
for(let d of n.left.declarations) {
|
|
3873
|
+
pattern_names(d.id, names);
|
|
3874
|
+
}
|
|
3875
|
+
} else {
|
|
3876
|
+
names.push(...write_targets(n.left).map(base_name));
|
|
3877
|
+
}
|
|
3878
|
+
break;
|
|
3879
|
+
default:
|
|
3880
|
+
return;
|
|
3881
|
+
}
|
|
3882
|
+
let site = null;
|
|
3883
|
+
for(let name of new Set(names)) {
|
|
3884
|
+
if(name === null) {
|
|
3885
|
+
continue;
|
|
3886
|
+
}
|
|
3887
|
+
site = site || {n, chain: [...ancestors, n], order: order++};
|
|
3888
|
+
if(!by_name.has(name)) {
|
|
3889
|
+
by_name.set(name, []);
|
|
3890
|
+
}
|
|
3891
|
+
by_name.get(name).push(site);
|
|
3892
|
+
}
|
|
3893
|
+
});
|
|
3894
|
+
known = {by_name, evals};
|
|
3895
|
+
WRITE_SITES.set(root, known);
|
|
3896
|
+
return known;
|
|
3897
|
+
}
|
|
3898
|
+
|
|
3462
3899
|
/***************************************************************
|
|
3463
3900
|
* The leaves of what is read from a `let` / `var` -- the variable
|
|
3464
3901
|
* itself, or a member or an element of it (`root`, a var_root of
|
|
@@ -3479,6 +3916,9 @@ function assigned_values(binding, members = false)
|
|
|
3479
3916
|
***************************************************************/
|
|
3480
3917
|
function var_leaves(root, seen = new Set(), depth = 0)
|
|
3481
3918
|
{
|
|
3919
|
+
if(READ_AT.length === 0) {
|
|
3920
|
+
return from_read(root.binding.declarators[0], root.binding.scope, () => var_leaves(root, seen, depth));
|
|
3921
|
+
}
|
|
3482
3922
|
let b = root.binding;
|
|
3483
3923
|
let steps = root.steps;
|
|
3484
3924
|
let out = {leaves: [], complete: true, written: false, unread: [], opaque: [], lets: [b]};
|
|
@@ -3642,6 +4082,9 @@ function literal_values(n, scope, seen, depth = 0)
|
|
|
3642
4082
|
if(!n) {
|
|
3643
4083
|
return null;
|
|
3644
4084
|
}
|
|
4085
|
+
if(READ_AT.length === 0) {
|
|
4086
|
+
return from_read(n, scope, () => literal_values(n, scope, seen, depth));
|
|
4087
|
+
}
|
|
3645
4088
|
if(depth > MAX_DEPTH) {
|
|
3646
4089
|
give_up(n, scope, GIVE_UP_DEEP);
|
|
3647
4090
|
return null;
|
|
@@ -3775,6 +4218,9 @@ function param_flows(node, scope, seen = new Set(), depth = 0)
|
|
|
3775
4218
|
if(!node || typeof node.type !== "string") {
|
|
3776
4219
|
return [];
|
|
3777
4220
|
}
|
|
4221
|
+
if(READ_AT.length === 0) {
|
|
4222
|
+
return from_read(node, scope, () => param_flows(node, scope, seen, depth));
|
|
4223
|
+
}
|
|
3778
4224
|
if(depth > MAX_DEPTH) {
|
|
3779
4225
|
give_up(node, scope, GIVE_UP_DEEP);
|
|
3780
4226
|
return [];
|
|
@@ -4508,17 +4954,38 @@ function list_mutations(ast, lists = [])
|
|
|
4508
4954
|
/*
|
|
4509
4955
|
* The list a node names, as said in a message, or null: its name
|
|
4510
4956
|
* bound at the top of the module, a member of a namespace import,
|
|
4511
|
-
* or an alias of one of those
|
|
4957
|
+
* or an alias of one of those. A chain of aliases is followed past
|
|
4958
|
+
* MAX_DEPTH to its end, and the reader gives up only when a list is
|
|
4959
|
+
* on it: up to gobj-ui 7.26.44 thirty aliases of any array, written
|
|
4960
|
+
* into, failed a module that publishes a list. `far`: where it went
|
|
4961
|
+
* past MAX_DEPTH, where it lost the end (past MAX_FOLLOW, or round
|
|
4962
|
+
* a cycle of lets), and whether it met a list.
|
|
4512
4963
|
*/
|
|
4513
|
-
let list_of = (n, chain,
|
|
4964
|
+
let list_of = (n, chain) => from_read(n, chain, () => {
|
|
4965
|
+
let far = {past: null, lost: null, list: false, seen: new Set()};
|
|
4966
|
+
let r = list_at(n, chain, 0, far);
|
|
4967
|
+
if(far.lost && (far.list || far.lost.why !== GIVE_UP_CYCLE)) {
|
|
4968
|
+
give_up(far.lost.node, far.lost.scope, far.lost.why);
|
|
4969
|
+
return null;
|
|
4970
|
+
}
|
|
4971
|
+
if(far.past && (r !== null || far.list)) {
|
|
4972
|
+
give_up(far.past.node, far.past.scope, GIVE_UP_DEEP);
|
|
4973
|
+
return null;
|
|
4974
|
+
}
|
|
4975
|
+
return r;
|
|
4976
|
+
});
|
|
4977
|
+
let list_at = (n, chain, depth, far) => {
|
|
4514
4978
|
while(n && n.type === "ChainExpression") {
|
|
4515
4979
|
n = n.expression;
|
|
4516
4980
|
}
|
|
4517
4981
|
if(!n) {
|
|
4518
4982
|
return null;
|
|
4519
4983
|
}
|
|
4520
|
-
if(depth > MAX_DEPTH) {
|
|
4521
|
-
|
|
4984
|
+
if(depth > MAX_DEPTH && !far.past) {
|
|
4985
|
+
far.past = {node: n, scope: chain};
|
|
4986
|
+
}
|
|
4987
|
+
if(depth > MAX_FOLLOW) {
|
|
4988
|
+
far.lost = far.lost || {node: n, scope: chain, why: GIVE_UP_DEEP};
|
|
4522
4989
|
return null;
|
|
4523
4990
|
}
|
|
4524
4991
|
if(n.type === "MemberExpression") {
|
|
@@ -4527,7 +4994,11 @@ function list_mutations(ast, lists = [])
|
|
|
4527
4994
|
return null;
|
|
4528
4995
|
}
|
|
4529
4996
|
let b = binding_of(n.object.name, chain);
|
|
4530
|
-
|
|
4997
|
+
if(b && b.kind === "import" && b.imported === "*") {
|
|
4998
|
+
far.list = true;
|
|
4999
|
+
return `${n.object.name}.${step.prop}`;
|
|
5000
|
+
}
|
|
5001
|
+
return null;
|
|
4531
5002
|
}
|
|
4532
5003
|
if(n.type !== "Identifier") {
|
|
4533
5004
|
return null;
|
|
@@ -4537,10 +5008,17 @@ function list_mutations(ast, lists = [])
|
|
|
4537
5008
|
return null;
|
|
4538
5009
|
}
|
|
4539
5010
|
if(names.has(n.name) && b.scope.length === 1) {
|
|
5011
|
+
far.list = true;
|
|
4540
5012
|
return n.name;
|
|
4541
5013
|
}
|
|
4542
5014
|
if(b.kind === "const" && b.steps.length === 0) {
|
|
4543
|
-
|
|
5015
|
+
if(far.seen.has(b.init)) {
|
|
5016
|
+
far.lost = far.lost || {node: b.init, scope: b.scope, why: GIVE_UP_CYCLE};
|
|
5017
|
+
return null;
|
|
5018
|
+
}
|
|
5019
|
+
far.seen.add(b.init);
|
|
5020
|
+
let inner = list_at(b.init, b.scope, depth + 1, far);
|
|
5021
|
+
far.seen.delete(b.init);
|
|
4544
5022
|
return inner? `${inner} (through its alias \`${n.name}\`)` : null;
|
|
4545
5023
|
}
|
|
4546
5024
|
if(b.kind === "var" && b.picks.size === 0) {
|
|
@@ -4548,13 +5026,24 @@ function list_mutations(ast, lists = [])
|
|
|
4548
5026
|
* first value asked first: `let out = []` is no alias, and costs
|
|
4549
5027
|
* no walk of its scope) */
|
|
4550
5028
|
let first = b.declarators[0];
|
|
4551
|
-
|
|
4552
|
-
|
|
5029
|
+
if(far.seen.has(first)) {
|
|
5030
|
+
far.lost = far.lost || {node: first, scope: b.scope, why: GIVE_UP_CYCLE};
|
|
4553
5031
|
return null;
|
|
4554
5032
|
}
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
5033
|
+
far.seen.add(first);
|
|
5034
|
+
let inner = null;
|
|
5035
|
+
try {
|
|
5036
|
+
inner = first.init? list_at(first.init, b.scope, depth + 1, far) : null;
|
|
5037
|
+
if(!inner) {
|
|
5038
|
+
return null;
|
|
5039
|
+
}
|
|
5040
|
+
let {values, unknown} = assigned_values(b);
|
|
5041
|
+
if(unknown.length > 0
|
|
5042
|
+
|| values.some((v) => !v.node || list_at(v.node, v.scope, depth + 1, far) !== inner)) {
|
|
5043
|
+
return null;
|
|
5044
|
+
}
|
|
5045
|
+
} finally {
|
|
5046
|
+
far.seen.delete(first);
|
|
4558
5047
|
}
|
|
4559
5048
|
return `${inner} (through its alias \`${n.name}\`)`;
|
|
4560
5049
|
}
|
|
@@ -4833,6 +5322,9 @@ function may_take_a_callback(n)
|
|
|
4833
5322
|
return false;
|
|
4834
5323
|
}
|
|
4835
5324
|
let m = member_step(c).prop;
|
|
5325
|
+
if(m === null && c.computed) {
|
|
5326
|
+
return true; // a name translator_callback() may follow to one of them
|
|
5327
|
+
}
|
|
4836
5328
|
return ITERATION_METHODS.has(m) || SETTLE_METHODS.has(m) || ARRAY_BUILDERS.has(m) || m === "call" || m === "apply";
|
|
4837
5329
|
}
|
|
4838
5330
|
|
|
@@ -4849,7 +5341,8 @@ function callback_leaves(call, callback, scope)
|
|
|
4849
5341
|
{
|
|
4850
5342
|
let via = [call, callback.arg];
|
|
4851
5343
|
if(callback.how === "elements") {
|
|
4852
|
-
return
|
|
5344
|
+
return from_read(callback.receiver, scope,
|
|
5345
|
+
() => elements_of(callback.receiver, {scope, via, off: false}, 0).map(classify));
|
|
4853
5346
|
}
|
|
4854
5347
|
return [{kind: "unknown", node: call, scope: scope.slice(0, -1), via, off: false}];
|
|
4855
5348
|
}
|
|
@@ -4861,15 +5354,17 @@ function callback_leaves(call, callback, scope)
|
|
|
4861
5354
|
***************************************************************/
|
|
4862
5355
|
function key_list_leaves(node, scope, root)
|
|
4863
5356
|
{
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
5357
|
+
return from_read(node, scope, () => {
|
|
5358
|
+
let out = [];
|
|
5359
|
+
for(let v of expand(node, {scope, via: [root], off: false})) {
|
|
5360
|
+
if(v.kind === "value" && v.node.type === "ArrayExpression") {
|
|
5361
|
+
out.push(...element_values(v, 0).map(classify));
|
|
5362
|
+
} else {
|
|
5363
|
+
out.push(classify(v));
|
|
5364
|
+
}
|
|
4870
5365
|
}
|
|
4871
|
-
|
|
4872
|
-
|
|
5366
|
+
return out;
|
|
5367
|
+
});
|
|
4873
5368
|
}
|
|
4874
5369
|
|
|
4875
5370
|
/***************************************************************
|
|
@@ -5400,7 +5895,14 @@ function collect_used_keys(opts)
|
|
|
5400
5895
|
for(let g of gave_up()) {
|
|
5401
5896
|
let module = lib_module_of(g.url);
|
|
5402
5897
|
let label = module? `gobj-ui/src/${module}` : g.url? relative(process.cwd(), fileURLToPath(g.url)) : "?";
|
|
5403
|
-
|
|
5898
|
+
let past = "";
|
|
5899
|
+
if(g.past) {
|
|
5900
|
+
let past_module = lib_module_of(g.past.url);
|
|
5901
|
+
let past_label = past_module? `gobj-ui/src/${past_module}` :
|
|
5902
|
+
g.past.url? relative(process.cwd(), fileURLToPath(g.past.url)) : "?";
|
|
5903
|
+
past = ` (past \`${g.past.text}\`, ${past_label}:${g.past.line})`;
|
|
5904
|
+
}
|
|
5905
|
+
fail(`${label}:${g.line}: the reader gave up on \`${g.text}\`${past}, and a key behind it would go ` +
|
|
5404
5906
|
`unasked: ${g.why}`);
|
|
5405
5907
|
}
|
|
5406
5908
|
|
|
@@ -5890,7 +6392,8 @@ export {
|
|
|
5890
6392
|
source_files,
|
|
5891
6393
|
lib_imports,
|
|
5892
6394
|
find_plural_groups,
|
|
5893
|
-
violation_count
|
|
6395
|
+
violation_count,
|
|
6396
|
+
Abort
|
|
5894
6397
|
};
|
|
5895
6398
|
|
|
5896
6399
|
/*
|
|
@@ -5907,5 +6410,33 @@ try {
|
|
|
5907
6410
|
is_main = false;
|
|
5908
6411
|
}
|
|
5909
6412
|
if(is_main) {
|
|
5910
|
-
|
|
6413
|
+
try {
|
|
6414
|
+
await main();
|
|
6415
|
+
} catch(e) {
|
|
6416
|
+
if(!(e instanceof Abort)) {
|
|
6417
|
+
throw e;
|
|
6418
|
+
}
|
|
6419
|
+
}
|
|
6420
|
+
exit_when_written();
|
|
6421
|
+
}
|
|
6422
|
+
|
|
6423
|
+
/***************************************************************
|
|
6424
|
+
* End the run with its exitCode once what it wrote has left: a
|
|
6425
|
+
* locale is IMPORTED, and a timer its code leaves running holds the
|
|
6426
|
+
* process for ever, verdict or not (up to gobj-ui 7.26.45, also a run
|
|
6427
|
+
* that failed). process.exit() runs from the callbacks of a last
|
|
6428
|
+
* write to each stream, which come after every write before them, so
|
|
6429
|
+
* a long list on its way to a pipe still reaches it whole.
|
|
6430
|
+
***************************************************************/
|
|
6431
|
+
function exit_when_written()
|
|
6432
|
+
{
|
|
6433
|
+
let pending = 2;
|
|
6434
|
+
let written = () => {
|
|
6435
|
+
pending--;
|
|
6436
|
+
if(pending === 0) {
|
|
6437
|
+
process.exit();
|
|
6438
|
+
}
|
|
6439
|
+
};
|
|
6440
|
+
process.stdout.write("", written);
|
|
6441
|
+
process.stderr.write("", written);
|
|
5911
6442
|
}
|