make comments output more robust (#2633)

- improve handling of comments right after `return`
- retain comments after `OutputStream`
- preserve trailing comments
- fix handling of new line before comments
- handle comments around parentheses

fixes #88
fixes #112
fixes #218
fixes #372
fixes #2629
This commit is contained in:
Alex Lam S.L
2017-12-22 04:59:54 +08:00
committed by GitHub
parent 4113609dd4
commit edb4e3bd52
7 changed files with 401 additions and 90 deletions

View File

@@ -293,3 +293,85 @@ unary: {
bar();
}
}
issue_2629_1: {
options = {
side_effects: true,
}
input: {
/*@__PURE__*/ a();
/*@__PURE__*/ (b());
(/*@__PURE__*/ c)();
(/*@__PURE__*/ d());
}
expect: {}
}
issue_2629_2: {
options = {
side_effects: true,
}
input: {
/*@__PURE__*/ a(1)(2)(3);
/*@__PURE__*/ (b(1))(2)(3);
/*@__PURE__*/ (c(1)(2))(3);
/*@__PURE__*/ (d(1)(2)(3));
(/*@__PURE__*/ e)(1)(2)(3);
(/*@__PURE__*/ f(1))(2)(3);
(/*@__PURE__*/ g(1)(2))(3);
(/*@__PURE__*/ h(1)(2)(3));
}
expect: {}
}
issue_2629_3: {
options = {
side_effects: true,
}
input: {
/*@__PURE__*/ a.x(1).y(2).z(3);
/*@__PURE__*/ (a.x)(1).y(2).z(3);
/*@__PURE__*/ (a.x(1)).y(2).z(3);
/*@__PURE__*/ (a.x(1).y)(2).z(3);
/*@__PURE__*/ (a.x(1).y(2)).z(3);
/*@__PURE__*/ (a.x(1).y(2).z)(3);
/*@__PURE__*/ (a.x(1).y(2).z(3));
(/*@__PURE__*/ a).x(1).y(2).z(3);
(/*@__PURE__*/ a.x)(1).y(2).z(3);
(/*@__PURE__*/ a.x(1)).y(2).z(3);
(/*@__PURE__*/ a.x(1).y)(2).z(3);
(/*@__PURE__*/ a.x(1).y(2)).z(3);
(/*@__PURE__*/ a.x(1).y(2).z)(3);
(/*@__PURE__*/ a.x(1).y(2).z(3));
}
expect: {}
}
issue_2629_4: {
options = {
side_effects: true,
}
input: {
(/*@__PURE__*/ x(), y());
(w(), /*@__PURE__*/ x(), y());
}
expect: {
y();
w(), y();
}
}
issue_2629_5: {
options = {
side_effects: true,
}
input: {
[ /*@__PURE__*/ x() ];
[ /*@__PURE__*/ x(), y() ];
[ w(), /*@__PURE__*/ x(), y() ];
}
expect: {
y();
w(), y();
}
}