Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support CoffeeScript source maps

  • Loading branch information...
commit 65d1119764c288c02493ec3b1bc59067c6557124 1 parent b5d0266
@andreyvit andreyvit authored
View
6 CoffeeScript.lrplugin/manifest.json
@@ -28,6 +28,12 @@
"Type": "checkbox",
"Title": "No wrapper (--bare)",
"OnArgument": "--bare"
+ },
+ {
+ "Id": "source-map",
+ "Type": "checkbox",
+ "Title": "Generate source map (--map)",
+ "OnArgument": "--map"
}
]
}
View
39 CoffeeScript.lrplugin/scripts/compile-coffeescript.iced
@@ -22,6 +22,7 @@ OPTIONS = [
"Compilation options:"
" -b, --bare Compile without a top-level function wrapper"
+ " --map Generate source map and save as .map files"
"General options:"
" -v, --version Display the version number", printVersion
@@ -50,9 +51,23 @@ compilePath = (source, destination, opts) ->
process.exit EXIT_E_IO
try
- js = CoffeeScript.compile coffee.toString(), compilerOptions(source, opts)
+ if opts.map
+ sourceMapPath = destination.replace(/\.js$/, '') + '.map'
+ sourceMapBaseName = path.basename(sourceMapPath)
+
+ compiled = CoffeeScript.compile coffee.toString(), compilerOptions(source, opts, { source, destination, sourceMapPath })
+ if opts.map
+ js = compiled.js
+ sourceMap = compiled.v3SourceMap
+ else
+ js = compiled
+ sourceMap = null
+
js = ' ' if js.length <= 0
+ if sourceMap
+ js = "#{js}\n/*\n//@ sourceMappingURL=#{sourceMapBaseName}\n*/\n"
+
await exists path.dirname(destination), defer(itExists)
unless itExists
await mkdir_p path.dirname(destination), `0777`, defer()
@@ -62,14 +77,32 @@ compilePath = (source, destination, opts) ->
console.error err.message
process.exit EXIT_E_IO
+ if sourceMap
+ await fs.writeFile sourceMapPath, sourceMap, defer(err)
+ if err
+ console.error err.message
+ process.exit EXIT_E_IO
+
+
catch err
printWarn err instanceof Error and err.stack or "ERROR: #{err}"
process.exit EXIT_E_COMPILATION
-compilerOptions = (filename, opts) ->
- {filename, bare: opts.bare, header: yes}
+compilerOptions = (filename, opts, paths) ->
+ srcDir = path.dirname(paths.source)
+ jsDir = path.dirname(paths.destination)
+
+ {
+ filename,
+ bare: opts.bare,
+ sourceMap: opts.map,
+ header: yes,
+ sourceRoot: path.relative jsDir, srcDir
+ sourceFiles: [path.basename(paths.source)]
+ generatedFile: path.basename(paths.destination)
+ }
mkdir_p = (path, mode, callback, position) ->
View
80 CoffeeScript.lrplugin/scripts/compile-coffeescript.js
@@ -1,4 +1,4 @@
-// Generated by IcedCoffeeScript 1.3.3b
+// Generated by IcedCoffeeScript 1.4.0a
(function() {
var CoffeeScript, EXIT_E_CMD_LINE, EXIT_E_COMPILATION, EXIT_E_IO, EXIT_SUCCESS, OPTIONS, compilePath, compilerOptions, exists, fs, iced, mkdir_p, path, printLine, printVersion, printWarn, run, __iced_k, __iced_k_noop,
__slice = [].slice;
@@ -36,6 +36,9 @@
})(),
findDeferral: function() {
return null;
+ },
+ trampoline: function(_fn) {
+ return _fn();
}
};
__iced_k = __iced_k_noop = function() {};
@@ -61,7 +64,7 @@
return process.exit(0);
};
- OPTIONS = ["Usage: node compile-coffee.js [options] source.coffee destination.js", "Files:", " source.coffee Path to the source file #required #var(source)", " destination.js Path to the destination file #required #var(destination)", "Compilation options:", " -b, --bare Compile without a top-level function wrapper", "General options:", " -v, --version Display the version number", printVersion];
+ OPTIONS = ["Usage: node compile-coffee.js [options] source.coffee destination.js", "Files:", " source.coffee Path to the source file #required #var(source)", " destination.js Path to the destination file #required #var(destination)", "Compilation options:", " -b, --bare Compile without a top-level function wrapper", " --map Generate source map and save as .map files", "General options:", " -v, --version Display the version number", printVersion];
EXIT_E_CMD_LINE = 3;
@@ -80,14 +83,14 @@
};
compilePath = function(source, destination, opts) {
- var coffee, err, itExists, js, ___iced_passed_deferral, __iced_deferrals, __iced_k,
+ var coffee, compiled, err, itExists, js, sourceMap, sourceMapBaseName, sourceMapPath, ___iced_passed_deferral, __iced_deferrals, __iced_k,
_this = this;
__iced_k = __iced_k_noop;
___iced_passed_deferral = iced.findDeferral(arguments);
(function(__iced_k) {
__iced_deferrals = new iced.Deferrals(__iced_k, {
parent: ___iced_passed_deferral,
- filename: "/Users/andreyvit/dev/products/LiveReload/LiveReload23/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
+ filename: "/Users/andreyvit/dev/livereload/maint-mac/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
funcname: "compilePath"
});
fs.readFile(source, __iced_deferrals.defer({
@@ -97,7 +100,7 @@
return coffee = arguments[1];
};
})(),
- lineno: 46
+ lineno: 47
}));
__iced_deferrals._fulfill();
})(function() {
@@ -106,12 +109,30 @@
process.exit(EXIT_E_IO);
}
try {
- js = CoffeeScript.compile(coffee.toString(), compilerOptions(source, opts));
+ if (opts.map) {
+ sourceMapPath = destination.replace(/\.js$/, '') + '.map';
+ sourceMapBaseName = path.basename(sourceMapPath);
+ }
+ compiled = CoffeeScript.compile(coffee.toString(), compilerOptions(source, opts, {
+ source: source,
+ destination: destination,
+ sourceMapPath: sourceMapPath
+ }));
+ if (opts.map) {
+ js = compiled.js;
+ sourceMap = compiled.v3SourceMap;
+ } else {
+ js = compiled;
+ sourceMap = null;
+ }
if (js.length <= 0) js = ' ';
+ if (sourceMap) {
+ js = "" + js + "\n/*\n//@ sourceMappingURL=" + sourceMapBaseName + "\n*/\n";
+ }
(function(__iced_k) {
__iced_deferrals = new iced.Deferrals(__iced_k, {
parent: ___iced_passed_deferral,
- filename: "/Users/andreyvit/dev/products/LiveReload/LiveReload23/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
+ filename: "/Users/andreyvit/dev/livereload/maint-mac/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
funcname: "compilePath"
});
exists(path.dirname(destination), __iced_deferrals.defer({
@@ -120,7 +141,7 @@
return itExists = arguments[0];
};
})(),
- lineno: 55
+ lineno: 70
}));
__iced_deferrals._fulfill();
})(function() {
@@ -129,11 +150,11 @@
(function(__iced_k) {
__iced_deferrals = new iced.Deferrals(__iced_k, {
parent: ___iced_passed_deferral,
- filename: "/Users/andreyvit/dev/products/LiveReload/LiveReload23/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
+ filename: "/Users/andreyvit/dev/livereload/maint-mac/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
funcname: "compilePath"
});
mkdir_p(path.dirname(destination), 0777, __iced_deferrals.defer({
- lineno: 57
+ lineno: 72
}));
__iced_deferrals._fulfill();
})(__iced_k);
@@ -144,7 +165,7 @@
(function(__iced_k) {
__iced_deferrals = new iced.Deferrals(__iced_k, {
parent: ___iced_passed_deferral,
- filename: "/Users/andreyvit/dev/products/LiveReload/LiveReload23/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
+ filename: "/Users/andreyvit/dev/livereload/maint-mac/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
funcname: "compilePath"
});
fs.writeFile(destination, js, __iced_deferrals.defer({
@@ -153,13 +174,35 @@
return err = arguments[0];
};
})(),
- lineno: 59
+ lineno: 74
}));
__iced_deferrals._fulfill();
})(function() {
if (err) {
console.error(err.message);
- return process.exit(EXIT_E_IO);
+ process.exit(EXIT_E_IO);
+ }
+ if (sourceMap) {
+ (function(__iced_k) {
+ __iced_deferrals = new iced.Deferrals(__iced_k, {
+ parent: ___iced_passed_deferral,
+ filename: "/Users/andreyvit/dev/livereload/maint-mac/LiveReload/Compilers/CoffeeScript.lrplugin/scripts/compile-coffeescript.iced",
+ funcname: "compilePath"
+ });
+ fs.writeFile(sourceMapPath, sourceMap, __iced_deferrals.defer({
+ assign_fn: (function() {
+ return function() {
+ return err = arguments[0];
+ };
+ })(),
+ lineno: 80
+ }));
+ __iced_deferrals._fulfill();
+ })(function() {
+ return __iced_k(err ? (console.error(err.message), process.exit(EXIT_E_IO)) : void 0);
+ });
+ } else {
+ return __iced_k();
}
});
});
@@ -171,11 +214,18 @@
});
};
- compilerOptions = function(filename, opts) {
+ compilerOptions = function(filename, opts, paths) {
+ var jsDir, srcDir;
+ srcDir = path.dirname(paths.source);
+ jsDir = path.dirname(paths.destination);
return {
filename: filename,
bare: opts.bare,
- header: true
+ sourceMap: opts.map,
+ header: true,
+ sourceRoot: path.relative(jsDir, srcDir),
+ sourceFiles: [path.basename(paths.source)],
+ generatedFile: path.basename(paths.destination)
};
};
Please sign in to comment.
Something went wrong with that request. Please try again.