From dec99506498de2e9d1fb1dfd029adb802f35bdf8 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Wed, 17 Feb 2010 23:22:05 -0500 Subject: [PATCH] Revert "namespacing CoffeeScript in the browser, and sniffing the 'require' function instead of the 'exports' object" This reverts commit 2f6b69b5800e489b24cc6c4efe080f673db7233b. --- documentation/index.html.erb | 2 +- index.html | 2 +- lib/coffee-script.js | 8 ++++---- lib/lexer.js | 6 +++--- lib/nodes.js | 4 ++-- lib/rewriter.js | 6 +++--- lib/scope.js | 6 +++--- src/coffee-script.coffee | 6 +++--- src/lexer.coffee | 4 ++-- src/nodes.coffee | 4 ++-- src/rewriter.coffee | 2 +- src/scope.coffee | 2 +- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/documentation/index.html.erb b/documentation/index.html.erb index 915a08d9..83291904 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 = CoffeeScript.compile(source, {no_wrap: true}); + js = compile(source, {no_wrap: true}); } catch(error) { alert(error); } diff --git a/index.html b/index.html index 2b6f9cd0..3b5f334e 100644 --- a/index.html +++ b/index.html @@ -1725,7 +1725,7 @@ html = &q var source = document.getElementById('repl_source').value; var js = ''; try { - js = CoffeeScript.compile(source, {no_wrap: true}); + js = compile(source, {no_wrap: true}); } catch(error) { alert(error); } diff --git a/lib/coffee-script.js b/lib/coffee-script.js index 13706e5d..5c3c8f60 100644 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -1,15 +1,15 @@ (function(){ - var exports, lexer, parser, path; + var lexer, parser, path; // Set up for both the browser and the server. - if ((typeof require !== "undefined" && require !== null)) { + if ((typeof process !== "undefined" && process !== null)) { process.mixin(require('nodes')); path = require('path'); lexer = new (require('lexer').Lexer)(); parser = require('parser').parser; } else { - exports = (this.CoffeeScript = {}); + this.exports = this; lexer = new Lexer(); - parser = this.parser; + parser = exports.parser; } // Thin wrapper for Jison compatibility around the real lexer. parser.lexer = { diff --git a/lib/lexer.js b/lib/lexer.js index e1b237e5..2262216f 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, exports, lex; - if ((typeof require !== "undefined" && require !== 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, lex; + if ((typeof process !== "undefined" && process !== null)) { Rewriter = require('./rewriter').Rewriter; } else { - exports = this; + 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 16f5449e..623d6fb2 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, exports, 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, flatten, inherit, merge, statement; var __hasProp = Object.prototype.hasOwnProperty; - (typeof require !== "undefined" && require !== null) ? process.mixin(require('scope')) : (exports = this); + (typeof process !== "undefined" && process !== null) ? process.mixin(require('scope')) : (this.exports = this); // Some helper functions // Tabs are two spaces for pretty printing. TAB = ' '; diff --git a/lib/rewriter.js b/lib/rewriter.js index 0b88ab6b..63414570 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, exports, 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, pair, re; var __hasProp = Object.prototype.hasOwnProperty; - if (!((typeof require !== "undefined" && require !== null))) { - exports = this; + if (!((typeof process !== "undefined" && process !== null))) { + this.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 55e28f57..753e4dd8 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -1,8 +1,8 @@ (function(){ - var Scope, exports; + var Scope; var __hasProp = Object.prototype.hasOwnProperty; - if (!((typeof require !== "undefined" && require !== null))) { - exports = this; + if (!((typeof process !== "undefined" && process !== null))) { + this.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 62bd20af..beeadd11 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 require? +if process? process.mixin require 'nodes' path: require 'path' lexer: new (require('lexer').Lexer)() parser: require('parser').parser else - exports: this.CoffeeScript: {} + this.exports: this lexer: new Lexer() - parser: this.parser + parser: exports.parser # Thin wrapper for Jison compatibility around the real lexer. parser.lexer: { diff --git a/src/lexer.coffee b/src/lexer.coffee index 386c23a3..ab45c4cb 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -1,7 +1,7 @@ -if require? +if process? Rewriter: require('./rewriter').Rewriter else - exports: this + 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 31905cc0..9f5b1412 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1,7 +1,7 @@ -if require? +if process? process.mixin require 'scope' else - exports: this + this.exports: this # Some helper functions diff --git a/src/rewriter.coffee b/src/rewriter.coffee index a30afea5..9f5e0f23 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -1,4 +1,4 @@ -exports: this unless require? +this.exports: this unless process? # 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 329f0c08..66465f5c 100644 --- a/src/scope.coffee +++ b/src/scope.coffee @@ -1,4 +1,4 @@ -exports: this unless require? +this.exports: this unless process? # Scope objects form a tree corresponding to the shape of the function # definitions present in the script. They provide lexical scope, to determine