Permalink
Browse files

Issue #856. Invert

  • Loading branch information...
1 parent 4afa6a2 commit c3f1820ebc862f275267dbe865ce02d5267213ec @jashkenas jashkenas committed Nov 28, 2010
View
@@ -147,7 +147,7 @@ runTests = (CoffeeScript) ->
startTime = Date.now()
passedTests = failedTests = 0
- for all name, func of require 'assert'
+ for name, func of require 'assert'
global[name] = ->
passedTests += 1
func arguments...
View
@@ -85,7 +85,7 @@ _.each = (obj, iterator, context) ->
else if _.isNumber obj.length
iterator.call context, obj[i], i, obj for i in [0...obj.length]
else
- iterator.call context, val, key, obj for key, val of obj
+ iterator.call context, val, key, obj for own key, val of obj
catch e
throw e if e isnt breaker
obj
@@ -176,8 +176,7 @@ _.some = (obj, iterator, context) ->
# based on `===`.
_.include = (obj, target) ->
return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf
- for key, val of obj
- return true if val is target
+ return true for own key, val of obj when val is target
false
@@ -486,14 +485,14 @@ _.isEqual = (a, b) ->
# Different object sizes?
return false if aKeys.length isnt bKeys.length
# Recursive comparison of contents.
- return false for all key, val of a when !(key of b) or !_.isEqual(val, b[key])
+ return false for key, val of a when !(key of b) or !_.isEqual(val, b[key])
true
# Is a given array or object empty?
_.isEmpty = (obj) ->
return obj.length is 0 if _.isArray(obj) or _.isString(obj)
- return false for key of obj when hasOwnProperty.call(obj, key)
+ return false for own key of obj
true
@@ -654,7 +653,7 @@ addToWrapper = (name, func) ->
result func.apply(_, args), this._chain
-# Add all of the Underscore functions to the wrapper object.
+# Add all ofthe Underscore functions to the wrapper object.
_.mixin _
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,9 +1,7 @@
(function() {
var key, val, _ref;
- var __hasProp = Object.prototype.hasOwnProperty;
_ref = require('./coffee-script');
for (key in _ref) {
- if (!__hasProp.call(_ref, key)) continue;
val = _ref[key];
exports[key] = val;
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -56,7 +56,7 @@ exports.run = ->
# Display the list of Cake tasks in a format similar to `rake -T`
printTasks = ->
console.log ''
- for all name, task of tasks
+ for name, task of tasks
spaces = 20 - name.length
spaces = if spaces > 0 then Array(spaces + 1).join(' ') else ''
desc = if task.description then "# #{task.description}" else ''
View
@@ -424,12 +424,12 @@ grammar =
ForBody: [
o 'FOR Range', -> source: new Value($2), vars: []
- o 'ForStart ForSource', -> $2.raw = $1.raw; $2.vars = $1; $2
+ o 'ForStart ForSource', -> $2.own = $1.own; $2.vars = $1; $2
]
ForStart: [
o 'FOR ForVariables', -> $2
- o 'FOR ALL ForVariables', -> $3.raw = yes; $3
+ o 'FOR OWN ForVariables', -> $3.own = yes; $3
]
# An array of all accepted values for a variable inside the loop.
@@ -577,7 +577,7 @@ operators = [
# terminals (every symbol which does not appear as the name of a rule above)
# as "tokens".
tokens = []
-for all name, alternatives of grammar
+for name, alternatives of grammar
grammar[name] = for alt in alternatives
for token in alt[0].split ' '
tokens.push token unless grammar[token]
View
@@ -29,7 +29,7 @@ exports.merge = (options, overrides) ->
# Extend a source object with the properties of another object (shallow copy).
extend = exports.extend = (object, properties) ->
- for all key, val of properties
+ for key, val of properties
object[key] = val
object
View
@@ -75,8 +75,8 @@ exports.Lexer = class Lexer
return 0 unless match = IDENTIFIER.exec @chunk
[input, id, colon] = match
- if id is 'all' and @tag() is 'FOR'
- @token 'ALL', id
+ if id is 'own' and @tag() is 'FOR'
+ @token 'OWN', id
return id.length
forcedIdentifier = colon or
(prev = last @tokens) and not prev.spaced and prev[0] in ['.', '?.', '@', '::']
@@ -499,7 +499,7 @@ JS_KEYWORDS = [
# CoffeeScript-only keywords.
COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when']
-COFFEE_KEYWORDS.push op for all op of COFFEE_ALIASES =
+COFFEE_KEYWORDS.push op for op of COFFEE_ALIASES =
and : '&&'
or : '||'
is : '=='
View
@@ -1374,7 +1374,7 @@ exports.For = class For extends Base
constructor: (body, source, @name, @index) ->
{@source, @guard, @step} = source
@body = Expressions.wrap [body]
- @raw = !!source.raw
+ @own = !!source.own
@object = !!source.object
[@name, @index] = [@index, @name] if @object
throw SyntaxError 'index cannot be a pattern matching expression' if @index instanceof Value
@@ -1418,7 +1418,7 @@ exports.For = class For extends Base
forPart = source.compile merge(o, {index: ivar, @step})
else
svar = @source.compile o, LEVEL_TOP
- if (name or not @raw) and not IDENTIFIER.test svar
+ if (name or @own) and not IDENTIFIER.test svar
defPart = "#{@tab}#{ref = scope.freeVariable 'ref'} = #{svar};\n"
svar = ref
namePart = if @pattern
@@ -1440,7 +1440,7 @@ exports.For = class For extends Base
varPart = "\n#{idt1}#{namePart};" if namePart
if @object
forPart = "#{ivar} in #{svar}"
- guardPart = "\n#{idt1}if (!#{utility('hasProp')}.call(#{svar}, #{ivar})) continue;" unless @raw
+ guardPart = "\n#{idt1}if (!#{utility('hasProp')}.call(#{svar}, #{ivar})) continue;" if @own
defPart += @pluckDirectCall o, body, name, index unless @pattern
body = body.compile merge(o, indent: idt1), LEVEL_TOP
body = '\n' + body + '\n' if body
View
@@ -217,7 +217,7 @@ class exports.Rewriter
openLine[open] = token[2] if levels[open]++ is 0
else if tag is close and --levels[open] < 0
throw Error "too many #{token[1]} on line #{token[2] + 1}"
- for all open, level of levels when level > 0
+ for open, level of levels when level > 0
throw Error "unclosed #{ open } on line #{openLine[open] + 1}"
this
@@ -240,7 +240,7 @@ class exports.Rewriter
rewriteClosingParens: ->
stack = []
debt = {}
- debt[key] = 0 for all key of INVERSES
+ debt[key] = 0 for key of INVERSES
@scanTokens (token, i, tokens) ->
if (tag = token[0]) in EXPRESSION_START
stack.push token
@@ -12,7 +12,7 @@ ok 'passed' is CoffeeScript.eval '"passed"', bare: on, fileName: 'test'
try ok not CoffeeScript.nodes 'f(->'
catch e then eq e.message, 'unclosed CALL_START on line 1'
-eq CoffeeScript.compile('for all k of o then', bare: on, globals: on),
+eq CoffeeScript.compile('for k of o then', bare: on, globals: on),
'for (k in o) {}'
#875: %d and %s in strings causes node.js to apply formatting
@@ -171,8 +171,8 @@ class Cat
hair: 'cream'
whiskers = new Cat
-own = (value for key, value of whiskers)
-all = (value for all key, value of whiskers)
+own = (value for own key, value of whiskers)
+all = (value for key, value of whiskers)
ok own.join(' ') is 'Whiskers'
ok all.sort().join(' ') is 'Whiskers cream tabby'

0 comments on commit c3f1820

Please sign in to comment.