@valbuild/core 0.13.6 → 0.13.8

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,8 +430,7 @@ function newSelectorProxy(source, path, moduleSchema) {
430
430
  if (isSelector(source)) {
431
431
  return source;
432
432
  } else if (isSerializedVal(source)) {
433
- var _source$valPath;
434
- return newSelectorProxy(source.val, (_source$valPath = source.valPath) !== null && _source$valPath !== void 0 ? _source$valPath : undefined);
433
+ return newSelectorProxy(source.val, source.valPath);
435
434
  }
436
435
  }
437
436
  if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
@@ -816,339 +815,6 @@ function parse(input) {
816
815
  return parseTokens(tokens);
817
816
  }
818
817
 
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
-
1152
818
  var EvalError = /*#__PURE__*/function () {
1153
819
  function EvalError(message, expr) {
1154
820
  createClass._classCallCheck(this, EvalError);
@@ -1164,354 +830,166 @@ var EvalError = /*#__PURE__*/function () {
1164
830
  return EvalError;
1165
831
  }();
1166
832
  var MAX_STACK_SIZE = 100; // an arbitrary semi-large number
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
- }
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) {
1202
846
  throw new EvalError("cannot call 'val' as anonymous function", expr);
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:
847
+ }
848
+ if (expr.children[1] instanceof StringLiteral) {
849
+ var _path = expr.children[1].value;
850
+ return newSelectorProxy(getSource(_path), _path);
851
+ } else {
1215
852
  throw new EvalError("argument of 'val' must be a string literal", expr);
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
- }
853
+ }
854
+ } else if (expr.children[0].value === "json") {
855
+ if (expr.children.length !== 2) {
1228
856
  throw new EvalError("must call 'json' with exactly one argument", expr);
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
- }
857
+ }
858
+ var value = evaluateSync(expr.children[1], getSource, stack);
859
+ var valObj = value[SourceOrExpr];
860
+ var valPath = value[Path];
861
+ if (typeof valObj !== "string") {
1240
862
  throw new EvalError("cannot parse JSON: ".concat(JSON.stringify(valObj), ", expected string"), expr.children[1]);
1241
- case 28:
1242
- _context2.prev = 28;
1243
- serialized = JSON.parse(valObj);
1244
- if (!isSerializedVal(serialized)) {
1245
- _context2.next = 32;
1246
- break;
1247
- }
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;
863
+ }
864
+ try {
865
+ var serialized = JSON.parse(valObj);
866
+ if (isSerializedVal(serialized)) {
867
+ return newSelectorProxy(serialized.val, serialized.valPath);
1269
868
  }
1270
- if (!(expr.children.length !== 2)) {
1271
- _context2.next = 46;
1272
- break;
869
+ var parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
870
+ return parsedValue;
871
+ } catch (e) {
872
+ if (e instanceof SyntaxError) {
873
+ throw new EvalError("cannot parse JSON: ".concat(valObj, ", ").concat(e.message, " - value: ").concat(JSON.stringify(value)), expr.children[1]);
1273
874
  }
875
+ throw e;
876
+ }
877
+ } else if (expr.children[0].value === "stringify") {
878
+ // TODO: remove stringify
879
+ if (expr.children.length !== 2) {
1274
880
  throw new EvalError("must call 'stringify' with exactly one argument", expr);
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
- }
881
+ }
882
+ var res = evaluateSync(expr.children[1], getSource, stack);
883
+ return newSelectorProxy(JSON.stringify(res[SourceOrExpr]));
884
+ }
885
+ }
886
+ var prop = evaluateSync(expr.children[0], getSource, stack)[SourceOrExpr];
887
+ if (expr.children.length === 1) {
888
+ // TODO: return if literal only?
889
+ return newSelectorProxy(prop);
890
+ }
891
+ var obj = evaluateSync(expr.children[1], getSource, stack);
892
+ if (typeof prop !== "string" && typeof prop !== "number") {
893
+ throw new EvalError("cannot access ".concat(JSON.stringify(obj), " with property ").concat(JSON.stringify(prop), ": is not a string or number"), expr);
894
+ }
895
+ if (prop in obj) {
896
+ if (expr.isAnon) {
897
+ // anon functions:
898
+ var maybeFunction = obj[prop];
899
+ if (typeof maybeFunction !== "function") {
1317
900
  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);
1318
- case 66:
1319
- if (!(expr.children[0] instanceof Sym)) {
1320
- _context2.next = 70;
1321
- break;
1322
- }
1323
- return _context2.abrupt("return", maybeFunction(function () {
901
+ }
902
+ if (expr.children[0] instanceof Sym) {
903
+ return maybeFunction(function () {
1324
904
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1325
905
  args[_key] = arguments[_key];
1326
906
  }
1327
- return evaluateAsync(expr.children[2], getSource, stack.concat([args]));
1328
- }));
1329
- case 70:
907
+ return evaluateSync(expr.children[2], getSource, stack.concat([args]));
908
+ });
909
+ } else {
1330
910
  throw new EvalError("cannot call an expression that is not a symbol, got: '".concat(expr.children[0].type, "'"), expr);
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;
1338
- }
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;
911
+ }
912
+ } else {
913
+ // non-anon functions:
914
+ if (expr.children[0] instanceof Sym) {
915
+ if (expr.children[0].value === "val") {
916
+ if (expr.children[1] instanceof StringLiteral) {
917
+ var _path2 = expr.children[1].value;
918
+ return newSelectorProxy(getSource(_path2), _path2);
919
+ } else {
920
+ throw new EvalError("argument of 'val' must be a string literal", expr);
921
+ }
1365
922
  }
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;
923
+ }
924
+ var args = expr.children.slice(2);
925
+ if (args.length > 0) {
926
+ var _maybeFunction = obj[prop];
927
+ if (typeof _maybeFunction !== "function") {
928
+ throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(createClass._typeof(obj[prop])), expr);
1376
929
  }
930
+ return _maybeFunction.apply(void 0, createClass._toConsumableArray(args.map(function (arg) {
931
+ return evaluateSync(arg, getSource, stack);
932
+ })));
933
+ }
934
+ var maybeValue = obj[prop];
935
+ if (typeof maybeValue === "function") {
1377
936
  throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required value got ").concat(createClass._typeof(obj[prop])), expr);
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();
937
+ }
938
+ return maybeValue;
1478
939
  }
1479
- }, _callee2, null, [[28, 36]]);
1480
- }));
1481
- return _evaluateAsync.apply(this, arguments);
1482
- }
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();
940
+ }
941
+ } else if (expr instanceof Sym) {
942
+ if (expr.value.startsWith("@")) {
943
+ var _stack$Number;
944
+ var _expr$value$slice$spl = expr.value.slice(2, -1).split(","),
945
+ _expr$value$slice$spl2 = createClass._slicedToArray(_expr$value$slice$spl, 3),
946
+ i = _expr$value$slice$spl2[0],
947
+ j = _expr$value$slice$spl2[1],
948
+ rest = _expr$value$slice$spl2[2];
949
+ if (rest) {
950
+ throw new EvalError("cannot access stack: too many indices", expr);
951
+ }
952
+ var stackValue = (_stack$Number = stack[Number(i)]) === null || _stack$Number === void 0 ? void 0 : _stack$Number[Number(j)];
953
+ if (stackValue === undefined) {
954
+ throw new EvalError("cannot access stack: out of bounds", expr);
955
+ }
956
+ return stackValue;
957
+ } else if (expr.value === "()") {
958
+ return newSelectorProxy(null);
959
+ }
960
+ return newSelectorProxy(expr.value);
961
+ } else if (expr instanceof StringLiteral) {
962
+ return newSelectorProxy(expr.value);
963
+ } else if (expr instanceof StringTemplate) {
964
+ return newSelectorProxy(expr.children.map(function (child) {
965
+ if (child instanceof Sym && child.value === "()") {
966
+ return "null";
967
+ }
968
+ var evalRes = evaluateSync(child, getSource, stack);
969
+ if (child.type === "StringLiteral" || child.type === "StringTemplate") {
970
+ return evalRes[SourceOrExpr];
1511
971
  }
1512
- }, _callee3, null, [[0, 8]]);
1513
- }));
1514
- return _evaluate.apply(this, arguments);
972
+ if (Path in evalRes) {
973
+ // a selector, so serialize to Val
974
+ return JSON.stringify({
975
+ val: evalRes[SourceOrExpr],
976
+ valPath: evalRes[Path]
977
+ });
978
+ }
979
+ return JSON.stringify(evalRes[SourceOrExpr]);
980
+ }).join(""));
981
+ }
982
+ throw new EvalError("could not evaluate", expr);
983
+ }
984
+ function evaluate(expr, source, stack) {
985
+ try {
986
+ return result.ok(evaluateSync(expr, source, stack));
987
+ } catch (err) {
988
+ if (err instanceof EvalError) {
989
+ return result.err(err);
990
+ }
991
+ throw err;
992
+ }
1515
993
  }
1516
994
 
1517
995
  var index = /*#__PURE__*/Object.freeze({