From 7efea4bb23dadebef78a733277ecbf9bd3e58d8a Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Fri, 29 Apr 2011 15:53:30 -0400 Subject: [PATCH] removed "globals" option of CoffeeScript.compile and enhanced fix from previous commits --- lib/coffee-script.js | 2 +- lib/nodes.js | 3 +-- lib/repl.js | 3 +-- src/coffee-script.coffee | 2 +- src/nodes.coffee | 3 +-- src/repl.coffee | 3 +-- test/compilation.coffee | 4 ++-- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/coffee-script.js b/lib/coffee-script.js index a1fe3476..378f5624 100755 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -79,7 +79,7 @@ global: {} }; for (g in global) { - sandbox[g] = global[g]; + sandbox.global[g] = global[g]; } sandbox.global.global = sandbox.global; sandbox.global.root = sandbox.global; diff --git a/lib/nodes.js b/lib/nodes.js index 55324041..ee158819 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -301,7 +301,7 @@ post = this.compileNode(o); scope = o.scope; if (scope.expressions === this) { - if (!o.globals && o.scope.hasDeclarations()) { + if (o.scope.hasDeclarations()) { code += "" + this.tab + "var " + (scope.declaredVariables().join(', ')) + ";\n"; } if (scope.hasAssignments) { @@ -1304,7 +1304,6 @@ o.scope.shared = del(o, 'sharedScope'); o.indent += TAB; delete o.bare; - delete o.globals; vars = []; exprs = []; _ref2 = this.params; diff --git a/lib/repl.js b/lib/repl.js index c7bc51c3..5ccb6da2 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -25,7 +25,7 @@ global: {} }; for (g in global) { - sandbox[g] = global[g]; + sandbox.global[g] = global[g]; } sandbox.global.global = sandbox.global; sandbox.global.root = sandbox.global; @@ -41,7 +41,6 @@ val = CoffeeScript.eval(code, { sandbox: sandbox, bare: true, - globals: true, filename: 'repl' }); if (val !== void 0) { diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index c63a1cc7..f2e6713f 100755 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -85,7 +85,7 @@ exports.eval = (code, options = {}) -> require: require module : { exports: {} } global : {} - sandbox[g] = global[g] for g of global + sandbox.global[g] = global[g] for g of global sandbox.global.global = sandbox.global sandbox.global.root = sandbox.global sandbox.global.GLOBAL = sandbox.global diff --git a/src/nodes.coffee b/src/nodes.coffee index f8cbf731..d7d78de6 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -250,7 +250,7 @@ exports.Block = class Block extends Base post = @compileNode o {scope} = o if scope.expressions is this - if not o.globals and o.scope.hasDeclarations() + if o.scope.hasDeclarations() code += "#{@tab}var #{ scope.declaredVariables().join(', ') };\n" if scope.hasAssignments code += "#{@tab}var #{ multident scope.assignedVariables().join(', '), @tab };\n" @@ -1048,7 +1048,6 @@ exports.Code = class Code extends Base o.scope.shared = del o, 'sharedScope' o.indent += TAB delete o.bare - delete o.globals vars = [] exprs = [] for param in @params when param.splat diff --git a/src/repl.coffee b/src/repl.coffee index 6731fa60..e4436b25 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -36,7 +36,7 @@ run = do -> require: require module : { exports: {} } global : {} - sandbox[g] = global[g] for g of global + sandbox.global[g] = global[g] for g of global sandbox.global.global = sandbox.global sandbox.global.root = sandbox.global sandbox.global.GLOBAL = sandbox.global @@ -49,7 +49,6 @@ run = do -> val = CoffeeScript.eval code, { sandbox, bare: on, - globals: on, filename: 'repl' } unless val is undefined diff --git a/test/compilation.coffee b/test/compilation.coffee index ab980cbd..6e4cba24 100644 --- a/test/compilation.coffee +++ b/test/compilation.coffee @@ -9,8 +9,8 @@ cantCompile = (code) -> test "ensure that carriage returns don't break compilation on Windows", -> doesNotThrow -> CoffeeScript.compile 'one\r\ntwo', bare: on -test "--bare and globals:on", -> - eq -1, CoffeeScript.compile('x = y', bare: on, globals: on).indexOf 'var' +test "--bare", -> + eq -1, CoffeeScript.compile('x = y', bare: on).indexOf 'function' ok 'passed' is CoffeeScript.eval '"passed"', bare: on, filename: 'test' test "multiple generated references", ->