diff --git a/lib/grammar.js b/lib/grammar.js index 43a4723f..8719090d 100644 --- a/lib/grammar.js +++ b/lib/grammar.js @@ -610,7 +610,8 @@ operators = [["left", '?'], ["nonassoc", 'UMINUS', 'UPLUS', '!', '!!', '~', '++', '--'], ["left", '*', '/', '%'], ["left", '+', '-'], ["left", '<<', '>>', '>>>'], ["left", '&', '|', '^'], ["left", '<=', '<', '>', '>='], ["right", 'DELETE', 'INSTANCEOF', 'TYPEOF'], ["left", '==', '!='], ["left", '&&', '||', 'OP?'], ["right", '-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?='], ["left", '.'], ["right", 'INDENT'], ["left", 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'NEW', 'SUPER', 'CLASS'], ["left", 'EXTENDS'], ["right", 'ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'IF', 'ELSE']]; tokens = []; _a = grammar; - for (name in _a) { if (__hasProp.call(_a, name)) { + for (name in _a) { + if (!__hasProp.call(_a, name)) continue; alternatives = _a[name]; grammar[name] = (function() { _b = []; _d = alternatives; @@ -632,7 +633,7 @@ } return _b; })(); - }} + } exports.parser = new Parser({ tokens: tokens.join(' '), bnf: grammar, diff --git a/lib/index.js b/lib/index.js index f7048dcc..8e014e91 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,8 +2,9 @@ var _a, key, val; var __hasProp = Object.prototype.hasOwnProperty; _a = require('./coffee-script'); - for (key in _a) { if (__hasProp.call(_a, key)) { + for (key in _a) { + if (!__hasProp.call(_a, key)) continue; val = _a[key]; (exports[key] = val); - }} + } })(); diff --git a/lib/nodes.js b/lib/nodes.js index fbda0569..b004d737 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1393,7 +1393,7 @@ return ''; }; ForNode.prototype.compileNode = function(o) { - var body, close, codeInBody, forPart, index, ivar, lvar, name, namePart, range, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars; + var body, codeInBody, forPart, guardPart, index, ivar, lvar, name, namePart, range, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars; topLevel = del(o, 'top') && !this.returns; range = this.source instanceof ValueNode && this.source.base instanceof RangeNode && !this.source.properties.length; source = range ? this.source.base : this.source; @@ -1422,6 +1422,7 @@ } })(); varPart = ''; + guardPart = ''; body = Expressions.wrap([this.body]); if (range) { sourcePart = source.compileVariables(o); @@ -1469,14 +1470,18 @@ } else { varPart = (namePart || '') && (this.pattern ? namePart : ("" + (this.idt(1)) + namePart + ";\n")); } - this.object ? this.raw ? (forPart = ("" + ivar + " in " + svar)) : (forPart = ("" + ivar + " in " + svar + ") { if (" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")")) : null; + if (this.object) { + forPart = ("" + ivar + " in " + svar); + if (!(this.raw)) { + guardPart = ("\n" + (this.idt(1)) + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;"); + } + } body = body.compile(merge(o, { indent: this.idt(1), top: true })); vars = range ? name : ("" + name + ", " + ivar); - close = this.object && !this.raw ? '}}' : '}'; - return "" + (sourcePart) + "for (" + forPart + ") {\n" + varPart + body + "\n" + this.tab + close + returnResult; + return "" + (sourcePart) + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + this.tab + "}" + returnResult; }; return ForNode; })(); diff --git a/lib/rewriter.js b/lib/rewriter.js index a563d8e1..2ec661ce 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -281,10 +281,11 @@ })(this)); unclosed = (function() { _c = []; _d = levels; - for (key in _d) { if (__hasProp.call(_d, key)) { + for (key in _d) { + if (!__hasProp.call(_d, key)) continue; value = _d[key]; value > 0 ? _c.push(key) : null; - }} + } return _c; })(); if (unclosed.length) { @@ -298,10 +299,11 @@ stack = []; debt = {}; _c = INVERSES; - for (key in _c) { if (__hasProp.call(_c, key)) { + for (key in _c) { + if (!__hasProp.call(_c, key)) continue; val = _c[key]; (debt[key] = 0); - }} + } return this.scanTokens((function(__this) { var __func = function(prev, token, post, i) { var inv, match, mtag, oppos, tag; diff --git a/lib/scope.js b/lib/scope.js index f1e6dd06..f299511f 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -31,12 +31,13 @@ Scope.prototype.any = function(fn) { var _a, k, v; _a = this.variables; - for (v in _a) { if (__hasProp.call(_a, v)) { + for (v in _a) { + if (!__hasProp.call(_a, v)) continue; k = _a[v]; if (fn(v, k)) { return true; } - }} + } return false; }; Scope.prototype.parameter = function(name) { @@ -79,20 +80,22 @@ var _a, _b, key, val; return (function() { _a = []; _b = this.variables; - for (key in _b) { if (__hasProp.call(_b, key)) { + for (key in _b) { + if (!__hasProp.call(_b, key)) continue; val = _b[key]; val === 'var' ? _a.push(key) : null; - }} + } return _a; }).call(this).sort(); }; Scope.prototype.assignedVariables = function() { var _a, _b, key, val; _a = []; _b = this.variables; - for (key in _b) { if (__hasProp.call(_b, key)) { + for (key in _b) { + if (!__hasProp.call(_b, key)) continue; val = _b[key]; val.assigned ? _a.push("" + key + " = " + val.value) : null; - }} + } return _a; }; Scope.prototype.compiledDeclarations = function() { diff --git a/src/nodes.coffee b/src/nodes.coffee index 687f0bf0..f39b4e2d 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1262,6 +1262,7 @@ exports.ForNode: class ForNode extends BaseNode rvar: scope.freeVariable() unless topLevel ivar: if range then name else if codeInBody then scope.freeVariable() else index or scope.freeVariable() varPart: '' + guardPart: '' body: Expressions.wrap([@body]) if range sourcePart: source.compileVariables(o) @@ -1292,14 +1293,11 @@ exports.ForNode: class ForNode extends BaseNode else varPart: (namePart or '') and (if @pattern then namePart else "${@idt(1)}$namePart;\n") if @object - if @raw - forPart: "$ivar in $svar" - else - forPart: "$ivar in $svar) { if (${utility('hasProp')}.call($svar, $ivar)" + forPart: "$ivar in $svar" + guardPart: "\n${@idt(1)}if (!${utility('hasProp')}.call($svar, $ivar)) continue;" unless @raw body: body.compile(merge(o, {indent: @idt(1), top: true})) vars: if range then name else "$name, $ivar" - close: if @object and not @raw then '}}' else '}' - "${sourcePart}for ($forPart) {\n$varPart$body\n$@tab$close$returnResult" + "${sourcePart}for ($forPart) {$guardPart\n$varPart$body\n$@tab}$returnResult" #### IfNode