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

Function getExpression

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

createExportedTokensFunction · 0.90
matchMethod · 0.80

Tested by

no test coverage detected