@yuneta/gobj-ui 7.26.41 → 7.26.43
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 +510 -78
- package/dist/gobj-ui.cjs.js +1120 -326
- package/dist/gobj-ui.es.js +1120 -326
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +971 -177
- package/src/c_g6_nodes_tree.js +3 -2
- package/src/c_yui_form.js +261 -154
- package/src/c_yui_fsm_graph.js +3 -2
- package/src/c_yui_gobj_tree_js.js +3 -2
- package/src/c_yui_json_graph.js +3 -2
- package/src/c_yui_nav.js +43 -28
- package/src/c_yui_node.js +51 -7
- package/src/c_yui_schema_editor.css +16 -0
- package/src/c_yui_schema_editor.js +110 -20
- package/src/c_yui_shell.css +4 -1
- package/src/c_yui_shell.js +227 -61
- package/src/c_yui_treedb_schema.js +3 -2
- package/src/c_yui_window.js +373 -62
- package/src/c_yui_window_manager.js +80 -8
- package/src/escape_taken.js +58 -0
- package/src/form_close_asks_for_edits.wiring.test.js +6 -3
- package/src/form_json_editor_names.js +3 -1
- package/src/form_json_editor_names.wiring.test.js +8 -4
- package/src/form_json_expand.wiring.test.js +6 -3
- package/src/form_json_field.wiring.test.js +8 -4
- package/src/form_label_i18n.wiring.test.js +10 -5
- package/src/form_table_edits_ask.wiring.test.js +18 -8
- package/src/form_table_rearm.wiring.test.js +13 -5
- package/src/form_table_rows.wiring.test.js +489 -0
- package/src/form_table_validator.wiring.test.js +8 -4
- package/src/form_template_field.wiring.test.js +6 -3
- package/src/g6_canvas_tab_order.css +29 -0
- package/src/g6_canvas_tab_order.js +41 -9
- package/src/g6_canvas_tab_order.wiring.test.js +107 -1
- package/src/g6_long_press_clock.test.js +8 -3
- package/src/i18n_key_functions.js +81 -27
- package/src/i18n_key_functions.test.js +402 -4
- package/src/modal_guard_back.wiring.test.js +188 -0
- package/src/named_controls.wiring.test.js +323 -19
- package/src/nav_cards_helpers.js +9 -4
- package/src/nav_item_badge.wiring.test.js +163 -15
- package/src/node_nav_events.wiring.test.js +93 -1
- package/src/route_map_model.js +59 -10
- package/src/route_map_model.test.js +90 -0
- package/src/schema_editor_diagram_click.wiring.test.js +277 -0
- package/src/schema_editor_openers.wiring.test.js +283 -0
- package/src/shell_dialog_names.wiring.test.js +149 -0
- package/src/shell_escape_taken.wiring.test.js +142 -0
- package/src/shell_focus_trap.js +30 -2
- package/src/shell_focus_trap.test.js +90 -6
- package/src/shell_modals.js +113 -22
- package/src/shell_route_map.js +15 -3
- package/src/shell_section_index.js +3 -1
- package/src/table_editor_name.wiring.test.js +10 -5
- package/src/treedb_column_title.wiring.test.js +8 -4
- package/src/treedb_graph_writes.wiring.test.js +6 -3
- package/src/treedb_json_drill.wiring.test.js +6 -3
- package/src/uplot_add_serie.test.js +6 -3
- package/src/uplot_ink.test.js +8 -4
- package/src/window_dialog.wiring.test.js +486 -0
- package/src/window_dock_band.wiring.test.js +189 -0
- package/src/window_layer.wiring.test.js +114 -0
- package/src/window_rect_rounding.wiring.test.js +121 -0
- package/src/yui_gclass_view.js +16 -1
- package/src/yui_tabulator_i18n.js +31 -1
- package/src/yui_tabulator_i18n.test.js +46 -0
|
@@ -62,26 +62,42 @@
|
|
|
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
64
|
* `t.apply(x, [k])`; an array there is i18next's list of
|
|
65
|
-
* fallback keys, each one a key (`t([k, "fallback"])`)
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
65
|
+
* fallback keys, each one a key (`t([k, "fallback"])`). A
|
|
66
|
+
* `.bind()` that binds a key (`const tk = t.bind(null, k)`)
|
|
67
|
+
* hands t() that key, read where the bind is written, and
|
|
68
|
+
* makes a translator whose calls hand i18next its options or
|
|
69
|
+
* its default value, not a key: what they hand is not read;
|
|
70
|
+
* - each element a translator handed as a CALLBACK walks, and
|
|
71
|
+
* only these: `.map`, `.flatMap`, `.forEach`, `.filter`,
|
|
72
|
+
* `.find`, `.findIndex`, `.findLast`, `.findLastIndex`,
|
|
73
|
+
* `.some`, `.every` -- called on the array (`keys.map(t)`,
|
|
74
|
+
* `keys["map"](t)`), or by `.call(keys, t)` / `.apply(keys,
|
|
75
|
+
* [t])` of the method (`Array.prototype.map.call(keys, t)`,
|
|
76
|
+
* `[].forEach.call(keys, t)`) --, `Array.from(keys, t)` and
|
|
77
|
+
* `Array.fromAsync(keys, t)`; and what `.then(t)` /
|
|
69
78
|
* `.catch(t)` settle with, which no source writes;
|
|
70
|
-
* - the string given to an `i18n`
|
|
79
|
+
* - the string given to an `i18n` property, to a
|
|
71
80
|
* `data-i18n*` attribute (as a property, also computed by a
|
|
72
81
|
* const, `{[ATTR]: k}`; as a member written, `x.i18n = k`,
|
|
73
82
|
* `x["data-i18n-title"] = k`, `x[ATTR] = k`,
|
|
74
83
|
* `el.dataset.i18nTitle = k`; by setAttribute() or
|
|
75
84
|
* setAttributeNS(), the name a literal or a const; or written
|
|
76
|
-
* in markup), and the
|
|
77
|
-
* (
|
|
85
|
+
* in markup), and to a `code` property in the modules of the
|
|
86
|
+
* library whose codes are keys (CODE_KEY_MODULES: the
|
|
87
|
+
* findings and conflicts of the schema checks, which the
|
|
88
|
+
* schema editor hands to t()); in an app a `code` is no key
|
|
89
|
+
* unless its package.json names it (`attr_keys`);
|
|
78
90
|
* - the strings given to a gobj-ui function that RECEIVES a key
|
|
79
91
|
* as an argument (`yui_shell_show_error(shell, "<key>")`,
|
|
80
92
|
* `icon_button(..., "<key>")`), at the positions its table
|
|
81
93
|
* names: I18N_KEY_FUNCTIONS, src/i18n_key_functions.js --
|
|
82
94
|
* however the call reaches it: its name, an import under any
|
|
83
95
|
* name, a re-export, a const alias, a map
|
|
84
|
-
* (`API.info(...)`), `.call()`, `.apply()
|
|
96
|
+
* (`API.info(...)`), `.call()`, `.apply()`, and a `.bind()`
|
|
97
|
+
* (`f.bind(x, shell, k)`), read at the positions it binds. A
|
|
98
|
+
* position that is only the fallback of others (`fallbacks`:
|
|
99
|
+
* a card's id, behind its name and its aria_label) is not
|
|
100
|
+
* read where one of those is surely given. A position may
|
|
85
101
|
* hold DOM as well, which is no key: an array (a
|
|
86
102
|
* createElement2 spec; not an array of string literals,
|
|
87
103
|
* which is none), createElement2(), createOneHtml() or
|
|
@@ -117,8 +133,10 @@
|
|
|
117
133
|
* const object literal (`DEFAULTS.ok`; every value of it for
|
|
118
134
|
* `NOTES[verdict]`), or of a copy of one (`{...o}`,
|
|
119
135
|
* `Object.assign({}, o)`); the element of a const array literal
|
|
120
|
-
*
|
|
121
|
-
*
|
|
136
|
+
* that a for...of iterates, or the first parameter of a callback
|
|
137
|
+
* of one of the methods above (in the same forms, and of
|
|
138
|
+
* `Array.from(items, cb)`), and what a destructuring reads from
|
|
139
|
+
* it;
|
|
122
140
|
* `String(x)`, and a template that is only `${x}`, as x; a
|
|
123
141
|
* parameter however it is read (`opts?.title`, `arguments[1]`,
|
|
124
142
|
* `rest[0]`) and its default; a call of a function the script
|
|
@@ -130,16 +148,25 @@
|
|
|
130
148
|
* was read again at every call, and three recursive branches
|
|
131
149
|
* hung the build. And an UNMARKED plain `let` / `var` whose
|
|
132
150
|
* every value in its scope -- its initializer, every `=`, `||=`,
|
|
133
|
-
* `??=`,
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
151
|
+
* `??=`, `&&=`, the value of a `var` of it declared again -- is
|
|
152
|
+
* written as a string literal, a const bound to one, `null`, or a
|
|
153
|
+
* `?:` / `||` / `??` of those (the right one of `&&`), read where
|
|
154
|
+
* t(), an i18n or a data-i18n* value reads a key: it can only
|
|
155
|
+
* ever hold those literals, and EVERY one of them is a key asked
|
|
156
|
+
* for. Every write counts: one whose value the reader does not
|
|
157
|
+
* read -- a property of a table, a call, data, a `+=`, a
|
|
158
|
+
* destructuring assignment, a for...of / for...in head that
|
|
159
|
+
* writes it (the variable, a destructuring of it, a `var` of it
|
|
160
|
+
* declared again there), a direct eval() -- leaves the variable
|
|
161
|
+
* not followed, and it fails nothing (up to 7.26.41 a
|
|
162
|
+
* destructuring loop head, and a `var` declared again in a loop
|
|
163
|
+
* head or in a block of the module, did not count, and the
|
|
164
|
+
* literal was asked for). The rule is flow-INSENSITIVE: a literal
|
|
165
|
+
* an `if` excludes, or one overwritten before the read, is asked
|
|
166
|
+
* for all the same; a sentinel that is no key is `null`, which is
|
|
167
|
+
* never asked for. A key built by concatenation, held in a `let`
|
|
168
|
+
* given anything else, or arriving as data cannot be known: its
|
|
169
|
+
* module publishes it in a `<NAME>_I18N_KEYS` list.
|
|
143
170
|
*
|
|
144
171
|
* A MARKER at the place a key is read says where the keys of what
|
|
145
172
|
* follows it come from: `/\* i18n: <NAME>_I18N_KEYS *\/` (that
|
|
@@ -161,11 +188,7 @@
|
|
|
161
188
|
* one, a call that returns literals, imported or not -- it is a
|
|
162
189
|
* violation, and so is one that would HIDE a key the reader does
|
|
163
190
|
* not read -- a call whose returns mix keys with data (split the
|
|
164
|
-
* branches), an array of string literals.
|
|
165
|
-
* TRANSLATED text -- `t("k")`, or a string built from one,
|
|
166
|
-
* `t("k") + ":"`, `t("k").toUpperCase()` --: the place keeps the
|
|
167
|
-
* translation as its key, and it never changes language. A
|
|
168
|
-
* marked `let` / `var`
|
|
191
|
+
* branches), an array of string literals. A marked `let` / `var`
|
|
169
192
|
* is READ, and so is one a marked member or element is read from
|
|
170
193
|
* (`LABELS[k]`, `picked = LIST[0]`, the `x` of
|
|
171
194
|
* `LIST.forEach((x) => ...)`): everything it is given in its
|
|
@@ -175,6 +198,15 @@
|
|
|
175
198
|
* lists named, and one given nothing but literals is a
|
|
176
199
|
* violation: it is a const.
|
|
177
200
|
*
|
|
201
|
+
* A TRANSLATED text where a key is read -- `t("k")`, any
|
|
202
|
+
* translator above, or a string built from one, `t("k") + ":"`,
|
|
203
|
+
* `t("k").toUpperCase()` -- is a violation, MARKED OR NOT, given
|
|
204
|
+
* to t() (`t(t("k") + "!")`), to an i18n / data-i18n* value or a
|
|
205
|
+
* `code` where it is a key (`{i18n: t("k")}`), or to a data-i18n*
|
|
206
|
+
* attribute: the
|
|
207
|
+
* place keeps the translation as its key, and it never changes
|
|
208
|
+
* language. Up to 7.26.41 only a marked one failed.
|
|
209
|
+
*
|
|
178
210
|
* THE RULE PER CALL holds the app's own code, as a test holds the
|
|
179
211
|
* library (i18n_key_functions.test.js): every value a key position
|
|
180
212
|
* of a key function can take is a literal (a branch of them,
|
|
@@ -205,15 +237,17 @@
|
|
|
205
237
|
* alias of (a parameter `translate`, a `let` alias,
|
|
206
238
|
* `i18next.getFixedT()`), or called by what is no name of it --
|
|
207
239
|
* `(0, t)(k)`, `[t][0](k)`, `Reflect.apply(t, x, [k])`,
|
|
208
|
-
* `Function.prototype.call.call(t, x, k)` --; a
|
|
209
|
-
* the translator, `t.bind(null, k)`; a parameter a closure
|
|
240
|
+
* `Function.prototype.call.call(t, x, k)` --; a parameter a closure
|
|
210
241
|
* returns (`const inner = () => key; t(inner())`: the search for
|
|
211
242
|
* the functions that forward a key does not see it); a translator
|
|
212
243
|
* handed to a function (`{t: t}`, `yui_tabulator_lang(t)`: it
|
|
213
|
-
* calls it with keys of its own)
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
244
|
+
* calls it with keys of its own), or to any method but those
|
|
245
|
+
* above (`keys.reduce(t)`, `keys.sort(t)`, an alias of a method,
|
|
246
|
+
* `Reflect.apply(Array.prototype.map, keys, [t])`); a translated
|
|
247
|
+
* text held in a `let`, marked or not (`let label = t(k); ...
|
|
248
|
+
* label`: the reader reads the literals of a `let`, not what it
|
|
249
|
+
* translates), or returned by a function (`{i18n:
|
|
250
|
+
* label_of(x)}`); a key function reached through a parameter, a
|
|
217
251
|
* `let` given more than one value, a computed member
|
|
218
252
|
* (`API[name](...)`); a data-i18n* attribute written through an
|
|
219
253
|
* alias of `dataset`, by Object.assign() into it, or named by a
|
|
@@ -223,6 +257,15 @@
|
|
|
223
257
|
* package (gobj-js, i18next); what is written into a const table
|
|
224
258
|
* after its declaration; a window's `title` given as an attr at
|
|
225
259
|
* gobj_create().
|
|
260
|
+
*
|
|
261
|
+
* Where the reader GIVES UP on a value it says so, with the file
|
|
262
|
+
* and the line, and that fails: a chain of consts, aliases or
|
|
263
|
+
* calls more than MAX_DEPTH (24) steps deep, a const that leads
|
|
264
|
+
* back to itself, an expression that can take more than
|
|
265
|
+
* MAX_VALUES (10000) values -- a key behind it would go unasked.
|
|
266
|
+
* Up to 7.26.42 it stopped there in silence, and a chain of consts
|
|
267
|
+
* that doubles at every link died with a RangeError naming no
|
|
268
|
+
* file. A const is read once, wherever it is read.
|
|
226
269
|
|
|
227
270
|
* Options (paths relative to the app's directory):
|
|
228
271
|
*
|
|
@@ -873,11 +916,6 @@ function callee_name(callee)
|
|
|
873
916
|
return null;
|
|
874
917
|
}
|
|
875
918
|
|
|
876
|
-
function is_string_literal(n, re)
|
|
877
|
-
{
|
|
878
|
-
return !!n && n.type === "Literal" && typeof n.value === "string" && (!re || re.test(n.value));
|
|
879
|
-
}
|
|
880
|
-
|
|
881
919
|
/***************************************************************
|
|
882
920
|
* `Object.<name>(...)`?
|
|
883
921
|
***************************************************************/
|
|
@@ -896,11 +934,90 @@ function is_object_call(n, name)
|
|
|
896
934
|
|
|
897
935
|
const FUNCTION_RE = /^(FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;
|
|
898
936
|
|
|
899
|
-
/* The array methods whose callback receives each ELEMENT first
|
|
937
|
+
/* The array methods whose callback receives each ELEMENT first (up to
|
|
938
|
+
* 7.26.41 without findIndex and findLastIndex) */
|
|
900
939
|
const ITERATION_METHODS = new Set([
|
|
901
|
-
"map", "flatMap", "forEach", "filter", "find", "findLast", "some", "every"
|
|
940
|
+
"map", "flatMap", "forEach", "filter", "find", "findIndex", "findLast", "findLastIndex", "some", "every"
|
|
902
941
|
]);
|
|
903
942
|
|
|
943
|
+
/* The builders of an array that hand their callback each element:
|
|
944
|
+
* Array.from(items, cb), Array.fromAsync(items, cb) */
|
|
945
|
+
const ARRAY_BUILDERS = new Set(["from", "fromAsync"]);
|
|
946
|
+
|
|
947
|
+
/***************************************************************
|
|
948
|
+
* A call that hands each ELEMENT of an array to a callback, in the
|
|
949
|
+
* forms the reader reads -- for a method of ITERATION_METHODS:
|
|
950
|
+
*
|
|
951
|
+
* items.map(cb) also `items?.map(cb)`, `items["map"](cb)`
|
|
952
|
+
* X.map.call(items, cb) `Array.prototype.map.call(...)`, `[].map.call(...)`
|
|
953
|
+
* X.map.apply(items, [cb])
|
|
954
|
+
* Array.from(items, cb) and Array.fromAsync(items, cb)
|
|
955
|
+
*
|
|
956
|
+
* -> {method, receiver, callback, form} | null
|
|
957
|
+
*
|
|
958
|
+
* `receiver` is the array walked, `callback` what it is handed (a
|
|
959
|
+
* function, a translator), `form` "" for a plain call, "call",
|
|
960
|
+
* "apply" or "from". `scope` is the chain of ancestors of the call:
|
|
961
|
+
* `Array` must be the global. Any other way to reach the method --
|
|
962
|
+
* an alias of it, Reflect.apply(), a computed name -- is not read.
|
|
963
|
+
***************************************************************/
|
|
964
|
+
function iteration_call(call, scope)
|
|
965
|
+
{
|
|
966
|
+
let unchain = (x) => (x && x.type === "ChainExpression")? x.expression : x;
|
|
967
|
+
let c = unchain(call.callee);
|
|
968
|
+
if(c.type !== "MemberExpression") {
|
|
969
|
+
return null;
|
|
970
|
+
}
|
|
971
|
+
let name = member_step(c).prop;
|
|
972
|
+
if(ITERATION_METHODS.has(name)) {
|
|
973
|
+
let cb = call.arguments[0];
|
|
974
|
+
return (cb && cb.type !== "SpreadElement")? {method: name, receiver: c.object, callback: cb, form: ""} : null;
|
|
975
|
+
}
|
|
976
|
+
if(name === "call" || name === "apply") {
|
|
977
|
+
let inner = unchain(c.object);
|
|
978
|
+
let method = (inner.type === "MemberExpression")? member_step(inner).prop : null;
|
|
979
|
+
if(!ITERATION_METHODS.has(method)) {
|
|
980
|
+
return null;
|
|
981
|
+
}
|
|
982
|
+
let receiver = call.arguments[0];
|
|
983
|
+
let rest = call.arguments[1];
|
|
984
|
+
let cb = (name === "call")? rest : ((rest && rest.type === "ArrayExpression")? rest.elements[0] : null);
|
|
985
|
+
if(!receiver || receiver.type === "SpreadElement" || !cb || cb.type === "SpreadElement") {
|
|
986
|
+
return null;
|
|
987
|
+
}
|
|
988
|
+
return {method, receiver, callback: cb, form: name};
|
|
989
|
+
}
|
|
990
|
+
if(ARRAY_BUILDERS.has(name) && c.object.type === "Identifier" && c.object.name === "Array"
|
|
991
|
+
&& call.arguments.length >= 2 && binding_of("Array", scope) === null) {
|
|
992
|
+
let [items, cb] = call.arguments;
|
|
993
|
+
if(items.type === "SpreadElement" || cb.type === "SpreadElement") {
|
|
994
|
+
return null;
|
|
995
|
+
}
|
|
996
|
+
return {method: `Array.${name}`, receiver: items, callback: cb, form: "from"};
|
|
997
|
+
}
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/***************************************************************
|
|
1002
|
+
* The iteration call (iteration_call()) a function is the CALLBACK
|
|
1003
|
+
* of, when `scope[i]` is that function: {receiver, scope}, `scope`
|
|
1004
|
+
* the chain of ancestors of the call, where `receiver` is read; or
|
|
1005
|
+
* null
|
|
1006
|
+
***************************************************************/
|
|
1007
|
+
function iteration_callback_of(fn, scope, i)
|
|
1008
|
+
{
|
|
1009
|
+
let k = i - 1;
|
|
1010
|
+
if(scope[k] && scope[k].type === "ArrayExpression") {
|
|
1011
|
+
k--; // `.apply(items, [cb])`
|
|
1012
|
+
}
|
|
1013
|
+
let call = scope[k];
|
|
1014
|
+
if(!call || call.type !== "CallExpression") {
|
|
1015
|
+
return null;
|
|
1016
|
+
}
|
|
1017
|
+
let it = iteration_call(call, scope.slice(0, k));
|
|
1018
|
+
return (it && it.callback === fn)? {receiver: it.receiver, scope: scope.slice(0, k)} : null;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
904
1021
|
/***************************************************************
|
|
905
1022
|
* The names a binding pattern declares
|
|
906
1023
|
***************************************************************/
|
|
@@ -959,8 +1076,25 @@ function function_scope_names(fn)
|
|
|
959
1076
|
if(fn.type === "FunctionExpression" && fn.id) {
|
|
960
1077
|
names.set(fn.id.name, null);
|
|
961
1078
|
}
|
|
1079
|
+
if(fn.body && fn.body.type === "BlockStatement") {
|
|
1080
|
+
hoisted_vars(fn.body.body, names);
|
|
1081
|
+
}
|
|
1082
|
+
FN_NAMES.set(fn, names);
|
|
1083
|
+
return names;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
/***************************************************************
|
|
1087
|
+
* The `var`s a list of statements declares, hoisted to the body
|
|
1088
|
+
* they are in -- a function's, the module's, or a class's static
|
|
1089
|
+
* block's: wherever they stand in it (a block, an `if`, a `switch`
|
|
1090
|
+
* case, a `for(;;)` init, a for...of / for...in head), not inside a
|
|
1091
|
+
* function or a static block nested in it, which have their own.
|
|
1092
|
+
* Into `names`, in the form of function_scope_names().
|
|
1093
|
+
***************************************************************/
|
|
1094
|
+
function hoisted_vars(statements, names = new Map())
|
|
1095
|
+
{
|
|
962
1096
|
let visit = (n) => {
|
|
963
|
-
if(!n || typeof n.type !== "string" || FUNCTION_RE.test(n.type)) {
|
|
1097
|
+
if(!n || typeof n.type !== "string" || FUNCTION_RE.test(n.type) || n.type === "StaticBlock") {
|
|
964
1098
|
return;
|
|
965
1099
|
}
|
|
966
1100
|
if(n.type === "VariableDeclaration" && n.kind === "var") {
|
|
@@ -991,12 +1125,9 @@ function function_scope_names(fn)
|
|
|
991
1125
|
}
|
|
992
1126
|
}
|
|
993
1127
|
};
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
visit(s);
|
|
997
|
-
}
|
|
1128
|
+
for(let s of statements) {
|
|
1129
|
+
visit(s);
|
|
998
1130
|
}
|
|
999
|
-
FN_NAMES.set(fn, names);
|
|
1000
1131
|
return names;
|
|
1001
1132
|
}
|
|
1002
1133
|
|
|
@@ -1023,13 +1154,13 @@ function function_name(fn, parent)
|
|
|
1023
1154
|
* it: name -> {kind: "const", init, steps, default} |
|
|
1024
1155
|
* {kind: "each", of} | {kind: "each_part", of} | {kind: "var",
|
|
1025
1156
|
* declarators, picks} (a `let`; a `var` belongs to its function, or
|
|
1026
|
-
* here to the module
|
|
1027
|
-
*
|
|
1028
|
-
* opts`: `.title`; `picks`
|
|
1029
|
-
* array pattern declares is
|
|
1030
|
-
* param_flows()), and an element of a
|
|
1031
|
-
* pattern destructures is "each_part".
|
|
1032
|
-
* function_scope_names().
|
|
1157
|
+
* here to the module, wherever it stands in it: hoisted_vars()) |
|
|
1158
|
+
* {kind: "other", init}. A name declared by a destructuring reads
|
|
1159
|
+
* `steps` from the value (`const {title} = opts`: `.title`; `picks`
|
|
1160
|
+
* per declarator for a `let`); one an array pattern declares is
|
|
1161
|
+
* "other" (its `init`, for param_flows()), and an element of a
|
|
1162
|
+
* for...of that an array pattern destructures is "each_part".
|
|
1163
|
+
* Cached, like function_scope_names().
|
|
1033
1164
|
***************************************************************/
|
|
1034
1165
|
const SCOPE_NAMES = new WeakMap();
|
|
1035
1166
|
|
|
@@ -1040,15 +1171,21 @@ function scope_names(a)
|
|
|
1040
1171
|
}
|
|
1041
1172
|
let names = new Map();
|
|
1042
1173
|
let declare = (name, what) => {
|
|
1043
|
-
|
|
1044
|
-
if(!had) {
|
|
1174
|
+
if(!names.has(name)) {
|
|
1045
1175
|
names.set(name, what);
|
|
1046
|
-
} else if(had.kind === "var" && what.kind === "var") {
|
|
1047
|
-
/* `var x = 1; ... var x = 2;`: one binding, two values */
|
|
1048
|
-
names.set(name, {kind: "var", decl: "var", declarators: [...had.declarators, ...what.declarators],
|
|
1049
|
-
picks: new Map([...had.picks, ...what.picks])});
|
|
1050
1176
|
}
|
|
1051
1177
|
};
|
|
1178
|
+
if((a.type === "Program" && has_var(a)) || a.type === "StaticBlock") {
|
|
1179
|
+
/* Every `var` of the module (or of a class's static block, which has
|
|
1180
|
+
* its own), one binding per name: up to 7.26.41 only those of the
|
|
1181
|
+
* module's top-level statements, so a `var` redeclared in a block or
|
|
1182
|
+
* in a loop head gave the variable a value the reader never saw, and
|
|
1183
|
+
* a `var` of a static block was not seen at all */
|
|
1184
|
+
for(let [name, h] of hoisted_vars(a.body)) {
|
|
1185
|
+
declare(name, h? {kind: "var", decl: "var", declarators: h.declarators, picks: h.picks}
|
|
1186
|
+
: {kind: "other", init: null});
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1052
1189
|
let statements = [];
|
|
1053
1190
|
switch(a.type) {
|
|
1054
1191
|
case "Program":
|
|
@@ -1094,8 +1231,8 @@ function scope_names(a)
|
|
|
1094
1231
|
continue;
|
|
1095
1232
|
}
|
|
1096
1233
|
if(d.type === "VariableDeclaration") {
|
|
1097
|
-
if(d.kind === "var"
|
|
1098
|
-
continue; // hoisted:
|
|
1234
|
+
if(d.kind === "var") {
|
|
1235
|
+
continue; // hoisted: its function's, module's or static block's hoisted_vars() holds it
|
|
1099
1236
|
}
|
|
1100
1237
|
for(let v of d.declarations) {
|
|
1101
1238
|
let plain = (v.id.type === "Identifier");
|
|
@@ -1297,12 +1434,11 @@ function binding_of(name, scope)
|
|
|
1297
1434
|
if(j !== undefined) {
|
|
1298
1435
|
let p = a.params[j];
|
|
1299
1436
|
let at = param_path(p, name);
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
return at? {kind: "each", of:
|
|
1304
|
-
|
|
1305
|
-
: {kind: "each_part", of: parent.callee.object, scope: scope.slice(0, i - 1)};
|
|
1437
|
+
let it = (j === 0 && parent && a.type !== "FunctionDeclaration")?
|
|
1438
|
+
iteration_callback_of(a, scope, i) : null;
|
|
1439
|
+
if(it) {
|
|
1440
|
+
return at? {kind: "each", of: it.receiver, steps: at.steps, scope: it.scope}
|
|
1441
|
+
: {kind: "each_part", of: it.receiver, scope: it.scope};
|
|
1306
1442
|
}
|
|
1307
1443
|
let base = {fn: a, name: function_name(a, parent), index: j, scope: scope.slice(0, i + 1)};
|
|
1308
1444
|
if(at) {
|
|
@@ -1610,7 +1746,12 @@ const TRANSLATOR = Object.freeze({kind: "t", name: "t"});
|
|
|
1610
1746
|
* const (`const translate = t`), a
|
|
1611
1747
|
* `.bind()` (`i18next.t.bind(i18next)`),
|
|
1612
1748
|
* a re-export of a module the reader
|
|
1613
|
-
* reads
|
|
1749
|
+
* reads. A `.bind()` that binds
|
|
1750
|
+
* arguments too (`t.bind(null, k)`)
|
|
1751
|
+
* adds `bound`, how many (and
|
|
1752
|
+
* `bound_spread` when a spread hides
|
|
1753
|
+
* it), to whatever it binds:
|
|
1754
|
+
* call_target() counts them
|
|
1614
1755
|
* {kind: "fn", fn, scope, name, url}
|
|
1615
1756
|
* a FUNCTION the reader reads: a
|
|
1616
1757
|
* declaration, a const bound to one
|
|
@@ -1630,7 +1771,11 @@ const TRANSLATOR = Object.freeze({kind: "t", name: "t"});
|
|
|
1630
1771
|
***************************************************************/
|
|
1631
1772
|
function callee_of(node, scope, depth = 0)
|
|
1632
1773
|
{
|
|
1633
|
-
if(!node
|
|
1774
|
+
if(!node) {
|
|
1775
|
+
return null;
|
|
1776
|
+
}
|
|
1777
|
+
if(depth > MAX_DEPTH) {
|
|
1778
|
+
give_up(node, scope, GIVE_UP_DEEP);
|
|
1634
1779
|
return null;
|
|
1635
1780
|
}
|
|
1636
1781
|
switch(node.type) {
|
|
@@ -1708,13 +1853,24 @@ function callee_of(node, scope, depth = 0)
|
|
|
1708
1853
|
return TRANSLATOR_NAMES.has(step.prop)? TRANSLATOR : null;
|
|
1709
1854
|
}
|
|
1710
1855
|
|
|
1711
|
-
case "CallExpression":
|
|
1712
|
-
/* f.bind(x) is f
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1856
|
+
case "CallExpression": {
|
|
1857
|
+
/* f.bind(x) is f; f.bind(x, a, ...) is f with its first arguments
|
|
1858
|
+
* BOUND, so what a call of it is handed comes after them */
|
|
1859
|
+
let c = node.callee;
|
|
1860
|
+
if(c.type !== "MemberExpression" || c.computed || c.property.type !== "Identifier"
|
|
1861
|
+
|| c.property.name !== "bind") {
|
|
1862
|
+
return null;
|
|
1716
1863
|
}
|
|
1717
|
-
|
|
1864
|
+
let inner = callee_of(c.object, scope, depth + 1);
|
|
1865
|
+
let taken = node.arguments.slice(1);
|
|
1866
|
+
if(!inner || taken.length === 0) {
|
|
1867
|
+
return inner;
|
|
1868
|
+
}
|
|
1869
|
+
return Object.assign({}, inner, {
|
|
1870
|
+
bound: (inner.bound || 0) + taken.length,
|
|
1871
|
+
bound_spread: !!inner.bound_spread || taken.some((a) => a.type === "SpreadElement")
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1718
1874
|
|
|
1719
1875
|
default:
|
|
1720
1876
|
return null;
|
|
@@ -1768,7 +1924,12 @@ function var_function(b)
|
|
|
1768
1924
|
* What a call calls (callee_of()), and the arguments the callee
|
|
1769
1925
|
* receives: `f(a)` a; `f.call(x, a)` a; `f.apply(x, [a, b])` a and
|
|
1770
1926
|
* b (null when `.apply()` hands an array the source does not write
|
|
1771
|
-
* out).
|
|
1927
|
+
* out). A callee with arguments BOUND (`const g = f.bind(x, a)`)
|
|
1928
|
+
* receives those first: they stand as holes (null) before what the
|
|
1929
|
+
* call hands -- a position not read HERE: what a bind binds is read
|
|
1930
|
+
* where the bind is written (bind_kind()) --, and the arguments are
|
|
1931
|
+
* null when a spread hides how many were bound. Cached per call: what
|
|
1932
|
+
* it calls does not change.
|
|
1772
1933
|
*
|
|
1773
1934
|
* -> {target, args} | null
|
|
1774
1935
|
***************************************************************/
|
|
@@ -1798,10 +1959,58 @@ function call_target(call, scope)
|
|
|
1798
1959
|
let target = callee_of(callee, scope);
|
|
1799
1960
|
r = target? {target, args: call.arguments} : null;
|
|
1800
1961
|
}
|
|
1962
|
+
if(r && r.target.bound) {
|
|
1963
|
+
/* Up to 7.26.41 the bound arguments were not counted: what a call of
|
|
1964
|
+
* `t.bind(null, k)` hands -- i18next's options, its default value -- was
|
|
1965
|
+
* asked for as a key */
|
|
1966
|
+
r = {target: r.target, args: (r.args && !r.target.bound_spread)?
|
|
1967
|
+
[...new Array(r.target.bound).fill(null), ...r.args] : null};
|
|
1968
|
+
}
|
|
1801
1969
|
CALL_TARGETS.set(call, r);
|
|
1802
1970
|
return r;
|
|
1803
1971
|
}
|
|
1804
1972
|
|
|
1973
|
+
/***************************************************************
|
|
1974
|
+
* A `.bind()` of a key function or of a translator, read as the
|
|
1975
|
+
* call it prepares: `yui_shell_show_info.bind(null, shell, "k")`
|
|
1976
|
+
* hands "k" at position 1 of yui_shell_show_info, `t.bind(null, "k")`
|
|
1977
|
+
* hands t() its key -- where the bind is written, since a call of
|
|
1978
|
+
* what it makes no longer hands those positions (call_target()).
|
|
1979
|
+
* Up to 7.26.42 what a bind binds was not read: a key bound there
|
|
1980
|
+
* went unasked, and a parameter bound there passed the rule per call.
|
|
1981
|
+
*
|
|
1982
|
+
* -> {kind: "key", entry, target, args} | {kind: "t", target, args}
|
|
1983
|
+
* | null, `args` the arguments the function receives, the ones
|
|
1984
|
+
* bound before (`f.bind(x, a).bind(y, b)`) as holes, and null
|
|
1985
|
+
* when a spread hides them
|
|
1986
|
+
***************************************************************/
|
|
1987
|
+
function bind_kind(call, scope, table = I18N_KEY_FUNCTIONS)
|
|
1988
|
+
{
|
|
1989
|
+
let c = call.callee;
|
|
1990
|
+
if(c.type !== "MemberExpression" || c.computed || c.property.type !== "Identifier"
|
|
1991
|
+
|| c.property.name !== "bind" || call.arguments.length < 2) {
|
|
1992
|
+
return null;
|
|
1993
|
+
}
|
|
1994
|
+
let inner = callee_of(c.object, scope);
|
|
1995
|
+
if(!inner) {
|
|
1996
|
+
return null;
|
|
1997
|
+
}
|
|
1998
|
+
let args = inner.bound_spread? null : [...new Array(inner.bound || 0).fill(null), ...call.arguments.slice(1)];
|
|
1999
|
+
if(inner.kind === "t") {
|
|
2000
|
+
return {kind: "t", target: inner, args};
|
|
2001
|
+
}
|
|
2002
|
+
let module = lib_module_of(inner.url);
|
|
2003
|
+
let fns = module? key_fn_index(table).by_module.get(module) : null;
|
|
2004
|
+
let entry = fns? (fns.get(inner.name) || null) : null;
|
|
2005
|
+
if(entry) {
|
|
2006
|
+
return {kind: "key", entry, target: inner, args};
|
|
2007
|
+
}
|
|
2008
|
+
if(TRANSLATOR_NAMES.has(inner.name)) {
|
|
2009
|
+
return {kind: "t", target: inner, args};
|
|
2010
|
+
}
|
|
2011
|
+
return null;
|
|
2012
|
+
}
|
|
2013
|
+
|
|
1805
2014
|
/***************************************************************
|
|
1806
2015
|
* What kind of call a call is, for the reader:
|
|
1807
2016
|
*
|
|
@@ -1881,7 +2090,11 @@ function is_translated_text(n, scope, depth = 0)
|
|
|
1881
2090
|
while(n && n.type === "ChainExpression") {
|
|
1882
2091
|
n = n.expression;
|
|
1883
2092
|
}
|
|
1884
|
-
if(!n
|
|
2093
|
+
if(!n) {
|
|
2094
|
+
return false;
|
|
2095
|
+
}
|
|
2096
|
+
if(depth > MAX_DEPTH) {
|
|
2097
|
+
give_up(n, scope, GIVE_UP_DEEP);
|
|
1885
2098
|
return false;
|
|
1886
2099
|
}
|
|
1887
2100
|
let sub = (x) => is_translated_text(x, scope, depth + 1);
|
|
@@ -1930,28 +2143,28 @@ const SETTLE_METHODS = new Set(["then", "catch"]);
|
|
|
1930
2143
|
* call it is handed to calls it, and what that call hands it is a
|
|
1931
2144
|
* key the source writes nowhere as one:
|
|
1932
2145
|
*
|
|
1933
|
-
* {how: "elements", method, receiver, arg}
|
|
1934
|
-
* `
|
|
1935
|
-
* `
|
|
1936
|
-
*
|
|
2146
|
+
* {how: "elements", method, form, receiver, arg}
|
|
2147
|
+
* each ELEMENT of `receiver` is a key, in every form of
|
|
2148
|
+
* iteration_call(): `keys.map(t)`, `.forEach(t)`,
|
|
2149
|
+
* `.findIndex(t)`, ... (ITERATION_METHODS),
|
|
2150
|
+
* `Array.prototype.map.call(keys, t)`,
|
|
2151
|
+
* `[].forEach.apply(keys, [t])`, `Array.from(keys, t)`,
|
|
2152
|
+
* `Array.fromAsync(keys, t)`
|
|
1937
2153
|
* {how: "settled", method, arg}
|
|
1938
2154
|
* `promise.then(t)`, `.catch(t)`: what the promise settles
|
|
1939
2155
|
* with, which no source writes
|
|
1940
2156
|
* null anything else. A translator handed to a FUNCTION is how
|
|
1941
2157
|
* gobj-ui receives one (`{t: t}`, `yui_tabulator_lang(t)`):
|
|
1942
2158
|
* that function calls it with keys of its own, read where
|
|
1943
|
-
* it does. A
|
|
1944
|
-
* k)
|
|
2159
|
+
* it does. A translator with arguments BOUND (`t.bind(null,
|
|
2160
|
+
* k)`, or a const bound to one) is no callback of these:
|
|
2161
|
+
* what it is handed goes after the bound key, as i18next's
|
|
2162
|
+
* options.
|
|
1945
2163
|
*
|
|
1946
2164
|
* `scope` is the chain of ancestors of the call, the call last.
|
|
1947
2165
|
***************************************************************/
|
|
1948
2166
|
function translator_callback(call, scope)
|
|
1949
2167
|
{
|
|
1950
|
-
let c = (call.callee.type === "ChainExpression")? call.callee.expression : call.callee;
|
|
1951
|
-
if(c.type !== "MemberExpression" || c.computed || c.property.type !== "Identifier") {
|
|
1952
|
-
return null;
|
|
1953
|
-
}
|
|
1954
|
-
let method = c.property.name;
|
|
1955
2168
|
let is_translator = (a) => {
|
|
1956
2169
|
while(a && a.type === "ChainExpression") {
|
|
1957
2170
|
a = a.expression;
|
|
@@ -1959,23 +2172,20 @@ function translator_callback(call, scope)
|
|
|
1959
2172
|
if(!a || a.type === "SpreadElement") {
|
|
1960
2173
|
return false;
|
|
1961
2174
|
}
|
|
1962
|
-
if(a.type === "CallExpression" && a.arguments.length > 1) {
|
|
1963
|
-
return false; // `t.bind(x, k)`: k is the key, not what the callback is handed
|
|
1964
|
-
}
|
|
1965
2175
|
let target = callee_of(a, scope);
|
|
1966
|
-
return !!target && (target.kind === "t" || (target.kind === "fn"
|
|
1967
|
-
&& !is_key_function(target)));
|
|
2176
|
+
return !!target && !target.bound && (target.kind === "t" || (target.kind === "fn"
|
|
2177
|
+
&& TRANSLATOR_NAMES.has(target.name) && !is_key_function(target)));
|
|
1968
2178
|
};
|
|
1969
|
-
let
|
|
1970
|
-
if(
|
|
1971
|
-
return
|
|
2179
|
+
let it = iteration_call(call, scope);
|
|
2180
|
+
if(it) {
|
|
2181
|
+
return is_translator(it.callback)?
|
|
2182
|
+
{how: "elements", method: it.method, form: it.form, receiver: it.receiver, arg: it.callback} : null;
|
|
1972
2183
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
return {how: "elements", method: "Array.from", receiver: call.arguments[0], arg: call.arguments[1]};
|
|
2184
|
+
let c = (call.callee.type === "ChainExpression")? call.callee.expression : call.callee;
|
|
2185
|
+
let method = (c.type === "MemberExpression")? member_step(c).prop : null;
|
|
2186
|
+
if(SETTLE_METHODS.has(method)) {
|
|
2187
|
+
let arg = call.arguments.find(is_translator);
|
|
2188
|
+
return arg? {how: "settled", method, arg} : null;
|
|
1979
2189
|
}
|
|
1980
2190
|
return null;
|
|
1981
2191
|
}
|
|
@@ -1996,8 +2206,60 @@ function is_key_function(target)
|
|
|
1996
2206
|
***************************/
|
|
1997
2207
|
|
|
1998
2208
|
|
|
1999
|
-
/* How far a chain of consts is followed
|
|
2209
|
+
/* How far a chain of consts, aliases or calls is followed (a cycle stops
|
|
2210
|
+
* here too), and how many values one expression may take. Past either the
|
|
2211
|
+
* reader GIVES UP, and says so (give_up()): a key behind a value it does
|
|
2212
|
+
* not follow would go unasked, and the build say OK */
|
|
2000
2213
|
const MAX_DEPTH = 24;
|
|
2214
|
+
const MAX_VALUES = 10000;
|
|
2215
|
+
|
|
2216
|
+
/***************************************************************
|
|
2217
|
+
* Where the reader GAVE UP on a value: a chain deeper than
|
|
2218
|
+
* MAX_DEPTH, a const that leads back to itself, an expression that
|
|
2219
|
+
* can take more than MAX_VALUES values. A key behind it would go
|
|
2220
|
+
* unasked, so it is a violation, with the file and the line
|
|
2221
|
+
* (collect_used_keys(); the library's own test holds the library to
|
|
2222
|
+
* none). Up to 7.26.42 the reader stopped there in silence: a chain
|
|
2223
|
+
* of 24 aliases of a const asked for nothing, and a chain of consts
|
|
2224
|
+
* that doubles at every step (`{...O, ...O}`) grew without end and
|
|
2225
|
+
* died with a RangeError naming no file.
|
|
2226
|
+
*
|
|
2227
|
+
* `node` is the value it gave up on, `scope` the chain of its
|
|
2228
|
+
* ancestors (the first one, the module: where it is said).
|
|
2229
|
+
***************************************************************/
|
|
2230
|
+
const GAVE_UP = new Map(); // node -> {node, scope, why}
|
|
2231
|
+
|
|
2232
|
+
const GIVE_UP_DEEP = `it is more than ${MAX_DEPTH} steps deep (a chain of consts, aliases or calls ` +
|
|
2233
|
+
`that long): shorten the chain`;
|
|
2234
|
+
const GIVE_UP_CYCLE = `it is a const that leads back to itself: break the cycle`;
|
|
2235
|
+
const GIVE_UP_MANY = `it can take more than ${MAX_VALUES} values: split it`;
|
|
2236
|
+
|
|
2237
|
+
function give_up(node, scope, why)
|
|
2238
|
+
{
|
|
2239
|
+
if(node && !GAVE_UP.has(node)) {
|
|
2240
|
+
GAVE_UP.set(node, {node, scope: scope || [], why});
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
/* Where the reader gave up so far -- in one parsed file, when it is
|
|
2245
|
+
* given: [{url, line, text, why}] */
|
|
2246
|
+
function gave_up(ast = null)
|
|
2247
|
+
{
|
|
2248
|
+
let out = [];
|
|
2249
|
+
for(let {node, scope, why} of GAVE_UP.values()) {
|
|
2250
|
+
let program = (scope.length > 0 && typeof scope[0].code === "string")? scope[0] : null;
|
|
2251
|
+
if(ast && program !== ast) {
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
out.push({
|
|
2255
|
+
url: program? (PROGRAM_URL.get(program) || null) : null,
|
|
2256
|
+
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
|
+
why
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
return out;
|
|
2262
|
+
}
|
|
2001
2263
|
|
|
2002
2264
|
/***************************************************************
|
|
2003
2265
|
* The values an expression can take, as far as the source writes
|
|
@@ -2062,6 +2324,16 @@ const MAX_DEPTH = 24;
|
|
|
2062
2324
|
* read for the declaration of a const: `via` stops growing there.
|
|
2063
2325
|
***************************************************************/
|
|
2064
2326
|
function expand(node, ctx, depth = 0)
|
|
2327
|
+
{
|
|
2328
|
+
let out = expand_node(node, ctx, depth);
|
|
2329
|
+
if(out.length > MAX_VALUES) {
|
|
2330
|
+
give_up(node, ctx.scope, GIVE_UP_MANY);
|
|
2331
|
+
return [{kind: "unknown", node, scope: ctx.scope, via: ctx.off? ctx.via : [...ctx.via, node], off: ctx.off}];
|
|
2332
|
+
}
|
|
2333
|
+
return out;
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
function expand_node(node, ctx, depth)
|
|
2065
2337
|
{
|
|
2066
2338
|
if(!node) {
|
|
2067
2339
|
return [];
|
|
@@ -2070,6 +2342,7 @@ function expand(node, ctx, depth = 0)
|
|
|
2070
2342
|
let here = {scope: ctx.scope, via: via, off: ctx.off};
|
|
2071
2343
|
let item = (kind, extra) => Object.assign({kind, node, scope: ctx.scope, via, off: ctx.off}, extra);
|
|
2072
2344
|
if(depth > MAX_DEPTH) {
|
|
2345
|
+
give_up(node, ctx.scope, GIVE_UP_DEEP);
|
|
2073
2346
|
return [item("unknown")];
|
|
2074
2347
|
}
|
|
2075
2348
|
|
|
@@ -2172,12 +2445,38 @@ function expand(node, ctx, depth = 0)
|
|
|
2172
2445
|
/***************************************************************
|
|
2173
2446
|
* The values of a const (a binding of binding_of(), or a const
|
|
2174
2447
|
* module_export() found in another module): its value read where it
|
|
2175
|
-
* is declared, the steps a destructuring reads from it, its default
|
|
2448
|
+
* is declared, the steps a destructuring reads from it, its default.
|
|
2449
|
+
*
|
|
2450
|
+
* Its value is read ONCE, without repeats, and kept: a const is read
|
|
2451
|
+
* where it is declared, so what it holds is the same wherever it is
|
|
2452
|
+
* read -- only `via`, the place it is read from, differs, and it is
|
|
2453
|
+
* the same for every value (the reader leaves the place for the
|
|
2454
|
+
* declaration). Up to 7.26.42 a const was read again at every read,
|
|
2455
|
+
* so `const O1 = c()? O0 : {...O0, ...O0}`, chained, took three
|
|
2456
|
+
* times as long at every link (eleven links, 906 ms) and grew its
|
|
2457
|
+
* values until a RangeError. A const met again while its value is
|
|
2458
|
+
* being read leads back to itself: the reader gives up on it
|
|
2459
|
+
* (give_up()).
|
|
2176
2460
|
***************************************************************/
|
|
2461
|
+
const CONST_VALUES = new WeakMap(); // the init of a const -> its values, `via` left out
|
|
2462
|
+
const CONST_READING = new Set(); // the inits being read
|
|
2463
|
+
|
|
2177
2464
|
function const_values(b, node, via, depth)
|
|
2178
2465
|
{
|
|
2179
2466
|
let ctx = {scope: b.scope, via: via, off: true};
|
|
2180
|
-
|
|
2467
|
+
if(!CONST_VALUES.has(b.init)) {
|
|
2468
|
+
if(CONST_READING.has(b.init)) {
|
|
2469
|
+
give_up(b.init, b.scope, GIVE_UP_CYCLE);
|
|
2470
|
+
return [{kind: "unknown", node: b.init, scope: b.scope, via, off: true}];
|
|
2471
|
+
}
|
|
2472
|
+
CONST_READING.add(b.init);
|
|
2473
|
+
try {
|
|
2474
|
+
CONST_VALUES.set(b.init, unique_values(expand(b.init, {scope: b.scope, via: [], off: true}, depth + 1)));
|
|
2475
|
+
} finally {
|
|
2476
|
+
CONST_READING.delete(b.init);
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
let out = CONST_VALUES.get(b.init).map((v) => Object.assign({}, v, {via}));
|
|
2181
2480
|
for(let step of b.steps || []) {
|
|
2182
2481
|
out = out.flatMap((o) => step_values(o, step, node, depth + 1));
|
|
2183
2482
|
}
|
|
@@ -2453,9 +2752,44 @@ function assigned_properties(o, step, depth)
|
|
|
2453
2752
|
* The values of property `name` of an object literal (`name` null:
|
|
2454
2753
|
* of every property), each followed with expand(). A spread is read
|
|
2455
2754
|
* for it: an object literal, or a parameter (`{...opts}` holds
|
|
2456
|
-
* opts.title as its title)
|
|
2755
|
+
* opts.title as its title).
|
|
2756
|
+
*
|
|
2757
|
+
* An object reached from a declaration (`o.off`: every value it
|
|
2758
|
+
* gives carries the same `via`) is read once per property, without
|
|
2759
|
+
* repeats, and kept -- as a const is (const_values()): a spread of the
|
|
2760
|
+
* same object twice, `{...O, ...O}`, gives its values once.
|
|
2457
2761
|
***************************************************************/
|
|
2762
|
+
const PROPERTY_VALUES = new WeakMap(); // an object literal -> Map(property -> its values, `via` left out)
|
|
2763
|
+
|
|
2458
2764
|
function property_values(o, name, depth)
|
|
2765
|
+
{
|
|
2766
|
+
if(!o.off) {
|
|
2767
|
+
return capped(o, property_values_of(o, name, depth));
|
|
2768
|
+
}
|
|
2769
|
+
let known = PROPERTY_VALUES.get(o.node);
|
|
2770
|
+
if(!known) {
|
|
2771
|
+
known = new Map();
|
|
2772
|
+
PROPERTY_VALUES.set(o.node, known);
|
|
2773
|
+
}
|
|
2774
|
+
if(!known.has(name)) {
|
|
2775
|
+
let values = unique_values(property_values_of(Object.assign({}, o, {via: []}), name, depth));
|
|
2776
|
+
known.set(name, capped(Object.assign({}, o, {via: []}), values));
|
|
2777
|
+
}
|
|
2778
|
+
return known.get(name).map((v) => Object.assign({}, v, {via: o.via}));
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
/* The values of a value, or the reader giving up on it when they are
|
|
2782
|
+
* more than MAX_VALUES */
|
|
2783
|
+
function capped(o, values)
|
|
2784
|
+
{
|
|
2785
|
+
if(values.length <= MAX_VALUES) {
|
|
2786
|
+
return values;
|
|
2787
|
+
}
|
|
2788
|
+
give_up(o.node, o.scope, GIVE_UP_MANY);
|
|
2789
|
+
return [Object.assign({}, o, {kind: "unknown", binding: null, var_root: null})];
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
function property_values_of(o, name, depth)
|
|
2459
2793
|
{
|
|
2460
2794
|
let out = [];
|
|
2461
2795
|
let scope = [...o.scope, o.node];
|
|
@@ -2518,9 +2852,30 @@ function elements_of(node, ctx, depth)
|
|
|
2518
2852
|
/***************************************************************
|
|
2519
2853
|
* The elements of one value of expand(): see elements_of(). Each
|
|
2520
2854
|
* element of a rest parameter is another parameter: no position can
|
|
2521
|
-
* name one, and the reader cannot follow it.
|
|
2855
|
+
* name one, and the reader cannot follow it. The elements of an array
|
|
2856
|
+
* literal (or of a `.map()` of one) reached from a declaration are
|
|
2857
|
+
* read once, without repeats, and kept, as the properties of an
|
|
2858
|
+
* object are (property_values()): `[...A, ...A]` gives A's once.
|
|
2522
2859
|
***************************************************************/
|
|
2860
|
+
const ELEMENT_VALUES = new WeakMap(); // an array literal or a .map() -> its elements, `via` left out
|
|
2861
|
+
|
|
2523
2862
|
function element_values(v, depth)
|
|
2863
|
+
{
|
|
2864
|
+
let literal = v.kind === "value" && (v.node.type === "ArrayExpression" || is_mapping(v.node));
|
|
2865
|
+
if(!literal) {
|
|
2866
|
+
return element_values_of(v, depth);
|
|
2867
|
+
}
|
|
2868
|
+
if(!v.off) {
|
|
2869
|
+
return capped(v, element_values_of(v, depth));
|
|
2870
|
+
}
|
|
2871
|
+
if(!ELEMENT_VALUES.has(v.node)) {
|
|
2872
|
+
let bare = Object.assign({}, v, {via: []});
|
|
2873
|
+
ELEMENT_VALUES.set(v.node, capped(bare, unique_values(element_values_of(bare, depth))));
|
|
2874
|
+
}
|
|
2875
|
+
return ELEMENT_VALUES.get(v.node).map((x) => Object.assign({}, x, {via: v.via}));
|
|
2876
|
+
}
|
|
2877
|
+
|
|
2878
|
+
function element_values_of(v, depth)
|
|
2524
2879
|
{
|
|
2525
2880
|
let out = [];
|
|
2526
2881
|
if(v.kind === "param" && v.binding.rest) {
|
|
@@ -2776,8 +3131,16 @@ function static_keys(node, scope = [])
|
|
|
2776
3131
|
* A position the call does not reach (an argument not given) has no
|
|
2777
3132
|
* leaf: its default applies. An options object held in a variable,
|
|
2778
3133
|
* a spread, a parameter, a copy: followed like any value.
|
|
3134
|
+
*
|
|
3135
|
+
* `fallbacks` (the entry's `fallbacks` of the position, or null):
|
|
3136
|
+
* the positions the function reads FIRST, the position itself being
|
|
3137
|
+
* only their fallback (`it.name || it.aria_label || it.id`). An
|
|
3138
|
+
* object that surely gives one of them -- every value it can take
|
|
3139
|
+
* there is a non-empty string -- does not reach the position, and has
|
|
3140
|
+
* no leaf there; any other object (one that may give none of them, a
|
|
3141
|
+
* parameter, data) reaches it.
|
|
2779
3142
|
***************************************************************/
|
|
2780
|
-
function values_at(call, path, scope = [], args = call.arguments)
|
|
3143
|
+
function values_at(call, path, scope = [], args = call.arguments, fallbacks = null)
|
|
2781
3144
|
{
|
|
2782
3145
|
let segs = String(path).split(".");
|
|
2783
3146
|
let first = segs.shift().match(/^(\d+)(\[\])?$/);
|
|
@@ -2799,11 +3162,16 @@ function values_at(call, path, scope = [], args = call.arguments)
|
|
|
2799
3162
|
|
|
2800
3163
|
let ctx = {scope: call_scope, via: [call], off: false};
|
|
2801
3164
|
let cur = first[2]? elements_of(arg, ctx, 0) : expand(arg, ctx);
|
|
2802
|
-
|
|
3165
|
+
let parent = String(path).slice(0, String(path).lastIndexOf(".") + 1);
|
|
3166
|
+
let shortcuts = (fallbacks || []).map((f) => f.slice(parent.length).split("."));
|
|
3167
|
+
for(let [i, seg] of segs.entries()) {
|
|
2803
3168
|
let m = seg.match(/^([\w$]+)(\[\])?$/);
|
|
2804
3169
|
if(!m) {
|
|
2805
3170
|
return [at_call];
|
|
2806
3171
|
}
|
|
3172
|
+
if(i === segs.length - 1 && shortcuts.length > 0) {
|
|
3173
|
+
cur = cur.filter((v) => !shortcuts.some((rel) => surely_given(v, rel)));
|
|
3174
|
+
}
|
|
2807
3175
|
let next = [];
|
|
2808
3176
|
for(let v of cur) {
|
|
2809
3177
|
if(v.kind === "nothing" || (v.kind === "value" && v.node.type === "Literal")) {
|
|
@@ -2819,6 +3187,24 @@ function values_at(call, path, scope = [], args = call.arguments)
|
|
|
2819
3187
|
return cur.map(classify);
|
|
2820
3188
|
}
|
|
2821
3189
|
|
|
3190
|
+
/* Does a value surely give a non-empty string at the steps `rel`
|
|
3191
|
+
* (["name"], ["roll", "label"]) -- every value it can take there is
|
|
3192
|
+
* one? Nothing, a parameter, data: not surely. */
|
|
3193
|
+
function surely_given(v, rel)
|
|
3194
|
+
{
|
|
3195
|
+
let cur = [v];
|
|
3196
|
+
for(let prop of rel) {
|
|
3197
|
+
cur = cur.flatMap((o) => (o.kind === "nothing")? [o] : step_values(o, {prop, computed: false}, null, 0));
|
|
3198
|
+
}
|
|
3199
|
+
return cur.length > 0 && cur.every((x) => classify(x).kind === "key");
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
/* The `fallbacks` of a position of an entry of I18N_KEY_FUNCTIONS */
|
|
3203
|
+
function fallbacks_of(entry, path)
|
|
3204
|
+
{
|
|
3205
|
+
return (entry.fallbacks && entry.fallbacks[path]) || null;
|
|
3206
|
+
}
|
|
3207
|
+
|
|
2822
3208
|
/***************************************************************
|
|
2823
3209
|
* The steps from a `let` / `var` to the member a node names, when
|
|
2824
3210
|
* the node is the variable itself (no step) or a member of it
|
|
@@ -2870,14 +3256,60 @@ function paths_meet(a, b)
|
|
|
2870
3256
|
* the first argument that is one (fill: only that one) */
|
|
2871
3257
|
const ELEMENT_WRITERS = new Map([["push", 0], ["unshift", 0], ["splice", 2], ["fill", 0]]);
|
|
2872
3258
|
|
|
3259
|
+
/***************************************************************
|
|
3260
|
+
* What a write TARGET sets -- the left of an `=`, the head of a
|
|
3261
|
+
* for...of / for...in that declares nothing --: each identifier and
|
|
3262
|
+
* each member it holds, through any destructuring (`[k, x.a] = v`,
|
|
3263
|
+
* `({k, y: x.b = "d"} = v)`, `[...rest]`)
|
|
3264
|
+
***************************************************************/
|
|
3265
|
+
function write_targets(p, out = [])
|
|
3266
|
+
{
|
|
3267
|
+
if(!p) {
|
|
3268
|
+
return out;
|
|
3269
|
+
}
|
|
3270
|
+
switch(p.type) {
|
|
3271
|
+
case "Identifier":
|
|
3272
|
+
case "MemberExpression":
|
|
3273
|
+
out.push(p);
|
|
3274
|
+
break;
|
|
3275
|
+
case "AssignmentPattern":
|
|
3276
|
+
write_targets(p.left, out);
|
|
3277
|
+
break;
|
|
3278
|
+
case "RestElement":
|
|
3279
|
+
write_targets(p.argument, out);
|
|
3280
|
+
break;
|
|
3281
|
+
case "ArrayPattern":
|
|
3282
|
+
for(let e of p.elements) {
|
|
3283
|
+
write_targets(e, out);
|
|
3284
|
+
}
|
|
3285
|
+
break;
|
|
3286
|
+
case "ObjectPattern":
|
|
3287
|
+
for(let q of p.properties) {
|
|
3288
|
+
write_targets((q.type === "RestElement")? q : q.value, out);
|
|
3289
|
+
}
|
|
3290
|
+
break;
|
|
3291
|
+
default:
|
|
3292
|
+
break;
|
|
3293
|
+
}
|
|
3294
|
+
return out;
|
|
3295
|
+
}
|
|
3296
|
+
|
|
2873
3297
|
/***************************************************************
|
|
2874
3298
|
* Everything a plain `let` / `var` is GIVEN, in the scope that
|
|
2875
3299
|
* declares it: the value of each declarator (one with none holds
|
|
2876
3300
|
* nothing), and the right side of every `=` to it (`||=`, `??=`,
|
|
2877
|
-
* `&&=` too: the old value stays possible besides).
|
|
2878
|
-
*
|
|
2879
|
-
*
|
|
2880
|
-
* (
|
|
3301
|
+
* `&&=` too: the old value stays possible besides). EVERY other
|
|
3302
|
+
* write to it is one whose value the reader does not read, and is
|
|
3303
|
+
* listed in `unknown`: `+=`, `++`, a destructuring assignment
|
|
3304
|
+
* (`[k, x] = v`, `({k} = v)`), the head of a for...of / for...in --
|
|
3305
|
+
* the variable itself (`for(k of v)`), a destructuring of it
|
|
3306
|
+
* (`for([k, x] of v)`, `for({k} of v)`), or a `var` of it declared
|
|
3307
|
+
* again there (`for(var k of v)`) --, and a direct `eval()` in its
|
|
3308
|
+
* scope, which can write any variable there. A `var` declared again
|
|
3309
|
+
* with a value anywhere in its function or module (a block, a
|
|
3310
|
+
* `for(;;)` init, a `switch` case) is one more declarator of it, so
|
|
3311
|
+
* its value is one more value. A name of another binding (shadowing)
|
|
3312
|
+
* is not a write to it.
|
|
2881
3313
|
*
|
|
2882
3314
|
* With `members` (it holds a table, and what is read is a member of
|
|
2883
3315
|
* it), also what is written INTO it: `x.a = v`, `x[k] = v`,
|
|
@@ -2885,7 +3317,8 @@ const ELEMENT_WRITERS = new Map([["push", 0], ["unshift", 0], ["splice", 2], ["f
|
|
|
2885
3317
|
* the elements `x.push(v)`, `x.unshift(v)`, `x.splice(i, n, v)`,
|
|
2886
3318
|
* `x.fill(v)` give it (a spread: every element of what is spread),
|
|
2887
3319
|
* and `Object.assign(x, v)` (v written over x). A `+=` or `++` on a
|
|
2888
|
-
* member
|
|
3320
|
+
* member, and a member a destructuring or a loop head writes
|
|
3321
|
+
* (`[x.a] = v`, `for(x.a of v)`), is unknown at that member.
|
|
2889
3322
|
*
|
|
2890
3323
|
* -> {values: [{node, scope, steps, spread, into, pick}],
|
|
2891
3324
|
* unknown: [{node, steps, scope}]}
|
|
@@ -2910,6 +3343,19 @@ function assigned_values(binding, members = false)
|
|
|
2910
3343
|
walk(root, (n, ancestors) => {
|
|
2911
3344
|
let chain = [...ancestors, n];
|
|
2912
3345
|
let into = (node) => (members? steps_to(node, (id) => is_it(id, chain)) : null);
|
|
3346
|
+
/* `n` writes `target` with a value the reader does not read */
|
|
3347
|
+
let opaque_write = (target) => {
|
|
3348
|
+
if(target.type === "Identifier") {
|
|
3349
|
+
if(is_it(target, chain)) {
|
|
3350
|
+
unknown.push({node: n, steps: [], scope: chain});
|
|
3351
|
+
}
|
|
3352
|
+
} else if(target.type === "MemberExpression") {
|
|
3353
|
+
let steps = into(target);
|
|
3354
|
+
if(steps) {
|
|
3355
|
+
unknown.push({node: n, steps, scope: chain});
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
};
|
|
2913
3359
|
switch(n.type) {
|
|
2914
3360
|
case "VariableDeclarator":
|
|
2915
3361
|
if(binding.declarators.includes(n)) {
|
|
@@ -2935,9 +3381,11 @@ function assigned_values(binding, members = false)
|
|
|
2935
3381
|
} else if(steps) {
|
|
2936
3382
|
unknown.push({node: n, steps, scope: chain});
|
|
2937
3383
|
}
|
|
2938
|
-
} else
|
|
2939
|
-
|
|
2940
|
-
|
|
3384
|
+
} else {
|
|
3385
|
+
/* A destructuring assignment: `[k, x] = v`, `({k} = v)` */
|
|
3386
|
+
for(let target of write_targets(n.left)) {
|
|
3387
|
+
opaque_write(target);
|
|
3388
|
+
}
|
|
2941
3389
|
}
|
|
2942
3390
|
break;
|
|
2943
3391
|
}
|
|
@@ -2952,6 +3400,13 @@ function assigned_values(binding, members = false)
|
|
|
2952
3400
|
}
|
|
2953
3401
|
break;
|
|
2954
3402
|
case "CallExpression": {
|
|
3403
|
+
if(n.callee.type === "Identifier" && n.callee.name === "eval" && !n.optional) {
|
|
3404
|
+
/* Not run: a direct eval() of the SOURCE writes what its text says, which no
|
|
3405
|
+
* reader reads (in a module no other binding can be called `eval`); `eval?.()`
|
|
3406
|
+
* is an indirect one, which runs in the global scope */
|
|
3407
|
+
unknown.push({node: n, steps: [], scope: chain});
|
|
3408
|
+
break;
|
|
3409
|
+
}
|
|
2955
3410
|
if(!members) {
|
|
2956
3411
|
break;
|
|
2957
3412
|
}
|
|
@@ -2986,8 +3441,15 @@ function assigned_values(binding, members = false)
|
|
|
2986
3441
|
}
|
|
2987
3442
|
case "ForOfStatement":
|
|
2988
3443
|
case "ForInStatement":
|
|
2989
|
-
|
|
2990
|
-
|
|
3444
|
+
/* Each turn writes an element (a key) into the head */
|
|
3445
|
+
if(n.left.type === "VariableDeclaration") {
|
|
3446
|
+
if(n.left.declarations.some((d) => binding.declarators.includes(d))) {
|
|
3447
|
+
unknown.push({node: n, steps: [], scope: chain}); // `for(var k of v)`: the same var
|
|
3448
|
+
}
|
|
3449
|
+
} else {
|
|
3450
|
+
for(let target of write_targets(n.left)) {
|
|
3451
|
+
opaque_write(target);
|
|
3452
|
+
}
|
|
2991
3453
|
}
|
|
2992
3454
|
break;
|
|
2993
3455
|
default:
|
|
@@ -3026,6 +3488,7 @@ function var_leaves(root, seen = new Set(), depth = 0)
|
|
|
3026
3488
|
}
|
|
3027
3489
|
seen.add(id);
|
|
3028
3490
|
if(depth > MAX_DEPTH) {
|
|
3491
|
+
give_up(b.declarators[0], b.scope, GIVE_UP_DEEP);
|
|
3029
3492
|
out.complete = false;
|
|
3030
3493
|
out.unread.push(b.declarators[0]);
|
|
3031
3494
|
return out;
|
|
@@ -3093,12 +3556,15 @@ function var_leaves(root, seen = new Set(), depth = 0)
|
|
|
3093
3556
|
* var_root and no step) -- when every value it is given in its scope
|
|
3094
3557
|
* (assigned_values(): its value, every `=`, `||=`, `??=`, `&&=`) is,
|
|
3095
3558
|
* as WRITTEN, a string literal or nothing (literal_values()). Such a
|
|
3096
|
-
* variable can only ever hold those literals, so they
|
|
3097
|
-
* the place that reads it
|
|
3098
|
-
*
|
|
3099
|
-
*
|
|
3100
|
-
*
|
|
3101
|
-
*
|
|
3559
|
+
* variable can only ever hold those literals, so they are the keys of
|
|
3560
|
+
* the place that reads it -- ALL of them: the reading is
|
|
3561
|
+
* flow-insensitive, and a literal an `if` keeps from reaching the
|
|
3562
|
+
* place is asked for too (a sentinel that is no key is `null`). Given
|
|
3563
|
+
* anything else -- a property of a table (`SHORT_MONTHS[m]`), an
|
|
3564
|
+
* element, a call, a parameter, data --, or written in any way the
|
|
3565
|
+
* reader does not read (`+=`, a destructuring, a loop head, a direct
|
|
3566
|
+
* eval(): assigned_values() lists every write), it is not followed
|
|
3567
|
+
* and answers [] -- the invisible case, which fails nothing. (expand()
|
|
3102
3568
|
* and var_leaves() read a member of a table as ANY value of it: good
|
|
3103
3569
|
* enough for a marker, which names the lists to check against, and
|
|
3104
3570
|
* too much to ask the locales for.) One declared by a destructuring,
|
|
@@ -3173,7 +3639,11 @@ function let_literals(b, seen)
|
|
|
3173
3639
|
***************************************************************/
|
|
3174
3640
|
function literal_values(n, scope, seen, depth = 0)
|
|
3175
3641
|
{
|
|
3176
|
-
if(!n
|
|
3642
|
+
if(!n) {
|
|
3643
|
+
return null;
|
|
3644
|
+
}
|
|
3645
|
+
if(depth > MAX_DEPTH) {
|
|
3646
|
+
give_up(n, scope, GIVE_UP_DEEP);
|
|
3177
3647
|
return null;
|
|
3178
3648
|
}
|
|
3179
3649
|
let sub = (x, s = scope) => literal_values(x, s, seen, depth + 1);
|
|
@@ -3302,7 +3772,11 @@ function param_flows(node, scope, seen = new Set(), depth = 0)
|
|
|
3302
3772
|
{
|
|
3303
3773
|
/* Through a call or an iteration a path names no position any more */
|
|
3304
3774
|
let unnamed = (flows) => flows.map((f) => (f.path === null)? f : {binding: f.binding, path: null, priv: f.priv});
|
|
3305
|
-
if(!node || typeof node.type !== "string"
|
|
3775
|
+
if(!node || typeof node.type !== "string") {
|
|
3776
|
+
return [];
|
|
3777
|
+
}
|
|
3778
|
+
if(depth > MAX_DEPTH) {
|
|
3779
|
+
give_up(node, scope, GIVE_UP_DEEP);
|
|
3306
3780
|
return [];
|
|
3307
3781
|
}
|
|
3308
3782
|
let sub = (n, s = scope) => param_flows(n, s, seen, depth + 1);
|
|
@@ -3627,7 +4101,7 @@ function key_calls(ast, lib_module, table = I18N_KEY_FUNCTIONS)
|
|
|
3627
4101
|
return;
|
|
3628
4102
|
}
|
|
3629
4103
|
ancestors.push(n);
|
|
3630
|
-
let c = call_kind(n, ancestors, table);
|
|
4104
|
+
let c = call_kind(n, ancestors, table) || bind_kind(n, ancestors, table);
|
|
3631
4105
|
ancestors.pop();
|
|
3632
4106
|
if(c && c.kind === "key") {
|
|
3633
4107
|
out.push({entry: c.entry, call: n, scope: ancestors.slice(), args: c.args});
|
|
@@ -3746,12 +4220,15 @@ function call_rule_violations(ast, lib_module, table)
|
|
|
3746
4220
|
};
|
|
3747
4221
|
for(let {entry, call, scope, args} of key_calls(ast, lib_module, table)) {
|
|
3748
4222
|
for(let path of entry.keys) {
|
|
3749
|
-
check(values_at(call, path, scope, args), call, entry.name, path, null);
|
|
4223
|
+
check(values_at(call, path, scope, args, fallbacks_of(entry, path)), call, entry.name, path, null);
|
|
3750
4224
|
}
|
|
3751
4225
|
}
|
|
3752
4226
|
for(let {call, scope, callback} of translator_callbacks(ast, lib_module)) {
|
|
3753
4227
|
let arg = ast.code.slice(callback.arg.start, callback.arg.end);
|
|
3754
|
-
let shown = (callback.
|
|
4228
|
+
let shown = (callback.form === "from")? `${callback.method}(..., ${arg})` :
|
|
4229
|
+
(callback.form === "call")? `.${callback.method}.call(..., ${arg})` :
|
|
4230
|
+
(callback.form === "apply")? `.${callback.method}.apply(..., [${arg}])` :
|
|
4231
|
+
`.${callback.method}(${arg})`;
|
|
3755
4232
|
check(callback_leaves(call, callback, scope), call, "t", `${callback.method} callback`,
|
|
3756
4233
|
{how: callback.how, shown});
|
|
3757
4234
|
}
|
|
@@ -4037,7 +4514,11 @@ function list_mutations(ast, lists = [])
|
|
|
4037
4514
|
while(n && n.type === "ChainExpression") {
|
|
4038
4515
|
n = n.expression;
|
|
4039
4516
|
}
|
|
4040
|
-
if(!n
|
|
4517
|
+
if(!n) {
|
|
4518
|
+
return null;
|
|
4519
|
+
}
|
|
4520
|
+
if(depth > MAX_DEPTH) {
|
|
4521
|
+
give_up(n, chain, GIVE_UP_DEEP);
|
|
4041
4522
|
return null;
|
|
4042
4523
|
}
|
|
4043
4524
|
if(n.type === "MemberExpression") {
|
|
@@ -4128,6 +4609,21 @@ function list_mutations(ast, lists = [])
|
|
|
4128
4609
|
***************************/
|
|
4129
4610
|
|
|
4130
4611
|
|
|
4612
|
+
/***************************************************************
|
|
4613
|
+
* The modules of the library whose `code` properties are i18n keys:
|
|
4614
|
+
* the findings of the schema checks (schema_validate.js) and the
|
|
4615
|
+
* conflicts of an import (schema_import.js), which the schema editor
|
|
4616
|
+
* (c_yui_schema_editor.js, which also writes some) hands to
|
|
4617
|
+
* `t(finding.code)` / `t(conflict.code)`. Anywhere else a `code` is
|
|
4618
|
+
* whatever the code says -- a language (`{code: "en"}`), an error
|
|
4619
|
+
* number --, and no key: up to 7.26.42 every `code` of every file was
|
|
4620
|
+
* read as one, and so was any `add("error", x)`, a `classList.add()`
|
|
4621
|
+
* included. (The checks' own add() is a key function of the table.)
|
|
4622
|
+
* i18n_key_functions.test.js holds the list to the library: a module
|
|
4623
|
+
* that writes a literal `code` is in it, and only those.
|
|
4624
|
+
***************************************************************/
|
|
4625
|
+
const CODE_KEY_MODULES = new Set(["schema_validate.js", "schema_import.js", "c_yui_schema_editor.js"]);
|
|
4626
|
+
|
|
4131
4627
|
/***************************************************************
|
|
4132
4628
|
* Every place a parsed file READS a key, with the leaves of what
|
|
4133
4629
|
* stands there (leaves_of(), values_at()):
|
|
@@ -4140,13 +4636,13 @@ function list_mutations(ast, lists = [])
|
|
|
4140
4636
|
* tr(), `i18next.t()`, an alias, `t?.()`,
|
|
4141
4637
|
* `t.call(x, key)`); an array there is the list of
|
|
4142
4638
|
* keys i18next tries in turn, each one a key
|
|
4143
|
-
* "code" the code of a schema check, add("error", <code>)
|
|
4144
4639
|
* "attribute" setAttribute("data-i18n*", <key>) and
|
|
4145
4640
|
* setAttributeNS(ns, "data-i18n*", <key>), the name a
|
|
4146
4641
|
* literal or a const the reader follows to one
|
|
4147
|
-
* "property" an `i18n
|
|
4148
|
-
*
|
|
4149
|
-
*
|
|
4642
|
+
* "property" an `i18n` or `data-i18n*` property of an object
|
|
4643
|
+
* literal (`{[ATTR]: k}` with ATTR a const bound to
|
|
4644
|
+
* one), one of ctx.attr_keys, or a `code` in a module
|
|
4645
|
+
* of CODE_KEY_MODULES
|
|
4150
4646
|
* "array" an element of one of ctx.array_keys
|
|
4151
4647
|
* "assignment" `x.i18n = <key>`, `x["data-i18n-title"] = <key>`,
|
|
4152
4648
|
* `x[ATTR] = <key>`, `el.dataset.i18nTitle = <key>`
|
|
@@ -4193,12 +4689,13 @@ function key_places(ast, ctx = {})
|
|
|
4193
4689
|
return (s !== null)? [s] : static_keys(node, scope).keys;
|
|
4194
4690
|
};
|
|
4195
4691
|
let is_i18n_name = (name) => name === "i18n" || DATA_I18N_ATTR_RE.test(name);
|
|
4196
|
-
let
|
|
4692
|
+
let codes_are_keys = CODE_KEY_MODULES.has(ctx.lib_module);
|
|
4693
|
+
let is_property_key = (x) => is_i18n_name(x) || (x === "code" && codes_are_keys) || attr_keys.has(x);
|
|
4197
4694
|
walk(ast, (n, ancestors) => {
|
|
4198
4695
|
switch(n.type) {
|
|
4199
4696
|
case "CallExpression": {
|
|
4200
4697
|
ancestors.push(n);
|
|
4201
|
-
let c = call_kind(n, ancestors, table);
|
|
4698
|
+
let c = call_kind(n, ancestors, table) || bind_kind(n, ancestors, table);
|
|
4202
4699
|
ancestors.pop();
|
|
4203
4700
|
if(c && c.kind === "key") {
|
|
4204
4701
|
/* A key function (a `tr` of the library too): read where its table says */
|
|
@@ -4210,9 +4707,6 @@ function key_places(ast, ctx = {})
|
|
|
4210
4707
|
let name = callee_name(n.callee);
|
|
4211
4708
|
if(c && c.kind === "t") {
|
|
4212
4709
|
read_t(c.args? c.args[0] : null, [...ancestors, n], n);
|
|
4213
|
-
} else if(name === "add" && is_string_literal(n.arguments[0], /^(error|warning)$/)) {
|
|
4214
|
-
/* The codes the schema checks hand to `t(finding.code)` */
|
|
4215
|
-
read("code", n.arguments[1], [...ancestors, n], n);
|
|
4216
4710
|
} else if((name === "setAttribute" && n.arguments.length >= 2)
|
|
4217
4711
|
|| (name === "setAttributeNS" && n.arguments.length >= 3)) {
|
|
4218
4712
|
/* setAttributeNS(ns, name, value): the same, one argument on */
|
|
@@ -4290,7 +4784,8 @@ function key_places(ast, ctx = {})
|
|
|
4290
4784
|
}
|
|
4291
4785
|
for(let {entry, call, scope, args} of calls) {
|
|
4292
4786
|
for(let path of entry.keys) {
|
|
4293
|
-
out.push({what: "call", node: call, entry, path,
|
|
4787
|
+
out.push({what: "call", node: call, entry, path,
|
|
4788
|
+
leaves: values_at(call, path, scope, args, fallbacks_of(entry, path))});
|
|
4294
4789
|
}
|
|
4295
4790
|
}
|
|
4296
4791
|
for(let {call, scope, callback} of callbacks) {
|
|
@@ -4334,11 +4829,11 @@ function translator_callbacks(ast, lib_module = null)
|
|
|
4334
4829
|
function may_take_a_callback(n)
|
|
4335
4830
|
{
|
|
4336
4831
|
let c = (n.callee.type === "ChainExpression")? n.callee.expression : n.callee;
|
|
4337
|
-
if(c.type !== "MemberExpression" ||
|
|
4832
|
+
if(c.type !== "MemberExpression" || n.arguments.length === 0) {
|
|
4338
4833
|
return false;
|
|
4339
4834
|
}
|
|
4340
|
-
let m = c.
|
|
4341
|
-
return ITERATION_METHODS.has(m) || SETTLE_METHODS.has(m) || m === "
|
|
4835
|
+
let m = member_step(c).prop;
|
|
4836
|
+
return ITERATION_METHODS.has(m) || SETTLE_METHODS.has(m) || ARRAY_BUILDERS.has(m) || m === "call" || m === "apply";
|
|
4342
4837
|
}
|
|
4343
4838
|
|
|
4344
4839
|
/***************************************************************
|
|
@@ -4387,7 +4882,8 @@ function key_list_leaves(node, scope, root)
|
|
|
4387
4882
|
* lists: [{name, keys}], list_errors: [why],
|
|
4388
4883
|
* list_mutations: [{line, why}] (list_mutations()),
|
|
4389
4884
|
* marker_refs: [{lists, keys, line, shapes}],
|
|
4390
|
-
* marker_errors: [{line, why}]
|
|
4885
|
+
* marker_errors: [{line, why}],
|
|
4886
|
+
* translated_errors: [{line, why}]}
|
|
4391
4887
|
*
|
|
4392
4888
|
* Every place a key is read (key_places()) goes through leaves_of(),
|
|
4393
4889
|
* so a marker standing there is found: one that marks no such place,
|
|
@@ -4401,12 +4897,28 @@ function key_list_leaves(node, scope, root)
|
|
|
4401
4897
|
* string literals. Under a LIST marker those keys are asked for and
|
|
4402
4898
|
* must be in the lists, and a template with `${}` must have the
|
|
4403
4899
|
* shape of a key of them (`shapes`, checked where the lists are
|
|
4404
|
-
* known: shape_owner_check()).
|
|
4405
|
-
*
|
|
4406
|
-
*
|
|
4407
|
-
*
|
|
4408
|
-
*
|
|
4900
|
+
* known: shape_owner_check()).
|
|
4901
|
+
*
|
|
4902
|
+
* A TRANSLATED text (is_translation()) where a key is read -- given
|
|
4903
|
+
* to t(), to an `i18n` / `data-i18n*` value (a `code` where it is a
|
|
4904
|
+
* key), to a data-i18n* attribute -- is an error, MARKED OR NOT
|
|
4905
|
+
* (`translated_errors`): the place keeps the translation as its key,
|
|
4906
|
+
* and it never changes language. Up to 7.26.41 only a marked one
|
|
4907
|
+
* failed, so `{i18n: t("k")}` passed and `{i18n: /\* i18n: data *\/
|
|
4908
|
+
* t("k")}` did not. At a key position of a key function and at a
|
|
4909
|
+
* translator handed as a callback the rule per call says it
|
|
4910
|
+
* (call_rule_violations()).
|
|
4409
4911
|
***************************************************************/
|
|
4912
|
+
|
|
4913
|
+
/* Where key_places() reads a key, as a message says it */
|
|
4914
|
+
const PLACE_NAMES = {
|
|
4915
|
+
t: "handed to a translator as its key",
|
|
4916
|
+
attribute: "given to a data-i18n* attribute",
|
|
4917
|
+
property: "given to a property that holds a key (i18n, code, data-i18n*)",
|
|
4918
|
+
array: "given as an element of a list of keys",
|
|
4919
|
+
assignment: "written to a property that holds a key (i18n, data-i18n*)"
|
|
4920
|
+
};
|
|
4921
|
+
|
|
4410
4922
|
function scan_ast(ast, ctx)
|
|
4411
4923
|
{
|
|
4412
4924
|
program_url(ast, ctx.lib_module || null);
|
|
@@ -4496,12 +5008,14 @@ function scan_ast(ast, ctx)
|
|
|
4496
5008
|
}
|
|
4497
5009
|
};
|
|
4498
5010
|
|
|
4499
|
-
/* `what`: the kind of place (key_places()). At a key position of
|
|
4500
|
-
* function and at a translator handed as a callback, a
|
|
4501
|
-
* text is the rule's (call_rule_violations()); anywhere
|
|
4502
|
-
*
|
|
4503
|
-
let
|
|
4504
|
-
|
|
5011
|
+
/* `place.what`: the kind of place (key_places()). At a key position of
|
|
5012
|
+
* a key function and at a translator handed as a callback, a
|
|
5013
|
+
* TRANSLATED text is the rule's (call_rule_violations()); anywhere
|
|
5014
|
+
* else it is said here, marked or not (`translated`). */
|
|
5015
|
+
let translated = []; // [{what, place, leaf, marker}]
|
|
5016
|
+
let take = (place) => {
|
|
5017
|
+
let what = place.what;
|
|
5018
|
+
for(let leaf of place.leaves) {
|
|
4505
5019
|
if(leaf.kind === "key") {
|
|
4506
5020
|
keys.add(leaf.value);
|
|
4507
5021
|
}
|
|
@@ -4513,7 +5027,6 @@ function scan_ast(ast, ctx)
|
|
|
4513
5027
|
m.leaves = [];
|
|
4514
5028
|
m.hidden = [];
|
|
4515
5029
|
m.shapes = [];
|
|
4516
|
-
m.translated = [];
|
|
4517
5030
|
}
|
|
4518
5031
|
m.leaves.push(leaf);
|
|
4519
5032
|
if(leaf.kind === "key") {
|
|
@@ -4523,15 +5036,15 @@ function scan_ast(ast, ctx)
|
|
|
4523
5036
|
check_marked_var(leaf, m);
|
|
4524
5037
|
}
|
|
4525
5038
|
answer(leaf, m);
|
|
4526
|
-
if(what !== "call" && what !== "callback" && is_translation(leaf)) {
|
|
4527
|
-
m.translated.push(leaf);
|
|
4528
|
-
}
|
|
4529
5039
|
} else if(what !== "call" && what !== "callback") {
|
|
4530
5040
|
/* An unmarked `let` that can only hold literals holds keys */
|
|
4531
5041
|
for(let k of literal_let_keys(leaf)) {
|
|
4532
5042
|
keys.add(k);
|
|
4533
5043
|
}
|
|
4534
5044
|
}
|
|
5045
|
+
if(what !== "call" && what !== "callback" && is_translation(leaf)) {
|
|
5046
|
+
translated.push({what, place: place.node, leaf, marker: m});
|
|
5047
|
+
}
|
|
4535
5048
|
}
|
|
4536
5049
|
};
|
|
4537
5050
|
let add_markup = (text) => {
|
|
@@ -4548,7 +5061,7 @@ function scan_ast(ast, ctx)
|
|
|
4548
5061
|
};
|
|
4549
5062
|
|
|
4550
5063
|
for(let place of key_places(ast, ctx)) {
|
|
4551
|
-
take(place
|
|
5064
|
+
take(place);
|
|
4552
5065
|
}
|
|
4553
5066
|
walk(ast, (n) => {
|
|
4554
5067
|
if(n.type === "Property") {
|
|
@@ -4580,21 +5093,6 @@ function scan_ast(ast, ctx)
|
|
|
4580
5093
|
marker_errors.push({line: m.line, why: marker_misplaced(ast, m)});
|
|
4581
5094
|
continue;
|
|
4582
5095
|
}
|
|
4583
|
-
let seen_translated = new Set();
|
|
4584
|
-
for(let leaf of m.translated) {
|
|
4585
|
-
if(seen_translated.has(leaf.node)) {
|
|
4586
|
-
continue;
|
|
4587
|
-
}
|
|
4588
|
-
seen_translated.add(leaf.node);
|
|
4589
|
-
/* A const imported from another file: its text is that file's */
|
|
4590
|
-
let program = (leaf.scope && leaf.scope.length > 0 && typeof leaf.scope[0].code === "string")?
|
|
4591
|
-
leaf.scope[0] : ast;
|
|
4592
|
-
let text = program.code.slice(leaf.node.start, leaf.node.end).replace(/\s+/g, " ").slice(0, 80);
|
|
4593
|
-
marker_errors.push({line: m.line, why: `marked as ` +
|
|
4594
|
-
`${m.kind === "data"? "data" : "keys of " + m.lists.join(", ")}, but \`${text}\` ` +
|
|
4595
|
-
`is a TRANSLATED text: where a key is read, the translation is kept as its key and never ` +
|
|
4596
|
-
`changes language, and no marker excuses it: hand the key, not t(key)`});
|
|
4597
|
-
}
|
|
4598
5096
|
if(m.kind === "lists") {
|
|
4599
5097
|
marker_refs.push({lists: m.lists, keys: [...m.keys], line: m.line, shapes: m.shapes});
|
|
4600
5098
|
continue;
|
|
@@ -4619,6 +5117,30 @@ function scan_ast(ast, ctx)
|
|
|
4619
5117
|
}
|
|
4620
5118
|
}
|
|
4621
5119
|
|
|
5120
|
+
/* A TRANSLATED text where a key is read: marked (at the marker's line) or not */
|
|
5121
|
+
let translated_errors = [];
|
|
5122
|
+
let said = new Set();
|
|
5123
|
+
for(let {what, place, leaf, marker} of translated) {
|
|
5124
|
+
/* A const imported from another file: its text is that file's, and the
|
|
5125
|
+
* line said is the place's, here */
|
|
5126
|
+
let program = (leaf.scope && leaf.scope.length > 0 && typeof leaf.scope[0].code === "string")?
|
|
5127
|
+
leaf.scope[0] : ast;
|
|
5128
|
+
let text = program.code.slice(leaf.node.start, leaf.node.end).replace(/\s+/g, " ").slice(0, 80);
|
|
5129
|
+
let place_line = line_of(ast, place.start);
|
|
5130
|
+
let line = marker? marker.line : (program === ast)? line_of(ast, leaf.node.start) : place_line;
|
|
5131
|
+
let read_at = (line !== place_line)? ` (read at line ${place_line})` : "";
|
|
5132
|
+
let why = marker?
|
|
5133
|
+
`marked as ${marker.kind === "data"? "data" : "keys of " + marker.lists.join(", ")}, but ` +
|
|
5134
|
+
`\`${text}\` is a TRANSLATED text: where a key is read, the translation is kept as its key ` +
|
|
5135
|
+
`and never changes language, and no marker excuses it: hand the key, not t(key)` :
|
|
5136
|
+
`\`${text}\` is a TRANSLATED text ${PLACE_NAMES[what] || "where a key is read"}${read_at}: the ` +
|
|
5137
|
+
`translation is kept as its key and never changes language: hand the key, not t(key)`;
|
|
5138
|
+
if(!said.has(`${line} ${why}`)) {
|
|
5139
|
+
said.add(`${line} ${why}`);
|
|
5140
|
+
translated_errors.push({line, why});
|
|
5141
|
+
}
|
|
5142
|
+
}
|
|
5143
|
+
|
|
4622
5144
|
return {
|
|
4623
5145
|
keys,
|
|
4624
5146
|
read_keys,
|
|
@@ -4627,7 +5149,8 @@ function scan_ast(ast, ctx)
|
|
|
4627
5149
|
list_errors: published.errors,
|
|
4628
5150
|
list_mutations: list_mutations(ast, published.lists),
|
|
4629
5151
|
marker_refs,
|
|
4630
|
-
marker_errors
|
|
5152
|
+
marker_errors,
|
|
5153
|
+
translated_errors
|
|
4631
5154
|
};
|
|
4632
5155
|
}
|
|
4633
5156
|
|
|
@@ -4714,6 +5237,7 @@ function shape_owner_check(shape, keys, shapes)
|
|
|
4714
5237
|
***************************************************************/
|
|
4715
5238
|
function collect_used_keys(opts)
|
|
4716
5239
|
{
|
|
5240
|
+
GAVE_UP.clear();
|
|
4717
5241
|
let keys = new Set();
|
|
4718
5242
|
let lib_keys = new Set();
|
|
4719
5243
|
let attr_keys = opts.attr_keys || [];
|
|
@@ -4767,7 +5291,7 @@ function collect_used_keys(opts)
|
|
|
4767
5291
|
published.get(list.name).add(k);
|
|
4768
5292
|
}
|
|
4769
5293
|
}
|
|
4770
|
-
for(let e of r.marker_errors) {
|
|
5294
|
+
for(let e of [...r.marker_errors, ...r.translated_errors]) {
|
|
4771
5295
|
fail(`${label}:${e.line}: ${e.why}`);
|
|
4772
5296
|
}
|
|
4773
5297
|
for(let ref of r.marker_refs) {
|
|
@@ -4872,6 +5396,14 @@ function collect_used_keys(opts)
|
|
|
4872
5396
|
}
|
|
4873
5397
|
}
|
|
4874
5398
|
|
|
5399
|
+
/* Where the reader gave up: a key behind it would go unasked */
|
|
5400
|
+
for(let g of gave_up()) {
|
|
5401
|
+
let module = lib_module_of(g.url);
|
|
5402
|
+
let label = module? `gobj-ui/src/${module}` : g.url? relative(process.cwd(), fileURLToPath(g.url)) : "?";
|
|
5403
|
+
fail(`${label}:${g.line}: the reader gave up on \`${g.text}\`, and a key behind it would go ` +
|
|
5404
|
+
`unasked: ${g.why}`);
|
|
5405
|
+
}
|
|
5406
|
+
|
|
4875
5407
|
return {keys, lib_keys};
|
|
4876
5408
|
}
|
|
4877
5409
|
|
|
@@ -4922,7 +5454,10 @@ function source_files(dir, locales_dir)
|
|
|
4922
5454
|
* a key -- "configuración" is a Spanish literal that forgot its key,
|
|
4923
5455
|
* and it is reported, as an ASCII one would be. `wordmark` and `alt` are
|
|
4924
5456
|
* deliberately out: a brand name is not translated. A key starting with
|
|
4925
|
-
* `_` is a comment.
|
|
5457
|
+
* `_` is a comment. And the `id` of a menu or a toolbar item with no
|
|
5458
|
+
* `name`, and of a C_YUI_NODE node with no `label`, is a key where the
|
|
5459
|
+
* library names it by it (menu_item_keys(), toolbar_item_keys(),
|
|
5460
|
+
* node_tree_keys()).
|
|
4926
5461
|
***************************************************************/
|
|
4927
5462
|
const CONFIG_I18N_FIELDS = ["name", "aria_label", "tooltip", "label", "title", "subtitle"];
|
|
4928
5463
|
|
|
@@ -4959,6 +5494,263 @@ function keys_from_shell_config(url, keys, is_key)
|
|
|
4959
5494
|
}
|
|
4960
5495
|
};
|
|
4961
5496
|
walk_config(config);
|
|
5497
|
+
menu_item_keys(config, keys, is_key);
|
|
5498
|
+
toolbar_item_keys(config, keys, is_key);
|
|
5499
|
+
node_tree_keys(config, keys, is_key);
|
|
5500
|
+
}
|
|
5501
|
+
|
|
5502
|
+
/***************************************************************
|
|
5503
|
+
* The `id` of a NODE of a C_YUI_NODE tree with no `label`: the library
|
|
5504
|
+
* names a node `label || id`, and that name is an i18n KEY -- the item
|
|
5505
|
+
* of the parent's navs (child_nav_items(), node_tree_model.js, after
|
|
5506
|
+
* normalize_spec() gave a child with no label its id as one), the
|
|
5507
|
+
* label of the node's own navs and its crumb in a path (c_yui_node.js,
|
|
5508
|
+
* translated with the shell's translator), its node in the site map.
|
|
5509
|
+
* Up to gobj-ui 7.26.41 the validator read a node's `label` and not
|
|
5510
|
+
* the id that stands in for a missing one.
|
|
5511
|
+
*
|
|
5512
|
+
* A tree is declared as `{"gclass": "C_YUI_NODE", "kw": {...}}`
|
|
5513
|
+
* wherever the shell declaration holds one (a menu item's `target`, a
|
|
5514
|
+
* route's): its root is the `kw` (its id is `node_id`), the nodes
|
|
5515
|
+
* below it the specs of `children` (`id`), down the whole tree. A
|
|
5516
|
+
* root names itself only on its navs and in a path: one with no
|
|
5517
|
+
* children and no path draws no label. A spec the library refuses --
|
|
5518
|
+
* no `id`, an id with a "/" -- is drawn by nothing.
|
|
5519
|
+
***************************************************************/
|
|
5520
|
+
function node_tree_keys(config, keys, is_key)
|
|
5521
|
+
{
|
|
5522
|
+
let ask = (v) => {
|
|
5523
|
+
if(typeof v === "string" && v && is_key(v)) {
|
|
5524
|
+
keys.add(v);
|
|
5525
|
+
}
|
|
5526
|
+
};
|
|
5527
|
+
/* normalize_spec()'s own test: a label is a non-empty string */
|
|
5528
|
+
let labelled = (spec) => typeof spec.label === "string" && spec.label !== "";
|
|
5529
|
+
let read_children = (children) => {
|
|
5530
|
+
for(let spec of (Array.isArray(children)? children : [])) {
|
|
5531
|
+
if(!spec || typeof spec !== "object" || Array.isArray(spec)
|
|
5532
|
+
|| typeof spec.id !== "string" || !spec.id || spec.id.includes("/")) {
|
|
5533
|
+
continue;
|
|
5534
|
+
}
|
|
5535
|
+
if(!labelled(spec)) {
|
|
5536
|
+
ask(spec.id);
|
|
5537
|
+
}
|
|
5538
|
+
read_children(spec.children);
|
|
5539
|
+
}
|
|
5540
|
+
};
|
|
5541
|
+
let walk = (n) => {
|
|
5542
|
+
if(Array.isArray(n)) {
|
|
5543
|
+
for(let x of n) {
|
|
5544
|
+
walk(x);
|
|
5545
|
+
}
|
|
5546
|
+
return;
|
|
5547
|
+
}
|
|
5548
|
+
if(!n || typeof n !== "object") {
|
|
5549
|
+
return;
|
|
5550
|
+
}
|
|
5551
|
+
if(n.gclass === "C_YUI_NODE" && n.kw && typeof n.kw === "object" && !Array.isArray(n.kw)) {
|
|
5552
|
+
let kw = n.kw;
|
|
5553
|
+
let draws = (Array.isArray(kw.children) && kw.children.length > 0) || kw.nav_mode === "path"
|
|
5554
|
+
|| !!(kw.projection && typeof kw.projection === "object" && kw.projection.path);
|
|
5555
|
+
if(draws && !labelled(kw)) {
|
|
5556
|
+
ask(kw.node_id);
|
|
5557
|
+
}
|
|
5558
|
+
read_children(kw.children);
|
|
5559
|
+
}
|
|
5560
|
+
for(let [k, v] of Object.entries(n)) {
|
|
5561
|
+
if(!k.startsWith("_")) {
|
|
5562
|
+
walk(v);
|
|
5563
|
+
}
|
|
5564
|
+
}
|
|
5565
|
+
};
|
|
5566
|
+
walk(config);
|
|
5567
|
+
}
|
|
5568
|
+
|
|
5569
|
+
/***************************************************************
|
|
5570
|
+
* The `id` of a MENU item that the library names the item by, as a
|
|
5571
|
+
* key, when the item has no `name` -- mirrored from C_YUI_NAV and the
|
|
5572
|
+
* shell, so a key they translate is a key asked for (up to gobj-ui
|
|
5573
|
+
* 7.26.41 such an item was named by its raw id, with no key):
|
|
5574
|
+
*
|
|
5575
|
+
* - when it has neither a `name` nor an `aria_label`: the name of
|
|
5576
|
+
* the item in every layout -- a tab, an entry of a vertical menu,
|
|
5577
|
+
* a submenu or an icon bar, a card, an accordion head, a crumb
|
|
5578
|
+
* (`name || aria_label || id`: c_yui_nav.js, nav_cards_helpers.js)
|
|
5579
|
+
* -- and its title too, when it has no `tooltip`; the navs its
|
|
5580
|
+
* submenu opens, and the landing of a SECTION INDEX it opens
|
|
5581
|
+
* (`submenu.index`), are labelled the same way (c_yui_shell.js,
|
|
5582
|
+
* shell_section_index.js), so they ask for nothing more;
|
|
5583
|
+
* - when it has no `name`, in a menu drawn as a BREADCRUMB that shows
|
|
5584
|
+
* its labels: the text of the crumb is `name || id`.
|
|
5585
|
+
*
|
|
5586
|
+
* And the id of a MENU (`menu.<id>`) drawn as a "submenu" in a zone
|
|
5587
|
+
* that hosts it: that layout heads the nav with its `nav_label`, and
|
|
5588
|
+
* the shell gives a menu none, so the heading is the menu's id, as a
|
|
5589
|
+
* key (render_submenu(), c_yui_nav.js). Up to gobj-ui 7.26.42 the
|
|
5590
|
+
* validator did not ask for it.
|
|
5591
|
+
*
|
|
5592
|
+
* The items are those of every menu (`menu.<id>.items`) and of every
|
|
5593
|
+
* submenu of them (`submenu.items`) -- and the rows of the dropdown
|
|
5594
|
+
* action of an entry with no submenu, which the site map draws and
|
|
5595
|
+
* labels as an entry (`name || aria_label || id`, route_map_model.js)
|
|
5596
|
+
* --; a decorative one (`type` "header" or "divider") is named by
|
|
5597
|
+
* nothing of this. A `name`, an `aria_label` or a `tooltip` is read
|
|
5598
|
+
* wherever it stands, above.
|
|
5599
|
+
***************************************************************/
|
|
5600
|
+
function menu_item_keys(config, keys, is_key)
|
|
5601
|
+
{
|
|
5602
|
+
let menus = (config && config.menu && typeof config.menu === "object")? config.menu : {};
|
|
5603
|
+
let zones = (config && config.shell && config.shell.zones && typeof config.shell.zones === "object")?
|
|
5604
|
+
config.shell.zones : {};
|
|
5605
|
+
let ask = (v) => {
|
|
5606
|
+
if(typeof v === "string" && v && is_key(v)) {
|
|
5607
|
+
keys.add(v);
|
|
5608
|
+
}
|
|
5609
|
+
};
|
|
5610
|
+
/* Does a render (`"tabs"` or `{layout, show_label}`) draw a
|
|
5611
|
+
* breadcrumb that shows the labels? */
|
|
5612
|
+
let draws_crumbs = (r) => {
|
|
5613
|
+
let cfg = (typeof r === "string")? {layout: r} : r;
|
|
5614
|
+
return !!cfg && typeof cfg === "object" && cfg.layout === "breadcrumb" && cfg.show_label !== false;
|
|
5615
|
+
};
|
|
5616
|
+
let layout_of = (r) => (typeof r === "string")? r : (r && typeof r === "object")? r.layout : null;
|
|
5617
|
+
let read_items = (items, crumbs) => {
|
|
5618
|
+
for(let it of (Array.isArray(items)? items : [])) {
|
|
5619
|
+
if(!it || typeof it !== "object" || it.type === "header" || it.type === "divider") {
|
|
5620
|
+
continue;
|
|
5621
|
+
}
|
|
5622
|
+
/* The library's own test: `it.name || it.aria_label || it.id` */
|
|
5623
|
+
if(!it.name && (!it.aria_label || crumbs)) {
|
|
5624
|
+
ask(it.id);
|
|
5625
|
+
}
|
|
5626
|
+
let sub = it.submenu;
|
|
5627
|
+
if(!sub || typeof sub !== "object" || !Array.isArray(sub.items)) {
|
|
5628
|
+
/* The site map draws the rows of a dropdown action too, named
|
|
5629
|
+
* as an entry is (route_map_model.js, nav_node_from_item()) */
|
|
5630
|
+
let a = it.action;
|
|
5631
|
+
if(a && typeof a === "object" && a.type === "dropdown") {
|
|
5632
|
+
read_items(a.items, false);
|
|
5633
|
+
}
|
|
5634
|
+
continue;
|
|
5635
|
+
}
|
|
5636
|
+
/* A submenu is drawn in each zone its `render` names ("*" is no
|
|
5637
|
+
* zone for it) */
|
|
5638
|
+
let render = (sub.render && typeof sub.render === "object")? sub.render : {};
|
|
5639
|
+
read_items(sub.items, Object.keys(render).some((z) => z !== "*" && draws_crumbs(render[z])));
|
|
5640
|
+
}
|
|
5641
|
+
};
|
|
5642
|
+
for(let menu_id of Object.keys(menus)) {
|
|
5643
|
+
let menu = menus[menu_id];
|
|
5644
|
+
if(!menu || typeof menu !== "object") {
|
|
5645
|
+
continue;
|
|
5646
|
+
}
|
|
5647
|
+
/* A menu is drawn in each zone that hosts it, with that zone's
|
|
5648
|
+
* render, else the render "*", else a vertical menu */
|
|
5649
|
+
let render = (menu.render && typeof menu.render === "object")? menu.render : {};
|
|
5650
|
+
let hosts = Object.keys(zones).filter((z) => zones[z] && zones[z].host === `menu.${menu_id}`);
|
|
5651
|
+
if(hosts.some((z) => layout_of(render[z] || render["*"]) === "submenu")) {
|
|
5652
|
+
ask(menu_id);
|
|
5653
|
+
}
|
|
5654
|
+
read_items(menu.items, hosts.some((z) => draws_crumbs(render[z] || render["*"])));
|
|
5655
|
+
}
|
|
5656
|
+
}
|
|
5657
|
+
|
|
5658
|
+
/***************************************************************
|
|
5659
|
+
* The `id` of a TOOLBAR item that the shell names the item by, as a
|
|
5660
|
+
* key, when the item has neither an `aria_label` nor a `name`
|
|
5661
|
+
* (`aria_label || name || id`, build_toolbar_*() of c_yui_shell.js;
|
|
5662
|
+
* up to gobj-ui 7.26.41 such an item was named by its raw id, with no
|
|
5663
|
+
* key) -- mirrored from the shell:
|
|
5664
|
+
*
|
|
5665
|
+
* - an action item (any `type` but "brand", "avatar", "connection");
|
|
5666
|
+
* - the menu a dropdown opens (`action.type` "dropdown"), named as
|
|
5667
|
+
* its trigger, except an avatar's, which the shell names "user
|
|
5668
|
+
* menu" -- and the one a RIGHT-click opens (`context_action`, which
|
|
5669
|
+
* the shell wires on an action item and on a connection), named
|
|
5670
|
+
* the same way (up to gobj-ui 7.26.42 the shell named it by the
|
|
5671
|
+
* raw id, and the validator did not read it);
|
|
5672
|
+
* - each entry of that menu (`action.items`) that is drawn: not a
|
|
5673
|
+
* divider, and with an `action` of its own;
|
|
5674
|
+
* - each row the SITE MAP draws under a toolbar node that is not the
|
|
5675
|
+
* brand -- its `submenu.items`, else the `items` of its dropdown
|
|
5676
|
+
* action, down every level, an entry with no `action` included --,
|
|
5677
|
+
* labelled as the toolbar names a control: `aria_label || name ||
|
|
5678
|
+
* id`, but "user menu" for a row typed "avatar" and "backend
|
|
5679
|
+
* connection" for one typed "connection" (route_map_model.js,
|
|
5680
|
+
* toolbar_item_label()).
|
|
5681
|
+
*
|
|
5682
|
+
* A brand is named by its `wordmark`, which it must have to be drawn;
|
|
5683
|
+
* an avatar and a connection button by the shell's own "user menu" and
|
|
5684
|
+
* "backend connection". A `name` or an `aria_label` is read wherever it
|
|
5685
|
+
* stands (keys_from_shell_config()).
|
|
5686
|
+
***************************************************************/
|
|
5687
|
+
function toolbar_item_keys(config, keys, is_key)
|
|
5688
|
+
{
|
|
5689
|
+
let tb = config && config.toolbar;
|
|
5690
|
+
let items = (tb && typeof tb === "object" && Array.isArray(tb.items))? tb.items : [];
|
|
5691
|
+
let ask = (v) => {
|
|
5692
|
+
if(typeof v === "string" && v && is_key(v)) {
|
|
5693
|
+
keys.add(v);
|
|
5694
|
+
}
|
|
5695
|
+
};
|
|
5696
|
+
let nameless = (it) => !it.aria_label && !it.name;
|
|
5697
|
+
/* The rows the site map walks under a node: its `submenu.items`, else
|
|
5698
|
+
* the `items` of a dropdown action (nav_node_from_item()) */
|
|
5699
|
+
let map_rows = (it) => {
|
|
5700
|
+
if(it.submenu && Array.isArray(it.submenu.items)) {
|
|
5701
|
+
return it.submenu.items;
|
|
5702
|
+
}
|
|
5703
|
+
let a = it.action;
|
|
5704
|
+
return (a && typeof a === "object" && a.type === "dropdown" && Array.isArray(a.items))? a.items : [];
|
|
5705
|
+
};
|
|
5706
|
+
let read_map_rows = (rows) => {
|
|
5707
|
+
for(let sub of rows) {
|
|
5708
|
+
if(!sub || typeof sub !== "object" || sub.type === "divider" || sub.type === "header") {
|
|
5709
|
+
continue;
|
|
5710
|
+
}
|
|
5711
|
+
if(nameless(sub) && sub.type !== "avatar" && sub.type !== "connection") {
|
|
5712
|
+
ask(sub.id);
|
|
5713
|
+
}
|
|
5714
|
+
read_map_rows(map_rows(sub));
|
|
5715
|
+
}
|
|
5716
|
+
};
|
|
5717
|
+
for(let it of items) {
|
|
5718
|
+
if(!it || typeof it !== "object") {
|
|
5719
|
+
continue;
|
|
5720
|
+
}
|
|
5721
|
+
let kind = (it.type === "brand" || it.type === "avatar" || it.type === "connection")? it.type : "action";
|
|
5722
|
+
if(kind === "action" && nameless(it)) {
|
|
5723
|
+
ask(it.id);
|
|
5724
|
+
}
|
|
5725
|
+
/* The menu a click opens, and the one a right-click opens: the
|
|
5726
|
+
* shell wires `context_action` on an action item and a connection */
|
|
5727
|
+
let actions = [it.action];
|
|
5728
|
+
if(kind === "action" || kind === "connection") {
|
|
5729
|
+
actions.push(it.context_action);
|
|
5730
|
+
}
|
|
5731
|
+
for(let action of actions) {
|
|
5732
|
+
if(!action || typeof action !== "object" || action.type !== "dropdown") {
|
|
5733
|
+
continue;
|
|
5734
|
+
}
|
|
5735
|
+
if(kind !== "avatar" && nameless(it)) {
|
|
5736
|
+
ask(it.id);
|
|
5737
|
+
}
|
|
5738
|
+
for(let sub of (Array.isArray(action.items)? action.items : [])) {
|
|
5739
|
+
if(!sub || typeof sub !== "object" || sub.type === "divider"
|
|
5740
|
+
|| !sub.action || typeof sub.action !== "object") {
|
|
5741
|
+
continue;
|
|
5742
|
+
}
|
|
5743
|
+
if(nameless(sub)) {
|
|
5744
|
+
ask(sub.id);
|
|
5745
|
+
}
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5748
|
+
/* The brand is the ROOT of the site map, named by its wordmark: no
|
|
5749
|
+
* node of its own, and no rows under it */
|
|
5750
|
+
if(kind !== "brand") {
|
|
5751
|
+
read_map_rows(map_rows(it));
|
|
5752
|
+
}
|
|
5753
|
+
}
|
|
4962
5754
|
}
|
|
4963
5755
|
|
|
4964
5756
|
/***************************************************************
|
|
@@ -5066,6 +5858,8 @@ function lib_imports(ast, barrel, lib_module)
|
|
|
5066
5858
|
/* The readers, for a test of the library and for an app whose catalog
|
|
5067
5859
|
* has another shape (gobj-ui's test-app) */
|
|
5068
5860
|
export {
|
|
5861
|
+
CODE_KEY_MODULES,
|
|
5862
|
+
gave_up,
|
|
5069
5863
|
parse_source,
|
|
5070
5864
|
walk,
|
|
5071
5865
|
line_of,
|