Skip to content

Commit

Permalink
removing expression field from ArrowFunctionExpression (babel#6836)
Browse files Browse the repository at this point in the history
  • Loading branch information
shogunpurple authored and nicolo-ribaudo committed Nov 23, 2017
1 parent 1ef7e0f commit 6d820a2
Show file tree
Hide file tree
Showing 786 changed files with 728 additions and 1,533 deletions.
1 change: 0 additions & 1 deletion packages/babylon/ast/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ A `this` expression.
interface ArrowFunctionExpression <: Function, Expression {
type: "ArrowFunctionExpression";
body: BlockStatement | Expression;
expression: boolean;
}
```

Expand Down
14 changes: 5 additions & 9 deletions packages/babylon/src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,6 @@ export default class ExpressionParser extends LValParser {
initFunction(node: N.BodilessFunctionOrMethodBase, isAsync: ?boolean): void {
node.id = null;
node.generator = false;
node.expression = false;
node.async = !!isAsync;
}

Expand Down Expand Up @@ -1559,11 +1558,10 @@ export default class ExpressionParser extends LValParser {
);
}

isStrictBody(
node: { body: N.BlockStatement },
isExpression: ?boolean,
): boolean {
if (!isExpression && node.body.directives.length) {
isStrictBody(node: { body: N.BlockStatement }): boolean {
const isBlockStatement = node.body.type === "BlockStatement";

if (isBlockStatement && node.body.directives.length) {
for (const directive of node.body.directives) {
if (directive.value.value === "use strict") {
return true;
Expand Down Expand Up @@ -1595,7 +1593,6 @@ export default class ExpressionParser extends LValParser {

if (isExpression) {
node.body = this.parseMaybeAssign();
node.expression = true;
} else {
// Start a new scope with regard to labels and the `inGenerator`
// flag (restore them to their old value afterwards).
Expand All @@ -1606,7 +1603,6 @@ export default class ExpressionParser extends LValParser {
this.state.inFunction = true;
this.state.labels = [];
node.body = this.parseBlock(true);
node.expression = false;
this.state.inFunction = oldInFunc;
this.state.inGenerator = oldInGen;
this.state.labels = oldLabels;
Expand All @@ -1624,7 +1620,7 @@ export default class ExpressionParser extends LValParser {
// If this is a strict mode function, verify that argument names
// are not repeated, and it does not try to bind the words `eval`
// or `arguments`.
const isStrict = this.isStrictBody(node, node.expression);
const isStrict = this.isStrictBody(node);
// Also check for arrow functions
const checkLVal = this.state.strict || isStrict || isArrowFunction;

Expand Down
22 changes: 17 additions & 5 deletions packages/babylon/src/plugins/estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// Overrides
// ==================================

initFunction(
node: N.BodilessFunctionOrMethodBase,
isAsync: ?boolean,
): void {
super.initFunction(node, isAsync);
node.expression = false;
}

checkDeclaration(node: N.Pattern): void {
if (isSimpleProperty(node)) {
// $FlowFixMe
Expand Down Expand Up @@ -128,11 +136,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}

isStrictBody(
node: { body: N.BlockStatement },
isExpression: ?boolean,
): boolean {
if (!isExpression && node.body.body.length > 0) {
isStrictBody(node: { body: N.BlockStatement }): boolean {
const isBlockStatement = node.body.type === "BlockStatement";

if (isBlockStatement && node.body.body.length > 0) {
for (const directive of node.body.body) {
if (
directive.type === "ExpressionStatement" &&
Expand Down Expand Up @@ -242,6 +249,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return node;
}

parseFunctionBody(node: N.Function, allowExpression: ?boolean): void {
super.parseFunctionBody(node, allowExpression);
node.expression = node.body.type !== "BlockStatement";
}

parseMethod<T: N.MethodLike>(
node: T,
isGenerator: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 103,
Expand All @@ -107,10 +106,10 @@
"name": "method1",
"leadingComments": null
},
"computed": false,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@
}
},
"method": false,
"shorthand": true,
"computed": false,
"key": {
"type": "Identifier",
"start": 8,
Expand All @@ -140,6 +138,8 @@
},
"name": "b"
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
"start": 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@
}
},
"method": false,
"shorthand": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
Expand All @@ -123,6 +121,8 @@
},
"name": "a"
},
"computed": false,
"shorthand": false,
"value": {
"type": "StringLiteral",
"start": 17,
Expand Down Expand Up @@ -159,8 +159,6 @@
}
},
"method": false,
"shorthand": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 37,
Expand All @@ -179,6 +177,8 @@
"name": "b",
"leadingComments": null
},
"computed": false,
"shorthand": false,
"value": {
"type": "StringLiteral",
"start": 40,
Expand Down Expand Up @@ -233,8 +233,6 @@
}
},
"method": false,
"shorthand": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 60,
Expand All @@ -253,6 +251,8 @@
"name": "c",
"leadingComments": null
},
"computed": false,
"shorthand": false,
"value": {
"type": "StringLiteral",
"start": 63,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 33,
Expand All @@ -106,6 +105,7 @@
"name": "spawn",
"leadingComments": null
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"name": "a"
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"name": "a"
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"name": "a"
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"name": "a"
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"name": "f"
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"name": "bar"
},
"generator": false,
"expression": false,
"async": false,
"params": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"name": "bar"
},
"generator": false,
"expression": false,
"async": false,
"params": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
Expand Down Expand Up @@ -191,7 +190,6 @@
"name": "isConstant"
},
"generator": false,
"expression": false,
"async": false,
"params": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"name": "x"
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"name": "fn"
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 6,
Expand All @@ -122,6 +121,7 @@
},
"name": "answer"
},
"computed": false,
"shorthand": false,
"value": {
"type": "NumericLiteral",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 6,
Expand All @@ -122,6 +121,7 @@
},
"name": "if"
},
"computed": false,
"shorthand": false,
"value": {
"type": "NumericLiteral",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 6,
Expand All @@ -122,6 +121,7 @@
},
"name": "true"
},
"computed": false,
"shorthand": false,
"value": {
"type": "NumericLiteral",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 6,
Expand All @@ -122,6 +121,7 @@
},
"name": "false"
},
"computed": false,
"shorthand": false,
"value": {
"type": "NumericLiteral",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 6,
Expand All @@ -122,6 +121,7 @@
},
"name": "null"
},
"computed": false,
"shorthand": false,
"value": {
"type": "NumericLiteral",
Expand Down
Loading

0 comments on commit 6d820a2

Please sign in to comment.