output shebang in transpiled code - fixes #55
This commit is contained in:
parent
a4575f5778
commit
9d18905ce9
@ -1,5 +1,7 @@
|
||||
module.exports = File;
|
||||
|
||||
var SHEBANG_REGEX = /^\#\!.*/;
|
||||
|
||||
var transform = require("./transform");
|
||||
var util = require("./util");
|
||||
var _ = require("lodash");
|
||||
@ -32,12 +34,23 @@ File.normaliseOptions = function (opts) {
|
||||
return opts;
|
||||
};
|
||||
|
||||
File.prototype.parse = function (code) {
|
||||
// remove shebang
|
||||
code = code.replace(/^\#\!.*/, "");
|
||||
File.prototype.parseShebang = function (code) {
|
||||
var shebangMatch = code.match(SHEBANG_REGEX);
|
||||
if (shebangMatch) {
|
||||
this.shebang = shebangMatch[0];
|
||||
|
||||
// remove shebang
|
||||
code = code.replace(SHEBANG_REGEX, "");
|
||||
}
|
||||
|
||||
return code;
|
||||
};
|
||||
|
||||
File.prototype.parse = function (code) {
|
||||
var self = this;
|
||||
|
||||
code = this.parseShebang(code);
|
||||
|
||||
return util.parse(this.opts, code, function (tree) {
|
||||
return self.transform(tree);
|
||||
});
|
||||
@ -55,6 +68,10 @@ File.prototype.transform = function (ast) {
|
||||
|
||||
var result = util.generate(ast, opts);
|
||||
|
||||
if (this.shebang) {
|
||||
result.code = this.shebang + result.code;
|
||||
}
|
||||
|
||||
if (opts.sourceMap === "inline") {
|
||||
result.code += "\n" + util.sourceMapToComment(result.map);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user