codegen: Don't emit newline after a block comment (#1062)

This commit is contained in:
강동윤 2020-09-11 15:09:35 +09:00 committed by GitHub
parent 09e3f96a3e
commit 2fff66d985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 74 additions and 147 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "swc_ecma_codegen"
version = "0.35.1"
version = "0.35.2"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git"

View File

@ -25,7 +25,7 @@ macro_rules! write_comments {
$e.wr.write_comment(cmt.span, "/*")?;
$e.wr.write_comment(cmt.span, &cmt.text)?;
$e.wr.write_comment(cmt.span, "*/")?;
$e.wr.write_line()?;
$e.wr.write_space()?;
}
}
}

View File

@ -144,12 +144,7 @@ b; // bar",
#[test]
fn comment_4() {
test_from_to(
"/** foo */
a",
"/** foo */
a;",
);
test_from_to("/** foo */ a", "/** foo */ a;");
}
#[test]

View File

@ -1,7 +1,5 @@
a.b('c').d('e', /*@ngInject*/
function(f) {
a.b('c').d('e', /*@ngInject*/ function(f) {
return f;
}).g('h', /*@ngInject*/
function(i) {
}).g('h', /*@ngInject*/ function(i) {
return i;
});

View File

@ -1,3 +1,2 @@
/*a
b*/
1;
b*/ 1;

View File

@ -1,5 +1,5 @@
function a() {
while(true){
} /* bar */
} /* bar */
var b;
}

View File

@ -1,6 +1,5 @@
while(true){
break;
/* Multiline
Comment */
a;
Comment */ a;
}

View File

@ -1,5 +1,4 @@
switch(a){
case 1:
/* perfect */
b();
/* perfect */ b();
}

View File

@ -1,5 +1,4 @@
b: while(1){
continue;
/**/
a;
/**/ a;
}

View File

@ -1,5 +1,4 @@
/**/
function a() {
/**/ function a() {
function b() {
}
}

View File

@ -1,2 +1 @@
/*Venus*/
debugger; // Mars
/*Venus*/ debugger; // Mars

View File

@ -1,6 +1,5 @@
(function() {
return;
/* Multiline
Comment */
a;
Comment */ a;
});

View File

@ -1 +1 @@
1; /* the * answer */
1; /* the * answer */

View File

@ -1,5 +1,4 @@
/**/
function a() {
/**/ function a() {
function b() {
}
}

View File

@ -1,4 +1,3 @@
/* header */
(function() {
/* header */ (function() {
var a = 1;
}).b(this);

View File

@ -1,5 +1,4 @@
b: while(1){
continue;
/**/
a;
/**/ a;
}

View File

@ -1 +1 @@
1; /**/
1; /**/

View File

@ -1,2 +1 @@
(a + /* assignment */
b) * c;
(a + /* assignment */ b) * c;

View File

@ -1,5 +1,4 @@
(/* comment */
{
(/* comment */ {
a: null,
b: null
});

View File

@ -1,6 +1,5 @@
b: while(1){
continue;
/*
*/
a;
*/ a;
}

View File

@ -1,3 +1,2 @@
/**/
function a() {
/**/ function a() {
}

View File

@ -1,4 +1,3 @@
(/* comment */
{
(/* comment */ {
a: null
});

View File

@ -1,4 +1,3 @@
/**
* @type {number}
*/
var a = 1;
*/ var a = 1;

View File

@ -1,2 +1 @@
1; /*the*/
/*answer*/
1; /*the*/ /*answer*/

View File

@ -1,2 +1 @@
1; /*The*/
/*Answer*/
1; /*The*/ /*Answer*/

View File

@ -1,3 +1,2 @@
/*a
c*/
1;
c*/ 1;

View File

@ -1,5 +1,5 @@
{
throw a; /* Multiline
Comment */
Comment */
a;
}

View File

@ -1,3 +1,2 @@
/*a
b*/
1;
b*/ 1;

View File

@ -1,6 +1,5 @@
while(true){
continue;
/* Multiline
Comment */
a;
Comment */ a;
}

View File

@ -1,5 +1,3 @@
(/* comment */
{
/* comment 2 */
a: null
(/* comment */ {
/* comment 2 */ a: null
});

View File

@ -1,2 +1 @@
throw /* */
a;
throw /* */ a;

View File

@ -5,18 +5,14 @@
insert something
there, but I'm sort
of lazy so whatever.
*/
a = new c();
*/ a = new c();
return a;
})()(function() {
var a;
if (b) return;
/* I would insert something there, */
/*
/* I would insert something there, */ /*
but I'm sort of lazy so
*/
/* whatever. */
a = new c();
*/ /* whatever. */ a = new c();
return a;
})()(function() {
var a;

View File

@ -1 +1 @@
1; /* The * answer */
1; /* The * answer */

View File

@ -1,7 +1,5 @@
/**
* @type {number}
*/
var a = 1, /**
*/ var a = 1, /**
* @type {number}
*/
b = 2;
*/ b = 2;

View File

@ -2,5 +2,4 @@
comment
should
be
ignored */
1;
ignored */ 1;

View File

@ -1,2 +1 @@
/* block comment */
1;
/* block comment */ 1;

View File

@ -1,3 +1,3 @@
(function() {
var a = 1; /* sync */
var a = 1; /* sync */
}).b(this);

View File

@ -1,2 +1 @@
/*a b*/
1;
/*a b*/ 1;

View File

@ -1,4 +1,3 @@
/*@ngInject*/
var a = function(b) {
/*@ngInject*/ var a = function(b) {
return b;
};

View File

@ -1,2 +1 @@
var a; /* block comment 1 */
/* block comment 2 */
var a; /* block comment 1 */ /* block comment 2 */

View File

@ -1,5 +1,4 @@
b: while(1){
continue;
/* */
a;
/* */ a;
}

View File

@ -1,2 +1 @@
/**/
1;
/**/ 1;

View File

@ -1,4 +1,3 @@
/*@ngInject*/
function a(b) {
/*@ngInject*/ function a(b) {
return b;
}

View File

@ -1,2 +1 @@
var a/* comment */
;
var a/* comment */ ;

View File

@ -1,2 +1 @@
1; /* block comment 1 */
/* block comment 2 */
1; /* block comment 1 */ /* block comment 2 */

View File

@ -1,3 +1,3 @@
function a() {
return; /*Saturn*/
return; /*Saturn*/
}

View File

@ -1,6 +1,5 @@
b: while(1){
continue;
/*
*/
a;
*/ a;
}

View File

@ -1,3 +1,2 @@
/* not comment*/
;
/* not comment*/ ;
a-- > 1;

View File

@ -18,11 +18,9 @@ var load = __spack_require__.bind(void 0, function(module, exports) {
* node-progress
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
/**
*/ /**
* Expose `ProgressBar`.
*/
{
*/ {
exports1 = module1.exports = ProgressBar;
/**
* Initialize a `ProgressBar` with the given `fmt` string and `options` or
@ -54,8 +52,7 @@ var load = __spack_require__.bind(void 0, function(module, exports) {
* @param {string} fmt
* @param {object|number} options or total
* @api public
*/
function ProgressBar(fmt, options) {
*/ function ProgressBar(fmt, options) {
this.stream = options.stream || process.stderr;
if (typeof options == 'number') {
var total = options;
@ -92,8 +89,7 @@ var load = __spack_require__.bind(void 0, function(module, exports) {
* @param {number|object} len or tokens
* @param {object} tokens
* @api public
*/
ProgressBar.prototype.tick = function(len, tokens) {
*/ ProgressBar.prototype.tick = function(len, tokens) {
if (len !== 0) len = len || 1;
// swap tokens
if ('object' == typeof len) tokens = len, len = 1;
@ -118,8 +114,7 @@ var load = __spack_require__.bind(void 0, function(module, exports) {
*
* @param {object} tokens
* @api public
*/
ProgressBar.prototype.render = function(tokens, force) {
*/ ProgressBar.prototype.render = function(tokens, force) {
force = force !== undefined ? force : false;
if (tokens) this.tokens = tokens;
if (!this.stream.isTTY) return;
@ -134,22 +129,16 @@ var load = __spack_require__.bind(void 0, function(module, exports) {
var elapsed = new Date - this.start;
var eta = percent == 100 ? 0 : elapsed * (this.total / this.curr - 1);
var rate = this.curr / (elapsed / 1000);
/* populate the bar template with percentages and timestamps */
var str = this.fmt.replace(':current', this.curr).replace(':total', this.total).replace(':elapsed', isNaN(elapsed) ? '0.0' : (elapsed / 1000).toFixed(1)).replace(':eta', isNaN(eta) || !isFinite(eta) ? '0.0' : (eta / 1000).toFixed(1)).replace(':percent', percent.toFixed(0) + '%').replace(':rate', Math.round(rate));
/* compute the available space (non-zero) for the bar */
var availableSpace = Math.max(0, this.stream.columns - str.replace(':bar', '').length);
/* populate the bar template with percentages and timestamps */ var str = this.fmt.replace(':current', this.curr).replace(':total', this.total).replace(':elapsed', isNaN(elapsed) ? '0.0' : (elapsed / 1000).toFixed(1)).replace(':eta', isNaN(eta) || !isFinite(eta) ? '0.0' : (eta / 1000).toFixed(1)).replace(':percent', percent.toFixed(0) + '%').replace(':rate', Math.round(rate));
/* compute the available space (non-zero) for the bar */ var availableSpace = Math.max(0, this.stream.columns - str.replace(':bar', '').length);
if (availableSpace && process.platform === 'win32') availableSpace = availableSpace - 1;
var width = Math.min(this.width, availableSpace);
/* TODO: the following assumes the user has one ':bar' token */
completeLength = Math.round(width * ratio);
/* TODO: the following assumes the user has one ':bar' token */ completeLength = Math.round(width * ratio);
complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);
incomplete = Array(Math.max(0, width - completeLength + 1)).join(this.chars.incomplete);
/* add head to the complete string */
if (completeLength > 0) complete = complete.slice(0, -1) + this.chars.head;
/* fill in the actual progress bar */
str = str.replace(':bar', complete + incomplete);
/* replace the extra tokens */
if (this.tokens) for(var key in this.tokens)str = str.replace(':' + key, this.tokens[key]);
/* add head to the complete string */ if (completeLength > 0) complete = complete.slice(0, -1) + this.chars.head;
/* fill in the actual progress bar */ str = str.replace(':bar', complete + incomplete);
/* replace the extra tokens */ if (this.tokens) for(var key in this.tokens)str = str.replace(':' + key, this.tokens[key]);
if (this.lastDraw !== str) {
this.stream.cursorTo(0);
this.stream.write(str);
@ -169,8 +158,7 @@ var load = __spack_require__.bind(void 0, function(module, exports) {
* @param {number} ratio The ratio (between 0 and 1 inclusive) to set the
* overall completion to.
* @api public
*/
ProgressBar.prototype.update = function(ratio, tokens) {
*/ ProgressBar.prototype.update = function(ratio, tokens) {
var goal = Math.floor(ratio * this.total);
var delta = goal - this.curr;
this.tick(delta, tokens);
@ -179,8 +167,7 @@ var load = __spack_require__.bind(void 0, function(module, exports) {
* "interrupt" the progress bar and write a message above it.
* @param {string} message The message to write.
* @api public
*/
ProgressBar.prototype.interrupt = function(message) {
*/ ProgressBar.prototype.interrupt = function(message) {
// clear the current line
this.stream.clearLine();
// move the cursor to the start of the line
@ -196,8 +183,7 @@ var load = __spack_require__.bind(void 0, function(module, exports) {
* Terminates a progress bar.
*
* @api public
*/
ProgressBar.prototype.terminate = function() {
*/ ProgressBar.prototype.terminate = function() {
if (this.clear) {
if (this.stream.clearLine) {
this.stream.clearLine();

View File

@ -1,4 +1,3 @@
/**
* Don't ask why it is named as divider.
*/
export var Divider = React.createElement("div", null);
*/ export var Divider = React.createElement("div", null);

View File

@ -329,21 +329,12 @@ fn issue_532() {
assert_eq!(
f,
"\
/*pre:1*/
test();
test(123/*post:3*/
);
test(/*pre:4*/
123);
test(/*pre:5*/
123/*post:6*/
);
test(/*pre:7*/
123,/*pre:8*/
456);
test(123/*post:9*/
,456/*post:10*/
);"
/*pre:1*/test();
test(123/*post:3*/);
test(/*pre:4*/123);
test(/*pre:5*/123/*post:6*/);
test(/*pre:7*/123,/*pre:8*/456);
test(123/*post:9*/,456/*post:10*/);"
)
}