mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
Further reducing amount of redundant parentheses.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var Lexer, compile, helpers, lexer, parser, path, processScripts;
|
var Lexer, compile, helpers, lexer, parser, path, processScripts;
|
||||||
if ((typeof process !== "undefined" && process !== null)) {
|
if (typeof process !== "undefined" && process !== null) {
|
||||||
path = require('path');
|
path = require('path');
|
||||||
Lexer = require('./lexer').Lexer;
|
Lexer = require('./lexer').Lexer;
|
||||||
parser = require('./parser').parser;
|
parser = require('./parser').parser;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
(function() {
|
(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 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;
|
var __slice = Array.prototype.slice;
|
||||||
if ((typeof process !== "undefined" && process !== null)) {
|
if (typeof process !== "undefined" && process !== null) {
|
||||||
_a = require('./rewriter');
|
_a = require('./rewriter');
|
||||||
Rewriter = _a.Rewriter;
|
Rewriter = _a.Rewriter;
|
||||||
_b = require('./helpers');
|
_b = require('./helpers');
|
||||||
@@ -491,7 +491,7 @@
|
|||||||
while (i < str.length - 1) {
|
while (i < str.length - 1) {
|
||||||
if (starts(str, '\\', i)) {
|
if (starts(str, '\\', i)) {
|
||||||
i += 1;
|
i += 1;
|
||||||
} else if ((expr = this.balancedString(str.substring(i), [['#{', '}']]))) {
|
} else if (expr = this.balancedString(str.substring(i), [['#{', '}']])) {
|
||||||
if (pi < i) {
|
if (pi < i) {
|
||||||
tokens.push(['STRING', quote + str.substring(pi, i) + quote]);
|
tokens.push(['STRING', quote + str.substring(pi, i) + quote]);
|
||||||
}
|
}
|
||||||
@@ -562,7 +562,7 @@
|
|||||||
if (!(tok = this.prev(index))) {
|
if (!(tok = this.prev(index))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ((typeof newTag !== "undefined" && newTag !== null)) {
|
if (typeof newTag !== "undefined" && newTag !== null) {
|
||||||
return (tok[0] = newTag);
|
return (tok[0] = newTag);
|
||||||
}
|
}
|
||||||
return tok[0];
|
return tok[0];
|
||||||
@@ -572,7 +572,7 @@
|
|||||||
if (!(tok = this.prev(index))) {
|
if (!(tok = this.prev(index))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ((typeof val !== "undefined" && val !== null)) {
|
if (typeof val !== "undefined" && val !== null) {
|
||||||
return (tok[1] = val);
|
return (tok[1] = val);
|
||||||
}
|
}
|
||||||
return tok[1];
|
return tok[1];
|
||||||
|
|||||||
13
lib/nodes.js
13
lib/nodes.js
@@ -8,7 +8,7 @@
|
|||||||
if (typeof parent.extended === "function") parent.extended(child);
|
if (typeof parent.extended === "function") parent.extended(child);
|
||||||
child.__superClass__ = parent.prototype;
|
child.__superClass__ = parent.prototype;
|
||||||
};
|
};
|
||||||
if ((typeof process !== "undefined" && process !== null)) {
|
if (typeof process !== "undefined" && process !== null) {
|
||||||
Scope = require('./scope').Scope;
|
Scope = require('./scope').Scope;
|
||||||
helpers = require('./helpers').helpers;
|
helpers = require('./helpers').helpers;
|
||||||
} else {
|
} else {
|
||||||
@@ -1200,6 +1200,7 @@
|
|||||||
top = del(o, 'top') && !this.returns;
|
top = del(o, 'top') && !this.returns;
|
||||||
o.indent = this.idt(1);
|
o.indent = this.idt(1);
|
||||||
o.top = true;
|
o.top = true;
|
||||||
|
this.condition.parenthetical = true;
|
||||||
cond = this.condition.compile(o);
|
cond = this.condition.compile(o);
|
||||||
set = '';
|
set = '';
|
||||||
if (!(top)) {
|
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))));
|
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) {
|
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() {
|
return (function() {
|
||||||
_b = []; _d = flatten([this.condition]);
|
_b = []; _d = conditions;
|
||||||
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
||||||
cond = _d[_c];
|
cond = _d[_c];
|
||||||
_b.push(cond.compile(o));
|
_b.push(cond.compile(o));
|
||||||
}
|
}
|
||||||
return _b;
|
return _b;
|
||||||
}).call(this).join(' || ');
|
})().join(' || ');
|
||||||
};
|
};
|
||||||
IfNode.prototype.compileNode = function(o) {
|
IfNode.prototype.compileNode = function(o) {
|
||||||
return this.isStatement(o) ? this.compileStatement(o) : this.compileTernary(o);
|
return this.isStatement(o) ? this.compileStatement(o) : this.compileTernary(o);
|
||||||
|
|||||||
@@ -100,7 +100,7 @@
|
|||||||
_b = args;
|
_b = args;
|
||||||
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
||||||
arg = _b[_a];
|
arg = _b[_a];
|
||||||
if ((match = arg.match(MULTI_FLAG))) {
|
if (match = arg.match(MULTI_FLAG)) {
|
||||||
_e = match[1].split('');
|
_e = match[1].split('');
|
||||||
for (_d = 0, _f = _e.length; _d < _f; _d++) {
|
for (_d = 0, _f = _e.length; _d < _f; _d++) {
|
||||||
l = _e[_d];
|
l = _e[_d];
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
(function() {
|
(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 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;
|
var __hasProp = Object.prototype.hasOwnProperty;
|
||||||
if ((typeof process !== "undefined" && process !== null)) {
|
if (typeof process !== "undefined" && process !== null) {
|
||||||
_a = require('./helpers');
|
_a = require('./helpers');
|
||||||
helpers = _a.helpers;
|
helpers = _a.helpers;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1033,6 +1033,7 @@ exports.WhileNode = class WhileNode extends BaseNode
|
|||||||
top = del(o, 'top') and not @returns
|
top = del(o, 'top') and not @returns
|
||||||
o.indent = @idt 1
|
o.indent = @idt 1
|
||||||
o.top = true
|
o.top = true
|
||||||
|
@condition.parenthetical = yes
|
||||||
cond = @condition.compile(o)
|
cond = @condition.compile(o)
|
||||||
set = ''
|
set = ''
|
||||||
unless top
|
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)))
|
@statement or= !!((o and o.top) or @tags.statement or @bodyNode().isStatement(o) or (@elseBody and @elseBodyNode().isStatement(o)))
|
||||||
|
|
||||||
compileCondition: (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) ->
|
compileNode: (o) ->
|
||||||
if @isStatement(o) then @compileStatement(o) else @compileTernary(o)
|
if @isStatement(o) then @compileStatement(o) else @compileTernary(o)
|
||||||
|
|||||||
Reference in New Issue
Block a user