Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Remove exponentiationOperator, asyncFunctions, trailingFunctionCommas #98

Merged
merged 4 commits into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ require("babylon").parse("code", {
sourceType: "module",

plugins: [
// enable experimental async functions
"asyncFunctions",

// enable jsx and flow syntax
"jsx",
"flow"
Expand All @@ -106,15 +103,12 @@ require("babylon").parse("code", {

- `jsx`
- `flow`
- `asyncFunctions`
- `classConstructorCall`
- `doExpressions`
- `trailingFunctionCommas`
- `objectRestSpread`
- `decorators`
- `classProperties`
- `exportExtensions`
- `exponentiationOperator`
- `asyncGenerators`
- `functionBind`
- `functionSent`
51 changes: 23 additions & 28 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {

let node = this.startNodeAt(startPos, startLoc);
node.callee = base;
node.arguments = this.parseCallExpressionArguments(tt.parenR, this.hasPlugin("trailingFunctionCommas"), possibleAsync);
node.arguments = this.parseCallExpressionArguments(tt.parenR, possibleAsync);
base = this.finishNode(node, "CallExpression");

if (possibleAsync && this.shouldParseAsyncArrow()) {
Expand All @@ -318,7 +318,7 @@ pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
}
};

pp.parseCallExpressionArguments = function (close, allowTrailingComma, possibleAsyncArrow) {
pp.parseCallExpressionArguments = function (close, possibleAsyncArrow) {
let innerParenStart;

let elts = [], first = true;
Expand All @@ -327,7 +327,7 @@ pp.parseCallExpressionArguments = function (close, allowTrailingComma, possibleA
first = false;
} else {
this.expect(tt.comma);
if (allowTrailingComma && this.eat(close)) break;
if (this.eat(close)) break;
}

// we need to make sure that if this is an async arrow functions, that we don't allow inner parens inside the params
Expand All @@ -351,7 +351,6 @@ pp.shouldParseAsyncArrow = function () {
};

pp.parseAsyncArrowFromCallExpression = function (node, call) {
if (!this.hasPlugin("asyncFunctions")) this.unexpected();
this.expect(tt.arrow);
return this.parseArrowExpression(node, call.arguments, true);
};
Expand Down Expand Up @@ -396,24 +395,22 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {

case tt.name:
node = this.startNode();
let allowAwait = this.hasPlugin("asyncFunctions") && this.state.value === "await" && this.state.inAsync;
let allowAwait = this.state.value === "await" && this.state.inAsync;
let allowYield = this.shouldAllowYieldIdentifier();
let id = this.parseIdentifier(allowAwait || allowYield);

if (this.hasPlugin("asyncFunctions")) {
if (id.name === "await") {
if (this.state.inAsync || this.inModule) {
return this.parseAwait(node);
}
} else if (id.name === "async" && this.match(tt._function) && !this.canInsertSemicolon()) {
this.next();
return this.parseFunction(node, false, false, true);
} else if (canBeArrow && id.name === "async" && this.match(tt.name)) {
let params = [this.parseIdentifier()];
this.expect(tt.arrow);
// let foo = bar => {};
return this.parseArrowExpression(node, params, true);
if (id.name === "await") {
if (this.state.inAsync || this.inModule) {
return this.parseAwait(node);
}
} else if (id.name === "async" && this.match(tt._function) && !this.canInsertSemicolon()) {
this.next();
return this.parseFunction(node, false, false, true);
} else if (canBeArrow && id.name === "async" && this.match(tt.name)) {
let params = [this.parseIdentifier()];
this.expect(tt.arrow);
// let foo = bar => {};
return this.parseArrowExpression(node, params, true);
}

if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
Expand Down Expand Up @@ -466,7 +463,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
case tt.bracketL:
node = this.startNode();
this.next();
node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos);
node.elements = this.parseExprList(tt.bracketR, true, refShorthandDefaultPos);
this.toReferencedList(node.elements);
return this.finishNode(node, "ArrayExpression");

Expand Down Expand Up @@ -559,7 +556,7 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
first = false;
} else {
this.expect(tt.comma, refNeedsArrowPos.start || null);
if (this.match(tt.parenR) && this.hasPlugin("trailingFunctionCommas")) {
if (this.match(tt.parenR)) {
optionalCommaStart = this.state.start;
break;
}
Expand Down Expand Up @@ -641,7 +638,7 @@ pp.parseNew = function () {
node.callee = this.parseNoCallExpr();

if (this.eat(tt.parenL)) {
node.arguments = this.parseExprList(tt.parenR, this.hasPlugin("trailingFunctionCommas"));
node.arguments = this.parseExprList(tt.parenR);
this.toReferencedList(node.arguments);
} else {
node.arguments = [];
Expand Down Expand Up @@ -727,7 +724,7 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) {
isGenerator = this.eat(tt.star);
}

if (!isPattern && this.hasPlugin("asyncFunctions") && this.isContextual("async")) {
if (!isPattern && this.isContextual("async")) {
if (isGenerator) this.unexpected();

let asyncId = this.parseIdentifier();
Expand Down Expand Up @@ -833,9 +830,7 @@ pp.initFunction = function (node, isAsync) {
node.id = null;
node.generator = false;
node.expression = false;
if (this.hasPlugin("asyncFunctions")) {
node.async = !!isAsync;
}
node.async = !!isAsync;
};

// Parse object or class method.
Expand All @@ -845,7 +840,7 @@ pp.parseMethod = function (node, isGenerator, isAsync) {
this.state.inMethod = node.kind || true;
this.initFunction(node, isAsync);
this.expect(tt.parenL);
node.params = this.parseBindingList(tt.parenR, false, this.hasPlugin("trailingFunctionCommas"));
node.params = this.parseBindingList(tt.parenR);
node.generator = isGenerator;
this.parseFunctionBody(node);
this.state.inMethod = oldInMethod;
Expand Down Expand Up @@ -929,14 +924,14 @@ pp.parseFunctionBody = function (node, allowExpression) {
// nothing in between them to be parsed as `null` (which is needed
// for array literals).

pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refShorthandDefaultPos) {
pp.parseExprList = function (close, allowEmpty, refShorthandDefaultPos) {
let elts = [], first = true;
while (!this.eat(close)) {
if (first) {
first = false;
} else {
this.expect(tt.comma);
if (allowTrailingComma && this.eat(close)) break;
if (this.eat(close)) break;
}

elts.push(this.parseExprListItem(allowEmpty, refShorthandDefaultPos));
Expand Down
8 changes: 4 additions & 4 deletions src/parser/lval.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ pp.parseBindingAtom = function () {
switch (this.state.type) {
case tt._yield:
if (this.state.strict || this.state.inGenerator) this.unexpected();

// fall-through
case tt.name:
return this.parseIdentifier(true);

case tt.bracketL:
let node = this.startNode();
this.next();
node.elements = this.parseBindingList(tt.bracketR, true, true);
node.elements = this.parseBindingList(tt.bracketR, true);
return this.finishNode(node, "ArrayPattern");

case tt.braceL:
Expand All @@ -144,7 +144,7 @@ pp.parseBindingAtom = function () {
}
};

pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
pp.parseBindingList = function (close, allowEmpty) {
let elts = [];
let first = true;
while (!this.eat(close)) {
Expand All @@ -155,7 +155,7 @@ pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
}
if (allowEmpty && this.match(tt.comma)) {
elts.push(null);
} else if (allowTrailingComma && this.eat(close)) {
} else if (this.eat(close)) {
break;
} else if (this.match(tt.ellipsis)) {
elts.push(this.parseAssignableListItemTypes(this.parseRest()));
Expand Down
8 changes: 4 additions & 4 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pp.parseStatement = function (declaration, topLevel) {
return starttype === tt._import ? this.parseImport(node) : this.parseExport(node);

case tt.name:
if (this.hasPlugin("asyncFunctions") && this.state.value === "async") {
if (this.state.value === "async") {
// peek ahead and see if next token is a function
let state = this.state.clone();
this.next();
Expand Down Expand Up @@ -603,7 +603,7 @@ pp.parseFunction = function (node, isStatement, allowExpressionBody, isAsync, op

pp.parseFunctionParams = function (node) {
this.expect(tt.parenL);
node.params = this.parseBindingList(tt.parenR, false, this.hasPlugin("trailingFunctionCommas"));
node.params = this.parseBindingList(tt.parenR);
};

// Parse a class declaration or literal (depending on the
Expand Down Expand Up @@ -684,7 +684,7 @@ pp.parseClassBody = function (node) {
}
}

let isAsyncMethod = this.hasPlugin("asyncFunctions") && !this.match(tt.parenL) && !method.computed && method.key.type === "Identifier" && method.key.name === "async";
let isAsyncMethod = !this.match(tt.parenL) && !method.computed && method.key.type === "Identifier" && method.key.name === "async";
if (isAsyncMethod) {
if (this.hasPlugin("asyncGenerators") && this.eat(tt.star)) isGenerator = true;
isAsync = true;
Expand Down Expand Up @@ -900,7 +900,7 @@ pp.parseExportFrom = function (node, expect?) {
};

pp.shouldParseExportDeclaration = function () {
return this.hasPlugin("asyncFunctions") && this.isContextual("async");
return this.isContextual("async");
};

pp.checkExport = function (node) {
Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export default class Tokenizer {
let width = 1;
let next = this.input.charCodeAt(this.state.pos + 1);

if (next === 42 && this.hasPlugin("exponentiationOperator")) { // '*'
if (next === 42) { // '*'
width++;
next = this.input.charCodeAt(this.state.pos + 2);
type = tt.exponent;
Expand Down
Loading