mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
unary-new: built parser and new => now works
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
return new LiteralNode($1);
|
return new LiteralNode($1);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
Expression: [o("Value"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment")],
|
Expression: [o("Value"), o("Invocation"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment")],
|
||||||
Block: [
|
Block: [
|
||||||
o("INDENT Body OUTDENT", function() {
|
o("INDENT Body OUTDENT", function() {
|
||||||
return $2;
|
return $2;
|
||||||
|
|||||||
@@ -1125,7 +1125,7 @@
|
|||||||
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
||||||
func = ("function(" + (params.join(', ')) + ") {" + (code) + (code && this.tab) + "}");
|
func = ("function(" + (params.join(', ')) + ") {" + (code) + (code && this.tab) + "}");
|
||||||
if (this.bound) {
|
if (this.bound) {
|
||||||
return ("" + (utility('bind')) + "(" + (func) + ", " + (this.context) + ")");
|
return ("(" + (utility('bind')) + "(" + (func) + ", " + (this.context) + "))");
|
||||||
}
|
}
|
||||||
return top ? ("(" + (func) + ")") : func;
|
return top ? ("(" + (func) + ")") : func;
|
||||||
};
|
};
|
||||||
|
|||||||
246
lib/parser.js
246
lib/parser.js
File diff suppressed because one or more lines are too long
@@ -88,6 +88,7 @@ grammar =
|
|||||||
# them somewhat circular.
|
# them somewhat circular.
|
||||||
Expression: [
|
Expression: [
|
||||||
o "Value"
|
o "Value"
|
||||||
|
o "Invocation"
|
||||||
o "Code"
|
o "Code"
|
||||||
o "Operation"
|
o "Operation"
|
||||||
o "Assign"
|
o "Assign"
|
||||||
|
|||||||
@@ -947,7 +947,7 @@ exports.CodeNode = class CodeNode extends BaseNode
|
|||||||
(o.scope.parameter(param)) for param in params
|
(o.scope.parameter(param)) for param in params
|
||||||
code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else ''
|
code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else ''
|
||||||
func = "function(#{ params.join(', ') }) {#{code}#{ code and @tab }}"
|
func = "function(#{ params.join(', ') }) {#{code}#{ code and @tab }}"
|
||||||
return "#{utility('bind')}(#{func}, #{@context})" if @bound
|
return "(#{utility 'bind'}(#{func}, #{@context}))" if @bound
|
||||||
if top then "(#{func})" else func
|
if top then "(#{func})" else func
|
||||||
|
|
||||||
topSensitive: ->
|
topSensitive: ->
|
||||||
|
|||||||
@@ -257,4 +257,6 @@ new get() args...
|
|||||||
ok new Date().constructor is Date
|
ok new Date().constructor is Date
|
||||||
|
|
||||||
#717: `new` works against bare function
|
#717: `new` works against bare function
|
||||||
new -> ok @
|
me = this
|
||||||
|
new -> ok this isnt me
|
||||||
|
new => ok this is me
|
||||||
|
|||||||
Reference in New Issue
Block a user