@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
|
@@ -25,6 +25,14 @@
|
|
|
25
25
|
* - the table is CORRECT (V22): the same search started from no
|
|
26
26
|
* table finds every entry, at every position, with the same
|
|
27
27
|
* `exported` -- an entry nothing forwards to fails;
|
|
28
|
+
* - a position the table declares the FALLBACK of others
|
|
29
|
+
* (`fallbacks`: a card's id, behind its name and aria_label) is
|
|
30
|
+
* one in the code: every hand-off of it is the right side of a
|
|
31
|
+
* `||` whose left reads those positions;
|
|
32
|
+
* - a `code` is a key only in the modules whose codes reach t()
|
|
33
|
+
* (CODE_KEY_MODULES), and those are the modules that write one;
|
|
34
|
+
* - the reader gives up on no value of the library (a chain too
|
|
35
|
+
* deep, a const that leads back to itself, too many values);
|
|
28
36
|
* - a parameter handed on through what no position can name (V22:
|
|
29
37
|
* `k.toLowerCase()`, a concatenation, `Object.entries(opts)`, a
|
|
30
38
|
* rest parameter walked, `arguments[i]`, an array pattern) fails,
|
|
@@ -40,6 +48,10 @@
|
|
|
40
48
|
* from one (`t("k") + ":"`) -- marked or not. A translator handed
|
|
41
49
|
* as a callback (V23.5: `keys.map(t)`, `promise.then(t)`) is held
|
|
42
50
|
* the same way, each element it walks a key position;
|
|
51
|
+
* - no module hands a TRANSLATED text to any other place a key is
|
|
52
|
+
* read -- t(), an i18n / code / data-i18n* value, a data-i18n*
|
|
53
|
+
* attribute --, marked or not (V24.5.2: up to 7.26.41 only a
|
|
54
|
+
* marked one failed);
|
|
43
55
|
* - every marker is one and stands where a key is read; the lists
|
|
44
56
|
* it names are published by its module or one it imports; the
|
|
45
57
|
* keys it marks that can be read are in them -- a marked `let`
|
|
@@ -73,6 +85,8 @@ import {fileURLToPath, pathToFileURL} from "node:url";
|
|
|
73
85
|
|
|
74
86
|
import {I18N_KEY_FUNCTIONS} from "./i18n_key_functions.js";
|
|
75
87
|
import {
|
|
88
|
+
CODE_KEY_MODULES,
|
|
89
|
+
gave_up,
|
|
76
90
|
parse_source,
|
|
77
91
|
walk,
|
|
78
92
|
line_of,
|
|
@@ -934,6 +948,93 @@ function table_errors(found, table = I18N_KEY_FUNCTIONS)
|
|
|
934
948
|
}
|
|
935
949
|
|
|
936
950
|
|
|
951
|
+
/*
|
|
952
|
+
* A FALLBACK of the table is one in the code: every hand-off of the
|
|
953
|
+
* position, in its function, is the right operand of a `||` / `??`
|
|
954
|
+
* chain whose left operands read every position the entry names as
|
|
955
|
+
* read first (`it.name || it.aria_label || it.id`, the left read
|
|
956
|
+
* through a `let` or a const too) -- or a key position of a key
|
|
957
|
+
* function whose own fallbacks are positions of this one, handed
|
|
958
|
+
* there with it (`{...it}`, not `{id: it.id}`, which drops them). A
|
|
959
|
+
* fallback the code does not show would let the validator skip a key
|
|
960
|
+
* the function asks for.
|
|
961
|
+
*/
|
|
962
|
+
function fallback_errors(table = I18N_KEY_FUNCTIONS, asts = ast_of)
|
|
963
|
+
{
|
|
964
|
+
let out = [];
|
|
965
|
+
let ancestors_of = (ast, node) => {
|
|
966
|
+
let found = null;
|
|
967
|
+
walk(ast, (n, ancestors) => {
|
|
968
|
+
if(!found && n === node) {
|
|
969
|
+
found = ancestors.slice();
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
return found || [];
|
|
973
|
+
};
|
|
974
|
+
let guards_in_code = (ast, e, node) => {
|
|
975
|
+
let guards = new Set();
|
|
976
|
+
let ancestors = ancestors_of(ast, node);
|
|
977
|
+
let cur = node;
|
|
978
|
+
for(let i = ancestors.length - 1; i >= 0; i--) {
|
|
979
|
+
let a = ancestors[i];
|
|
980
|
+
if(a.type === "LogicalExpression" && a.operator !== "&&" && a.right === cur) {
|
|
981
|
+
for(let f of param_flows(a.left, ancestors.slice(0, i + 1))) {
|
|
982
|
+
if(f.binding.name === e.name && f.path !== null) {
|
|
983
|
+
guards.add(`${f.binding.index}${f.path}`);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
} else if(!(a.type === "LogicalExpression" && a.left === cur)
|
|
987
|
+
&& !(a.type === "ConditionalExpression" && a.test !== cur)
|
|
988
|
+
&& a.type !== "ChainExpression") {
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
cur = a;
|
|
992
|
+
}
|
|
993
|
+
return guards;
|
|
994
|
+
};
|
|
995
|
+
let modules = [...new Set(table.filter((e) => e.fallbacks).map((e) => e.module))];
|
|
996
|
+
for(let module of modules) {
|
|
997
|
+
let ast = asts(module);
|
|
998
|
+
let entries = table.filter((e) => e.module === module && e.fallbacks);
|
|
999
|
+
for(let place of key_places(ast, {lib_module: module, table})) {
|
|
1000
|
+
for(let leaf of place.leaves) {
|
|
1001
|
+
for(let p of handed_params(leaf)) {
|
|
1002
|
+
let pos = `${p.binding.index}${p.path}`;
|
|
1003
|
+
let e = entries.find((x) => x.name === p.binding.name && x.fallbacks[pos]);
|
|
1004
|
+
if(!e) {
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
let guards;
|
|
1008
|
+
let callee_firsts = (place.what === "call" && place.entry.fallbacks)?
|
|
1009
|
+
place.entry.fallbacks[place.path] : null;
|
|
1010
|
+
if(callee_firsts) {
|
|
1011
|
+
/* What the callee reads first, where it is handed: the
|
|
1012
|
+
* positions of this function that arrive there */
|
|
1013
|
+
let k = key_calls(ast, module, table).find((c) => c.call === place.node);
|
|
1014
|
+
guards = new Set();
|
|
1015
|
+
for(let f of callee_firsts) {
|
|
1016
|
+
for(let l of values_at(k.call, f, k.scope, k.args)) {
|
|
1017
|
+
if(l.kind === "param" && l.binding.name === e.name && l.path !== null) {
|
|
1018
|
+
guards.add(`${l.binding.index}${l.path}`);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
} else {
|
|
1023
|
+
guards = guards_in_code(ast, e, p.node);
|
|
1024
|
+
}
|
|
1025
|
+
let lacking = e.fallbacks[pos].filter((f) => !guards.has(f));
|
|
1026
|
+
if(lacking.length > 0) {
|
|
1027
|
+
out.push(`${module}:${line_of(ast, p.node.start)} ${e.name}() hands [${pos}] to a place a key ` +
|
|
1028
|
+
`is read without reading [${lacking.join(", ")}] first: its \`fallbacks\` in ` +
|
|
1029
|
+
`I18N_KEY_FUNCTIONS say otherwise`);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return [...new Set(out)];
|
|
1036
|
+
}
|
|
1037
|
+
|
|
937
1038
|
describe("I18N_KEY_FUNCTIONS: the table", () => {
|
|
938
1039
|
test("every entry names a function of its module, at positions that can be followed", () => {
|
|
939
1040
|
let wrong = [];
|
|
@@ -969,6 +1070,29 @@ describe("I18N_KEY_FUNCTIONS: the table", () => {
|
|
|
969
1070
|
wrong.push(`${where}: key position ${JSON.stringify(k)} cannot be followed`);
|
|
970
1071
|
}
|
|
971
1072
|
}
|
|
1073
|
+
if(e.fallbacks === undefined) {
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
1076
|
+
if(!e.fallbacks || typeof e.fallbacks !== "object" || Array.isArray(e.fallbacks)) {
|
|
1077
|
+
wrong.push(`${where}: \`fallbacks\` is not an object`);
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
for(let [k, firsts] of Object.entries(e.fallbacks)) {
|
|
1081
|
+
let parent = k.slice(0, k.lastIndexOf(".") + 1);
|
|
1082
|
+
if(!e.keys.includes(k) || !parent) {
|
|
1083
|
+
wrong.push(`${where}: the fallback ${JSON.stringify(k)} is no property position of \`keys\``);
|
|
1084
|
+
}
|
|
1085
|
+
if(!Array.isArray(firsts) || firsts.length === 0) {
|
|
1086
|
+
wrong.push(`${where}: the fallback ${JSON.stringify(k)} names no position read first`);
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
for(let f of firsts) {
|
|
1090
|
+
if(f === k || !e.keys.includes(f) || !f.startsWith(parent) || f.slice(parent.length).includes("[]")) {
|
|
1091
|
+
wrong.push(`${where}: ${JSON.stringify(f)}, read before ${JSON.stringify(k)}, is no other ` +
|
|
1092
|
+
`position of \`keys\` under ${JSON.stringify(parent)}`);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
972
1096
|
}
|
|
973
1097
|
expect(wrong).toEqual([]);
|
|
974
1098
|
});
|
|
@@ -983,6 +1107,38 @@ describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
|
983
1107
|
expect(table_errors(find_forwarders(MODULES, ast_of, []).found)).toEqual([]);
|
|
984
1108
|
});
|
|
985
1109
|
|
|
1110
|
+
test("every fallback of the table is one in the code, and the check fails when it is not", () => {
|
|
1111
|
+
expect(fallback_errors()).toEqual([]);
|
|
1112
|
+
let module = "nav_cards_helpers.js";
|
|
1113
|
+
let wider = I18N_KEY_FUNCTIONS.map((e) => (e.name !== "card_descriptor")? e :
|
|
1114
|
+
Object.assign({}, e, {fallbacks: {"0.id": ["0.name", "0.aria_label", "0.tooltip"]}}));
|
|
1115
|
+
expect(fallback_errors(wider)).toEqual([
|
|
1116
|
+
`${module}:55 card_descriptor() hands [0.id] to a place a key is read without reading [0.tooltip] ` +
|
|
1117
|
+
`first: its \`fallbacks\` in I18N_KEY_FUNCTIONS say otherwise`
|
|
1118
|
+
]);
|
|
1119
|
+
let code = readFileSync(join(SRC, module), "utf8");
|
|
1120
|
+
let plain = code.replace('"data-disabled": it.disabled ? "1" : "0",',
|
|
1121
|
+
'"data-disabled": it.disabled ? "1" : "0", "data-i18n-placeholder": it.id,');
|
|
1122
|
+
expect(plain).not.toBe(code);
|
|
1123
|
+
let mutated = parse_as(plain, module);
|
|
1124
|
+
expect(fallback_errors(I18N_KEY_FUNCTIONS, (m) => (m === module)? mutated : ast_of(m))).toEqual([
|
|
1125
|
+
`${module}:61 card_descriptor() hands [0.id] to a place a key is read without reading [0.name, ` +
|
|
1126
|
+
`0.aria_label] first: its \`fallbacks\` in I18N_KEY_FUNCTIONS say otherwise`
|
|
1127
|
+
]);
|
|
1128
|
+
/* A hand-off to a key function counts its fallbacks only when they
|
|
1129
|
+
* arrive with the id: `{id: it.id}` drops them (7.26.42's right-click) */
|
|
1130
|
+
let shell = "c_yui_shell.js";
|
|
1131
|
+
let shell_code = readFileSync(join(SRC, shell), "utf8");
|
|
1132
|
+
let dropped = shell_code.replace("{...it, action: it.context_action}", "{id: it.id, action: it.context_action}");
|
|
1133
|
+
expect(dropped).not.toBe(shell_code);
|
|
1134
|
+
let shell_mutated = parse_as(dropped, shell);
|
|
1135
|
+
let table = I18N_KEY_FUNCTIONS.map((e) => (e.name !== "attach_context_action")? e :
|
|
1136
|
+
Object.assign({}, e, {keys: ["2.id"]}));
|
|
1137
|
+
let said = fallback_errors(table, (m) => (m === shell)? shell_mutated : ast_of(m));
|
|
1138
|
+
expect(said.length).toBe(1);
|
|
1139
|
+
expect(said[0]).toMatch(/^c_yui_shell\.js:\d+ attach_context_action\(\) hands \[2\.id\] to a place a key is read without reading \[2\.aria_label, 2\.name\] first/);
|
|
1140
|
+
});
|
|
1141
|
+
|
|
986
1142
|
test("the search finds what it should, and nothing else", () => {
|
|
987
1143
|
let code = [
|
|
988
1144
|
`import {yui_shell_show_error} from "./shell_modals.js";`,
|
|
@@ -995,14 +1151,16 @@ describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
|
995
1151
|
`function by_pattern(gobj, {title, label = "fallback"}) { return t(title); }`,
|
|
996
1152
|
`function ac_show(gobj, event, kw, src) { yui_shell_show_error(shell, kw.comment); }`,
|
|
997
1153
|
`function ac_marked(gobj, event, kw, src) { return t(/* i18n: data */ kw.comment); }`,
|
|
998
|
-
`
|
|
1154
|
+
`function by_bind(gobj, msg) { return yui_shell_show_error.bind(null, shell, msg); }`,
|
|
1155
|
+
`function by_bound_t(gobj, key) { return t.bind(null, key); }`,
|
|
1156
|
+
`say(); told(); relay(); own(); as_dom(); by_let(); by_pattern(); by_bind(); by_bound_t();`
|
|
999
1157
|
].join("\n");
|
|
1000
1158
|
let ast = parse_as(code, "x.js");
|
|
1001
1159
|
let found = find_forwarders(["x.js"], () => ast);
|
|
1002
1160
|
let got = Object.fromEntries(found.missing.map((m) => [m.name, m.keys.sort()]));
|
|
1003
1161
|
expect(got).toEqual({
|
|
1004
1162
|
say: ["1"], told: ["1.message"], relay: ["1"], as_dom: ["1"],
|
|
1005
|
-
by_let: ["1.name"], by_pattern: ["1.title"]
|
|
1163
|
+
by_let: ["1.name"], by_pattern: ["1.title"], by_bind: ["1"], by_bound_t: ["1"]
|
|
1006
1164
|
});
|
|
1007
1165
|
expect(found.unmarked.map((u) => `${u.name} ${u.pos}`)).toEqual(["ac_show 2.comment"]);
|
|
1008
1166
|
|
|
@@ -1035,6 +1193,55 @@ describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
|
1035
1193
|
});
|
|
1036
1194
|
});
|
|
1037
1195
|
|
|
1196
|
+
describe("a `code` is a key where the library makes one", () => {
|
|
1197
|
+
test("the modules that write a literal `code` are CODE_KEY_MODULES, and only those", () => {
|
|
1198
|
+
let writers = new Set();
|
|
1199
|
+
for(let module of MODULES) {
|
|
1200
|
+
walk(ast_of(module), (n, ancestors) => {
|
|
1201
|
+
let parent = ancestors[ancestors.length - 1];
|
|
1202
|
+
if(n.type === "Property" && parent && parent.type === "ObjectExpression"
|
|
1203
|
+
&& !n.computed && ((n.key.type === "Identifier" && n.key.name === "code")
|
|
1204
|
+
|| (n.key.type === "Literal" && n.key.value === "code"))
|
|
1205
|
+
&& n.value.type === "Literal" && typeof n.value.value === "string") {
|
|
1206
|
+
writers.add(module);
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
expect([...writers].sort()).toEqual([...CODE_KEY_MODULES].sort());
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
test("there a literal `code` is asked for; in any other module it is not", () => {
|
|
1214
|
+
let code = `let finding = {severity: "error", code: "a finding code"};`;
|
|
1215
|
+
expect([...scan_ast(parse_as(code, "schema_validate.js"), {lib_module: "schema_validate.js"}).keys])
|
|
1216
|
+
.toEqual(["a finding code"]);
|
|
1217
|
+
expect([...scan_ast(parse_as(code, "x.js"), {lib_module: "x.js"}).keys]).toEqual([]);
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1221
|
+
describe("the reader never gives up on the library", () => {
|
|
1222
|
+
test("no chain too deep, no const that leads back to itself, no value with too many values", () => {
|
|
1223
|
+
let said = [];
|
|
1224
|
+
for(let module of MODULES) {
|
|
1225
|
+
let ast = ast_of(module);
|
|
1226
|
+
scan_ast(ast, {lib_module: module});
|
|
1227
|
+
call_rule_violations(ast, module);
|
|
1228
|
+
said.push(...gave_up(ast).map((g) => `${module}:${g.line} \`${g.text}\`: ${g.why}`));
|
|
1229
|
+
}
|
|
1230
|
+
expect(said).toEqual([]);
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
test("...and says where it would", () => {
|
|
1234
|
+
let lines = [`const K0 = "far";`];
|
|
1235
|
+
for(let i = 1; i <= 24; i++) {
|
|
1236
|
+
lines.push(`const K${i} = K${i - 1};`);
|
|
1237
|
+
}
|
|
1238
|
+
lines.push(`function f() { return t(K24); }`);
|
|
1239
|
+
let ast = parse_as(lines.join("\n"), "x.js");
|
|
1240
|
+
scan_ast(ast, {lib_module: "x.js"});
|
|
1241
|
+
expect(gave_up(ast).map((g) => `${g.line} ${g.text}`)).toEqual([`1 "far"`]);
|
|
1242
|
+
});
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1038
1245
|
describe("the rule, per call: a key position gets what the validator can read, or a marker", () => {
|
|
1039
1246
|
test("every call of a key function, in every module of the library", () => {
|
|
1040
1247
|
let wrong = [];
|
|
@@ -2009,8 +2216,9 @@ describe("REV-CLOUD V23.5: a translator as a callback, by destructuring; setAttr
|
|
|
2009
2216
|
let r = scan([`t(/* i18n: data */ t("k") + "!");`,
|
|
2010
2217
|
`x.i18n = /* i18n: data */ t("k").trim();`,
|
|
2011
2218
|
`t(/* i18n: data */ kw.comment + "!");`]);
|
|
2012
|
-
expect(r.
|
|
2013
|
-
expect(r.
|
|
2219
|
+
expect(r.translated_errors.map((e) => e.line)).toEqual([3, 4]);
|
|
2220
|
+
expect(r.translated_errors[0].why).toMatch(/^marked as data, but `t\("k"\) \+ "!"` is a TRANSLATED text: .*hand the key, not t\(key\)$/);
|
|
2221
|
+
expect(r.marker_errors).toEqual([]);
|
|
2014
2222
|
});
|
|
2015
2223
|
|
|
2016
2224
|
test("an UNMARKED let given nothing but literals is read where a key is read -- at a key position the rule still fails it", () => {
|
|
@@ -2057,3 +2265,193 @@ describe("REV-CLOUD V23.5: a translator as a callback, by destructuring; setAttr
|
|
|
2057
2265
|
expect(list_mutations(ast, [{name: "X_I18N_KEYS", keys: ["x"]}]).map((e) => e.line)).toEqual([5, 7, 8, 10, 18]);
|
|
2058
2266
|
});
|
|
2059
2267
|
});
|
|
2268
|
+
|
|
2269
|
+
describe("REV-CLOUD V24.5: every write counts; a translated text fails unmarked too; the callbacks, exactly; .bind()", () => {
|
|
2270
|
+
let module = "x.js";
|
|
2271
|
+
let head = [`import {yui_shell_show_info} from "./shell_modals.js";`,
|
|
2272
|
+
`import i18next from "i18next";`];
|
|
2273
|
+
let scan = (lines) => scan_ast(parse_as([...head, ...lines].join("\n"), module), {lib_module: module});
|
|
2274
|
+
let rule = (lines) => rule_report(parse_as([...head, ...lines].join("\n"), module), module);
|
|
2275
|
+
let keys_of = (lines) => [...scan(lines).keys].sort();
|
|
2276
|
+
|
|
2277
|
+
test("every write to an unmarked let counts: one the reader cannot read leaves it unfollowed", () => {
|
|
2278
|
+
/* Each body gives `key` the sentinel "-" and then a value the reader
|
|
2279
|
+
* does not read: up to 7.26.41 the eight first asked for "-" */
|
|
2280
|
+
let writes = [
|
|
2281
|
+
`for([key, label] of rows) { el.setAttribute("data-i18n", key); }`, // the review's probe
|
|
2282
|
+
`for({key} of rows) { t(key); }`,
|
|
2283
|
+
`for({k: key = "d"} of rows) { t(key); }`,
|
|
2284
|
+
`for([key] in obj) { t(key); }`,
|
|
2285
|
+
`for await ([key] of rows) { t(key); }`,
|
|
2286
|
+
`for(key of rows) { t(key); }`,
|
|
2287
|
+
`for(key in obj) { t(key); }`,
|
|
2288
|
+
`[key, x] = rows;`,
|
|
2289
|
+
`({key} = row);`,
|
|
2290
|
+
`[[key]] = rows;`,
|
|
2291
|
+
`rows.forEach((r) => { ({key} = r); });`,
|
|
2292
|
+
`key += "!";`,
|
|
2293
|
+
`key = kw.label;`,
|
|
2294
|
+
`eval(code);`
|
|
2295
|
+
];
|
|
2296
|
+
for(let w of writes) {
|
|
2297
|
+
expect(keys_of([`async function f(el, rows, obj, row, kw, code) {`, ` let key = "-";`,
|
|
2298
|
+
` ${w}`, ` return t(key);`, `}`]), w).not.toContain("-");
|
|
2299
|
+
}
|
|
2300
|
+
/* A `var` declared again: in a loop head (function and module), and
|
|
2301
|
+
* -- for one of the module -- in a block, a for(;;) init, a switch
|
|
2302
|
+
* case, or by an array pattern */
|
|
2303
|
+
let redeclared = [
|
|
2304
|
+
[`function f(rows) {`, ` var key = "-";`, ` for(var key of rows) {`, ` }`, ` return t(key);`, `}`],
|
|
2305
|
+
[`function f(obj) {`, ` var key = "-";`, ` for(var key in obj) {`, ` }`, ` return t(key);`, `}`],
|
|
2306
|
+
[`var key = "-";`, `for(var key of rows) {`, `}`, `t(key);`],
|
|
2307
|
+
[`var key = "-";`, `if(c) {`, ` var key = kw.data;`, `}`, `t(key);`],
|
|
2308
|
+
[`var key = "-";`, `for(var key = kw.data; c; ) {`, `}`, `t(key);`],
|
|
2309
|
+
[`var key = "-";`, `switch(c) {`, ` case 1:`, ` var key = kw.data;`, `}`, `t(key);`],
|
|
2310
|
+
[`var key = "-";`, `var [key] = rows;`, `t(key);`]
|
|
2311
|
+
];
|
|
2312
|
+
for(let lines of redeclared) {
|
|
2313
|
+
expect(keys_of(lines), lines.join(" ")).not.toContain("-");
|
|
2314
|
+
}
|
|
2315
|
+
/* ...and one whose every value is a literal still asks for them, a
|
|
2316
|
+
* module `var` given more in a block included */
|
|
2317
|
+
expect(keys_of([`var key = "a module key";`, `if(c) {`, ` var key = "a block key";`, `}`, `t(key);`]))
|
|
2318
|
+
.toEqual(["a block key", "a module key"]);
|
|
2319
|
+
/* An INDIRECT eval -- `eval?.()`, `(0, eval)()` -- runs in the global
|
|
2320
|
+
* scope and writes no variable of the module: the let is still
|
|
2321
|
+
* followed (up to 7.26.42 `eval?.()` counted as a direct eval) */
|
|
2322
|
+
for(let call of [`eval?.(code);`, `(0, eval)(code);`]) {
|
|
2323
|
+
expect(keys_of([`function f(code) {`, ` let key = "an eval-proof key";`, ` ${call}`,
|
|
2324
|
+
` return t(key);`, `}`]), call).toEqual(["an eval-proof key"]);
|
|
2325
|
+
}
|
|
2326
|
+
/* A `var` of a class's static block is the block's own: it hides an
|
|
2327
|
+
* outer `let` of the same name (up to 7.26.41 it was not seen) */
|
|
2328
|
+
expect(keys_of([`let key = "-";`, `class A {`, ` static {`, ` var key = kw.data;`, ` t(key);`,
|
|
2329
|
+
` }`, `}`])).not.toContain("-");
|
|
2330
|
+
expect(keys_of([`class A {`, ` static {`, ` var key = "a static key";`, ` t(key);`, ` }`, `}`]))
|
|
2331
|
+
.toEqual(["a static key"]);
|
|
2332
|
+
/* A marked let written by a loop head is no "make it a const" */
|
|
2333
|
+
expect(scan([`export const X_I18N_KEYS = ["accept"];`, `let k = "accept";`, `for([k] of rows) {`, `}`,
|
|
2334
|
+
`t(/* i18n: X_I18N_KEYS */ k);`]).marker_errors).toEqual([]);
|
|
2335
|
+
expect(scan([`export const X_I18N_KEYS = ["accept"];`, `let LABELS = {ok: "accept"};`,
|
|
2336
|
+
`for(LABELS.extra of rows) {`, `}`, `t(/* i18n: X_I18N_KEYS */ LABELS[k]);`]).marker_errors).toEqual([]);
|
|
2337
|
+
});
|
|
2338
|
+
|
|
2339
|
+
test("the let rule is flow-INSENSITIVE: every literal the let is given in its scope is asked for; null is never", () => {
|
|
2340
|
+
let body = (first) => [`function f(c) {`, ` let key = ${first};`, ` if(c) {`, ` key = "save";`, ` }`,
|
|
2341
|
+
` if(key !== "-") {`, ` t(key);`, ` }`, `}`];
|
|
2342
|
+
expect(keys_of(body(`"-"`))).toEqual(["-", "save"]); // the `if` does not hide "-"
|
|
2343
|
+
expect(keys_of(body(`null`))).toEqual(["save"]); // the way out for a sentinel
|
|
2344
|
+
expect(keys_of([`const NONE = "-";`, ...body(`NONE`)])).toEqual(["-", "save"]); // a const IS its literal
|
|
2345
|
+
});
|
|
2346
|
+
|
|
2347
|
+
test("a TRANSLATED text where a key is read fails, marked or not", () => {
|
|
2348
|
+
let r = scan([`x = {i18n: t("k")};`, // 3
|
|
2349
|
+
`el.setAttribute("data-i18n-title", t("k"));`, // 4
|
|
2350
|
+
`t(t("k") + "!");`, // 5
|
|
2351
|
+
`el.dataset.i18nTitle = tr("k");`, // 6
|
|
2352
|
+
`x = {code: i18next.t("k")};`, // 7: no key place in x.js
|
|
2353
|
+
`add("error", t("k"));`, // 8: no key function
|
|
2354
|
+
`t([t("k"), "fallback"]);`, // 9
|
|
2355
|
+
`const L = t("k");`, // 10: the text, read at 11
|
|
2356
|
+
`x = {"data-i18n": L};`,
|
|
2357
|
+
`x = {i18n: /* i18n: data */ t("k")};`, // 12: marked
|
|
2358
|
+
`x = {i18n: ["p", {}, t("k")]};`, // DOM is DOM
|
|
2359
|
+
`let held = t("k");`,
|
|
2360
|
+
`x = {i18n: held};`]); // in a let: the documented limit
|
|
2361
|
+
expect(r.translated_errors.map((e) => e.line)).toEqual([3, 4, 5, 6, 9, 10, 12]);
|
|
2362
|
+
expect(r.translated_errors[0].why).toBe('`t("k")` is a TRANSLATED text given to a property that holds a key ' +
|
|
2363
|
+
'(i18n, code, data-i18n*): the translation is kept as its key and never changes language: hand the key, ' +
|
|
2364
|
+
'not t(key)');
|
|
2365
|
+
expect(r.translated_errors[1].why).toMatch(/^`t\("k"\)` is a TRANSLATED text given to a data-i18n\* attribute: /);
|
|
2366
|
+
expect(r.translated_errors[2].why).toMatch(/^`t\("k"\) \+ "!"` is a TRANSLATED text handed to a translator as its key: /);
|
|
2367
|
+
expect(r.translated_errors[5].why).toMatch(/^`t\("k"\)` is a TRANSLATED text given to a property .* \(read at line 11\): /);
|
|
2368
|
+
expect(r.translated_errors[6].why).toMatch(/^marked as data, but `t\("k"\)` is a TRANSLATED text: .*no marker excuses it/);
|
|
2369
|
+
expect(r.marker_errors).toEqual([]);
|
|
2370
|
+
/* Where a `code` is a key, a translated one fails as well */
|
|
2371
|
+
let c = scan_ast(parse_as([`x = {code: i18next.t("k")};`].join("\n"), "schema_import.js"),
|
|
2372
|
+
{lib_module: "schema_import.js"});
|
|
2373
|
+
expect(c.translated_errors.map((e) => e.line)).toEqual([1]);
|
|
2374
|
+
});
|
|
2375
|
+
|
|
2376
|
+
test("no module of the library hands a TRANSLATED text to a place a key is read", () => {
|
|
2377
|
+
let wrong = [];
|
|
2378
|
+
for(let m of MODULES) {
|
|
2379
|
+
for(let e of scan_ast(ast_of(m), {lib_module: m}).translated_errors) {
|
|
2380
|
+
wrong.push(`${m}:${e.line}: ${e.why}`);
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
expect(wrong).toEqual([]);
|
|
2384
|
+
/* ...and the check sees one: a module given one, unmarked */
|
|
2385
|
+
let code = readFileSync(join(SRC, "yui_text.js"), "utf8");
|
|
2386
|
+
let lines = code.split("\n").length;
|
|
2387
|
+
let mutated = parse_as(code + `\nexport function probe(el) { el.setAttribute("data-i18n", t("probe")); }\n`,
|
|
2388
|
+
"yui_text.js");
|
|
2389
|
+
expect(scan_ast(mutated, {lib_module: "yui_text.js"}).translated_errors.map((e) => e.line)).toEqual([lines + 1]);
|
|
2390
|
+
});
|
|
2391
|
+
|
|
2392
|
+
test("the callbacks read, exactly: findIndex, findLastIndex, .call(), .apply(), a literal name, Array.fromAsync()", () => {
|
|
2393
|
+
expect(keys_of([`const K = ["k1", "k2"];`,
|
|
2394
|
+
`K.findIndex(t);`,
|
|
2395
|
+
`K.findLastIndex(i18next.t);`,
|
|
2396
|
+
`Array.prototype.map.call(["k3"], t);`,
|
|
2397
|
+
`[].forEach.call(["k4"], t);`,
|
|
2398
|
+
`Array.prototype.some.apply(["k5"], [t]);`,
|
|
2399
|
+
`["k6"]["every"](t);`,
|
|
2400
|
+
`Array.fromAsync(["k7"], t);`,
|
|
2401
|
+
`["k8"].reduce(t);`, // no element is the key
|
|
2402
|
+
`Reflect.apply(Array.prototype.map, ["k9"], [t]);`])).toEqual( // not read: documented
|
|
2403
|
+
["k1", "k2", "k3", "k4", "k5", "k6", "k7"]);
|
|
2404
|
+
/* A function callback's first parameter is an element in the same forms */
|
|
2405
|
+
expect(keys_of([`Array.prototype.forEach.call(["f1"], (k) => t(k));`,
|
|
2406
|
+
`[].map.apply(["f2"], [(k) => t(k)]);`,
|
|
2407
|
+
`Array.from(["f3"], (k) => t(k));`,
|
|
2408
|
+
`["f4"].findIndex((k) => t(k));`])).toEqual(["f1", "f2", "f3", "f4"]);
|
|
2409
|
+
/* ...and the rule holds them: an array the reader cannot follow fails unmarked */
|
|
2410
|
+
expect(rule([`function f(kw) {`,
|
|
2411
|
+
` let rows = kw.rows;`,
|
|
2412
|
+
` Array.prototype.map.call(rows, t);`,
|
|
2413
|
+
` rows.findIndex(t);`,
|
|
2414
|
+
` [].forEach.apply(rows, [t]);`,
|
|
2415
|
+
` /* i18n: data */ Array.prototype.map.call(rows, t);`,
|
|
2416
|
+
`}`])).toEqual([
|
|
2417
|
+
`${module}:5 t() [map callback]: rows`,
|
|
2418
|
+
`${module}:6 t() [findIndex callback]: rows`,
|
|
2419
|
+
`${module}:7 t() [forEach callback]: rows`
|
|
2420
|
+
]);
|
|
2421
|
+
/* The forwarder search sees a parameter walked through .call() */
|
|
2422
|
+
let ast = parse_as(`export function f_call(gobj, keys) { Array.prototype.forEach.call(keys, t); }`, module);
|
|
2423
|
+
let found = find_forwarders([module], () => ast, []);
|
|
2424
|
+
expect(found.opaque).toEqual([]);
|
|
2425
|
+
expect(Object.fromEntries(found.found.map((f) => [f.name, f.keys]))).toEqual({f_call: ["1[]"]});
|
|
2426
|
+
});
|
|
2427
|
+
|
|
2428
|
+
test("a bound translator: what a call of it is handed is i18next's options, no key; a bound key function counts them", () => {
|
|
2429
|
+
/* The key it binds is read where the bind is written */
|
|
2430
|
+
expect(keys_of([`const tk = t.bind(null, "bound key");`,
|
|
2431
|
+
`tk("an option");`,
|
|
2432
|
+
`tk.call(null, "another option");`,
|
|
2433
|
+
`t.bind(i18next).bind(null, "bound key")("a third option");`,
|
|
2434
|
+
`["an element"].map(tk);`,
|
|
2435
|
+
`["another element"].map(t.bind(null, "bound key"));`,
|
|
2436
|
+
`const tt = t.bind(i18next);`,
|
|
2437
|
+
`tt("a key: nothing bound");`])).toEqual(["a key: nothing bound", "bound key"]);
|
|
2438
|
+
/* Its text is translated text all the same */
|
|
2439
|
+
expect(scan([`const tk = t.bind(null, "bound key");`, `x = {i18n: tk()};`]).translated_errors.map((e) => e.line))
|
|
2440
|
+
.toEqual([4]);
|
|
2441
|
+
/* A key function bound with its first argument: the key is the call's first one now */
|
|
2442
|
+
let r = scan([`const show = yui_shell_show_info.bind(null, shell);`, `show("a bound function key");`]);
|
|
2443
|
+
expect(r.keys.has("a bound function key")).toBe(true);
|
|
2444
|
+
expect(rule([`const show = yui_shell_show_info.bind(null, shell);`, `show(kw.message);`,
|
|
2445
|
+
`const more = yui_shell_show_info.bind(null, ...args);`, `more("k");`])).toEqual([
|
|
2446
|
+
`${module}:4 yui_shell_show_info() [1]: kw.message`,
|
|
2447
|
+
`${module}:5 yui_shell_show_info() [1]: ...args`, // what the bind hands, unknown: loud
|
|
2448
|
+
`${module}:6 yui_shell_show_info() [1]: more("k")` // a spread hides the positions: loud
|
|
2449
|
+
]);
|
|
2450
|
+
/* What a bind binds is read where it is written: keys asked, and the rule per call */
|
|
2451
|
+
let b = scan([`const say = yui_shell_show_info.bind(null, shell, "a bound message");`, `say();`,
|
|
2452
|
+
`const ask = yui_shell_show_info.bind(null, shell).bind(null, "a twice bound one");`]);
|
|
2453
|
+
expect([...b.keys].sort()).toEqual(["a bound message", "a twice bound one"]);
|
|
2454
|
+
expect(rule([`function relay(msg) {`, ` return yui_shell_show_info.bind(null, shell, msg);`, `}`]))
|
|
2455
|
+
.toEqual([`${module}:4 yui_shell_show_info() [1]: msg`]);
|
|
2456
|
+
});
|
|
2457
|
+
});
|