@valbuild/core 0.13.5 → 0.13.6

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,5 +1,5 @@
1
1
  import { e as _toPropertyKey, a as _createClass, _ as _classCallCheck, b as _typeof, c as _slicedToArray, d as _toConsumableArray } from './createClass-012eebbf.esm.js';
2
- import { i as isErr, e as err, o as ok, a as isOk } from './result-b96df128.esm.js';
2
+ import { i as isErr, e as err, o as ok, a as isOk, r as result } from './result-b96df128.esm.js';
3
3
 
4
4
  function _defineProperty(obj, key, value) {
5
5
  key = _toPropertyKey(key);
@@ -428,7 +428,8 @@ function newSelectorProxy(source, path, moduleSchema) {
428
428
  if (isSelector(source)) {
429
429
  return source;
430
430
  } else if (isSerializedVal(source)) {
431
- return newSelectorProxy(source.val, source.valPath);
431
+ var _source$valPath;
432
+ return newSelectorProxy(source.val, (_source$valPath = source.valPath) !== null && _source$valPath !== void 0 ? _source$valPath : undefined);
432
433
  }
433
434
  }
434
435
  if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
@@ -813,6 +814,339 @@ function parse(input) {
813
814
  return parseTokens(tokens);
814
815
  }
815
816
 
817
+ function _regeneratorRuntime() {
818
+ _regeneratorRuntime = function () {
819
+ return exports;
820
+ };
821
+ var exports = {},
822
+ Op = Object.prototype,
823
+ hasOwn = Op.hasOwnProperty,
824
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
825
+ obj[key] = desc.value;
826
+ },
827
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
828
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
829
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
830
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
831
+ function define(obj, key, value) {
832
+ return Object.defineProperty(obj, key, {
833
+ value: value,
834
+ enumerable: !0,
835
+ configurable: !0,
836
+ writable: !0
837
+ }), obj[key];
838
+ }
839
+ try {
840
+ define({}, "");
841
+ } catch (err) {
842
+ define = function (obj, key, value) {
843
+ return obj[key] = value;
844
+ };
845
+ }
846
+ function wrap(innerFn, outerFn, self, tryLocsList) {
847
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
848
+ generator = Object.create(protoGenerator.prototype),
849
+ context = new Context(tryLocsList || []);
850
+ return defineProperty(generator, "_invoke", {
851
+ value: makeInvokeMethod(innerFn, self, context)
852
+ }), generator;
853
+ }
854
+ function tryCatch(fn, obj, arg) {
855
+ try {
856
+ return {
857
+ type: "normal",
858
+ arg: fn.call(obj, arg)
859
+ };
860
+ } catch (err) {
861
+ return {
862
+ type: "throw",
863
+ arg: err
864
+ };
865
+ }
866
+ }
867
+ exports.wrap = wrap;
868
+ var ContinueSentinel = {};
869
+ function Generator() {}
870
+ function GeneratorFunction() {}
871
+ function GeneratorFunctionPrototype() {}
872
+ var IteratorPrototype = {};
873
+ define(IteratorPrototype, iteratorSymbol, function () {
874
+ return this;
875
+ });
876
+ var getProto = Object.getPrototypeOf,
877
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
878
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
879
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
880
+ function defineIteratorMethods(prototype) {
881
+ ["next", "throw", "return"].forEach(function (method) {
882
+ define(prototype, method, function (arg) {
883
+ return this._invoke(method, arg);
884
+ });
885
+ });
886
+ }
887
+ function AsyncIterator(generator, PromiseImpl) {
888
+ function invoke(method, arg, resolve, reject) {
889
+ var record = tryCatch(generator[method], generator, arg);
890
+ if ("throw" !== record.type) {
891
+ var result = record.arg,
892
+ value = result.value;
893
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
894
+ invoke("next", value, resolve, reject);
895
+ }, function (err) {
896
+ invoke("throw", err, resolve, reject);
897
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
898
+ result.value = unwrapped, resolve(result);
899
+ }, function (error) {
900
+ return invoke("throw", error, resolve, reject);
901
+ });
902
+ }
903
+ reject(record.arg);
904
+ }
905
+ var previousPromise;
906
+ defineProperty(this, "_invoke", {
907
+ value: function (method, arg) {
908
+ function callInvokeWithMethodAndArg() {
909
+ return new PromiseImpl(function (resolve, reject) {
910
+ invoke(method, arg, resolve, reject);
911
+ });
912
+ }
913
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
914
+ }
915
+ });
916
+ }
917
+ function makeInvokeMethod(innerFn, self, context) {
918
+ var state = "suspendedStart";
919
+ return function (method, arg) {
920
+ if ("executing" === state) throw new Error("Generator is already running");
921
+ if ("completed" === state) {
922
+ if ("throw" === method) throw arg;
923
+ return doneResult();
924
+ }
925
+ for (context.method = method, context.arg = arg;;) {
926
+ var delegate = context.delegate;
927
+ if (delegate) {
928
+ var delegateResult = maybeInvokeDelegate(delegate, context);
929
+ if (delegateResult) {
930
+ if (delegateResult === ContinueSentinel) continue;
931
+ return delegateResult;
932
+ }
933
+ }
934
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
935
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
936
+ context.dispatchException(context.arg);
937
+ } else "return" === context.method && context.abrupt("return", context.arg);
938
+ state = "executing";
939
+ var record = tryCatch(innerFn, self, context);
940
+ if ("normal" === record.type) {
941
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
942
+ return {
943
+ value: record.arg,
944
+ done: context.done
945
+ };
946
+ }
947
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
948
+ }
949
+ };
950
+ }
951
+ function maybeInvokeDelegate(delegate, context) {
952
+ var methodName = context.method,
953
+ method = delegate.iterator[methodName];
954
+ if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
955
+ var record = tryCatch(method, delegate.iterator, context.arg);
956
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
957
+ var info = record.arg;
958
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
959
+ }
960
+ function pushTryEntry(locs) {
961
+ var entry = {
962
+ tryLoc: locs[0]
963
+ };
964
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
965
+ }
966
+ function resetTryEntry(entry) {
967
+ var record = entry.completion || {};
968
+ record.type = "normal", delete record.arg, entry.completion = record;
969
+ }
970
+ function Context(tryLocsList) {
971
+ this.tryEntries = [{
972
+ tryLoc: "root"
973
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
974
+ }
975
+ function values(iterable) {
976
+ if (iterable) {
977
+ var iteratorMethod = iterable[iteratorSymbol];
978
+ if (iteratorMethod) return iteratorMethod.call(iterable);
979
+ if ("function" == typeof iterable.next) return iterable;
980
+ if (!isNaN(iterable.length)) {
981
+ var i = -1,
982
+ next = function next() {
983
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
984
+ return next.value = undefined, next.done = !0, next;
985
+ };
986
+ return next.next = next;
987
+ }
988
+ }
989
+ return {
990
+ next: doneResult
991
+ };
992
+ }
993
+ function doneResult() {
994
+ return {
995
+ value: undefined,
996
+ done: !0
997
+ };
998
+ }
999
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
1000
+ value: GeneratorFunctionPrototype,
1001
+ configurable: !0
1002
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
1003
+ value: GeneratorFunction,
1004
+ configurable: !0
1005
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
1006
+ var ctor = "function" == typeof genFun && genFun.constructor;
1007
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
1008
+ }, exports.mark = function (genFun) {
1009
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
1010
+ }, exports.awrap = function (arg) {
1011
+ return {
1012
+ __await: arg
1013
+ };
1014
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1015
+ return this;
1016
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1017
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
1018
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1019
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
1020
+ return result.done ? result.value : iter.next();
1021
+ });
1022
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
1023
+ return this;
1024
+ }), define(Gp, "toString", function () {
1025
+ return "[object Generator]";
1026
+ }), exports.keys = function (val) {
1027
+ var object = Object(val),
1028
+ keys = [];
1029
+ for (var key in object) keys.push(key);
1030
+ return keys.reverse(), function next() {
1031
+ for (; keys.length;) {
1032
+ var key = keys.pop();
1033
+ if (key in object) return next.value = key, next.done = !1, next;
1034
+ }
1035
+ return next.done = !0, next;
1036
+ };
1037
+ }, exports.values = values, Context.prototype = {
1038
+ constructor: Context,
1039
+ reset: function (skipTempReset) {
1040
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
1041
+ },
1042
+ stop: function () {
1043
+ this.done = !0;
1044
+ var rootRecord = this.tryEntries[0].completion;
1045
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
1046
+ return this.rval;
1047
+ },
1048
+ dispatchException: function (exception) {
1049
+ if (this.done) throw exception;
1050
+ var context = this;
1051
+ function handle(loc, caught) {
1052
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1053
+ }
1054
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1055
+ var entry = this.tryEntries[i],
1056
+ record = entry.completion;
1057
+ if ("root" === entry.tryLoc) return handle("end");
1058
+ if (entry.tryLoc <= this.prev) {
1059
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
1060
+ hasFinally = hasOwn.call(entry, "finallyLoc");
1061
+ if (hasCatch && hasFinally) {
1062
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1063
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1064
+ } else if (hasCatch) {
1065
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1066
+ } else {
1067
+ if (!hasFinally) throw new Error("try statement without catch or finally");
1068
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1069
+ }
1070
+ }
1071
+ }
1072
+ },
1073
+ abrupt: function (type, arg) {
1074
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1075
+ var entry = this.tryEntries[i];
1076
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1077
+ var finallyEntry = entry;
1078
+ break;
1079
+ }
1080
+ }
1081
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1082
+ var record = finallyEntry ? finallyEntry.completion : {};
1083
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1084
+ },
1085
+ complete: function (record, afterLoc) {
1086
+ if ("throw" === record.type) throw record.arg;
1087
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
1088
+ },
1089
+ finish: function (finallyLoc) {
1090
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1091
+ var entry = this.tryEntries[i];
1092
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1093
+ }
1094
+ },
1095
+ catch: function (tryLoc) {
1096
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1097
+ var entry = this.tryEntries[i];
1098
+ if (entry.tryLoc === tryLoc) {
1099
+ var record = entry.completion;
1100
+ if ("throw" === record.type) {
1101
+ var thrown = record.arg;
1102
+ resetTryEntry(entry);
1103
+ }
1104
+ return thrown;
1105
+ }
1106
+ }
1107
+ throw new Error("illegal catch attempt");
1108
+ },
1109
+ delegateYield: function (iterable, resultName, nextLoc) {
1110
+ return this.delegate = {
1111
+ iterator: values(iterable),
1112
+ resultName: resultName,
1113
+ nextLoc: nextLoc
1114
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
1115
+ }
1116
+ }, exports;
1117
+ }
1118
+
1119
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1120
+ try {
1121
+ var info = gen[key](arg);
1122
+ var value = info.value;
1123
+ } catch (error) {
1124
+ reject(error);
1125
+ return;
1126
+ }
1127
+ if (info.done) {
1128
+ resolve(value);
1129
+ } else {
1130
+ Promise.resolve(value).then(_next, _throw);
1131
+ }
1132
+ }
1133
+ function _asyncToGenerator(fn) {
1134
+ return function () {
1135
+ var self = this,
1136
+ args = arguments;
1137
+ return new Promise(function (resolve, reject) {
1138
+ var gen = fn.apply(self, args);
1139
+ function _next(value) {
1140
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1141
+ }
1142
+ function _throw(err) {
1143
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1144
+ }
1145
+ _next(undefined);
1146
+ });
1147
+ };
1148
+ }
1149
+
816
1150
  var EvalError = /*#__PURE__*/function () {
817
1151
  function EvalError(message, expr) {
818
1152
  _classCallCheck(this, EvalError);
@@ -828,164 +1162,354 @@ var EvalError = /*#__PURE__*/function () {
828
1162
  return EvalError;
829
1163
  }();
830
1164
  var MAX_STACK_SIZE = 100; // an arbitrary semi-large number
831
- function evaluateSync(expr, getSource, stack) {
832
- // TODO: amount of evaluates should be limited?
833
- if (stack.length > MAX_STACK_SIZE) {
834
- throw new EvalError("Stack overflow. Final frames: ".concat(stack.slice(-10).map(function (frame, i) {
835
- return frame.map(function (s, j) {
836
- return "@[".concat(i, ",").concat(j, "]: ").concat(JSON.stringify(s));
837
- }).join(", ");
838
- }).join(" -> ")), expr);
839
- }
840
- if (expr instanceof Call) {
841
- if (expr.children[0] instanceof Sym) {
842
- if (expr.children[0].value === "val") {
843
- if (expr.isAnon) {
1165
+ function evaluateAsync(_x, _x2, _x3) {
1166
+ return _evaluateAsync.apply(this, arguments);
1167
+ }
1168
+ function _evaluateAsync() {
1169
+ _evaluateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(expr, getSource, stack) {
1170
+ var path, source, value, valObj, valPath, serialized, _serialized$valPath, parsedValue, res, prop, obj, maybeFunction, _path, _source, args, _maybeFunction, maybeValue, _stack$Number, _expr$value$slice$spl, _expr$value$slice$spl2, i, j, rest, stackValue;
1171
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1172
+ while (1) switch (_context2.prev = _context2.next) {
1173
+ case 0:
1174
+ if (!(stack.length > MAX_STACK_SIZE)) {
1175
+ _context2.next = 2;
1176
+ break;
1177
+ }
1178
+ throw new EvalError("Stack overflow. Final frames: ".concat(stack.slice(-10).map(function (frame, i) {
1179
+ return frame.map(function (s, j) {
1180
+ return "@[".concat(i, ",").concat(j, "]: ").concat(JSON.stringify(s));
1181
+ }).join(", ");
1182
+ }).join(" -> ")), expr);
1183
+ case 2:
1184
+ if (!(expr instanceof Call)) {
1185
+ _context2.next = 96;
1186
+ break;
1187
+ }
1188
+ if (!(expr.children[0] instanceof Sym)) {
1189
+ _context2.next = 50;
1190
+ break;
1191
+ }
1192
+ if (!(expr.children[0].value === "val")) {
1193
+ _context2.next = 18;
1194
+ break;
1195
+ }
1196
+ if (!expr.isAnon) {
1197
+ _context2.next = 7;
1198
+ break;
1199
+ }
844
1200
  throw new EvalError("cannot call 'val' as anonymous function", expr);
845
- }
846
- if (expr.children[1] instanceof StringLiteral) {
847
- return getSource(expr.children[1].value);
848
- } else {
1201
+ case 7:
1202
+ if (!(expr.children[1] instanceof StringLiteral)) {
1203
+ _context2.next = 15;
1204
+ break;
1205
+ }
1206
+ path = expr.children[1].value;
1207
+ _context2.next = 11;
1208
+ return getSource(path);
1209
+ case 11:
1210
+ source = _context2.sent;
1211
+ return _context2.abrupt("return", newSelectorProxy(source, path));
1212
+ case 15:
849
1213
  throw new EvalError("argument of 'val' must be a string literal", expr);
850
- }
851
- } else if (expr.children[0].value === "json") {
852
- if (expr.children.length !== 2) {
1214
+ case 16:
1215
+ _context2.next = 50;
1216
+ break;
1217
+ case 18:
1218
+ if (!(expr.children[0].value === "json")) {
1219
+ _context2.next = 43;
1220
+ break;
1221
+ }
1222
+ if (!(expr.children.length !== 2)) {
1223
+ _context2.next = 21;
1224
+ break;
1225
+ }
853
1226
  throw new EvalError("must call 'json' with exactly one argument", expr);
854
- }
855
- var value = evaluateSync(expr.children[1], getSource, stack);
856
- var valObj = value[SourceOrExpr];
857
- var valPath = value[Path];
858
- if (typeof valObj !== "string") {
1227
+ case 21:
1228
+ _context2.next = 23;
1229
+ return evaluateAsync(expr.children[1], getSource, stack);
1230
+ case 23:
1231
+ value = _context2.sent;
1232
+ valObj = value[SourceOrExpr];
1233
+ valPath = value[Path];
1234
+ if (!(typeof valObj !== "string")) {
1235
+ _context2.next = 28;
1236
+ break;
1237
+ }
859
1238
  throw new EvalError("cannot parse JSON: ".concat(JSON.stringify(valObj), ", expected string"), expr.children[1]);
860
- }
861
- try {
862
- var serialized = JSON.parse(valObj);
863
- if (isSerializedVal(serialized)) {
864
- return newSelectorProxy(serialized.val, serialized.valPath);
865
- }
866
- var parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
867
- return parsedValue;
868
- } catch (e) {
869
- if (e instanceof SyntaxError) {
870
- throw new EvalError("cannot parse JSON: ".concat(valObj, ", ").concat(e.message, " - value: ").concat(JSON.stringify(value)), expr.children[1]);
871
- }
872
- throw e;
873
- }
874
- } else if (expr.children[0].value === "stringify") {
875
- // TODO: remove stringify
876
- if (expr.children.length !== 2) {
1239
+ case 28:
1240
+ _context2.prev = 28;
1241
+ serialized = JSON.parse(valObj);
1242
+ if (!isSerializedVal(serialized)) {
1243
+ _context2.next = 32;
1244
+ break;
1245
+ }
1246
+ return _context2.abrupt("return", newSelectorProxy(serialized.val, (_serialized$valPath = serialized.valPath) !== null && _serialized$valPath !== void 0 ? _serialized$valPath : undefined));
1247
+ case 32:
1248
+ parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
1249
+ return _context2.abrupt("return", parsedValue);
1250
+ case 36:
1251
+ _context2.prev = 36;
1252
+ _context2.t0 = _context2["catch"](28);
1253
+ if (!(_context2.t0 instanceof SyntaxError)) {
1254
+ _context2.next = 40;
1255
+ break;
1256
+ }
1257
+ throw new EvalError("cannot parse JSON: ".concat(valObj, ", ").concat(_context2.t0.message, " - value: ").concat(JSON.stringify(value)), expr.children[1]);
1258
+ case 40:
1259
+ throw _context2.t0;
1260
+ case 41:
1261
+ _context2.next = 50;
1262
+ break;
1263
+ case 43:
1264
+ if (!(expr.children[0].value === "stringify")) {
1265
+ _context2.next = 50;
1266
+ break;
1267
+ }
1268
+ if (!(expr.children.length !== 2)) {
1269
+ _context2.next = 46;
1270
+ break;
1271
+ }
877
1272
  throw new EvalError("must call 'stringify' with exactly one argument", expr);
878
- }
879
- var res = evaluateSync(expr.children[1], getSource, stack);
880
- return newSelectorProxy(JSON.stringify(res[SourceOrExpr]));
881
- }
882
- }
883
- var prop = evaluateSync(expr.children[0], getSource, stack)[SourceOrExpr];
884
- if (expr.children.length === 1) {
885
- // TODO: return if literal only?
886
- return newSelectorProxy(prop);
887
- }
888
- var obj = evaluateSync(expr.children[1], getSource, stack);
889
- if (typeof prop !== "string" && typeof prop !== "number") {
890
- throw new EvalError("cannot access ".concat(JSON.stringify(obj), " with property ").concat(JSON.stringify(prop), ": is not a string or number"), expr);
891
- }
892
- if (prop in obj) {
893
- if (expr.isAnon) {
894
- // anon functions:
895
- var maybeFunction = obj[prop];
896
- if (typeof maybeFunction !== "function") {
1273
+ case 46:
1274
+ _context2.next = 48;
1275
+ return evaluateAsync(expr.children[1], getSource, stack);
1276
+ case 48:
1277
+ res = _context2.sent;
1278
+ return _context2.abrupt("return", newSelectorProxy(JSON.stringify(res[SourceOrExpr])));
1279
+ case 50:
1280
+ _context2.next = 52;
1281
+ return evaluateAsync(expr.children[0], getSource, stack);
1282
+ case 52:
1283
+ _context2.t1 = SourceOrExpr;
1284
+ prop = _context2.sent[_context2.t1];
1285
+ if (!(expr.children.length === 1)) {
1286
+ _context2.next = 56;
1287
+ break;
1288
+ }
1289
+ return _context2.abrupt("return", newSelectorProxy(prop));
1290
+ case 56:
1291
+ _context2.next = 58;
1292
+ return evaluateAsync(expr.children[1], getSource, stack);
1293
+ case 58:
1294
+ obj = _context2.sent;
1295
+ if (!(typeof prop !== "string" && typeof prop !== "number")) {
1296
+ _context2.next = 61;
1297
+ break;
1298
+ }
1299
+ throw new EvalError("cannot access ".concat(JSON.stringify(obj), " with property ").concat(JSON.stringify(prop), ": is not a string or number"), expr);
1300
+ case 61:
1301
+ if (!(prop in obj)) {
1302
+ _context2.next = 94;
1303
+ break;
1304
+ }
1305
+ if (!expr.isAnon) {
1306
+ _context2.next = 73;
1307
+ break;
1308
+ }
1309
+ // anon functions:
1310
+ maybeFunction = obj[prop];
1311
+ if (!(typeof maybeFunction !== "function")) {
1312
+ _context2.next = 66;
1313
+ break;
1314
+ }
897
1315
  throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required higher ordered function got ").concat(_typeof(obj[prop])), expr);
898
- }
899
- if (expr.children[0] instanceof Sym) {
900
- return maybeFunction(function () {
1316
+ case 66:
1317
+ if (!(expr.children[0] instanceof Sym)) {
1318
+ _context2.next = 70;
1319
+ break;
1320
+ }
1321
+ return _context2.abrupt("return", maybeFunction(function () {
901
1322
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
902
1323
  args[_key] = arguments[_key];
903
1324
  }
904
- return evaluateSync(expr.children[2], getSource, stack.concat([args]));
905
- });
906
- } else {
1325
+ return evaluateAsync(expr.children[2], getSource, stack.concat([args]));
1326
+ }));
1327
+ case 70:
907
1328
  throw new EvalError("cannot call an expression that is not a symbol, got: '".concat(expr.children[0].type, "'"), expr);
908
- }
909
- } else {
910
- // non-anon functions:
911
- if (expr.children[0] instanceof Sym) {
912
- if (expr.children[0].value === "val") {
913
- if (expr.children[1] instanceof StringLiteral) {
914
- return getSource(expr.children[1].value);
915
- } else {
916
- throw new EvalError("argument of 'val' must be a string literal", expr);
917
- }
1329
+ case 71:
1330
+ _context2.next = 94;
1331
+ break;
1332
+ case 73:
1333
+ if (!(expr.children[0] instanceof Sym)) {
1334
+ _context2.next = 84;
1335
+ break;
1336
+ }
1337
+ if (!(expr.children[0].value === "val")) {
1338
+ _context2.next = 84;
1339
+ break;
1340
+ }
1341
+ if (!(expr.children[1] instanceof StringLiteral)) {
1342
+ _context2.next = 83;
1343
+ break;
1344
+ }
1345
+ _path = expr.children[1].value;
1346
+ _context2.next = 79;
1347
+ return getSource(_path);
1348
+ case 79:
1349
+ _source = _context2.sent;
1350
+ return _context2.abrupt("return", newSelectorProxy(_source, _path));
1351
+ case 83:
1352
+ throw new EvalError("argument of 'val' must be a string literal", expr);
1353
+ case 84:
1354
+ args = expr.children.slice(2);
1355
+ if (!(args.length > 0)) {
1356
+ _context2.next = 90;
1357
+ break;
1358
+ }
1359
+ _maybeFunction = obj[prop];
1360
+ if (!(typeof _maybeFunction !== "function")) {
1361
+ _context2.next = 89;
1362
+ break;
1363
+ }
1364
+ throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(_typeof(obj[prop])), expr);
1365
+ case 89:
1366
+ return _context2.abrupt("return", _maybeFunction.apply(void 0, _toConsumableArray(args.map(function (arg) {
1367
+ return evaluateAsync(arg, getSource, stack);
1368
+ }))));
1369
+ case 90:
1370
+ maybeValue = obj[prop];
1371
+ if (!(typeof maybeValue === "function")) {
1372
+ _context2.next = 93;
1373
+ break;
918
1374
  }
919
- }
920
- var args = expr.children.slice(2);
921
- if (args.length > 0) {
922
- var _maybeFunction = obj[prop];
923
- if (typeof _maybeFunction !== "function") {
924
- throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(_typeof(obj[prop])), expr);
925
- }
926
- return _maybeFunction.apply(void 0, _toConsumableArray(args.map(function (arg) {
927
- return evaluateSync(arg, getSource, stack);
928
- })));
929
- }
930
- var maybeValue = obj[prop];
931
- if (typeof maybeValue === "function") {
932
1375
  throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required value got ").concat(_typeof(obj[prop])), expr);
933
- }
934
- return maybeValue;
935
- }
936
- }
937
- } else if (expr instanceof Sym) {
938
- if (expr.value.startsWith("@")) {
939
- var _stack$Number;
940
- var _expr$value$slice$spl = expr.value.slice(2, -1).split(","),
941
- _expr$value$slice$spl2 = _slicedToArray(_expr$value$slice$spl, 3),
942
- i = _expr$value$slice$spl2[0],
943
- j = _expr$value$slice$spl2[1],
944
- rest = _expr$value$slice$spl2[2];
945
- if (rest) {
946
- throw new EvalError("cannot access stack: too many indices", expr);
947
- }
948
- var stackValue = (_stack$Number = stack[Number(i)]) === null || _stack$Number === void 0 ? void 0 : _stack$Number[Number(j)];
949
- if (stackValue === undefined) {
950
- throw new EvalError("cannot access stack: out of bounds", expr);
951
- }
952
- return stackValue;
953
- } else if (expr.value === "()") {
954
- return newSelectorProxy(null);
955
- }
956
- return newSelectorProxy(expr.value);
957
- } else if (expr instanceof StringLiteral) {
958
- return newSelectorProxy(expr.value);
959
- } else if (expr instanceof StringTemplate) {
960
- return newSelectorProxy(expr.children.map(function (child) {
961
- if (child instanceof Sym && child.value === "()") {
962
- return "null";
963
- }
964
- var evalRes = evaluateSync(child, getSource, stack);
965
- if (child.type === "StringLiteral" || child.type === "StringTemplate") {
966
- return evalRes[SourceOrExpr];
967
- }
968
- if (Path in evalRes) {
969
- // a selector, so serialize to Val
970
- return JSON.stringify({
971
- val: evalRes[SourceOrExpr],
972
- valPath: evalRes[Path]
973
- });
1376
+ case 93:
1377
+ return _context2.abrupt("return", maybeValue);
1378
+ case 94:
1379
+ _context2.next = 122;
1380
+ break;
1381
+ case 96:
1382
+ if (!(expr instanceof Sym)) {
1383
+ _context2.next = 112;
1384
+ break;
1385
+ }
1386
+ if (!expr.value.startsWith("@")) {
1387
+ _context2.next = 107;
1388
+ break;
1389
+ }
1390
+ _expr$value$slice$spl = expr.value.slice(2, -1).split(","), _expr$value$slice$spl2 = _slicedToArray(_expr$value$slice$spl, 3), i = _expr$value$slice$spl2[0], j = _expr$value$slice$spl2[1], rest = _expr$value$slice$spl2[2];
1391
+ if (!rest) {
1392
+ _context2.next = 101;
1393
+ break;
1394
+ }
1395
+ throw new EvalError("cannot access stack: too many indices", expr);
1396
+ case 101:
1397
+ stackValue = (_stack$Number = stack[Number(i)]) === null || _stack$Number === void 0 ? void 0 : _stack$Number[Number(j)];
1398
+ if (!(stackValue === undefined)) {
1399
+ _context2.next = 104;
1400
+ break;
1401
+ }
1402
+ throw new EvalError("cannot access stack: out of bounds", expr);
1403
+ case 104:
1404
+ return _context2.abrupt("return", stackValue);
1405
+ case 107:
1406
+ if (!(expr.value === "()")) {
1407
+ _context2.next = 109;
1408
+ break;
1409
+ }
1410
+ return _context2.abrupt("return", newSelectorProxy(null));
1411
+ case 109:
1412
+ return _context2.abrupt("return", newSelectorProxy(expr.value));
1413
+ case 112:
1414
+ if (!(expr instanceof StringLiteral)) {
1415
+ _context2.next = 116;
1416
+ break;
1417
+ }
1418
+ return _context2.abrupt("return", newSelectorProxy(expr.value));
1419
+ case 116:
1420
+ if (!(expr instanceof StringTemplate)) {
1421
+ _context2.next = 122;
1422
+ break;
1423
+ }
1424
+ _context2.t2 = newSelectorProxy;
1425
+ _context2.next = 120;
1426
+ return Promise.all(expr.children.map( /*#__PURE__*/function () {
1427
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(child) {
1428
+ var evalRes;
1429
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1430
+ while (1) switch (_context.prev = _context.next) {
1431
+ case 0:
1432
+ if (!(child instanceof Sym && child.value === "()")) {
1433
+ _context.next = 2;
1434
+ break;
1435
+ }
1436
+ return _context.abrupt("return", "null");
1437
+ case 2:
1438
+ _context.next = 4;
1439
+ return evaluateAsync(child, getSource, stack);
1440
+ case 4:
1441
+ evalRes = _context.sent;
1442
+ if (!(child.type === "StringLiteral" || child.type === "StringTemplate")) {
1443
+ _context.next = 7;
1444
+ break;
1445
+ }
1446
+ return _context.abrupt("return", evalRes[SourceOrExpr]);
1447
+ case 7:
1448
+ if (!(Path in evalRes)) {
1449
+ _context.next = 9;
1450
+ break;
1451
+ }
1452
+ return _context.abrupt("return", JSON.stringify({
1453
+ val: evalRes[SourceOrExpr],
1454
+ valPath: evalRes[Path]
1455
+ }));
1456
+ case 9:
1457
+ return _context.abrupt("return", JSON.stringify(evalRes[SourceOrExpr]));
1458
+ case 10:
1459
+ case "end":
1460
+ return _context.stop();
1461
+ }
1462
+ }, _callee);
1463
+ }));
1464
+ return function (_x7) {
1465
+ return _ref.apply(this, arguments);
1466
+ };
1467
+ }()).join(""));
1468
+ case 120:
1469
+ _context2.t3 = _context2.sent;
1470
+ return _context2.abrupt("return", (0, _context2.t2)(_context2.t3));
1471
+ case 122:
1472
+ throw new EvalError("could not evaluate", expr);
1473
+ case 123:
1474
+ case "end":
1475
+ return _context2.stop();
974
1476
  }
975
- return JSON.stringify(evalRes[SourceOrExpr]);
976
- }).join(""));
977
- }
978
- throw new EvalError("could not evaluate", expr);
1477
+ }, _callee2, null, [[28, 36]]);
1478
+ }));
1479
+ return _evaluateAsync.apply(this, arguments);
979
1480
  }
980
- function evaluate(expr, source, stack) {
981
- try {
982
- return ok(evaluateSync(expr, source, stack));
983
- } catch (err$1) {
984
- if (err$1 instanceof EvalError) {
985
- return err(err$1);
986
- }
987
- throw err$1;
988
- }
1481
+ function evaluate(_x4, _x5, _x6) {
1482
+ return _evaluate.apply(this, arguments);
1483
+ }
1484
+ function _evaluate() {
1485
+ _evaluate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(expr, source, stack) {
1486
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1487
+ while (1) switch (_context3.prev = _context3.next) {
1488
+ case 0:
1489
+ _context3.prev = 0;
1490
+ _context3.t0 = result;
1491
+ _context3.next = 4;
1492
+ return evaluateAsync(expr, source, stack);
1493
+ case 4:
1494
+ _context3.t1 = _context3.sent;
1495
+ return _context3.abrupt("return", _context3.t0.ok.call(_context3.t0, _context3.t1));
1496
+ case 8:
1497
+ _context3.prev = 8;
1498
+ _context3.t2 = _context3["catch"](0);
1499
+ if (!(_context3.t2 instanceof EvalError)) {
1500
+ _context3.next = 12;
1501
+ break;
1502
+ }
1503
+ return _context3.abrupt("return", err(_context3.t2));
1504
+ case 12:
1505
+ throw _context3.t2;
1506
+ case 13:
1507
+ case "end":
1508
+ return _context3.stop();
1509
+ }
1510
+ }, _callee3, null, [[0, 8]]);
1511
+ }));
1512
+ return _evaluate.apply(this, arguments);
989
1513
  }
990
1514
 
991
1515
  var index = /*#__PURE__*/Object.freeze({