@rulecad/variables 0.3.2 → 0.3.3
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/package.json +1 -1
- package/variables.mjs +3 -0
package/package.json
CHANGED
package/variables.mjs
CHANGED
|
@@ -196,6 +196,7 @@ export function resolve(object, { sets = {}, set = {}, display = {}, load } = {}
|
|
|
196
196
|
// deps: each name's own references (what its expression reads), for explaining a value; stack: whose expression is being read
|
|
197
197
|
const done = new Map(), busy = new Set(), deps = new Map(), stack = [];
|
|
198
198
|
const pathOf = (name) => (name.includes('.') ? `rules.${name}.value` : `variables.${name}.value`);
|
|
199
|
+
const ruleOf = (name) => { let [t, r] = name.split('.'); if (!own(ruleSets, t)) t = t.replace(/_/g, '-'); return ruleSets[t]?.rules[r]; };
|
|
199
200
|
const lookup = (name) => {
|
|
200
201
|
if (stack.length) deps.get(stack[stack.length - 1]).add(name);
|
|
201
202
|
if (done.has(name)) return done.get(name);
|
|
@@ -221,6 +222,8 @@ export function resolve(object, { sets = {}, set = {}, display = {}, load } = {}
|
|
|
221
222
|
deps.set(name, new Set()); stack.push(name);
|
|
222
223
|
try { v = evaluate(src, (n) => lookup(where(n))); } catch (e) {
|
|
223
224
|
busy.delete(name); stack.pop();
|
|
225
|
+
// A rule with words for a value and no unit (a bearing's "radial", a pinout) is text, read as it is
|
|
226
|
+
if (name.includes('.') && typeof src === 'string' && !ruleOf(name)?.unit) { done.set(name, src); return src; }
|
|
224
227
|
const out = e.message.startsWith('"') || e.message.startsWith('no ') ? e : fail(e.code || 'var.expression', `"${name}" = ${JSON.stringify(src)}: ${e.message}`);
|
|
225
228
|
if (!out.path) out.path = pathOf(name); // the first expression that reads the bad name: where to fix it
|
|
226
229
|
throw out;
|