From 5c3716ff99b161b7560e1eb01ad2c585af5fbcf1 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sun, 31 Jul 2022 09:13:41 -0700 Subject: [PATCH] refactor: Avoid use of a "magic string " 'T' --- src/core/PocomathInstance.mjs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/PocomathInstance.mjs b/src/core/PocomathInstance.mjs index 8cb572b..901514b 100644 --- a/src/core/PocomathInstance.mjs +++ b/src/core/PocomathInstance.mjs @@ -5,6 +5,8 @@ import {subsetOfKeys, typesOfSignature} from './utils.mjs' const anySpec = {} // fixed dummy specification of 'any' type +const theTemplateParam = 'T' // First pass: only allow this one exact parameter + export default class PocomathInstance { /* Disallowed names for ops; beware, this is slightly non-DRY * in that if a new top-level PocomathInstance method is added, its name @@ -339,7 +341,7 @@ export default class PocomathInstance { * We will start this out very simply: the special string `T` is always * a template parameter, and that's the only one */ - _templateParam(t) { return t === 'T' } + _templateParam(t) { return t === theTemplateParam } _addAffect(dependency, dependent) { if (dependency in this._affects) { @@ -401,8 +403,8 @@ export default class PocomathInstance { Object.defineProperty(this, name, {configurable: true, value: 'limbo'}) const tf_imps = {} for (const [rawSignature, {uses, does}] of usableEntries) { - /* For now, replace 'T' with 'any' */ - const signature = rawSignature.replaceAll('T', 'any') + /* For now, replace theTemplateParam with 'any' */ + const signature = rawSignature.replaceAll(theTemplateParam, 'any') if (uses.length === 0) { tf_imps[signature] = does() } else { @@ -413,7 +415,7 @@ export default class PocomathInstance { let [func, needsig] = dep.split(/[()]/) const needTypes = needsig ? typesOfSignature(needsig) : new Set() /* For now, punt on template parameters */ - if (needTypes.has('T')) needsig = '' + if (needTypes.has(theTemplateParam)) needsig = '' if (func === 'self') { if (needsig) { if (full_self_referential) {