@skillstech/thunderlang 1.4.0 → 1.4.1

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.
@@ -10,8 +10,10 @@
10
10
  //
11
11
  // Which rules count as the same: decisions whose rule has the same condition, comparing names as words
12
12
  // (orderTotal, OrderTotal, and order_total are the same name), numbers by value, and comparisons and text exactly.
13
- // A rule with the same shape where only the names or only the values differ is listed as "not included, check by
14
- // hand", never changed. Test files are never edited; those that mention the rule's old values are listed.
13
+ // The same condition in a decision whose name shares no word with the chosen one (couponAllowed next to
14
+ // shippingFee, both "subtotal >= 50") is a different rule that happens to use the same limit, so it is listed, not
15
+ // changed. A rule with the same shape where only the names or only the values differ is listed as "not included,
16
+ // check by hand", never changed. Test files are never edited; those that mention the rule's old values are listed.
15
17
  //
16
18
  // Deterministic and browser-safe: it takes file contents and returns new contents. It never runs anything.
17
19
  import { readCode, sayCondition } from './read.mjs';
@@ -26,6 +28,10 @@ const editable = (t) => t.t === 'num' || t.t === 'str' || (t.t === 'op' && ['<',
26
28
  const keyOf = (t) => (t.t === 'id' ? `id:${words(t.v)}` : t.t === 'str' ? `str:${JSON.stringify(t.v)}` : `${t.t}:${t.v}`);
27
29
  const shapeOf = (t) => (t.t === 'id' ? 'id' : editable(t) ? (t.t === 'op' ? 'cmp' : t.t) : `${t.t}:${t.v}`);
28
30
  const join = (toks) => toks.map((t) => (t.t === 'str' ? JSON.stringify(t.v) : String(t.v))).join(' ');
31
+ // Words that say nothing about which rule a function is (get_shipping_fee and ShippingFee share "shipping").
32
+ const FILLER = new Set(['get', 'is', 'has', 'can', 'should', 'calc', 'calculate', 'compute', 'check', 'find', 'the', 'a', 'an', 'of', 'for', 'to', 'by']);
33
+ const nameWords = (name) => new Set(words(name).split(' ').filter((w) => w && !FILLER.has(w)));
34
+ const sharesWord = (a, b) => { const A = nameWords(a); return [...nameWords(b)].some((w) => A.has(w)); };
29
35
  const toks = (when) => { try { return tokenize(when); } catch { return null; } };
30
36
 
31
37
  /** Every decision rule in the parts' source files (test files left out), read once. */
@@ -75,7 +81,11 @@ export function findSameRule(files, { decision, rule }) {
75
81
  if (x === anchor) continue;
76
82
  const k = x.toks.map(keyOf).join(' ');
77
83
  const said = sayCondition(x.when);
78
- if (k === key) { same.push({ ...x, why: `the same condition: ${said} (names compared as words)` }); continue; }
84
+ if (k === key) {
85
+ if (sharesWord(x.decision, anchor.decision)) same.push({ ...x, why: `the same condition: ${said} (names compared as words)` });
86
+ else notIncluded.push({ ...x, why: `the same condition (${said}) in ${x.decision}, whose name shares no word with ${anchor.decision}; it may be a different rule that happens to use the same limit` });
87
+ continue;
88
+ }
79
89
  if (x.toks.map(shapeOf).join(' ') !== shape) continue;
80
90
  const xNames = x.toks.filter((t) => t.t === 'id').map(keyOf).join(' ');
81
91
  const xValues = x.toks.filter((t) => t.t !== 'id').map(keyOf).join(' ');