diff --git a/lib/babel/transformation/file.js b/lib/babel/transformation/file.js index 76be03515f..e74beccab5 100644 --- a/lib/babel/transformation/file.js +++ b/lib/babel/transformation/file.js @@ -2,9 +2,8 @@ module.exports = File; -var SHEBANG_REGEX = /^\#\!.*/; - var sourceMapToComment = require("source-map-to-comment"); +var shebangRegex = require("shebang-regex"); var isFunction = require("lodash/lang/isFunction"); var transform = require("./index"); var generate = require("../generation"); @@ -247,12 +246,13 @@ File.prototype.getModuleFormatter = function (type) { }; File.prototype.parseShebang = function (code) { - var shebangMatch = code.match(SHEBANG_REGEX); + var shebangMatch = shebangRegex.exec(code); + if (shebangMatch) { this.shebang = shebangMatch[0]; // remove shebang - code = code.replace(SHEBANG_REGEX, ""); + code = code.replace(shebangRegex, ""); } return code; diff --git a/package.json b/package.json index 59e278bfd2..3527e868f4 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "regenerator-babel": "0.8.10-2", "regexpu": "^1.1.1", "repeating": "^1.1.2", + "shebang-regex": "^1.0.0", "slash": "^1.0.0", "source-map": "^0.1.43", "source-map-support": "^0.2.9",