1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

changing 'filter' to 'guard' to get around Express' clobbering of Object.prototype.

This commit is contained in:
Jeremy Ashkenas 2010-04-28 21:46:47 -04:00
parent 502abade7c
commit 17ba44056e
5 changed files with 29 additions and 29 deletions

View file

@ -468,7 +468,7 @@
return new WhileNode($2);
}), o("WHILE Expression WHEN Expression", function() {
return new WhileNode($2, {
filter: $4
guard: $4
});
})
],
@ -514,7 +514,7 @@
return [$1, $3];
})
],
// The source of a comprehension is an array or object with an optional filter
// The source of a comprehension is an array or object with an optional guard
// clause. If it's an array comprehension, you can also choose to step through
// in fixed-size increments.
ForSource: [
@ -530,12 +530,12 @@
}), o("IN Expression WHEN Expression", function() {
return {
source: $2,
filter: $4
guard: $4
};
}), o("OF Expression WHEN Expression", function() {
return {
source: $2,
filter: $4,
guard: $4,
object: true
};
}), o("IN Expression BY Expression", function() {
@ -546,14 +546,14 @@
}), o("IN Expression WHEN Expression BY Expression", function() {
return {
source: $2,
filter: $4,
guard: $4,
step: $6
};
}), o("IN Expression BY Expression WHEN Expression", function() {
return {
source: $2,
step: $4,
filter: $6
guard: $6
};
})
],

View file

@ -1177,7 +1177,7 @@
exports.WhileNode = (function() {
WhileNode = function WhileNode(condition, opts) {
this.children = [(this.condition = condition)];
this.filter = opts && opts.filter;
this.guard = opts && opts.guard;
return this;
};
__extends(WhileNode, BaseNode);
@ -1213,8 +1213,8 @@
if (!this.body) {
return ("" + pre + " null;" + post);
}
if (this.filter) {
this.body = Expressions.wrap([new IfNode(this.filter, this.body)]);
if (this.guard) {
this.body = Expressions.wrap([new IfNode(this.guard, this.body)]);
}
this.returns ? (post = new ReturnNode(literal(rvar)).compile(merge(o, {
indent: this.idt()
@ -1460,7 +1460,7 @@
this.name = name;
this.index = index || null;
this.source = source.source;
this.filter = source.filter;
this.guard = source.guard;
this.step = source.step;
this.object = !!source.object;
if (this.object) {
@ -1472,7 +1472,7 @@
if (this.index instanceof ValueNode) {
throw new Error('index cannot be a pattern matching expression');
}
this.children = compact([this.body, this.source, this.filter]);
this.children = compact([this.body, this.source, this.guard]);
this.returns = false;
return this;
};
@ -1551,7 +1551,7 @@
if (!(top_level)) {
body = PushNode.wrap(rvar, body);
}
this.filter ? (body = Expressions.wrap([new IfNode(this.filter, body)])) : null;
this.guard ? (body = Expressions.wrap([new IfNode(this.guard, body)])) : null;
this.object ? (for_part = ("" + ivar + " in " + svar + ") { if (" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")")) : null;
body = body.compile(merge(o, {
indent: body_dent,

View file

@ -294,7 +294,7 @@ break;
case 139:this.$ = new WhileNode($$[$0-2+2-1]);
break;
case 140:this.$ = new WhileNode($$[$0-4+2-1], {
filter: $$[$0-4+4-1]
guard: $$[$0-4+4-1]
});
break;
case 141:this.$ = $$[$0-2+1-1].add_body($$[$0-2+2-1]);
@ -330,12 +330,12 @@ case 153:this.$ = {
break;
case 154:this.$ = {
source: $$[$0-4+2-1],
filter: $$[$0-4+4-1]
guard: $$[$0-4+4-1]
};
break;
case 155:this.$ = {
source: $$[$0-4+2-1],
filter: $$[$0-4+4-1],
guard: $$[$0-4+4-1],
object: true
};
break;
@ -346,14 +346,14 @@ case 156:this.$ = {
break;
case 157:this.$ = {
source: $$[$0-6+2-1],
filter: $$[$0-6+4-1],
guard: $$[$0-6+4-1],
step: $$[$0-6+6-1]
};
break;
case 158:this.$ = {
source: $$[$0-6+2-1],
step: $$[$0-6+4-1],
filter: $$[$0-6+6-1]
guard: $$[$0-6+6-1]
};
break;
case 159:this.$ = $$[$0-5+4-1].rewrite_condition($$[$0-5+2-1]);

View file

@ -413,7 +413,7 @@ grammar: {
# The condition portion of a while loop.
WhileSource: [
o "WHILE Expression", -> new WhileNode $2
o "WHILE Expression WHEN Expression", -> new WhileNode $2, {filter : $4}
o "WHILE Expression WHEN Expression", -> new WhileNode $2, {guard : $4}
]
# The while loop can either be normal, with a block of expressions to execute,
@ -449,17 +449,17 @@ grammar: {
o "ForValue , ForValue", -> [$1, $3]
]
# The source of a comprehension is an array or object with an optional filter
# The source of a comprehension is an array or object with an optional guard
# clause. If it's an array comprehension, you can also choose to step through
# in fixed-size increments.
ForSource: [
o "IN Expression", -> {source: $2}
o "OF Expression", -> {source: $2, object: true}
o "IN Expression WHEN Expression", -> {source: $2, filter: $4}
o "OF Expression WHEN Expression", -> {source: $2, filter: $4, object: true}
o "IN Expression WHEN Expression", -> {source: $2, guard: $4}
o "OF Expression WHEN Expression", -> {source: $2, guard: $4, object: true}
o "IN Expression BY Expression", -> {source: $2, step: $4}
o "IN Expression WHEN Expression BY Expression", -> {source: $2, filter: $4, step: $6}
o "IN Expression BY Expression WHEN Expression", -> {source: $2, step: $4, filter: $6}
o "IN Expression WHEN Expression BY Expression", -> {source: $2, guard: $4, step: $6}
o "IN Expression BY Expression WHEN Expression", -> {source: $2, step: $4, guard: $6}
]
# The CoffeeScript switch/when/else block replaces the JavaScript

View file

@ -856,7 +856,7 @@ exports.WhileNode: class WhileNode extends BaseNode
constructor: (condition, opts) ->
@children:[@condition: condition]
@filter: opts and opts.filter
@guard: opts and opts.guard
add_body: (body) ->
@children.push @body: body
@ -884,7 +884,7 @@ exports.WhileNode: class WhileNode extends BaseNode
@body: PushNode.wrap(rvar, @body) if @body
pre: "$set${@tab}while ($cond)"
return "$pre null;$post" if not @body
@body: Expressions.wrap([new IfNode(@filter, @body)]) if @filter
@body: Expressions.wrap([new IfNode(@guard, @body)]) if @guard
if @returns
post: new ReturnNode(literal(rvar)).compile(merge(o, {indent: @idt()}))
else
@ -1078,13 +1078,13 @@ exports.ForNode: class ForNode extends BaseNode
@name: name
@index: index or null
@source: source.source
@filter: source.filter
@guard: source.guard
@step: source.step
@object: !!source.object
[@name, @index]: [@index, @name] if @object
@pattern: @name instanceof ValueNode
throw new Error('index cannot be a pattern matching expression') if @index instanceof ValueNode
@children: compact [@body, @source, @filter]
@children: compact [@body, @source, @guard]
@returns: false
top_sensitive: ->
@ -1138,8 +1138,8 @@ exports.ForNode: class ForNode extends BaseNode
body: ClosureNode.wrap(body, true) if top_level and body.contains (n) -> n instanceof CodeNode
body: PushNode.wrap(rvar, body) unless top_level
if @filter
body: Expressions.wrap([new IfNode(@filter, body)])
if @guard
body: Expressions.wrap([new IfNode(@guard, body)])
if @object
for_part: "$ivar in $svar) { if (${utility('hasProp')}.call($svar, $ivar)"
body: body.compile(merge(o, {indent: body_dent, top: true}))