@@ -8,7 +8,7 @@ var to_base64 = typeof btoa == "undefined" ? function(str) {
|
|||||||
} : btoa;
|
} : btoa;
|
||||||
|
|
||||||
function read_source_map(name, code) {
|
function read_source_map(name, code) {
|
||||||
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code);
|
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(\S+)\s*$/.exec(code);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
AST_Node.warn("inline source map not found: " + name);
|
AST_Node.warn("inline source map not found: " + name);
|
||||||
return null;
|
return null;
|
||||||
@@ -204,10 +204,14 @@ function minify(files, options) {
|
|||||||
result.code = stream.get();
|
result.code = stream.get();
|
||||||
if (options.sourceMap) {
|
if (options.sourceMap) {
|
||||||
result.map = options.output.source_map.toString();
|
result.map = options.output.source_map.toString();
|
||||||
if (options.sourceMap.url == "inline") {
|
var url = options.sourceMap.url;
|
||||||
|
if (url) {
|
||||||
|
result.code = result.code.replace(/\n\/\/# sourceMappingURL=\S+\s*$/, "");
|
||||||
|
if (url == "inline") {
|
||||||
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
||||||
} else if (options.sourceMap.url) {
|
} else {
|
||||||
result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
|
result.code += "\n//# sourceMappingURL=" + url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
test/input/issue-3294/input.js
Normal file
6
test/input/issue-3294/input.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
var Foo = function Foo(){console.log(1+2);}; new Foo();
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,DeadBeef
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjpudWxsLCJzb3VyY2VzIjpbInN0ZGluIl0sInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLElBQU0sR0FBRyxHQUFDLEFBQUUsWUFBVyxFQUFFLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFBLEFBQUUsQ0FBQyxJQUFJLEdBQUcsRUFBRSxDQUFDOyJ9
|
||||||
|
|
||||||
|
|
||||||
2
test/input/issue-3294/output.js
Normal file
2
test/input/issue-3294/output.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
new function(){console.log(3)};
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl19
|
||||||
@@ -114,13 +114,12 @@ describe("bin/uglifyjs", function() {
|
|||||||
|
|
||||||
var child = exec(command, function(err, stdout) {
|
var child = exec(command, function(err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
assert.strictEqual(stdout, read("test/input/issue-3040/expect.js"));
|
||||||
assert.strictEqual(stdout, read("test/input/pr-3040/expect.js"));
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
fs.writeFileSync(mapFile, read("test/input/pr-3040/input.js.map"));
|
fs.writeFileSync(mapFile, read("test/input/issue-3040/input.js.map"));
|
||||||
child.stdin.end(read("test/input/pr-3040/input.js"));
|
child.stdin.end(read("test/input/issue-3040/input.js"));
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
it("Should work with --keep-fnames (mangle only)", function(done) {
|
it("Should work with --keep-fnames (mangle only)", function(done) {
|
||||||
|
|||||||
@@ -277,6 +277,43 @@ describe("comments", function() {
|
|||||||
].join("\n"));
|
].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() {
|
describe("comment before constant", function() {
|
||||||
var js = 'function f() { /*c1*/ var /*c2*/ foo = /*c3*/ false; return foo; }';
|
var js = 'function f() { /*c1*/ var /*c2*/ foo = /*c3*/ false; return foo; }';
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,18 @@ describe("sourcemaps", function() {
|
|||||||
map = JSON.parse(result.map);
|
map = JSON.parse(result.map);
|
||||||
assert.ok(!("sourcesContent" in 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() {
|
describe("sourceMapInline", function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user