title |
---|
Developer Guide |
- Builds the AST with Acorn.
- Loads the plugins.
- Instantiates a
ModuleLoader
. - Parsing stage
- Takes the entry module(s), finds the modules it imports, and then imports all those continuing until all necessary modules are imported.
- Analysing stage (linking)
- Populate the dependency links and determine the topological execution order for the bundle
- Marking stage
- include all statements that should be included
- generation stage
- construct the chunks, working out the optimal chunking using entry point graph colouring, before generating the import and export facades
This is responsible for loading the module code and creating instances of Module
. It also looks in the shared module cache. It also loads in all dependency modules.
Calls setSource()
on Module
which generates the AST (or uses an existing AST if one was provided).
Analyses the AST
setSource()
on Module
generates the ast (esTreeAst) (or uses an existing AST if one was provided). Creates a MagicString
. Creates ModuleScope
. Creates Program
which is a Node
that has analysed AST.
keys
: The property names that point to otherNode
's that are part of the currentNode
.parent
: ParentNode
(or special case whenNode
isProgram
).context
: context of parentscope
: scope of parentparseNode()
(called in constructor): Adds the other properties to the object such astype
,start
,end
and constructs new instances of the correctNode
classes for the other object properties. E.g.IfStatement
node will have atest
property of typeExpression
,consequent
of typeStatement
and optionalalternate
.bind()
: Called once all nodes have been initialised and the scopes have been populated.declare()
: Declares a new variable.hasEffects()
: Returnstrue
if theNode
has an effect on the bundle.shouldBeIncluded()
: Determine if theNode
has an effect on the bundle and should therefore be included.include()
: Called to include theNode
in the bundle.includeWithAllDeclaredVariables()
: similar toinclude()
.render()
: output the code for theNode
.
TODO example
Declare a new variable. This only applies to some nodes, such as Identifier
.
TODO why does this exist for all nodes?
TODO example
TODO example
TODO example
TODO example
The root Node
for a Module
.