From 573fdf14f22ef710c0b363e77568e42be1cb1f63 Mon Sep 17 00:00:00 2001 From: aleclarson Date: Fri, 10 Nov 2017 22:23:45 -0500 Subject: [PATCH 1/2] Add tests for template strings --- test/comment-regex.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/comment-regex.js b/test/comment-regex.js index 7e588da..5c7a8f3 100644 --- a/test/comment-regex.js +++ b/test/comment-regex.js @@ -82,6 +82,7 @@ test('mapFileComment regex old spec - @', function (t) { [ [' @// @', ''], + ['var sm = `//@ ', '`'], // not inside a string ['var sm = "//@ ', '"'], // not inside a string ['var sm = \'//@ ', '\''], // not inside a string ['var sm = \' //@ ', '\''], // not inside a string @@ -101,6 +102,7 @@ test('mapFileComment regex new spec - #', function (t) { [ [' #// #', ''], + ['var sm = `//# ', '`'], // not inside a string ['var sm = "//# ', '"'], // not inside a string ['var sm = \'//# ', '\''], // not inside a string ['var sm = \' //# ', '\''], // not inside a string From 38ca213128c5d493ead8068cc4d155aa92d66c2b Mon Sep 17 00:00:00 2001 From: aleclarson Date: Sat, 11 Nov 2017 09:37:26 -0500 Subject: [PATCH 2/2] Avoid matching sourceMappingURL inside a template string --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8d8674c..2d08f1e 100644 --- a/index.js +++ b/index.js @@ -10,9 +10,8 @@ Object.defineProperty(exports, 'commentRegex', { Object.defineProperty(exports, 'mapFileCommentRegex', { get: function getMapFileCommentRegex () { - //Example (Extra space between slashes added to solve Safari bug. Exclude space in production): - // / /# sourceMappingURL=foo.js.map /*# sourceMappingURL=foo.js.map */ - return /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/){1}[ \t]*$)/mg; + // Matches sourceMappingURL in either // or /* comment styles. + return /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"`]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/){1}[ \t]*$)/mg; } });