@danielx/civet 0.5.26 → 0.5.27

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/civet CHANGED
@@ -20,7 +20,9 @@ if (process.argv.includes("--help")) {
20
20
 
21
21
  Usage:
22
22
 
23
- civet [options] # REPL
23
+ civet # REPL for executing code
24
+ civet -c # REPL for transpiling code
25
+ civet --ast # REPL for parsing code
24
26
  civet [options] -c input.civet # -> input.civet.tsx
25
27
  civet [options] -c input.civet -o .ts # -> input.ts
26
28
  civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
@@ -108,6 +110,9 @@ parseArgs = function(args = process.argv.slice(2)) {
108
110
  endOfArgs(++i);
109
111
  break;
110
112
  default:
113
+ if (arg.startsWith("-")) {
114
+ throw new Error(`Invalid command-line argument ${arg}`);
115
+ }
111
116
  if (options.run) {
112
117
  endOfArgs(i);
113
118
  } else {
@@ -158,14 +163,35 @@ readFiles = async function* (filenames, options) {
158
163
  };
159
164
  repl = function(options) {
160
165
  var nodeRepl, r, vm;
161
- console.log(`Civet ${version()} REPL. Enter a blank line to execute code.`);
166
+ console.log(`Civet ${version()} REPL. Enter a blank line to ${function() {
167
+ switch (false) {
168
+ case !options.ast:
169
+ return "parse";
170
+ case !options.compile:
171
+ return "transpile";
172
+ default:
173
+ return "execute";
174
+ }
175
+ }()} code.`);
162
176
  global.quit = global.exit = function() {
163
177
  return process.exit(0);
164
178
  };
165
179
  nodeRepl = require("repl");
166
180
  vm = require("vm");
167
181
  return r = nodeRepl.start({
168
- prompt: "\u{1F431}> ",
182
+ prompt: function() {
183
+ switch (false) {
184
+ case !options.ast:
185
+ return "\u{1F332}> ";
186
+ case !options.compile:
187
+ return "\u{1F408}> ";
188
+ default:
189
+ return "\u{1F431}> ";
190
+ }
191
+ }(),
192
+ writer: options.compile && !options.ast ? function(obj) {
193
+ return obj != null ? obj.replace(/\n*$/, "") : void 0;
194
+ } : void 0,
169
195
  eval: function(input, context, filename, callback) {
170
196
  var error, output, result;
171
197
  if (input === "\n") {
@@ -179,13 +205,17 @@ repl = function(options) {
179
205
  error = error1;
180
206
  return callback(error);
181
207
  }
182
- try {
183
- result = vm.runInContext(output, context, { filename });
184
- } catch (error1) {
185
- error = error1;
186
- return callback(error);
208
+ if (options.compile || options.ast) {
209
+ return callback(null, output);
210
+ } else {
211
+ try {
212
+ result = vm.runInContext(output, context, { filename });
213
+ } catch (error1) {
214
+ error = error1;
215
+ return callback(error);
216
+ }
217
+ return callback(null, result);
187
218
  }
188
- return callback(null, result);
189
219
  } else {
190
220
  return callback(new nodeRepl.Recoverable("Enter a blank line to execute code."));
191
221
  }
@@ -196,10 +226,10 @@ cli = async function() {
196
226
  var content, error, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
197
227
  ({ filenames, scriptArgs, options } = parseArgs());
198
228
  if (!filenames.length) {
199
- options.compile = true;
200
229
  if (process.stdin.isTTY) {
201
230
  options.repl = true;
202
231
  } else {
232
+ options.compile = true;
203
233
  filenames = ["-"];
204
234
  }
205
235
  }