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:
parent
502abade7c
commit
17ba44056e
5 changed files with 29 additions and 29 deletions
|
@ -468,7 +468,7 @@
|
||||||
return new WhileNode($2);
|
return new WhileNode($2);
|
||||||
}), o("WHILE Expression WHEN Expression", function() {
|
}), o("WHILE Expression WHEN Expression", function() {
|
||||||
return new WhileNode($2, {
|
return new WhileNode($2, {
|
||||||
filter: $4
|
guard: $4
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
@ -514,7 +514,7 @@
|
||||||
return [$1, $3];
|
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
|
// clause. If it's an array comprehension, you can also choose to step through
|
||||||
// in fixed-size increments.
|
// in fixed-size increments.
|
||||||
ForSource: [
|
ForSource: [
|
||||||
|
@ -530,12 +530,12 @@
|
||||||
}), o("IN Expression WHEN Expression", function() {
|
}), o("IN Expression WHEN Expression", function() {
|
||||||
return {
|
return {
|
||||||
source: $2,
|
source: $2,
|
||||||
filter: $4
|
guard: $4
|
||||||
};
|
};
|
||||||
}), o("OF Expression WHEN Expression", function() {
|
}), o("OF Expression WHEN Expression", function() {
|
||||||
return {
|
return {
|
||||||
source: $2,
|
source: $2,
|
||||||
filter: $4,
|
guard: $4,
|
||||||
object: true
|
object: true
|
||||||
};
|
};
|
||||||
}), o("IN Expression BY Expression", function() {
|
}), o("IN Expression BY Expression", function() {
|
||||||
|
@ -546,14 +546,14 @@
|
||||||
}), o("IN Expression WHEN Expression BY Expression", function() {
|
}), o("IN Expression WHEN Expression BY Expression", function() {
|
||||||
return {
|
return {
|
||||||
source: $2,
|
source: $2,
|
||||||
filter: $4,
|
guard: $4,
|
||||||
step: $6
|
step: $6
|
||||||
};
|
};
|
||||||
}), o("IN Expression BY Expression WHEN Expression", function() {
|
}), o("IN Expression BY Expression WHEN Expression", function() {
|
||||||
return {
|
return {
|
||||||
source: $2,
|
source: $2,
|
||||||
step: $4,
|
step: $4,
|
||||||
filter: $6
|
guard: $6
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
12
lib/nodes.js
12
lib/nodes.js
|
@ -1177,7 +1177,7 @@
|
||||||
exports.WhileNode = (function() {
|
exports.WhileNode = (function() {
|
||||||
WhileNode = function WhileNode(condition, opts) {
|
WhileNode = function WhileNode(condition, opts) {
|
||||||
this.children = [(this.condition = condition)];
|
this.children = [(this.condition = condition)];
|
||||||
this.filter = opts && opts.filter;
|
this.guard = opts && opts.guard;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(WhileNode, BaseNode);
|
__extends(WhileNode, BaseNode);
|
||||||
|
@ -1213,8 +1213,8 @@
|
||||||
if (!this.body) {
|
if (!this.body) {
|
||||||
return ("" + pre + " null;" + post);
|
return ("" + pre + " null;" + post);
|
||||||
}
|
}
|
||||||
if (this.filter) {
|
if (this.guard) {
|
||||||
this.body = Expressions.wrap([new IfNode(this.filter, this.body)]);
|
this.body = Expressions.wrap([new IfNode(this.guard, this.body)]);
|
||||||
}
|
}
|
||||||
this.returns ? (post = new ReturnNode(literal(rvar)).compile(merge(o, {
|
this.returns ? (post = new ReturnNode(literal(rvar)).compile(merge(o, {
|
||||||
indent: this.idt()
|
indent: this.idt()
|
||||||
|
@ -1460,7 +1460,7 @@
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.index = index || null;
|
this.index = index || null;
|
||||||
this.source = source.source;
|
this.source = source.source;
|
||||||
this.filter = source.filter;
|
this.guard = source.guard;
|
||||||
this.step = source.step;
|
this.step = source.step;
|
||||||
this.object = !!source.object;
|
this.object = !!source.object;
|
||||||
if (this.object) {
|
if (this.object) {
|
||||||
|
@ -1472,7 +1472,7 @@
|
||||||
if (this.index instanceof ValueNode) {
|
if (this.index instanceof ValueNode) {
|
||||||
throw new Error('index cannot be a pattern matching expression');
|
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;
|
this.returns = false;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -1551,7 +1551,7 @@
|
||||||
if (!(top_level)) {
|
if (!(top_level)) {
|
||||||
body = PushNode.wrap(rvar, body);
|
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;
|
this.object ? (for_part = ("" + ivar + " in " + svar + ") { if (" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")")) : null;
|
||||||
body = body.compile(merge(o, {
|
body = body.compile(merge(o, {
|
||||||
indent: body_dent,
|
indent: body_dent,
|
||||||
|
|
|
@ -294,7 +294,7 @@ break;
|
||||||
case 139:this.$ = new WhileNode($$[$0-2+2-1]);
|
case 139:this.$ = new WhileNode($$[$0-2+2-1]);
|
||||||
break;
|
break;
|
||||||
case 140:this.$ = new WhileNode($$[$0-4+2-1], {
|
case 140:this.$ = new WhileNode($$[$0-4+2-1], {
|
||||||
filter: $$[$0-4+4-1]
|
guard: $$[$0-4+4-1]
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 141:this.$ = $$[$0-2+1-1].add_body($$[$0-2+2-1]);
|
case 141:this.$ = $$[$0-2+1-1].add_body($$[$0-2+2-1]);
|
||||||
|
@ -330,12 +330,12 @@ case 153:this.$ = {
|
||||||
break;
|
break;
|
||||||
case 154:this.$ = {
|
case 154:this.$ = {
|
||||||
source: $$[$0-4+2-1],
|
source: $$[$0-4+2-1],
|
||||||
filter: $$[$0-4+4-1]
|
guard: $$[$0-4+4-1]
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case 155:this.$ = {
|
case 155:this.$ = {
|
||||||
source: $$[$0-4+2-1],
|
source: $$[$0-4+2-1],
|
||||||
filter: $$[$0-4+4-1],
|
guard: $$[$0-4+4-1],
|
||||||
object: true
|
object: true
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
@ -346,14 +346,14 @@ case 156:this.$ = {
|
||||||
break;
|
break;
|
||||||
case 157:this.$ = {
|
case 157:this.$ = {
|
||||||
source: $$[$0-6+2-1],
|
source: $$[$0-6+2-1],
|
||||||
filter: $$[$0-6+4-1],
|
guard: $$[$0-6+4-1],
|
||||||
step: $$[$0-6+6-1]
|
step: $$[$0-6+6-1]
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case 158:this.$ = {
|
case 158:this.$ = {
|
||||||
source: $$[$0-6+2-1],
|
source: $$[$0-6+2-1],
|
||||||
step: $$[$0-6+4-1],
|
step: $$[$0-6+4-1],
|
||||||
filter: $$[$0-6+6-1]
|
guard: $$[$0-6+6-1]
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case 159:this.$ = $$[$0-5+4-1].rewrite_condition($$[$0-5+2-1]);
|
case 159:this.$ = $$[$0-5+4-1].rewrite_condition($$[$0-5+2-1]);
|
||||||
|
|
|
@ -413,7 +413,7 @@ grammar: {
|
||||||
# The condition portion of a while loop.
|
# The condition portion of a while loop.
|
||||||
WhileSource: [
|
WhileSource: [
|
||||||
o "WHILE Expression", -> new WhileNode $2
|
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,
|
# The while loop can either be normal, with a block of expressions to execute,
|
||||||
|
@ -449,17 +449,17 @@ grammar: {
|
||||||
o "ForValue , ForValue", -> [$1, $3]
|
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
|
# clause. If it's an array comprehension, you can also choose to step through
|
||||||
# in fixed-size increments.
|
# in fixed-size increments.
|
||||||
ForSource: [
|
ForSource: [
|
||||||
o "IN Expression", -> {source: $2}
|
o "IN Expression", -> {source: $2}
|
||||||
o "OF Expression", -> {source: $2, object: true}
|
o "OF Expression", -> {source: $2, object: true}
|
||||||
o "IN Expression WHEN Expression", -> {source: $2, filter: $4}
|
o "IN Expression WHEN Expression", -> {source: $2, guard: $4}
|
||||||
o "OF Expression WHEN Expression", -> {source: $2, filter: $4, object: true}
|
o "OF Expression WHEN Expression", -> {source: $2, guard: $4, object: true}
|
||||||
o "IN Expression BY Expression", -> {source: $2, step: $4}
|
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 WHEN Expression BY Expression", -> {source: $2, guard: $4, step: $6}
|
||||||
o "IN Expression BY Expression WHEN Expression", -> {source: $2, step: $4, filter: $6}
|
o "IN Expression BY Expression WHEN Expression", -> {source: $2, step: $4, guard: $6}
|
||||||
]
|
]
|
||||||
|
|
||||||
# The CoffeeScript switch/when/else block replaces the JavaScript
|
# The CoffeeScript switch/when/else block replaces the JavaScript
|
||||||
|
|
|
@ -856,7 +856,7 @@ exports.WhileNode: class WhileNode extends BaseNode
|
||||||
|
|
||||||
constructor: (condition, opts) ->
|
constructor: (condition, opts) ->
|
||||||
@children:[@condition: condition]
|
@children:[@condition: condition]
|
||||||
@filter: opts and opts.filter
|
@guard: opts and opts.guard
|
||||||
|
|
||||||
add_body: (body) ->
|
add_body: (body) ->
|
||||||
@children.push @body: body
|
@children.push @body: body
|
||||||
|
@ -884,7 +884,7 @@ exports.WhileNode: class WhileNode extends BaseNode
|
||||||
@body: PushNode.wrap(rvar, @body) if @body
|
@body: PushNode.wrap(rvar, @body) if @body
|
||||||
pre: "$set${@tab}while ($cond)"
|
pre: "$set${@tab}while ($cond)"
|
||||||
return "$pre null;$post" if not @body
|
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
|
if @returns
|
||||||
post: new ReturnNode(literal(rvar)).compile(merge(o, {indent: @idt()}))
|
post: new ReturnNode(literal(rvar)).compile(merge(o, {indent: @idt()}))
|
||||||
else
|
else
|
||||||
|
@ -1078,13 +1078,13 @@ exports.ForNode: class ForNode extends BaseNode
|
||||||
@name: name
|
@name: name
|
||||||
@index: index or null
|
@index: index or null
|
||||||
@source: source.source
|
@source: source.source
|
||||||
@filter: source.filter
|
@guard: source.guard
|
||||||
@step: source.step
|
@step: source.step
|
||||||
@object: !!source.object
|
@object: !!source.object
|
||||||
[@name, @index]: [@index, @name] if @object
|
[@name, @index]: [@index, @name] if @object
|
||||||
@pattern: @name instanceof ValueNode
|
@pattern: @name instanceof ValueNode
|
||||||
throw new Error('index cannot be a pattern matching expression') if @index 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
|
@returns: false
|
||||||
|
|
||||||
top_sensitive: ->
|
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: ClosureNode.wrap(body, true) if top_level and body.contains (n) -> n instanceof CodeNode
|
||||||
body: PushNode.wrap(rvar, body) unless top_level
|
body: PushNode.wrap(rvar, body) unless top_level
|
||||||
if @filter
|
if @guard
|
||||||
body: Expressions.wrap([new IfNode(@filter, body)])
|
body: Expressions.wrap([new IfNode(@guard, body)])
|
||||||
if @object
|
if @object
|
||||||
for_part: "$ivar in $svar) { if (${utility('hasProp')}.call($svar, $ivar)"
|
for_part: "$ivar in $svar) { if (${utility('hasProp')}.call($svar, $ivar)"
|
||||||
body: body.compile(merge(o, {indent: body_dent, top: true}))
|
body: body.compile(merge(o, {indent: body_dent, top: true}))
|
||||||
|
|
Loading…
Add table
Reference in a new issue