diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-05-04 20:08:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-04 20:08:57 +0800 |
commit | 11cdab745d29313a4e1799c65d13f7d6d5a45938 (patch) | |
tree | 336375b5eac05211b5ea2c77aecc37069a3753ba /test/mocha | |
parent | a89d424a0bd85c80a6b49b6585143ff723a243ca (diff) | |
download | tracifyjs-11cdab745d29313a4e1799c65d13f7d6d5a45938.tar.gz tracifyjs-11cdab745d29313a4e1799c65d13f7d6d5a45938.zip |
fix corner cases in `sourceMap` (#3397)
fixes #3255
fixes #3294
Diffstat (limited to 'test/mocha')
-rw-r--r-- | test/mocha/cli.js | 7 | ||||
-rw-r--r-- | test/mocha/comments.js | 37 | ||||
-rw-r--r-- | test/mocha/sourcemaps.js | 12 |
3 files changed, 52 insertions, 4 deletions
diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 6d6e1e80..f99a8be4 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -114,13 +114,12 @@ describe("bin/uglifyjs", function() { var child = exec(command, function(err, stdout) { if (err) throw err; - - assert.strictEqual(stdout, read("test/input/pr-3040/expect.js")); + assert.strictEqual(stdout, read("test/input/issue-3040/expect.js")); done(); }); setTimeout(function() { - fs.writeFileSync(mapFile, read("test/input/pr-3040/input.js.map")); - child.stdin.end(read("test/input/pr-3040/input.js")); + fs.writeFileSync(mapFile, read("test/input/issue-3040/input.js.map")); + child.stdin.end(read("test/input/issue-3040/input.js")); }, 1000); }); it("Should work with --keep-fnames (mangle only)", function(done) { diff --git a/test/mocha/comments.js b/test/mocha/comments.js index 3907f2fa..04dd171e 100644 --- a/test/mocha/comments.js +++ b/test/mocha/comments.js @@ -277,6 +277,43 @@ describe("comments", function() { ].join("\n")); }); + it("Should not duplicate sourceMappingURL", function() { + var code = [ + "//# sourceMappingURL=input.map", + "print(42);", + "//# sourceMappingURL=input.map", + "", + "//# sourceMappingURL=input.map", + "//# sourceMappingURL=input.map", + "", + ].join("\n"); + + var result = UglifyJS.minify(code, { + output: { comments: true }, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, [ + "//# sourceMappingURL=input.map", + "print(42);", + "//# sourceMappingURL=input.map", + "//# sourceMappingURL=input.map", + "//# sourceMappingURL=input.map", + ].join("\n")); + + result = UglifyJS.minify(code, { + output: { comments: true }, + sourceMap: { url: "output.map" }, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, [ + "//# sourceMappingURL=input.map", + "print(42);", + "//# sourceMappingURL=input.map", + "//# sourceMappingURL=input.map", + "//# sourceMappingURL=output.map", + ].join("\n")); + }); + describe("comment before constant", function() { var js = 'function f() { /*c1*/ var /*c2*/ foo = /*c3*/ false; return foo; }'; diff --git a/test/mocha/sourcemaps.js b/test/mocha/sourcemaps.js index f625b227..78e100ba 100644 --- a/test/mocha/sourcemaps.js +++ b/test/mocha/sourcemaps.js @@ -169,6 +169,18 @@ describe("sourcemaps", function() { map = JSON.parse(result.map); assert.ok(!("sourcesContent" in map)); }); + it("Should parse the correct sourceMappingURL", function() { + var result = UglifyJS.minify(read("./test/input/issue-3294/input.js"), { + compress: { toplevel: true }, + sourceMap: { + content: "inline", + includeSources: true, + url: "inline" + } + }); + if (result.error) throw result.error; + assert.strictEqual(result.code + "\n", readFileSync("test/input/issue-3294/output.js", "utf8")); + }); }); describe("sourceMapInline", function() { |