@danielx/civet 0.6.88 → 0.6.89

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 CHANGED
@@ -235,6 +235,9 @@ var Civet = (() => {
235
235
  function hasYield(exp) {
236
236
  return gatherRecursiveWithinFunction(exp, ({ type }) => type === "Yield").length > 0;
237
237
  }
238
+ function hasImportDeclaration(exp) {
239
+ return gatherRecursiveWithinFunction(exp, ({ type }) => type === "ImportDeclaration").length > 0;
240
+ }
238
241
  function deepCopy(node) {
239
242
  if (node == null)
240
243
  return node;
@@ -396,9 +399,10 @@ var Civet = (() => {
396
399
  }
397
400
  return ["(", type, ")"];
398
401
  }
399
- function wrapIIFE(expressions, async) {
402
+ function wrapIIFE(expressions, asyncFlag) {
400
403
  let prefix;
401
- if (async) {
404
+ let async;
405
+ if (asyncFlag) {
402
406
  async = "async ";
403
407
  } else if (hasAwait(expressions)) {
404
408
  async = "async ";
@@ -586,16 +590,16 @@ var Civet = (() => {
586
590
  expressions,
587
591
  children: block.children === block.expressions ? expressions : block.children.map((c) => c === block.expressions ? expressions : c)
588
592
  };
589
- if (block.bare) {
590
- block.children = [[" {"], ...block.children, "}"];
591
- block.bare = false;
592
- }
593
+ braceBlock(block);
593
594
  updateParentPointers(block);
594
595
  }
595
596
  return block;
596
597
  }
597
598
  function braceBlock(block) {
598
599
  if (block.bare) {
600
+ if (block.children === block.expressions) {
601
+ block.children = [block.expressions];
602
+ }
599
603
  block.children.unshift(" {");
600
604
  block.children.push("}");
601
605
  return block.bare = false;
@@ -605,8 +609,13 @@ var Civet = (() => {
605
609
  }
606
610
  function duplicateBlock(block) {
607
611
  const expressions = [...block.expressions];
608
- const children = [...block.children];
609
- children.splice(children.indexOf(block.expressions), 1, expressions);
612
+ let children;
613
+ if (block.children === block.expressions) {
614
+ children = expressions;
615
+ } else {
616
+ children = [...block.children];
617
+ children.splice(children.indexOf(block.expressions), 1, expressions);
618
+ }
610
619
  return {
611
620
  ...block,
612
621
  expressions,
@@ -2023,8 +2032,7 @@ var Civet = (() => {
2023
2032
  throw new Error("Could not find iteration statement in iteration expression");
2024
2033
  }
2025
2034
  if (subtype === "DoStatement") {
2026
- insertReturn(block);
2027
- children.splice(i, 1, ...wrapIIFE(["", statement, void 0], async));
2035
+ children.splice(i, 1, ...wrapIIFE([["", statement, void 0]], async));
2028
2036
  updateParentPointers(exp);
2029
2037
  return;
2030
2038
  }
@@ -3266,13 +3274,17 @@ var Civet = (() => {
3266
3274
  forRange: () => forRange,
3267
3275
  gatherBindingCode: () => gatherBindingCode,
3268
3276
  gatherRecursive: () => gatherRecursive,
3277
+ gatherRecursiveAll: () => gatherRecursiveAll,
3278
+ gatherRecursiveWithinFunction: () => gatherRecursiveWithinFunction,
3269
3279
  getIndentLevel: () => getIndentLevel,
3270
3280
  getPrecedence: () => getPrecedence,
3271
3281
  getTrimmingSpace: () => getTrimmingSpace,
3272
3282
  hasAwait: () => hasAwait,
3283
+ hasImportDeclaration: () => hasImportDeclaration,
3273
3284
  hasYield: () => hasYield,
3274
3285
  insertTrimmingSpace: () => insertTrimmingSpace,
3275
3286
  isEmptyBareBlock: () => isEmptyBareBlock,
3287
+ isFunction: () => isFunction,
3276
3288
  isWhitespaceOrEmpty: () => isWhitespaceOrEmpty,
3277
3289
  lastAccessInCallExpression: () => lastAccessInCallExpression,
3278
3290
  literalValue: () => literalValue,
@@ -8817,11 +8829,14 @@ ${input.slice(result.pos)}
8817
8829
  });
8818
8830
  var NonSingleBracedBlock$1 = ImplicitNestedBlock;
8819
8831
  var NonSingleBracedBlock$2 = $TS($S(InsertOpenBrace, NestedImplicitObjectLiteral, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3) {
8832
+ var o = $1;
8820
8833
  var s = $2;
8834
+ var c = $3;
8835
+ const expressions = [s];
8821
8836
  return {
8822
8837
  type: "BlockStatement",
8823
- expressions: [s],
8824
- children: $0
8838
+ expressions,
8839
+ children: [o, expressions, c]
8825
8840
  };
8826
8841
  });
8827
8842
  var NonSingleBracedBlock$$ = [NonSingleBracedBlock$0, NonSingleBracedBlock$1, NonSingleBracedBlock$2];
@@ -16620,10 +16635,13 @@ ${input.slice(result.pos)}
16620
16635
  let ast;
16621
16636
  try {
16622
16637
  import_parser.parse.config = options.parseOptions || {};
16623
- ast = prune((0, import_parser.parse)(src, {
16638
+ ast = (0, import_parser.parse)(src, {
16624
16639
  filename,
16625
16640
  events
16626
- }));
16641
+ });
16642
+ if (!(options.ast === "raw")) {
16643
+ ast = prune(ast);
16644
+ }
16627
16645
  } finally {
16628
16646
  if (hits || trace) {
16629
16647
  import("fs").then(function({ writeFileSync }) {
package/dist/civet CHANGED
@@ -344,11 +344,7 @@ async function repl(options) {
344
344
  return callback(null, output);
345
345
  }
346
346
  let ast = (0, import_main.compile)(input, { ...options, filename, ast: true });
347
- const topLevelAwait = import_main.lib.gatherRecursive(
348
- ast,
349
- ($) => $.type === "Await",
350
- import_main.lib.isFunction
351
- ).length > 0;
347
+ const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
352
348
  if (topLevelAwait) {
353
349
  const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
354
350
  const prefix = input.slice(0, -rest.length);
@@ -357,6 +353,15 @@ async function repl(options) {
357
353
  prefix + (coffee ? "(do ->\n" : "async do\n") + rest.replace(/^/gm, " ") + (coffee ? ")" : ""),
358
354
  { ...options, filename, ast: true }
359
355
  );
356
+ import_main.lib.gatherRecursive(ast, ($) => $.type === "BlockStatement").forEach((topBlock) => {
357
+ return import_main.lib.gatherRecursiveWithinFunction(topBlock, ($1) => $1.type === "Declaration").forEach((decl) => {
358
+ const type = decl.children.shift();
359
+ if (!Array.isArray(ast)) {
360
+ ast = [ast];
361
+ }
362
+ return ast.unshift(`var ${decl.names.join(",")};`);
363
+ });
364
+ });
360
365
  }
361
366
  const errors = [];
362
367
  try {
@@ -366,7 +371,7 @@ async function repl(options) {
366
371
  return callback(null, void 0);
367
372
  }
368
373
  if (errors.length) {
369
- console.error(`Parse errors: ${errors.map(($1) => $1.message).join("\n")}`);
374
+ console.error(`Parse errors: ${errors.map(($2) => $2.message).join("\n")}`);
370
375
  return callback(null, void 0);
371
376
  }
372
377
  let result;
@@ -379,12 +384,18 @@ async function repl(options) {
379
384
  return callback(error, void 0);
380
385
  }
381
386
  if (topLevelAwait) {
387
+ let threw = false;
382
388
  try {
383
389
  result = await result;
384
390
  } catch (error) {
391
+ threw = true;
385
392
  callback(error, void 0);
386
393
  }
387
- return callback(null, result);
394
+ if (!threw) {
395
+ return callback(null, result);
396
+ }
397
+ ;
398
+ return;
388
399
  } else {
389
400
  return callback(null, result);
390
401
  }
package/dist/main.js CHANGED
@@ -227,6 +227,9 @@ function hasAwait(exp) {
227
227
  function hasYield(exp) {
228
228
  return gatherRecursiveWithinFunction(exp, ({ type }) => type === "Yield").length > 0;
229
229
  }
230
+ function hasImportDeclaration(exp) {
231
+ return gatherRecursiveWithinFunction(exp, ({ type }) => type === "ImportDeclaration").length > 0;
232
+ }
230
233
  function deepCopy(node) {
231
234
  if (node == null)
232
235
  return node;
@@ -388,9 +391,10 @@ function parenthesizeType(type) {
388
391
  }
389
392
  return ["(", type, ")"];
390
393
  }
391
- function wrapIIFE(expressions, async) {
394
+ function wrapIIFE(expressions, asyncFlag) {
392
395
  let prefix;
393
- if (async) {
396
+ let async;
397
+ if (asyncFlag) {
394
398
  async = "async ";
395
399
  } else if (hasAwait(expressions)) {
396
400
  async = "async ";
@@ -578,16 +582,16 @@ function blockWithPrefix(prefixStatements, block) {
578
582
  expressions,
579
583
  children: block.children === block.expressions ? expressions : block.children.map((c) => c === block.expressions ? expressions : c)
580
584
  };
581
- if (block.bare) {
582
- block.children = [[" {"], ...block.children, "}"];
583
- block.bare = false;
584
- }
585
+ braceBlock(block);
585
586
  updateParentPointers(block);
586
587
  }
587
588
  return block;
588
589
  }
589
590
  function braceBlock(block) {
590
591
  if (block.bare) {
592
+ if (block.children === block.expressions) {
593
+ block.children = [block.expressions];
594
+ }
591
595
  block.children.unshift(" {");
592
596
  block.children.push("}");
593
597
  return block.bare = false;
@@ -597,8 +601,13 @@ function braceBlock(block) {
597
601
  }
598
602
  function duplicateBlock(block) {
599
603
  const expressions = [...block.expressions];
600
- const children = [...block.children];
601
- children.splice(children.indexOf(block.expressions), 1, expressions);
604
+ let children;
605
+ if (block.children === block.expressions) {
606
+ children = expressions;
607
+ } else {
608
+ children = [...block.children];
609
+ children.splice(children.indexOf(block.expressions), 1, expressions);
610
+ }
602
611
  return {
603
612
  ...block,
604
613
  expressions,
@@ -2015,8 +2024,7 @@ function expressionizeIteration(exp) {
2015
2024
  throw new Error("Could not find iteration statement in iteration expression");
2016
2025
  }
2017
2026
  if (subtype === "DoStatement") {
2018
- insertReturn(block);
2019
- children.splice(i, 1, ...wrapIIFE(["", statement, void 0], async));
2027
+ children.splice(i, 1, ...wrapIIFE([["", statement, void 0]], async));
2020
2028
  updateParentPointers(exp);
2021
2029
  return;
2022
2030
  }
@@ -3258,13 +3266,17 @@ __export(lib_exports, {
3258
3266
  forRange: () => forRange,
3259
3267
  gatherBindingCode: () => gatherBindingCode,
3260
3268
  gatherRecursive: () => gatherRecursive,
3269
+ gatherRecursiveAll: () => gatherRecursiveAll,
3270
+ gatherRecursiveWithinFunction: () => gatherRecursiveWithinFunction,
3261
3271
  getIndentLevel: () => getIndentLevel,
3262
3272
  getPrecedence: () => getPrecedence,
3263
3273
  getTrimmingSpace: () => getTrimmingSpace,
3264
3274
  hasAwait: () => hasAwait,
3275
+ hasImportDeclaration: () => hasImportDeclaration,
3265
3276
  hasYield: () => hasYield,
3266
3277
  insertTrimmingSpace: () => insertTrimmingSpace,
3267
3278
  isEmptyBareBlock: () => isEmptyBareBlock,
3279
+ isFunction: () => isFunction,
3268
3280
  isWhitespaceOrEmpty: () => isWhitespaceOrEmpty,
3269
3281
  lastAccessInCallExpression: () => lastAccessInCallExpression,
3270
3282
  literalValue: () => literalValue,
@@ -8809,11 +8821,14 @@ var require_parser = __commonJS({
8809
8821
  });
8810
8822
  var NonSingleBracedBlock$1 = ImplicitNestedBlock;
8811
8823
  var NonSingleBracedBlock$2 = $TS($S(InsertOpenBrace, NestedImplicitObjectLiteral, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3) {
8824
+ var o = $1;
8812
8825
  var s = $2;
8826
+ var c = $3;
8827
+ const expressions = [s];
8813
8828
  return {
8814
8829
  type: "BlockStatement",
8815
- expressions: [s],
8816
- children: $0
8830
+ expressions,
8831
+ children: [o, expressions, c]
8817
8832
  };
8818
8833
  });
8819
8834
  var NonSingleBracedBlock$$ = [NonSingleBracedBlock$0, NonSingleBracedBlock$1, NonSingleBracedBlock$2];
@@ -16613,10 +16628,13 @@ function compile(src, options) {
16613
16628
  let ast;
16614
16629
  try {
16615
16630
  import_parser.parse.config = options.parseOptions || {};
16616
- ast = prune((0, import_parser.parse)(src, {
16631
+ ast = (0, import_parser.parse)(src, {
16617
16632
  filename,
16618
16633
  events
16619
- }));
16634
+ });
16635
+ if (!(options.ast === "raw")) {
16636
+ ast = prune(ast);
16637
+ }
16620
16638
  } finally {
16621
16639
  if (hits || trace) {
16622
16640
  import("fs").then(function({ writeFileSync }) {
package/dist/main.mjs CHANGED
@@ -225,6 +225,9 @@ function hasAwait(exp) {
225
225
  function hasYield(exp) {
226
226
  return gatherRecursiveWithinFunction(exp, ({ type }) => type === "Yield").length > 0;
227
227
  }
228
+ function hasImportDeclaration(exp) {
229
+ return gatherRecursiveWithinFunction(exp, ({ type }) => type === "ImportDeclaration").length > 0;
230
+ }
228
231
  function deepCopy(node) {
229
232
  if (node == null)
230
233
  return node;
@@ -386,9 +389,10 @@ function parenthesizeType(type) {
386
389
  }
387
390
  return ["(", type, ")"];
388
391
  }
389
- function wrapIIFE(expressions, async) {
392
+ function wrapIIFE(expressions, asyncFlag) {
390
393
  let prefix;
391
- if (async) {
394
+ let async;
395
+ if (asyncFlag) {
392
396
  async = "async ";
393
397
  } else if (hasAwait(expressions)) {
394
398
  async = "async ";
@@ -576,16 +580,16 @@ function blockWithPrefix(prefixStatements, block) {
576
580
  expressions,
577
581
  children: block.children === block.expressions ? expressions : block.children.map((c) => c === block.expressions ? expressions : c)
578
582
  };
579
- if (block.bare) {
580
- block.children = [[" {"], ...block.children, "}"];
581
- block.bare = false;
582
- }
583
+ braceBlock(block);
583
584
  updateParentPointers(block);
584
585
  }
585
586
  return block;
586
587
  }
587
588
  function braceBlock(block) {
588
589
  if (block.bare) {
590
+ if (block.children === block.expressions) {
591
+ block.children = [block.expressions];
592
+ }
589
593
  block.children.unshift(" {");
590
594
  block.children.push("}");
591
595
  return block.bare = false;
@@ -595,8 +599,13 @@ function braceBlock(block) {
595
599
  }
596
600
  function duplicateBlock(block) {
597
601
  const expressions = [...block.expressions];
598
- const children = [...block.children];
599
- children.splice(children.indexOf(block.expressions), 1, expressions);
602
+ let children;
603
+ if (block.children === block.expressions) {
604
+ children = expressions;
605
+ } else {
606
+ children = [...block.children];
607
+ children.splice(children.indexOf(block.expressions), 1, expressions);
608
+ }
600
609
  return {
601
610
  ...block,
602
611
  expressions,
@@ -2013,8 +2022,7 @@ function expressionizeIteration(exp) {
2013
2022
  throw new Error("Could not find iteration statement in iteration expression");
2014
2023
  }
2015
2024
  if (subtype === "DoStatement") {
2016
- insertReturn(block);
2017
- children.splice(i, 1, ...wrapIIFE(["", statement, void 0], async));
2025
+ children.splice(i, 1, ...wrapIIFE([["", statement, void 0]], async));
2018
2026
  updateParentPointers(exp);
2019
2027
  return;
2020
2028
  }
@@ -3256,13 +3264,17 @@ __export(lib_exports, {
3256
3264
  forRange: () => forRange,
3257
3265
  gatherBindingCode: () => gatherBindingCode,
3258
3266
  gatherRecursive: () => gatherRecursive,
3267
+ gatherRecursiveAll: () => gatherRecursiveAll,
3268
+ gatherRecursiveWithinFunction: () => gatherRecursiveWithinFunction,
3259
3269
  getIndentLevel: () => getIndentLevel,
3260
3270
  getPrecedence: () => getPrecedence,
3261
3271
  getTrimmingSpace: () => getTrimmingSpace,
3262
3272
  hasAwait: () => hasAwait,
3273
+ hasImportDeclaration: () => hasImportDeclaration,
3263
3274
  hasYield: () => hasYield,
3264
3275
  insertTrimmingSpace: () => insertTrimmingSpace,
3265
3276
  isEmptyBareBlock: () => isEmptyBareBlock,
3277
+ isFunction: () => isFunction,
3266
3278
  isWhitespaceOrEmpty: () => isWhitespaceOrEmpty,
3267
3279
  lastAccessInCallExpression: () => lastAccessInCallExpression,
3268
3280
  literalValue: () => literalValue,
@@ -8807,11 +8819,14 @@ var require_parser = __commonJS({
8807
8819
  });
8808
8820
  var NonSingleBracedBlock$1 = ImplicitNestedBlock;
8809
8821
  var NonSingleBracedBlock$2 = $TS($S(InsertOpenBrace, NestedImplicitObjectLiteral, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3) {
8822
+ var o = $1;
8810
8823
  var s = $2;
8824
+ var c = $3;
8825
+ const expressions = [s];
8811
8826
  return {
8812
8827
  type: "BlockStatement",
8813
- expressions: [s],
8814
- children: $0
8828
+ expressions,
8829
+ children: [o, expressions, c]
8815
8830
  };
8816
8831
  });
8817
8832
  var NonSingleBracedBlock$$ = [NonSingleBracedBlock$0, NonSingleBracedBlock$1, NonSingleBracedBlock$2];
@@ -16599,10 +16614,13 @@ function compile(src, options) {
16599
16614
  let ast;
16600
16615
  try {
16601
16616
  import_parser.parse.config = options.parseOptions || {};
16602
- ast = prune((0, import_parser.parse)(src, {
16617
+ ast = (0, import_parser.parse)(src, {
16603
16618
  filename,
16604
16619
  events
16605
- }));
16620
+ });
16621
+ if (!(options.ast === "raw")) {
16622
+ ast = prune(ast);
16623
+ }
16606
16624
  } finally {
16607
16625
  if (hits || trace) {
16608
16626
  import("fs").then(function({ writeFileSync }) {
package/dist/types.d.ts CHANGED
@@ -32,8 +32,13 @@ declare module "@danielx/civet" {
32
32
  }>
33
33
  export type CompileOptions = {
34
34
  filename?: string
35
- js?: boolean
36
35
  sourceMap?: boolean
36
+ inlineMap?: boolean
37
+ ast?: boolean | "raw"
38
+ js?: boolean
39
+ noCache?: boolean
40
+ hits?: string
41
+ trace?: string
37
42
  parseOptions?: ParseOptions
38
43
  }
39
44
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.6.88",
4
+ "version": "0.6.89",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",