@calcit/procs 0.6.10 → 0.6.11-a1

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.
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.6.10";
3
+ export const calcit_version = "0.6.11-a1";
4
4
  import { parse } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
6
6
  import "./js-primes.mjs";
@@ -1166,60 +1166,64 @@ let calcit_builtin_classes = {
1166
1166
  export let register_calcit_builtin_classes = (options) => {
1167
1167
  Object.assign(calcit_builtin_classes, options);
1168
1168
  };
1169
- export function invoke_method(p) {
1169
+ /** method used as closure */
1170
+ export function invoke_method_closure(p) {
1170
1171
  return (obj, ...args) => {
1171
- let klass;
1172
- let value = obj;
1173
- if (obj == null) {
1174
- klass = calcit_builtin_classes.nil;
1175
- }
1176
- else if (obj instanceof CalcitTuple) {
1177
- if (obj.fst instanceof CalcitRecord) {
1178
- klass = obj.fst;
1179
- }
1180
- else {
1181
- throw new Error("Method invoking expected a record as class");
1182
- }
1183
- }
1184
- else if (typeof obj === "number") {
1185
- klass = calcit_builtin_classes.number;
1186
- }
1187
- else if (typeof obj === "string") {
1188
- klass = calcit_builtin_classes.string;
1189
- }
1190
- else if (typeof obj === "function") {
1191
- klass = calcit_builtin_classes.fn;
1192
- }
1193
- else if (obj instanceof CalcitSet) {
1194
- klass = calcit_builtin_classes.set;
1195
- }
1196
- else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
1197
- klass = calcit_builtin_classes.list;
1198
- }
1199
- else if (obj instanceof CalcitRecord) {
1200
- klass = calcit_builtin_classes.record;
1201
- }
1202
- else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
1203
- klass = calcit_builtin_classes.map;
1172
+ return invoke_method(p, obj, ...args);
1173
+ };
1174
+ }
1175
+ export function invoke_method(p, obj, ...args) {
1176
+ let klass;
1177
+ let value = obj;
1178
+ if (obj == null) {
1179
+ klass = calcit_builtin_classes.nil;
1180
+ }
1181
+ else if (obj instanceof CalcitTuple) {
1182
+ if (obj.fst instanceof CalcitRecord) {
1183
+ klass = obj.fst;
1204
1184
  }
1205
1185
  else {
1206
- if (obj[p] == null) {
1207
- throw new Error(`Missing method \`${p}\` on object`);
1208
- }
1209
- return obj[p](...args); // trying to call native JavaScript method
1210
- }
1211
- if (klass == null)
1212
- throw new Error("Cannot find class for this object for invoking");
1213
- if (!klass.contains(p))
1214
- throw new Error(`Missing method '${p}' for object: ${obj}`);
1215
- let method = klass.get(p);
1216
- if (typeof method === "function") {
1217
- return method(value, ...args);
1186
+ throw new Error("Method invoking expected a record as class");
1218
1187
  }
1219
- else {
1220
- throw new Error("Method for invoking is not a function");
1188
+ }
1189
+ else if (typeof obj === "number") {
1190
+ klass = calcit_builtin_classes.number;
1191
+ }
1192
+ else if (typeof obj === "string") {
1193
+ klass = calcit_builtin_classes.string;
1194
+ }
1195
+ else if (typeof obj === "function") {
1196
+ klass = calcit_builtin_classes.fn;
1197
+ }
1198
+ else if (obj instanceof CalcitSet) {
1199
+ klass = calcit_builtin_classes.set;
1200
+ }
1201
+ else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
1202
+ klass = calcit_builtin_classes.list;
1203
+ }
1204
+ else if (obj instanceof CalcitRecord) {
1205
+ klass = calcit_builtin_classes.record;
1206
+ }
1207
+ else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
1208
+ klass = calcit_builtin_classes.map;
1209
+ }
1210
+ else {
1211
+ if (obj[p] == null) {
1212
+ throw new Error(`Missing method \`${p}\` on object`);
1221
1213
  }
1222
- };
1214
+ return obj[p](...args); // trying to call native JavaScript method
1215
+ }
1216
+ if (klass == null)
1217
+ throw new Error("Cannot find class for this object for invoking");
1218
+ if (!klass.contains(p))
1219
+ throw new Error(`Missing method '${p}' for object: ${obj}`);
1220
+ let method = klass.get(p);
1221
+ if (typeof method === "function") {
1222
+ return method(value, ...args);
1223
+ }
1224
+ else {
1225
+ throw new Error("Method for invoking is not a function");
1226
+ }
1223
1227
  }
1224
1228
  export let _$n_map_$o_to_list = (m) => {
1225
1229
  if (m instanceof CalcitMap || m instanceof CalcitSliceMap) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.6.10",
3
+ "version": "0.6.11-a1",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^18.11.3",
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.6.10";
2
+ export const calcit_version = "0.6.11-a1";
3
3
 
4
4
  import { parse, ICirruNode } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
@@ -1267,49 +1267,54 @@ export let register_calcit_builtin_classes = (options: typeof calcit_builtin_cla
1267
1267
  Object.assign(calcit_builtin_classes, options);
1268
1268
  };
1269
1269
 
1270
- export function invoke_method(p: string) {
1270
+ /** method used as closure */
1271
+ export function invoke_method_closure(p: string) {
1271
1272
  return (obj: CalcitValue, ...args: CalcitValue[]) => {
1272
- let klass: CalcitRecord;
1273
- let value = obj;
1274
- if (obj == null) {
1275
- klass = calcit_builtin_classes.nil;
1276
- } else if (obj instanceof CalcitTuple) {
1277
- if (obj.fst instanceof CalcitRecord) {
1278
- klass = obj.fst;
1279
- } else {
1280
- throw new Error("Method invoking expected a record as class");
1281
- }
1282
- } else if (typeof obj === "number") {
1283
- klass = calcit_builtin_classes.number;
1284
- } else if (typeof obj === "string") {
1285
- klass = calcit_builtin_classes.string;
1286
- } else if (typeof obj === "function") {
1287
- klass = calcit_builtin_classes.fn;
1288
- } else if (obj instanceof CalcitSet) {
1289
- klass = calcit_builtin_classes.set;
1290
- } else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
1291
- klass = calcit_builtin_classes.list;
1292
- } else if (obj instanceof CalcitRecord) {
1293
- klass = calcit_builtin_classes.record;
1294
- } else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
1295
- klass = calcit_builtin_classes.map;
1273
+ return invoke_method(p, obj, ...args);
1274
+ };
1275
+ }
1276
+
1277
+ export function invoke_method(p: string, obj: CalcitValue, ...args: CalcitValue[]) {
1278
+ let klass: CalcitRecord;
1279
+ let value = obj;
1280
+ if (obj == null) {
1281
+ klass = calcit_builtin_classes.nil;
1282
+ } else if (obj instanceof CalcitTuple) {
1283
+ if (obj.fst instanceof CalcitRecord) {
1284
+ klass = obj.fst;
1296
1285
  } else {
1297
- if ((obj as any)[p] == null) {
1298
- throw new Error(`Missing method \`${p}\` on object`);
1299
- }
1300
- return (obj as any)[p](...args); // trying to call native JavaScript method
1286
+ throw new Error("Method invoking expected a record as class");
1287
+ }
1288
+ } else if (typeof obj === "number") {
1289
+ klass = calcit_builtin_classes.number;
1290
+ } else if (typeof obj === "string") {
1291
+ klass = calcit_builtin_classes.string;
1292
+ } else if (typeof obj === "function") {
1293
+ klass = calcit_builtin_classes.fn;
1294
+ } else if (obj instanceof CalcitSet) {
1295
+ klass = calcit_builtin_classes.set;
1296
+ } else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
1297
+ klass = calcit_builtin_classes.list;
1298
+ } else if (obj instanceof CalcitRecord) {
1299
+ klass = calcit_builtin_classes.record;
1300
+ } else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
1301
+ klass = calcit_builtin_classes.map;
1302
+ } else {
1303
+ if ((obj as any)[p] == null) {
1304
+ throw new Error(`Missing method \`${p}\` on object`);
1301
1305
  }
1302
- if (klass == null) throw new Error("Cannot find class for this object for invoking");
1306
+ return (obj as any)[p](...args); // trying to call native JavaScript method
1307
+ }
1308
+ if (klass == null) throw new Error("Cannot find class for this object for invoking");
1303
1309
 
1304
- if (!klass.contains(p)) throw new Error(`Missing method '${p}' for object: ${obj}`);
1310
+ if (!klass.contains(p)) throw new Error(`Missing method '${p}' for object: ${obj}`);
1305
1311
 
1306
- let method = klass.get(p);
1307
- if (typeof method === "function") {
1308
- return method(value, ...args);
1309
- } else {
1310
- throw new Error("Method for invoking is not a function");
1311
- }
1312
- };
1312
+ let method = klass.get(p);
1313
+ if (typeof method === "function") {
1314
+ return method(value, ...args);
1315
+ } else {
1316
+ throw new Error("Method for invoking is not a function");
1317
+ }
1313
1318
  }
1314
1319
 
1315
1320
  export let _$n_map_$o_to_list = (m: CalcitValue): CalcitSliceList => {