Skip to content

Commit ffa53ce

Browse files
committed
Use colon syntax instead of comma-arrow
1 parent 6299ef9 commit ffa53ce

File tree

63 files changed

+2880
-3609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2880
-3609
lines changed

src/parser/expression.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,12 @@ pp.parseExprOps = function (noIn, refShorthandDefaultPos) {
239239
pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
240240
// correct ASI failures.
241241
if (this.hasPlugin("lightscript") && this.isLineBreak()) {
242-
243242
// if it's a newline followed by a unary +/-, bail so it can be parsed separately.
244243
if (this.match(tt.plusMin) && !this.isNextCharWhitespace()) {
245244
return left;
246245
}
247-
// if it's a `|` in a match/case on a newline, assume it's for the "case"
248-
// TODO: consider using indentation to be more precise about this
249-
// TODO: just remove all bitwise operators so this isn't necessary.
250-
if (this.match(tt.bitwiseOR) && this.state.inMatchCaseConsequent) {
246+
// for match/case
247+
if (this.match(tt.bitwiseOR)) {
251248
return left;
252249
}
253250
}
@@ -752,7 +749,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
752749
}
753750

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

src/plugins/lightscript.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ pp.parseMatch = function () {
573573
}
574574

575575
const matchCase = this.parseMatchCase();
576-
if (matchCase.test && matchCase.test.type === "MatchElse") {
576+
if (matchCase.test.type === "MatchElse") {
577577
hasUsedElse = true;
578578
}
579579
node.cases.push(matchCase);
@@ -586,17 +586,13 @@ pp.parseMatchCase = function () {
586586
const node = this.startNode();
587587

588588
node.test = this.parseMatchCaseTest();
589-
this.expect(tt.comma);
590589

591-
// parse arrow function expression. (TODO: consider allowing NamedArrowExpression)
592-
const oldInMatchCaseConsequent = this.state.inMatchCaseConsequent;
593-
this.state.inMatchCaseConsequent = true;
594-
node.consequent = this.parseMaybeAssign();
595-
this.state.inMatchCaseConsequent = oldInMatchCaseConsequent;
596-
if (node.consequent.type !== "ArrowFunctionExpression") {
597-
this.unexpected(node.consequent.start, tt.arrow);
590+
if (this.eat(tt._with)) {
591+
node.binding = this.parseBindingAtom();
598592
}
599593

594+
node.consequent = this.parseBlock(false);
595+
600596
return this.finishNode(node, "MatchCase");
601597
};
602598

@@ -634,8 +630,7 @@ pp.isSubscriptTokenForMatchCase = function (tokenType) {
634630
tokenType === tt.dot ||
635631
tokenType === tt.elvis ||
636632
tokenType === tt.tilde ||
637-
tokenType === tt.bracketL ||
638-
(tokenType === this.state.type && this.isNumberStartingWithDot())
633+
tokenType === tt.bracketL
639634
);
640635
};
641636

src/tokenizer/state.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ export default class State {
4040

4141
// for lightscript
4242
this.indentLevel = 0;
43-
this.inMatchCaseConsequent =
44-
this.inMatchCaseTest =
45-
false;
43+
this.inMatchCaseTest = false;
4644

4745
this.type = tt.eof;
4846
this.value = null;

test/fixtures/lightscript/match/arrow-fns/actual.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)