@yuneta/gobj-ui 7.26.45 → 7.26.47

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.
@@ -61,8 +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])` (`t["call"](x, k)` too, and a computed
65
- * `["bind"]`); an array there is i18next's list of
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
66
69
  * fallback keys, each one a key (`t([k, "fallback"])`). A
67
70
  * `.bind()` that binds a key (`const tk = t.bind(null, k)`)
68
71
  * hands t() that key, read where the bind is written, and
@@ -238,9 +241,12 @@
238
241
  * alias of (a parameter `translate`, a `let` alias,
239
242
  * `i18next.getFixedT()`), or called by what is no name of it --
240
243
  * `(0, t)(k)`, `[t][0](k)`, `Reflect.apply(t, x, [k])`,
241
- * `Function.prototype.call.call(t, x, k)` --; a parameter a closure
242
- * returns (`const inner = () => key; t(inner())`: the search for
243
- * the functions that forward a key does not see it); a translator
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
244
250
  * handed to a function (`{t: t}`, `yui_tabulator_lang(t)`: it
245
251
  * calls it with keys of its own), or to any method but those
246
252
  * above (`keys.reduce(t)`, `keys.sort(t)`, an alias of a method,
@@ -249,10 +255,10 @@
249
255
  * label`: the reader reads the literals of a `let`, not what it
250
256
  * translates), or returned by a function (`{i18n:
251
257
  * label_of(x)}`); a key function reached through a parameter, a
252
- * `let` given more than one value, a computed member
253
- * (`API[name](...)`); a data-i18n* attribute written through an
254
- * alias of `dataset`, by Object.assign() into it, or named by a
255
- * `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
256
262
  * function it is handed to, or by
257
263
  * `Array.prototype.push.call(X_I18N_KEYS, k)`; a module of a
258
264
  * package (gobj-js, i18next); what is written into a const table
@@ -988,20 +994,20 @@ function iteration_call(call, scope)
988
994
  if(c.type !== "MemberExpression") {
989
995
  return null;
990
996
  }
991
- let name = member_step(c).prop;
997
+ let name = member_name(c, scope);
992
998
  if(ITERATION_METHODS.has(name)) {
993
999
  let cb = call.arguments[0];
994
1000
  return (cb && cb.type !== "SpreadElement")? {method: name, receiver: c.object, callback: cb, form: ""} : null;
995
1001
  }
996
1002
  if(name === "call" || name === "apply") {
997
1003
  let inner = unchain(c.object);
998
- let method = (inner.type === "MemberExpression")? member_step(inner).prop : null;
1004
+ let method = (inner.type === "MemberExpression")? member_name(inner, scope) : null;
999
1005
  if(!ITERATION_METHODS.has(method)) {
1000
1006
  return null;
1001
1007
  }
1002
- let receiver = call.arguments[0];
1003
- let rest = call.arguments[1];
1004
- let cb = (name === "call")? rest : ((rest && rest.type === "ArrayExpression")? rest.elements[0] : null);
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);
1005
1011
  if(!receiver || receiver.type === "SpreadElement" || !cb || cb.type === "SpreadElement") {
1006
1012
  return null;
1007
1013
  }
@@ -1697,7 +1703,7 @@ function declared_value(b, url, seen)
1697
1703
  if(b.steps.length === 0 && FUNCTION_RE.test(b.init.type)) {
1698
1704
  return {kind: "fn", fn: b.init, scope: b.scope, name: b.name, url};
1699
1705
  }
1700
- return {kind: "const", init: b.init, steps: b.steps, default: b.default, scope: b.scope, url};
1706
+ return {kind: "const", init: b.init, steps: b.steps, default: b.default, scope: b.scope, url, name: b.name};
1701
1707
  }
1702
1708
  if(b.kind === "import") {
1703
1709
  return import_target(b, seen);
@@ -1872,7 +1878,7 @@ function callee_at(node, scope, depth, far)
1872
1878
  }
1873
1879
 
1874
1880
  case "MemberExpression": {
1875
- let step = member_step(node);
1881
+ let step = {prop: member_name(node, scope), computed: !!node.computed};
1876
1882
  if(step.prop === null) {
1877
1883
  return null;
1878
1884
  }
@@ -1914,17 +1920,19 @@ function callee_at(node, scope, depth, far)
1914
1920
  /* f.bind(x) is f; f.bind(x, a, ...) is f with its first arguments
1915
1921
  * BOUND, so what a call of it is handed comes after them */
1916
1922
  let c = node.callee;
1917
- if(c.type !== "MemberExpression" || member_step(c).prop !== "bind") {
1923
+ if(c.type !== "MemberExpression" || member_name(c, scope) !== "bind") {
1918
1924
  return null;
1919
1925
  }
1920
1926
  let inner = callee_at(c.object, scope, depth + 1, far);
1921
- let taken = node.arguments.slice(1);
1922
- if(!inner || taken.length === 0) {
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)) {
1923
1931
  return inner;
1924
1932
  }
1925
1933
  return Object.assign({}, inner, {
1926
1934
  bound: (inner.bound || 0) + taken.length,
1927
- bound_spread: !!inner.bound_spread || taken.some((a) => a.type === "SpreadElement")
1935
+ bound_spread: !!inner.bound_spread || hidden || taken.some(is_spread)
1928
1936
  });
1929
1937
  }
1930
1938
 
@@ -2005,21 +2013,23 @@ function call_target(call, scope)
2005
2013
  }
2006
2014
  let r = null;
2007
2015
  let callee = call.callee;
2008
- let method = (callee.type === "MemberExpression")? member_step(callee).prop : null;
2016
+ let method = (callee.type === "MemberExpression")? member_name(callee, scope) : null;
2009
2017
  if(method === "call" || method === "apply") {
2010
2018
  let inner = callee_of(callee.object, scope);
2011
2019
  if(inner) {
2012
- let args = call.arguments.slice(1);
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);
2013
2023
  if(method === "apply") {
2014
- let list = call.arguments[1];
2015
- args = !list? [] : (list.type === "ArrayExpression")? list.elements : null;
2024
+ let list = given[1];
2025
+ args = (hidden || is_spread(list))? null : !list? [] : written_elements(list, scope);
2016
2026
  }
2017
2027
  r = {target: inner, args};
2018
2028
  }
2019
2029
  }
2020
2030
  if(!r) {
2021
2031
  let target = callee_of(callee, scope);
2022
- r = target? {target, args: call.arguments} : null;
2032
+ r = target? {target, args: written_args(call.arguments, scope)} : null;
2023
2033
  }
2024
2034
  if(r && r.target.bound) {
2025
2035
  /* Up to 7.26.41 the bound arguments were not counted: what a call of
@@ -2049,14 +2059,19 @@ function call_target(call, scope)
2049
2059
  function bind_kind(call, scope, table = I18N_KEY_FUNCTIONS)
2050
2060
  {
2051
2061
  let c = call.callee;
2052
- if(c.type !== "MemberExpression" || member_step(c).prop !== "bind" || call.arguments.length < 2) {
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) {
2053
2068
  return null;
2054
2069
  }
2055
2070
  let inner = callee_of(c.object, scope);
2056
2071
  if(!inner) {
2057
2072
  return null;
2058
2073
  }
2059
- let args = inner.bound_spread? null : [...new Array(inner.bound || 0).fill(null), ...call.arguments.slice(1)];
2074
+ let args = (inner.bound_spread || hidden)? null : [...new Array(inner.bound || 0).fill(null), ...given.slice(1)];
2060
2075
  if(inner.kind === "t") {
2061
2076
  return {kind: "t", target: inner, args};
2062
2077
  }
@@ -2100,7 +2115,8 @@ function call_kind(call, scope, table = I18N_KEY_FUNCTIONS)
2100
2115
  let fns = module? key_fn_index(table).by_module.get(module) : null;
2101
2116
  let entry = (fns && call.callee.type === "Identifier" && !binding_of(call.callee.name, scope))?
2102
2117
  (fns.get(call.callee.name) || null) : null;
2103
- return entry? {kind: "key", entry, target: {kind: "unbound", name: entry.name}, args: call.arguments} : null;
2118
+ return entry? {kind: "key", entry, target: {kind: "unbound", name: entry.name},
2119
+ args: written_args(call.arguments, scope)} : null;
2104
2120
  }
2105
2121
  let {target, args} = r;
2106
2122
  if(target.kind === "t") {
@@ -2246,7 +2262,7 @@ function translator_callback(call, scope)
2246
2262
  {how: "elements", method: it.method, form: it.form, receiver: it.receiver, arg: it.callback} : null;
2247
2263
  }
2248
2264
  let c = (call.callee.type === "ChainExpression")? call.callee.expression : call.callee;
2249
- let method = (c.type === "MemberExpression")? member_step(c).prop : null;
2265
+ let method = (c.type === "MemberExpression")? member_name(c, scope) : null;
2250
2266
  if(SETTLE_METHODS.has(method)) {
2251
2267
  let arg = call.arguments.find(is_translator);
2252
2268
  return arg? {how: "settled", method, arg} : null;
@@ -2367,16 +2383,22 @@ function gave_up(ast = null)
2367
2383
  * A read counts its steps from the place the value is read: a const,
2368
2384
  * a property, an element, the returns of a function called, each
2369
2385
  * read ONCE and kept, keep the steps they took beside their values
2370
- * (`height`), so a later read of them adds those steps to its own.
2371
- * The verdict on a read is the same whatever was read before it: up
2372
- * to gobj-ui 7.26.44 a const kept the values of its FIRST read, cut
2373
- * at the depth that read had reached, so `t(J16); t(K10)` failed and
2374
- * `t(K10); t(J16)` passed. A read that goes past MAX_DEPTH is given
2375
- * up as a whole (TooDeep unwinds it to its outermost frame), and no
2376
- * value read on the way is kept: each is kept only when it was read
2377
- * to its end.
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).
2378
2400
  ***************************************************************/
2379
- const FRAMES = []; // the reads in progress, outermost first: {max: the deepest step reached}
2401
+ const FRAMES = []; // the reads in progress, outermost first: {max, at}
2380
2402
 
2381
2403
  class TooDeep
2382
2404
  {
@@ -2387,10 +2409,17 @@ class TooDeep
2387
2409
  }
2388
2410
  }
2389
2411
 
2390
- function note_depth(depth)
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)
2391
2416
  {
2392
- if(FRAMES.length > 0 && depth > FRAMES[FRAMES.length - 1].max) {
2393
- FRAMES[FRAMES.length - 1].max = depth;
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;
2394
2423
  }
2395
2424
  }
2396
2425
 
@@ -2398,7 +2427,7 @@ function note_depth(depth)
2398
2427
  * outside one, it is given up here and the caller stops: true */
2399
2428
  function too_deep(depth, node, scope)
2400
2429
  {
2401
- note_depth(depth);
2430
+ note_step(depth, node, scope);
2402
2431
  if(depth <= MAX_DEPTH) {
2403
2432
  return false;
2404
2433
  }
@@ -2414,7 +2443,7 @@ function too_deep(depth, node, scope)
2414
2443
  function outermost_read(node, scope, fn, fallback)
2415
2444
  {
2416
2445
  return from_read(node, scope, () => {
2417
- FRAMES.push({max: 0});
2446
+ FRAMES.push({max: 0, at: []});
2418
2447
  try {
2419
2448
  return fn();
2420
2449
  } catch(e) {
@@ -2430,19 +2459,22 @@ function outermost_read(node, scope, fn, fallback)
2430
2459
  }
2431
2460
 
2432
2461
  /* What `compute()` answers for `key` of `cache`, read once and kept
2433
- * with its height, read at `depth` by `node` (in `scope`) */
2462
+ * with its steps, read at `depth` by `node` (in `scope`) */
2434
2463
  function kept_values(cache, key, depth, node, scope, compute, fallback)
2435
2464
  {
2436
- let known = cache.get(key);
2437
- if(known) {
2438
- too_deep(depth + known.height, node, scope);
2439
- return known.values;
2440
- }
2441
2465
  if(FRAMES.length === 0) {
2442
2466
  return outermost_read(node, scope, () => kept_values(cache, key, depth, node, scope, compute, fallback),
2443
2467
  fallback);
2444
2468
  }
2445
- let frame = {max: depth};
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: []};
2446
2478
  FRAMES.push(frame);
2447
2479
  let values;
2448
2480
  try {
@@ -2450,8 +2482,11 @@ function kept_values(cache, key, depth, node, scope, compute, fallback)
2450
2482
  } finally {
2451
2483
  FRAMES.pop();
2452
2484
  }
2453
- note_depth(frame.max);
2454
- cache.set(key, {values, height: frame.max - depth});
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});
2455
2490
  return values;
2456
2491
  }
2457
2492
 
@@ -2657,11 +2692,12 @@ function expand_node(node, ctx, depth)
2657
2692
  * again while its value is being read leads back to itself: the reader
2658
2693
  * gives up on it (give_up()).
2659
2694
  ***************************************************************/
2660
- const CONST_VALUES = new WeakMap(); // the init of a const -> {values, height}, `via` left out
2695
+ const CONST_VALUES = new WeakMap(); // the init of a const -> {values, steps}, `via` left out
2661
2696
  const CONST_READING = new Set(); // the inits being read
2662
2697
 
2663
2698
  function const_values(b, node, scope, via, depth)
2664
2699
  {
2700
+ note_const_array(b);
2665
2701
  let ctx = {scope: b.scope, via: via, off: true};
2666
2702
  let unknown = () => [{kind: "unknown", node: b.init, scope: b.scope, via, off: true}];
2667
2703
  if(!CONST_VALUES.has(b.init) && CONST_READING.has(b.init)) {
@@ -2784,7 +2820,7 @@ function local_call_values(call, ctx, via, depth = 0)
2784
2820
  * the count again, so thirty nested calls were read through.
2785
2821
  * `call` makes it, in `scope`, at `depth`.
2786
2822
  ***************************************************************/
2787
- const FN_RETURNS = new WeakMap(); // a function -> {values: {items, complete, keys}, height}
2823
+ const FN_RETURNS = new WeakMap(); // a function -> {values: {items, complete, keys}, steps}
2788
2824
  const FN_READING = new Set();
2789
2825
 
2790
2826
  function fn_returns(target, call, scope, depth)
@@ -2867,10 +2903,219 @@ function member_step(node)
2867
2903
  name = node.property.name;
2868
2904
  } else if(node.computed && node.property.type === "Literal") {
2869
2905
  name = String(node.property.value);
2906
+ } else if(node.computed && static_string(node.property) !== null) {
2907
+ name = static_string(node.property); // x[`a`]
2870
2908
  }
2871
2909
  return {prop: name, computed: !!node.computed};
2872
2910
  }
2873
2911
 
2912
+ /***************************************************************
2913
+ * The name of the METHOD a member names: member_step()'s, or the one
2914
+ * string a computed name is when the reader follows it to one -- `t[M]`
2915
+ * with `const M = "call"` (an import of one, a chain of them). Up to
2916
+ * gobj-ui 7.26.45 such a `.call` / `.apply` / `.bind` / `.map`, and
2917
+ * `i18next[T]`, were not read. Only for names of methods: a property
2918
+ * read by a computed name reads every property it may be.
2919
+ ***************************************************************/
2920
+ function member_name(node, scope)
2921
+ {
2922
+ let name = member_step(node).prop;
2923
+ if(name !== null || !node.computed || !scope
2924
+ || (node.property.type !== "Identifier" && node.property.type !== "MemberExpression")) {
2925
+ return name;
2926
+ }
2927
+ let {keys, complete} = static_keys(node.property, scope);
2928
+ return (complete && keys.length === 1)? keys[0] : null;
2929
+ }
2930
+
2931
+ /***************************************************************
2932
+ * The arguments of a call as the callee receives them, a SPREAD of an
2933
+ * array the source writes out read as its elements: `t(...["k"])`,
2934
+ * `t(...KEYS)` with `const KEYS = ["k"]`. A spread of anything else
2935
+ * stays where it is: no position from it on is known. Up to gobj-ui
2936
+ * 7.26.45 every spread did.
2937
+ ***************************************************************/
2938
+ function written_args(list, scope)
2939
+ {
2940
+ let out = [];
2941
+ for(let i = 0; i < list.length; i++) {
2942
+ let a = list[i];
2943
+ if(a && a.type === "SpreadElement") {
2944
+ let elements = written_elements(a.argument, scope);
2945
+ if(elements === null) {
2946
+ return [...out, ...list.slice(i)];
2947
+ }
2948
+ out.push(...elements);
2949
+ } else {
2950
+ out.push(a);
2951
+ }
2952
+ }
2953
+ return out;
2954
+ }
2955
+
2956
+ /***************************************************************
2957
+ * The elements of an array the source writes out, or null: an array
2958
+ * literal (its spreads read by written_args(), a hole is an argument
2959
+ * not given), or a const bound to one with no spread and no hole --
2960
+ * its elements read THROUGH it, as `X[0]`, `X[1]`... (element_ref()),
2961
+ * so each is read where the const is declared.
2962
+ ***************************************************************/
2963
+ function written_elements(n, scope)
2964
+ {
2965
+ if(!n) {
2966
+ return null;
2967
+ }
2968
+ if(n.type === "ArrayExpression") {
2969
+ return written_args(n.elements, scope);
2970
+ }
2971
+ if(n.type !== "Identifier") {
2972
+ return null;
2973
+ }
2974
+ let array = const_array(n, scope);
2975
+ if(!array || array.elements.some((e) => e === null || e.type === "SpreadElement")) {
2976
+ return null;
2977
+ }
2978
+ return array.elements.map((e, i) => element_ref(n, i));
2979
+ }
2980
+
2981
+ /***************************************************************
2982
+ * The array literal a name is a const of, or null: its own value
2983
+ * (`Object.freeze()`d too), an import of one, or a const ALIAS of
2984
+ * one (`const B = A`), followed to its end. Up to gobj-ui 7.26.46 an
2985
+ * alias or an import was a spread of what the source does not write.
2986
+ ***************************************************************/
2987
+ function const_array(n, scope)
2988
+ {
2989
+ let seen = new Set();
2990
+ for(;;) {
2991
+ let b = binding_of(n.name, scope);
2992
+ if(b && b.kind === "import") {
2993
+ b = import_target(b);
2994
+ }
2995
+ if(!b || b.kind !== "const" || (b.steps || []).length > 0 || b.default || !b.init || seen.has(b.init)) {
2996
+ return null;
2997
+ }
2998
+ seen.add(b.init);
2999
+ let init = b.init;
3000
+ if(is_object_call(init, "freeze") && init.arguments.length === 1) {
3001
+ init = init.arguments[0];
3002
+ }
3003
+ if(init.type === "ArrayExpression") {
3004
+ return init;
3005
+ }
3006
+ if(init.type !== "Identifier") {
3007
+ return null;
3008
+ }
3009
+ n = init;
3010
+ scope = b.scope;
3011
+ }
3012
+ }
3013
+
3014
+ /***************************************************************
3015
+ * The array literals an element is read from by its index
3016
+ * (step_values()): the value of a const that its scope does not
3017
+ * write INTO -- `X[i] = k`, `X.length = n`, `X[i]++`, `delete X[i]`,
3018
+ * `X.push()` and every method that moves its elements (`reverse()`,
3019
+ * `sort()`, `shift()`, ...), `Object.assign(X, ...)`. Any other
3020
+ * array -- one written into, where an element read by its index may
3021
+ * be another one by then (`X.reverse(); t(X[0])`), the value of a
3022
+ * `let`, an `export default` -- is read by every element written out,
3023
+ * at any index. What is written into it is not read (the invisible
3024
+ * list of the README), nor a write through an alias of it, from a
3025
+ * module that imports it, or by a function it is handed to.
3026
+ ***************************************************************/
3027
+ const INDEXED_ARRAYS = new WeakSet(); // the array literals of consts not written into
3028
+ const ARRAY_WRITERS = new Set(["push", "unshift", "splice", "fill", "copyWithin", "reverse", "sort", "shift",
3029
+ "pop"]);
3030
+ const NOTED_ARRAYS = new WeakSet(); // the inits of consts already asked
3031
+
3032
+ function note_const_array(b)
3033
+ {
3034
+ let init = b.init;
3035
+ if(!init || init.type !== "ArrayExpression" || NOTED_ARRAYS.has(init) || !b.name || !b.scope) {
3036
+ return;
3037
+ }
3038
+ NOTED_ARRAYS.add(init);
3039
+ let root = b.scope[b.scope.length - 1];
3040
+ for(let chain of (in_place_writes(root).get(b.name) || [])) {
3041
+ let w = binding_of(b.name, chain);
3042
+ if(w && w.kind === "const" && w.init === init) {
3043
+ return;
3044
+ }
3045
+ }
3046
+ INDEXED_ARRAYS.add(init);
3047
+ }
3048
+
3049
+ /* The places a scope writes INTO what a name holds: name -> [the
3050
+ * chain from the scope to the name written], found in one walk */
3051
+ const IN_PLACE_WRITES = new WeakMap(); // a scope -> Map(name -> [chain])
3052
+
3053
+ function in_place_writes(root)
3054
+ {
3055
+ let known = IN_PLACE_WRITES.get(root);
3056
+ if(known) {
3057
+ return known;
3058
+ }
3059
+ known = new Map();
3060
+ let add = (target, ancestors) => {
3061
+ let chain = [...ancestors];
3062
+ while(target && target.type === "MemberExpression") {
3063
+ target = target.object;
3064
+ }
3065
+ if(target && target.type === "Identifier") {
3066
+ if(!known.has(target.name)) {
3067
+ known.set(target.name, []);
3068
+ }
3069
+ known.get(target.name).push(chain);
3070
+ }
3071
+ };
3072
+ walk(root, (n, ancestors) => {
3073
+ if(n.type === "AssignmentExpression") {
3074
+ for(let t of write_targets(n.left)) {
3075
+ if(t.type === "MemberExpression") {
3076
+ add(t, [...ancestors, n]);
3077
+ }
3078
+ }
3079
+ } else if((n.type === "UpdateExpression" && n.argument.type === "MemberExpression")
3080
+ || (n.type === "UnaryExpression" && n.operator === "delete" && n.argument.type === "MemberExpression")) {
3081
+ add(n.argument, [...ancestors, n]);
3082
+ } else if(n.type === "CallExpression") {
3083
+ let c = n.callee;
3084
+ if(c.type === "MemberExpression" && ARRAY_WRITERS.has(member_step(c).prop)) {
3085
+ add(c.object, [...ancestors, n]);
3086
+ } else if((is_object_call(n, "assign") || is_object_call(n, "defineProperty")
3087
+ || is_object_call(n, "defineProperties")) && n.arguments.length > 0) {
3088
+ add(n.arguments[0], [...ancestors, n]);
3089
+ }
3090
+ }
3091
+ });
3092
+ IN_PLACE_WRITES.set(root, known);
3093
+ return known;
3094
+ }
3095
+
3096
+ function is_spread(n)
3097
+ {
3098
+ return !!n && n.type === "SpreadElement";
3099
+ }
3100
+
3101
+ /* `X[i]` for the name X, a node of no source (at the place of X), made
3102
+ * once: what is said about it is said once */
3103
+ const ELEMENT_REFS = new WeakMap(); // an Identifier -> [its X[i]]
3104
+
3105
+ function element_ref(n, i)
3106
+ {
3107
+ if(!ELEMENT_REFS.has(n)) {
3108
+ ELEMENT_REFS.set(n, []);
3109
+ }
3110
+ let refs = ELEMENT_REFS.get(n);
3111
+ if(!refs[i]) {
3112
+ refs[i] = {type: "MemberExpression", object: n, computed: true, optional: false,
3113
+ property: {type: "Literal", value: i, raw: String(i), start: n.start, end: n.end},
3114
+ start: n.start, end: n.end};
3115
+ }
3116
+ return refs[i];
3117
+ }
3118
+
2874
3119
  /***************************************************************
2875
3120
  * The var_root of what is read one step further from something read
2876
3121
  * from a `let` / `var` (null when it was not)
@@ -2911,6 +3156,11 @@ function step_values(o, step, node, depth)
2911
3156
  return assigned_properties(o, step, depth + 1);
2912
3157
  }
2913
3158
  if(o.kind === "value" && o.node.type === "ArrayExpression" && step.computed) {
3159
+ let i = array_index(step);
3160
+ if(i !== null && INDEXED_ARRAYS.has(o.node)
3161
+ && !o.node.elements.slice(0, i + 1).some((e) => e && e.type === "SpreadElement")) {
3162
+ return indexed_values(o, i, at, depth + 1);
3163
+ }
2914
3164
  return element_values(o, depth + 1);
2915
3165
  }
2916
3166
  if(o.kind === "nothing" || (o.kind === "value" && o.node.type === "Literal")) {
@@ -2964,7 +3214,7 @@ function assigned_properties(o, step, depth)
2964
3214
  * (const_values()): a spread of the same object twice, `{...O, ...O}`,
2965
3215
  * gives its values once.
2966
3216
  ***************************************************************/
2967
- const PROPERTY_VALUES = new WeakMap(); // an object literal -> Map(property -> {values, height}, `via` left out)
3217
+ const PROPERTY_VALUES = new WeakMap(); // an object literal -> Map(property -> {values, steps}, `via` left out)
2968
3218
 
2969
3219
  function property_values(o, name, depth)
2970
3220
  {
@@ -3039,6 +3289,52 @@ function property_values_of(o, name, depth)
3039
3289
  return out;
3040
3290
  }
3041
3291
 
3292
+ /***************************************************************
3293
+ * The index a step reads, when it is one written out (`X[1]`,
3294
+ * `X["1"]`, ``X[`1`]``), or null
3295
+ ***************************************************************/
3296
+ function array_index(step)
3297
+ {
3298
+ return (step.prop !== null && /^(0|[1-9][0-9]{0,8})$/.test(step.prop))? Number(step.prop) : null;
3299
+ }
3300
+
3301
+ /***************************************************************
3302
+ * The element `i` of an array literal with no spread up to it: that
3303
+ * element followed with expand() -- a hole, or past the end, is
3304
+ * nothing. Up to gobj-ui 7.26.46 `X[1]` read every element of X, and
3305
+ * so did the spread of a const array (written_args()):
3306
+ * `t.apply(null, ["k", "a default value"])` asked for the default
3307
+ * value, and `f.apply(x, [shell, "k"])` gave `shell` to the key
3308
+ * position of a key function. Kept per element, as a property is
3309
+ * (property_values()).
3310
+ ***************************************************************/
3311
+ const INDEXED_VALUES = new WeakMap(); // an array literal -> Map(index -> {values, steps}), `via` left out
3312
+
3313
+ function indexed_values(o, i, at, depth)
3314
+ {
3315
+ if(i >= o.node.elements.length || o.node.elements[i] === null) {
3316
+ return [Object.assign({}, o, {kind: "nothing", node: at})];
3317
+ }
3318
+ if(!o.off) {
3319
+ return capped(o, indexed_values_of(o, i, depth));
3320
+ }
3321
+ let known = INDEXED_VALUES.get(o.node);
3322
+ if(!known) {
3323
+ known = new Map();
3324
+ INDEXED_VALUES.set(o.node, known);
3325
+ }
3326
+ let bare = Object.assign({}, o, {via: []});
3327
+ let values = kept_values(known, i, depth, o.node, o.scope,
3328
+ () => capped(bare, unique_values(indexed_values_of(bare, i, depth))),
3329
+ () => [Object.assign({}, bare, {kind: "unknown", binding: null, var_root: null})]);
3330
+ return values.map((v) => Object.assign({}, v, {via: o.via}));
3331
+ }
3332
+
3333
+ function indexed_values_of(o, i, depth)
3334
+ {
3335
+ return expand(o.node.elements[i], {scope: [...o.scope, o.node], via: o.via, off: o.off}, depth + 1);
3336
+ }
3337
+
3042
3338
  /***************************************************************
3043
3339
  * The elements of whatever `node` is, when it is an array literal
3044
3340
  * (after expand()): each element followed with expand(). A `.map()`
@@ -3063,7 +3359,7 @@ function elements_of(node, ctx, depth)
3063
3359
  * the properties of an object are (property_values()): `[...A, ...A]`
3064
3360
  * gives A's once.
3065
3361
  ***************************************************************/
3066
- const ELEMENT_VALUES = new WeakMap(); // an array literal or a .map() -> {values, height}, `via` left out
3362
+ const ELEMENT_VALUES = new WeakMap(); // an array literal or a .map() -> {values, steps}, `via` left out
3067
3363
 
3068
3364
  function element_values(v, depth)
3069
3365
  {
@@ -5192,6 +5488,9 @@ function may_take_a_callback(n)
5192
5488
  return false;
5193
5489
  }
5194
5490
  let m = member_step(c).prop;
5491
+ if(m === null && c.computed) {
5492
+ return true; // a name translator_callback() may follow to one of them
5493
+ }
5195
5494
  return ITERATION_METHODS.has(m) || SETTLE_METHODS.has(m) || ARRAY_BUILDERS.has(m) || m === "call" || m === "apply";
5196
5495
  }
5197
5496
 
@@ -6277,6 +6576,11 @@ try {
6277
6576
  is_main = false;
6278
6577
  }
6279
6578
  if(is_main) {
6579
+ process.on("unhandledRejection", (reason) => {
6580
+ console.error("validate-locales: a promise was rejected and nothing handled it (a locale is " +
6581
+ `imported, so its code runs): ${(reason && reason.stack) || reason}`);
6582
+ process.exitCode = 1;
6583
+ });
6280
6584
  try {
6281
6585
  await main();
6282
6586
  } catch(e) {
@@ -6284,4 +6588,32 @@ if(is_main) {
6284
6588
  throw e;
6285
6589
  }
6286
6590
  }
6591
+ exit_when_written();
6592
+ }
6593
+
6594
+ /***************************************************************
6595
+ * End the run with its exitCode once what it wrote has left: a
6596
+ * locale is IMPORTED, and a timer its code leaves running holds the
6597
+ * process for ever, verdict or not (up to gobj-ui 7.26.45, also a run
6598
+ * that failed). process.exit() runs from the callbacks of a last
6599
+ * write to each stream, which come after every write before them, so
6600
+ * a long list on its way to a pipe still reaches it whole. It waits
6601
+ * for a timer first: a promise rejected with nothing to handle it is
6602
+ * told only when the loop turns, and a timer of 0 a locale set is due
6603
+ * before it -- up to gobj-ui 7.26.46 such a rejection was lost, and
6604
+ * the run passed.
6605
+ ***************************************************************/
6606
+ function exit_when_written()
6607
+ {
6608
+ let pending = 2;
6609
+ let written = () => {
6610
+ pending--;
6611
+ if(pending === 0) {
6612
+ process.exit();
6613
+ }
6614
+ };
6615
+ setTimeout(() => {
6616
+ process.stdout.write("", written);
6617
+ process.stderr.write("", written);
6618
+ }, 0);
6287
6619
  }