source-map-url
Advanced tools
+21
| The MIT License (MIT) | ||
| Copyright (c) 2014 Simon Lydell | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. |
+1
-1
| { | ||
| "name": "source-map-url", | ||
| "version": "0.3.0", | ||
| "version": "0.4.0", | ||
| "author": "Simon Lydell", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+10
-0
@@ -0,1 +1,11 @@ | ||
| ### Version 0.4.0 (2015-11-12) ### | ||
| - Changed: sourceMappingURL comments used to be matched only when placed at | ||
| the end of the script. However, since several commonly used JavaScript | ||
| libraries do not follow this convention and all popular web browsers accept | ||
| non-trailing comments, this has been revised. | ||
| So now non-trailing SourceMappingURL comments are matched as well. | ||
| ### Version 0.3.0 (2014-08-16) ### | ||
@@ -2,0 +12,0 @@ |
+2
-2
| { | ||
| "name": "source-map-url", | ||
| "version": "0.3.0", | ||
| "version": "0.4.0", | ||
| "author": "Simon Lydell", | ||
@@ -18,2 +18,2 @@ "license": "MIT", | ||
| ] | ||
| } | ||
| } |
+2
-2
| { | ||
| "name": "source-map-url", | ||
| "version": "0.3.0", | ||
| "version": "0.4.0", | ||
| "author": "Simon Lydell", | ||
@@ -39,2 +39,2 @@ "license": "MIT", | ||
| } | ||
| } | ||
| } |
+2
-2
@@ -77,4 +77,4 @@ Overview [](https://travis-ci.org/lydell/source-map-url) | ||
| Lets you append something to a file without worrying about breaking the | ||
| sourceMappingURL comment (which needs to be at the end of the file). | ||
| Lets you append something to a file without worrying about burying the | ||
| sourceMappingURL comment (by keeping it at the end of the file). | ||
@@ -81,0 +81,0 @@ ### `sourceMappingURL.regex` ### |
@@ -26,3 +26,3 @@ // Copyright 2014 Simon Lydell | ||
| ")" + | ||
| "\\s*$" | ||
| "\\s*" | ||
| ) | ||
@@ -29,0 +29,0 @@ |
+106
-25
@@ -32,2 +32,30 @@ // Copyright 2014 Simon Lydell | ||
| var nonTrailingComments = { | ||
| jsLeading: { | ||
| contents: [ | ||
| "//# sourceMappingURL=foo.js.map", | ||
| "(function(){})" | ||
| ], | ||
| solution: [ | ||
| "(function(){})" | ||
| ] | ||
| }, | ||
| mixEmbedded: { | ||
| contents: [ | ||
| "/*! Library Name v1.0.0", | ||
| "//# sourceMappingURL=foo.js.map", | ||
| "*/", | ||
| "(function(){})" | ||
| ], | ||
| solution: [ | ||
| "/*! Library Name v1.0.0", | ||
| "*/", | ||
| "(function(){})" | ||
| ] | ||
| } | ||
| } | ||
| function forEachComment(fn) { | ||
@@ -41,2 +69,19 @@ forOf(comments, function(name, comment) { | ||
| function forEachNonTrailingComment(fn) { | ||
| forOf(nonTrailingComments, function(name, comment) { | ||
| var description = "the '" + name + "' syntax with " | ||
| fn({ | ||
| contents: comment.contents.join("\n"), | ||
| solution: comment.solution.join("\n") | ||
| }, description + "regular newlines") | ||
| fn({ | ||
| contents: comment.contents.join("\r\n"), | ||
| solution: comment.solution.join("\r\n") | ||
| }, description + "Windows newlines") | ||
| }) | ||
| } | ||
| function forOf(obj, fn) { | ||
@@ -70,3 +115,18 @@ for (var key in obj) { | ||
| forEachNonTrailingComment(function(comment, description) { | ||
| it("gets the url from " + description, function() { | ||
| expect(sourceMappingURL.getFrom("code\n" + comment.contents)) | ||
| .to.equal("foo.js.map") | ||
| expect(sourceMappingURL.getFrom("code" + comment.contents)) | ||
| .to.equal("foo.js.map") | ||
| expect(sourceMappingURL.getFrom(comment.contents)) | ||
| .to.equal("foo.js.map") | ||
| }) | ||
| }) | ||
| it("returns null if no comment", function() { | ||
@@ -110,3 +170,18 @@ expect(sourceMappingURL.getFrom("code")) | ||
| forEachNonTrailingComment(function(comment, description) { | ||
| it("returns true for " + description, function() { | ||
| expect(sourceMappingURL.existsIn("code\n" + comment.contents)) | ||
| .to.equal(true) | ||
| expect(sourceMappingURL.existsIn("code" + comment.contents)) | ||
| .to.equal(true) | ||
| expect(sourceMappingURL.existsIn(comment.contents)) | ||
| .to.equal(true) | ||
| }) | ||
| }) | ||
| it("returns false if no comment", function() { | ||
@@ -144,3 +219,18 @@ expect(sourceMappingURL.existsIn("code")) | ||
| forEachNonTrailingComment(function(comment, description) { | ||
| it("removes the comment for " + description, function() { | ||
| expect(sourceMappingURL.removeFrom("code\n" + comment.contents)) | ||
| .to.equal("code\n" + comment.solution) | ||
| expect(sourceMappingURL.removeFrom("code" + comment.contents)) | ||
| .to.equal("code" + comment.solution) | ||
| expect(sourceMappingURL.removeFrom(comment.contents)) | ||
| .to.equal(comment.solution) | ||
| }) | ||
| }) | ||
| it("does nothing if no comment", function() { | ||
@@ -179,2 +269,18 @@ expect(sourceMappingURL.removeFrom("code\n")) | ||
| it("inserts a string before an embedded comment", function() { | ||
| expect(sourceMappingURL.insertBefore("/*! Library Name v1.0.0\n" + | ||
| "//# sourceMappingURL=foo.js.map\n*/\n(function(){})", "code\n")) | ||
| .to.equal("/*! Library Name v1.0.0\ncode\n" + | ||
| "//# sourceMappingURL=foo.js.map\n*/\n(function(){})") | ||
| }) | ||
| it("inserts a string before a leading comment", function() { | ||
| expect(sourceMappingURL.insertBefore("//# sourceMappingURL=foo.js.map\n" + | ||
| "(function(){})", "code\n")) | ||
| .to.equal("code\n//# sourceMappingURL=foo.js.map\n" + | ||
| "(function(){})") | ||
| }) | ||
| it("appends if no comment", function() { | ||
@@ -229,16 +335,2 @@ expect(sourceMappingURL.insertBefore("code", "\nmore code")) | ||
| it("only matches " + description + " at the end of files", function() { | ||
| noMatch("code\n" + comment + " code") | ||
| noMatch("code" + comment + " code") | ||
| noMatch("code\n" + comment + "\ncode") | ||
| noMatch("code" + comment + "\ncode") | ||
| noMatch("code\n" + comment + "\n// Generated by foobar") | ||
| noMatch("code" + comment + "\n// Generated by foobar") | ||
| noMatch("alert\n('\\" + comment + "')") | ||
| noMatch("alert('\\" + comment + "')") | ||
| noMatch('alert\n("\\' + comment + '")') | ||
| noMatch('alert("\\' + comment + '")') | ||
| }) | ||
| }) | ||
@@ -253,13 +345,2 @@ | ||
| noMatch( | ||
| "/*\n" + | ||
| " //# sourceMappingURL=foo\n" + | ||
| "*/" | ||
| ) | ||
| noMatch( | ||
| "/*//# sourceMappingURL=foo\n" + | ||
| "*/" | ||
| ) | ||
| noMatch( | ||
| "// # sourceMappingURL=foo" | ||
@@ -266,0 +347,0 @@ ) |
+1
-1
| { | ||
| name: "source-map-url", | ||
| version: "0.3.0", | ||
| version: "0.4.0", | ||
| author: "Simon Lydell", | ||
@@ -5,0 +5,0 @@ license: "MIT", |
Sorry, the diff of this file is not supported yet
19369
22.29%366
19.22%