Switching parenthesized side in comprehensions.

This commit is contained in:
Jeremy Ashkenas 2010-10-24 14:11:09 -04:00
parent b32a75858a
commit 6347849cd0
15 changed files with 19 additions and 21 deletions

View File

@ -42,7 +42,7 @@ task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options)
task 'build', 'build the CoffeeScript language from source', ->
files = fs.readdirSync 'src'
files = 'src/' + file for file in files when file.match(/\.coffee$/)
files = ('src/' + file for file in files when file.match(/\.coffee$/))
run ['-c', '-o', 'lib'].concat(files)

View File

@ -438,7 +438,7 @@
# Extend a given object with all of the properties in a source object.
_.extend = (obj) ->
for source in _.rest(arguments)
(obj[key] = val) for key, val of source
obj[key] = val for key, val of source
obj

View File

@ -120,7 +120,7 @@
if (o.watch) {
return console.log(err.message);
}
error(err.stack);
console.error(err.stack);
return process.exit(1);
}
};

View File

@ -596,7 +596,7 @@
})
]
};
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", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'POST_IF', 'POST_UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']];
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", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW', 'IF', 'UNLESS', 'POST_IF', 'POST_UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']];
tokens = [];
for (name in grammar) {
alternatives = grammar[name];

View File

@ -664,7 +664,7 @@
}
}
o.indent = this.idt(1);
nonComments = (function() {
nonComments = ((function() {
_ref3 = this.properties;
_result = [];
for (_i = 0, _len2 = _ref3.length; _i < _len2; _i++) {
@ -674,7 +674,7 @@
}
}
return _result;
}).call(this);
}).call(this));
lastNoncom = last(nonComments);
props = (function() {
_ref3 = this.properties;

View File

@ -21,7 +21,7 @@
console.log(inspect(val));
}
} catch (err) {
console.log(err.stack || err.toString());
console.error(err.stack || err.toString());
}
return repl.prompt();
};

View File

@ -300,7 +300,7 @@
}
return 1;
});
unclosed = (function() {
unclosed = ((function() {
_result = [];
for (key in levels) {
value = levels[key];
@ -309,7 +309,7 @@
}
}
return _result;
})();
})());
if (unclosed.length) {
throw Error("unclosed " + (open = unclosed[0]) + " on line " + (openLine[open] + 1));
}

View File

@ -109,12 +109,10 @@ compileScript = (file, input, base) ->
else if o.compile then writeJs t.file, t.output, base
else if o.lint then lint t.output
catch err
# Avoid using 'error' as it is a special event -- if there is no handler,
# node will print a stack trace and exit the program.
CoffeeScript.emit 'failure', err, task
return if CoffeeScript.listeners('failure').length
return console.log err.message if o.watch
error err.stack
console.error err.stack
process.exit 1
# Attach the appropriate listeners to compile scripts incoming over **stdin**,

View File

@ -1,2 +1,2 @@
# Loader for CoffeeScript as a Node.js library.
(exports[key] = val) for key, val of require './coffee-script'
exports[key] = val for key, val of require './coffee-script'

View File

@ -169,7 +169,7 @@ exports.Expressions = class Expressions extends Base
push: (node) ->
@expressions.push node
this
# Remove and return the last expression of this expression list.
pop: ->
@expressions.pop()
@ -578,7 +578,7 @@ exports.Obj = class Obj extends Base
for prop, i in @properties when (prop.variable or prop).base instanceof Parens
return @compileDynamic o, i
o.indent = @idt 1
nonComments = prop for prop in @properties when prop not instanceof Comment
nonComments = (prop for prop in @properties when prop not instanceof Comment)
lastNoncom = last nonComments
props = for prop, i in @properties
join = if i is @properties.length - 1

View File

@ -23,7 +23,7 @@ run = (buffer) ->
val = CoffeeScript.eval buffer.toString(), bare: on, globals: on, fileName: 'repl'
console.log inspect val if val isnt undefined
catch err
console.log err.stack or err.toString()
console.error err.stack or err.toString()
repl.prompt()
# Create the REPL by listening to **stdin**.

View File

@ -241,7 +241,7 @@ class exports.Rewriter
levels[open] -= 1
throw Error "too many #{token[1]} on line #{token[2] + 1}" if levels[open] < 0
1
unclosed = key for all key, value of levels when value > 0
unclosed = (key for all key, value of levels when value > 0)
if unclosed.length
throw Error "unclosed #{ open = unclosed[0] } on line #{openLine[open] + 1}"
@ -264,7 +264,7 @@ class exports.Rewriter
rewriteClosingParens: ->
stack = []
debt = {}
(debt[key] = 0) for all key of INVERSES
debt[key] = 0 for all key of INVERSES
@scanTokens (token, i, tokens) ->
if (tag = token[0]) in EXPRESSION_START
stack.push token

View File

@ -112,7 +112,7 @@ exports.Scope = class Scope
# Return the list of assignments that are supposed to be made at the top
# of this scope.
assignedVariables: ->
"#{v.name} = #{v.type.value}" for v in @variables when v.type.assigned
("#{v.name} = #{v.type.value}" for v in @variables when v.type.assigned)
# Compile the JavaScript for all of the variable declarations in this scope.
compiledDeclarations: ->

View File

@ -19,7 +19,7 @@ ok(area(
sumOfArgs = ->
sum = 0
(sum += val) for val in arguments
sum += val for val in arguments
sum
ok sumOfArgs(1, 2, 3, 4, 5) is 15

View File

@ -112,7 +112,7 @@ ok del() is 5
# Ensure that functions can have a trailing comma in their argument list
mult = (x, mids..., y) ->
(x *= n) for n in mids
x *= n for n in mids
x *= y
ok mult(1, 2,) is 2