brsh 2.4.0 → 2.4.1
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/CHANGELOG.md +7 -0
- package/POSIX-CHECKLIST.md +5 -5
- package/dist/shell.es.js +72 -23
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +2 -2
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.es.js +72 -23
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +2 -2
- package/dist/terminal.min.js.map +1 -1
- package/index.js +5 -1
- package/lib/Command.js +6 -0
- package/lib/ScriptCommand.js +71 -43
- package/package.json +1 -1
- package/test/scripts.test.js +91 -0
package/dist/terminal.es.js
CHANGED
|
@@ -916,7 +916,10 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
916
916
|
return Promise.reject("Command not implemented...");
|
|
917
917
|
}
|
|
918
918
|
runCommand() {
|
|
919
|
-
return this.run().then((e) => (e && e.split(/\r?\n/).forEach((e) => this.stdOut = e), this.result)).catch((e) =>
|
|
919
|
+
return this.run().then((e) => (e && e.split(/\r?\n/).forEach((e) => this.stdOut = e), this.result)).catch((e) => {
|
|
920
|
+
if (e && e.__type) throw e;
|
|
921
|
+
return e && (this.stdErr = e.message || e), this.exitCode = 127, this.result;
|
|
922
|
+
});
|
|
920
923
|
}
|
|
921
924
|
onInput(e) {}
|
|
922
925
|
set exitCode(e) {
|
|
@@ -977,6 +980,7 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
977
980
|
return this._executeNodes(n).catch((e) => {
|
|
978
981
|
if (e && e.__type === "return") this.sandbox.lastCode = e.code;
|
|
979
982
|
else if (e && e.__type === "errexit") this.sandbox.lastCode = e.code;
|
|
983
|
+
else if (e && (e.__type === "break" || e.__type === "continue")) this.stdErr = `${e.__type}: only meaningful in a for or while loop`, this.sandbox.lastCode = 1;
|
|
980
984
|
else return Promise.reject(e);
|
|
981
985
|
}).then(() => {
|
|
982
986
|
this.exitCode = this.sandbox.lastCode, this.source && this.context.source(this.sandbox.context);
|
|
@@ -1099,8 +1103,8 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
1099
1103
|
consumed: a - t
|
|
1100
1104
|
};
|
|
1101
1105
|
}
|
|
1102
|
-
_executeNodes(e) {
|
|
1103
|
-
|
|
1106
|
+
async _executeNodes(e) {
|
|
1107
|
+
for (let t of e) await this._executeNode(t);
|
|
1104
1108
|
}
|
|
1105
1109
|
_executeNode(e) {
|
|
1106
1110
|
if (e.type === "function") {
|
|
@@ -1136,6 +1140,20 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
1136
1140
|
code: n
|
|
1137
1141
|
});
|
|
1138
1142
|
}
|
|
1143
|
+
if (/^break(\s+\d+)?\s*$/.test(e.line.trim())) {
|
|
1144
|
+
let t = e.line.trim().match(/^break\s+(\d+)/), n = t ? parseInt(t[1], 10) : 1;
|
|
1145
|
+
return Promise.reject({
|
|
1146
|
+
__type: "break",
|
|
1147
|
+
count: n
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
if (/^continue(\s+\d+)?\s*$/.test(e.line.trim())) {
|
|
1151
|
+
let t = e.line.trim().match(/^continue\s+(\d+)/), n = t ? parseInt(t[1], 10) : 1;
|
|
1152
|
+
return Promise.reject({
|
|
1153
|
+
__type: "continue",
|
|
1154
|
+
count: n
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1139
1157
|
return (this.sandbox.context.getVar("-") || "").includes("x") && (this.stdErr = `+ ${e.line.trim()}`, this.flush()), this.sandbox.onCommand(e.line, !1).then(() => {
|
|
1140
1158
|
if ((this.sandbox.context.getVar("-") || "").includes("e") && this.sandbox.lastCode !== 0) return Promise.reject({
|
|
1141
1159
|
__type: "errexit",
|
|
@@ -1145,22 +1163,55 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
1145
1163
|
}
|
|
1146
1164
|
return e.type === "if" ? this._executeIf(e) : e.type === "while" ? this._executeWhile(e) : e.type === "for" ? this._executeFor(e) : e.type === "case" ? this._executeCase(e) : Promise.resolve();
|
|
1147
1165
|
}
|
|
1148
|
-
_executeIf(e) {
|
|
1149
|
-
let t
|
|
1150
|
-
|
|
1151
|
-
let r = e.clauses[n];
|
|
1152
|
-
return this.sandbox.onCommand(r.condition, !1).then(() => this.sandbox.lastCode === 0 ? this._executeNodes(this._parseLines(r.bodyLines)) : t(n + 1));
|
|
1153
|
-
};
|
|
1154
|
-
return t(0);
|
|
1166
|
+
async _executeIf(e) {
|
|
1167
|
+
for (let t of e.clauses) if (await this.sandbox.onCommand(t.condition, !1), this.sandbox.lastCode === 0) return this._executeNodes(this._parseLines(t.bodyLines));
|
|
1168
|
+
if (e.elseLines.length > 0) return this._executeNodes(this._parseLines(e.elseLines));
|
|
1155
1169
|
}
|
|
1156
|
-
_executeWhile(e) {
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
})
|
|
1160
|
-
|
|
1170
|
+
async _executeWhile(e) {
|
|
1171
|
+
for (; await this.sandbox.onCommand(e.condition, !1), this.sandbox.lastCode === 0;) try {
|
|
1172
|
+
await this._executeNodes(this._parseLines(e.bodyLines));
|
|
1173
|
+
} catch (e) {
|
|
1174
|
+
if (e && e.__type === "break") {
|
|
1175
|
+
if (e.count <= 1) break;
|
|
1176
|
+
throw {
|
|
1177
|
+
__type: "break",
|
|
1178
|
+
count: e.count - 1
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
if (e && e.__type === "continue") {
|
|
1182
|
+
if (e.count <= 1) continue;
|
|
1183
|
+
throw {
|
|
1184
|
+
__type: "continue",
|
|
1185
|
+
count: e.count - 1
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
throw e;
|
|
1189
|
+
}
|
|
1161
1190
|
}
|
|
1162
|
-
_executeFor(e) {
|
|
1163
|
-
|
|
1191
|
+
async _executeFor(e) {
|
|
1192
|
+
let t = e.list.replace(/\${?([\w\d]+)}?/g, (e, t) => this.sandbox.context.getVar(t) || "").split(/\s+/).filter(Boolean);
|
|
1193
|
+
for (let n of t) {
|
|
1194
|
+
this.sandbox.context.setVar(e.variable, n);
|
|
1195
|
+
try {
|
|
1196
|
+
await this._executeNodes(this._parseLines(e.bodyLines));
|
|
1197
|
+
} catch (e) {
|
|
1198
|
+
if (e && e.__type === "break") {
|
|
1199
|
+
if (e.count <= 1) break;
|
|
1200
|
+
throw {
|
|
1201
|
+
__type: "break",
|
|
1202
|
+
count: e.count - 1
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
if (e && e.__type === "continue") {
|
|
1206
|
+
if (e.count <= 1) continue;
|
|
1207
|
+
throw {
|
|
1208
|
+
__type: "continue",
|
|
1209
|
+
count: e.count - 1
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
throw e;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1164
1215
|
}
|
|
1165
1216
|
_parseFunction(e, t) {
|
|
1166
1217
|
let n = e[t].trim(), r = n.match(/^function\s+([\w\d_]+)/) || n.match(/^([\w\d_]+)\s*\(/), i = r ? r[1] : "", a = t + 1;
|
|
@@ -1237,11 +1288,9 @@ var g, _, v, y, b, x, S, C, w, T, E = e((() => {
|
|
|
1237
1288
|
_executeFunctionBody(e) {
|
|
1238
1289
|
return this._executeNodes(this._parseLines(e));
|
|
1239
1290
|
}
|
|
1240
|
-
_executeCase(e) {
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
for (let t of e.clauses) if (this._matchPattern(t.pattern, n)) return this._executeNodes(this._parseLines(t.bodyLines));
|
|
1244
|
-
});
|
|
1291
|
+
async _executeCase(e) {
|
|
1292
|
+
let t = await this.sandbox._replaceVariables(e.word), n = t.startsWith("\"") && t.endsWith("\"") || t.startsWith("'") && t.endsWith("'") ? t.slice(1, -1) : t;
|
|
1293
|
+
for (let t of e.clauses) if (this._matchPattern(t.pattern, n)) return this._executeNodes(this._parseLines(t.bodyLines));
|
|
1245
1294
|
}
|
|
1246
1295
|
_matchPattern(e, t) {
|
|
1247
1296
|
let n = "", r = 0;
|
|
@@ -6170,7 +6219,7 @@ var V, re, H, U, W, ie, G, ae, oe, se, K = e((() => {
|
|
|
6170
6219
|
}
|
|
6171
6220
|
_evalArithmetic(e) {
|
|
6172
6221
|
let t = e.replace(/\${?([\w\d]+)}?/g, (e, t) => String(parseInt(this.context.getVar(t)) || 0));
|
|
6173
|
-
if (!/^[\d\s+\-*/%()]+$/.test(t.trim())) return 0;
|
|
6222
|
+
if (t = t.replace(/\b([A-Za-z_]\w*)\b/g, (e, t) => String(parseInt(this.context.getVar(t)) || 0)), !/^[\d\s+\-*/%()]+$/.test(t.trim())) return 0;
|
|
6174
6223
|
try {
|
|
6175
6224
|
return Function("return (" + t + ")")();
|
|
6176
6225
|
} catch {
|