From 51c625205bdd27f2028c89c614f226d091ed17e3 Mon Sep 17 00:00:00 2001 From: Demian Ferreiro Date: Tue, 30 Jul 2013 01:06:41 -0300 Subject: [PATCH] Update compiled JS --- lib/coffee-script/browser.js | 2 +- lib/coffee-script/coffee-script.js | 124 +++++++++++++++-------------- lib/coffee-script/command.js | 2 +- 3 files changed, 65 insertions(+), 63 deletions(-) diff --git a/lib/coffee-script/browser.js b/lib/coffee-script/browser.js index e5411d8c..2077c63b 100644 --- a/lib/coffee-script/browser.js +++ b/lib/coffee-script/browser.js @@ -41,7 +41,7 @@ options.sourceMap = true; options.inline = true; _ref = CoffeeScript.compile(code, options), js = _ref.js, v3SourceMap = _ref.v3SourceMap; - return "" + js + "\n//@ sourceMappingURL=data:application/json;base64," + (btoa(unescape(encodeURIComponent(v3SourceMap)))) + "\n//@ sourceURL=coffeescript"; + return "" + js + "\n//# sourceMappingURL=data:application/json;base64," + (btoa(unescape(encodeURIComponent(v3SourceMap)))) + "\n//# sourceURL=coffeescript"; }; } diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index 448fc2ca..05717f41 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -1,7 +1,8 @@ // Generated by CoffeeScript 1.6.3 (function() { - var Lexer, Module, SourceMap, child_process, compile, ext, findExtension, fork, formatSourcePosition, fs, helpers, lexer, loadFile, parser, patchStackTrace, patched, path, sourceMaps, vm, _i, _len, _ref, - __hasProp = {}.hasOwnProperty; + var Lexer, Module, SourceMap, child_process, compile, compileFile, ext, fileExtensions, findExtension, fork, formatSourcePosition, fs, getSourceMap, helpers, lexer, loadFile, parser, path, sourceMaps, vm, _i, _len, + __hasProp = {}.hasOwnProperty, + __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; }; fs = require('fs'); @@ -21,6 +22,8 @@ exports.VERSION = '1.6.3'; + fileExtensions = ['.coffee', '.litcoffee', '.coffee.md']; + exports.helpers = helpers; exports.compile = compile = function(code, options) { @@ -85,25 +88,19 @@ }; exports.run = function(code, options) { - var answer, mainModule; + var answer, mainModule, _ref; if (options == null) { options = {}; } mainModule = require.main; - if (options.sourceMap == null) { - options.sourceMap = true; - } 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 (!helpers.isCoffee(mainModule.filename) || require.extensions) { answer = compile(code, options); - patchStackTrace(); - sourceMaps[mainModule.filename] = answer.sourceMap; - return mainModule._compile(answer.js, mainModule.filename); - } else { - return mainModule._compile(code, mainModule.filename); + code = (_ref = answer.js) != null ? _ref : answer; } + return mainModule._compile(code, mainModule.filename); }; exports["eval"] = function(code, options) { @@ -169,14 +166,14 @@ } }; - loadFile = function(module, filename) { + compileFile = function(filename, sourceMap) { var answer, err, raw, stripped; raw = fs.readFileSync(filename, 'utf8'); stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw; try { answer = compile(stripped, { filename: filename, - sourceMap: true, + sourceMap: sourceMap, literate: helpers.isLiterate(filename) }); } catch (_error) { @@ -185,14 +182,18 @@ err.code = stripped; throw err; } - sourceMaps[filename] = answer.sourceMap; - return module._compile(answer.js, filename); + return answer; + }; + + loadFile = function(module, filename) { + var answer; + answer = compileFile(filename, false); + return module._compile(answer, filename); }; if (require.extensions) { - _ref = ['.coffee', '.litcoffee', '.coffee.md']; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - ext = _ref[_i]; + for (_i = 0, _len = fileExtensions.length; _i < _len; _i++) { + ext = fileExtensions[_i]; require.extensions[ext] = loadFile; } Module = require('module'); @@ -272,48 +273,6 @@ return helpers.throwSyntaxError(message, parser.lexer.yylloc); }; - patched = false; - - sourceMaps = {}; - - patchStackTrace = function() { - var mainModule; - if (patched) { - return; - } - patched = true; - mainModule = require.main; - return Error.prepareStackTrace = function(err, stack) { - var frame, frames, getSourceMapping, sourceFiles, _ref1; - sourceFiles = {}; - getSourceMapping = function(filename, line, column) { - var answer, sourceMap; - sourceMap = sourceMaps[filename]; - if (sourceMap) { - answer = sourceMap.sourceLocation([line - 1, column - 1]); - } - if (answer) { - return [answer[0] + 1, answer[1] + 1]; - } else { - return null; - } - }; - frames = (function() { - var _j, _len1, _results; - _results = []; - for (_j = 0, _len1 = stack.length; _j < _len1; _j++) { - frame = stack[_j]; - if (frame.getFunction() === exports.run) { - break; - } - _results.push(" at " + (formatSourcePosition(frame, getSourceMapping))); - } - return _results; - })(); - return "" + err.name + ": " + ((_ref1 = err.message) != null ? _ref1 : '') + "\n" + (frames.join('\n')) + "\n"; - }; - }; - formatSourcePosition = function(frame, getSourceMapping) { var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName; fileName = void 0; @@ -333,7 +292,7 @@ line = frame.getLineNumber(); column = frame.getColumnNumber(); source = getSourceMapping(fileName, line, column); - fileLocation = source ? "" + fileName + ":" + source[0] + ":" + source[1] + ", :" + line + ":" + column : "" + fileName + ":" + line + ":" + column; + fileLocation = source ? "" + fileName + ":" + source[0] + ":" + source[1] : "" + fileName + ":" + line + ":" + column; } functionName = frame.getFunctionName(); isConstructor = frame.isConstructor(); @@ -362,4 +321,47 @@ } }; + sourceMaps = {}; + + getSourceMap = function(filename) { + var answer, _ref; + if (sourceMaps[filename]) { + return sourceMaps[filename]; + } + if (_ref = path != null ? path.extname(filename) : void 0, __indexOf.call(fileExtensions, _ref) < 0) { + return; + } + answer = compileFile(filename, true); + return sourceMaps[filename] = answer.sourceMap; + }; + + Error.prepareStackTrace = function(err, stack) { + var frame, frames, getSourceMapping, _ref; + getSourceMapping = function(filename, line, column) { + var answer, sourceMap; + sourceMap = getSourceMap(filename); + if (sourceMap) { + answer = sourceMap.sourceLocation([line - 1, column - 1]); + } + if (answer) { + return [answer[0] + 1, answer[1] + 1]; + } else { + return null; + } + }; + frames = (function() { + var _j, _len1, _results; + _results = []; + for (_j = 0, _len1 = stack.length; _j < _len1; _j++) { + frame = stack[_j]; + if (frame.getFunction() === exports.run) { + break; + } + _results.push(" at " + (formatSourcePosition(frame, getSourceMapping))); + } + return _results; + })(); + return "" + err.name + ": " + ((_ref = err.message) != null ? _ref : '') + "\n" + (frames.join('\n')) + "\n"; + }; + }).call(this); diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index 44c96878..1ee917b5 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -407,7 +407,7 @@ js = ' '; } if (generatedSourceMap) { - js = "" + js + "\n/*\n//@ sourceMappingURL=" + (helpers.baseFileName(sourceMapPath, false, useWinPathSep)) + "\n*/\n"; + js = "" + js + "\n//# sourceMappingURL=" + (helpers.baseFileName(sourceMapPath, false, useWinPathSep)) + "\n"; } fs.writeFile(jsPath, js, function(err) { if (err) {