Skip to content

Instantly share code, notes, and snippets.

@khyperia
Created November 27, 2018 19:53
Show Gist options
  • Save khyperia/4ee7c2c60b4e25acdfba508585c3cc07 to your computer and use it in GitHub Desktop.
Save khyperia/4ee7c2c60b4e25acdfba508585c3cc07 to your computer and use it in GitHub Desktop.
Conclusion:
functionFormalParametersAndBody does AST things. So do (most) callers of
functionDefinition. However, sandwiched between are functionDefinition,
trySyntaxParseInnerFunction, innerFunction, and innerFunctionForFunctionBox,
which are all handling of random state and object construction (the "second
pass"-style material we might want to factor out).
functionFormalParametersAndBody does actual tokenStream parse/consumption,
and mutates the AST passed in as an argument to add the parsed body.
It calls functionArguments to do the parameter parsing.
Callers of functionFormalParametersAndBody:
standaloneLazyFunction
standaloneFunction
innerFunctionForFunctionBox
innerFunctionForFunctionBox pushes a SourceParseContext, calls
functionFormalParametersAndBody, then calls leaveInnerFunction which honestly I
have no idea what it does other than "crazy state shenanigans".
Callers of innerFunctionForFunctionBox:
innerFunction
trySyntaxParseInnerFunction
(trySyntaxParseInnerFunction calls innerFunction)
These are just SyntaxParser vs. FullParser handling - they force a full parse I
think?
Callers of trySyntaxParseInnerFunction:
functionDefinition
functionDefinition creates the JSFunction object, with logic to get the proper
prototype/etc. It *also* handles "use strict" directives, and calls
trySyntaxParseInnerFunction in a loop (in case directives change).
Callers of functionDefinition:
functionStmt
functionExpr
assignExpr
methodDefinition
functionStmt does actual tokenStream parse/consumption. It parses the `function`
with optional `*`, as well as the name of the function, and creates a
FunctionStatement AST node, then calls functionDefinition.
functionExpr does actual tokenStream parse/consumption. Very similar to
functionStmt, creates a FunctionExpression AST node.
assignExpr does actual tokenStream parse/consumption. It parses arrow functions
(which is very complicated due to the parsing ambiguities). Creates a
ArrowFunction AST node, then calls functionDefinition.
methodDefinition does some enum conversions (PropertyType -> combo of
FunctionSyntaxKind/Generator/FunctionAsyncKind). Creates a FunctionExpression
AST node (???) then calls functionDefinition.
Callers of methodDefinition:
classDefinition
objectLiteral
classDefinition does actual tokenStream parse/consumption. It parses the
entirety of a class (sans `class` keyword), and calls into methodDefinition when
it sees a method.
objectLiteral does actual tokenStream parse/consumption. It parses object
literals, and calls into methodDefinition when it sees a method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment