MCPcopy Create free account
hub / github.com/babel/babel / getExpression

Function getExpression

packages/babel-parser/src/parser/expression.ts:156–177  ·  view source on GitHub ↗
(this: Parser)

Source from the content-addressed store, hash-verified

154
155 // Convenience method to parse an Expression only
156 getExpression(this: Parser): N.Expression & N.ParserOutput {
157 this.enterInitialScopes();
158 this.nextToken();
159 if (this.match(tt.eof)) {
160 throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
161 }
162 const expr = this.parseExpression() as N.Expression & N.ParserOutput;
163 if (!this.match(tt.eof)) {
164 throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
165 unexpected: this.input.codePointAt(this.state.start)!,
166 });
167 }
168 // Unlike parseTopLevel, we need to drain remaining commentStacks
169 // because the top level node is _not_ Program.
170 this.finalizeRemainingComments();
171 expr.comments = this.comments;
172 expr.errors = this.state.errors;
173 if (this.optionFlags & OptionFlags.Tokens) {
174 expr.tokens = createExportedTokens(this.tokens);
175 }
176 return expr;
177 }
178
179 // ### Expression parsing
180

Callers

nothing calls this directly

Calls 3

createExportedTokensFunction · 0.90
matchMethod · 0.80

Tested by

no test coverage detected