Remove whitespace generation (#5833)
* Remove whitespace generation and rely on default printing Changes to printing: * Add newline after last empty SwitchCase * Add newlines around block comments if they are non-flow comments or contain newlines * Fix a few more fixtures
This commit is contained in:
committed by
Brian Ng
parent
bc29145465
commit
b3372a572d
@@ -1,9 +1,7 @@
|
||||
var code = [
|
||||
'var foo = 1;',
|
||||
'if (x) {',
|
||||
' const bar = 1;',
|
||||
'}',
|
||||
].join('\n');
|
||||
var code = `var foo = 1;
|
||||
if (x) {
|
||||
const bar = 1;
|
||||
}`;
|
||||
|
||||
var innerScope = true;
|
||||
var res = transform(code, {
|
||||
@@ -29,11 +27,10 @@ var res = transform(code, {
|
||||
]),
|
||||
});
|
||||
|
||||
var expected = [
|
||||
'var foo = 1;',
|
||||
'if (x) {',
|
||||
' var bar = 1;',
|
||||
'}',
|
||||
].join('\n');
|
||||
var expected = `var foo = 1;
|
||||
|
||||
if (x) {
|
||||
var bar = 1;
|
||||
}`;
|
||||
|
||||
assert.equal(res.code, expected);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
fns.push(function () {
|
||||
return i;
|
||||
});
|
||||
|
||||
if (i === 1) {
|
||||
return "continue";
|
||||
} else if (i === 2) {
|
||||
|
||||
@@ -2,6 +2,7 @@ var _loop = function (_i) {
|
||||
(function () {
|
||||
_i;
|
||||
});
|
||||
|
||||
console.log(_i);
|
||||
_i += 1;
|
||||
i = _i;
|
||||
@@ -9,4 +10,4 @@ var _loop = function (_i) {
|
||||
|
||||
for (var i = 0; i < 2; i++) {
|
||||
_loop(i);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
var _loop = function (i) {
|
||||
x = 5;
|
||||
({ f } = { f: 2 });
|
||||
|
||||
({
|
||||
f
|
||||
} = {
|
||||
f: 2
|
||||
});
|
||||
fns.push(function () {
|
||||
return i * x;
|
||||
});
|
||||
@@ -32,4 +35,4 @@ try {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ foo.func1 = function () {
|
||||
if (cond2) {
|
||||
var _ret = function () {
|
||||
function func2() {}
|
||||
|
||||
function func3() {}
|
||||
|
||||
func4(function () {
|
||||
func2();
|
||||
});
|
||||
@@ -15,4 +17,4 @@ foo.func1 = function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
var arr = [];
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
var _loop = function (_i) {
|
||||
arr.push(function () {
|
||||
@@ -9,4 +10,4 @@ for (var i = 0; i < 10; i++) {
|
||||
for (var _i = 0; _i < 10; _i++) {
|
||||
_loop(_i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// #1683
|
||||
|
||||
var arr = [];
|
||||
|
||||
for (var i = 0; i < 4; ++i) {
|
||||
arr.push(React.createElement("i", null));
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,24 @@ var x = void 0,
|
||||
y = void 0;
|
||||
{
|
||||
a: var _x = void 0;
|
||||
|
||||
var _y = void 0;
|
||||
}
|
||||
|
||||
switch (0) {
|
||||
case 0:
|
||||
a: var _x2 = 0;
|
||||
}
|
||||
|
||||
// it should break from inside of switch statements using labels
|
||||
} // it should break from inside of switch statements using labels
|
||||
|
||||
|
||||
var _loop = function () {
|
||||
var z = 3; // force loop function
|
||||
|
||||
(function () {
|
||||
return z;
|
||||
});
|
||||
|
||||
switch (true) {
|
||||
case true:
|
||||
return "break|loop";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
function foo() {
|
||||
var x = 5;
|
||||
console.log(x);
|
||||
|
||||
{
|
||||
var _x = 7;
|
||||
setTimeout(function () {
|
||||
@@ -37,6 +36,7 @@ function baz() {
|
||||
return x;
|
||||
}, 0);
|
||||
};
|
||||
|
||||
qux(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
var f1, f2;
|
||||
{
|
||||
var z = 'z1 value';
|
||||
|
||||
f1 = function () {
|
||||
return z;
|
||||
};
|
||||
}
|
||||
{
|
||||
var _z = 'z2 value';
|
||||
|
||||
f2 = function () {
|
||||
return _z;
|
||||
};
|
||||
|
||||
@@ -4,12 +4,15 @@ function fn() {
|
||||
switch (true) {
|
||||
default:
|
||||
var foo = 4;
|
||||
|
||||
if (true) {
|
||||
var bar = function () {
|
||||
return foo;
|
||||
};
|
||||
|
||||
console.log(bar());
|
||||
}
|
||||
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ var _loop = function () {
|
||||
}
|
||||
|
||||
var z = 3; // to force the plugin to convert to loop function call
|
||||
|
||||
(function () {
|
||||
return z;
|
||||
});
|
||||
@@ -17,9 +18,8 @@ for (i = 0; i < 10; i++) {
|
||||
_loop();
|
||||
}
|
||||
|
||||
assert.equal(i, 10);
|
||||
assert.equal(i, 10); // it should continue on continue statements within switch
|
||||
|
||||
// it should continue on continue statements within switch
|
||||
var j = 0;
|
||||
|
||||
var _loop2 = function () {
|
||||
@@ -27,9 +27,10 @@ var _loop2 = function () {
|
||||
case 0:
|
||||
return "continue";
|
||||
}
|
||||
j++;
|
||||
|
||||
j++;
|
||||
var z = 3;
|
||||
|
||||
(function () {
|
||||
return z;
|
||||
});
|
||||
@@ -41,9 +42,8 @@ for (i = 0; i < 10; i++) {
|
||||
if (_ret === "continue") continue;
|
||||
}
|
||||
|
||||
assert.equal(j, 9);
|
||||
assert.equal(j, 9); // it should work with loops nested within switch
|
||||
|
||||
// it should work with loops nested within switch
|
||||
j = 0;
|
||||
|
||||
var _loop3 = function () {
|
||||
@@ -51,9 +51,11 @@ var _loop3 = function () {
|
||||
case 0:
|
||||
var _loop4 = function () {
|
||||
var z = 3;
|
||||
|
||||
(function () {
|
||||
return z;
|
||||
});
|
||||
|
||||
j++;
|
||||
return "break";
|
||||
};
|
||||
@@ -63,10 +65,12 @@ var _loop3 = function () {
|
||||
|
||||
if (_ret2 === "break") break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
var z = 3;
|
||||
|
||||
(function () {
|
||||
return z;
|
||||
});
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
var a = true;
|
||||
var b = false;
|
||||
|
||||
class e {}
|
||||
|
||||
function f() {}
|
||||
|
||||
switch (a) {
|
||||
@@ -8,6 +10,7 @@ switch (a) {
|
||||
var c = 2;
|
||||
var foo = true;
|
||||
break;
|
||||
|
||||
case false:
|
||||
var d = 3;
|
||||
foo = false;
|
||||
@@ -26,4 +29,4 @@ switch (true) {
|
||||
|
||||
var _f = function () {};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,5 @@ var _loop = function (_a) {
|
||||
for (var _a = 1; _a < 100; _a++) {
|
||||
_loop(_a);
|
||||
}
|
||||
console.log(a);
|
||||
|
||||
console.log(a);
|
||||
Reference in New Issue
Block a user