Merge branch 'master' into hon2a/ie-error-stack
This commit is contained in:
commit
8df5a9d49e
@ -53,8 +53,9 @@ This document specifies the core ESTree AST node types that support the ES5 gram
|
||||
- [AwaitExpression](#awaitexpression)
|
||||
- [ArrayExpression](#arrayexpression)
|
||||
- [ObjectExpression](#objectexpression)
|
||||
- [ObjectProperty](#objectproperty)
|
||||
- [ObjectMethod](#objectmethod)
|
||||
- [ObjectMember](#objectmember)
|
||||
- [ObjectProperty](#objectproperty)
|
||||
- [ObjectMethod](#objectmethod)
|
||||
- [RestProperty](#restproperty)
|
||||
- [SpreadProperty](#spreadproperty)
|
||||
- [FunctionExpression](#functionexpression)
|
||||
@ -631,29 +632,32 @@ interface ObjectExpression <: Expression {
|
||||
|
||||
An object expression.
|
||||
|
||||
### ObjectProperty
|
||||
### ObjectMember
|
||||
|
||||
```js
|
||||
interface ObjectProperty <: Node {
|
||||
type: "ObjectProperty";
|
||||
interface ObjectMember <: Node {
|
||||
key: Expression;
|
||||
computed: boolean;
|
||||
value: Expression;
|
||||
shorthand: boolean;
|
||||
decorators: [ Decorator ];
|
||||
}
|
||||
```
|
||||
|
||||
### ObjectMethod
|
||||
#### ObjectProperty
|
||||
|
||||
```js
|
||||
interface ObjectMethod <: Function {
|
||||
interface ObjectProperty <: ObjectMember {
|
||||
type: "ObjectProperty";
|
||||
shorthand: boolean;
|
||||
}
|
||||
```
|
||||
|
||||
#### ObjectMethod
|
||||
|
||||
```js
|
||||
interface ObjectMethod <: ObjectMember, Function {
|
||||
type: "ObjectMethod";
|
||||
key: Expression;
|
||||
computed: boolean;
|
||||
value: Expression;
|
||||
kind: "get" | "set" | "method";
|
||||
decorators: [ Decorator ];
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@ -101,7 +101,9 @@ export default class Buffer {
|
||||
|
||||
rightBrace() {
|
||||
this.newline(true);
|
||||
//if (this.format.compact) this._removeLast(";");
|
||||
if (this.format.compact && !this._lastPrintedIsEmptyStatement) {
|
||||
this._removeLast(";");
|
||||
}
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
|
||||
@ -130,6 +130,7 @@ export let YieldExpression = buildYieldAwait("yield");
|
||||
export let AwaitExpression = buildYieldAwait("await");
|
||||
|
||||
export function EmptyStatement() {
|
||||
this._lastPrintedIsEmptyStatement = true;
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
@ -140,7 +141,9 @@ export function ExpressionStatement(node: Object) {
|
||||
|
||||
export function AssignmentPattern(node: Object) {
|
||||
this.print(node.left, node);
|
||||
this.push(" = ");
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
}
|
||||
|
||||
@ -157,7 +160,6 @@ export function AssignmentExpression(node: Object, parent: Object) {
|
||||
this.print(node.left, node);
|
||||
|
||||
let spaces = !this.format.compact || node.operator === "in" || node.operator === "instanceof";
|
||||
spaces = true; // todo: https://github.com/babel/babel/issues/1835
|
||||
if (spaces) this.push(" ");
|
||||
|
||||
this.push(node.operator);
|
||||
@ -167,7 +169,11 @@ export function AssignmentExpression(node: Object, parent: Object) {
|
||||
// http://javascript.spec.whatwg.org/#comment-syntax
|
||||
spaces = node.operator === "<" &&
|
||||
t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) &&
|
||||
t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" });
|
||||
t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" }) ||
|
||||
// Need spaces for operators of the same kind to avoid: `a+++b`
|
||||
t.isUnaryExpression(node.right, { prefix: true, operator: node.operator }) ||
|
||||
t.isUpdateExpression(node.right, { prefix: true, operator: node.operator + node.operator });
|
||||
|
||||
}
|
||||
|
||||
if (spaces) this.push(" ");
|
||||
|
||||
@ -13,6 +13,8 @@ export default class Printer extends Buffer {
|
||||
print(node, parent, opts = {}) {
|
||||
if (!node) return;
|
||||
|
||||
this._lastPrintedIsEmptyStatement = false;
|
||||
|
||||
if (parent && parent._compact) {
|
||||
node._compact = true;
|
||||
}
|
||||
@ -144,12 +146,12 @@ export default class Printer extends Buffer {
|
||||
|
||||
printBlock(parent) {
|
||||
let node = parent.body;
|
||||
if (t.isEmptyStatement(node)) {
|
||||
this.semicolon();
|
||||
} else {
|
||||
this.push(" ");
|
||||
this.print(node, parent);
|
||||
|
||||
if (!t.isEmptyStatement(node)) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node, parent);
|
||||
}
|
||||
|
||||
generateComment(comment) {
|
||||
|
||||
2
packages/babel-generator/test/fixtures/compact/assignment/actual.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/compact/assignment/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
x = 1;
|
||||
var { y = 1 } = obj;
|
||||
1
packages/babel-generator/test/fixtures/compact/assignment/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/compact/assignment/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
x=1;var {y=1}=obj;
|
||||
4
packages/babel-generator/test/fixtures/compact/binary-expressions/actual.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/compact/binary-expressions/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
1 * 1;
|
||||
1 && 1;
|
||||
1 + +1;
|
||||
x + ++y;
|
||||
1
packages/babel-generator/test/fixtures/compact/binary-expressions/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/compact/binary-expressions/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
1*1;1&&1;1+ +1;x+ ++y;
|
||||
@ -1,6 +1,12 @@
|
||||
function foo() {
|
||||
var x = 1;
|
||||
y();
|
||||
if (bar) {
|
||||
baz();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function bar() {
|
||||
for(;;);
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
function foo(){if(bar){baz();}return;}
|
||||
function foo(){var x=1;y();if(bar){baz()}return}function bar(){for(;;);}
|
||||
|
||||
1
packages/babel-generator/test/fixtures/compact/while/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/compact/while/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
while(true) x();
|
||||
1
packages/babel-generator/test/fixtures/compact/while/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/compact/while/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
while(true)x();
|
||||
@ -1,4 +1,4 @@
|
||||
function foo(l){
|
||||
return (
|
||||
|
||||
l);}
|
||||
l)}
|
||||
|
||||
@ -498,7 +498,7 @@ defineType("ObjectMethod", {
|
||||
}
|
||||
},
|
||||
visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"],
|
||||
aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method"]
|
||||
aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"]
|
||||
});
|
||||
|
||||
defineType("ObjectProperty", {
|
||||
@ -527,7 +527,7 @@ defineType("ObjectProperty", {
|
||||
}
|
||||
},
|
||||
visitor: ["key", "value", "decorators"],
|
||||
aliases: ["UserWhitespacable", "Property"]
|
||||
aliases: ["UserWhitespacable", "Property", "ObjectMember"]
|
||||
});
|
||||
|
||||
defineType("RestElement", {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user