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