mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
removing all of the 'type' tags from the Nodes. Simply using constructor.name instead.
This commit is contained in:
parent
2b578367a9
commit
aae2405de4
3 changed files with 26 additions and 80 deletions
|
@ -2,13 +2,13 @@
|
||||||
nodes are created as the result of actions in the <a href="grammar.html">grammar</a>,
|
nodes are created as the result of actions in the <a href="grammar.html">grammar</a>,
|
||||||
but some are created by other nodes as a method of code generation. To convert
|
but some are created by other nodes as a method of code generation. To convert
|
||||||
the syntax tree into a string of JavaScript code, call <code>compile()</code> on the root.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-2">#</a> </div> <p>Set up for both <strong>Node.js</strong> and the browser, by
|
the syntax tree into a string of JavaScript code, call <code>compile()</code> on the root.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-2">#</a> </div> <p>Set up for both <strong>Node.js</strong> and the browser, by
|
||||||
including the <a href="scope.html">Scope</a> class.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nx">process</span><span class="o">?</span>
|
including the <a href="scope.html">Scope</a> class and the <a href="helpers.html">helper</a> functions.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nx">process</span><span class="o">?</span>
|
||||||
<span class="nv">Scope: </span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./scope'</span><span class="p">).</span><span class="nx">Scope</span>
|
<span class="nv">Scope: </span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./scope'</span><span class="p">).</span><span class="nx">Scope</span>
|
||||||
<span class="nv">helpers: </span><span class="nx">require</span><span class="p">(</span><span class="s1">'./helpers'</span><span class="p">).</span><span class="nx">helpers</span>
|
<span class="nv">helpers: </span><span class="nx">require</span><span class="p">(</span><span class="s1">'./helpers'</span><span class="p">).</span><span class="nx">helpers</span>
|
||||||
<span class="k">else</span>
|
<span class="k">else</span>
|
||||||
<span class="k">this</span><span class="p">.</span><span class="nv">exports: </span><span class="k">this</span>
|
<span class="k">this</span><span class="p">.</span><span class="nv">exports: </span><span class="k">this</span>
|
||||||
<span class="nv">helpers: </span> <span class="k">this</span><span class="p">.</span><span class="nx">helpers</span>
|
<span class="nv">helpers: </span> <span class="k">this</span><span class="p">.</span><span class="nx">helpers</span>
|
||||||
<span class="nv">Scope: </span> <span class="k">this</span><span class="p">.</span><span class="nx">Scope</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <p>Import the helpers we need.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">compact: </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">compact</span>
|
<span class="nv">Scope: </span> <span class="k">this</span><span class="p">.</span><span class="nx">Scope</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <p>Import the helpers we plan to use.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">compact: </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">compact</span>
|
||||||
<span class="nv">flatten: </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">flatten</span>
|
<span class="nv">flatten: </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">flatten</span>
|
||||||
<span class="nv">merge: </span> <span class="nx">helpers</span><span class="p">.</span><span class="nx">merge</span>
|
<span class="nv">merge: </span> <span class="nx">helpers</span><span class="p">.</span><span class="nx">merge</span>
|
||||||
<span class="nv">del: </span> <span class="nx">helpers</span><span class="p">.</span><span class="nx">del</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</a> </div> <p>Helper function that marks a node as a JavaScript <em>statement</em>, or as a
|
<span class="nv">del: </span> <span class="nx">helpers</span><span class="p">.</span><span class="nx">del</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</a> </div> <p>Helper function that marks a node as a JavaScript <em>statement</em>, or as a
|
||||||
|
@ -926,7 +926,7 @@ in which case, no dice.</p> </td> <td class="code">
|
||||||
|
|
||||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-135"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-135">#</a> </div> <h2>Utility Functions</h2> </td> <td class="code"> <div class="highlight"><pre><span class="nv">UTILITIES: </span><span class="p">{</span></pre></div> </td> </tr> <tr id="section-136"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-136">#</a> </div> <p>Correctly set up a prototype chain for inheritance, including a reference
|
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-135"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-135">#</a> </div> <h2>Utility Functions</h2> </td> <td class="code"> <div class="highlight"><pre><span class="nv">UTILITIES: </span><span class="p">{</span></pre></div> </td> </tr> <tr id="section-136"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-136">#</a> </div> <p>Correctly set up a prototype chain for inheritance, including a reference
|
||||||
to the superclass for <code>super()</code> calls. See:
|
to the superclass for <code>super()</code> calls. See:
|
||||||
<a href="http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.source.html#line1206">goog.inherits</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">__extends: </span> <span class="s2">"""</span>
|
<a href="http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.source.html#line1206">goog.inherits</a>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">__extends: </span> <span class="s2">"""</span>
|
||||||
<span class="s2"> function(child, parent) {</span>
|
<span class="s2"> function(child, parent) {</span>
|
||||||
<span class="s2"> var ctor = function(){ };</span>
|
<span class="s2"> var ctor = function(){ };</span>
|
||||||
<span class="s2"> ctor.prototype = parent.prototype;</span>
|
<span class="s2"> ctor.prototype = parent.prototype;</span>
|
||||||
|
@ -935,21 +935,18 @@ to the superclass for <code>super()</code> calls. See:
|
||||||
<span class="s2"> child.prototype.constructor = child;</span>
|
<span class="s2"> child.prototype.constructor = child;</span>
|
||||||
<span class="s2"> }</span>
|
<span class="s2"> }</span>
|
||||||
<span class="s2"> """</span></pre></div> </td> </tr> <tr id="section-137"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-137">#</a> </div> <p>Bind a function to a calling context, optionally including curried arguments.
|
<span class="s2"> """</span></pre></div> </td> </tr> <tr id="section-137"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-137">#</a> </div> <p>Bind a function to a calling context, optionally including curried arguments.
|
||||||
See <a href="http://jashkenas.github.com/coffee-script/documentation/docs/underscore.html#section-47">Underscore's implementation</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">__bind: </span> <span class="s2">"""</span>
|
See <a href="http://jashkenas.github.com/coffee-script/documentation/docs/underscore.html#section-47">Underscore's implementation</a>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">__bind: </span> <span class="s2">"""</span>
|
||||||
<span class="s2"> function(func, obj, args) {</span>
|
<span class="s2"> function(func, obj, args) {</span>
|
||||||
<span class="s2"> return function() {</span>
|
<span class="s2"> return function() {</span>
|
||||||
<span class="s2"> return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);</span>
|
<span class="s2"> return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);</span>
|
||||||
<span class="s2"> };</span>
|
<span class="s2"> };</span>
|
||||||
<span class="s2"> }</span>
|
<span class="s2"> }</span>
|
||||||
<span class="s2"> """</span>
|
<span class="s2"> """</span></pre></div> </td> </tr> <tr id="section-138"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-138">#</a> </div> <p>Shortcuts to speed up the lookup time for native functions.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">__hasProp: </span><span class="s1">'Object.prototype.hasOwnProperty'</span>
|
||||||
|
<span class="nv">__slice: </span><span class="s1">'Array.prototype.slice'</span>
|
||||||
|
|
||||||
<span class="nx">__hasProp</span><span class="o">:</span><span class="s1">'Object.prototype.hasOwnProperty'</span>
|
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-139"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-139">#</a> </div> <h2>Constants</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-140"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-140">#</a> </div> <p>Tabs are two spaces for pretty printing.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">TAB: </span><span class="s1">' '</span></pre></div> </td> </tr> <tr id="section-141"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-141">#</a> </div> <p>Trim out all trailing whitespace, so that the generated code plays nice
|
||||||
|
with Git.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">TRAILING_WHITESPACE: </span><span class="sr">/\s+$/gm</span></pre></div> </td> </tr> <tr id="section-142"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-142">#</a> </div> <p>Keep this identifier regex in sync with the Lexer.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IDENTIFIER: </span><span class="sr">/^[a-zA-Z\$_](\w|\$)*$/</span></pre></div> </td> </tr> <tr id="section-143"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-143">#</a> </div> <h2>Utility Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-144"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-144">#</a> </div> <p>Handy helper for a generating LiteralNode.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">literal: </span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
|
||||||
<span class="nv">__slice: </span> <span class="s1">'Array.prototype.slice'</span>
|
<span class="k">new</span> <span class="nx">LiteralNode</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-145"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-145">#</a> </div> <p>Helper for ensuring that utility functions are assigned at the top level.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">utility: </span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
|
||||||
|
|
||||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-138"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-138">#</a> </div> <h2>Constants</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-139"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-139">#</a> </div> <p>Tabs are two spaces for pretty printing.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">TAB: </span><span class="s1">' '</span></pre></div> </td> </tr> <tr id="section-140"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-140">#</a> </div> <p>Trim out all trailing whitespace, so that the generated code plays nice
|
|
||||||
with Git.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">TRAILING_WHITESPACE: </span><span class="sr">/\s+$/gm</span></pre></div> </td> </tr> <tr id="section-141"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-141">#</a> </div> <p>Keep this identifier regex in sync with the Lexer.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IDENTIFIER: </span><span class="sr">/^[a-zA-Z\$_](\w|\$)*$/</span></pre></div> </td> </tr> <tr id="section-142"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-142">#</a> </div> <h2>Utility Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-143"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-143">#</a> </div> <p>Handy helper for a generating LiteralNode.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">literal: </span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
|
|
||||||
<span class="k">new</span> <span class="nx">LiteralNode</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-144"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-144">#</a> </div> <p>Helper for ensuring that utility functions are assigned at the top level.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">utility: </span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
|
|
||||||
<span class="nv">ref: </span><span class="s2">"__$name"</span>
|
<span class="nv">ref: </span><span class="s2">"__$name"</span>
|
||||||
<span class="nx">Scope</span><span class="p">.</span><span class="nx">root</span><span class="p">.</span><span class="nx">assign</span> <span class="nx">ref</span><span class="p">,</span> <span class="nx">UTILITIES</span><span class="p">[</span><span class="nx">ref</span><span class="p">]</span>
|
<span class="nx">Scope</span><span class="p">.</span><span class="nx">root</span><span class="p">.</span><span class="nx">assign</span> <span class="nx">ref</span><span class="p">,</span> <span class="nx">UTILITIES</span><span class="p">[</span><span class="nx">ref</span><span class="p">]</span>
|
||||||
<span class="nx">ref</span>
|
<span class="nx">ref</span>
|
||||||
|
|
39
lib/nodes.js
39
lib/nodes.js
|
@ -16,7 +16,7 @@
|
||||||
// but some are created by other nodes as a method of code generation. To convert
|
// but some are created by other nodes as a method of code generation. To convert
|
||||||
// the syntax tree into a string of JavaScript code, call `compile()` on the root.
|
// the syntax tree into a string of JavaScript code, call `compile()` on the root.
|
||||||
// Set up for both **Node.js** and the browser, by
|
// Set up for both **Node.js** and the browser, by
|
||||||
// including the [Scope](scope.html) class.
|
// including the [Scope](scope.html) class and the [helper](helpers.html) functions.
|
||||||
if ((typeof process !== "undefined" && process !== null)) {
|
if ((typeof process !== "undefined" && process !== null)) {
|
||||||
Scope = require('./scope').Scope;
|
Scope = require('./scope').Scope;
|
||||||
helpers = require('./helpers').helpers;
|
helpers = require('./helpers').helpers;
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
helpers = this.helpers;
|
helpers = this.helpers;
|
||||||
Scope = this.Scope;
|
Scope = this.Scope;
|
||||||
}
|
}
|
||||||
// Import the helpers we need.
|
// Import the helpers we plan to use.
|
||||||
compact = helpers.compact;
|
compact = helpers.compact;
|
||||||
flatten = helpers.flatten;
|
flatten = helpers.flatten;
|
||||||
merge = helpers.merge;
|
merge = helpers.merge;
|
||||||
|
@ -158,7 +158,7 @@
|
||||||
BaseNode.prototype.toString = function toString(idt) {
|
BaseNode.prototype.toString = function toString(idt) {
|
||||||
var _a, _b, _c, _d, child;
|
var _a, _b, _c, _d, child;
|
||||||
idt = idt || '';
|
idt = idt || '';
|
||||||
return '\n' + idt + this.type + (function() {
|
return '\n' + idt + this.constructor.name + (function() {
|
||||||
_a = []; _c = this.children;
|
_a = []; _c = this.children;
|
||||||
for (_b = 0, _d = _c.length; _b < _d; _b++) {
|
for (_b = 0, _d = _c.length; _b < _d; _b++) {
|
||||||
child = _c[_b];
|
child = _c[_b];
|
||||||
|
@ -194,7 +194,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(Expressions, BaseNode);
|
__extends(Expressions, BaseNode);
|
||||||
Expressions.prototype.type = 'Expressions';
|
|
||||||
// Tack an expression on to the end of this expression list.
|
// Tack an expression on to the end of this expression list.
|
||||||
Expressions.prototype.push = function push(node) {
|
Expressions.prototype.push = function push(node) {
|
||||||
this.expressions.push(node);
|
this.expressions.push(node);
|
||||||
|
@ -322,7 +321,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(LiteralNode, BaseNode);
|
__extends(LiteralNode, BaseNode);
|
||||||
LiteralNode.prototype.type = 'Literal';
|
|
||||||
// Break and continue must be treated as pure statements -- they lose their
|
// Break and continue must be treated as pure statements -- they lose their
|
||||||
// meaning when wrapped in a closure.
|
// meaning when wrapped in a closure.
|
||||||
LiteralNode.prototype.is_statement = function is_statement() {
|
LiteralNode.prototype.is_statement = function is_statement() {
|
||||||
|
@ -349,7 +347,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ReturnNode, BaseNode);
|
__extends(ReturnNode, BaseNode);
|
||||||
ReturnNode.prototype.type = 'Return';
|
|
||||||
ReturnNode.prototype.top_sensitive = function top_sensitive() {
|
ReturnNode.prototype.top_sensitive = function top_sensitive() {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -377,7 +374,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ValueNode, BaseNode);
|
__extends(ValueNode, BaseNode);
|
||||||
ValueNode.prototype.type = 'Value';
|
|
||||||
ValueNode.prototype.SOAK = " == undefined ? undefined : ";
|
ValueNode.prototype.SOAK = " == undefined ? undefined : ";
|
||||||
// A **ValueNode** has a base and a list of property accesses.
|
// A **ValueNode** has a base and a list of property accesses.
|
||||||
// Add a property access to the list.
|
// Add a property access to the list.
|
||||||
|
@ -471,7 +467,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(CommentNode, BaseNode);
|
__extends(CommentNode, BaseNode);
|
||||||
CommentNode.prototype.type = 'Comment';
|
|
||||||
CommentNode.prototype.make_return = function make_return() {
|
CommentNode.prototype.make_return = function make_return() {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -494,7 +489,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(CallNode, BaseNode);
|
__extends(CallNode, BaseNode);
|
||||||
CallNode.prototype.type = 'Call';
|
|
||||||
// Tag this invocation as creating a new instance.
|
// Tag this invocation as creating a new instance.
|
||||||
CallNode.prototype.new_instance = function new_instance() {
|
CallNode.prototype.new_instance = function new_instance() {
|
||||||
this.is_new = true;
|
this.is_new = true;
|
||||||
|
@ -564,7 +558,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(CurryNode, CallNode);
|
__extends(CurryNode, CallNode);
|
||||||
CurryNode.prototype.type = 'Curry';
|
|
||||||
CurryNode.prototype.arguments = function arguments(o) {
|
CurryNode.prototype.arguments = function arguments(o) {
|
||||||
var _a, _b, _c, arg;
|
var _a, _b, _c, arg;
|
||||||
_b = this.args;
|
_b = this.args;
|
||||||
|
@ -594,7 +587,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ExtendsNode, BaseNode);
|
__extends(ExtendsNode, BaseNode);
|
||||||
ExtendsNode.prototype.type = 'Extends';
|
|
||||||
// Hooks one constructor into another's prototype chain.
|
// Hooks one constructor into another's prototype chain.
|
||||||
ExtendsNode.prototype.compile_node = function compile_node(o) {
|
ExtendsNode.prototype.compile_node = function compile_node(o) {
|
||||||
var ref;
|
var ref;
|
||||||
|
@ -615,7 +607,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(AccessorNode, BaseNode);
|
__extends(AccessorNode, BaseNode);
|
||||||
AccessorNode.prototype.type = 'Accessor';
|
|
||||||
AccessorNode.prototype.compile_node = function compile_node(o) {
|
AccessorNode.prototype.compile_node = function compile_node(o) {
|
||||||
var proto_part;
|
var proto_part;
|
||||||
proto_part = this.prototype ? 'prototype.' : '';
|
proto_part = this.prototype ? 'prototype.' : '';
|
||||||
|
@ -632,7 +623,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(IndexNode, BaseNode);
|
__extends(IndexNode, BaseNode);
|
||||||
IndexNode.prototype.type = 'Index';
|
|
||||||
IndexNode.prototype.compile_node = function compile_node(o) {
|
IndexNode.prototype.compile_node = function compile_node(o) {
|
||||||
var idx;
|
var idx;
|
||||||
idx = this.index.compile(o);
|
idx = this.index.compile(o);
|
||||||
|
@ -651,7 +641,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(RangeNode, BaseNode);
|
__extends(RangeNode, BaseNode);
|
||||||
RangeNode.prototype.type = 'Range';
|
|
||||||
// Compiles the range's source variables -- where it starts and where it ends.
|
// Compiles the range's source variables -- where it starts and where it ends.
|
||||||
RangeNode.prototype.compile_variables = function compile_variables(o) {
|
RangeNode.prototype.compile_variables = function compile_variables(o) {
|
||||||
var _a, _b, from, to;
|
var _a, _b, from, to;
|
||||||
|
@ -707,7 +696,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(SliceNode, BaseNode);
|
__extends(SliceNode, BaseNode);
|
||||||
SliceNode.prototype.type = 'Slice';
|
|
||||||
SliceNode.prototype.compile_node = function compile_node(o) {
|
SliceNode.prototype.compile_node = function compile_node(o) {
|
||||||
var from, plus_part, to;
|
var from, plus_part, to;
|
||||||
from = this.range.from.compile(o);
|
from = this.range.from.compile(o);
|
||||||
|
@ -725,7 +713,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ObjectNode, BaseNode);
|
__extends(ObjectNode, BaseNode);
|
||||||
ObjectNode.prototype.type = 'Object';
|
|
||||||
// All the mucking about with commas is to make sure that CommentNodes and
|
// All the mucking about with commas is to make sure that CommentNodes and
|
||||||
// AssignNodes get interleaved correctly, with no trailing commas or
|
// AssignNodes get interleaved correctly, with no trailing commas or
|
||||||
// commas affixed to comments.
|
// commas affixed to comments.
|
||||||
|
@ -775,7 +762,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ArrayNode, BaseNode);
|
__extends(ArrayNode, BaseNode);
|
||||||
ArrayNode.prototype.type = 'Array';
|
|
||||||
ArrayNode.prototype.compile_node = function compile_node(o) {
|
ArrayNode.prototype.compile_node = function compile_node(o) {
|
||||||
var _a, _b, code, ending, i, obj, objects;
|
var _a, _b, code, ending, i, obj, objects;
|
||||||
o.indent = this.idt(1);
|
o.indent = this.idt(1);
|
||||||
|
@ -809,7 +795,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ClassNode, BaseNode);
|
__extends(ClassNode, BaseNode);
|
||||||
ClassNode.prototype.type = 'Class';
|
|
||||||
// Initialize a **ClassNode** with its name, an optional superclass, and a
|
// Initialize a **ClassNode** with its name, an optional superclass, and a
|
||||||
// list of prototype property assignments.
|
// list of prototype property assignments.
|
||||||
ClassNode.prototype.make_return = function make_return() {
|
ClassNode.prototype.make_return = function make_return() {
|
||||||
|
@ -869,7 +854,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(AssignNode, BaseNode);
|
__extends(AssignNode, BaseNode);
|
||||||
AssignNode.prototype.type = 'Assign';
|
|
||||||
// Matchers for detecting prototype assignments.
|
// Matchers for detecting prototype assignments.
|
||||||
AssignNode.prototype.PROTO_ASSIGN = /^(\S+)\.prototype/;
|
AssignNode.prototype.PROTO_ASSIGN = /^(\S+)\.prototype/;
|
||||||
AssignNode.prototype.LEADING_DOT = /^\.(prototype\.)?/;
|
AssignNode.prototype.LEADING_DOT = /^\.(prototype\.)?/;
|
||||||
|
@ -993,7 +977,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(CodeNode, BaseNode);
|
__extends(CodeNode, BaseNode);
|
||||||
CodeNode.prototype.type = 'Code';
|
|
||||||
// Compilation creates a new scope unless explicitly asked to share with the
|
// Compilation creates a new scope unless explicitly asked to share with the
|
||||||
// outer scope. Handles splat parameters in the parameter list by peeking at
|
// outer scope. Handles splat parameters in the parameter list by peeking at
|
||||||
// the JavaScript `arguments` objects. If the function is bound with the `=>`
|
// the JavaScript `arguments` objects. If the function is bound with the `=>`
|
||||||
|
@ -1099,7 +1082,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(SplatNode, BaseNode);
|
__extends(SplatNode, BaseNode);
|
||||||
SplatNode.prototype.type = 'Splat';
|
|
||||||
SplatNode.prototype.compile_node = function compile_node(o) {
|
SplatNode.prototype.compile_node = function compile_node(o) {
|
||||||
var _a;
|
var _a;
|
||||||
if ((typeof (_a = this.index) !== "undefined" && _a !== null)) {
|
if ((typeof (_a = this.index) !== "undefined" && _a !== null)) {
|
||||||
|
@ -1170,7 +1152,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(WhileNode, BaseNode);
|
__extends(WhileNode, BaseNode);
|
||||||
WhileNode.prototype.type = 'While';
|
|
||||||
WhileNode.prototype.add_body = function add_body(body) {
|
WhileNode.prototype.add_body = function add_body(body) {
|
||||||
this.children.push((this.body = body));
|
this.children.push((this.body = body));
|
||||||
return this;
|
return this;
|
||||||
|
@ -1219,14 +1200,13 @@
|
||||||
// CoffeeScript operations into their JavaScript equivalents.
|
// CoffeeScript operations into their JavaScript equivalents.
|
||||||
exports.OpNode = (function() {
|
exports.OpNode = (function() {
|
||||||
OpNode = function OpNode(operator, first, second, flip) {
|
OpNode = function OpNode(operator, first, second, flip) {
|
||||||
this.type += ' ' + operator;
|
this.constructor.name += ' ' + operator;
|
||||||
this.children = compact([(this.first = first), (this.second = second)]);
|
this.children = compact([(this.first = first), (this.second = second)]);
|
||||||
this.operator = this.CONVERSIONS[operator] || operator;
|
this.operator = this.CONVERSIONS[operator] || operator;
|
||||||
this.flip = !!flip;
|
this.flip = !!flip;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(OpNode, BaseNode);
|
__extends(OpNode, BaseNode);
|
||||||
OpNode.prototype.type = 'Op';
|
|
||||||
// The map of conversions from CoffeeScript to JavaScript symbols.
|
// The map of conversions from CoffeeScript to JavaScript symbols.
|
||||||
OpNode.prototype.CONVERSIONS = {
|
OpNode.prototype.CONVERSIONS = {
|
||||||
'==': '===',
|
'==': '===',
|
||||||
|
@ -1327,7 +1307,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(TryNode, BaseNode);
|
__extends(TryNode, BaseNode);
|
||||||
TryNode.prototype.type = 'Try';
|
|
||||||
TryNode.prototype.make_return = function make_return() {
|
TryNode.prototype.make_return = function make_return() {
|
||||||
if (this.attempt) {
|
if (this.attempt) {
|
||||||
this.attempt = this.attempt.make_return();
|
this.attempt = this.attempt.make_return();
|
||||||
|
@ -1360,7 +1339,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ThrowNode, BaseNode);
|
__extends(ThrowNode, BaseNode);
|
||||||
ThrowNode.prototype.type = 'Throw';
|
|
||||||
// A **ThrowNode** is already a return, of sorts...
|
// A **ThrowNode** is already a return, of sorts...
|
||||||
ThrowNode.prototype.make_return = function make_return() {
|
ThrowNode.prototype.make_return = function make_return() {
|
||||||
return this;
|
return this;
|
||||||
|
@ -1381,7 +1359,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ExistenceNode, BaseNode);
|
__extends(ExistenceNode, BaseNode);
|
||||||
ExistenceNode.prototype.type = 'Existence';
|
|
||||||
ExistenceNode.prototype.compile_node = function compile_node(o) {
|
ExistenceNode.prototype.compile_node = function compile_node(o) {
|
||||||
return ExistenceNode.compile_test(o, this.expression);
|
return ExistenceNode.compile_test(o, this.expression);
|
||||||
};
|
};
|
||||||
|
@ -1416,7 +1393,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ParentheticalNode, BaseNode);
|
__extends(ParentheticalNode, BaseNode);
|
||||||
ParentheticalNode.prototype.type = 'Paren';
|
|
||||||
ParentheticalNode.prototype.is_statement = function is_statement() {
|
ParentheticalNode.prototype.is_statement = function is_statement() {
|
||||||
return this.expression.is_statement();
|
return this.expression.is_statement();
|
||||||
};
|
};
|
||||||
|
@ -1468,7 +1444,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(ForNode, BaseNode);
|
__extends(ForNode, BaseNode);
|
||||||
ForNode.prototype.type = 'For';
|
|
||||||
ForNode.prototype.top_sensitive = function top_sensitive() {
|
ForNode.prototype.top_sensitive = function top_sensitive() {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -1572,7 +1547,6 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(IfNode, BaseNode);
|
__extends(IfNode, BaseNode);
|
||||||
IfNode.prototype.type = 'If';
|
|
||||||
// Add a new *else* clause to this **IfNode**, or push it down to the bottom
|
// Add a new *else* clause to this **IfNode**, or push it down to the bottom
|
||||||
// of the chain recursively.
|
// of the chain recursively.
|
||||||
IfNode.prototype.push = function push(else_body) {
|
IfNode.prototype.push = function push(else_body) {
|
||||||
|
@ -1737,11 +1711,12 @@
|
||||||
UTILITIES = {
|
UTILITIES = {
|
||||||
// Correctly set up a prototype chain for inheritance, including a reference
|
// Correctly set up a prototype chain for inheritance, including a reference
|
||||||
// to the superclass for `super()` calls. See:
|
// to the superclass for `super()` calls. See:
|
||||||
// [goog.inherits](http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.source.html#line1206)
|
// [goog.inherits](http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.source.html#line1206).
|
||||||
__extends: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n }",
|
__extends: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n }",
|
||||||
// Bind a function to a calling context, optionally including curried arguments.
|
// Bind a function to a calling context, optionally including curried arguments.
|
||||||
// See [Underscore's implementation](http://jashkenas.github.com/coffee-script/documentation/docs/underscore.html#section-47)
|
// See [Underscore's implementation](http://jashkenas.github.com/coffee-script/documentation/docs/underscore.html#section-47).
|
||||||
__bind: "function(func, obj, args) {\n return function() {\n return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);\n };\n }",
|
__bind: "function(func, obj, args) {\n return function() {\n return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);\n };\n }",
|
||||||
|
// Shortcuts to speed up the lookup time for native functions.
|
||||||
__hasProp: 'Object.prototype.hasOwnProperty',
|
__hasProp: 'Object.prototype.hasOwnProperty',
|
||||||
__slice: 'Array.prototype.slice'
|
__slice: 'Array.prototype.slice'
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
# the syntax tree into a string of JavaScript code, call `compile()` on the root.
|
# the syntax tree into a string of JavaScript code, call `compile()` on the root.
|
||||||
|
|
||||||
# Set up for both **Node.js** and the browser, by
|
# Set up for both **Node.js** and the browser, by
|
||||||
# including the [Scope](scope.html) class.
|
# including the [Scope](scope.html) class and the [helper](helpers.html) functions.
|
||||||
if process?
|
if process?
|
||||||
Scope: require('./scope').Scope
|
Scope: require('./scope').Scope
|
||||||
helpers: require('./helpers').helpers
|
helpers: require('./helpers').helpers
|
||||||
|
@ -13,7 +13,7 @@ else
|
||||||
helpers: this.helpers
|
helpers: this.helpers
|
||||||
Scope: this.Scope
|
Scope: this.Scope
|
||||||
|
|
||||||
# Import the helpers we need.
|
# Import the helpers we plan to use.
|
||||||
compact: helpers.compact
|
compact: helpers.compact
|
||||||
flatten: helpers.flatten
|
flatten: helpers.flatten
|
||||||
merge: helpers.merge
|
merge: helpers.merge
|
||||||
|
@ -113,7 +113,7 @@ exports.BaseNode: class BaseNode
|
||||||
# This is what `coffee --nodes` prints out.
|
# This is what `coffee --nodes` prints out.
|
||||||
toString: (idt) ->
|
toString: (idt) ->
|
||||||
idt: or ''
|
idt: or ''
|
||||||
'\n' + idt + @type + (child.toString(idt + TAB) for child in @children).join('')
|
'\n' + idt + @constructor.name + (child.toString(idt + TAB) for child in @children).join('')
|
||||||
|
|
||||||
# Default implementations of the common node identification methods. Nodes
|
# Default implementations of the common node identification methods. Nodes
|
||||||
# will override these with custom logic, if needed.
|
# will override these with custom logic, if needed.
|
||||||
|
@ -129,7 +129,6 @@ exports.BaseNode: class BaseNode
|
||||||
# indented block of code -- the implementation of a function, a clause in an
|
# indented block of code -- the implementation of a function, a clause in an
|
||||||
# `if`, `switch`, or `try`, and so on...
|
# `if`, `switch`, or `try`, and so on...
|
||||||
exports.Expressions: class Expressions extends BaseNode
|
exports.Expressions: class Expressions extends BaseNode
|
||||||
type: 'Expressions'
|
|
||||||
|
|
||||||
constructor: (nodes) ->
|
constructor: (nodes) ->
|
||||||
@children: @expressions: compact flatten nodes or []
|
@children: @expressions: compact flatten nodes or []
|
||||||
|
@ -214,7 +213,6 @@ statement Expressions
|
||||||
# JavaScript without translation, such as: strings, numbers,
|
# JavaScript without translation, such as: strings, numbers,
|
||||||
# `true`, `false`, `null`...
|
# `true`, `false`, `null`...
|
||||||
exports.LiteralNode: class LiteralNode extends BaseNode
|
exports.LiteralNode: class LiteralNode extends BaseNode
|
||||||
type: 'Literal'
|
|
||||||
|
|
||||||
constructor: (value) ->
|
constructor: (value) ->
|
||||||
@value: value
|
@value: value
|
||||||
|
@ -238,7 +236,6 @@ exports.LiteralNode: class LiteralNode extends BaseNode
|
||||||
# A `return` is a *pure_statement* -- wrapping it in a closure wouldn't
|
# A `return` is a *pure_statement* -- wrapping it in a closure wouldn't
|
||||||
# make sense.
|
# make sense.
|
||||||
exports.ReturnNode: class ReturnNode extends BaseNode
|
exports.ReturnNode: class ReturnNode extends BaseNode
|
||||||
type: 'Return'
|
|
||||||
|
|
||||||
constructor: (expression) ->
|
constructor: (expression) ->
|
||||||
@children: [@expression: expression]
|
@children: [@expression: expression]
|
||||||
|
@ -260,7 +257,6 @@ statement ReturnNode, true
|
||||||
# A value, variable or literal or parenthesized, indexed or dotted into,
|
# A value, variable or literal or parenthesized, indexed or dotted into,
|
||||||
# or vanilla.
|
# or vanilla.
|
||||||
exports.ValueNode: class ValueNode extends BaseNode
|
exports.ValueNode: class ValueNode extends BaseNode
|
||||||
type: 'Value'
|
|
||||||
|
|
||||||
SOAK: " == undefined ? undefined : "
|
SOAK: " == undefined ? undefined : "
|
||||||
|
|
||||||
|
@ -335,7 +331,6 @@ exports.ValueNode: class ValueNode extends BaseNode
|
||||||
# CoffeeScript passes through comments as JavaScript comments at the
|
# CoffeeScript passes through comments as JavaScript comments at the
|
||||||
# same position.
|
# same position.
|
||||||
exports.CommentNode: class CommentNode extends BaseNode
|
exports.CommentNode: class CommentNode extends BaseNode
|
||||||
type: 'Comment'
|
|
||||||
|
|
||||||
constructor: (lines) ->
|
constructor: (lines) ->
|
||||||
@lines: lines
|
@lines: lines
|
||||||
|
@ -354,7 +349,6 @@ statement CommentNode
|
||||||
# Node for a function invocation. Takes care of converting `super()` calls into
|
# Node for a function invocation. Takes care of converting `super()` calls into
|
||||||
# calls against the prototype's function of the same name.
|
# calls against the prototype's function of the same name.
|
||||||
exports.CallNode: class CallNode extends BaseNode
|
exports.CallNode: class CallNode extends BaseNode
|
||||||
type: 'Call'
|
|
||||||
|
|
||||||
constructor: (variable, args) ->
|
constructor: (variable, args) ->
|
||||||
@is_new: false
|
@is_new: false
|
||||||
|
@ -406,7 +400,6 @@ exports.CallNode: class CallNode extends BaseNode
|
||||||
# returning the bound function. After ECMAScript 5, Prototype.js, and
|
# returning the bound function. After ECMAScript 5, Prototype.js, and
|
||||||
# Underscore's `bind` functions.
|
# Underscore's `bind` functions.
|
||||||
exports.CurryNode: class CurryNode extends CallNode
|
exports.CurryNode: class CurryNode extends CallNode
|
||||||
type: 'Curry'
|
|
||||||
|
|
||||||
constructor: (meth, args) ->
|
constructor: (meth, args) ->
|
||||||
@children: flatten [@meth: meth, @context: args[0], @args: (args.slice(1) or [])]
|
@children: flatten [@meth: meth, @context: args[0], @args: (args.slice(1) or [])]
|
||||||
|
@ -429,7 +422,6 @@ exports.CurryNode: class CurryNode extends CallNode
|
||||||
# After `goog.inherits` from the
|
# After `goog.inherits` from the
|
||||||
# [Closure Library](http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.html).
|
# [Closure Library](http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.html).
|
||||||
exports.ExtendsNode: class ExtendsNode extends BaseNode
|
exports.ExtendsNode: class ExtendsNode extends BaseNode
|
||||||
type: 'Extends'
|
|
||||||
|
|
||||||
constructor: (child, parent) ->
|
constructor: (child, parent) ->
|
||||||
@children: [@child: child, @parent: parent]
|
@children: [@child: child, @parent: parent]
|
||||||
|
@ -444,11 +436,10 @@ exports.ExtendsNode: class ExtendsNode extends BaseNode
|
||||||
# A `.` accessor into a property of a value, or the `::` shorthand for
|
# A `.` accessor into a property of a value, or the `::` shorthand for
|
||||||
# an accessor into the object's prototype.
|
# an accessor into the object's prototype.
|
||||||
exports.AccessorNode: class AccessorNode extends BaseNode
|
exports.AccessorNode: class AccessorNode extends BaseNode
|
||||||
type: 'Accessor'
|
|
||||||
|
|
||||||
constructor: (name, tag) ->
|
constructor: (name, tag) ->
|
||||||
@children: [@name: name]
|
@children: [@name: name]
|
||||||
@prototype: tag is 'prototype'
|
@prototype:tag is 'prototype'
|
||||||
@soak_node: tag is 'soak'
|
@soak_node: tag is 'soak'
|
||||||
this
|
this
|
||||||
|
|
||||||
|
@ -460,7 +451,6 @@ exports.AccessorNode: class AccessorNode extends BaseNode
|
||||||
|
|
||||||
# A `[ ... ]` indexed accessor into an array or object.
|
# A `[ ... ]` indexed accessor into an array or object.
|
||||||
exports.IndexNode: class IndexNode extends BaseNode
|
exports.IndexNode: class IndexNode extends BaseNode
|
||||||
type: 'Index'
|
|
||||||
|
|
||||||
constructor: (index, tag) ->
|
constructor: (index, tag) ->
|
||||||
@children: [@index: index]
|
@children: [@index: index]
|
||||||
|
@ -476,7 +466,6 @@ exports.IndexNode: class IndexNode extends BaseNode
|
||||||
# to specify a range for comprehensions, or as a value, to be expanded into the
|
# to specify a range for comprehensions, or as a value, to be expanded into the
|
||||||
# corresponding array of integers at runtime.
|
# corresponding array of integers at runtime.
|
||||||
exports.RangeNode: class RangeNode extends BaseNode
|
exports.RangeNode: class RangeNode extends BaseNode
|
||||||
type: 'Range'
|
|
||||||
|
|
||||||
constructor: (from, to, exclusive) ->
|
constructor: (from, to, exclusive) ->
|
||||||
@children: [@from: from, @to: to]
|
@children: [@from: from, @to: to]
|
||||||
|
@ -518,7 +507,6 @@ exports.RangeNode: class RangeNode extends BaseNode
|
||||||
# specifies the index of the end of the slice, just as the first parameter
|
# specifies the index of the end of the slice, just as the first parameter
|
||||||
# is the index of the beginning.
|
# is the index of the beginning.
|
||||||
exports.SliceNode: class SliceNode extends BaseNode
|
exports.SliceNode: class SliceNode extends BaseNode
|
||||||
type: 'Slice'
|
|
||||||
|
|
||||||
constructor: (range) ->
|
constructor: (range) ->
|
||||||
@children: [@range: range]
|
@children: [@range: range]
|
||||||
|
@ -534,7 +522,6 @@ exports.SliceNode: class SliceNode extends BaseNode
|
||||||
|
|
||||||
# An object literal, nothing fancy.
|
# An object literal, nothing fancy.
|
||||||
exports.ObjectNode: class ObjectNode extends BaseNode
|
exports.ObjectNode: class ObjectNode extends BaseNode
|
||||||
type: 'Object'
|
|
||||||
|
|
||||||
constructor: (props) ->
|
constructor: (props) ->
|
||||||
@children: @objects: @properties: props or []
|
@children: @objects: @properties: props or []
|
||||||
|
@ -562,7 +549,6 @@ exports.ObjectNode: class ObjectNode extends BaseNode
|
||||||
|
|
||||||
# An array literal.
|
# An array literal.
|
||||||
exports.ArrayNode: class ArrayNode extends BaseNode
|
exports.ArrayNode: class ArrayNode extends BaseNode
|
||||||
type: 'Array'
|
|
||||||
|
|
||||||
constructor: (objects) ->
|
constructor: (objects) ->
|
||||||
@children: @objects: objects or []
|
@children: @objects: objects or []
|
||||||
|
@ -589,7 +575,6 @@ exports.ArrayNode: class ArrayNode extends BaseNode
|
||||||
|
|
||||||
# The CoffeeScript class definition.
|
# The CoffeeScript class definition.
|
||||||
exports.ClassNode: class ClassNode extends BaseNode
|
exports.ClassNode: class ClassNode extends BaseNode
|
||||||
type: 'Class'
|
|
||||||
|
|
||||||
# Initialize a **ClassNode** with its name, an optional superclass, and a
|
# Initialize a **ClassNode** with its name, an optional superclass, and a
|
||||||
# list of prototype property assignments.
|
# list of prototype property assignments.
|
||||||
|
@ -645,7 +630,6 @@ statement ClassNode
|
||||||
# The **AssignNode** is used to assign a local variable to value, or to set the
|
# The **AssignNode** is used to assign a local variable to value, or to set the
|
||||||
# property of an object -- including within object literals.
|
# property of an object -- including within object literals.
|
||||||
exports.AssignNode: class AssignNode extends BaseNode
|
exports.AssignNode: class AssignNode extends BaseNode
|
||||||
type: 'Assign'
|
|
||||||
|
|
||||||
# Matchers for detecting prototype assignments.
|
# Matchers for detecting prototype assignments.
|
||||||
PROTO_ASSIGN: /^(\S+)\.prototype/
|
PROTO_ASSIGN: /^(\S+)\.prototype/
|
||||||
|
@ -735,7 +719,6 @@ exports.AssignNode: class AssignNode extends BaseNode
|
||||||
# When for the purposes of walking the contents of a function body, the CodeNode
|
# When for the purposes of walking the contents of a function body, the CodeNode
|
||||||
# has no *children* -- they're within the inner scope.
|
# has no *children* -- they're within the inner scope.
|
||||||
exports.CodeNode: class CodeNode extends BaseNode
|
exports.CodeNode: class CodeNode extends BaseNode
|
||||||
type: 'Code'
|
|
||||||
|
|
||||||
constructor: (params, body, tag) ->
|
constructor: (params, body, tag) ->
|
||||||
@params: params or []
|
@params: params or []
|
||||||
|
@ -804,7 +787,6 @@ exports.CodeNode: class CodeNode extends BaseNode
|
||||||
# A splat, either as a parameter to a function, an argument to a call,
|
# A splat, either as a parameter to a function, an argument to a call,
|
||||||
# or as part of a destructuring assignment.
|
# or as part of a destructuring assignment.
|
||||||
exports.SplatNode: class SplatNode extends BaseNode
|
exports.SplatNode: class SplatNode extends BaseNode
|
||||||
type: 'Splat'
|
|
||||||
|
|
||||||
constructor: (name) ->
|
constructor: (name) ->
|
||||||
name: literal(name) unless name.compile
|
name: literal(name) unless name.compile
|
||||||
|
@ -857,7 +839,6 @@ exports.SplatNode: class SplatNode extends BaseNode
|
||||||
# it, all other loops can be manufactured. Useful in cases where you need more
|
# it, all other loops can be manufactured. Useful in cases where you need more
|
||||||
# flexibility or more speed than a comprehension can provide.
|
# flexibility or more speed than a comprehension can provide.
|
||||||
exports.WhileNode: class WhileNode extends BaseNode
|
exports.WhileNode: class WhileNode extends BaseNode
|
||||||
type: 'While'
|
|
||||||
|
|
||||||
constructor: (condition, opts) ->
|
constructor: (condition, opts) ->
|
||||||
@children:[@condition: condition]
|
@children:[@condition: condition]
|
||||||
|
@ -903,7 +884,6 @@ statement WhileNode
|
||||||
# Simple Arithmetic and logical operations. Performs some conversion from
|
# Simple Arithmetic and logical operations. Performs some conversion from
|
||||||
# CoffeeScript operations into their JavaScript equivalents.
|
# CoffeeScript operations into their JavaScript equivalents.
|
||||||
exports.OpNode: class OpNode extends BaseNode
|
exports.OpNode: class OpNode extends BaseNode
|
||||||
type: 'Op'
|
|
||||||
|
|
||||||
# The map of conversions from CoffeeScript to JavaScript symbols.
|
# The map of conversions from CoffeeScript to JavaScript symbols.
|
||||||
CONVERSIONS: {
|
CONVERSIONS: {
|
||||||
|
@ -922,7 +902,7 @@ exports.OpNode: class OpNode extends BaseNode
|
||||||
PREFIX_OPERATORS: ['typeof', 'delete']
|
PREFIX_OPERATORS: ['typeof', 'delete']
|
||||||
|
|
||||||
constructor: (operator, first, second, flip) ->
|
constructor: (operator, first, second, flip) ->
|
||||||
@type: + ' ' + operator
|
@constructor.name: + ' ' + operator
|
||||||
@children: compact [@first: first, @second: second]
|
@children: compact [@first: first, @second: second]
|
||||||
@operator: @CONVERSIONS[operator] or operator
|
@operator: @CONVERSIONS[operator] or operator
|
||||||
@flip: !!flip
|
@flip: !!flip
|
||||||
|
@ -979,7 +959,6 @@ exports.OpNode: class OpNode extends BaseNode
|
||||||
|
|
||||||
# A classic *try/catch/finally* block.
|
# A classic *try/catch/finally* block.
|
||||||
exports.TryNode: class TryNode extends BaseNode
|
exports.TryNode: class TryNode extends BaseNode
|
||||||
type: 'Try'
|
|
||||||
|
|
||||||
constructor: (attempt, error, recovery, ensure) ->
|
constructor: (attempt, error, recovery, ensure) ->
|
||||||
@children: compact [@attempt: attempt, @recovery: recovery, @ensure: ensure]
|
@children: compact [@attempt: attempt, @recovery: recovery, @ensure: ensure]
|
||||||
|
@ -1008,7 +987,6 @@ statement TryNode
|
||||||
|
|
||||||
# Simple node to throw an exception.
|
# Simple node to throw an exception.
|
||||||
exports.ThrowNode: class ThrowNode extends BaseNode
|
exports.ThrowNode: class ThrowNode extends BaseNode
|
||||||
type: 'Throw'
|
|
||||||
|
|
||||||
constructor: (expression) ->
|
constructor: (expression) ->
|
||||||
@children: [@expression: expression]
|
@children: [@expression: expression]
|
||||||
|
@ -1028,7 +1006,6 @@ statement ThrowNode
|
||||||
# similar to `.nil?` in Ruby, and avoids having to consult a JavaScript truth
|
# similar to `.nil?` in Ruby, and avoids having to consult a JavaScript truth
|
||||||
# table.
|
# table.
|
||||||
exports.ExistenceNode: class ExistenceNode extends BaseNode
|
exports.ExistenceNode: class ExistenceNode extends BaseNode
|
||||||
type: 'Existence'
|
|
||||||
|
|
||||||
constructor: (expression) ->
|
constructor: (expression) ->
|
||||||
@children: [@expression: expression]
|
@children: [@expression: expression]
|
||||||
|
@ -1054,7 +1031,6 @@ exports.ExistenceNode: class ExistenceNode extends BaseNode
|
||||||
#
|
#
|
||||||
# Parentheses are a good way to force any statement to become an expression.
|
# Parentheses are a good way to force any statement to become an expression.
|
||||||
exports.ParentheticalNode: class ParentheticalNode extends BaseNode
|
exports.ParentheticalNode: class ParentheticalNode extends BaseNode
|
||||||
type: 'Paren'
|
|
||||||
|
|
||||||
constructor: (expression) ->
|
constructor: (expression) ->
|
||||||
@children: [@expression: expression]
|
@children: [@expression: expression]
|
||||||
|
@ -1082,7 +1058,6 @@ exports.ParentheticalNode: class ParentheticalNode extends BaseNode
|
||||||
# the current index of the loop as a second parameter. Unlike Ruby blocks,
|
# the current index of the loop as a second parameter. Unlike Ruby blocks,
|
||||||
# you can map and filter in a single pass.
|
# you can map and filter in a single pass.
|
||||||
exports.ForNode: class ForNode extends BaseNode
|
exports.ForNode: class ForNode extends BaseNode
|
||||||
type: 'For'
|
|
||||||
|
|
||||||
constructor: (body, source, name, index) ->
|
constructor: (body, source, name, index) ->
|
||||||
@body: body
|
@body: body
|
||||||
|
@ -1163,7 +1138,6 @@ statement ForNode
|
||||||
# Single-expression **IfNodes** are compiled into ternary operators if possible,
|
# Single-expression **IfNodes** are compiled into ternary operators if possible,
|
||||||
# because ternaries are already proper expressions, and don't need conversion.
|
# because ternaries are already proper expressions, and don't need conversion.
|
||||||
exports.IfNode: class IfNode extends BaseNode
|
exports.IfNode: class IfNode extends BaseNode
|
||||||
type: 'If'
|
|
||||||
|
|
||||||
constructor: (condition, body, else_body, tags) ->
|
constructor: (condition, body, else_body, tags) ->
|
||||||
@condition: condition
|
@condition: condition
|
||||||
|
@ -1304,7 +1278,7 @@ UTILITIES: {
|
||||||
|
|
||||||
# Correctly set up a prototype chain for inheritance, including a reference
|
# Correctly set up a prototype chain for inheritance, including a reference
|
||||||
# to the superclass for `super()` calls. See:
|
# to the superclass for `super()` calls. See:
|
||||||
# [goog.inherits](http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.source.html#line1206)
|
# [goog.inherits](http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.source.html#line1206).
|
||||||
__extends: """
|
__extends: """
|
||||||
function(child, parent) {
|
function(child, parent) {
|
||||||
var ctor = function(){ };
|
var ctor = function(){ };
|
||||||
|
@ -1316,7 +1290,7 @@ UTILITIES: {
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Bind a function to a calling context, optionally including curried arguments.
|
# Bind a function to a calling context, optionally including curried arguments.
|
||||||
# See [Underscore's implementation](http://jashkenas.github.com/coffee-script/documentation/docs/underscore.html#section-47)
|
# See [Underscore's implementation](http://jashkenas.github.com/coffee-script/documentation/docs/underscore.html#section-47).
|
||||||
__bind: """
|
__bind: """
|
||||||
function(func, obj, args) {
|
function(func, obj, args) {
|
||||||
return function() {
|
return function() {
|
||||||
|
@ -1325,9 +1299,9 @@ UTILITIES: {
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__hasProp:'Object.prototype.hasOwnProperty'
|
# Shortcuts to speed up the lookup time for native functions.
|
||||||
|
__hasProp: 'Object.prototype.hasOwnProperty'
|
||||||
__slice: 'Array.prototype.slice'
|
__slice: 'Array.prototype.slice'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue