From 211c9802a51051f01738fb9f2a3d93e43f885804 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 17 Feb 2015 12:26:36 +0700 Subject: [PATCH] modularize `SHEBANG_REGEX` https://github.com/sindresorhus/shebang-regex --- lib/babel/transformation/file.js | 8 ++++---- package.json | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) 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",