@danielx/civet 0.2.6 → 0.2.9

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 CHANGED
@@ -60,17 +60,16 @@ Things Kept from CoffeeScript
60
60
  - OptionalChain shorthand for index and function application `a?[b]` -> `a?.[b]`, `a?(b)` -> `a?.(b)`
61
61
  - `@` -> `this`
62
62
  - `@id` -> `this.id`
63
+ - Postfix `if/unless`
63
64
  - JSX 😿
64
65
  - TODO
65
66
  - [ ] `"""` Strings (for compatibility with existing .coffee code)
66
- - [ ] `///` Heregexp
67
67
  - [ ] Chained comparisons
68
68
 
69
69
  Things Removed from CoffeeScript
70
70
  ---
71
71
 
72
- - `on` (use `true`)
73
- - `off` (use `false`)
72
+ - `on/yes/off/no` (use `true/false`)
74
73
  - `do` keyword (replaced with JS `do`)
75
74
  - `for from` (use JS `for of`)
76
75
  - Array slices `list[0...2]` (use `list.slice(0, 2)`)
@@ -79,6 +78,8 @@ Things Removed from CoffeeScript
79
78
  - Implicit declarations
80
79
  - Implicit returns (will probably add later)
81
80
  - Rest parameter in any assignment position (might add later)
81
+ - `///` Heregexp
82
+ - Embedded JS
82
83
 
83
84
  Things Changed from CoffeeScript
84
85
  ---
@@ -89,6 +90,8 @@ Things Changed from CoffeeScript
89
90
  - `a...` is now `...a` just like JS
90
91
  - `x?.y` now compiles to `x?.y` rather than the `if typeof x !== 'undefined' && x !== null` if check
91
92
  - Existential `x?` -> `(x != null)` no longer checks for undeclared variables.
93
+ - Embedded JS `\`\`` has been replaced with JS template literals.
94
+ - No longer allowing multiple postfix `if/unless` on the same line.
92
95
 
93
96
  Things Added that CoffeeScript didn't
94
97
  ---
@@ -115,3 +118,11 @@ Things Added that CoffeeScript didn't
115
118
  console.log "hi"
116
119
  ```
117
120
  - TypeScript Types
121
+
122
+ Things Changed from ES6
123
+ ---
124
+
125
+ - Disallow no parens on single argument arrow function. `x => ...` must become `(x) => ...`
126
+ The reasoning is `x -> ` => `x(function() ...)` in CoffeeScript and having `->` and `=>`
127
+ behave more differently than they already do is bad. Passing an anonymous function to an
128
+ application without parens is also convenient.
package/dist/browser.js CHANGED
@@ -421,6 +421,7 @@ var Civet = (() => {
421
421
  AssignmentExpressionRest,
422
422
  YieldExpression,
423
423
  ArrowFunction,
424
+ FatArrow,
424
425
  ConciseBody,
425
426
  ConditionalExpression,
426
427
  ShortCircuitExpression,
@@ -498,6 +499,8 @@ var Civet = (() => {
498
499
  BinaryOp,
499
500
  UnaryOp,
500
501
  ModuleItem,
502
+ StatementListItem,
503
+ PostfixConditional,
501
504
  Statement,
502
505
  EmptyStatement,
503
506
  BlockStatement,
@@ -726,10 +729,10 @@ var Civet = (() => {
726
729
  var $L82 = $L("delete");
727
730
  var $L83 = $L("void");
728
731
  var $L84 = $L("typeof");
729
- var $L85 = $L(";");
730
- var $L86 = $L("if");
731
- var $L87 = $L("else");
732
- var $L88 = $L("unless");
732
+ var $L85 = $L("if");
733
+ var $L86 = $L("unless");
734
+ var $L87 = $L(";");
735
+ var $L88 = $L("else");
733
736
  var $L89 = $L("loop");
734
737
  var $L90 = $L("do");
735
738
  var $L91 = $L("while");
@@ -951,7 +954,7 @@ var Civet = (() => {
951
954
  }
952
955
  var AssignmentExpressionRest$0 = YieldExpression;
953
956
  var AssignmentExpressionRest$1 = $S($E($S($EXPECT($L7, fail, 'AssignmentExpressionRest "async"'), __)), ArrowFunction);
954
- var AssignmentExpressionRest$2 = $S($P($S(__, LeftHandSideExpression, __, AssignmentOp)), $C($S($Q(_), Expression), $S(__, Expression)));
957
+ var AssignmentExpressionRest$2 = $S($P($S(__, LeftHandSideExpression, __, AssignmentOp)), Expression);
955
958
  var AssignmentExpressionRest$3 = ConditionalExpression;
956
959
  function AssignmentExpressionRest(state) {
957
960
  if (state.tokenize) {
@@ -971,7 +974,7 @@ var Civet = (() => {
971
974
  }
972
975
  }
973
976
  var ArrowFunction$0 = ThinArrowFunction;
974
- var ArrowFunction$1 = $S($C(BindingIdentifier, Parameters), $E(ReturnTypeSuffix), __, $EXPECT($L10, fail, 'ArrowFunction "=>"'), ConciseBody);
977
+ var ArrowFunction$1 = $S(Parameters, $E(ReturnTypeSuffix), FatArrow, ConciseBody);
975
978
  function ArrowFunction(state) {
976
979
  if (state.tokenize) {
977
980
  return $TOKEN("ArrowFunction", state, ArrowFunction$0(state) || ArrowFunction$1(state));
@@ -979,8 +982,23 @@ var Civet = (() => {
979
982
  return ArrowFunction$0(state) || ArrowFunction$1(state);
980
983
  }
981
984
  }
982
- var ConciseBody$0 = $S($N($S($Q(_), $EXPECT($L11, fail, 'ConciseBody "{"'))), AssignmentExpression);
983
- var ConciseBody$1 = $S(EOS, SingleNestedBlockExpression);
985
+ var FatArrow$0 = $TS($S(__, $EXPECT($L10, fail, 'FatArrow "=>"')), function($skip, $loc, $0, $1, $2) {
986
+ var ws = $1;
987
+ if (!ws.length)
988
+ return " =>";
989
+ return $0;
990
+ });
991
+ function FatArrow(state) {
992
+ if (state.verbose)
993
+ console.log("ENTER:", "FatArrow");
994
+ if (state.tokenize) {
995
+ return $TOKEN("FatArrow", state, FatArrow$0(state));
996
+ } else {
997
+ return FatArrow$0(state);
998
+ }
999
+ }
1000
+ var ConciseBody$0 = $S(EOS, SingleNestedBlockExpression);
1001
+ var ConciseBody$1 = $S($N($S($Q(_), $EXPECT($L11, fail, 'ConciseBody "{"'))), AssignmentExpression);
984
1002
  var ConciseBody$2 = BracedBlock;
985
1003
  function ConciseBody(state) {
986
1004
  if (state.tokenize) {
@@ -1419,7 +1437,7 @@ var Civet = (() => {
1419
1437
  return BracedBlock$0(state) || BracedBlock$1(state) || BracedBlock$2(state);
1420
1438
  }
1421
1439
  }
1422
- var SingleNestedBlockExpression$0 = $TS($S(PushIndent, $E($S(Nested, $C(Declaration, Statement))), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
1440
+ var SingleNestedBlockExpression$0 = $TS($S(PushIndent, $E($S(Nested, StatementListItem)), $C($C($N($S(Nested, StatementListItem)), $S(PopIndent, $N($EXPECT($L30, fail, 'SingleNestedBlockExpression ""')))), PopIndent)), function($skip, $loc, $0, $1, $2, $3) {
1423
1441
  var exp = $2;
1424
1442
  if (exp)
1425
1443
  return exp;
@@ -1449,7 +1467,7 @@ var Civet = (() => {
1449
1467
  return NestedBlockExpressions$0(state);
1450
1468
  }
1451
1469
  }
1452
- var BlockExpression$0 = $S(Nested, $C(Declaration, Statement), StatementDelimiter);
1470
+ var BlockExpression$0 = $S(Nested, StatementListItem, StatementDelimiter);
1453
1471
  function BlockExpression(state) {
1454
1472
  if (state.verbose)
1455
1473
  console.log("ENTER:", "BlockExpression");
@@ -1859,13 +1877,45 @@ var Civet = (() => {
1859
1877
  }
1860
1878
  var ModuleItem$0 = ImportDeclaration;
1861
1879
  var ModuleItem$1 = ExportDeclaration;
1862
- var ModuleItem$2 = Declaration;
1863
- var ModuleItem$3 = Statement;
1880
+ var ModuleItem$2 = StatementListItem;
1864
1881
  function ModuleItem(state) {
1865
1882
  if (state.tokenize) {
1866
- return $TOKEN("ModuleItem", state, ModuleItem$0(state) || ModuleItem$1(state) || ModuleItem$2(state) || ModuleItem$3(state));
1883
+ return $TOKEN("ModuleItem", state, ModuleItem$0(state) || ModuleItem$1(state) || ModuleItem$2(state));
1867
1884
  } else {
1868
- return ModuleItem$0(state) || ModuleItem$1(state) || ModuleItem$2(state) || ModuleItem$3(state);
1885
+ return ModuleItem$0(state) || ModuleItem$1(state) || ModuleItem$2(state);
1886
+ }
1887
+ }
1888
+ var StatementListItem$0 = $TS($S($C(Declaration, Statement), $E(PostfixConditional)), function($skip, $loc, $0, $1, $2) {
1889
+ var statement = $1;
1890
+ var cond = $2;
1891
+ if (cond)
1892
+ return [cond, statement, "}"];
1893
+ return $0;
1894
+ });
1895
+ function StatementListItem(state) {
1896
+ if (state.verbose)
1897
+ console.log("ENTER:", "StatementListItem");
1898
+ if (state.tokenize) {
1899
+ return $TOKEN("StatementListItem", state, StatementListItem$0(state));
1900
+ } else {
1901
+ return StatementListItem$0(state);
1902
+ }
1903
+ }
1904
+ var PostfixConditional$0 = $TS($S($Q(TrailingComment), $C($EXPECT($L85, fail, 'PostfixConditional "if"'), $EXPECT($L86, fail, 'PostfixConditional "unless"')), NonIdContinue, Expression), function($skip, $loc, $0, $1, $2, $3, $4) {
1905
+ var ws = $1;
1906
+ var cond = $2;
1907
+ var exp = $4;
1908
+ if (cond === "if")
1909
+ return [ws, "if(", exp, ") {"];
1910
+ return [ws, "if(!(", exp, ")) {"];
1911
+ });
1912
+ function PostfixConditional(state) {
1913
+ if (state.verbose)
1914
+ console.log("ENTER:", "PostfixConditional");
1915
+ if (state.tokenize) {
1916
+ return $TOKEN("PostfixConditional", state, PostfixConditional$0(state));
1917
+ } else {
1918
+ return PostfixConditional$0(state);
1869
1919
  }
1870
1920
  }
1871
1921
  var Statement$0 = KeywordStatement;
@@ -1884,7 +1934,7 @@ var Civet = (() => {
1884
1934
  return Statement$0(state) || Statement$1(state) || Statement$2(state) || Statement$3(state) || Statement$4(state) || Statement$5(state) || Statement$6(state) || Statement$7(state) || Statement$8(state);
1885
1935
  }
1886
1936
  }
1887
- var EmptyStatement$0 = $S($Q(TrailingComment), $Y($EXPECT($L85, fail, 'EmptyStatement ";"')));
1937
+ var EmptyStatement$0 = $S($Q(TrailingComment), $Y($EXPECT($L87, fail, 'EmptyStatement ";"')));
1888
1938
  function EmptyStatement(state) {
1889
1939
  if (state.verbose)
1890
1940
  console.log("ENTER:", "EmptyStatement");
@@ -1904,8 +1954,8 @@ var Civet = (() => {
1904
1954
  return BlockStatement$0(state);
1905
1955
  }
1906
1956
  }
1907
- var IfStatement$0 = $S($EXPECT($L86, fail, 'IfStatement "if"'), Condition, Block, $E($S(__, $EXPECT($L87, fail, 'IfStatement "else"'), Block)));
1908
- var IfStatement$1 = $TS($S($EXPECT($L88, fail, 'IfStatement "unless"'), Condition, Block), function($skip, $loc, $0, $1, $2, $3) {
1957
+ var IfStatement$0 = $S($EXPECT($L85, fail, 'IfStatement "if"'), Condition, Block, $E($S(__, $EXPECT($L88, fail, 'IfStatement "else"'), Block)));
1958
+ var IfStatement$1 = $TS($S($EXPECT($L86, fail, 'IfStatement "unless"'), Condition, Block), function($skip, $loc, $0, $1, $2, $3) {
1909
1959
  var condition = $2;
1910
1960
  var block = $3;
1911
1961
  return ["if", condition.map((c) => {
@@ -1968,7 +2018,7 @@ var Civet = (() => {
1968
2018
  return WhileStatement$0(state);
1969
2019
  }
1970
2020
  }
1971
- var ForStatement$0 = $S($EXPECT($L92, fail, 'ForStatement "for"'), __, $EXPECT($L1, fail, 'ForStatement "("'), __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, $EXPECT($L85, fail, 'ForStatement ";"'), __, $E(Expression), $EXPECT($L85, fail, 'ForStatement ";"'), __, $E(Expression), $EXPECT($L2, fail, 'ForStatement ")"'), Block);
2021
+ var ForStatement$0 = $S($EXPECT($L92, fail, 'ForStatement "for"'), __, $EXPECT($L1, fail, 'ForStatement "("'), __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, $EXPECT($L87, fail, 'ForStatement ";"'), __, $E(Expression), $EXPECT($L87, fail, 'ForStatement ";"'), __, $E(Expression), $EXPECT($L2, fail, 'ForStatement ")"'), Block);
1972
2022
  function ForStatement(state) {
1973
2023
  if (state.verbose)
1974
2024
  console.log("ENTER:", "ForStatement");
@@ -2689,7 +2739,7 @@ var Civet = (() => {
2689
2739
  return __$0(state);
2690
2740
  }
2691
2741
  }
2692
- var StatementDelimiter$0 = $S($Q(TrailingComment), $EXPECT($L85, fail, 'StatementDelimiter ";"'), $Q(TrailingComment));
2742
+ var StatementDelimiter$0 = $S($Q(TrailingComment), $EXPECT($L87, fail, 'StatementDelimiter ";"'), $Q(TrailingComment));
2693
2743
  var StatementDelimiter$1 = $T($Y(EOS), function(value) {
2694
2744
  return [";", value];
2695
2745
  });
@@ -2934,7 +2984,7 @@ var Civet = (() => {
2934
2984
  return InterfaceProperty$0(state);
2935
2985
  }
2936
2986
  }
2937
- var InterfacePropertyDelimiter$0 = $S($Q(_), $EXPECT($L85, fail, 'InterfacePropertyDelimiter ";"'));
2987
+ var InterfacePropertyDelimiter$0 = $S($Q(_), $EXPECT($L87, fail, 'InterfacePropertyDelimiter ";"'));
2938
2988
  var InterfacePropertyDelimiter$1 = $Y($S($Q(_), $EXPECT($L16, fail, 'InterfacePropertyDelimiter "}"')));
2939
2989
  var InterfacePropertyDelimiter$2 = $T($Y($S(__, $EXPECT($L16, fail, 'InterfacePropertyDelimiter "}"'))), function(value) {
2940
2990
  return ";";
@@ -3469,7 +3519,8 @@ var Civet = (() => {
3469
3519
  parse,
3470
3520
  compile: function(src, options) {
3471
3521
  return gen(parse(src), options);
3472
- }
3522
+ },
3523
+ generate: gen
3473
3524
  };
3474
3525
  }
3475
3526
  });