rip-lang 2.7.2 → 2.8.0

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rip-lang",
3
- "version": "2.7.2",
3
+ "version": "2.8.0",
4
4
  "description": "A modern language that compiles to JavaScript",
5
5
  "type": "module",
6
6
  "main": "src/compiler.js",
package/src/lexer.js CHANGED
@@ -2061,6 +2061,7 @@ Rewriter = (function() {
2061
2061
  this.convertPostfixSpreadRest();
2062
2062
  this.tagPostfixConditionals();
2063
2063
  this.addImplicitBracesAndParens();
2064
+ this.addImplicitCallCommas();
2064
2065
  this.rescueStowawayComments();
2065
2066
  this.addLocationDataToGeneratedTokens();
2066
2067
  this.fixIndentationLocationData();
@@ -2589,6 +2590,32 @@ Rewriter = (function() {
2589
2590
  });
2590
2591
  }
2591
2592
 
2593
+ // Insert commas before arrow functions in implicit calls.
2594
+ // Allows: get '/users' -> ... instead of: get '/users', -> ...
2595
+ addImplicitCallCommas() {
2596
+ var callDepth, i, prevTag, tag, tokens;
2597
+ tokens = this.tokens;
2598
+ callDepth = 0;
2599
+ i = 0;
2600
+ while (i < tokens.length) {
2601
+ tag = tokens[i][0];
2602
+ prevTag = i > 0 ? tokens[i - 1][0] : null;
2603
+ // Track call depth
2604
+ if (tag === 'CALL_START' || tag === '(') {
2605
+ callDepth++;
2606
+ } else if (tag === 'CALL_END' || tag === ')') {
2607
+ callDepth--;
2608
+ }
2609
+ // Inside a call, if we see -> or => preceded by STRING, insert comma
2610
+ if (callDepth > 0 && (tag === '->' || tag === '=>') &&
2611
+ (prevTag === 'STRING' || prevTag === 'STRING_END')) {
2612
+ tokens.splice(i, 0, generate(',', ',', tokens[i], tokens[i - 1]));
2613
+ i++; // Skip past the inserted comma
2614
+ }
2615
+ i++;
2616
+ }
2617
+ }
2618
+
2592
2619
  // Not all tokens survive processing by the parser. To avoid comments getting
2593
2620
  // lost into the ether, find comments attached to doomed tokens and move them
2594
2621
  // to a token that will make it to the other side.