MCPcopy Create free account
hub / github.com/dop251/goja / parseFunction

Method parseFunction

parser/statement.go:206–264  ·  view source on GitHub ↗
(declaration, async bool, start file.Idx)

Source from the content-addressed store, hash-verified

204}
205
206func (self *_parser) parseFunction(declaration, async bool, start file.Idx) *ast.FunctionLiteral {
207
208 node := &ast.FunctionLiteral{
209 Function: start,
210 Async: async,
211 }
212 self.expect(token.FUNCTION)
213
214 if self.token == token.MULTIPLY {
215 node.Generator = true
216 self.next()
217 }
218
219 if !declaration {
220 if async != self.scope.allowAwait {
221 self.scope.allowAwait = async
222 defer func() {
223 self.scope.allowAwait = !async
224 }()
225 }
226 if node.Generator != self.scope.allowYield {
227 self.scope.allowYield = node.Generator
228 defer func() {
229 self.scope.allowYield = !node.Generator
230 }()
231 }
232 }
233
234 self.tokenToBindingId()
235 var name *ast.Identifier
236 if self.token == token.IDENTIFIER {
237 name = self.parseIdentifier()
238 } else if declaration {
239 // Use expect error handling
240 self.expect(token.IDENTIFIER)
241 }
242 node.Name = name
243
244 if declaration {
245 if async != self.scope.allowAwait {
246 self.scope.allowAwait = async
247 defer func() {
248 self.scope.allowAwait = !async
249 }()
250 }
251 if node.Generator != self.scope.allowYield {
252 self.scope.allowYield = node.Generator
253 defer func() {
254 self.scope.allowYield = !node.Generator
255 }()
256 }
257 }
258
259 node.ParameterList = self.parseFunctionParameterList()
260 node.Body, node.DeclarationList = self.parseFunctionBlock(async, async, self.scope.allowYield)
261 node.Source = self.slice(node.Idx0(), node.Idx1())
262
263 return node

Callers 3

parseStatementMethod · 0.95

Calls 9

expectMethod · 0.95
nextMethod · 0.95
tokenToBindingIdMethod · 0.95
parseIdentifierMethod · 0.95
parseFunctionBlockMethod · 0.95
sliceMethod · 0.95
Idx0Method · 0.95
Idx1Method · 0.95

Tested by

no test coverage detected