rip-lang 2.7.3 → 2.8.1
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 +25 -3
- package/docs/dist/rip.browser.js +26 -3
- package/docs/dist/rip.browser.min.js +84 -84
- package/docs/dist/rip.browser.min.js.br +0 -0
- package/package.json +1 -1
- package/src/lexer.js +34 -2
|
Binary file
|
package/package.json
CHANGED
package/src/lexer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var BALANCED_PAIRS, BOM, BOOL, CALLABLE, CALL_CLOSERS, CODE, COMMENT, COMPARABLE_LEFT_SIDE, COMPARE, COMPOUND_ASSIGN, CONTROL_IN_IMPLICIT, DISCARDED, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_COMMENT, HERE_JSTOKEN, IDENTIFIER, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_KEYWORDS, LINEBREAKS, LINE_BREAK, LINE_CONTINUER, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, REGEX_INVALID_ESCAPE, RELATION, RESERVED, RIP_ALIASES, RIP_ALIAS_MAP, RIP_KEYWORDS, Rewriter, SHIFT, SINGLE_CLOSERS, SINGLE_LINERS, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_INVALID_ESCAPE, STRING_SINGLE, STRING_START, TRAILING_SPACES, UNARY, UNARY_MATH, UNFINISHED, VALID_FLAGS, WHITESPACE, addTokenData, generate, isForFrom, k, key, left, len, moveComments, right, indexOf = [].indexOf, slice = [].slice, hasProp = {}.hasOwnProperty;
|
|
1
|
+
var BALANCED_PAIRS, BOM, BOOL, CALLABLE, CALL_CLOSERS, CODE, COMMENT, COMPARABLE_LEFT_SIDE, COMPARE, COMPOUND_ASSIGN, CONTROL_IN_IMPLICIT, DISCARDED, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_COMMENT, HERE_JSTOKEN, IDENTIFIER, IMPLICIT_CALL, IMPLICIT_COMMA_BEFORE_ARROW, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_KEYWORDS, LINEBREAKS, LINE_BREAK, LINE_CONTINUER, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, REGEX_INVALID_ESCAPE, RELATION, RESERVED, RIP_ALIASES, RIP_ALIAS_MAP, RIP_KEYWORDS, Rewriter, SHIFT, SINGLE_CLOSERS, SINGLE_LINERS, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_INVALID_ESCAPE, STRING_SINGLE, STRING_START, TRAILING_SPACES, UNARY, UNARY_MATH, UNFINISHED, VALID_FLAGS, WHITESPACE, addTokenData, generate, isForFrom, k, key, left, len, moveComments, right, indexOf = [].indexOf, slice = [].slice, hasProp = {}.hasOwnProperty;
|
|
2
2
|
|
|
3
3
|
// The Rip Lexer. Uses a series of token-matching regexes to attempt
|
|
4
4
|
// matches against the beginning of the source code. When a match is found,
|
|
@@ -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();
|
|
@@ -2428,7 +2429,8 @@ Rewriter = (function() {
|
|
|
2428
2429
|
// Recognize standard implicit calls like
|
|
2429
2430
|
// f a, f() b, f? c, h[0] d etc.
|
|
2430
2431
|
// Added support for spread dots on the left side: f ...a
|
|
2431
|
-
|
|
2432
|
+
// Don't treat `] ->` or `} ->` as implicit calls (these become args with comma insertion)
|
|
2433
|
+
if ((indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || (nextTag === '...' && (ref = this.tag(i + 2), indexOf.call(IMPLICIT_CALL, ref) >= 0) && !this.findTagsBackwards(i, ['INDEX_START', '['])) || indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !nextToken.spaced && !nextToken.newLine) && !inControlFlow() && !((tag === ']' || tag === '}') && (nextTag === '->' || nextTag === '=>'))) {
|
|
2432
2434
|
if (tag === '?') {
|
|
2433
2435
|
tag = token[0] = 'FUNC_EXIST';
|
|
2434
2436
|
}
|
|
@@ -2589,6 +2591,33 @@ Rewriter = (function() {
|
|
|
2589
2591
|
});
|
|
2590
2592
|
}
|
|
2591
2593
|
|
|
2594
|
+
// Insert commas before arrow functions in implicit calls.
|
|
2595
|
+
// Allows: get '/users' -> ... instead of: get '/users', -> ...
|
|
2596
|
+
// Works with literals that would otherwise be syntax errors before arrows.
|
|
2597
|
+
addImplicitCallCommas() {
|
|
2598
|
+
var callDepth, i, prevTag, ref, tag, tokens;
|
|
2599
|
+
tokens = this.tokens;
|
|
2600
|
+
callDepth = 0;
|
|
2601
|
+
i = 0;
|
|
2602
|
+
while (i < tokens.length) {
|
|
2603
|
+
tag = tokens[i][0];
|
|
2604
|
+
prevTag = i > 0 ? tokens[i - 1][0] : null;
|
|
2605
|
+
// Track call depth
|
|
2606
|
+
if (tag === 'CALL_START' || tag === '(') {
|
|
2607
|
+
callDepth++;
|
|
2608
|
+
} else if (tag === 'CALL_END' || tag === ')') {
|
|
2609
|
+
callDepth--;
|
|
2610
|
+
}
|
|
2611
|
+
// Inside a call, if we see -> or => preceded by a literal value, insert comma
|
|
2612
|
+
if (callDepth > 0 && (tag === '->' || tag === '=>') &&
|
|
2613
|
+
(ref = prevTag, indexOf.call(IMPLICIT_COMMA_BEFORE_ARROW, ref) >= 0)) {
|
|
2614
|
+
tokens.splice(i, 0, generate(',', ',', tokens[i], tokens[i - 1]));
|
|
2615
|
+
i++; // Skip past the inserted comma
|
|
2616
|
+
}
|
|
2617
|
+
i++;
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2592
2621
|
// Not all tokens survive processing by the parser. To avoid comments getting
|
|
2593
2622
|
// lost into the ether, find comments attached to doomed tokens and move them
|
|
2594
2623
|
// to a token that will make it to the other side.
|
|
@@ -3223,6 +3252,9 @@ IMPLICIT_UNSPACED_CALL = ['+', '-'];
|
|
|
3223
3252
|
// Tokens that always mark the end of an implicit call for single-liners.
|
|
3224
3253
|
IMPLICIT_END = ['POST_IF', 'FOR', 'WHILE', 'UNTIL', 'WHEN', 'BY', 'LOOP', 'TERMINATOR'];
|
|
3225
3254
|
|
|
3255
|
+
// Literals that trigger comma insertion before arrows: get '/path' -> ... becomes get('/path', -> ...)
|
|
3256
|
+
IMPLICIT_COMMA_BEFORE_ARROW = ['STRING', 'STRING_END', 'REGEX', 'REGEX_END', 'NUMBER', 'BOOL', 'NULL', 'UNDEFINED', 'INFINITY', 'NAN', ']', '}'];
|
|
3257
|
+
|
|
3226
3258
|
// Single-line flavors of block expressions that have unclosed endings.
|
|
3227
3259
|
// The grammar can't disambiguate them, so we insert the implicit indentation.
|
|
3228
3260
|
SINGLE_LINERS = ['ELSE', '->', '=>', 'TRY', 'FINALLY', 'THEN'];
|