6.0.0
I'm extremely stupid and didn't commit as I go. To anyone reading this I'm extremely sorry. A lot of these changes are very broad and I plan on releasing Babel 6.0.0 today live on stage at Ember Camp London so I'm afraid I couldn't wait. If you're ever in London I'll buy you a beer (or assorted beverage!) to make up for it, also I'll kiss your feet and give you a back massage, maybe.
This commit is contained in:
@@ -6,7 +6,10 @@ export function File(node: Object) {
|
||||
|
||||
export function Program(node: Object) {
|
||||
this.printInnerComments(node, false);
|
||||
|
||||
this.printSequence(node.directives, node);
|
||||
if (node.directives && node.directives.length) this.newline();
|
||||
|
||||
this.printSequence(node.body, node);
|
||||
}
|
||||
|
||||
@@ -15,7 +18,10 @@ export function BlockStatement(node: Object) {
|
||||
this.printInnerComments(node);
|
||||
if (node.body.length) {
|
||||
this.newline();
|
||||
|
||||
this.printSequence(node.directives, node, { indent: true });
|
||||
if (node.directives && node.directives.length) this.newline();
|
||||
|
||||
this.printSequence(node.body, node, { indent: true });
|
||||
if (!this.format.retainLines) this.removeLast("\n");
|
||||
this.rightBrace();
|
||||
|
||||
@@ -59,12 +59,16 @@ export function ClassProperty(node: Object) {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function MethodDefinition(node: Object) {
|
||||
export function ClassMethod(node: Object) {
|
||||
this.printJoin(node.decorators, node, { separator: "" });
|
||||
|
||||
if (node.static) {
|
||||
this.push("static ");
|
||||
}
|
||||
|
||||
if (node.kind === "constructorCall") {
|
||||
this.push("call ");
|
||||
}
|
||||
|
||||
this._method(node);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import isInteger from "is-integer";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import * as t from "babel-types";
|
||||
import n from "../node";
|
||||
|
||||
const SCIENTIFIC_NOTATION = /e/i;
|
||||
|
||||
@@ -107,7 +108,7 @@ export function CallExpression(node: Object) {
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
function buildYieldAwait(keyword) {
|
||||
function buildYieldAwait(keyword: string) {
|
||||
return function (node: Object) {
|
||||
this.push(keyword);
|
||||
|
||||
@@ -142,7 +143,16 @@ export function AssignmentPattern(node: Object) {
|
||||
this.print(node.right, node);
|
||||
}
|
||||
|
||||
export function AssignmentExpression(node: Object) {
|
||||
export function AssignmentExpression(node: Object, parent: Object) {
|
||||
// Somewhere inside a for statement `init` node but doesn't usually
|
||||
// needs a paren except for `in` expressions: `for (a in b ? a : b;;)`
|
||||
let parens = this._inForStatementInit && node.operator === "in" &&
|
||||
!n.needsParens(node, parent);
|
||||
|
||||
if (parens) {
|
||||
this.push("(");
|
||||
}
|
||||
|
||||
this.print(node.left, node);
|
||||
|
||||
let spaces = !this.format.compact || node.operator === "in" || node.operator === "instanceof";
|
||||
@@ -162,6 +172,10 @@ export function AssignmentExpression(node: Object) {
|
||||
if (spaces) this.push(" ");
|
||||
|
||||
this.print(node.right, node);
|
||||
|
||||
if (parens) {
|
||||
this.push(")");
|
||||
}
|
||||
}
|
||||
|
||||
export function BindExpression(node: Object) {
|
||||
@@ -193,7 +207,7 @@ export function MemberExpression(node: Object) {
|
||||
this.push("]");
|
||||
} else {
|
||||
if (t.isLiteral(node.object)) {
|
||||
let val = this._stringLiteral(node.object);
|
||||
let val = this.getPossibleRaw(node.object) || this._stringLiteral(node.object);
|
||||
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !this.endsWith(".")) {
|
||||
this.push(".");
|
||||
}
|
||||
|
||||
@@ -19,12 +19,11 @@ export function _params(node: Object) {
|
||||
}
|
||||
|
||||
export function _method(node: Object) {
|
||||
let value = node.value;
|
||||
let kind = node.kind;
|
||||
let key = node.key;
|
||||
let kind = node.kind;
|
||||
let key = node.key;
|
||||
|
||||
if (kind === "method" || kind === "init") {
|
||||
if (value.generator) {
|
||||
if (node.generator) {
|
||||
this.push("*");
|
||||
}
|
||||
}
|
||||
@@ -33,7 +32,7 @@ export function _method(node: Object) {
|
||||
this.push(kind + " ");
|
||||
}
|
||||
|
||||
if (value.async) this.push("async ");
|
||||
if (node.async) this.push("async ");
|
||||
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
@@ -43,9 +42,9 @@ export function _method(node: Object) {
|
||||
this.print(key, node);
|
||||
}
|
||||
|
||||
this._params(value);
|
||||
this._params(node);
|
||||
this.space();
|
||||
this.print(value.body, value);
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
export function FunctionExpression(node: Object) {
|
||||
|
||||
@@ -64,13 +64,18 @@ function ExportDeclaration(node: Object) {
|
||||
|
||||
let specifiers = node.specifiers.slice(0);
|
||||
|
||||
let first = specifiers[0];
|
||||
// print "special" specifiers first
|
||||
let hasSpecial = false;
|
||||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
||||
hasSpecial = true;
|
||||
this.print(specifiers.shift(), node);
|
||||
if (specifiers.length) {
|
||||
this.push(", ");
|
||||
while (true) {
|
||||
let first = specifiers[0];
|
||||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
||||
hasSpecial = true;
|
||||
this.print(specifiers.shift(), node);
|
||||
if (specifiers.length) {
|
||||
this.push(", ");
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,11 +107,16 @@ export function ImportDeclaration(node: Object) {
|
||||
|
||||
let specifiers = node.specifiers.slice(0);
|
||||
if (specifiers && specifiers.length) {
|
||||
let first = specifiers[0];
|
||||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
||||
this.print(specifiers.shift(), node);
|
||||
if (specifiers.length) {
|
||||
this.push(", ");
|
||||
// print "special" specifiers first
|
||||
while (true) {
|
||||
let first = specifiers[0];
|
||||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
||||
this.print(specifiers.shift(), node);
|
||||
if (specifiers.length) {
|
||||
this.push(", ");
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,9 @@ export function ForStatement(node: Object) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
|
||||
this._inForStatementInit = true;
|
||||
this.print(node.init, node);
|
||||
this._inForStatementInit = false;
|
||||
this.push(";");
|
||||
|
||||
if (node.test) {
|
||||
|
||||
@@ -36,38 +36,39 @@ export function ObjectExpression(node: Object) {
|
||||
|
||||
export { ObjectExpression as ObjectPattern };
|
||||
|
||||
export function Property(node: Object) {
|
||||
export function ObjectMethod(node: Object) {
|
||||
this.printJoin(node.decorators, node, { separator: "" });
|
||||
this._method(node);
|
||||
}
|
||||
|
||||
export function ObjectProperty(node: Object) {
|
||||
this.printJoin(node.decorators, node, { separator: "" });
|
||||
|
||||
if (node.method || node.kind === "get" || node.kind === "set") {
|
||||
this._method(node);
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
this.print(node.key, node);
|
||||
this.push("]");
|
||||
} else {
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
this.print(node.key, node);
|
||||
this.push("]");
|
||||
} else {
|
||||
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});`
|
||||
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
|
||||
this.print(node.value, node);
|
||||
return;
|
||||
}
|
||||
|
||||
this.print(node.key, node);
|
||||
|
||||
// shorthand!
|
||||
if (node.shorthand &&
|
||||
(t.isIdentifier(node.key) &&
|
||||
t.isIdentifier(node.value) &&
|
||||
node.key.name === node.value.name)) {
|
||||
return;
|
||||
}
|
||||
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});`
|
||||
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
|
||||
this.print(node.value, node);
|
||||
return;
|
||||
}
|
||||
|
||||
this.push(":");
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
this.print(node.key, node);
|
||||
|
||||
// shorthand!
|
||||
if (node.shorthand &&
|
||||
(t.isIdentifier(node.key) &&
|
||||
t.isIdentifier(node.value) &&
|
||||
node.key.name === node.value.name)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.push(":");
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
|
||||
export function ArrayExpression(node: Object) {
|
||||
|
||||
Reference in New Issue
Block a user