Skip to content
Prev Previous commit
Next Next commit
Use colon syntax instead of comma-arrow
  • Loading branch information
rattrayalex committed Jun 3, 2017
commit 045731f1b0d0041a5bd6b83316a5f8cc88cda2f4
9 changes: 3 additions & 6 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,12 @@ pp.parseExprOps = function (noIn, refShorthandDefaultPos) {
pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
// correct ASI failures.
if (this.hasPlugin("lightscript") && this.isLineBreak()) {

// if it's a newline followed by a unary +/-, bail so it can be parsed separately.
if (this.match(tt.plusMin) && !this.isNextCharWhitespace()) {
return left;
}
// if it's a `|` in a match/case on a newline, assume it's for the "case"
// TODO: consider using indentation to be more precise about this
// TODO: just remove all bitwise operators so this isn't necessary.
if (this.match(tt.bitwiseOR) && this.state.inMatchCaseConsequent) {
// for match/case
if (this.match(tt.bitwiseOR)) {
return left;
}
}
Expand Down Expand Up @@ -752,7 +749,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
}

case tt.dot:
if (this.hasPlugin("lightscript") && this.lookahead().type === tt.num) {
if (this.hasPlugin("lightscript") && this.lookahead().type === tt.num && !this.allowMatchCasePlaceholder()) {
this.unexpected(null, "Decimal numbers must be prefixed with a `0` in LightScript (eg; `0.1`).");
}

Expand Down
17 changes: 6 additions & 11 deletions src/plugins/lightscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ pp.parseMatch = function () {
}

const matchCase = this.parseMatchCase();
if (matchCase.test && matchCase.test.type === "MatchElse") {
if (matchCase.test.type === "MatchElse") {
hasUsedElse = true;
}
node.cases.push(matchCase);
Expand All @@ -586,17 +586,13 @@ pp.parseMatchCase = function () {
const node = this.startNode();

node.test = this.parseMatchCaseTest();
this.expect(tt.comma);

// parse arrow function expression. (TODO: consider allowing NamedArrowExpression)
const oldInMatchCaseConsequent = this.state.inMatchCaseConsequent;
this.state.inMatchCaseConsequent = true;
node.consequent = this.parseMaybeAssign();
this.state.inMatchCaseConsequent = oldInMatchCaseConsequent;
if (node.consequent.type !== "ArrowFunctionExpression") {
this.unexpected(node.consequent.start, tt.arrow);
if (this.eat(tt._with)) {
node.binding = this.parseBindingAtom();
}

node.consequent = this.parseBlock(false);

return this.finishNode(node, "MatchCase");
};

Expand Down Expand Up @@ -634,8 +630,7 @@ pp.isSubscriptTokenForMatchCase = function (tokenType) {
tokenType === tt.dot ||
tokenType === tt.elvis ||
tokenType === tt.tilde ||
tokenType === tt.bracketL ||
(tokenType === this.state.type && this.isNumberStartingWithDot())
tokenType === tt.bracketL
);
};

Expand Down
4 changes: 1 addition & 3 deletions src/tokenizer/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export default class State {

// for lightscript
this.indentLevel = 0;
this.inMatchCaseConsequent =
this.inMatchCaseTest =
false;
this.inMatchCaseTest = false;

this.type = tt.eof;
this.value = null;
Expand Down
11 changes: 0 additions & 11 deletions test/fixtures/lightscript/match/arrow-fns/actual.js

This file was deleted.

Loading