@danielx/civet 0.7.9 → 0.7.10
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/dist/browser.js +457 -372
- package/dist/civet +35 -11
- package/dist/esm.mjs +1 -2
- package/dist/main.js +460 -373
- package/dist/main.mjs +458 -372
- package/dist/types.d.ts +11 -4
- package/package.json +4 -4
package/dist/civet
CHANGED
|
@@ -46,11 +46,11 @@ var unplugin;
|
|
|
46
46
|
function version() {
|
|
47
47
|
return require("../package.json").version;
|
|
48
48
|
}
|
|
49
|
-
if (process.argv.
|
|
49
|
+
if (process.argv.some((a) => a === "--version" || a === "-version" || a === "-v")) {
|
|
50
50
|
console.log(version());
|
|
51
51
|
process.exit(0);
|
|
52
52
|
}
|
|
53
|
-
if (process.argv.
|
|
53
|
+
if (process.argv.some((a1) => a1 === "--help" || a1 === "-help" || a1 === "-h")) {
|
|
54
54
|
process.stderr.write(` \u2584\u2584\xB7 \u25AA \u258C \u2590\xB7\u2584\u2584\u2584 .\u2584\u2584\u2584\u2584\u2584
|
|
55
55
|
\u2590\u2588 \u258C\u25AA\u2588\u2588 \u25AA\u2588\xB7\u2588\u258C\u2580\u2584.\u2580\xB7\u2022\u2588\u2588 _._ _,-'""\`-._
|
|
56
56
|
\u2588\u2588 \u2584\u2584\u2590\u2588\xB7\u2590\u2588\u2590\u2588\u2022\u2590\u2580\u2580\u25AA\u2584 \u2590\u2588.\u25AA (,-.\`._,'( |\\\`-/|
|
|
@@ -106,6 +106,7 @@ function parseArgs(args) {
|
|
|
106
106
|
const filenames = [];
|
|
107
107
|
let scriptArgs = [];
|
|
108
108
|
let i = 0;
|
|
109
|
+
let errors = 0;
|
|
109
110
|
function endOfArgs(j) {
|
|
110
111
|
i = args.length;
|
|
111
112
|
if (j >= args.length) {
|
|
@@ -199,9 +200,9 @@ function parseArgs(args) {
|
|
|
199
200
|
}
|
|
200
201
|
default: {
|
|
201
202
|
if (arg.startsWith("-") && arg !== "-") {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (options.run) {
|
|
203
|
+
console.error(`Invalid command-line argument: ${arg}`);
|
|
204
|
+
errors++;
|
|
205
|
+
} else if (options.run) {
|
|
205
206
|
endOfArgs(i);
|
|
206
207
|
} else {
|
|
207
208
|
filenames.push(arg);
|
|
@@ -210,6 +211,9 @@ function parseArgs(args) {
|
|
|
210
211
|
}
|
|
211
212
|
i++;
|
|
212
213
|
}
|
|
214
|
+
if (errors) {
|
|
215
|
+
process.exit(Math.min(255, errors));
|
|
216
|
+
}
|
|
213
217
|
return { filenames, scriptArgs, options };
|
|
214
218
|
}
|
|
215
219
|
async function* readFiles(filenames) {
|
|
@@ -273,7 +277,6 @@ async function repl(options) {
|
|
|
273
277
|
};
|
|
274
278
|
} else {
|
|
275
279
|
const execArgv = ["--experimental-vm-modules"];
|
|
276
|
-
const { register } = await import("node:module");
|
|
277
280
|
if (process.env.NODE_OPTIONS) {
|
|
278
281
|
execArgv.push(process.env.NODE_OPTIONS);
|
|
279
282
|
}
|
|
@@ -343,17 +346,36 @@ async function repl(options) {
|
|
|
343
346
|
} else if (input in ["quit\n", "exit\n", "quit()\n", "exit()\n"]) {
|
|
344
347
|
return process.exit(0);
|
|
345
348
|
} else if (input.endsWith("\n\n")) {
|
|
349
|
+
let showError2 = function(error) {
|
|
350
|
+
console.error("Error while parsing Civet code:");
|
|
351
|
+
if ((0, import_main.isCompileError)(error)) {
|
|
352
|
+
if (error.errors != null) {
|
|
353
|
+
error = error.errors[0];
|
|
354
|
+
}
|
|
355
|
+
return console.log(`${input.split("\n").slice(0, error.line).join("\n")}
|
|
356
|
+
${" ".repeat(error.column - 1)}^ ${error.header}`);
|
|
357
|
+
} else {
|
|
358
|
+
return console.error(error);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var showError = showError2;
|
|
346
362
|
let output;
|
|
347
363
|
if (options.compile || options.ast) {
|
|
348
364
|
try {
|
|
349
365
|
output = await (0, import_main.compile)(input, { ...options, filename });
|
|
350
366
|
} catch (error) {
|
|
351
|
-
|
|
367
|
+
showError2(error);
|
|
352
368
|
return callback(null, void 0);
|
|
353
369
|
}
|
|
354
370
|
return callback(null, output);
|
|
355
371
|
}
|
|
356
|
-
let ast
|
|
372
|
+
let ast;
|
|
373
|
+
try {
|
|
374
|
+
ast = await (0, import_main.compile)(input, { ...options, filename, ast: true });
|
|
375
|
+
} catch (error) {
|
|
376
|
+
showError2(error);
|
|
377
|
+
return callback(null, void 0);
|
|
378
|
+
}
|
|
357
379
|
const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
|
|
358
380
|
if (topLevelAwait) {
|
|
359
381
|
const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
|
|
@@ -373,7 +395,7 @@ async function repl(options) {
|
|
|
373
395
|
});
|
|
374
396
|
});
|
|
375
397
|
}
|
|
376
|
-
|
|
398
|
+
let errors = [];
|
|
377
399
|
try {
|
|
378
400
|
output = (0, import_main.generate)(ast, { errors });
|
|
379
401
|
} catch (error) {
|
|
@@ -381,7 +403,9 @@ async function repl(options) {
|
|
|
381
403
|
return callback(null, void 0);
|
|
382
404
|
}
|
|
383
405
|
if (errors.length) {
|
|
384
|
-
|
|
406
|
+
errors = [];
|
|
407
|
+
(0, import_main.generate)(ast, { errors, sourceMap: (0, import_main.SourceMap)(input) });
|
|
408
|
+
showError2(errors[0]);
|
|
385
409
|
return callback(null, void 0);
|
|
386
410
|
}
|
|
387
411
|
let result;
|
|
@@ -531,7 +555,7 @@ async function cli() {
|
|
|
531
555
|
targetPath = outputPath;
|
|
532
556
|
}
|
|
533
557
|
if (targetPath.dir) {
|
|
534
|
-
import_promises.default.mkdir(targetPath.dir, { recursive: true });
|
|
558
|
+
await import_promises.default.mkdir(targetPath.dir, { recursive: true });
|
|
535
559
|
}
|
|
536
560
|
const targetFilename = import_path.default.format(targetPath);
|
|
537
561
|
try {
|
package/dist/esm.mjs
CHANGED
|
@@ -3,8 +3,7 @@ import { readFileSync } from "fs";
|
|
|
3
3
|
import { pathToFileURL, fileURLToPath } from "url";
|
|
4
4
|
import sourceMapSupport from "@cspotcode/source-map-support";
|
|
5
5
|
import Civet from "./main.js";
|
|
6
|
-
var { compile,
|
|
7
|
-
var { SourceMap } = util;
|
|
6
|
+
var { compile, SourceMap } = Civet;
|
|
8
7
|
var baseURL = pathToFileURL(process.cwd() + "/").href;
|
|
9
8
|
var extensionsRegex = /\.civet$/;
|
|
10
9
|
var registered = false;
|