mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
use btoa as base64 encoder, inspired by @ashtuchkin
This commit is contained in:
@@ -1,12 +1,36 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
(function() {
|
||||
var CoffeeScript, runScripts,
|
||||
var CoffeeScript, compile, isModernBrowser, runScripts,
|
||||
__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; };
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
CoffeeScript.require = require;
|
||||
|
||||
isModernBrowser = typeof window !== "undefined" && window !== null ? function() {
|
||||
if (btoa && JSON) {
|
||||
return true;
|
||||
}
|
||||
} : function() {};
|
||||
|
||||
compile = function(code, options) {
|
||||
var answer, js, res, v3SourceMap, _ref;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
res = void 0;
|
||||
if (isModernBrowser()) {
|
||||
options.sourceMap = true;
|
||||
options.inline = true;
|
||||
_ref = CoffeeScript.compile(code, options), js = _ref.js, v3SourceMap = _ref.v3SourceMap;
|
||||
answer = btoa(v3SourceMap);
|
||||
res = "" + js + "\n//@ sourceMappingURL=data:application/json;base64," + answer + "\n//@ sourceURL=coffeescript.coffee";
|
||||
} else {
|
||||
res = CoffeeScript.compile(code, options);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
CoffeeScript["eval"] = function(code, options) {
|
||||
var _ref;
|
||||
if (options == null) {
|
||||
@@ -15,7 +39,7 @@
|
||||
if ((_ref = options.bare) == null) {
|
||||
options.bare = true;
|
||||
}
|
||||
return eval(CoffeeScript.compile(code, options));
|
||||
return eval(compile(code, options));
|
||||
};
|
||||
|
||||
CoffeeScript.run = function(code, options) {
|
||||
@@ -23,7 +47,7 @@
|
||||
options = {};
|
||||
}
|
||||
options.bare = true;
|
||||
return Function(CoffeeScript.compile(code, options))();
|
||||
return Function(compile(code, options))();
|
||||
};
|
||||
|
||||
if (typeof window === "undefined" || window === null) {
|
||||
@@ -35,6 +59,7 @@
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
options.sourceFiles = [url];
|
||||
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
if ('overrideMimeType' in xhr) {
|
||||
@@ -84,6 +109,7 @@
|
||||
if (script.src) {
|
||||
return CoffeeScript.load(script.src, execute, options);
|
||||
} else {
|
||||
options.sourceFiles = ['embedded'];
|
||||
CoffeeScript.run(script.innerHTML, options);
|
||||
return execute();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
};
|
||||
if (sourceMap) {
|
||||
answer.sourceMap = sourceMap;
|
||||
answer.v3SourceMap = sourcemap.generateV3SourceMap(sourceMap, options);
|
||||
answer.v3SourceMap = sourcemap.generateV3SourceMap(sourceMap, options, code);
|
||||
}
|
||||
return answer;
|
||||
} else {
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
|
||||
})();
|
||||
|
||||
exports.generateV3SourceMap = function(sourceMap, options) {
|
||||
exports.generateV3SourceMap = function(sourceMap, options, code) {
|
||||
var answer, generatedFile, lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, sourceFiles, sourceRoot, writingGeneratedLine;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
@@ -155,6 +155,9 @@
|
||||
names: [],
|
||||
mappings: mappings
|
||||
};
|
||||
if (options.inline) {
|
||||
answer.sourcesContent = [code];
|
||||
}
|
||||
return JSON.stringify(answer, null, 2);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user