diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index 54dd818c..8feaf58d 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.5.0 (function() { - var Lexer, baseFileName, compile, count, ext, extensions, fs, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, + var Lexer, baseFileName, compile, count, ext, extend, extensions, fs, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, _ref, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __hasProp = {}.hasOwnProperty; @@ -16,7 +16,7 @@ vm = require('vm'); - count = require('./helpers').count; + _ref = require('./helpers'), count = _ref.count, extend = _ref.extend; extensions = ['.coffee', '.litcoffee']; @@ -85,18 +85,23 @@ }; exports.compileWithSourceMap = function(code, options) { - var coffeeFile, js, jsFile, map, merge; + var coffeeFile, compiledJs, jsFile, merge, v3SourceMap; if (options == null) { options = {}; } merge = exports.helpers.merge; try { + options = extend({}, options); options.sourceMap = new sourcemap.SourceMap(); coffeeFile = path.basename(options.filename); jsFile = baseFileName(options.filename) + ".js"; - js = exports.compile(code, options); - map = sourcemap.generateV3SourceMap(options.sourceMap, coffeeFile, jsFile); - return [js, map]; + compiledJs = exports.compile(code, options); + v3SourceMap = sourcemap.generateV3SourceMap(options.sourceMap, coffeeFile, jsFile); + return { + compiledJs: compiledJs, + v3SourceMap: v3SourceMap, + sourceMap: options.sourceMap + }; } catch (err) { if (options.filename) { err.message = "In " + options.filename + ", " + err.message; @@ -118,7 +123,7 @@ }; exports.run = function(code, options) { - var mainModule, _ref; + var mainModule, _ref1; if (options == null) { options = {}; } @@ -126,7 +131,7 @@ mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.'; mainModule.moduleCache && (mainModule.moduleCache = {}); mainModule.paths = require('module')._nodeModulePaths(path.dirname(fs.realpathSync(options.filename))); - if ((_ref = path.extname(mainModule.filename), __indexOf.call(extensions, _ref) < 0) || require.extensions) { + if ((_ref1 = path.extname(mainModule.filename), __indexOf.call(extensions, _ref1) < 0) || require.extensions) { return mainModule._compile(compile(code, options), mainModule.filename); } else { return mainModule._compile(code, mainModule.filename); @@ -134,7 +139,7 @@ }; exports["eval"] = function(code, options) { - var Module, Script, js, k, o, r, sandbox, v, _j, _len1, _module, _ref, _ref1, _require; + var Module, Script, js, k, o, r, sandbox, v, _j, _len1, _module, _ref1, _ref2, _require; if (options == null) { options = {}; } @@ -148,10 +153,10 @@ sandbox = options.sandbox; } else { sandbox = Script.createContext(); - _ref = options.sandbox; - for (k in _ref) { - if (!__hasProp.call(_ref, k)) continue; - v = _ref[k]; + _ref1 = options.sandbox; + for (k in _ref1) { + if (!__hasProp.call(_ref1, k)) continue; + v = _ref1[k]; sandbox[k] = v; } } @@ -168,9 +173,9 @@ return Module._load(path, _module, true); }; _module.filename = sandbox.__filename; - _ref1 = Object.getOwnPropertyNames(require); - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - r = _ref1[_j]; + _ref2 = Object.getOwnPropertyNames(require); + for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { + r = _ref2[_j]; if (r !== 'paths') { _require[r] = require[r]; } diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index bb83ee71..98509092 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -152,7 +152,7 @@ }; compileScript = function(file, input, base) { - var o, options, t, task, _ref1; + var compiled, o, options, t, task; o = opts; options = compileOptions(file); try { @@ -173,7 +173,9 @@ return compileJoin(); } else { if (o.maps) { - _ref1 = CoffeeScript.compileWithSourceMap(t.input, t.options), t.output = _ref1[0], t.sourceMap = _ref1[1]; + compiled = CoffeeScript.compileWithSourceMap(t.input, t.options); + t.output = compiled.compiledJs; + t.sourceMap = compiled.v3SourceMap; } else { t.output = CoffeeScript.compile(t.input, t.options); } diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 44ae9a1d..d7c4700c 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -12,7 +12,7 @@ path = require 'path' {parser} = require './parser' sourcemap = require './sourcemap' vm = require 'vm' -{count} = require './helpers' +{count, extend} = require './helpers' # The file extensions that are considered to be CoffeeScript. extensions = ['.coffee', '.litcoffee'] @@ -70,17 +70,23 @@ exports.compile = compile = (code, options = {}) -> "// #{header}\n#{js}" # Generates a compiled code and a source map for a string of CoffeeScript code. -# Callers should specifiy `options.filename`. Returns a `[sourcemap, compiledCode]` pair, where -# sourcemap is a v3 source map. +# Callers should specifiy `options.filename`. Returns a `{compiledJs, v3SourceMap, sourceMap} +# object, where sourceMap is a sourcemap.coffee#SourceMap object, handy for doing programatic +# lookups. exports.compileWithSourceMap = (code, options={}) -> {merge} = exports.helpers try + options = extend {}, options options.sourceMap = new sourcemap.SourceMap() coffeeFile = path.basename options.filename jsFile = baseFileName(options.filename) + ".js" - js = exports.compile code, options - map = sourcemap.generateV3SourceMap options.sourceMap, coffeeFile, jsFile - return [js, map] + compiledJs = exports.compile code, options + v3SourceMap = sourcemap.generateV3SourceMap options.sourceMap, coffeeFile, jsFile + return { + compiledJs, + v3SourceMap, + sourceMap: options.sourceMap + } catch err err.message = "In #{options.filename}, #{err.message}" if options.filename throw err diff --git a/src/command.coffee b/src/command.coffee index 3c596331..f7ee39fb 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -127,7 +127,9 @@ compileScript = (file, input, base) -> compileJoin() else if o.maps - [t.output, t.sourceMap] = CoffeeScript.compileWithSourceMap t.input, t.options + compiled = CoffeeScript.compileWithSourceMap t.input, t.options + t.output = compiled.compiledJs + t.sourceMap = compiled.v3SourceMap else t.output = CoffeeScript.compile t.input, t.options