mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
resolving merge conflict.
This commit is contained in:
@@ -596,7 +596,7 @@
|
||||
})
|
||||
]
|
||||
};
|
||||
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'RELATION'], ["left", '==', '!='], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'RELATION'], ["left", '==', '!=', 'COMPARE'], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||
tokens = [];
|
||||
for (name in grammar) {
|
||||
alternatives = grammar[name];
|
||||
|
||||
@@ -416,7 +416,7 @@
|
||||
if (!herecomment) {
|
||||
while (match = HEREDOC_INDENT.exec(doc)) {
|
||||
attempt = match[1];
|
||||
if (indent === null || 0 < (_ref2 = attempt.length) && _ref2 < indent.length) {
|
||||
if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) {
|
||||
indent = attempt;
|
||||
}
|
||||
}
|
||||
|
||||
40
lib/nodes.js
40
lib/nodes.js
@@ -1232,9 +1232,6 @@
|
||||
'!==': '===',
|
||||
'===': '!=='
|
||||
};
|
||||
Op.prototype.CHAINABLE = ['<', '>', '>=', '<=', '===', '!=='];
|
||||
Op.prototype.PREFIX_OPERATORS = ['new', 'typeof', 'delete'];
|
||||
Op.prototype.MUTATORS = ['++', '--', 'delete'];
|
||||
Op.prototype.children = ['first', 'second'];
|
||||
Op.prototype.isUnary = function() {
|
||||
return !this.second;
|
||||
@@ -1244,7 +1241,7 @@
|
||||
};
|
||||
Op.prototype.isChainable = function() {
|
||||
var _ref2;
|
||||
return _ref2 = this.operator, __indexOf.call(this.CHAINABLE, _ref2) >= 0;
|
||||
return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!==';
|
||||
};
|
||||
Op.prototype.invert = function() {
|
||||
var op;
|
||||
@@ -1253,18 +1250,15 @@
|
||||
return this;
|
||||
} else return this.second ? new Parens(this).invert() : Op.__super__.invert.call(this);
|
||||
};
|
||||
Op.prototype.toString = function(idt) {
|
||||
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
|
||||
};
|
||||
Op.prototype.unfoldSoak = function(o) {
|
||||
var _ref2;
|
||||
return (_ref2 = this.operator, __indexOf.call(this.MUTATORS, _ref2) >= 0) && If.unfoldSoak(o, this, 'first');
|
||||
return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && If.unfoldSoak(o, this, 'first');
|
||||
};
|
||||
Op.prototype.compileNode = function(o) {
|
||||
if (this.isUnary()) {
|
||||
return this.compileUnary(o);
|
||||
}
|
||||
if (this.isChainable() && this.first.unwrap().isChainable()) {
|
||||
if (this.isChainable() && this.first.isChainable()) {
|
||||
return this.compileChain(o);
|
||||
}
|
||||
if (this.operator === '?') {
|
||||
@@ -1274,9 +1268,14 @@
|
||||
return "" + (this.first.compile(o, LEVEL_OP)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
||||
};
|
||||
Op.prototype.compileChain = function(o) {
|
||||
var _ref2, shared;
|
||||
_ref2 = this.first.unwrap().second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
|
||||
return "" + (this.first.compile(o, LEVEL_OP)) + " && " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
||||
var _ref2, code, fst, shared;
|
||||
_ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
|
||||
fst = this.first.compile(o, LEVEL_OP);
|
||||
if (fst.charAt(0) === '(') {
|
||||
fst = fst.slice(1, -1);
|
||||
}
|
||||
code = "" + fst + " && " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
||||
return o.level < LEVEL_OP ? code : "(" + code + ")";
|
||||
};
|
||||
Op.prototype.compileExistence = function(o) {
|
||||
var fst, ref;
|
||||
@@ -1290,10 +1289,19 @@
|
||||
return new Existence(fst).compile(o) + (" ? " + ref + " : " + (this.second.compile(o, LEVEL_LIST)));
|
||||
};
|
||||
Op.prototype.compileUnary = function(o) {
|
||||
var _ref2, _ref3, parts, space;
|
||||
space = (_ref2 = this.operator, __indexOf.call(this.PREFIX_OPERATORS, _ref2) >= 0) || this.first instanceof Op && this.first.operator === this.operator && ((_ref3 = this.operator) === '+' || _ref3 === '-') ? ' ' : '';
|
||||
parts = [this.operator, space, this.first.compile(o, LEVEL_OP)];
|
||||
return (this.flip ? parts.reverse() : parts).join('');
|
||||
var op, parts;
|
||||
parts = [op = this.operator];
|
||||
if ((op === 'new' || op === 'typeof' || op === 'delete') || (op === '+' || op === '-') && this.first instanceof Op && this.first.operator === op) {
|
||||
parts.push(' ');
|
||||
}
|
||||
parts.push(this.first.compile(o, LEVEL_OP));
|
||||
if (this.flip) {
|
||||
parts.reverse();
|
||||
}
|
||||
return parts.join('');
|
||||
};
|
||||
Op.prototype.toString = function(idt) {
|
||||
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
|
||||
};
|
||||
return Op;
|
||||
})();
|
||||
|
||||
138
lib/parser.js
138
lib/parser.js
File diff suppressed because one or more lines are too long
@@ -555,9 +555,8 @@ operators = [
|
||||
["left", 'MATH']
|
||||
["left", '+', '-']
|
||||
["left", 'SHIFT']
|
||||
["left", 'COMPARE']
|
||||
["left", 'RELATION']
|
||||
["left", '==', '!=']
|
||||
["left", '==', '!=', 'COMPARE']
|
||||
["left", 'LOGIC']
|
||||
["left", '.']
|
||||
["nonassoc", 'INDENT', 'OUTDENT']
|
||||
|
||||
@@ -1033,16 +1033,6 @@ exports.Op = class Op extends Base
|
||||
'!==': '==='
|
||||
'===': '!=='
|
||||
|
||||
# The list of operators for which we perform
|
||||
# [Python-style comparison chaining](http://docs.python.org/reference/expressions.html#notin).
|
||||
CHAINABLE: ['<', '>', '>=', '<=', '===', '!==']
|
||||
|
||||
# Operators must come before their operands with a space.
|
||||
PREFIX_OPERATORS: ['new', 'typeof', 'delete']
|
||||
|
||||
# Operators that modify a reference.
|
||||
MUTATORS: ['++', '--', 'delete']
|
||||
|
||||
children: ['first', 'second']
|
||||
|
||||
constructor: (op, first, second, flip) ->
|
||||
@@ -1056,14 +1046,13 @@ exports.Op = class Op extends Base
|
||||
@second = second
|
||||
@flip = !!flip
|
||||
|
||||
isUnary: ->
|
||||
not @second
|
||||
isUnary: -> not @second
|
||||
|
||||
isComplex: ->
|
||||
@operator isnt '!' or @first.isComplex()
|
||||
isComplex: -> @operator isnt '!' or @first.isComplex()
|
||||
|
||||
isChainable: ->
|
||||
@operator in @CHAINABLE
|
||||
# Am I capable of
|
||||
# [Python-style comparison chaining](http://docs.python.org/reference/expressions.html#notin)?
|
||||
isChainable: -> @operator in ['<', '>', '>=', '<=', '===', '!==']
|
||||
|
||||
invert: ->
|
||||
if op = @INVERSIONS[@operator]
|
||||
@@ -1074,16 +1063,12 @@ exports.Op = class Op extends Base
|
||||
else
|
||||
super()
|
||||
|
||||
toString: (idt) ->
|
||||
super idt, @constructor.name + ' ' + @operator
|
||||
|
||||
unfoldSoak: (o) ->
|
||||
@operator in @MUTATORS and If.unfoldSoak o, this, 'first'
|
||||
@operator in ['++', '--', 'delete'] and If.unfoldSoak o, this, 'first'
|
||||
|
||||
compileNode: (o) ->
|
||||
if @isUnary()
|
||||
return @compileUnary o
|
||||
return @compileChain o if @isChainable() and @first.unwrap().isChainable()
|
||||
return @compileUnary o if @isUnary()
|
||||
return @compileChain o if @isChainable() and @first.isChainable()
|
||||
return @compileExistence o if @operator is '?'
|
||||
@first.tags.front = @tags.front
|
||||
"#{ @first.compile o, LEVEL_OP } #{@operator} #{ @second.compile o, LEVEL_OP }"
|
||||
@@ -1094,8 +1079,11 @@ exports.Op = class Op extends Base
|
||||
# bin/coffee -e 'console.log 50 < 65 > 10'
|
||||
# true
|
||||
compileChain: (o) ->
|
||||
[@first.second, shared] = @first.unwrap().second.cache o
|
||||
"#{ @first.compile o, LEVEL_OP } && #{ shared.compile o } #{@operator} #{ @second.compile o, LEVEL_OP }"
|
||||
[@first.second, shared] = @first.second.cache o
|
||||
fst = @first .compile o, LEVEL_OP
|
||||
fst = fst.slice 1, -1 if fst.charAt(0) is '('
|
||||
code = "#{fst} && #{ shared.compile o } #{@operator} #{ @second.compile o, LEVEL_OP }"
|
||||
if o.level < LEVEL_OP then code else "(#{code})"
|
||||
|
||||
compileExistence: (o) ->
|
||||
if @first.isComplex()
|
||||
@@ -1108,10 +1096,14 @@ exports.Op = class Op extends Base
|
||||
|
||||
# Compile a unary **Op**.
|
||||
compileUnary: (o) ->
|
||||
space = if @operator in @PREFIX_OPERATORS or @first instanceof Op and
|
||||
@first.operator is @operator and @operator in ['+', '-'] then ' ' else ''
|
||||
parts = [@operator, space, @first.compile(o, LEVEL_OP)]
|
||||
(if @flip then parts.reverse() else parts).join ''
|
||||
parts = [op = @operator]
|
||||
parts.push ' ' if op in ['new', 'typeof', 'delete'] or
|
||||
op in ['+', '-'] and @first instanceof Op and @first.operator is op
|
||||
parts.push @first.compile o, LEVEL_OP
|
||||
parts.reverse() if @flip
|
||||
parts.join ''
|
||||
|
||||
toString: (idt) -> super idt, @constructor.name + ' ' + @operator
|
||||
|
||||
#### In
|
||||
exports.In = class In extends Base
|
||||
|
||||
@@ -9,6 +9,10 @@ ok 10 < 20 > 10
|
||||
|
||||
ok 50 > 10 > 5 is parseInt('5', 10)
|
||||
|
||||
eq 1, 1 | 2 < 3 < 4
|
||||
|
||||
ok 1 == 1 <= 1, '`x == y <= z` should become `x === y && y <= z`'
|
||||
|
||||
i = 0
|
||||
ok 1 > i++ < 1, 'chained operations should evaluate each value only once'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user