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)
|
- [AwaitExpression](#awaitexpression)
|
||||||
- [ArrayExpression](#arrayexpression)
|
- [ArrayExpression](#arrayexpression)
|
||||||
- [ObjectExpression](#objectexpression)
|
- [ObjectExpression](#objectexpression)
|
||||||
- [ObjectProperty](#objectproperty)
|
- [ObjectMember](#objectmember)
|
||||||
- [ObjectMethod](#objectmethod)
|
- [ObjectProperty](#objectproperty)
|
||||||
|
- [ObjectMethod](#objectmethod)
|
||||||
- [RestProperty](#restproperty)
|
- [RestProperty](#restproperty)
|
||||||
- [SpreadProperty](#spreadproperty)
|
- [SpreadProperty](#spreadproperty)
|
||||||
- [FunctionExpression](#functionexpression)
|
- [FunctionExpression](#functionexpression)
|
||||||
@ -631,29 +632,32 @@ interface ObjectExpression <: Expression {
|
|||||||
|
|
||||||
An object expression.
|
An object expression.
|
||||||
|
|
||||||
### ObjectProperty
|
### ObjectMember
|
||||||
|
|
||||||
```js
|
```js
|
||||||
interface ObjectProperty <: Node {
|
interface ObjectMember <: Node {
|
||||||
type: "ObjectProperty";
|
|
||||||
key: Expression;
|
key: Expression;
|
||||||
computed: boolean;
|
computed: boolean;
|
||||||
value: Expression;
|
value: Expression;
|
||||||
shorthand: boolean;
|
|
||||||
decorators: [ Decorator ];
|
decorators: [ Decorator ];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### ObjectMethod
|
#### ObjectProperty
|
||||||
|
|
||||||
```js
|
```js
|
||||||
interface ObjectMethod <: Function {
|
interface ObjectProperty <: ObjectMember {
|
||||||
|
type: "ObjectProperty";
|
||||||
|
shorthand: boolean;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### ObjectMethod
|
||||||
|
|
||||||
|
```js
|
||||||
|
interface ObjectMethod <: ObjectMember, Function {
|
||||||
type: "ObjectMethod";
|
type: "ObjectMethod";
|
||||||
key: Expression;
|
|
||||||
computed: boolean;
|
|
||||||
value: Expression;
|
|
||||||
kind: "get" | "set" | "method";
|
kind: "get" | "set" | "method";
|
||||||
decorators: [ Decorator ];
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -101,7 +101,9 @@ export default class Buffer {
|
|||||||
|
|
||||||
rightBrace() {
|
rightBrace() {
|
||||||
this.newline(true);
|
this.newline(true);
|
||||||
//if (this.format.compact) this._removeLast(";");
|
if (this.format.compact && !this._lastPrintedIsEmptyStatement) {
|
||||||
|
this._removeLast(";");
|
||||||
|
}
|
||||||
this.push("}");
|
this.push("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -130,6 +130,7 @@ export let YieldExpression = buildYieldAwait("yield");
|
|||||||
export let AwaitExpression = buildYieldAwait("await");
|
export let AwaitExpression = buildYieldAwait("await");
|
||||||
|
|
||||||
export function EmptyStatement() {
|
export function EmptyStatement() {
|
||||||
|
this._lastPrintedIsEmptyStatement = true;
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +141,9 @@ export function ExpressionStatement(node: Object) {
|
|||||||
|
|
||||||
export function AssignmentPattern(node: Object) {
|
export function AssignmentPattern(node: Object) {
|
||||||
this.print(node.left, node);
|
this.print(node.left, node);
|
||||||
this.push(" = ");
|
this.space();
|
||||||
|
this.push("=");
|
||||||
|
this.space();
|
||||||
this.print(node.right, node);
|
this.print(node.right, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +160,6 @@ export function AssignmentExpression(node: Object, parent: Object) {
|
|||||||
this.print(node.left, node);
|
this.print(node.left, node);
|
||||||
|
|
||||||
let spaces = !this.format.compact || node.operator === "in" || node.operator === "instanceof";
|
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(" ");
|
if (spaces) this.push(" ");
|
||||||
|
|
||||||
this.push(node.operator);
|
this.push(node.operator);
|
||||||
@ -167,7 +169,11 @@ export function AssignmentExpression(node: Object, parent: Object) {
|
|||||||
// http://javascript.spec.whatwg.org/#comment-syntax
|
// http://javascript.spec.whatwg.org/#comment-syntax
|
||||||
spaces = node.operator === "<" &&
|
spaces = node.operator === "<" &&
|
||||||
t.isUnaryExpression(node.right, { prefix: true, 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(" ");
|
if (spaces) this.push(" ");
|
||||||
|
|||||||
@ -13,6 +13,8 @@ export default class Printer extends Buffer {
|
|||||||
print(node, parent, opts = {}) {
|
print(node, parent, opts = {}) {
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
|
this._lastPrintedIsEmptyStatement = false;
|
||||||
|
|
||||||
if (parent && parent._compact) {
|
if (parent && parent._compact) {
|
||||||
node._compact = true;
|
node._compact = true;
|
||||||
}
|
}
|
||||||
@ -144,12 +146,12 @@ export default class Printer extends Buffer {
|
|||||||
|
|
||||||
printBlock(parent) {
|
printBlock(parent) {
|
||||||
let node = parent.body;
|
let node = parent.body;
|
||||||
if (t.isEmptyStatement(node)) {
|
|
||||||
this.semicolon();
|
if (!t.isEmptyStatement(node)) {
|
||||||
} else {
|
this.space();
|
||||||
this.push(" ");
|
|
||||||
this.print(node, parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.print(node, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
generateComment(comment) {
|
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() {
|
function foo() {
|
||||||
|
var x = 1;
|
||||||
|
y();
|
||||||
if (bar) {
|
if (bar) {
|
||||||
baz();
|
baz();
|
||||||
}
|
}
|
||||||
return;
|
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){
|
function foo(l){
|
||||||
return (
|
return (
|
||||||
|
|
||||||
l);}
|
l)}
|
||||||
|
|||||||
@ -498,7 +498,7 @@ defineType("ObjectMethod", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"],
|
visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"],
|
||||||
aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method"]
|
aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"]
|
||||||
});
|
});
|
||||||
|
|
||||||
defineType("ObjectProperty", {
|
defineType("ObjectProperty", {
|
||||||
@ -527,7 +527,7 @@ defineType("ObjectProperty", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
visitor: ["key", "value", "decorators"],
|
visitor: ["key", "value", "decorators"],
|
||||||
aliases: ["UserWhitespacable", "Property"]
|
aliases: ["UserWhitespacable", "Property", "ObjectMember"]
|
||||||
});
|
});
|
||||||
|
|
||||||
defineType("RestElement", {
|
defineType("RestElement", {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user