* @param state Set 'state.stop = true' to indicate that we should stop parsing subscripts. * state.optionalChainMember to indicate that the member is currently in OptionalChain
(
this: Parser,
base: N.Expression | N.Super | N.Import,
startLoc: Position,
noCalls: boolean | undefined | null,
state: N.ParseSubscriptState,
)
| 836 | * state.optionalChainMember to indicate that the member is currently in OptionalChain |
| 837 | */ |
| 838 | parseSubscript( |
| 839 | this: Parser, |
| 840 | base: N.Expression | N.Super | N.Import, |
| 841 | startLoc: Position, |
| 842 | noCalls: boolean | undefined | null, |
| 843 | state: N.ParseSubscriptState, |
| 844 | ): N.Expression { |
| 845 | const { type } = this.state; |
| 846 | if (!noCalls && type === tt.doubleColon) { |
| 847 | // super:: or import:: are not allowed |
| 848 | return this.parseBind(base as N.Expression, startLoc, state); |
| 849 | } else if (tokenIsTemplate(type)) { |
| 850 | return this.parseTaggedTemplateExpression( |
| 851 | base as N.Expression, |
| 852 | startLoc, |
| 853 | state, |
| 854 | ); |
| 855 | } |
| 856 | |
| 857 | let optional = false; |
| 858 | |
| 859 | if (type === tt.questionDot) { |
| 860 | if (noCalls) { |
| 861 | this.raise(Errors.OptionalChainingNoNew, this.state.startLoc); |
| 862 | if (this.lookaheadCharCode() === charCodes.leftParenthesis) { |
| 863 | // stop at `?.` when parsing `new a?.()` |
| 864 | return this.stopParseSubscript(base as N.Expression, state); |
| 865 | } |
| 866 | } |
| 867 | state.optionalChainMember = optional = true; |
| 868 | this.next(); |
| 869 | } |
| 870 | |
| 871 | if (!noCalls && this.match(tt.parenL)) { |
| 872 | return this.parseCoverCallAndAsyncArrowHead( |
| 873 | base, |
| 874 | startLoc, |
| 875 | state, |
| 876 | optional, |
| 877 | ); |
| 878 | } else { |
| 879 | const computed = this.eat(tt.bracketL); |
| 880 | if (computed || optional || this.eat(tt.dot)) { |
| 881 | return this.parseMember( |
| 882 | base as N.Expression | N.Super, |
| 883 | startLoc, |
| 884 | state, |
| 885 | computed, |
| 886 | optional, |
| 887 | ); |
| 888 | } else { |
| 889 | return this.stopParseSubscript(base as N.Expression, state); |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | stopParseSubscript( |
| 895 | this: Parser, |
nothing calls this directly
no test coverage detected