@yuneta/gobj-ui 7.26.41 → 7.26.42
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 +304 -63
- package/dist/gobj-ui.cjs.js +352 -135
- package/dist/gobj-ui.es.js +352 -135
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +644 -142
- package/src/c_g6_nodes_tree.js +3 -2
- 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_schema_editor.css +16 -0
- package/src/c_yui_schema_editor.js +61 -17
- package/src/c_yui_shell.js +199 -59
- package/src/c_yui_treedb_schema.js +3 -2
- package/src/c_yui_window_manager.js +6 -6
- 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/i18n_key_functions.js +41 -25
- package/src/i18n_key_functions.test.js +178 -2
- package/src/modal_guard_back.wiring.test.js +135 -0
- package/src/named_controls.wiring.test.js +270 -6
- package/src/nav_cards_helpers.js +9 -4
- package/src/nav_item_badge.wiring.test.js +163 -15
- package/src/route_map_model.js +59 -10
- package/src/route_map_model.test.js +90 -0
- package/src/schema_editor_openers.wiring.test.js +283 -0
- package/src/shell_modals.js +24 -4
- package/src/shell_route_map.js +15 -3
- package/src/shell_section_index.js +3 -1
- package/src/window_layer.wiring.test.js +114 -0
- package/src/yui_gclass_view.js +16 -1
|
@@ -62,10 +62,18 @@
|
|
|
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
|
+
* makes a translator whose calls hand i18next its options or
|
|
68
|
+
* its default value, not a key: what they hand is not read;
|
|
69
|
+
* - each element a translator handed as a CALLBACK walks, and
|
|
70
|
+
* only these: `.map`, `.flatMap`, `.forEach`, `.filter`,
|
|
71
|
+
* `.find`, `.findIndex`, `.findLast`, `.findLastIndex`,
|
|
72
|
+
* `.some`, `.every` -- called on the array (`keys.map(t)`,
|
|
73
|
+
* `keys["map"](t)`), or by `.call(keys, t)` / `.apply(keys,
|
|
74
|
+
* [t])` of the method (`Array.prototype.map.call(keys, t)`,
|
|
75
|
+
* `[].forEach.call(keys, t)`) --, `Array.from(keys, t)` and
|
|
76
|
+
* `Array.fromAsync(keys, t)`; and what `.then(t)` /
|
|
69
77
|
* `.catch(t)` settle with, which no source writes;
|
|
70
78
|
* - the string given to an `i18n` or `code` property, to a
|
|
71
79
|
* `data-i18n*` attribute (as a property, also computed by a
|
|
@@ -117,8 +125,10 @@
|
|
|
117
125
|
* const object literal (`DEFAULTS.ok`; every value of it for
|
|
118
126
|
* `NOTES[verdict]`), or of a copy of one (`{...o}`,
|
|
119
127
|
* `Object.assign({}, o)`); the element of a const array literal
|
|
120
|
-
*
|
|
121
|
-
*
|
|
128
|
+
* that a for...of iterates, or the first parameter of a callback
|
|
129
|
+
* of one of the methods above (in the same forms, and of
|
|
130
|
+
* `Array.from(items, cb)`), and what a destructuring reads from
|
|
131
|
+
* it;
|
|
122
132
|
* `String(x)`, and a template that is only `${x}`, as x; a
|
|
123
133
|
* parameter however it is read (`opts?.title`, `arguments[1]`,
|
|
124
134
|
* `rest[0]`) and its default; a call of a function the script
|
|
@@ -130,16 +140,25 @@
|
|
|
130
140
|
* was read again at every call, and three recursive branches
|
|
131
141
|
* hung the build. And an UNMARKED plain `let` / `var` whose
|
|
132
142
|
* every value in its scope -- its initializer, every `=`, `||=`,
|
|
133
|
-
* `??=`,
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
+
* `??=`, `&&=`, the value of a `var` of it declared again -- is
|
|
144
|
+
* written as a string literal, a const bound to one, `null`, or a
|
|
145
|
+
* `?:` / `||` / `??` of those (the right one of `&&`), read where
|
|
146
|
+
* t(), an i18n or a data-i18n* value reads a key: it can only
|
|
147
|
+
* ever hold those literals, and EVERY one of them is a key asked
|
|
148
|
+
* for. Every write counts: one whose value the reader does not
|
|
149
|
+
* read -- a property of a table, a call, data, a `+=`, a
|
|
150
|
+
* destructuring assignment, a for...of / for...in head that
|
|
151
|
+
* writes it (the variable, a destructuring of it, a `var` of it
|
|
152
|
+
* declared again there), a direct eval() -- leaves the variable
|
|
153
|
+
* not followed, and it fails nothing (up to 7.26.41 a
|
|
154
|
+
* destructuring loop head, and a `var` declared again in a loop
|
|
155
|
+
* head or in a block of the module, did not count, and the
|
|
156
|
+
* literal was asked for). The rule is flow-INSENSITIVE: a literal
|
|
157
|
+
* an `if` excludes, or one overwritten before the read, is asked
|
|
158
|
+
* for all the same; a sentinel that is no key is `null`, which is
|
|
159
|
+
* never asked for. A key built by concatenation, held in a `let`
|
|
160
|
+
* given anything else, or arriving as data cannot be known: its
|
|
161
|
+
* module publishes it in a `<NAME>_I18N_KEYS` list.
|
|
143
162
|
*
|
|
144
163
|
* A MARKER at the place a key is read says where the keys of what
|
|
145
164
|
* follows it come from: `/\* i18n: <NAME>_I18N_KEYS *\/` (that
|
|
@@ -161,11 +180,7 @@
|
|
|
161
180
|
* one, a call that returns literals, imported or not -- it is a
|
|
162
181
|
* violation, and so is one that would HIDE a key the reader does
|
|
163
182
|
* 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`
|
|
183
|
+
* branches), an array of string literals. A marked `let` / `var`
|
|
169
184
|
* is READ, and so is one a marked member or element is read from
|
|
170
185
|
* (`LABELS[k]`, `picked = LIST[0]`, the `x` of
|
|
171
186
|
* `LIST.forEach((x) => ...)`): everything it is given in its
|
|
@@ -175,6 +190,14 @@
|
|
|
175
190
|
* lists named, and one given nothing but literals is a
|
|
176
191
|
* violation: it is a const.
|
|
177
192
|
*
|
|
193
|
+
* A TRANSLATED text where a key is read -- `t("k")`, any
|
|
194
|
+
* translator above, or a string built from one, `t("k") + ":"`,
|
|
195
|
+
* `t("k").toUpperCase()` -- is a violation, MARKED OR NOT, given
|
|
196
|
+
* to t() (`t(t("k") + "!")`), to an i18n / code / data-i18n*
|
|
197
|
+
* value (`{i18n: t("k")}`) or to a data-i18n* attribute: the
|
|
198
|
+
* place keeps the translation as its key, and it never changes
|
|
199
|
+
* language. Up to 7.26.41 only a marked one failed.
|
|
200
|
+
*
|
|
178
201
|
* THE RULE PER CALL holds the app's own code, as a test holds the
|
|
179
202
|
* library (i18n_key_functions.test.js): every value a key position
|
|
180
203
|
* of a key function can take is a literal (a branch of them,
|
|
@@ -210,10 +233,13 @@
|
|
|
210
233
|
* returns (`const inner = () => key; t(inner())`: the search for
|
|
211
234
|
* the functions that forward a key does not see it); a translator
|
|
212
235
|
* handed to a function (`{t: t}`, `yui_tabulator_lang(t)`: it
|
|
213
|
-
* calls it with keys of its own)
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
236
|
+
* calls it with keys of its own), or to any method but those
|
|
237
|
+
* above (`keys.reduce(t)`, `keys.sort(t)`, an alias of a method,
|
|
238
|
+
* `Reflect.apply(Array.prototype.map, keys, [t])`); a translated
|
|
239
|
+
* text held in a `let`, marked or not (`let label = t(k); ...
|
|
240
|
+
* label`: the reader reads the literals of a `let`, not what it
|
|
241
|
+
* translates), or returned by a function (`{i18n:
|
|
242
|
+
* label_of(x)}`); a key function reached through a parameter, a
|
|
217
243
|
* `let` given more than one value, a computed member
|
|
218
244
|
* (`API[name](...)`); a data-i18n* attribute written through an
|
|
219
245
|
* alias of `dataset`, by Object.assign() into it, or named by a
|
|
@@ -896,11 +922,90 @@ function is_object_call(n, name)
|
|
|
896
922
|
|
|
897
923
|
const FUNCTION_RE = /^(FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;
|
|
898
924
|
|
|
899
|
-
/* The array methods whose callback receives each ELEMENT first
|
|
925
|
+
/* The array methods whose callback receives each ELEMENT first (up to
|
|
926
|
+
* 7.26.41 without findIndex and findLastIndex) */
|
|
900
927
|
const ITERATION_METHODS = new Set([
|
|
901
|
-
"map", "flatMap", "forEach", "filter", "find", "findLast", "some", "every"
|
|
928
|
+
"map", "flatMap", "forEach", "filter", "find", "findIndex", "findLast", "findLastIndex", "some", "every"
|
|
902
929
|
]);
|
|
903
930
|
|
|
931
|
+
/* The builders of an array that hand their callback each element:
|
|
932
|
+
* Array.from(items, cb), Array.fromAsync(items, cb) */
|
|
933
|
+
const ARRAY_BUILDERS = new Set(["from", "fromAsync"]);
|
|
934
|
+
|
|
935
|
+
/***************************************************************
|
|
936
|
+
* A call that hands each ELEMENT of an array to a callback, in the
|
|
937
|
+
* forms the reader reads -- for a method of ITERATION_METHODS:
|
|
938
|
+
*
|
|
939
|
+
* items.map(cb) also `items?.map(cb)`, `items["map"](cb)`
|
|
940
|
+
* X.map.call(items, cb) `Array.prototype.map.call(...)`, `[].map.call(...)`
|
|
941
|
+
* X.map.apply(items, [cb])
|
|
942
|
+
* Array.from(items, cb) and Array.fromAsync(items, cb)
|
|
943
|
+
*
|
|
944
|
+
* -> {method, receiver, callback, form} | null
|
|
945
|
+
*
|
|
946
|
+
* `receiver` is the array walked, `callback` what it is handed (a
|
|
947
|
+
* function, a translator), `form` "" for a plain call, "call",
|
|
948
|
+
* "apply" or "from". `scope` is the chain of ancestors of the call:
|
|
949
|
+
* `Array` must be the global. Any other way to reach the method --
|
|
950
|
+
* an alias of it, Reflect.apply(), a computed name -- is not read.
|
|
951
|
+
***************************************************************/
|
|
952
|
+
function iteration_call(call, scope)
|
|
953
|
+
{
|
|
954
|
+
let unchain = (x) => (x && x.type === "ChainExpression")? x.expression : x;
|
|
955
|
+
let c = unchain(call.callee);
|
|
956
|
+
if(c.type !== "MemberExpression") {
|
|
957
|
+
return null;
|
|
958
|
+
}
|
|
959
|
+
let name = member_step(c).prop;
|
|
960
|
+
if(ITERATION_METHODS.has(name)) {
|
|
961
|
+
let cb = call.arguments[0];
|
|
962
|
+
return (cb && cb.type !== "SpreadElement")? {method: name, receiver: c.object, callback: cb, form: ""} : null;
|
|
963
|
+
}
|
|
964
|
+
if(name === "call" || name === "apply") {
|
|
965
|
+
let inner = unchain(c.object);
|
|
966
|
+
let method = (inner.type === "MemberExpression")? member_step(inner).prop : null;
|
|
967
|
+
if(!ITERATION_METHODS.has(method)) {
|
|
968
|
+
return null;
|
|
969
|
+
}
|
|
970
|
+
let receiver = call.arguments[0];
|
|
971
|
+
let rest = call.arguments[1];
|
|
972
|
+
let cb = (name === "call")? rest : ((rest && rest.type === "ArrayExpression")? rest.elements[0] : null);
|
|
973
|
+
if(!receiver || receiver.type === "SpreadElement" || !cb || cb.type === "SpreadElement") {
|
|
974
|
+
return null;
|
|
975
|
+
}
|
|
976
|
+
return {method, receiver, callback: cb, form: name};
|
|
977
|
+
}
|
|
978
|
+
if(ARRAY_BUILDERS.has(name) && c.object.type === "Identifier" && c.object.name === "Array"
|
|
979
|
+
&& call.arguments.length >= 2 && binding_of("Array", scope) === null) {
|
|
980
|
+
let [items, cb] = call.arguments;
|
|
981
|
+
if(items.type === "SpreadElement" || cb.type === "SpreadElement") {
|
|
982
|
+
return null;
|
|
983
|
+
}
|
|
984
|
+
return {method: `Array.${name}`, receiver: items, callback: cb, form: "from"};
|
|
985
|
+
}
|
|
986
|
+
return null;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/***************************************************************
|
|
990
|
+
* The iteration call (iteration_call()) a function is the CALLBACK
|
|
991
|
+
* of, when `scope[i]` is that function: {receiver, scope}, `scope`
|
|
992
|
+
* the chain of ancestors of the call, where `receiver` is read; or
|
|
993
|
+
* null
|
|
994
|
+
***************************************************************/
|
|
995
|
+
function iteration_callback_of(fn, scope, i)
|
|
996
|
+
{
|
|
997
|
+
let k = i - 1;
|
|
998
|
+
if(scope[k] && scope[k].type === "ArrayExpression") {
|
|
999
|
+
k--; // `.apply(items, [cb])`
|
|
1000
|
+
}
|
|
1001
|
+
let call = scope[k];
|
|
1002
|
+
if(!call || call.type !== "CallExpression") {
|
|
1003
|
+
return null;
|
|
1004
|
+
}
|
|
1005
|
+
let it = iteration_call(call, scope.slice(0, k));
|
|
1006
|
+
return (it && it.callback === fn)? {receiver: it.receiver, scope: scope.slice(0, k)} : null;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
904
1009
|
/***************************************************************
|
|
905
1010
|
* The names a binding pattern declares
|
|
906
1011
|
***************************************************************/
|
|
@@ -959,8 +1064,25 @@ function function_scope_names(fn)
|
|
|
959
1064
|
if(fn.type === "FunctionExpression" && fn.id) {
|
|
960
1065
|
names.set(fn.id.name, null);
|
|
961
1066
|
}
|
|
1067
|
+
if(fn.body && fn.body.type === "BlockStatement") {
|
|
1068
|
+
hoisted_vars(fn.body.body, names);
|
|
1069
|
+
}
|
|
1070
|
+
FN_NAMES.set(fn, names);
|
|
1071
|
+
return names;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
/***************************************************************
|
|
1075
|
+
* The `var`s a list of statements declares, hoisted to the body
|
|
1076
|
+
* they are in -- a function's, the module's, or a class's static
|
|
1077
|
+
* block's: wherever they stand in it (a block, an `if`, a `switch`
|
|
1078
|
+
* case, a `for(;;)` init, a for...of / for...in head), not inside a
|
|
1079
|
+
* function or a static block nested in it, which have their own.
|
|
1080
|
+
* Into `names`, in the form of function_scope_names().
|
|
1081
|
+
***************************************************************/
|
|
1082
|
+
function hoisted_vars(statements, names = new Map())
|
|
1083
|
+
{
|
|
962
1084
|
let visit = (n) => {
|
|
963
|
-
if(!n || typeof n.type !== "string" || FUNCTION_RE.test(n.type)) {
|
|
1085
|
+
if(!n || typeof n.type !== "string" || FUNCTION_RE.test(n.type) || n.type === "StaticBlock") {
|
|
964
1086
|
return;
|
|
965
1087
|
}
|
|
966
1088
|
if(n.type === "VariableDeclaration" && n.kind === "var") {
|
|
@@ -991,12 +1113,9 @@ function function_scope_names(fn)
|
|
|
991
1113
|
}
|
|
992
1114
|
}
|
|
993
1115
|
};
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
visit(s);
|
|
997
|
-
}
|
|
1116
|
+
for(let s of statements) {
|
|
1117
|
+
visit(s);
|
|
998
1118
|
}
|
|
999
|
-
FN_NAMES.set(fn, names);
|
|
1000
1119
|
return names;
|
|
1001
1120
|
}
|
|
1002
1121
|
|
|
@@ -1023,13 +1142,13 @@ function function_name(fn, parent)
|
|
|
1023
1142
|
* it: name -> {kind: "const", init, steps, default} |
|
|
1024
1143
|
* {kind: "each", of} | {kind: "each_part", of} | {kind: "var",
|
|
1025
1144
|
* 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().
|
|
1145
|
+
* here to the module, wherever it stands in it: hoisted_vars()) |
|
|
1146
|
+
* {kind: "other", init}. A name declared by a destructuring reads
|
|
1147
|
+
* `steps` from the value (`const {title} = opts`: `.title`; `picks`
|
|
1148
|
+
* per declarator for a `let`); one an array pattern declares is
|
|
1149
|
+
* "other" (its `init`, for param_flows()), and an element of a
|
|
1150
|
+
* for...of that an array pattern destructures is "each_part".
|
|
1151
|
+
* Cached, like function_scope_names().
|
|
1033
1152
|
***************************************************************/
|
|
1034
1153
|
const SCOPE_NAMES = new WeakMap();
|
|
1035
1154
|
|
|
@@ -1040,15 +1159,21 @@ function scope_names(a)
|
|
|
1040
1159
|
}
|
|
1041
1160
|
let names = new Map();
|
|
1042
1161
|
let declare = (name, what) => {
|
|
1043
|
-
|
|
1044
|
-
if(!had) {
|
|
1162
|
+
if(!names.has(name)) {
|
|
1045
1163
|
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
1164
|
}
|
|
1051
1165
|
};
|
|
1166
|
+
if((a.type === "Program" && has_var(a)) || a.type === "StaticBlock") {
|
|
1167
|
+
/* Every `var` of the module (or of a class's static block, which has
|
|
1168
|
+
* its own), one binding per name: up to 7.26.41 only those of the
|
|
1169
|
+
* module's top-level statements, so a `var` redeclared in a block or
|
|
1170
|
+
* in a loop head gave the variable a value the reader never saw, and
|
|
1171
|
+
* a `var` of a static block was not seen at all */
|
|
1172
|
+
for(let [name, h] of hoisted_vars(a.body)) {
|
|
1173
|
+
declare(name, h? {kind: "var", decl: "var", declarators: h.declarators, picks: h.picks}
|
|
1174
|
+
: {kind: "other", init: null});
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1052
1177
|
let statements = [];
|
|
1053
1178
|
switch(a.type) {
|
|
1054
1179
|
case "Program":
|
|
@@ -1094,8 +1219,8 @@ function scope_names(a)
|
|
|
1094
1219
|
continue;
|
|
1095
1220
|
}
|
|
1096
1221
|
if(d.type === "VariableDeclaration") {
|
|
1097
|
-
if(d.kind === "var"
|
|
1098
|
-
continue; // hoisted:
|
|
1222
|
+
if(d.kind === "var") {
|
|
1223
|
+
continue; // hoisted: its function's, module's or static block's hoisted_vars() holds it
|
|
1099
1224
|
}
|
|
1100
1225
|
for(let v of d.declarations) {
|
|
1101
1226
|
let plain = (v.id.type === "Identifier");
|
|
@@ -1297,12 +1422,11 @@ function binding_of(name, scope)
|
|
|
1297
1422
|
if(j !== undefined) {
|
|
1298
1423
|
let p = a.params[j];
|
|
1299
1424
|
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)};
|
|
1425
|
+
let it = (j === 0 && parent && a.type !== "FunctionDeclaration")?
|
|
1426
|
+
iteration_callback_of(a, scope, i) : null;
|
|
1427
|
+
if(it) {
|
|
1428
|
+
return at? {kind: "each", of: it.receiver, steps: at.steps, scope: it.scope}
|
|
1429
|
+
: {kind: "each_part", of: it.receiver, scope: it.scope};
|
|
1306
1430
|
}
|
|
1307
1431
|
let base = {fn: a, name: function_name(a, parent), index: j, scope: scope.slice(0, i + 1)};
|
|
1308
1432
|
if(at) {
|
|
@@ -1610,7 +1734,12 @@ const TRANSLATOR = Object.freeze({kind: "t", name: "t"});
|
|
|
1610
1734
|
* const (`const translate = t`), a
|
|
1611
1735
|
* `.bind()` (`i18next.t.bind(i18next)`),
|
|
1612
1736
|
* a re-export of a module the reader
|
|
1613
|
-
* reads
|
|
1737
|
+
* reads. A `.bind()` that binds
|
|
1738
|
+
* arguments too (`t.bind(null, k)`)
|
|
1739
|
+
* adds `bound`, how many (and
|
|
1740
|
+
* `bound_spread` when a spread hides
|
|
1741
|
+
* it), to whatever it binds:
|
|
1742
|
+
* call_target() counts them
|
|
1614
1743
|
* {kind: "fn", fn, scope, name, url}
|
|
1615
1744
|
* a FUNCTION the reader reads: a
|
|
1616
1745
|
* declaration, a const bound to one
|
|
@@ -1708,13 +1837,24 @@ function callee_of(node, scope, depth = 0)
|
|
|
1708
1837
|
return TRANSLATOR_NAMES.has(step.prop)? TRANSLATOR : null;
|
|
1709
1838
|
}
|
|
1710
1839
|
|
|
1711
|
-
case "CallExpression":
|
|
1712
|
-
/* f.bind(x) is f
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1840
|
+
case "CallExpression": {
|
|
1841
|
+
/* f.bind(x) is f; f.bind(x, a, ...) is f with its first arguments
|
|
1842
|
+
* BOUND, so what a call of it is handed comes after them */
|
|
1843
|
+
let c = node.callee;
|
|
1844
|
+
if(c.type !== "MemberExpression" || c.computed || c.property.type !== "Identifier"
|
|
1845
|
+
|| c.property.name !== "bind") {
|
|
1846
|
+
return null;
|
|
1716
1847
|
}
|
|
1717
|
-
|
|
1848
|
+
let inner = callee_of(c.object, scope, depth + 1);
|
|
1849
|
+
let taken = node.arguments.slice(1);
|
|
1850
|
+
if(!inner || taken.length === 0) {
|
|
1851
|
+
return inner;
|
|
1852
|
+
}
|
|
1853
|
+
return Object.assign({}, inner, {
|
|
1854
|
+
bound: (inner.bound || 0) + taken.length,
|
|
1855
|
+
bound_spread: !!inner.bound_spread || taken.some((a) => a.type === "SpreadElement")
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1718
1858
|
|
|
1719
1859
|
default:
|
|
1720
1860
|
return null;
|
|
@@ -1768,7 +1908,12 @@ function var_function(b)
|
|
|
1768
1908
|
* What a call calls (callee_of()), and the arguments the callee
|
|
1769
1909
|
* receives: `f(a)` a; `f.call(x, a)` a; `f.apply(x, [a, b])` a and
|
|
1770
1910
|
* b (null when `.apply()` hands an array the source does not write
|
|
1771
|
-
* out).
|
|
1911
|
+
* out). A callee with arguments BOUND (`const g = f.bind(x, a)`)
|
|
1912
|
+
* receives those first: they stand as holes (null) before what the
|
|
1913
|
+
* call hands -- a position that is not read, as the bound key of
|
|
1914
|
+
* `t.bind(null, k)` is not --, and the arguments are null when a
|
|
1915
|
+
* spread hides how many were bound. Cached per call: what it calls
|
|
1916
|
+
* does not change.
|
|
1772
1917
|
*
|
|
1773
1918
|
* -> {target, args} | null
|
|
1774
1919
|
***************************************************************/
|
|
@@ -1798,6 +1943,13 @@ function call_target(call, scope)
|
|
|
1798
1943
|
let target = callee_of(callee, scope);
|
|
1799
1944
|
r = target? {target, args: call.arguments} : null;
|
|
1800
1945
|
}
|
|
1946
|
+
if(r && r.target.bound) {
|
|
1947
|
+
/* Up to 7.26.41 the bound arguments were not counted: what a call of
|
|
1948
|
+
* `t.bind(null, k)` hands -- i18next's options, its default value -- was
|
|
1949
|
+
* asked for as a key */
|
|
1950
|
+
r = {target: r.target, args: (r.args && !r.target.bound_spread)?
|
|
1951
|
+
[...new Array(r.target.bound).fill(null), ...r.args] : null};
|
|
1952
|
+
}
|
|
1801
1953
|
CALL_TARGETS.set(call, r);
|
|
1802
1954
|
return r;
|
|
1803
1955
|
}
|
|
@@ -1930,28 +2082,28 @@ const SETTLE_METHODS = new Set(["then", "catch"]);
|
|
|
1930
2082
|
* call it is handed to calls it, and what that call hands it is a
|
|
1931
2083
|
* key the source writes nowhere as one:
|
|
1932
2084
|
*
|
|
1933
|
-
* {how: "elements", method, receiver, arg}
|
|
1934
|
-
* `
|
|
1935
|
-
* `
|
|
1936
|
-
*
|
|
2085
|
+
* {how: "elements", method, form, receiver, arg}
|
|
2086
|
+
* each ELEMENT of `receiver` is a key, in every form of
|
|
2087
|
+
* iteration_call(): `keys.map(t)`, `.forEach(t)`,
|
|
2088
|
+
* `.findIndex(t)`, ... (ITERATION_METHODS),
|
|
2089
|
+
* `Array.prototype.map.call(keys, t)`,
|
|
2090
|
+
* `[].forEach.apply(keys, [t])`, `Array.from(keys, t)`,
|
|
2091
|
+
* `Array.fromAsync(keys, t)`
|
|
1937
2092
|
* {how: "settled", method, arg}
|
|
1938
2093
|
* `promise.then(t)`, `.catch(t)`: what the promise settles
|
|
1939
2094
|
* with, which no source writes
|
|
1940
2095
|
* null anything else. A translator handed to a FUNCTION is how
|
|
1941
2096
|
* gobj-ui receives one (`{t: t}`, `yui_tabulator_lang(t)`):
|
|
1942
2097
|
* that function calls it with keys of its own, read where
|
|
1943
|
-
* it does. A
|
|
1944
|
-
* k)
|
|
2098
|
+
* it does. A translator with arguments BOUND (`t.bind(null,
|
|
2099
|
+
* k)`, or a const bound to one) is no callback of these:
|
|
2100
|
+
* what it is handed goes after the bound key, as i18next's
|
|
2101
|
+
* options.
|
|
1945
2102
|
*
|
|
1946
2103
|
* `scope` is the chain of ancestors of the call, the call last.
|
|
1947
2104
|
***************************************************************/
|
|
1948
2105
|
function translator_callback(call, scope)
|
|
1949
2106
|
{
|
|
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
2107
|
let is_translator = (a) => {
|
|
1956
2108
|
while(a && a.type === "ChainExpression") {
|
|
1957
2109
|
a = a.expression;
|
|
@@ -1959,23 +2111,20 @@ function translator_callback(call, scope)
|
|
|
1959
2111
|
if(!a || a.type === "SpreadElement") {
|
|
1960
2112
|
return false;
|
|
1961
2113
|
}
|
|
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
2114
|
let target = callee_of(a, scope);
|
|
1966
|
-
return !!target && (target.kind === "t" || (target.kind === "fn"
|
|
1967
|
-
&& !is_key_function(target)));
|
|
2115
|
+
return !!target && !target.bound && (target.kind === "t" || (target.kind === "fn"
|
|
2116
|
+
&& TRANSLATOR_NAMES.has(target.name) && !is_key_function(target)));
|
|
1968
2117
|
};
|
|
1969
|
-
let
|
|
1970
|
-
if(
|
|
1971
|
-
return
|
|
2118
|
+
let it = iteration_call(call, scope);
|
|
2119
|
+
if(it) {
|
|
2120
|
+
return is_translator(it.callback)?
|
|
2121
|
+
{how: "elements", method: it.method, form: it.form, receiver: it.receiver, arg: it.callback} : null;
|
|
1972
2122
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
return {how: "elements", method: "Array.from", receiver: call.arguments[0], arg: call.arguments[1]};
|
|
2123
|
+
let c = (call.callee.type === "ChainExpression")? call.callee.expression : call.callee;
|
|
2124
|
+
let method = (c.type === "MemberExpression")? member_step(c).prop : null;
|
|
2125
|
+
if(SETTLE_METHODS.has(method)) {
|
|
2126
|
+
let arg = call.arguments.find(is_translator);
|
|
2127
|
+
return arg? {how: "settled", method, arg} : null;
|
|
1979
2128
|
}
|
|
1980
2129
|
return null;
|
|
1981
2130
|
}
|
|
@@ -2870,14 +3019,60 @@ function paths_meet(a, b)
|
|
|
2870
3019
|
* the first argument that is one (fill: only that one) */
|
|
2871
3020
|
const ELEMENT_WRITERS = new Map([["push", 0], ["unshift", 0], ["splice", 2], ["fill", 0]]);
|
|
2872
3021
|
|
|
3022
|
+
/***************************************************************
|
|
3023
|
+
* What a write TARGET sets -- the left of an `=`, the head of a
|
|
3024
|
+
* for...of / for...in that declares nothing --: each identifier and
|
|
3025
|
+
* each member it holds, through any destructuring (`[k, x.a] = v`,
|
|
3026
|
+
* `({k, y: x.b = "d"} = v)`, `[...rest]`)
|
|
3027
|
+
***************************************************************/
|
|
3028
|
+
function write_targets(p, out = [])
|
|
3029
|
+
{
|
|
3030
|
+
if(!p) {
|
|
3031
|
+
return out;
|
|
3032
|
+
}
|
|
3033
|
+
switch(p.type) {
|
|
3034
|
+
case "Identifier":
|
|
3035
|
+
case "MemberExpression":
|
|
3036
|
+
out.push(p);
|
|
3037
|
+
break;
|
|
3038
|
+
case "AssignmentPattern":
|
|
3039
|
+
write_targets(p.left, out);
|
|
3040
|
+
break;
|
|
3041
|
+
case "RestElement":
|
|
3042
|
+
write_targets(p.argument, out);
|
|
3043
|
+
break;
|
|
3044
|
+
case "ArrayPattern":
|
|
3045
|
+
for(let e of p.elements) {
|
|
3046
|
+
write_targets(e, out);
|
|
3047
|
+
}
|
|
3048
|
+
break;
|
|
3049
|
+
case "ObjectPattern":
|
|
3050
|
+
for(let q of p.properties) {
|
|
3051
|
+
write_targets((q.type === "RestElement")? q : q.value, out);
|
|
3052
|
+
}
|
|
3053
|
+
break;
|
|
3054
|
+
default:
|
|
3055
|
+
break;
|
|
3056
|
+
}
|
|
3057
|
+
return out;
|
|
3058
|
+
}
|
|
3059
|
+
|
|
2873
3060
|
/***************************************************************
|
|
2874
3061
|
* Everything a plain `let` / `var` is GIVEN, in the scope that
|
|
2875
3062
|
* declares it: the value of each declarator (one with none holds
|
|
2876
3063
|
* nothing), and the right side of every `=` to it (`||=`, `??=`,
|
|
2877
|
-
* `&&=` too: the old value stays possible besides).
|
|
2878
|
-
*
|
|
2879
|
-
*
|
|
2880
|
-
* (
|
|
3064
|
+
* `&&=` too: the old value stays possible besides). EVERY other
|
|
3065
|
+
* write to it is one whose value the reader does not read, and is
|
|
3066
|
+
* listed in `unknown`: `+=`, `++`, a destructuring assignment
|
|
3067
|
+
* (`[k, x] = v`, `({k} = v)`), the head of a for...of / for...in --
|
|
3068
|
+
* the variable itself (`for(k of v)`), a destructuring of it
|
|
3069
|
+
* (`for([k, x] of v)`, `for({k} of v)`), or a `var` of it declared
|
|
3070
|
+
* again there (`for(var k of v)`) --, and a direct `eval()` in its
|
|
3071
|
+
* scope, which can write any variable there. A `var` declared again
|
|
3072
|
+
* with a value anywhere in its function or module (a block, a
|
|
3073
|
+
* `for(;;)` init, a `switch` case) is one more declarator of it, so
|
|
3074
|
+
* its value is one more value. A name of another binding (shadowing)
|
|
3075
|
+
* is not a write to it.
|
|
2881
3076
|
*
|
|
2882
3077
|
* With `members` (it holds a table, and what is read is a member of
|
|
2883
3078
|
* it), also what is written INTO it: `x.a = v`, `x[k] = v`,
|
|
@@ -2885,7 +3080,8 @@ const ELEMENT_WRITERS = new Map([["push", 0], ["unshift", 0], ["splice", 2], ["f
|
|
|
2885
3080
|
* the elements `x.push(v)`, `x.unshift(v)`, `x.splice(i, n, v)`,
|
|
2886
3081
|
* `x.fill(v)` give it (a spread: every element of what is spread),
|
|
2887
3082
|
* and `Object.assign(x, v)` (v written over x). A `+=` or `++` on a
|
|
2888
|
-
* member
|
|
3083
|
+
* member, and a member a destructuring or a loop head writes
|
|
3084
|
+
* (`[x.a] = v`, `for(x.a of v)`), is unknown at that member.
|
|
2889
3085
|
*
|
|
2890
3086
|
* -> {values: [{node, scope, steps, spread, into, pick}],
|
|
2891
3087
|
* unknown: [{node, steps, scope}]}
|
|
@@ -2910,6 +3106,19 @@ function assigned_values(binding, members = false)
|
|
|
2910
3106
|
walk(root, (n, ancestors) => {
|
|
2911
3107
|
let chain = [...ancestors, n];
|
|
2912
3108
|
let into = (node) => (members? steps_to(node, (id) => is_it(id, chain)) : null);
|
|
3109
|
+
/* `n` writes `target` with a value the reader does not read */
|
|
3110
|
+
let opaque_write = (target) => {
|
|
3111
|
+
if(target.type === "Identifier") {
|
|
3112
|
+
if(is_it(target, chain)) {
|
|
3113
|
+
unknown.push({node: n, steps: [], scope: chain});
|
|
3114
|
+
}
|
|
3115
|
+
} else if(target.type === "MemberExpression") {
|
|
3116
|
+
let steps = into(target);
|
|
3117
|
+
if(steps) {
|
|
3118
|
+
unknown.push({node: n, steps, scope: chain});
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
};
|
|
2913
3122
|
switch(n.type) {
|
|
2914
3123
|
case "VariableDeclarator":
|
|
2915
3124
|
if(binding.declarators.includes(n)) {
|
|
@@ -2935,9 +3144,11 @@ function assigned_values(binding, members = false)
|
|
|
2935
3144
|
} else if(steps) {
|
|
2936
3145
|
unknown.push({node: n, steps, scope: chain});
|
|
2937
3146
|
}
|
|
2938
|
-
} else
|
|
2939
|
-
|
|
2940
|
-
|
|
3147
|
+
} else {
|
|
3148
|
+
/* A destructuring assignment: `[k, x] = v`, `({k} = v)` */
|
|
3149
|
+
for(let target of write_targets(n.left)) {
|
|
3150
|
+
opaque_write(target);
|
|
3151
|
+
}
|
|
2941
3152
|
}
|
|
2942
3153
|
break;
|
|
2943
3154
|
}
|
|
@@ -2952,6 +3163,12 @@ function assigned_values(binding, members = false)
|
|
|
2952
3163
|
}
|
|
2953
3164
|
break;
|
|
2954
3165
|
case "CallExpression": {
|
|
3166
|
+
if(n.callee.type === "Identifier" && n.callee.name === "eval") {
|
|
3167
|
+
/* Not run: a direct eval() of the SOURCE writes what its text says, which no
|
|
3168
|
+
* reader reads (in a module no other binding can be called `eval`) */
|
|
3169
|
+
unknown.push({node: n, steps: [], scope: chain});
|
|
3170
|
+
break;
|
|
3171
|
+
}
|
|
2955
3172
|
if(!members) {
|
|
2956
3173
|
break;
|
|
2957
3174
|
}
|
|
@@ -2986,8 +3203,15 @@ function assigned_values(binding, members = false)
|
|
|
2986
3203
|
}
|
|
2987
3204
|
case "ForOfStatement":
|
|
2988
3205
|
case "ForInStatement":
|
|
2989
|
-
|
|
2990
|
-
|
|
3206
|
+
/* Each turn writes an element (a key) into the head */
|
|
3207
|
+
if(n.left.type === "VariableDeclaration") {
|
|
3208
|
+
if(n.left.declarations.some((d) => binding.declarators.includes(d))) {
|
|
3209
|
+
unknown.push({node: n, steps: [], scope: chain}); // `for(var k of v)`: the same var
|
|
3210
|
+
}
|
|
3211
|
+
} else {
|
|
3212
|
+
for(let target of write_targets(n.left)) {
|
|
3213
|
+
opaque_write(target);
|
|
3214
|
+
}
|
|
2991
3215
|
}
|
|
2992
3216
|
break;
|
|
2993
3217
|
default:
|
|
@@ -3093,12 +3317,15 @@ function var_leaves(root, seen = new Set(), depth = 0)
|
|
|
3093
3317
|
* var_root and no step) -- when every value it is given in its scope
|
|
3094
3318
|
* (assigned_values(): its value, every `=`, `||=`, `??=`, `&&=`) is,
|
|
3095
3319
|
* 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
|
-
*
|
|
3320
|
+
* variable can only ever hold those literals, so they are the keys of
|
|
3321
|
+
* the place that reads it -- ALL of them: the reading is
|
|
3322
|
+
* flow-insensitive, and a literal an `if` keeps from reaching the
|
|
3323
|
+
* place is asked for too (a sentinel that is no key is `null`). Given
|
|
3324
|
+
* anything else -- a property of a table (`SHORT_MONTHS[m]`), an
|
|
3325
|
+
* element, a call, a parameter, data --, or written in any way the
|
|
3326
|
+
* reader does not read (`+=`, a destructuring, a loop head, a direct
|
|
3327
|
+
* eval(): assigned_values() lists every write), it is not followed
|
|
3328
|
+
* and answers [] -- the invisible case, which fails nothing. (expand()
|
|
3102
3329
|
* and var_leaves() read a member of a table as ANY value of it: good
|
|
3103
3330
|
* enough for a marker, which names the lists to check against, and
|
|
3104
3331
|
* too much to ask the locales for.) One declared by a destructuring,
|
|
@@ -3751,7 +3978,10 @@ function call_rule_violations(ast, lib_module, table)
|
|
|
3751
3978
|
}
|
|
3752
3979
|
for(let {call, scope, callback} of translator_callbacks(ast, lib_module)) {
|
|
3753
3980
|
let arg = ast.code.slice(callback.arg.start, callback.arg.end);
|
|
3754
|
-
let shown = (callback.
|
|
3981
|
+
let shown = (callback.form === "from")? `${callback.method}(..., ${arg})` :
|
|
3982
|
+
(callback.form === "call")? `.${callback.method}.call(..., ${arg})` :
|
|
3983
|
+
(callback.form === "apply")? `.${callback.method}.apply(..., [${arg}])` :
|
|
3984
|
+
`.${callback.method}(${arg})`;
|
|
3755
3985
|
check(callback_leaves(call, callback, scope), call, "t", `${callback.method} callback`,
|
|
3756
3986
|
{how: callback.how, shown});
|
|
3757
3987
|
}
|
|
@@ -4334,11 +4564,11 @@ function translator_callbacks(ast, lib_module = null)
|
|
|
4334
4564
|
function may_take_a_callback(n)
|
|
4335
4565
|
{
|
|
4336
4566
|
let c = (n.callee.type === "ChainExpression")? n.callee.expression : n.callee;
|
|
4337
|
-
if(c.type !== "MemberExpression" ||
|
|
4567
|
+
if(c.type !== "MemberExpression" || n.arguments.length === 0) {
|
|
4338
4568
|
return false;
|
|
4339
4569
|
}
|
|
4340
|
-
let m = c.
|
|
4341
|
-
return ITERATION_METHODS.has(m) || SETTLE_METHODS.has(m) || m === "
|
|
4570
|
+
let m = member_step(c).prop;
|
|
4571
|
+
return ITERATION_METHODS.has(m) || SETTLE_METHODS.has(m) || ARRAY_BUILDERS.has(m) || m === "call" || m === "apply";
|
|
4342
4572
|
}
|
|
4343
4573
|
|
|
4344
4574
|
/***************************************************************
|
|
@@ -4387,7 +4617,8 @@ function key_list_leaves(node, scope, root)
|
|
|
4387
4617
|
* lists: [{name, keys}], list_errors: [why],
|
|
4388
4618
|
* list_mutations: [{line, why}] (list_mutations()),
|
|
4389
4619
|
* marker_refs: [{lists, keys, line, shapes}],
|
|
4390
|
-
* marker_errors: [{line, why}]
|
|
4620
|
+
* marker_errors: [{line, why}],
|
|
4621
|
+
* translated_errors: [{line, why}]}
|
|
4391
4622
|
*
|
|
4392
4623
|
* Every place a key is read (key_places()) goes through leaves_of(),
|
|
4393
4624
|
* so a marker standing there is found: one that marks no such place,
|
|
@@ -4401,12 +4632,29 @@ function key_list_leaves(node, scope, root)
|
|
|
4401
4632
|
* string literals. Under a LIST marker those keys are asked for and
|
|
4402
4633
|
* must be in the lists, and a template with `${}` must have the
|
|
4403
4634
|
* shape of a key of them (`shapes`, checked where the lists are
|
|
4404
|
-
* known: shape_owner_check()).
|
|
4405
|
-
*
|
|
4406
|
-
*
|
|
4407
|
-
*
|
|
4408
|
-
*
|
|
4635
|
+
* known: shape_owner_check()).
|
|
4636
|
+
*
|
|
4637
|
+
* A TRANSLATED text (is_translation()) where a key is read -- given
|
|
4638
|
+
* to t(), to an `i18n` / `code` / `data-i18n*` value, to a
|
|
4639
|
+
* data-i18n* attribute -- is an error, MARKED OR NOT
|
|
4640
|
+
* (`translated_errors`): the place keeps the translation as its key,
|
|
4641
|
+
* and it never changes language. Up to 7.26.41 only a marked one
|
|
4642
|
+
* failed, so `{i18n: t("k")}` passed and `{i18n: /\* i18n: data *\/
|
|
4643
|
+
* t("k")}` did not. At a key position of a key function and at a
|
|
4644
|
+
* translator handed as a callback the rule per call says it
|
|
4645
|
+
* (call_rule_violations()).
|
|
4409
4646
|
***************************************************************/
|
|
4647
|
+
|
|
4648
|
+
/* Where key_places() reads a key, as a message says it */
|
|
4649
|
+
const PLACE_NAMES = {
|
|
4650
|
+
t: "handed to a translator as its key",
|
|
4651
|
+
code: "handed as the code of a schema check",
|
|
4652
|
+
attribute: "given to a data-i18n* attribute",
|
|
4653
|
+
property: "given to a property that holds a key (i18n, code, data-i18n*)",
|
|
4654
|
+
array: "given as an element of a list of keys",
|
|
4655
|
+
assignment: "written to a property that holds a key (i18n, data-i18n*)"
|
|
4656
|
+
};
|
|
4657
|
+
|
|
4410
4658
|
function scan_ast(ast, ctx)
|
|
4411
4659
|
{
|
|
4412
4660
|
program_url(ast, ctx.lib_module || null);
|
|
@@ -4496,12 +4744,14 @@ function scan_ast(ast, ctx)
|
|
|
4496
4744
|
}
|
|
4497
4745
|
};
|
|
4498
4746
|
|
|
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
|
-
|
|
4747
|
+
/* `place.what`: the kind of place (key_places()). At a key position of
|
|
4748
|
+
* a key function and at a translator handed as a callback, a
|
|
4749
|
+
* TRANSLATED text is the rule's (call_rule_violations()); anywhere
|
|
4750
|
+
* else it is said here, marked or not (`translated`). */
|
|
4751
|
+
let translated = []; // [{what, place, leaf, marker}]
|
|
4752
|
+
let take = (place) => {
|
|
4753
|
+
let what = place.what;
|
|
4754
|
+
for(let leaf of place.leaves) {
|
|
4505
4755
|
if(leaf.kind === "key") {
|
|
4506
4756
|
keys.add(leaf.value);
|
|
4507
4757
|
}
|
|
@@ -4513,7 +4763,6 @@ function scan_ast(ast, ctx)
|
|
|
4513
4763
|
m.leaves = [];
|
|
4514
4764
|
m.hidden = [];
|
|
4515
4765
|
m.shapes = [];
|
|
4516
|
-
m.translated = [];
|
|
4517
4766
|
}
|
|
4518
4767
|
m.leaves.push(leaf);
|
|
4519
4768
|
if(leaf.kind === "key") {
|
|
@@ -4523,15 +4772,15 @@ function scan_ast(ast, ctx)
|
|
|
4523
4772
|
check_marked_var(leaf, m);
|
|
4524
4773
|
}
|
|
4525
4774
|
answer(leaf, m);
|
|
4526
|
-
if(what !== "call" && what !== "callback" && is_translation(leaf)) {
|
|
4527
|
-
m.translated.push(leaf);
|
|
4528
|
-
}
|
|
4529
4775
|
} else if(what !== "call" && what !== "callback") {
|
|
4530
4776
|
/* An unmarked `let` that can only hold literals holds keys */
|
|
4531
4777
|
for(let k of literal_let_keys(leaf)) {
|
|
4532
4778
|
keys.add(k);
|
|
4533
4779
|
}
|
|
4534
4780
|
}
|
|
4781
|
+
if(what !== "call" && what !== "callback" && is_translation(leaf)) {
|
|
4782
|
+
translated.push({what, place: place.node, leaf, marker: m});
|
|
4783
|
+
}
|
|
4535
4784
|
}
|
|
4536
4785
|
};
|
|
4537
4786
|
let add_markup = (text) => {
|
|
@@ -4548,7 +4797,7 @@ function scan_ast(ast, ctx)
|
|
|
4548
4797
|
};
|
|
4549
4798
|
|
|
4550
4799
|
for(let place of key_places(ast, ctx)) {
|
|
4551
|
-
take(place
|
|
4800
|
+
take(place);
|
|
4552
4801
|
}
|
|
4553
4802
|
walk(ast, (n) => {
|
|
4554
4803
|
if(n.type === "Property") {
|
|
@@ -4580,21 +4829,6 @@ function scan_ast(ast, ctx)
|
|
|
4580
4829
|
marker_errors.push({line: m.line, why: marker_misplaced(ast, m)});
|
|
4581
4830
|
continue;
|
|
4582
4831
|
}
|
|
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
4832
|
if(m.kind === "lists") {
|
|
4599
4833
|
marker_refs.push({lists: m.lists, keys: [...m.keys], line: m.line, shapes: m.shapes});
|
|
4600
4834
|
continue;
|
|
@@ -4619,6 +4853,30 @@ function scan_ast(ast, ctx)
|
|
|
4619
4853
|
}
|
|
4620
4854
|
}
|
|
4621
4855
|
|
|
4856
|
+
/* A TRANSLATED text where a key is read: marked (at the marker's line) or not */
|
|
4857
|
+
let translated_errors = [];
|
|
4858
|
+
let said = new Set();
|
|
4859
|
+
for(let {what, place, leaf, marker} of translated) {
|
|
4860
|
+
/* A const imported from another file: its text is that file's, and the
|
|
4861
|
+
* line said is the place's, here */
|
|
4862
|
+
let program = (leaf.scope && leaf.scope.length > 0 && typeof leaf.scope[0].code === "string")?
|
|
4863
|
+
leaf.scope[0] : ast;
|
|
4864
|
+
let text = program.code.slice(leaf.node.start, leaf.node.end).replace(/\s+/g, " ").slice(0, 80);
|
|
4865
|
+
let place_line = line_of(ast, place.start);
|
|
4866
|
+
let line = marker? marker.line : (program === ast)? line_of(ast, leaf.node.start) : place_line;
|
|
4867
|
+
let read_at = (line !== place_line)? ` (read at line ${place_line})` : "";
|
|
4868
|
+
let why = marker?
|
|
4869
|
+
`marked as ${marker.kind === "data"? "data" : "keys of " + marker.lists.join(", ")}, but ` +
|
|
4870
|
+
`\`${text}\` is a TRANSLATED text: where a key is read, the translation is kept as its key ` +
|
|
4871
|
+
`and never changes language, and no marker excuses it: hand the key, not t(key)` :
|
|
4872
|
+
`\`${text}\` is a TRANSLATED text ${PLACE_NAMES[what] || "where a key is read"}${read_at}: the ` +
|
|
4873
|
+
`translation is kept as its key and never changes language: hand the key, not t(key)`;
|
|
4874
|
+
if(!said.has(`${line} ${why}`)) {
|
|
4875
|
+
said.add(`${line} ${why}`);
|
|
4876
|
+
translated_errors.push({line, why});
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
|
|
4622
4880
|
return {
|
|
4623
4881
|
keys,
|
|
4624
4882
|
read_keys,
|
|
@@ -4627,7 +4885,8 @@ function scan_ast(ast, ctx)
|
|
|
4627
4885
|
list_errors: published.errors,
|
|
4628
4886
|
list_mutations: list_mutations(ast, published.lists),
|
|
4629
4887
|
marker_refs,
|
|
4630
|
-
marker_errors
|
|
4888
|
+
marker_errors,
|
|
4889
|
+
translated_errors
|
|
4631
4890
|
};
|
|
4632
4891
|
}
|
|
4633
4892
|
|
|
@@ -4767,7 +5026,7 @@ function collect_used_keys(opts)
|
|
|
4767
5026
|
published.get(list.name).add(k);
|
|
4768
5027
|
}
|
|
4769
5028
|
}
|
|
4770
|
-
for(let e of r.marker_errors) {
|
|
5029
|
+
for(let e of [...r.marker_errors, ...r.translated_errors]) {
|
|
4771
5030
|
fail(`${label}:${e.line}: ${e.why}`);
|
|
4772
5031
|
}
|
|
4773
5032
|
for(let ref of r.marker_refs) {
|
|
@@ -4922,7 +5181,10 @@ function source_files(dir, locales_dir)
|
|
|
4922
5181
|
* a key -- "configuración" is a Spanish literal that forgot its key,
|
|
4923
5182
|
* and it is reported, as an ASCII one would be. `wordmark` and `alt` are
|
|
4924
5183
|
* deliberately out: a brand name is not translated. A key starting with
|
|
4925
|
-
* `_` is a comment.
|
|
5184
|
+
* `_` is a comment. And the `id` of a menu or a toolbar item with no
|
|
5185
|
+
* `name`, and of a C_YUI_NODE node with no `label`, is a key where the
|
|
5186
|
+
* library names it by it (menu_item_keys(), toolbar_item_keys(),
|
|
5187
|
+
* node_tree_keys()).
|
|
4926
5188
|
***************************************************************/
|
|
4927
5189
|
const CONFIG_I18N_FIELDS = ["name", "aria_label", "tooltip", "label", "title", "subtitle"];
|
|
4928
5190
|
|
|
@@ -4959,6 +5221,246 @@ function keys_from_shell_config(url, keys, is_key)
|
|
|
4959
5221
|
}
|
|
4960
5222
|
};
|
|
4961
5223
|
walk_config(config);
|
|
5224
|
+
menu_item_keys(config, keys, is_key);
|
|
5225
|
+
toolbar_item_keys(config, keys, is_key);
|
|
5226
|
+
node_tree_keys(config, keys, is_key);
|
|
5227
|
+
}
|
|
5228
|
+
|
|
5229
|
+
/***************************************************************
|
|
5230
|
+
* The `id` of a NODE of a C_YUI_NODE tree with no `label`: the library
|
|
5231
|
+
* names a node `label || id`, and that name is an i18n KEY -- the item
|
|
5232
|
+
* of the parent's navs (child_nav_items(), node_tree_model.js, after
|
|
5233
|
+
* normalize_spec() gave a child with no label its id as one), the
|
|
5234
|
+
* label of the node's own navs and its crumb in a path (c_yui_node.js,
|
|
5235
|
+
* translated with the shell's translator), its node in the site map.
|
|
5236
|
+
* Up to gobj-ui 7.26.41 the validator read a node's `label` and not
|
|
5237
|
+
* the id that stands in for a missing one.
|
|
5238
|
+
*
|
|
5239
|
+
* A tree is declared as `{"gclass": "C_YUI_NODE", "kw": {...}}`
|
|
5240
|
+
* wherever the shell declaration holds one (a menu item's `target`, a
|
|
5241
|
+
* route's): its root is the `kw` (its id is `node_id`), the nodes
|
|
5242
|
+
* below it the specs of `children` (`id`), down the whole tree. A
|
|
5243
|
+
* root names itself only on its navs and in a path: one with no
|
|
5244
|
+
* children and no path draws no label. A spec the library refuses --
|
|
5245
|
+
* no `id`, an id with a "/" -- is drawn by nothing.
|
|
5246
|
+
***************************************************************/
|
|
5247
|
+
function node_tree_keys(config, keys, is_key)
|
|
5248
|
+
{
|
|
5249
|
+
let ask = (v) => {
|
|
5250
|
+
if(typeof v === "string" && v && is_key(v)) {
|
|
5251
|
+
keys.add(v);
|
|
5252
|
+
}
|
|
5253
|
+
};
|
|
5254
|
+
/* normalize_spec()'s own test: a label is a non-empty string */
|
|
5255
|
+
let labelled = (spec) => typeof spec.label === "string" && spec.label !== "";
|
|
5256
|
+
let read_children = (children) => {
|
|
5257
|
+
for(let spec of (Array.isArray(children)? children : [])) {
|
|
5258
|
+
if(!spec || typeof spec !== "object" || Array.isArray(spec)
|
|
5259
|
+
|| typeof spec.id !== "string" || !spec.id || spec.id.includes("/")) {
|
|
5260
|
+
continue;
|
|
5261
|
+
}
|
|
5262
|
+
if(!labelled(spec)) {
|
|
5263
|
+
ask(spec.id);
|
|
5264
|
+
}
|
|
5265
|
+
read_children(spec.children);
|
|
5266
|
+
}
|
|
5267
|
+
};
|
|
5268
|
+
let walk = (n) => {
|
|
5269
|
+
if(Array.isArray(n)) {
|
|
5270
|
+
for(let x of n) {
|
|
5271
|
+
walk(x);
|
|
5272
|
+
}
|
|
5273
|
+
return;
|
|
5274
|
+
}
|
|
5275
|
+
if(!n || typeof n !== "object") {
|
|
5276
|
+
return;
|
|
5277
|
+
}
|
|
5278
|
+
if(n.gclass === "C_YUI_NODE" && n.kw && typeof n.kw === "object" && !Array.isArray(n.kw)) {
|
|
5279
|
+
let kw = n.kw;
|
|
5280
|
+
let draws = (Array.isArray(kw.children) && kw.children.length > 0) || kw.nav_mode === "path"
|
|
5281
|
+
|| !!(kw.projection && typeof kw.projection === "object" && kw.projection.path);
|
|
5282
|
+
if(draws && !labelled(kw)) {
|
|
5283
|
+
ask(kw.node_id);
|
|
5284
|
+
}
|
|
5285
|
+
read_children(kw.children);
|
|
5286
|
+
}
|
|
5287
|
+
for(let [k, v] of Object.entries(n)) {
|
|
5288
|
+
if(!k.startsWith("_")) {
|
|
5289
|
+
walk(v);
|
|
5290
|
+
}
|
|
5291
|
+
}
|
|
5292
|
+
};
|
|
5293
|
+
walk(config);
|
|
5294
|
+
}
|
|
5295
|
+
|
|
5296
|
+
/***************************************************************
|
|
5297
|
+
* The `id` of a MENU item that the library names the item by, as a
|
|
5298
|
+
* key, when the item has no `name` -- mirrored from C_YUI_NAV and the
|
|
5299
|
+
* shell, so a key they translate is a key asked for (up to gobj-ui
|
|
5300
|
+
* 7.26.41 such an item was named by its raw id, with no key):
|
|
5301
|
+
*
|
|
5302
|
+
* - when it has neither a `name` nor an `aria_label`: the name of
|
|
5303
|
+
* the item in every layout -- a tab, an entry of a vertical menu,
|
|
5304
|
+
* a submenu or an icon bar, a card, an accordion head, a crumb
|
|
5305
|
+
* (`name || aria_label || id`: c_yui_nav.js, nav_cards_helpers.js)
|
|
5306
|
+
* -- and its title too, when it has no `tooltip`;
|
|
5307
|
+
* - when it has no `name`, in a menu drawn as a BREADCRUMB that shows
|
|
5308
|
+
* its labels: the text of the crumb is `name || id`;
|
|
5309
|
+
* - when it has no `name`, for an item that opens a SECTION INDEX
|
|
5310
|
+
* (`submenu.index`, a `route`, no `target`): the landing's nav is
|
|
5311
|
+
* labelled `name || id` (shell_section_index.js).
|
|
5312
|
+
*
|
|
5313
|
+
* The items are those of every menu (`menu.<id>.items`) and of every
|
|
5314
|
+
* submenu of them (`submenu.items`) -- and the rows of the dropdown
|
|
5315
|
+
* action of an entry with no submenu, which the site map draws and
|
|
5316
|
+
* labels as an entry (`name || aria_label || id`, route_map_model.js)
|
|
5317
|
+
* --; a decorative one (`type` "header" or "divider") is named by
|
|
5318
|
+
* nothing of this. A `name`, an `aria_label` or a `tooltip` is read
|
|
5319
|
+
* wherever it stands, above.
|
|
5320
|
+
***************************************************************/
|
|
5321
|
+
function menu_item_keys(config, keys, is_key)
|
|
5322
|
+
{
|
|
5323
|
+
let menus = (config && config.menu && typeof config.menu === "object")? config.menu : {};
|
|
5324
|
+
let zones = (config && config.shell && config.shell.zones && typeof config.shell.zones === "object")?
|
|
5325
|
+
config.shell.zones : {};
|
|
5326
|
+
let ask = (v) => {
|
|
5327
|
+
if(typeof v === "string" && v && is_key(v)) {
|
|
5328
|
+
keys.add(v);
|
|
5329
|
+
}
|
|
5330
|
+
};
|
|
5331
|
+
/* Does a render (`"tabs"` or `{layout, show_label}`) draw a
|
|
5332
|
+
* breadcrumb that shows the labels? */
|
|
5333
|
+
let draws_crumbs = (r) => {
|
|
5334
|
+
let cfg = (typeof r === "string")? {layout: r} : r;
|
|
5335
|
+
return !!cfg && typeof cfg === "object" && cfg.layout === "breadcrumb" && cfg.show_label !== false;
|
|
5336
|
+
};
|
|
5337
|
+
let read_items = (items, crumbs, top) => {
|
|
5338
|
+
for(let it of (Array.isArray(items)? items : [])) {
|
|
5339
|
+
if(!it || typeof it !== "object" || it.type === "header" || it.type === "divider") {
|
|
5340
|
+
continue;
|
|
5341
|
+
}
|
|
5342
|
+
/* The library's own test: `it.name || it.aria_label || it.id` */
|
|
5343
|
+
if(!it.name && (!it.aria_label || crumbs)) {
|
|
5344
|
+
ask(it.id);
|
|
5345
|
+
}
|
|
5346
|
+
let sub = it.submenu;
|
|
5347
|
+
if(!sub || typeof sub !== "object" || !Array.isArray(sub.items)) {
|
|
5348
|
+
/* The site map draws the rows of a dropdown action too, named
|
|
5349
|
+
* as an entry is (route_map_model.js, nav_node_from_item()) */
|
|
5350
|
+
let a = it.action;
|
|
5351
|
+
if(a && typeof a === "object" && a.type === "dropdown") {
|
|
5352
|
+
read_items(a.items, false, false);
|
|
5353
|
+
}
|
|
5354
|
+
continue;
|
|
5355
|
+
}
|
|
5356
|
+
if(top && sub.index && it.route && !it.target && !it.name) {
|
|
5357
|
+
ask(it.id);
|
|
5358
|
+
}
|
|
5359
|
+
/* A submenu is drawn in each zone its `render` names ("*" is no
|
|
5360
|
+
* zone for it) */
|
|
5361
|
+
let render = (sub.render && typeof sub.render === "object")? sub.render : {};
|
|
5362
|
+
read_items(sub.items, Object.keys(render).some((z) => z !== "*" && draws_crumbs(render[z])), false);
|
|
5363
|
+
}
|
|
5364
|
+
};
|
|
5365
|
+
for(let menu_id of Object.keys(menus)) {
|
|
5366
|
+
let menu = menus[menu_id];
|
|
5367
|
+
if(!menu || typeof menu !== "object") {
|
|
5368
|
+
continue;
|
|
5369
|
+
}
|
|
5370
|
+
/* A menu is drawn in each zone that hosts it, with that zone's
|
|
5371
|
+
* render, else the render "*", else a vertical menu */
|
|
5372
|
+
let render = (menu.render && typeof menu.render === "object")? menu.render : {};
|
|
5373
|
+
let crumbs = Object.keys(zones).some((z) => zones[z] && zones[z].host === `menu.${menu_id}`
|
|
5374
|
+
&& draws_crumbs(render[z] || render["*"]));
|
|
5375
|
+
read_items(menu.items, crumbs, true);
|
|
5376
|
+
}
|
|
5377
|
+
}
|
|
5378
|
+
|
|
5379
|
+
/***************************************************************
|
|
5380
|
+
* The `id` of a TOOLBAR item that the shell names the item by, as a
|
|
5381
|
+
* key, when the item has neither an `aria_label` nor a `name`
|
|
5382
|
+
* (`aria_label || name || id`, build_toolbar_*() of c_yui_shell.js;
|
|
5383
|
+
* up to gobj-ui 7.26.41 such an item was named by its raw id, with no
|
|
5384
|
+
* key) -- mirrored from the shell:
|
|
5385
|
+
*
|
|
5386
|
+
* - an action item (any `type` but "brand", "avatar", "connection");
|
|
5387
|
+
* - the menu a dropdown opens (`action.type` "dropdown"), named as
|
|
5388
|
+
* its trigger, except an avatar's, which the shell names "user
|
|
5389
|
+
* menu";
|
|
5390
|
+
* - each entry of that menu (`action.items`) that is drawn: not a
|
|
5391
|
+
* divider, and with an `action` of its own;
|
|
5392
|
+
* - each row the SITE MAP draws under a toolbar node that is not the
|
|
5393
|
+
* brand -- its `submenu.items`, else the `items` of its dropdown
|
|
5394
|
+
* action, down every level, an entry with no `action` included --,
|
|
5395
|
+
* labelled as the toolbar names a control: `aria_label || name ||
|
|
5396
|
+
* id`, but "user menu" for a row typed "avatar" and "backend
|
|
5397
|
+
* connection" for one typed "connection" (route_map_model.js,
|
|
5398
|
+
* toolbar_item_label()).
|
|
5399
|
+
*
|
|
5400
|
+
* A brand is named by its `wordmark`, which it must have to be drawn;
|
|
5401
|
+
* an avatar and a connection button by the shell's own "user menu" and
|
|
5402
|
+
* "backend connection". A `name` or an `aria_label` is read wherever it
|
|
5403
|
+
* stands (keys_from_shell_config()).
|
|
5404
|
+
***************************************************************/
|
|
5405
|
+
function toolbar_item_keys(config, keys, is_key)
|
|
5406
|
+
{
|
|
5407
|
+
let tb = config && config.toolbar;
|
|
5408
|
+
let items = (tb && typeof tb === "object" && Array.isArray(tb.items))? tb.items : [];
|
|
5409
|
+
let ask = (v) => {
|
|
5410
|
+
if(typeof v === "string" && v && is_key(v)) {
|
|
5411
|
+
keys.add(v);
|
|
5412
|
+
}
|
|
5413
|
+
};
|
|
5414
|
+
let nameless = (it) => !it.aria_label && !it.name;
|
|
5415
|
+
/* The rows the site map walks under a node: its `submenu.items`, else
|
|
5416
|
+
* the `items` of a dropdown action (nav_node_from_item()) */
|
|
5417
|
+
let map_rows = (it) => {
|
|
5418
|
+
if(it.submenu && Array.isArray(it.submenu.items)) {
|
|
5419
|
+
return it.submenu.items;
|
|
5420
|
+
}
|
|
5421
|
+
let a = it.action;
|
|
5422
|
+
return (a && typeof a === "object" && a.type === "dropdown" && Array.isArray(a.items))? a.items : [];
|
|
5423
|
+
};
|
|
5424
|
+
let read_map_rows = (rows) => {
|
|
5425
|
+
for(let sub of rows) {
|
|
5426
|
+
if(!sub || typeof sub !== "object" || sub.type === "divider" || sub.type === "header") {
|
|
5427
|
+
continue;
|
|
5428
|
+
}
|
|
5429
|
+
if(nameless(sub) && sub.type !== "avatar" && sub.type !== "connection") {
|
|
5430
|
+
ask(sub.id);
|
|
5431
|
+
}
|
|
5432
|
+
read_map_rows(map_rows(sub));
|
|
5433
|
+
}
|
|
5434
|
+
};
|
|
5435
|
+
for(let it of items) {
|
|
5436
|
+
if(!it || typeof it !== "object") {
|
|
5437
|
+
continue;
|
|
5438
|
+
}
|
|
5439
|
+
let kind = (it.type === "brand" || it.type === "avatar" || it.type === "connection")? it.type : "action";
|
|
5440
|
+
if(kind === "action" && nameless(it)) {
|
|
5441
|
+
ask(it.id);
|
|
5442
|
+
}
|
|
5443
|
+
let action = (it.action && typeof it.action === "object")? it.action : {};
|
|
5444
|
+
if(action.type === "dropdown") {
|
|
5445
|
+
if(kind !== "avatar" && nameless(it)) {
|
|
5446
|
+
ask(it.id);
|
|
5447
|
+
}
|
|
5448
|
+
for(let sub of (Array.isArray(action.items)? action.items : [])) {
|
|
5449
|
+
if(!sub || typeof sub !== "object" || sub.type === "divider"
|
|
5450
|
+
|| !sub.action || typeof sub.action !== "object") {
|
|
5451
|
+
continue;
|
|
5452
|
+
}
|
|
5453
|
+
if(nameless(sub)) {
|
|
5454
|
+
ask(sub.id);
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5457
|
+
}
|
|
5458
|
+
/* The brand is the ROOT of the site map, named by its wordmark: no
|
|
5459
|
+
* node of its own, and no rows under it */
|
|
5460
|
+
if(kind !== "brand") {
|
|
5461
|
+
read_map_rows(map_rows(it));
|
|
5462
|
+
}
|
|
5463
|
+
}
|
|
4962
5464
|
}
|
|
4963
5465
|
|
|
4964
5466
|
/***************************************************************
|