Further reducing amount of redundant parentheses.
This commit is contained in:
parent
9894eeb8e9
commit
f496cc229b
|
@ -1,6 +1,6 @@
|
|||
(function() {
|
||||
var Lexer, compile, helpers, lexer, parser, path, processScripts;
|
||||
if ((typeof process !== "undefined" && process !== null)) {
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
path = require('path');
|
||||
Lexer = require('./lexer').Lexer;
|
||||
parser = require('./parser').parser;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function() {
|
||||
var ASSIGNED, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, CONVERSIONS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_END, REGEX_ESCAPE, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, SHIFT, STRING_NEWLINES, UNARY, WHITESPACE, _a, _b, _c, compact, count, helpers, include, starts;
|
||||
var __slice = Array.prototype.slice;
|
||||
if ((typeof process !== "undefined" && process !== null)) {
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
_a = require('./rewriter');
|
||||
Rewriter = _a.Rewriter;
|
||||
_b = require('./helpers');
|
||||
|
@ -491,7 +491,7 @@
|
|||
while (i < str.length - 1) {
|
||||
if (starts(str, '\\', i)) {
|
||||
i += 1;
|
||||
} else if ((expr = this.balancedString(str.substring(i), [['#{', '}']]))) {
|
||||
} else if (expr = this.balancedString(str.substring(i), [['#{', '}']])) {
|
||||
if (pi < i) {
|
||||
tokens.push(['STRING', quote + str.substring(pi, i) + quote]);
|
||||
}
|
||||
|
@ -562,7 +562,7 @@
|
|||
if (!(tok = this.prev(index))) {
|
||||
return null;
|
||||
}
|
||||
if ((typeof newTag !== "undefined" && newTag !== null)) {
|
||||
if (typeof newTag !== "undefined" && newTag !== null) {
|
||||
return (tok[0] = newTag);
|
||||
}
|
||||
return tok[0];
|
||||
|
@ -572,7 +572,7 @@
|
|||
if (!(tok = this.prev(index))) {
|
||||
return null;
|
||||
}
|
||||
if ((typeof val !== "undefined" && val !== null)) {
|
||||
if (typeof val !== "undefined" && val !== null) {
|
||||
return (tok[1] = val);
|
||||
}
|
||||
return tok[1];
|
||||
|
|
13
lib/nodes.js
13
lib/nodes.js
|
@ -8,7 +8,7 @@
|
|||
if (typeof parent.extended === "function") parent.extended(child);
|
||||
child.__superClass__ = parent.prototype;
|
||||
};
|
||||
if ((typeof process !== "undefined" && process !== null)) {
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
Scope = require('./scope').Scope;
|
||||
helpers = require('./helpers').helpers;
|
||||
} else {
|
||||
|
@ -1200,6 +1200,7 @@
|
|||
top = del(o, 'top') && !this.returns;
|
||||
o.indent = this.idt(1);
|
||||
o.top = true;
|
||||
this.condition.parenthetical = true;
|
||||
cond = this.condition.compile(o);
|
||||
set = '';
|
||||
if (!(top)) {
|
||||
|
@ -1702,15 +1703,19 @@
|
|||
return this.statement = this.statement || (!!((o && o.top) || this.tags.statement || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o))));
|
||||
};
|
||||
IfNode.prototype.compileCondition = function(o) {
|
||||
var _b, _c, _d, _e, cond;
|
||||
var _b, _c, _d, _e, cond, conditions;
|
||||
conditions = flatten([this.condition]);
|
||||
if (conditions.length === 1) {
|
||||
conditions[0].parenthetical = true;
|
||||
}
|
||||
return (function() {
|
||||
_b = []; _d = flatten([this.condition]);
|
||||
_b = []; _d = conditions;
|
||||
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
||||
cond = _d[_c];
|
||||
_b.push(cond.compile(o));
|
||||
}
|
||||
return _b;
|
||||
}).call(this).join(' || ');
|
||||
})().join(' || ');
|
||||
};
|
||||
IfNode.prototype.compileNode = function(o) {
|
||||
return this.isStatement(o) ? this.compileStatement(o) : this.compileTernary(o);
|
||||
|
|
|
@ -100,7 +100,7 @@
|
|||
_b = args;
|
||||
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
||||
arg = _b[_a];
|
||||
if ((match = arg.match(MULTI_FLAG))) {
|
||||
if (match = arg.match(MULTI_FLAG)) {
|
||||
_e = match[1].split('');
|
||||
for (_d = 0, _f = _e.length; _d < _f; _d++) {
|
||||
l = _e[_d];
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function() {
|
||||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, helpers, include, pair;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
if ((typeof process !== "undefined" && process !== null)) {
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
_a = require('./helpers');
|
||||
helpers = _a.helpers;
|
||||
} else {
|
||||
|
|
|
@ -1033,6 +1033,7 @@ exports.WhileNode = class WhileNode extends BaseNode
|
|||
top = del(o, 'top') and not @returns
|
||||
o.indent = @idt 1
|
||||
o.top = true
|
||||
@condition.parenthetical = yes
|
||||
cond = @condition.compile(o)
|
||||
set = ''
|
||||
unless top
|
||||
|
@ -1417,7 +1418,9 @@ exports.IfNode = class IfNode extends BaseNode
|
|||
@statement or= !!((o and o.top) or @tags.statement or @bodyNode().isStatement(o) or (@elseBody and @elseBodyNode().isStatement(o)))
|
||||
|
||||
compileCondition: (o) ->
|
||||
(cond.compile(o) for cond in flatten([@condition])).join(' || ')
|
||||
conditions = flatten [@condition]
|
||||
conditions[0].parenthetical = yes if conditions.length is 1
|
||||
(cond.compile(o) for cond in conditions).join(' || ')
|
||||
|
||||
compileNode: (o) ->
|
||||
if @isStatement(o) then @compileStatement(o) else @compileTernary(o)
|
||||
|
|
Loading…
Reference in New Issue