Skip to content

Commit d8f7417

Browse files
committed
Remove match placeholders
1 parent 347d118 commit d8f7417

File tree

40 files changed

+584
-5414
lines changed

40 files changed

+584
-5414
lines changed

src/parser/expression.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,7 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
291291
// Parse unary operators, both prefix and postfix.
292292

293293
pp.parseMaybeUnary = function (refShorthandDefaultPos) {
294-
const matchCaseBinaryPlusMin = this.hasPlugin("lightscript") &&
295-
this.state.inMatchCaseTest &&
296-
this.match(tt.plusMin) &&
297-
this.state.tokens[this.state.tokens.length - 1].value !== "!" &&
298-
this.isNextCharWhitespace();
299-
300-
if (this.state.type.prefix && !matchCaseBinaryPlusMin) {
294+
if (this.state.type.prefix) {
301295
if (this.hasPlugin("lightscript") && this.match(tt.plusMin)) {
302296
if (this.isNextCharWhitespace()) this.unexpected(null, "Unary +/- cannot be followed by a space in lightscript.");
303297
}
@@ -313,19 +307,7 @@ pp.parseMaybeUnary = function (refShorthandDefaultPos) {
313307
this.next();
314308

315309
const argType = this.state.type;
316-
317-
// change precedence / allow autofill of `not` within `match` test
318-
if (this.hasPlugin("lightscript") && node.operator === "!" && this.state.inMatchCaseTest && !argType.startsExpr) {
319-
if (this.match(tt.colon) || this.match(tt.logicalOR) || this.match(tt.logicalAND)) {
320-
// allow `| not:`, `| !!:`, `| not or x:`
321-
node.argument = this.parseMatchCasePlaceholder();
322-
} else {
323-
// change precedence of `| not < 3:` to `!(x < 3)` from `(!x) < 3`
324-
node.argument = this.parseExprOps();
325-
}
326-
} else {
327-
node.argument = this.parseMaybeUnary();
328-
}
310+
node.argument = this.parseMaybeUnary();
329311

330312
this.addExtra(node, "parenthesizedArgument", argType === tt.parenL && (!node.argument.extra || !node.argument.extra.parenthesized));
331313

@@ -763,14 +745,11 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
763745
}
764746

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

770752
default:
771-
if (this.hasPlugin("lightscript") && this.allowMatchCasePlaceholder()) {
772-
return this.parseMatchCasePlaceholder();
773-
}
774753
this.unexpected();
775754
}
776755
};

src/plugins/lightscript.js

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -655,66 +655,6 @@ pp.parseMatchCaseTest = function (node) {
655655
this.state.inMatchCaseTest = false;
656656
};
657657

658-
pp.isBinaryTokenForMatchCase = function (tokenType) {
659-
return (
660-
tokenType.binop != null &&
661-
tokenType !== tt.logicalOR &&
662-
tokenType !== tt.logicalAND &&
663-
tokenType !== tt.bitwiseOR
664-
);
665-
};
666-
667-
pp.isSubscriptTokenForMatchCase = function (tokenType) {
668-
return (
669-
tokenType === tt.dot ||
670-
tokenType === tt.elvis ||
671-
tokenType === tt.tilde
672-
);
673-
};
674-
675-
pp.allowMatchCasePlaceholder = function () {
676-
if (!this.state.inMatchCaseTest) {
677-
return false;
678-
}
679-
const cur = this.state.type;
680-
const prev = this.state.tokens[this.state.tokens.length - 1].type;
681-
682-
// don't allow two binary tokens in a row to use placeholders, eg; `+ *`
683-
if (this.isBinaryTokenForMatchCase(cur)) {
684-
return !this.isBinaryTokenForMatchCase(prev);
685-
}
686-
// don't allow two subscripts in a row to use placeholders, eg; `..`
687-
if (this.isSubscriptTokenForMatchCase(cur)) {
688-
return !this.isSubscriptTokenForMatchCase(prev);
689-
}
690-
return false;
691-
};
692-
693-
pp.parseMatchCaseTestPattern = function () {
694-
if (!this.state.allowMatchCaseTestPattern) {
695-
this.unexpected(null, "Only one pattern allowed per match case test.");
696-
}
697-
698-
const oldInMatchCaseTestPattern = this.state.inMatchCaseTestPattern;
699-
this.state.inMatchCaseTestPattern = true;
700-
701-
const node = this.parseBindingAtom();
702-
703-
// once we have finished recursing through a pattern, disallow future patterns
704-
this.state.inMatchCaseTestPattern = oldInMatchCaseTestPattern;
705-
if (this.state.inMatchCaseTestPattern === false) {
706-
this.state.allowMatchCaseTestPattern = false;
707-
}
708-
709-
return node;
710-
};
711-
712-
pp.parseMatchCasePlaceholder = function () {
713-
// use the blank space as an empty value (perhaps 0-length would be better)
714-
const node = this.startNodeAt(this.state.lastTokEnd, this.state.lastTokEndLoc);
715-
return this.finishNodeAt(node, "PlaceholderExpression", this.state.start, this.state.startLoc);
716-
};
717-
718658

719659
export default function (instance) {
720660

src/tokenizer/state.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export default class State {
4141
// for lightscript
4242
this.indentLevel = 0;
4343
this.inMatchCaseTest = false;
44-
this.inMatchCaseTestPattern = false;
45-
this.allowMatchCaseTestPattern = false;
4644

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

test/fixtures/lightscript/match/binary-both-subscripts/actual.js

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

test/fixtures/lightscript/match/binary-both-subscripts/expected.json

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

test/fixtures/lightscript/match/binary/actual.js

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

0 commit comments

Comments
 (0)