aboutsummaryrefslogtreecommitdiff
path: root/test/mocha/comments.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-10-20 03:21:30 +0800
committerGitHub <noreply@github.com>2019-10-20 03:21:30 +0800
commit543dd7d3d750e83b00e50bbf74fa786a7c1d243e (patch)
tree24fae6f9d8fa4996cb4a140eac0780a994023593 /test/mocha/comments.js
parent6b4886c908c6415a397539701117cd493545d21b (diff)
downloadtracifyjs-543dd7d3d750e83b00e50bbf74fa786a7c1d243e.tar.gz
tracifyjs-543dd7d3d750e83b00e50bbf74fa786a7c1d243e.zip
fix corner case in `comments` (#3500)
Diffstat (limited to 'test/mocha/comments.js')
-rw-r--r--test/mocha/comments.js119
1 files changed, 75 insertions, 44 deletions
diff --git a/test/mocha/comments.js b/test/mocha/comments.js
index 04dd171e..764f6db8 100644
--- a/test/mocha/comments.js
+++ b/test/mocha/comments.js
@@ -48,53 +48,84 @@ describe("comments", function() {
}
});
- it("Should handle comment within return correctly", function() {
- var result = UglifyJS.minify([
- "function unequal(x, y) {",
- " return (",
- " // Either one",
- " x < y",
- " ||",
- " y < x",
- " );",
- "}",
- ].join("\n"), {
- compress: false,
- mangle: false,
- output: {
- beautify: true,
- comments: "all",
- },
+ describe("comment within return", function() {
+ it("Should handle leading return", function() {
+ var result = UglifyJS.minify([
+ "function unequal(x, y) {",
+ " return (",
+ " // Either one",
+ " x < y",
+ " ||",
+ " y < x",
+ " );",
+ "}",
+ ].join("\n"), {
+ compress: false,
+ mangle: false,
+ output: {
+ beautify: true,
+ comments: "all",
+ },
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, [
+ "function unequal(x, y) {",
+ " // Either one",
+ " return x < y || y < x;",
+ "}",
+ ].join("\n"));
});
- if (result.error) throw result.error;
- assert.strictEqual(result.code, [
- "function unequal(x, y) {",
- " // Either one",
- " return x < y || y < x;",
- "}",
- ].join("\n"));
- });
- it("Should handle comment folded into return correctly", function() {
- var result = UglifyJS.minify([
- "function f() {",
- " /* boo */ x();",
- " return y();",
- "}",
- ].join("\n"), {
- mangle: false,
- output: {
- beautify: true,
- comments: "all",
- },
+ it("Should handle trailing return", function() {
+ var result = UglifyJS.minify([
+ "function unequal(x) {",
+ " var y;",
+ " return (",
+ " // Either one",
+ " x < y",
+ " ||",
+ " y < x",
+ " );",
+ "}",
+ ].join("\n"), {
+ compress: false,
+ mangle: false,
+ output: {
+ beautify: true,
+ comments: "all",
+ },
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, [
+ "function unequal(x) {",
+ " var y;",
+ " // Either one",
+ " return x < y || y < x;",
+ "}",
+ ].join("\n"));
+ });
+
+ it("Should handle comment folded into return", function() {
+ var result = UglifyJS.minify([
+ "function f() {",
+ " /* boo */ x();",
+ " return y();",
+ "}",
+ ].join("\n"), {
+ mangle: false,
+ output: {
+ beautify: true,
+ comments: "all",
+ },
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, [
+ "function f() {",
+ " /* boo */",
+ " return x(), y();",
+ "}",
+ ].join("\n"));
});
- if (result.error) throw result.error;
- assert.strictEqual(result.code, [
- "function f() {",
- " /* boo */",
- " return x(), y();",
- "}",
- ].join("\n"));
});
it("Should not drop comments after first OutputStream", function() {