@uipath/solution-tool 1.196.0 → 1.197.0-preview.59
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.
- package/README.md +19 -2
- package/dist/deploy.js +898 -1907
- package/dist/index.js +2 -0
- package/dist/init.js +106 -1415
- package/dist/models/pack-command-types.d.ts +9 -4
- package/dist/pack.js +180834 -150455
- package/dist/publish.js +833 -1868
- package/dist/resource.js +1310 -2084
- package/dist/services/pack-command-service.d.ts +0 -1
- package/dist/services/pack-service.d.ts +0 -10
- package/dist/services/solution-packager-helpers.d.ts +25 -0
- package/dist/services/sync-resources-from-bindings.d.ts +8 -0
- package/dist/templates/AGENTS.md +15 -2
- package/dist/tool.js +52509 -32947
- package/package.json +2 -2
package/dist/init.js
CHANGED
|
@@ -3006,6 +3006,18 @@ var NETWORK_ERROR_CODES = new Set([
|
|
|
3006
3006
|
"ENETUNREACH",
|
|
3007
3007
|
"EAI_FAIL"
|
|
3008
3008
|
]);
|
|
3009
|
+
var TLS_ERROR_CODES = new Set([
|
|
3010
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
3011
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
3012
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
3013
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
3014
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
3015
|
+
"CERT_HAS_EXPIRED",
|
|
3016
|
+
"CERT_UNTRUSTED",
|
|
3017
|
+
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
3018
|
+
]);
|
|
3019
|
+
var TLS_INSTRUCTIONS = "The server's TLS certificate could not be verified. Most often a " + "corporate proxy/firewall re-signs HTTPS with a root CA that Node does " + "not trust — set NODE_EXTRA_CA_CERTS to that CA's PEM file (and HTTPS_PROXY " + "if you connect through a proxy). If the certificate is instead expired or " + "its hostname does not match, fix the endpoint URL or the system clock. " + "Then retry.";
|
|
3020
|
+
var NETWORK_INSTRUCTIONS = "Could not reach the UiPath service. Check your network connection and " + "VPN, confirm any HTTP_PROXY/HTTPS_PROXY/NO_PROXY settings are correct, " + "then retry.";
|
|
3009
3021
|
// ../../node_modules/commander/esm.mjs
|
|
3010
3022
|
var import__ = __toESM(require_commander(), 1);
|
|
3011
3023
|
var {
|
|
@@ -3080,6 +3092,7 @@ var CONSOLE_FALLBACK = {
|
|
|
3080
3092
|
writeLog: (str) => process.stdout.write(str),
|
|
3081
3093
|
capabilities: {
|
|
3082
3094
|
isInteractive: false,
|
|
3095
|
+
canReadInput: false,
|
|
3083
3096
|
supportsColor: false,
|
|
3084
3097
|
outputWidth: 80
|
|
3085
3098
|
}
|
|
@@ -8279,6 +8292,29 @@ function isPlainRecord(value) {
|
|
|
8279
8292
|
const prototype = Object.getPrototypeOf(value);
|
|
8280
8293
|
return prototype === Object.prototype || prototype === null;
|
|
8281
8294
|
}
|
|
8295
|
+
function extractPagedRows(value) {
|
|
8296
|
+
if (Array.isArray(value) || !isPlainRecord(value))
|
|
8297
|
+
return null;
|
|
8298
|
+
const entries = Object.values(value);
|
|
8299
|
+
if (entries.length === 0)
|
|
8300
|
+
return null;
|
|
8301
|
+
let rows = null;
|
|
8302
|
+
let hasScalarSibling = false;
|
|
8303
|
+
for (const entry of entries) {
|
|
8304
|
+
if (Array.isArray(entry)) {
|
|
8305
|
+
if (rows !== null)
|
|
8306
|
+
return null;
|
|
8307
|
+
rows = entry;
|
|
8308
|
+
} else if (entry !== null && typeof entry === "object") {
|
|
8309
|
+
return null;
|
|
8310
|
+
} else {
|
|
8311
|
+
hasScalarSibling = true;
|
|
8312
|
+
}
|
|
8313
|
+
}
|
|
8314
|
+
if (rows === null || !hasScalarSibling)
|
|
8315
|
+
return null;
|
|
8316
|
+
return rows;
|
|
8317
|
+
}
|
|
8282
8318
|
function toLowerCamelCaseKey(key) {
|
|
8283
8319
|
if (!key)
|
|
8284
8320
|
return key;
|
|
@@ -8343,7 +8379,8 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
8343
8379
|
break;
|
|
8344
8380
|
case "plain": {
|
|
8345
8381
|
if ("Data" in data && data.Data != null) {
|
|
8346
|
-
const
|
|
8382
|
+
const pagedRows = extractPagedRows(data.Data);
|
|
8383
|
+
const items = pagedRows ?? (Array.isArray(data.Data) ? data.Data : [data.Data]);
|
|
8347
8384
|
items.forEach((item) => {
|
|
8348
8385
|
const values = Object.values(item).map((v) => v ?? "").join("\t");
|
|
8349
8386
|
logFn(values);
|
|
@@ -8355,10 +8392,13 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
8355
8392
|
break;
|
|
8356
8393
|
}
|
|
8357
8394
|
default: {
|
|
8358
|
-
|
|
8395
|
+
const hasData = "Data" in data && data.Data != null;
|
|
8396
|
+
const pagedRows = hasData ? extractPagedRows(data.Data) : null;
|
|
8397
|
+
const rows = pagedRows ? pagedRows : Array.isArray(data.Data) ? data.Data : null;
|
|
8398
|
+
if (hasData && !(rows !== null && rows.length === 0)) {
|
|
8359
8399
|
const logValue = data.Log;
|
|
8360
|
-
if (
|
|
8361
|
-
printResizableTable(
|
|
8400
|
+
if (rows !== null) {
|
|
8401
|
+
printResizableTable(rows, logFn, logValue);
|
|
8362
8402
|
} else {
|
|
8363
8403
|
printVerticalTable(data.Data, logFn, logValue);
|
|
8364
8404
|
}
|
|
@@ -8546,6 +8586,44 @@ function defaultErrorCodeForResult(result) {
|
|
|
8546
8586
|
return "unknown_error";
|
|
8547
8587
|
}
|
|
8548
8588
|
}
|
|
8589
|
+
function parseHttpStatusFromMessage(message) {
|
|
8590
|
+
const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
|
|
8591
|
+
if (!match)
|
|
8592
|
+
return;
|
|
8593
|
+
const status = Number(match[1]);
|
|
8594
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
8595
|
+
}
|
|
8596
|
+
function defaultErrorCodeForHttpStatus(status) {
|
|
8597
|
+
if (status === undefined)
|
|
8598
|
+
return;
|
|
8599
|
+
if (status === 400 || status === 409 || status === 422) {
|
|
8600
|
+
return "invalid_argument";
|
|
8601
|
+
}
|
|
8602
|
+
if (status === 401)
|
|
8603
|
+
return "authentication_required";
|
|
8604
|
+
if (status === 403)
|
|
8605
|
+
return "permission_denied";
|
|
8606
|
+
if (status === 404)
|
|
8607
|
+
return "not_found";
|
|
8608
|
+
if (status === 405)
|
|
8609
|
+
return "method_not_allowed";
|
|
8610
|
+
if (status === 408)
|
|
8611
|
+
return "timeout";
|
|
8612
|
+
if (status === 429)
|
|
8613
|
+
return "rate_limited";
|
|
8614
|
+
if (status >= 500 && status < 600)
|
|
8615
|
+
return "server_error";
|
|
8616
|
+
return;
|
|
8617
|
+
}
|
|
8618
|
+
function defaultErrorCodeForFailure(data) {
|
|
8619
|
+
if (data.Result === RESULTS.Failure) {
|
|
8620
|
+
const status = data.Context?.httpStatus ?? parseHttpStatusFromMessage(data.Message);
|
|
8621
|
+
const errorCode = defaultErrorCodeForHttpStatus(status);
|
|
8622
|
+
if (errorCode)
|
|
8623
|
+
return errorCode;
|
|
8624
|
+
}
|
|
8625
|
+
return defaultErrorCodeForResult(data.Result);
|
|
8626
|
+
}
|
|
8549
8627
|
function defaultRetryForErrorCode(errorCode) {
|
|
8550
8628
|
switch (errorCode) {
|
|
8551
8629
|
case "network_error":
|
|
@@ -8575,16 +8653,19 @@ var OutputFormatter;
|
|
|
8575
8653
|
OutputFormatter.success = success;
|
|
8576
8654
|
function error(data) {
|
|
8577
8655
|
data.Log ??= getLogFilePath() || undefined;
|
|
8578
|
-
data.ErrorCode ??=
|
|
8656
|
+
data.ErrorCode ??= defaultErrorCodeForFailure(data);
|
|
8579
8657
|
data.Retry ??= defaultRetryForErrorCode(data.ErrorCode);
|
|
8580
8658
|
process.exitCode = EXIT_CODES[data.Result] ?? 1;
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8659
|
+
const { SuppressTelemetry, ...envelope } = data;
|
|
8660
|
+
if (!SuppressTelemetry) {
|
|
8661
|
+
telemetry.trackEvent(CommonTelemetryEvents.Error, {
|
|
8662
|
+
result: data.Result,
|
|
8663
|
+
errorCode: data.ErrorCode,
|
|
8664
|
+
retry: data.Retry,
|
|
8665
|
+
message: data.Message
|
|
8666
|
+
});
|
|
8667
|
+
}
|
|
8668
|
+
logOutput(normalizeOutputKeys(envelope), getOutputFormat());
|
|
8588
8669
|
}
|
|
8589
8670
|
OutputFormatter.error = error;
|
|
8590
8671
|
function emitList(code, items, opts) {
|
|
@@ -8866,1409 +8947,6 @@ var savedOriginalsSlot = singleton("ConsoleGuardOriginals");
|
|
|
8866
8947
|
var DEFAULT_AUTH_TIMEOUT_MS = 5 * 60 * 1000;
|
|
8867
8948
|
// ../common/src/interactivity-context.ts
|
|
8868
8949
|
var modeSlot = singleton("InteractivityMode");
|
|
8869
|
-
// ../../node_modules/jsonpath-plus/dist/index-node-esm.js
|
|
8870
|
-
import vm from "vm";
|
|
8871
|
-
|
|
8872
|
-
class Hooks {
|
|
8873
|
-
add(name, callback, first) {
|
|
8874
|
-
if (typeof arguments[0] != "string") {
|
|
8875
|
-
for (let name2 in arguments[0]) {
|
|
8876
|
-
this.add(name2, arguments[0][name2], arguments[1]);
|
|
8877
|
-
}
|
|
8878
|
-
} else {
|
|
8879
|
-
(Array.isArray(name) ? name : [name]).forEach(function(name2) {
|
|
8880
|
-
this[name2] = this[name2] || [];
|
|
8881
|
-
if (callback) {
|
|
8882
|
-
this[name2][first ? "unshift" : "push"](callback);
|
|
8883
|
-
}
|
|
8884
|
-
}, this);
|
|
8885
|
-
}
|
|
8886
|
-
}
|
|
8887
|
-
run(name, env) {
|
|
8888
|
-
this[name] = this[name] || [];
|
|
8889
|
-
this[name].forEach(function(callback) {
|
|
8890
|
-
callback.call(env && env.context ? env.context : env, env);
|
|
8891
|
-
});
|
|
8892
|
-
}
|
|
8893
|
-
}
|
|
8894
|
-
|
|
8895
|
-
class Plugins {
|
|
8896
|
-
constructor(jsep) {
|
|
8897
|
-
this.jsep = jsep;
|
|
8898
|
-
this.registered = {};
|
|
8899
|
-
}
|
|
8900
|
-
register(...plugins) {
|
|
8901
|
-
plugins.forEach((plugin) => {
|
|
8902
|
-
if (typeof plugin !== "object" || !plugin.name || !plugin.init) {
|
|
8903
|
-
throw new Error("Invalid JSEP plugin format");
|
|
8904
|
-
}
|
|
8905
|
-
if (this.registered[plugin.name]) {
|
|
8906
|
-
return;
|
|
8907
|
-
}
|
|
8908
|
-
plugin.init(this.jsep);
|
|
8909
|
-
this.registered[plugin.name] = plugin;
|
|
8910
|
-
});
|
|
8911
|
-
}
|
|
8912
|
-
}
|
|
8913
|
-
|
|
8914
|
-
class Jsep {
|
|
8915
|
-
static get version() {
|
|
8916
|
-
return "1.4.0";
|
|
8917
|
-
}
|
|
8918
|
-
static toString() {
|
|
8919
|
-
return "JavaScript Expression Parser (JSEP) v" + Jsep.version;
|
|
8920
|
-
}
|
|
8921
|
-
static addUnaryOp(op_name) {
|
|
8922
|
-
Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
|
|
8923
|
-
Jsep.unary_ops[op_name] = 1;
|
|
8924
|
-
return Jsep;
|
|
8925
|
-
}
|
|
8926
|
-
static addBinaryOp(op_name, precedence, isRightAssociative) {
|
|
8927
|
-
Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
|
|
8928
|
-
Jsep.binary_ops[op_name] = precedence;
|
|
8929
|
-
if (isRightAssociative) {
|
|
8930
|
-
Jsep.right_associative.add(op_name);
|
|
8931
|
-
} else {
|
|
8932
|
-
Jsep.right_associative.delete(op_name);
|
|
8933
|
-
}
|
|
8934
|
-
return Jsep;
|
|
8935
|
-
}
|
|
8936
|
-
static addIdentifierChar(char) {
|
|
8937
|
-
Jsep.additional_identifier_chars.add(char);
|
|
8938
|
-
return Jsep;
|
|
8939
|
-
}
|
|
8940
|
-
static addLiteral(literal_name, literal_value) {
|
|
8941
|
-
Jsep.literals[literal_name] = literal_value;
|
|
8942
|
-
return Jsep;
|
|
8943
|
-
}
|
|
8944
|
-
static removeUnaryOp(op_name) {
|
|
8945
|
-
delete Jsep.unary_ops[op_name];
|
|
8946
|
-
if (op_name.length === Jsep.max_unop_len) {
|
|
8947
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
8948
|
-
}
|
|
8949
|
-
return Jsep;
|
|
8950
|
-
}
|
|
8951
|
-
static removeAllUnaryOps() {
|
|
8952
|
-
Jsep.unary_ops = {};
|
|
8953
|
-
Jsep.max_unop_len = 0;
|
|
8954
|
-
return Jsep;
|
|
8955
|
-
}
|
|
8956
|
-
static removeIdentifierChar(char) {
|
|
8957
|
-
Jsep.additional_identifier_chars.delete(char);
|
|
8958
|
-
return Jsep;
|
|
8959
|
-
}
|
|
8960
|
-
static removeBinaryOp(op_name) {
|
|
8961
|
-
delete Jsep.binary_ops[op_name];
|
|
8962
|
-
if (op_name.length === Jsep.max_binop_len) {
|
|
8963
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
8964
|
-
}
|
|
8965
|
-
Jsep.right_associative.delete(op_name);
|
|
8966
|
-
return Jsep;
|
|
8967
|
-
}
|
|
8968
|
-
static removeAllBinaryOps() {
|
|
8969
|
-
Jsep.binary_ops = {};
|
|
8970
|
-
Jsep.max_binop_len = 0;
|
|
8971
|
-
return Jsep;
|
|
8972
|
-
}
|
|
8973
|
-
static removeLiteral(literal_name) {
|
|
8974
|
-
delete Jsep.literals[literal_name];
|
|
8975
|
-
return Jsep;
|
|
8976
|
-
}
|
|
8977
|
-
static removeAllLiterals() {
|
|
8978
|
-
Jsep.literals = {};
|
|
8979
|
-
return Jsep;
|
|
8980
|
-
}
|
|
8981
|
-
get char() {
|
|
8982
|
-
return this.expr.charAt(this.index);
|
|
8983
|
-
}
|
|
8984
|
-
get code() {
|
|
8985
|
-
return this.expr.charCodeAt(this.index);
|
|
8986
|
-
}
|
|
8987
|
-
constructor(expr) {
|
|
8988
|
-
this.expr = expr;
|
|
8989
|
-
this.index = 0;
|
|
8990
|
-
}
|
|
8991
|
-
static parse(expr) {
|
|
8992
|
-
return new Jsep(expr).parse();
|
|
8993
|
-
}
|
|
8994
|
-
static getMaxKeyLen(obj) {
|
|
8995
|
-
return Math.max(0, ...Object.keys(obj).map((k) => k.length));
|
|
8996
|
-
}
|
|
8997
|
-
static isDecimalDigit(ch) {
|
|
8998
|
-
return ch >= 48 && ch <= 57;
|
|
8999
|
-
}
|
|
9000
|
-
static binaryPrecedence(op_val) {
|
|
9001
|
-
return Jsep.binary_ops[op_val] || 0;
|
|
9002
|
-
}
|
|
9003
|
-
static isIdentifierStart(ch) {
|
|
9004
|
-
return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)] || Jsep.additional_identifier_chars.has(String.fromCharCode(ch));
|
|
9005
|
-
}
|
|
9006
|
-
static isIdentifierPart(ch) {
|
|
9007
|
-
return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
|
|
9008
|
-
}
|
|
9009
|
-
throwError(message) {
|
|
9010
|
-
const error = new Error(message + " at character " + this.index);
|
|
9011
|
-
error.index = this.index;
|
|
9012
|
-
error.description = message;
|
|
9013
|
-
throw error;
|
|
9014
|
-
}
|
|
9015
|
-
runHook(name, node) {
|
|
9016
|
-
if (Jsep.hooks[name]) {
|
|
9017
|
-
const env = {
|
|
9018
|
-
context: this,
|
|
9019
|
-
node
|
|
9020
|
-
};
|
|
9021
|
-
Jsep.hooks.run(name, env);
|
|
9022
|
-
return env.node;
|
|
9023
|
-
}
|
|
9024
|
-
return node;
|
|
9025
|
-
}
|
|
9026
|
-
searchHook(name) {
|
|
9027
|
-
if (Jsep.hooks[name]) {
|
|
9028
|
-
const env = {
|
|
9029
|
-
context: this
|
|
9030
|
-
};
|
|
9031
|
-
Jsep.hooks[name].find(function(callback) {
|
|
9032
|
-
callback.call(env.context, env);
|
|
9033
|
-
return env.node;
|
|
9034
|
-
});
|
|
9035
|
-
return env.node;
|
|
9036
|
-
}
|
|
9037
|
-
}
|
|
9038
|
-
gobbleSpaces() {
|
|
9039
|
-
let ch = this.code;
|
|
9040
|
-
while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) {
|
|
9041
|
-
ch = this.expr.charCodeAt(++this.index);
|
|
9042
|
-
}
|
|
9043
|
-
this.runHook("gobble-spaces");
|
|
9044
|
-
}
|
|
9045
|
-
parse() {
|
|
9046
|
-
this.runHook("before-all");
|
|
9047
|
-
const nodes = this.gobbleExpressions();
|
|
9048
|
-
const node = nodes.length === 1 ? nodes[0] : {
|
|
9049
|
-
type: Jsep.COMPOUND,
|
|
9050
|
-
body: nodes
|
|
9051
|
-
};
|
|
9052
|
-
return this.runHook("after-all", node);
|
|
9053
|
-
}
|
|
9054
|
-
gobbleExpressions(untilICode) {
|
|
9055
|
-
let nodes = [], ch_i, node;
|
|
9056
|
-
while (this.index < this.expr.length) {
|
|
9057
|
-
ch_i = this.code;
|
|
9058
|
-
if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
|
|
9059
|
-
this.index++;
|
|
9060
|
-
} else {
|
|
9061
|
-
if (node = this.gobbleExpression()) {
|
|
9062
|
-
nodes.push(node);
|
|
9063
|
-
} else if (this.index < this.expr.length) {
|
|
9064
|
-
if (ch_i === untilICode) {
|
|
9065
|
-
break;
|
|
9066
|
-
}
|
|
9067
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
9068
|
-
}
|
|
9069
|
-
}
|
|
9070
|
-
}
|
|
9071
|
-
return nodes;
|
|
9072
|
-
}
|
|
9073
|
-
gobbleExpression() {
|
|
9074
|
-
const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
|
|
9075
|
-
this.gobbleSpaces();
|
|
9076
|
-
return this.runHook("after-expression", node);
|
|
9077
|
-
}
|
|
9078
|
-
gobbleBinaryOp() {
|
|
9079
|
-
this.gobbleSpaces();
|
|
9080
|
-
let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
|
|
9081
|
-
let tc_len = to_check.length;
|
|
9082
|
-
while (tc_len > 0) {
|
|
9083
|
-
if (Jsep.binary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
|
|
9084
|
-
this.index += tc_len;
|
|
9085
|
-
return to_check;
|
|
9086
|
-
}
|
|
9087
|
-
to_check = to_check.substr(0, --tc_len);
|
|
9088
|
-
}
|
|
9089
|
-
return false;
|
|
9090
|
-
}
|
|
9091
|
-
gobbleBinaryExpression() {
|
|
9092
|
-
let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
|
|
9093
|
-
left = this.gobbleToken();
|
|
9094
|
-
if (!left) {
|
|
9095
|
-
return left;
|
|
9096
|
-
}
|
|
9097
|
-
biop = this.gobbleBinaryOp();
|
|
9098
|
-
if (!biop) {
|
|
9099
|
-
return left;
|
|
9100
|
-
}
|
|
9101
|
-
biop_info = {
|
|
9102
|
-
value: biop,
|
|
9103
|
-
prec: Jsep.binaryPrecedence(biop),
|
|
9104
|
-
right_a: Jsep.right_associative.has(biop)
|
|
9105
|
-
};
|
|
9106
|
-
right = this.gobbleToken();
|
|
9107
|
-
if (!right) {
|
|
9108
|
-
this.throwError("Expected expression after " + biop);
|
|
9109
|
-
}
|
|
9110
|
-
stack = [left, biop_info, right];
|
|
9111
|
-
while (biop = this.gobbleBinaryOp()) {
|
|
9112
|
-
prec = Jsep.binaryPrecedence(biop);
|
|
9113
|
-
if (prec === 0) {
|
|
9114
|
-
this.index -= biop.length;
|
|
9115
|
-
break;
|
|
9116
|
-
}
|
|
9117
|
-
biop_info = {
|
|
9118
|
-
value: biop,
|
|
9119
|
-
prec,
|
|
9120
|
-
right_a: Jsep.right_associative.has(biop)
|
|
9121
|
-
};
|
|
9122
|
-
cur_biop = biop;
|
|
9123
|
-
const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
|
|
9124
|
-
while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
|
|
9125
|
-
right = stack.pop();
|
|
9126
|
-
biop = stack.pop().value;
|
|
9127
|
-
left = stack.pop();
|
|
9128
|
-
node = {
|
|
9129
|
-
type: Jsep.BINARY_EXP,
|
|
9130
|
-
operator: biop,
|
|
9131
|
-
left,
|
|
9132
|
-
right
|
|
9133
|
-
};
|
|
9134
|
-
stack.push(node);
|
|
9135
|
-
}
|
|
9136
|
-
node = this.gobbleToken();
|
|
9137
|
-
if (!node) {
|
|
9138
|
-
this.throwError("Expected expression after " + cur_biop);
|
|
9139
|
-
}
|
|
9140
|
-
stack.push(biop_info, node);
|
|
9141
|
-
}
|
|
9142
|
-
i = stack.length - 1;
|
|
9143
|
-
node = stack[i];
|
|
9144
|
-
while (i > 1) {
|
|
9145
|
-
node = {
|
|
9146
|
-
type: Jsep.BINARY_EXP,
|
|
9147
|
-
operator: stack[i - 1].value,
|
|
9148
|
-
left: stack[i - 2],
|
|
9149
|
-
right: node
|
|
9150
|
-
};
|
|
9151
|
-
i -= 2;
|
|
9152
|
-
}
|
|
9153
|
-
return node;
|
|
9154
|
-
}
|
|
9155
|
-
gobbleToken() {
|
|
9156
|
-
let ch, to_check, tc_len, node;
|
|
9157
|
-
this.gobbleSpaces();
|
|
9158
|
-
node = this.searchHook("gobble-token");
|
|
9159
|
-
if (node) {
|
|
9160
|
-
return this.runHook("after-token", node);
|
|
9161
|
-
}
|
|
9162
|
-
ch = this.code;
|
|
9163
|
-
if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
|
|
9164
|
-
return this.gobbleNumericLiteral();
|
|
9165
|
-
}
|
|
9166
|
-
if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
|
|
9167
|
-
node = this.gobbleStringLiteral();
|
|
9168
|
-
} else if (ch === Jsep.OBRACK_CODE) {
|
|
9169
|
-
node = this.gobbleArray();
|
|
9170
|
-
} else {
|
|
9171
|
-
to_check = this.expr.substr(this.index, Jsep.max_unop_len);
|
|
9172
|
-
tc_len = to_check.length;
|
|
9173
|
-
while (tc_len > 0) {
|
|
9174
|
-
if (Jsep.unary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
|
|
9175
|
-
this.index += tc_len;
|
|
9176
|
-
const argument = this.gobbleToken();
|
|
9177
|
-
if (!argument) {
|
|
9178
|
-
this.throwError("missing unaryOp argument");
|
|
9179
|
-
}
|
|
9180
|
-
return this.runHook("after-token", {
|
|
9181
|
-
type: Jsep.UNARY_EXP,
|
|
9182
|
-
operator: to_check,
|
|
9183
|
-
argument,
|
|
9184
|
-
prefix: true
|
|
9185
|
-
});
|
|
9186
|
-
}
|
|
9187
|
-
to_check = to_check.substr(0, --tc_len);
|
|
9188
|
-
}
|
|
9189
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
9190
|
-
node = this.gobbleIdentifier();
|
|
9191
|
-
if (Jsep.literals.hasOwnProperty(node.name)) {
|
|
9192
|
-
node = {
|
|
9193
|
-
type: Jsep.LITERAL,
|
|
9194
|
-
value: Jsep.literals[node.name],
|
|
9195
|
-
raw: node.name
|
|
9196
|
-
};
|
|
9197
|
-
} else if (node.name === Jsep.this_str) {
|
|
9198
|
-
node = {
|
|
9199
|
-
type: Jsep.THIS_EXP
|
|
9200
|
-
};
|
|
9201
|
-
}
|
|
9202
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
9203
|
-
node = this.gobbleGroup();
|
|
9204
|
-
}
|
|
9205
|
-
}
|
|
9206
|
-
if (!node) {
|
|
9207
|
-
return this.runHook("after-token", false);
|
|
9208
|
-
}
|
|
9209
|
-
node = this.gobbleTokenProperty(node);
|
|
9210
|
-
return this.runHook("after-token", node);
|
|
9211
|
-
}
|
|
9212
|
-
gobbleTokenProperty(node) {
|
|
9213
|
-
this.gobbleSpaces();
|
|
9214
|
-
let ch = this.code;
|
|
9215
|
-
while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {
|
|
9216
|
-
let optional;
|
|
9217
|
-
if (ch === Jsep.QUMARK_CODE) {
|
|
9218
|
-
if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {
|
|
9219
|
-
break;
|
|
9220
|
-
}
|
|
9221
|
-
optional = true;
|
|
9222
|
-
this.index += 2;
|
|
9223
|
-
this.gobbleSpaces();
|
|
9224
|
-
ch = this.code;
|
|
9225
|
-
}
|
|
9226
|
-
this.index++;
|
|
9227
|
-
if (ch === Jsep.OBRACK_CODE) {
|
|
9228
|
-
node = {
|
|
9229
|
-
type: Jsep.MEMBER_EXP,
|
|
9230
|
-
computed: true,
|
|
9231
|
-
object: node,
|
|
9232
|
-
property: this.gobbleExpression()
|
|
9233
|
-
};
|
|
9234
|
-
if (!node.property) {
|
|
9235
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
9236
|
-
}
|
|
9237
|
-
this.gobbleSpaces();
|
|
9238
|
-
ch = this.code;
|
|
9239
|
-
if (ch !== Jsep.CBRACK_CODE) {
|
|
9240
|
-
this.throwError("Unclosed [");
|
|
9241
|
-
}
|
|
9242
|
-
this.index++;
|
|
9243
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
9244
|
-
node = {
|
|
9245
|
-
type: Jsep.CALL_EXP,
|
|
9246
|
-
arguments: this.gobbleArguments(Jsep.CPAREN_CODE),
|
|
9247
|
-
callee: node
|
|
9248
|
-
};
|
|
9249
|
-
} else if (ch === Jsep.PERIOD_CODE || optional) {
|
|
9250
|
-
if (optional) {
|
|
9251
|
-
this.index--;
|
|
9252
|
-
}
|
|
9253
|
-
this.gobbleSpaces();
|
|
9254
|
-
node = {
|
|
9255
|
-
type: Jsep.MEMBER_EXP,
|
|
9256
|
-
computed: false,
|
|
9257
|
-
object: node,
|
|
9258
|
-
property: this.gobbleIdentifier()
|
|
9259
|
-
};
|
|
9260
|
-
}
|
|
9261
|
-
if (optional) {
|
|
9262
|
-
node.optional = true;
|
|
9263
|
-
}
|
|
9264
|
-
this.gobbleSpaces();
|
|
9265
|
-
ch = this.code;
|
|
9266
|
-
}
|
|
9267
|
-
return node;
|
|
9268
|
-
}
|
|
9269
|
-
gobbleNumericLiteral() {
|
|
9270
|
-
let number = "", ch, chCode;
|
|
9271
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
9272
|
-
number += this.expr.charAt(this.index++);
|
|
9273
|
-
}
|
|
9274
|
-
if (this.code === Jsep.PERIOD_CODE) {
|
|
9275
|
-
number += this.expr.charAt(this.index++);
|
|
9276
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
9277
|
-
number += this.expr.charAt(this.index++);
|
|
9278
|
-
}
|
|
9279
|
-
}
|
|
9280
|
-
ch = this.char;
|
|
9281
|
-
if (ch === "e" || ch === "E") {
|
|
9282
|
-
number += this.expr.charAt(this.index++);
|
|
9283
|
-
ch = this.char;
|
|
9284
|
-
if (ch === "+" || ch === "-") {
|
|
9285
|
-
number += this.expr.charAt(this.index++);
|
|
9286
|
-
}
|
|
9287
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
9288
|
-
number += this.expr.charAt(this.index++);
|
|
9289
|
-
}
|
|
9290
|
-
if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
|
|
9291
|
-
this.throwError("Expected exponent (" + number + this.char + ")");
|
|
9292
|
-
}
|
|
9293
|
-
}
|
|
9294
|
-
chCode = this.code;
|
|
9295
|
-
if (Jsep.isIdentifierStart(chCode)) {
|
|
9296
|
-
this.throwError("Variable names cannot start with a number (" + number + this.char + ")");
|
|
9297
|
-
} else if (chCode === Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE) {
|
|
9298
|
-
this.throwError("Unexpected period");
|
|
9299
|
-
}
|
|
9300
|
-
return {
|
|
9301
|
-
type: Jsep.LITERAL,
|
|
9302
|
-
value: parseFloat(number),
|
|
9303
|
-
raw: number
|
|
9304
|
-
};
|
|
9305
|
-
}
|
|
9306
|
-
gobbleStringLiteral() {
|
|
9307
|
-
let str = "";
|
|
9308
|
-
const startIndex = this.index;
|
|
9309
|
-
const quote = this.expr.charAt(this.index++);
|
|
9310
|
-
let closed = false;
|
|
9311
|
-
while (this.index < this.expr.length) {
|
|
9312
|
-
let ch = this.expr.charAt(this.index++);
|
|
9313
|
-
if (ch === quote) {
|
|
9314
|
-
closed = true;
|
|
9315
|
-
break;
|
|
9316
|
-
} else if (ch === "\\") {
|
|
9317
|
-
ch = this.expr.charAt(this.index++);
|
|
9318
|
-
switch (ch) {
|
|
9319
|
-
case "n":
|
|
9320
|
-
str += `
|
|
9321
|
-
`;
|
|
9322
|
-
break;
|
|
9323
|
-
case "r":
|
|
9324
|
-
str += "\r";
|
|
9325
|
-
break;
|
|
9326
|
-
case "t":
|
|
9327
|
-
str += "\t";
|
|
9328
|
-
break;
|
|
9329
|
-
case "b":
|
|
9330
|
-
str += "\b";
|
|
9331
|
-
break;
|
|
9332
|
-
case "f":
|
|
9333
|
-
str += "\f";
|
|
9334
|
-
break;
|
|
9335
|
-
case "v":
|
|
9336
|
-
str += "\v";
|
|
9337
|
-
break;
|
|
9338
|
-
default:
|
|
9339
|
-
str += ch;
|
|
9340
|
-
}
|
|
9341
|
-
} else {
|
|
9342
|
-
str += ch;
|
|
9343
|
-
}
|
|
9344
|
-
}
|
|
9345
|
-
if (!closed) {
|
|
9346
|
-
this.throwError('Unclosed quote after "' + str + '"');
|
|
9347
|
-
}
|
|
9348
|
-
return {
|
|
9349
|
-
type: Jsep.LITERAL,
|
|
9350
|
-
value: str,
|
|
9351
|
-
raw: this.expr.substring(startIndex, this.index)
|
|
9352
|
-
};
|
|
9353
|
-
}
|
|
9354
|
-
gobbleIdentifier() {
|
|
9355
|
-
let ch = this.code, start = this.index;
|
|
9356
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
9357
|
-
this.index++;
|
|
9358
|
-
} else {
|
|
9359
|
-
this.throwError("Unexpected " + this.char);
|
|
9360
|
-
}
|
|
9361
|
-
while (this.index < this.expr.length) {
|
|
9362
|
-
ch = this.code;
|
|
9363
|
-
if (Jsep.isIdentifierPart(ch)) {
|
|
9364
|
-
this.index++;
|
|
9365
|
-
} else {
|
|
9366
|
-
break;
|
|
9367
|
-
}
|
|
9368
|
-
}
|
|
9369
|
-
return {
|
|
9370
|
-
type: Jsep.IDENTIFIER,
|
|
9371
|
-
name: this.expr.slice(start, this.index)
|
|
9372
|
-
};
|
|
9373
|
-
}
|
|
9374
|
-
gobbleArguments(termination) {
|
|
9375
|
-
const args = [];
|
|
9376
|
-
let closed = false;
|
|
9377
|
-
let separator_count = 0;
|
|
9378
|
-
while (this.index < this.expr.length) {
|
|
9379
|
-
this.gobbleSpaces();
|
|
9380
|
-
let ch_i = this.code;
|
|
9381
|
-
if (ch_i === termination) {
|
|
9382
|
-
closed = true;
|
|
9383
|
-
this.index++;
|
|
9384
|
-
if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
|
|
9385
|
-
this.throwError("Unexpected token " + String.fromCharCode(termination));
|
|
9386
|
-
}
|
|
9387
|
-
break;
|
|
9388
|
-
} else if (ch_i === Jsep.COMMA_CODE) {
|
|
9389
|
-
this.index++;
|
|
9390
|
-
separator_count++;
|
|
9391
|
-
if (separator_count !== args.length) {
|
|
9392
|
-
if (termination === Jsep.CPAREN_CODE) {
|
|
9393
|
-
this.throwError("Unexpected token ,");
|
|
9394
|
-
} else if (termination === Jsep.CBRACK_CODE) {
|
|
9395
|
-
for (let arg = args.length;arg < separator_count; arg++) {
|
|
9396
|
-
args.push(null);
|
|
9397
|
-
}
|
|
9398
|
-
}
|
|
9399
|
-
}
|
|
9400
|
-
} else if (args.length !== separator_count && separator_count !== 0) {
|
|
9401
|
-
this.throwError("Expected comma");
|
|
9402
|
-
} else {
|
|
9403
|
-
const node = this.gobbleExpression();
|
|
9404
|
-
if (!node || node.type === Jsep.COMPOUND) {
|
|
9405
|
-
this.throwError("Expected comma");
|
|
9406
|
-
}
|
|
9407
|
-
args.push(node);
|
|
9408
|
-
}
|
|
9409
|
-
}
|
|
9410
|
-
if (!closed) {
|
|
9411
|
-
this.throwError("Expected " + String.fromCharCode(termination));
|
|
9412
|
-
}
|
|
9413
|
-
return args;
|
|
9414
|
-
}
|
|
9415
|
-
gobbleGroup() {
|
|
9416
|
-
this.index++;
|
|
9417
|
-
let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
|
|
9418
|
-
if (this.code === Jsep.CPAREN_CODE) {
|
|
9419
|
-
this.index++;
|
|
9420
|
-
if (nodes.length === 1) {
|
|
9421
|
-
return nodes[0];
|
|
9422
|
-
} else if (!nodes.length) {
|
|
9423
|
-
return false;
|
|
9424
|
-
} else {
|
|
9425
|
-
return {
|
|
9426
|
-
type: Jsep.SEQUENCE_EXP,
|
|
9427
|
-
expressions: nodes
|
|
9428
|
-
};
|
|
9429
|
-
}
|
|
9430
|
-
} else {
|
|
9431
|
-
this.throwError("Unclosed (");
|
|
9432
|
-
}
|
|
9433
|
-
}
|
|
9434
|
-
gobbleArray() {
|
|
9435
|
-
this.index++;
|
|
9436
|
-
return {
|
|
9437
|
-
type: Jsep.ARRAY_EXP,
|
|
9438
|
-
elements: this.gobbleArguments(Jsep.CBRACK_CODE)
|
|
9439
|
-
};
|
|
9440
|
-
}
|
|
9441
|
-
}
|
|
9442
|
-
var hooks = new Hooks;
|
|
9443
|
-
Object.assign(Jsep, {
|
|
9444
|
-
hooks,
|
|
9445
|
-
plugins: new Plugins(Jsep),
|
|
9446
|
-
COMPOUND: "Compound",
|
|
9447
|
-
SEQUENCE_EXP: "SequenceExpression",
|
|
9448
|
-
IDENTIFIER: "Identifier",
|
|
9449
|
-
MEMBER_EXP: "MemberExpression",
|
|
9450
|
-
LITERAL: "Literal",
|
|
9451
|
-
THIS_EXP: "ThisExpression",
|
|
9452
|
-
CALL_EXP: "CallExpression",
|
|
9453
|
-
UNARY_EXP: "UnaryExpression",
|
|
9454
|
-
BINARY_EXP: "BinaryExpression",
|
|
9455
|
-
ARRAY_EXP: "ArrayExpression",
|
|
9456
|
-
TAB_CODE: 9,
|
|
9457
|
-
LF_CODE: 10,
|
|
9458
|
-
CR_CODE: 13,
|
|
9459
|
-
SPACE_CODE: 32,
|
|
9460
|
-
PERIOD_CODE: 46,
|
|
9461
|
-
COMMA_CODE: 44,
|
|
9462
|
-
SQUOTE_CODE: 39,
|
|
9463
|
-
DQUOTE_CODE: 34,
|
|
9464
|
-
OPAREN_CODE: 40,
|
|
9465
|
-
CPAREN_CODE: 41,
|
|
9466
|
-
OBRACK_CODE: 91,
|
|
9467
|
-
CBRACK_CODE: 93,
|
|
9468
|
-
QUMARK_CODE: 63,
|
|
9469
|
-
SEMCOL_CODE: 59,
|
|
9470
|
-
COLON_CODE: 58,
|
|
9471
|
-
unary_ops: {
|
|
9472
|
-
"-": 1,
|
|
9473
|
-
"!": 1,
|
|
9474
|
-
"~": 1,
|
|
9475
|
-
"+": 1
|
|
9476
|
-
},
|
|
9477
|
-
binary_ops: {
|
|
9478
|
-
"||": 1,
|
|
9479
|
-
"??": 1,
|
|
9480
|
-
"&&": 2,
|
|
9481
|
-
"|": 3,
|
|
9482
|
-
"^": 4,
|
|
9483
|
-
"&": 5,
|
|
9484
|
-
"==": 6,
|
|
9485
|
-
"!=": 6,
|
|
9486
|
-
"===": 6,
|
|
9487
|
-
"!==": 6,
|
|
9488
|
-
"<": 7,
|
|
9489
|
-
">": 7,
|
|
9490
|
-
"<=": 7,
|
|
9491
|
-
">=": 7,
|
|
9492
|
-
"<<": 8,
|
|
9493
|
-
">>": 8,
|
|
9494
|
-
">>>": 8,
|
|
9495
|
-
"+": 9,
|
|
9496
|
-
"-": 9,
|
|
9497
|
-
"*": 10,
|
|
9498
|
-
"/": 10,
|
|
9499
|
-
"%": 10,
|
|
9500
|
-
"**": 11
|
|
9501
|
-
},
|
|
9502
|
-
right_associative: new Set(["**"]),
|
|
9503
|
-
additional_identifier_chars: new Set(["$", "_"]),
|
|
9504
|
-
literals: {
|
|
9505
|
-
true: true,
|
|
9506
|
-
false: false,
|
|
9507
|
-
null: null
|
|
9508
|
-
},
|
|
9509
|
-
this_str: "this"
|
|
9510
|
-
});
|
|
9511
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
9512
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
9513
|
-
var jsep = (expr) => new Jsep(expr).parse();
|
|
9514
|
-
var stdClassProps = Object.getOwnPropertyNames(class Test {
|
|
9515
|
-
});
|
|
9516
|
-
Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === undefined).forEach((m) => {
|
|
9517
|
-
jsep[m] = Jsep[m];
|
|
9518
|
-
});
|
|
9519
|
-
jsep.Jsep = Jsep;
|
|
9520
|
-
var CONDITIONAL_EXP = "ConditionalExpression";
|
|
9521
|
-
var ternary = {
|
|
9522
|
-
name: "ternary",
|
|
9523
|
-
init(jsep2) {
|
|
9524
|
-
jsep2.hooks.add("after-expression", function gobbleTernary(env) {
|
|
9525
|
-
if (env.node && this.code === jsep2.QUMARK_CODE) {
|
|
9526
|
-
this.index++;
|
|
9527
|
-
const test = env.node;
|
|
9528
|
-
const consequent = this.gobbleExpression();
|
|
9529
|
-
if (!consequent) {
|
|
9530
|
-
this.throwError("Expected expression");
|
|
9531
|
-
}
|
|
9532
|
-
this.gobbleSpaces();
|
|
9533
|
-
if (this.code === jsep2.COLON_CODE) {
|
|
9534
|
-
this.index++;
|
|
9535
|
-
const alternate = this.gobbleExpression();
|
|
9536
|
-
if (!alternate) {
|
|
9537
|
-
this.throwError("Expected expression");
|
|
9538
|
-
}
|
|
9539
|
-
env.node = {
|
|
9540
|
-
type: CONDITIONAL_EXP,
|
|
9541
|
-
test,
|
|
9542
|
-
consequent,
|
|
9543
|
-
alternate
|
|
9544
|
-
};
|
|
9545
|
-
if (test.operator && jsep2.binary_ops[test.operator] <= 0.9) {
|
|
9546
|
-
let newTest = test;
|
|
9547
|
-
while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
|
|
9548
|
-
newTest = newTest.right;
|
|
9549
|
-
}
|
|
9550
|
-
env.node.test = newTest.right;
|
|
9551
|
-
newTest.right = env.node;
|
|
9552
|
-
env.node = test;
|
|
9553
|
-
}
|
|
9554
|
-
} else {
|
|
9555
|
-
this.throwError("Expected :");
|
|
9556
|
-
}
|
|
9557
|
-
}
|
|
9558
|
-
});
|
|
9559
|
-
}
|
|
9560
|
-
};
|
|
9561
|
-
jsep.plugins.register(ternary);
|
|
9562
|
-
var FSLASH_CODE = 47;
|
|
9563
|
-
var BSLASH_CODE = 92;
|
|
9564
|
-
var index = {
|
|
9565
|
-
name: "regex",
|
|
9566
|
-
init(jsep2) {
|
|
9567
|
-
jsep2.hooks.add("gobble-token", function gobbleRegexLiteral(env) {
|
|
9568
|
-
if (this.code === FSLASH_CODE) {
|
|
9569
|
-
const patternIndex = ++this.index;
|
|
9570
|
-
let inCharSet = false;
|
|
9571
|
-
while (this.index < this.expr.length) {
|
|
9572
|
-
if (this.code === FSLASH_CODE && !inCharSet) {
|
|
9573
|
-
const pattern = this.expr.slice(patternIndex, this.index);
|
|
9574
|
-
let flags = "";
|
|
9575
|
-
while (++this.index < this.expr.length) {
|
|
9576
|
-
const code = this.code;
|
|
9577
|
-
if (code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57) {
|
|
9578
|
-
flags += this.char;
|
|
9579
|
-
} else {
|
|
9580
|
-
break;
|
|
9581
|
-
}
|
|
9582
|
-
}
|
|
9583
|
-
let value;
|
|
9584
|
-
try {
|
|
9585
|
-
value = new RegExp(pattern, flags);
|
|
9586
|
-
} catch (e) {
|
|
9587
|
-
this.throwError(e.message);
|
|
9588
|
-
}
|
|
9589
|
-
env.node = {
|
|
9590
|
-
type: jsep2.LITERAL,
|
|
9591
|
-
value,
|
|
9592
|
-
raw: this.expr.slice(patternIndex - 1, this.index)
|
|
9593
|
-
};
|
|
9594
|
-
env.node = this.gobbleTokenProperty(env.node);
|
|
9595
|
-
return env.node;
|
|
9596
|
-
}
|
|
9597
|
-
if (this.code === jsep2.OBRACK_CODE) {
|
|
9598
|
-
inCharSet = true;
|
|
9599
|
-
} else if (inCharSet && this.code === jsep2.CBRACK_CODE) {
|
|
9600
|
-
inCharSet = false;
|
|
9601
|
-
}
|
|
9602
|
-
this.index += this.code === BSLASH_CODE ? 2 : 1;
|
|
9603
|
-
}
|
|
9604
|
-
this.throwError("Unclosed Regex");
|
|
9605
|
-
}
|
|
9606
|
-
});
|
|
9607
|
-
}
|
|
9608
|
-
};
|
|
9609
|
-
var PLUS_CODE = 43;
|
|
9610
|
-
var MINUS_CODE = 45;
|
|
9611
|
-
var plugin = {
|
|
9612
|
-
name: "assignment",
|
|
9613
|
-
assignmentOperators: new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
9614
|
-
updateOperators: [PLUS_CODE, MINUS_CODE],
|
|
9615
|
-
assignmentPrecedence: 0.9,
|
|
9616
|
-
init(jsep2) {
|
|
9617
|
-
const updateNodeTypes = [jsep2.IDENTIFIER, jsep2.MEMBER_EXP];
|
|
9618
|
-
plugin.assignmentOperators.forEach((op) => jsep2.addBinaryOp(op, plugin.assignmentPrecedence, true));
|
|
9619
|
-
jsep2.hooks.add("gobble-token", function gobbleUpdatePrefix(env) {
|
|
9620
|
-
const code = this.code;
|
|
9621
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
9622
|
-
this.index += 2;
|
|
9623
|
-
env.node = {
|
|
9624
|
-
type: "UpdateExpression",
|
|
9625
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
9626
|
-
argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
|
|
9627
|
-
prefix: true
|
|
9628
|
-
};
|
|
9629
|
-
if (!env.node.argument || !updateNodeTypes.includes(env.node.argument.type)) {
|
|
9630
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
9631
|
-
}
|
|
9632
|
-
}
|
|
9633
|
-
});
|
|
9634
|
-
jsep2.hooks.add("after-token", function gobbleUpdatePostfix(env) {
|
|
9635
|
-
if (env.node) {
|
|
9636
|
-
const code = this.code;
|
|
9637
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
9638
|
-
if (!updateNodeTypes.includes(env.node.type)) {
|
|
9639
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
9640
|
-
}
|
|
9641
|
-
this.index += 2;
|
|
9642
|
-
env.node = {
|
|
9643
|
-
type: "UpdateExpression",
|
|
9644
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
9645
|
-
argument: env.node,
|
|
9646
|
-
prefix: false
|
|
9647
|
-
};
|
|
9648
|
-
}
|
|
9649
|
-
}
|
|
9650
|
-
});
|
|
9651
|
-
jsep2.hooks.add("after-expression", function gobbleAssignment(env) {
|
|
9652
|
-
if (env.node) {
|
|
9653
|
-
updateBinariesToAssignments(env.node);
|
|
9654
|
-
}
|
|
9655
|
-
});
|
|
9656
|
-
function updateBinariesToAssignments(node) {
|
|
9657
|
-
if (plugin.assignmentOperators.has(node.operator)) {
|
|
9658
|
-
node.type = "AssignmentExpression";
|
|
9659
|
-
updateBinariesToAssignments(node.left);
|
|
9660
|
-
updateBinariesToAssignments(node.right);
|
|
9661
|
-
} else if (!node.operator) {
|
|
9662
|
-
Object.values(node).forEach((val) => {
|
|
9663
|
-
if (val && typeof val === "object") {
|
|
9664
|
-
updateBinariesToAssignments(val);
|
|
9665
|
-
}
|
|
9666
|
-
});
|
|
9667
|
-
}
|
|
9668
|
-
}
|
|
9669
|
-
}
|
|
9670
|
-
};
|
|
9671
|
-
jsep.plugins.register(index, plugin);
|
|
9672
|
-
jsep.addUnaryOp("typeof");
|
|
9673
|
-
jsep.addUnaryOp("void");
|
|
9674
|
-
jsep.addLiteral("null", null);
|
|
9675
|
-
jsep.addLiteral("undefined", undefined);
|
|
9676
|
-
var BLOCKED_PROTO_PROPERTIES = new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
9677
|
-
var SafeEval = {
|
|
9678
|
-
evalAst(ast, subs) {
|
|
9679
|
-
switch (ast.type) {
|
|
9680
|
-
case "BinaryExpression":
|
|
9681
|
-
case "LogicalExpression":
|
|
9682
|
-
return SafeEval.evalBinaryExpression(ast, subs);
|
|
9683
|
-
case "Compound":
|
|
9684
|
-
return SafeEval.evalCompound(ast, subs);
|
|
9685
|
-
case "ConditionalExpression":
|
|
9686
|
-
return SafeEval.evalConditionalExpression(ast, subs);
|
|
9687
|
-
case "Identifier":
|
|
9688
|
-
return SafeEval.evalIdentifier(ast, subs);
|
|
9689
|
-
case "Literal":
|
|
9690
|
-
return SafeEval.evalLiteral(ast, subs);
|
|
9691
|
-
case "MemberExpression":
|
|
9692
|
-
return SafeEval.evalMemberExpression(ast, subs);
|
|
9693
|
-
case "UnaryExpression":
|
|
9694
|
-
return SafeEval.evalUnaryExpression(ast, subs);
|
|
9695
|
-
case "ArrayExpression":
|
|
9696
|
-
return SafeEval.evalArrayExpression(ast, subs);
|
|
9697
|
-
case "CallExpression":
|
|
9698
|
-
return SafeEval.evalCallExpression(ast, subs);
|
|
9699
|
-
case "AssignmentExpression":
|
|
9700
|
-
return SafeEval.evalAssignmentExpression(ast, subs);
|
|
9701
|
-
default:
|
|
9702
|
-
throw SyntaxError("Unexpected expression", ast);
|
|
9703
|
-
}
|
|
9704
|
-
},
|
|
9705
|
-
evalBinaryExpression(ast, subs) {
|
|
9706
|
-
const result = {
|
|
9707
|
-
"||": (a, b) => a || b(),
|
|
9708
|
-
"&&": (a, b) => a && b(),
|
|
9709
|
-
"|": (a, b) => a | b(),
|
|
9710
|
-
"^": (a, b) => a ^ b(),
|
|
9711
|
-
"&": (a, b) => a & b(),
|
|
9712
|
-
"==": (a, b) => a == b(),
|
|
9713
|
-
"!=": (a, b) => a != b(),
|
|
9714
|
-
"===": (a, b) => a === b(),
|
|
9715
|
-
"!==": (a, b) => a !== b(),
|
|
9716
|
-
"<": (a, b) => a < b(),
|
|
9717
|
-
">": (a, b) => a > b(),
|
|
9718
|
-
"<=": (a, b) => a <= b(),
|
|
9719
|
-
">=": (a, b) => a >= b(),
|
|
9720
|
-
"<<": (a, b) => a << b(),
|
|
9721
|
-
">>": (a, b) => a >> b(),
|
|
9722
|
-
">>>": (a, b) => a >>> b(),
|
|
9723
|
-
"+": (a, b) => a + b(),
|
|
9724
|
-
"-": (a, b) => a - b(),
|
|
9725
|
-
"*": (a, b) => a * b(),
|
|
9726
|
-
"/": (a, b) => a / b(),
|
|
9727
|
-
"%": (a, b) => a % b()
|
|
9728
|
-
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
|
|
9729
|
-
return result;
|
|
9730
|
-
},
|
|
9731
|
-
evalCompound(ast, subs) {
|
|
9732
|
-
let last;
|
|
9733
|
-
for (let i = 0;i < ast.body.length; i++) {
|
|
9734
|
-
if (ast.body[i].type === "Identifier" && ["var", "let", "const"].includes(ast.body[i].name) && ast.body[i + 1] && ast.body[i + 1].type === "AssignmentExpression") {
|
|
9735
|
-
i += 1;
|
|
9736
|
-
}
|
|
9737
|
-
const expr = ast.body[i];
|
|
9738
|
-
last = SafeEval.evalAst(expr, subs);
|
|
9739
|
-
}
|
|
9740
|
-
return last;
|
|
9741
|
-
},
|
|
9742
|
-
evalConditionalExpression(ast, subs) {
|
|
9743
|
-
if (SafeEval.evalAst(ast.test, subs)) {
|
|
9744
|
-
return SafeEval.evalAst(ast.consequent, subs);
|
|
9745
|
-
}
|
|
9746
|
-
return SafeEval.evalAst(ast.alternate, subs);
|
|
9747
|
-
},
|
|
9748
|
-
evalIdentifier(ast, subs) {
|
|
9749
|
-
if (Object.hasOwn(subs, ast.name)) {
|
|
9750
|
-
return subs[ast.name];
|
|
9751
|
-
}
|
|
9752
|
-
throw ReferenceError(`${ast.name} is not defined`);
|
|
9753
|
-
},
|
|
9754
|
-
evalLiteral(ast) {
|
|
9755
|
-
return ast.value;
|
|
9756
|
-
},
|
|
9757
|
-
evalMemberExpression(ast, subs) {
|
|
9758
|
-
const prop = String(ast.computed ? SafeEval.evalAst(ast.property) : ast.property.name);
|
|
9759
|
-
const obj = SafeEval.evalAst(ast.object, subs);
|
|
9760
|
-
if (obj === undefined || obj === null) {
|
|
9761
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
9762
|
-
}
|
|
9763
|
-
if (!Object.hasOwn(obj, prop) && BLOCKED_PROTO_PROPERTIES.has(prop)) {
|
|
9764
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
9765
|
-
}
|
|
9766
|
-
const result = obj[prop];
|
|
9767
|
-
if (typeof result === "function") {
|
|
9768
|
-
return result.bind(obj);
|
|
9769
|
-
}
|
|
9770
|
-
return result;
|
|
9771
|
-
},
|
|
9772
|
-
evalUnaryExpression(ast, subs) {
|
|
9773
|
-
const result = {
|
|
9774
|
-
"-": (a) => -SafeEval.evalAst(a, subs),
|
|
9775
|
-
"!": (a) => !SafeEval.evalAst(a, subs),
|
|
9776
|
-
"~": (a) => ~SafeEval.evalAst(a, subs),
|
|
9777
|
-
"+": (a) => +SafeEval.evalAst(a, subs),
|
|
9778
|
-
typeof: (a) => typeof SafeEval.evalAst(a, subs),
|
|
9779
|
-
void: (a) => void SafeEval.evalAst(a, subs)
|
|
9780
|
-
}[ast.operator](ast.argument);
|
|
9781
|
-
return result;
|
|
9782
|
-
},
|
|
9783
|
-
evalArrayExpression(ast, subs) {
|
|
9784
|
-
return ast.elements.map((el) => SafeEval.evalAst(el, subs));
|
|
9785
|
-
},
|
|
9786
|
-
evalCallExpression(ast, subs) {
|
|
9787
|
-
const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
|
|
9788
|
-
const func = SafeEval.evalAst(ast.callee, subs);
|
|
9789
|
-
if (func === Function) {
|
|
9790
|
-
throw new Error("Function constructor is disabled");
|
|
9791
|
-
}
|
|
9792
|
-
return func(...args);
|
|
9793
|
-
},
|
|
9794
|
-
evalAssignmentExpression(ast, subs) {
|
|
9795
|
-
if (ast.left.type !== "Identifier") {
|
|
9796
|
-
throw SyntaxError("Invalid left-hand side in assignment");
|
|
9797
|
-
}
|
|
9798
|
-
const id = ast.left.name;
|
|
9799
|
-
const value = SafeEval.evalAst(ast.right, subs);
|
|
9800
|
-
subs[id] = value;
|
|
9801
|
-
return subs[id];
|
|
9802
|
-
}
|
|
9803
|
-
};
|
|
9804
|
-
|
|
9805
|
-
class SafeScript {
|
|
9806
|
-
constructor(expr) {
|
|
9807
|
-
this.code = expr;
|
|
9808
|
-
this.ast = jsep(this.code);
|
|
9809
|
-
}
|
|
9810
|
-
runInNewContext(context) {
|
|
9811
|
-
const keyMap = Object.assign(Object.create(null), context);
|
|
9812
|
-
return SafeEval.evalAst(this.ast, keyMap);
|
|
9813
|
-
}
|
|
9814
|
-
}
|
|
9815
|
-
function push(arr, item) {
|
|
9816
|
-
arr = arr.slice();
|
|
9817
|
-
arr.push(item);
|
|
9818
|
-
return arr;
|
|
9819
|
-
}
|
|
9820
|
-
function unshift(item, arr) {
|
|
9821
|
-
arr = arr.slice();
|
|
9822
|
-
arr.unshift(item);
|
|
9823
|
-
return arr;
|
|
9824
|
-
}
|
|
9825
|
-
|
|
9826
|
-
class NewError extends Error {
|
|
9827
|
-
constructor(value) {
|
|
9828
|
-
super('JSONPath should not be called with "new" (it prevents return ' + "of (unwrapped) scalar values)");
|
|
9829
|
-
this.avoidNew = true;
|
|
9830
|
-
this.value = value;
|
|
9831
|
-
this.name = "NewError";
|
|
9832
|
-
}
|
|
9833
|
-
}
|
|
9834
|
-
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
|
|
9835
|
-
if (!(this instanceof JSONPath)) {
|
|
9836
|
-
try {
|
|
9837
|
-
return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
|
|
9838
|
-
} catch (e) {
|
|
9839
|
-
if (!e.avoidNew) {
|
|
9840
|
-
throw e;
|
|
9841
|
-
}
|
|
9842
|
-
return e.value;
|
|
9843
|
-
}
|
|
9844
|
-
}
|
|
9845
|
-
if (typeof opts === "string") {
|
|
9846
|
-
otherTypeCallback = callback;
|
|
9847
|
-
callback = obj;
|
|
9848
|
-
obj = expr;
|
|
9849
|
-
expr = opts;
|
|
9850
|
-
opts = null;
|
|
9851
|
-
}
|
|
9852
|
-
const optObj = opts && typeof opts === "object";
|
|
9853
|
-
opts = opts || {};
|
|
9854
|
-
this.json = opts.json || obj;
|
|
9855
|
-
this.path = opts.path || expr;
|
|
9856
|
-
this.resultType = opts.resultType || "value";
|
|
9857
|
-
this.flatten = opts.flatten || false;
|
|
9858
|
-
this.wrap = Object.hasOwn(opts, "wrap") ? opts.wrap : true;
|
|
9859
|
-
this.sandbox = opts.sandbox || {};
|
|
9860
|
-
this.eval = opts.eval === undefined ? "safe" : opts.eval;
|
|
9861
|
-
this.ignoreEvalErrors = typeof opts.ignoreEvalErrors === "undefined" ? false : opts.ignoreEvalErrors;
|
|
9862
|
-
this.parent = opts.parent || null;
|
|
9863
|
-
this.parentProperty = opts.parentProperty || null;
|
|
9864
|
-
this.callback = opts.callback || callback || null;
|
|
9865
|
-
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function() {
|
|
9866
|
-
throw new TypeError("You must supply an otherTypeCallback callback option " + "with the @other() operator.");
|
|
9867
|
-
};
|
|
9868
|
-
if (opts.autostart !== false) {
|
|
9869
|
-
const args = {
|
|
9870
|
-
path: optObj ? opts.path : expr
|
|
9871
|
-
};
|
|
9872
|
-
if (!optObj) {
|
|
9873
|
-
args.json = obj;
|
|
9874
|
-
} else if ("json" in opts) {
|
|
9875
|
-
args.json = opts.json;
|
|
9876
|
-
}
|
|
9877
|
-
const ret = this.evaluate(args);
|
|
9878
|
-
if (!ret || typeof ret !== "object") {
|
|
9879
|
-
throw new NewError(ret);
|
|
9880
|
-
}
|
|
9881
|
-
return ret;
|
|
9882
|
-
}
|
|
9883
|
-
}
|
|
9884
|
-
JSONPath.prototype.evaluate = function(expr, json, callback, otherTypeCallback) {
|
|
9885
|
-
let currParent = this.parent, currParentProperty = this.parentProperty;
|
|
9886
|
-
let {
|
|
9887
|
-
flatten,
|
|
9888
|
-
wrap
|
|
9889
|
-
} = this;
|
|
9890
|
-
this.currResultType = this.resultType;
|
|
9891
|
-
this.currEval = this.eval;
|
|
9892
|
-
this.currSandbox = this.sandbox;
|
|
9893
|
-
callback = callback || this.callback;
|
|
9894
|
-
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
9895
|
-
json = json || this.json;
|
|
9896
|
-
expr = expr || this.path;
|
|
9897
|
-
if (expr && typeof expr === "object" && !Array.isArray(expr)) {
|
|
9898
|
-
if (!expr.path && expr.path !== "") {
|
|
9899
|
-
throw new TypeError('You must supply a "path" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
9900
|
-
}
|
|
9901
|
-
if (!Object.hasOwn(expr, "json")) {
|
|
9902
|
-
throw new TypeError('You must supply a "json" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
9903
|
-
}
|
|
9904
|
-
({
|
|
9905
|
-
json
|
|
9906
|
-
} = expr);
|
|
9907
|
-
flatten = Object.hasOwn(expr, "flatten") ? expr.flatten : flatten;
|
|
9908
|
-
this.currResultType = Object.hasOwn(expr, "resultType") ? expr.resultType : this.currResultType;
|
|
9909
|
-
this.currSandbox = Object.hasOwn(expr, "sandbox") ? expr.sandbox : this.currSandbox;
|
|
9910
|
-
wrap = Object.hasOwn(expr, "wrap") ? expr.wrap : wrap;
|
|
9911
|
-
this.currEval = Object.hasOwn(expr, "eval") ? expr.eval : this.currEval;
|
|
9912
|
-
callback = Object.hasOwn(expr, "callback") ? expr.callback : callback;
|
|
9913
|
-
this.currOtherTypeCallback = Object.hasOwn(expr, "otherTypeCallback") ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
9914
|
-
currParent = Object.hasOwn(expr, "parent") ? expr.parent : currParent;
|
|
9915
|
-
currParentProperty = Object.hasOwn(expr, "parentProperty") ? expr.parentProperty : currParentProperty;
|
|
9916
|
-
expr = expr.path;
|
|
9917
|
-
}
|
|
9918
|
-
currParent = currParent || null;
|
|
9919
|
-
currParentProperty = currParentProperty || null;
|
|
9920
|
-
if (Array.isArray(expr)) {
|
|
9921
|
-
expr = JSONPath.toPathString(expr);
|
|
9922
|
-
}
|
|
9923
|
-
if (!expr && expr !== "" || !json) {
|
|
9924
|
-
return;
|
|
9925
|
-
}
|
|
9926
|
-
const exprList = JSONPath.toPathArray(expr);
|
|
9927
|
-
if (exprList[0] === "$" && exprList.length > 1) {
|
|
9928
|
-
exprList.shift();
|
|
9929
|
-
}
|
|
9930
|
-
this._hasParentSelector = null;
|
|
9931
|
-
const result = this._trace(exprList, json, ["$"], currParent, currParentProperty, callback).filter(function(ea) {
|
|
9932
|
-
return ea && !ea.isParentSelector;
|
|
9933
|
-
});
|
|
9934
|
-
if (!result.length) {
|
|
9935
|
-
return wrap ? [] : undefined;
|
|
9936
|
-
}
|
|
9937
|
-
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
|
|
9938
|
-
return this._getPreferredOutput(result[0]);
|
|
9939
|
-
}
|
|
9940
|
-
return result.reduce((rslt, ea) => {
|
|
9941
|
-
const valOrPath = this._getPreferredOutput(ea);
|
|
9942
|
-
if (flatten && Array.isArray(valOrPath)) {
|
|
9943
|
-
rslt = rslt.concat(valOrPath);
|
|
9944
|
-
} else {
|
|
9945
|
-
rslt.push(valOrPath);
|
|
9946
|
-
}
|
|
9947
|
-
return rslt;
|
|
9948
|
-
}, []);
|
|
9949
|
-
};
|
|
9950
|
-
JSONPath.prototype._getPreferredOutput = function(ea) {
|
|
9951
|
-
const resultType = this.currResultType;
|
|
9952
|
-
switch (resultType) {
|
|
9953
|
-
case "all": {
|
|
9954
|
-
const path3 = Array.isArray(ea.path) ? ea.path : JSONPath.toPathArray(ea.path);
|
|
9955
|
-
ea.pointer = JSONPath.toPointer(path3);
|
|
9956
|
-
ea.path = typeof ea.path === "string" ? ea.path : JSONPath.toPathString(ea.path);
|
|
9957
|
-
return ea;
|
|
9958
|
-
}
|
|
9959
|
-
case "value":
|
|
9960
|
-
case "parent":
|
|
9961
|
-
case "parentProperty":
|
|
9962
|
-
return ea[resultType];
|
|
9963
|
-
case "path":
|
|
9964
|
-
return JSONPath.toPathString(ea[resultType]);
|
|
9965
|
-
case "pointer":
|
|
9966
|
-
return JSONPath.toPointer(ea.path);
|
|
9967
|
-
default:
|
|
9968
|
-
throw new TypeError("Unknown result type");
|
|
9969
|
-
}
|
|
9970
|
-
};
|
|
9971
|
-
JSONPath.prototype._handleCallback = function(fullRetObj, callback, type) {
|
|
9972
|
-
if (callback) {
|
|
9973
|
-
const preferredOutput = this._getPreferredOutput(fullRetObj);
|
|
9974
|
-
fullRetObj.path = typeof fullRetObj.path === "string" ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
|
|
9975
|
-
callback(preferredOutput, type, fullRetObj);
|
|
9976
|
-
}
|
|
9977
|
-
};
|
|
9978
|
-
JSONPath.prototype._trace = function(expr, val, path3, parent, parentPropName, callback, hasArrExpr, literalPriority) {
|
|
9979
|
-
let retObj;
|
|
9980
|
-
if (!expr.length) {
|
|
9981
|
-
retObj = {
|
|
9982
|
-
path: path3,
|
|
9983
|
-
value: val,
|
|
9984
|
-
parent,
|
|
9985
|
-
parentProperty: parentPropName,
|
|
9986
|
-
hasArrExpr
|
|
9987
|
-
};
|
|
9988
|
-
this._handleCallback(retObj, callback, "value");
|
|
9989
|
-
return retObj;
|
|
9990
|
-
}
|
|
9991
|
-
const loc = expr[0], x = expr.slice(1);
|
|
9992
|
-
const ret = [];
|
|
9993
|
-
function addRet(elems) {
|
|
9994
|
-
if (Array.isArray(elems)) {
|
|
9995
|
-
elems.forEach((t) => {
|
|
9996
|
-
ret.push(t);
|
|
9997
|
-
});
|
|
9998
|
-
} else {
|
|
9999
|
-
ret.push(elems);
|
|
10000
|
-
}
|
|
10001
|
-
}
|
|
10002
|
-
if ((typeof loc !== "string" || literalPriority) && val && Object.hasOwn(val, loc)) {
|
|
10003
|
-
addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr));
|
|
10004
|
-
} else if (loc === "*") {
|
|
10005
|
-
this._walk(val, (m) => {
|
|
10006
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true, true));
|
|
10007
|
-
});
|
|
10008
|
-
} else if (loc === "..") {
|
|
10009
|
-
addRet(this._trace(x, val, path3, parent, parentPropName, callback, hasArrExpr));
|
|
10010
|
-
this._walk(val, (m) => {
|
|
10011
|
-
if (typeof val[m] === "object") {
|
|
10012
|
-
addRet(this._trace(expr.slice(), val[m], push(path3, m), val, m, callback, true));
|
|
10013
|
-
}
|
|
10014
|
-
});
|
|
10015
|
-
} else if (loc === "^") {
|
|
10016
|
-
this._hasParentSelector = true;
|
|
10017
|
-
return {
|
|
10018
|
-
path: path3.slice(0, -1),
|
|
10019
|
-
expr: x,
|
|
10020
|
-
isParentSelector: true
|
|
10021
|
-
};
|
|
10022
|
-
} else if (loc === "~") {
|
|
10023
|
-
retObj = {
|
|
10024
|
-
path: push(path3, loc),
|
|
10025
|
-
value: parentPropName,
|
|
10026
|
-
parent,
|
|
10027
|
-
parentProperty: null
|
|
10028
|
-
};
|
|
10029
|
-
this._handleCallback(retObj, callback, "property");
|
|
10030
|
-
return retObj;
|
|
10031
|
-
} else if (loc === "$") {
|
|
10032
|
-
addRet(this._trace(x, val, path3, null, null, callback, hasArrExpr));
|
|
10033
|
-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
10034
|
-
addRet(this._slice(loc, x, val, path3, parent, parentPropName, callback));
|
|
10035
|
-
} else if (loc.indexOf("?(") === 0) {
|
|
10036
|
-
if (this.currEval === false) {
|
|
10037
|
-
throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
|
|
10038
|
-
}
|
|
10039
|
-
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, "$1");
|
|
10040
|
-
const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
|
|
10041
|
-
if (nested) {
|
|
10042
|
-
this._walk(val, (m) => {
|
|
10043
|
-
const npath = [nested[2]];
|
|
10044
|
-
const nvalue = nested[1] ? val[m][nested[1]] : val[m];
|
|
10045
|
-
const filterResults = this._trace(npath, nvalue, path3, parent, parentPropName, callback, true);
|
|
10046
|
-
if (filterResults.length > 0) {
|
|
10047
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
|
|
10048
|
-
}
|
|
10049
|
-
});
|
|
10050
|
-
} else {
|
|
10051
|
-
this._walk(val, (m) => {
|
|
10052
|
-
if (this._eval(safeLoc, val[m], m, path3, parent, parentPropName)) {
|
|
10053
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
|
|
10054
|
-
}
|
|
10055
|
-
});
|
|
10056
|
-
}
|
|
10057
|
-
} else if (loc[0] === "(") {
|
|
10058
|
-
if (this.currEval === false) {
|
|
10059
|
-
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
10060
|
-
}
|
|
10061
|
-
addRet(this._trace(unshift(this._eval(loc, val, path3.at(-1), path3.slice(0, -1), parent, parentPropName), x), val, path3, parent, parentPropName, callback, hasArrExpr));
|
|
10062
|
-
} else if (loc[0] === "@") {
|
|
10063
|
-
let addType = false;
|
|
10064
|
-
const valueType = loc.slice(1, -2);
|
|
10065
|
-
switch (valueType) {
|
|
10066
|
-
case "scalar":
|
|
10067
|
-
if (!val || !["object", "function"].includes(typeof val)) {
|
|
10068
|
-
addType = true;
|
|
10069
|
-
}
|
|
10070
|
-
break;
|
|
10071
|
-
case "boolean":
|
|
10072
|
-
case "string":
|
|
10073
|
-
case "undefined":
|
|
10074
|
-
case "function":
|
|
10075
|
-
if (typeof val === valueType) {
|
|
10076
|
-
addType = true;
|
|
10077
|
-
}
|
|
10078
|
-
break;
|
|
10079
|
-
case "integer":
|
|
10080
|
-
if (Number.isFinite(val) && !(val % 1)) {
|
|
10081
|
-
addType = true;
|
|
10082
|
-
}
|
|
10083
|
-
break;
|
|
10084
|
-
case "number":
|
|
10085
|
-
if (Number.isFinite(val)) {
|
|
10086
|
-
addType = true;
|
|
10087
|
-
}
|
|
10088
|
-
break;
|
|
10089
|
-
case "nonFinite":
|
|
10090
|
-
if (typeof val === "number" && !Number.isFinite(val)) {
|
|
10091
|
-
addType = true;
|
|
10092
|
-
}
|
|
10093
|
-
break;
|
|
10094
|
-
case "object":
|
|
10095
|
-
if (val && typeof val === valueType) {
|
|
10096
|
-
addType = true;
|
|
10097
|
-
}
|
|
10098
|
-
break;
|
|
10099
|
-
case "array":
|
|
10100
|
-
if (Array.isArray(val)) {
|
|
10101
|
-
addType = true;
|
|
10102
|
-
}
|
|
10103
|
-
break;
|
|
10104
|
-
case "other":
|
|
10105
|
-
addType = this.currOtherTypeCallback(val, path3, parent, parentPropName);
|
|
10106
|
-
break;
|
|
10107
|
-
case "null":
|
|
10108
|
-
if (val === null) {
|
|
10109
|
-
addType = true;
|
|
10110
|
-
}
|
|
10111
|
-
break;
|
|
10112
|
-
default:
|
|
10113
|
-
throw new TypeError("Unknown value type " + valueType);
|
|
10114
|
-
}
|
|
10115
|
-
if (addType) {
|
|
10116
|
-
retObj = {
|
|
10117
|
-
path: path3,
|
|
10118
|
-
value: val,
|
|
10119
|
-
parent,
|
|
10120
|
-
parentProperty: parentPropName
|
|
10121
|
-
};
|
|
10122
|
-
this._handleCallback(retObj, callback, "value");
|
|
10123
|
-
return retObj;
|
|
10124
|
-
}
|
|
10125
|
-
} else if (loc[0] === "`" && val && Object.hasOwn(val, loc.slice(1))) {
|
|
10126
|
-
const locProp = loc.slice(1);
|
|
10127
|
-
addRet(this._trace(x, val[locProp], push(path3, locProp), val, locProp, callback, hasArrExpr, true));
|
|
10128
|
-
} else if (loc.includes(",")) {
|
|
10129
|
-
const parts = loc.split(",");
|
|
10130
|
-
for (const part of parts) {
|
|
10131
|
-
addRet(this._trace(unshift(part, x), val, path3, parent, parentPropName, callback, true));
|
|
10132
|
-
}
|
|
10133
|
-
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
|
|
10134
|
-
addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr, true));
|
|
10135
|
-
}
|
|
10136
|
-
if (this._hasParentSelector) {
|
|
10137
|
-
for (let t = 0;t < ret.length; t++) {
|
|
10138
|
-
const rett = ret[t];
|
|
10139
|
-
if (rett && rett.isParentSelector) {
|
|
10140
|
-
const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
|
|
10141
|
-
if (Array.isArray(tmp)) {
|
|
10142
|
-
ret[t] = tmp[0];
|
|
10143
|
-
const tl = tmp.length;
|
|
10144
|
-
for (let tt = 1;tt < tl; tt++) {
|
|
10145
|
-
t++;
|
|
10146
|
-
ret.splice(t, 0, tmp[tt]);
|
|
10147
|
-
}
|
|
10148
|
-
} else {
|
|
10149
|
-
ret[t] = tmp;
|
|
10150
|
-
}
|
|
10151
|
-
}
|
|
10152
|
-
}
|
|
10153
|
-
}
|
|
10154
|
-
return ret;
|
|
10155
|
-
};
|
|
10156
|
-
JSONPath.prototype._walk = function(val, f) {
|
|
10157
|
-
if (Array.isArray(val)) {
|
|
10158
|
-
const n = val.length;
|
|
10159
|
-
for (let i = 0;i < n; i++) {
|
|
10160
|
-
f(i);
|
|
10161
|
-
}
|
|
10162
|
-
} else if (val && typeof val === "object") {
|
|
10163
|
-
Object.keys(val).forEach((m) => {
|
|
10164
|
-
f(m);
|
|
10165
|
-
});
|
|
10166
|
-
}
|
|
10167
|
-
};
|
|
10168
|
-
JSONPath.prototype._slice = function(loc, expr, val, path3, parent, parentPropName, callback) {
|
|
10169
|
-
if (!Array.isArray(val)) {
|
|
10170
|
-
return;
|
|
10171
|
-
}
|
|
10172
|
-
const len = val.length, parts = loc.split(":"), step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
10173
|
-
let start = parts[0] && Number.parseInt(parts[0]) || 0, end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
10174
|
-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
10175
|
-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
10176
|
-
const ret = [];
|
|
10177
|
-
for (let i = start;i < end; i += step) {
|
|
10178
|
-
const tmp = this._trace(unshift(i, expr), val, path3, parent, parentPropName, callback, true);
|
|
10179
|
-
tmp.forEach((t) => {
|
|
10180
|
-
ret.push(t);
|
|
10181
|
-
});
|
|
10182
|
-
}
|
|
10183
|
-
return ret;
|
|
10184
|
-
};
|
|
10185
|
-
JSONPath.prototype._eval = function(code, _v, _vname, path3, parent, parentPropName) {
|
|
10186
|
-
this.currSandbox._$_parentProperty = parentPropName;
|
|
10187
|
-
this.currSandbox._$_parent = parent;
|
|
10188
|
-
this.currSandbox._$_property = _vname;
|
|
10189
|
-
this.currSandbox._$_root = this.json;
|
|
10190
|
-
this.currSandbox._$_v = _v;
|
|
10191
|
-
const containsPath = code.includes("@path");
|
|
10192
|
-
if (containsPath) {
|
|
10193
|
-
this.currSandbox._$_path = JSONPath.toPathString(path3.concat([_vname]));
|
|
10194
|
-
}
|
|
10195
|
-
const scriptCacheKey = this.currEval + "Script:" + code;
|
|
10196
|
-
if (!JSONPath.cache[scriptCacheKey]) {
|
|
10197
|
-
let script = code.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
10198
|
-
if (containsPath) {
|
|
10199
|
-
script = script.replaceAll("@path", "_$_path");
|
|
10200
|
-
}
|
|
10201
|
-
if (this.currEval === "safe" || this.currEval === true || this.currEval === undefined) {
|
|
10202
|
-
JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);
|
|
10203
|
-
} else if (this.currEval === "native") {
|
|
10204
|
-
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
10205
|
-
} else if (typeof this.currEval === "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
10206
|
-
const CurrEval = this.currEval;
|
|
10207
|
-
JSONPath.cache[scriptCacheKey] = new CurrEval(script);
|
|
10208
|
-
} else if (typeof this.currEval === "function") {
|
|
10209
|
-
JSONPath.cache[scriptCacheKey] = {
|
|
10210
|
-
runInNewContext: (context) => this.currEval(script, context)
|
|
10211
|
-
};
|
|
10212
|
-
} else {
|
|
10213
|
-
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
10214
|
-
}
|
|
10215
|
-
}
|
|
10216
|
-
try {
|
|
10217
|
-
return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
|
|
10218
|
-
} catch (e) {
|
|
10219
|
-
if (this.ignoreEvalErrors) {
|
|
10220
|
-
return false;
|
|
10221
|
-
}
|
|
10222
|
-
throw new Error("jsonPath: " + e.message + ": " + code);
|
|
10223
|
-
}
|
|
10224
|
-
};
|
|
10225
|
-
JSONPath.cache = {};
|
|
10226
|
-
JSONPath.toPathString = function(pathArr) {
|
|
10227
|
-
const x = pathArr, n = x.length;
|
|
10228
|
-
let p = "$";
|
|
10229
|
-
for (let i = 1;i < n; i++) {
|
|
10230
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
10231
|
-
p += /^[0-9*]+$/u.test(x[i]) ? "[" + x[i] + "]" : "['" + x[i] + "']";
|
|
10232
|
-
}
|
|
10233
|
-
}
|
|
10234
|
-
return p;
|
|
10235
|
-
};
|
|
10236
|
-
JSONPath.toPointer = function(pointer) {
|
|
10237
|
-
const x = pointer, n = x.length;
|
|
10238
|
-
let p = "";
|
|
10239
|
-
for (let i = 1;i < n; i++) {
|
|
10240
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
10241
|
-
p += "/" + x[i].toString().replaceAll("~", "~0").replaceAll("/", "~1");
|
|
10242
|
-
}
|
|
10243
|
-
}
|
|
10244
|
-
return p;
|
|
10245
|
-
};
|
|
10246
|
-
JSONPath.toPathArray = function(expr) {
|
|
10247
|
-
const {
|
|
10248
|
-
cache
|
|
10249
|
-
} = JSONPath;
|
|
10250
|
-
if (cache[expr]) {
|
|
10251
|
-
return cache[expr].concat();
|
|
10252
|
-
}
|
|
10253
|
-
const subx = [];
|
|
10254
|
-
const normalized = expr.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function($0, $1) {
|
|
10255
|
-
return "[#" + (subx.push($1) - 1) + "]";
|
|
10256
|
-
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function($0, prop) {
|
|
10257
|
-
return "['" + prop.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
10258
|
-
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function($0, ups) {
|
|
10259
|
-
return ";" + ups.split("").join(";") + ";";
|
|
10260
|
-
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "");
|
|
10261
|
-
const exprList = normalized.split(";").map(function(exp) {
|
|
10262
|
-
const match = exp.match(/#(\d+)/u);
|
|
10263
|
-
return !match || !match[1] ? exp : subx[match[1]];
|
|
10264
|
-
});
|
|
10265
|
-
cache[expr] = exprList;
|
|
10266
|
-
return cache[expr].concat();
|
|
10267
|
-
};
|
|
10268
|
-
JSONPath.prototype.safeVm = {
|
|
10269
|
-
Script: SafeScript
|
|
10270
|
-
};
|
|
10271
|
-
JSONPath.prototype.vm = vm;
|
|
10272
8950
|
// ../common/src/polling/types.ts
|
|
10273
8951
|
var PollOutcome = {
|
|
10274
8952
|
Completed: "completed",
|
|
@@ -10303,6 +8981,17 @@ var FAILURE_STATUSES = new Set([
|
|
|
10303
8981
|
"canceled",
|
|
10304
8982
|
"stopped"
|
|
10305
8983
|
]);
|
|
8984
|
+
// ../common/src/preview.ts
|
|
8985
|
+
var previewSlot = singleton("PreviewBuild");
|
|
8986
|
+
function isPreviewBuild() {
|
|
8987
|
+
return previewSlot.get(false) ?? false;
|
|
8988
|
+
}
|
|
8989
|
+
Command.prototype.previewCommand = function(nameAndArgs, opts) {
|
|
8990
|
+
if (isPreviewBuild()) {
|
|
8991
|
+
return this.command(nameAndArgs, opts);
|
|
8992
|
+
}
|
|
8993
|
+
return new Command(nameAndArgs.split(/\s+/)[0] ?? nameAndArgs);
|
|
8994
|
+
};
|
|
10306
8995
|
// ../common/src/screen-logger.ts
|
|
10307
8996
|
var ScreenLogger;
|
|
10308
8997
|
((ScreenLogger) => {
|
|
@@ -10379,3 +9068,5 @@ export {
|
|
|
10379
9068
|
solutionInitAsync,
|
|
10380
9069
|
SolutionInitError
|
|
10381
9070
|
};
|
|
9071
|
+
|
|
9072
|
+
//# debugId=AE44FF1DFEB3A7F564756E2164756E21
|