@@ -659,31 +659,54 @@ pp.parseMatch = function (node, isExpression) {
659
659
return this . finishNode ( node , isExpression ? "MatchExpression" : "MatchStatement" ) ;
660
660
} ;
661
661
662
+ pp . parseMatchCaseConsequent = function ( matchNode ) {
663
+ // c/p parseIf
664
+ if ( this . match ( tt . braceL ) ) {
665
+ matchNode . consequent = this . parseBlock ( false , true ) ;
666
+ } else {
667
+ matchNode . consequent = this . parseWhiteBlock ( true ) ;
668
+ }
669
+ } ;
670
+
671
+ pp . parseMatchCaseWithConsequent = function ( matchNode ) {
672
+ // with (x) -> ..., with async, with ->
673
+ if ( this . match ( tt . parenL ) || this . match ( tt . arrow ) || this . isContextual ( "async" ) ) {
674
+ const consequent = this . parseMaybeAssign ( ) ;
675
+ if ( consequent . type !== "ArrowFunctionExpression" ) {
676
+ this . unexpected ( consequent . start , tt . arrow ) ;
677
+ }
678
+ matchNode . consequent = consequent ;
679
+ matchNode . functional = true ;
680
+ return ;
681
+ }
682
+
683
+ // with <Identifier> -> ...
684
+ // with <BindingAtom>: ...
685
+ const node = this . startNode ( ) ;
686
+ const bindingAtom = this . parseBindingAtom ( ) ;
687
+ if ( this . match ( tt . arrow ) ) {
688
+ matchNode . consequent = this . parseArrowExpression ( node , bindingAtom ? [ bindingAtom ] : [ ] , false ) ;
689
+ matchNode . functional = true ;
690
+ return ;
691
+ }
692
+
693
+ matchNode . binding = bindingAtom ;
694
+ this . parseMatchCaseConsequent ( matchNode ) ;
695
+ } ;
696
+
662
697
pp . parseMatchCase = function ( ) {
663
698
const node = this . startNode ( ) ;
664
699
665
700
node . test = this . parseMatchCaseTest ( ) ;
666
701
702
+ const oldInMatchCaseConsequent = this . state . inMatchCaseConsequent ;
703
+ this . state . inMatchCaseConsequent = true ;
667
704
if ( this . eat ( tt . _with ) ) {
668
- const oldInMatchCaseConsequent = this . state . inMatchCaseConsequent ;
669
- this . state . inMatchCaseConsequent = true ;
670
- node . consequent = this . parseMaybeAssign ( ) ;
671
- this . state . inMatchCaseConsequent = oldInMatchCaseConsequent ;
672
- if ( node . consequent . type !== "ArrowFunctionExpression" ) {
673
- this . unexpected ( node . consequent . start , tt . arrow ) ;
674
- }
675
- node . functional = true ;
705
+ this . parseMatchCaseWithConsequent ( node ) ;
676
706
} else {
677
- const oldInMatchCaseConsequent = this . state . inMatchCaseConsequent ;
678
- this . state . inMatchCaseConsequent = true ;
679
- // c/p parseIf
680
- if ( this . match ( tt . braceL ) ) {
681
- node . consequent = this . parseBlock ( false , true ) ;
682
- } else {
683
- node . consequent = this . parseWhiteBlock ( true ) ;
684
- }
685
- this . state . inMatchCaseConsequent = oldInMatchCaseConsequent ;
707
+ this . parseMatchCaseConsequent ( node ) ;
686
708
}
709
+ this . state . inMatchCaseConsequent = oldInMatchCaseConsequent ;
687
710
688
711
return this . finishNode ( node , "MatchCase" ) ;
689
712
} ;
0 commit comments