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:
Daniel Tschinder
2017-06-27 19:57:02 -07:00
committed by Brian Ng
parent bc29145465
commit b3372a572d
379 changed files with 1974 additions and 1109 deletions

View File

@@ -1,4 +1,5 @@
var x = "outside";
function outer() {
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
return eval("x");
@@ -8,4 +9,5 @@ function outer() {
return a();
}();
}
outer();

View File

@@ -1,7 +1,6 @@
var Ref = function Ref() {
var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ++Ref.nextID;
babelHelpers.classCallCheck(this, Ref);
this.id = id;
};

View File

@@ -1,13 +1,11 @@
var Ref = function Ref() {
var ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Ref;
babelHelpers.classCallCheck(this, Ref);
this.ref = ref;
};
var X = function X() {
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : foo;
babelHelpers.classCallCheck(this, X);
this.x = x;
};
};

View File

@@ -1,12 +1,10 @@
var t = function () {
var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "foo";
var f = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
return e + " bar " + f;
};
var a = function (e) {
var f = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
return e + " bar " + f;
};

View File

@@ -1,21 +1,22 @@
var a = 1;
function rest() {
var b = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : a;
assert.equal(b, 1);
}
rest(undefined, 2);
function rest2() {
var b = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : a;
assert.equal(arguments.length <= 1 ? undefined : arguments[1], 2);
}
rest2(undefined, 2);
function rest3() {
var b = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : a;
assert.equal(arguments.length <= 1 ? 0 : arguments.length - 1, 1);
}
rest3(undefined, 2);
rest3(undefined, 2);

View File

@@ -1,5 +1,4 @@
var t = function () {
var f = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "foo";
return f + " bar";
};

View File

@@ -1,8 +1,9 @@
var args = 'bar';
function foo() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return args;
}
}

View File

@@ -6,5 +6,6 @@ let oneOf = function () {
if (nodes.length === 1) {
return nodes[0];
}
return new OneOfNode(nodes);
};
};

View File

@@ -6,14 +6,18 @@ var concat = function () {
var somefun = function () {
var get2ndArg = function (a, b) {
var _b = arguments.length <= 2 ? undefined : arguments[2];
var somef = function (x, y, z) {
var _a = arguments.length <= 3 ? undefined : arguments[3];
};
var somefg = function (c, d, e, f) {
var _a = arguments.length <= 4 ? undefined : arguments[4];
};
var _d = arguments.length <= 3 ? undefined : arguments[3];
};
var get3rdArg = function () {
return arguments.length <= 2 ? undefined : arguments[2];
};
@@ -50,4 +54,4 @@ var innerclassproperties = function () {
babelHelpers.classCallCheck(this, _class);
this.args = args;
}, _class.args = args, _temp;
};
};

View File

@@ -7,9 +7,9 @@ function r() {
}
return rest;
}
} // multiple references
// multiple references
function r() {
if (noNeedToWork) return 0;
@@ -19,9 +19,9 @@ function r() {
rest;
rest;
}
} // multiple nested references
// multiple nested references
function r() {
if (noNeedToWork) return 0;
@@ -34,9 +34,9 @@ function r() {
} else {
return rest;
}
}
} // deeply nested
// deeply nested
function r() {
if (true) {
for (var _len4 = arguments.length, rest = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
@@ -49,9 +49,9 @@ function r() {
return rest;
}
}
}
} // nested reference with root reference
// nested reference with root reference
function r() {
if (noNeedToWork) return 0;
@@ -61,9 +61,9 @@ function r() {
if (lol) rest;
rest;
}
} // nested functions
// nested functions
function a() {
for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
@@ -74,9 +74,9 @@ function a() {
console.log("Shouldn't args be from a's scope?", args);
};
}
} // loop
// loop
function runQueue(queue) {
for (var _len7 = arguments.length, args = Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
args[_key7 - 1] = arguments[_key7];
@@ -85,9 +85,9 @@ function runQueue(queue) {
for (var i = 0; i < queue.length; i++) {
queue[i].apply(queue, args);
}
}
} // nested loop
// nested loop
function runQueue(queue) {
if (foo) {
for (var _len8 = arguments.length, args = Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
@@ -112,6 +112,5 @@ function r() {
var _x2 = babelHelpers.slicedToArray(_x, 1);
rest[0] = _x2[0];
return rest;
}
}

View File

@@ -132,10 +132,10 @@ function newExp() {
}
new rest[0]();
}
// In addition to swap() above because at some point someone tried checking
} // In addition to swap() above because at some point someone tried checking
// grandparent path for isArrayExpression() to deopt.
function arrayDestructure() {
for (var _len15 = arguments.length, rest = Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
rest[_key15] = arguments[_key15];

View File

@@ -10,13 +10,15 @@ function t() {
function t() {
var a = [];
for (var i = 0; i < arguments.length; i++) {
a.push(i);
}
return a;
}
// https://github.com/babel/babel/pull/2833#issuecomment-166039291
return a;
} // https://github.com/babel/babel/pull/2833#issuecomment-166039291
function t() {
for (var _len = arguments.length, items = Array(_len), _key = 0; _key < _len; _key++) {
items[_key] = arguments[_key];
@@ -25,4 +27,4 @@ function t() {
for (var i = 0; i < items.length; i++) {
return items[i];
}
}
}

View File

@@ -2,6 +2,7 @@ function a() {
var foo = function () {
return bar.apply(undefined, arguments);
};
foo.apply(undefined, arguments);
}
@@ -9,6 +10,7 @@ function b() {
var foo = function () {
return bar.apply(undefined, arguments);
};
foo.apply(undefined, arguments);
}
@@ -16,6 +18,7 @@ function c() {
var foo = function () {
return bar.apply(undefined, arguments);
};
foo([]);
}
@@ -23,6 +26,7 @@ function d(thing) {
var foo = function () {
return bar.apply(undefined, arguments);
};
{
var _args = thing;
foo(thing);

View File

@@ -1,10 +1,8 @@
// optimisation
function foo() {
foo.apply(undefined, arguments);
}
} // deoptimisation
// deoptimisation
function foo(a) {
for (var _len = arguments.length, b = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -29,4 +27,4 @@ function foo() {
args.pop();
foo.apply(undefined, args);
}
}