Skip to content

Commit 1ce7c74

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

File tree

40 files changed

+583
-5407
lines changed

40 files changed

+583
-5407
lines changed

src/parser/expression.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,7 @@ pp.parseMaybeUnary = function (refShorthandDefaultPos) {
313313
this.next();
314314

315315
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-
}
316+
node.argument = this.parseMaybeUnary();
329317

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

@@ -763,14 +751,11 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
763751
}
764752

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

770758
default:
771-
if (this.hasPlugin("lightscript") && this.allowMatchCasePlaceholder()) {
772-
return this.parseMatchCasePlaceholder();
773-
}
774759
this.unexpected();
775760
}
776761
};

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)