Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid matching sourceMappingURL inside a template string #61

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});

Expand Down
2 changes: 2 additions & 0 deletions test/comment-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down