diff --git a/documentation/index.html.erb b/documentation/index.html.erb index 83291904..915a08d9 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -854,7 +854,7 @@ print reverse 'tpircseeffoc' var source = document.getElementById('repl_source').value; var js = ''; try { - js = compile(source, {no_wrap: true}); + js = CoffeeScript.compile(source, {no_wrap: true}); } catch(error) { alert(error); } diff --git a/index.html b/index.html index 3b5f334e..2b6f9cd0 100644 --- a/index.html +++ b/index.html @@ -1725,7 +1725,7 @@ html = &q var source = document.getElementById('repl_source').value; var js = ''; try { - js = compile(source, {no_wrap: true}); + js = CoffeeScript.compile(source, {no_wrap: true}); } catch(error) { alert(error); } diff --git a/lib/coffee-script.js b/lib/coffee-script.js index 5c3c8f60..13706e5d 100644 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -1,15 +1,15 @@ (function(){ - var lexer, parser, path; + var exports, lexer, parser, path; // Set up for both the browser and the server. - if ((typeof process !== "undefined" && process !== null)) { + if ((typeof require !== "undefined" && require !== null)) { process.mixin(require('nodes')); path = require('path'); lexer = new (require('lexer').Lexer)(); parser = require('parser').parser; } else { - this.exports = this; + exports = (this.CoffeeScript = {}); lexer = new Lexer(); - parser = exports.parser; + parser = this.parser; } // Thin wrapper for Jison compatibility around the real lexer. parser.lexer = { diff --git a/lib/lexer.js b/lib/lexer.js index 2262216f..e1b237e5 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -1,9 +1,9 @@ (function(){ - var ACCESSORS, ASSIGNMENT, BEFORE_WHEN, CALLABLE, CODE, COMMENT, COMMENT_CLEANER, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS, JS_CLEANER, KEYWORDS, LAST_DENT, LAST_DENTS, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RESERVED, Rewriter, STRING, STRING_NEWLINES, WHITESPACE, lex; - if ((typeof process !== "undefined" && process !== null)) { + var ACCESSORS, ASSIGNMENT, BEFORE_WHEN, CALLABLE, CODE, COMMENT, COMMENT_CLEANER, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS, JS_CLEANER, KEYWORDS, LAST_DENT, LAST_DENTS, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RESERVED, Rewriter, STRING, STRING_NEWLINES, WHITESPACE, exports, lex; + if ((typeof require !== "undefined" && require !== null)) { Rewriter = require('./rewriter').Rewriter; } else { - this.exports = this; + exports = this; Rewriter = this.Rewriter; } // The lexer reads a stream of CoffeeScript and divvys it up into tagged diff --git a/lib/nodes.js b/lib/nodes.js index 623d6fb2..16f5449e 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1,7 +1,7 @@ (function(){ - var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, compact, del, flatten, inherit, merge, statement; + var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, compact, del, exports, flatten, inherit, merge, statement; var __hasProp = Object.prototype.hasOwnProperty; - (typeof process !== "undefined" && process !== null) ? process.mixin(require('scope')) : (this.exports = this); + (typeof require !== "undefined" && require !== null) ? process.mixin(require('scope')) : (exports = this); // Some helper functions // Tabs are two spaces for pretty printing. TAB = ' '; diff --git a/lib/rewriter.js b/lib/rewriter.js index 63414570..0b88ab6b 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -1,8 +1,8 @@ (function(){ - var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_START, EXPRESSION_TAIL, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, pair, re; + var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_START, EXPRESSION_TAIL, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, exports, pair, re; var __hasProp = Object.prototype.hasOwnProperty; - if (!((typeof process !== "undefined" && process !== null))) { - this.exports = this; + if (!((typeof require !== "undefined" && require !== null))) { + exports = this; } // In order to keep the grammar simple, the stream of tokens that the Lexer // emits is rewritten by the Rewriter, smoothing out ambiguities, mis-nested diff --git a/lib/scope.js b/lib/scope.js index 753e4dd8..55e28f57 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -1,8 +1,8 @@ (function(){ - var Scope; + var Scope, exports; var __hasProp = Object.prototype.hasOwnProperty; - if (!((typeof process !== "undefined" && process !== null))) { - this.exports = this; + if (!((typeof require !== "undefined" && require !== null))) { + exports = this; } // Scope objects form a tree corresponding to the shape of the function // definitions present in the script. They provide lexical scope, to determine diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index beeadd11..62bd20af 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -1,13 +1,13 @@ # Set up for both the browser and the server. -if process? +if require? process.mixin require 'nodes' path: require 'path' lexer: new (require('lexer').Lexer)() parser: require('parser').parser else - this.exports: this + exports: this.CoffeeScript: {} lexer: new Lexer() - parser: exports.parser + parser: this.parser # Thin wrapper for Jison compatibility around the real lexer. parser.lexer: { diff --git a/src/lexer.coffee b/src/lexer.coffee index ab45c4cb..386c23a3 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -1,7 +1,7 @@ -if process? +if require? Rewriter: require('./rewriter').Rewriter else - this.exports: this + exports: this Rewriter: this.Rewriter # The lexer reads a stream of CoffeeScript and divvys it up into tagged diff --git a/src/nodes.coffee b/src/nodes.coffee index 9f5b1412..31905cc0 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1,7 +1,7 @@ -if process? +if require? process.mixin require 'scope' else - this.exports: this + exports: this # Some helper functions diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 9f5e0f23..a30afea5 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -1,4 +1,4 @@ -this.exports: this unless process? +exports: this unless require? # In order to keep the grammar simple, the stream of tokens that the Lexer # emits is rewritten by the Rewriter, smoothing out ambiguities, mis-nested diff --git a/src/scope.coffee b/src/scope.coffee index 66465f5c..329f0c08 100644 --- a/src/scope.coffee +++ b/src/scope.coffee @@ -1,4 +1,4 @@ -this.exports: this unless process? +exports: this unless require? # Scope objects form a tree corresponding to the shape of the function # definitions present in the script. They provide lexical scope, to determine