33## Table of contents
44
551 . [ What it looks like] ( #what-it-looks-like )
6- 1 . [ Concepts overview] ( #concepts-overview )
7- 2 . [ Algorithm overview] ( #algorithm-overview )
6+ 1 . [ Concepts overview] ( #concepts )
7+ 1 . [ Algorithm overview] ( #algorithm-overview )
88
99## What it looks like
1010
@@ -18,42 +18,47 @@ It's a web of modules and links between them.
1818
1919A ** Graph** is a set of Nodes and Edges.
2020
21- A ** Theme Graph** is a set of * Modules* (nodes) and * References* (edges) defined by an array of * Entry Points* . It has these properties:
21+ A ** Theme Graph** is a set of _ Modules_ (nodes) and _ References_ (edges) defined by an array of _ Entry Points_ . It has these properties:
22+
2223- ` rootUri ` - root of the theme, e.g. ` file:/path/to/theme `
2324- ` entryPoints ` - array of modules that define the theme (all templates and sections)
2425- ` modules ` - all the modules in the theme indexed by URI
2526
2627A ** Module** is an object that represents a theme file. It has these properties:
28+
2729- ` uri ` - module identifier, e.g. ` file:/path/to/theme/snippets/file.liquid `
2830- ` type ` - e.g. ` liquid ` , ` json ` , ` javascript ` , ` css ` .
2931- ` kind ` - e.g. ` block ` , ` section ` , ` snippet ` , ` template ` , etc.
30- - ` references ` - array of * References * that point to this module.
31- - ` dependencies ` - array of * References * that this module depends on.
32+ - ` references ` - array of _ References _ that point to this module.
33+ - ` dependencies ` - array of _ References _ that this module depends on.
3234
3335A ** Reference** is an object that defines a link between two modules. It has these properties:
36+
3437- ` source ` - a ` uri ` and ` range ` that defines which module depends on an other and _ where_ in the source file,
3538- ` target ` - a ` uri ` and ` range ` that defines which module is being dependended on and optionally what is being depended on in that file,
3639- ` type ` - one of the following:
3740 - ` direct ` - the file can't exist without the other, e.g. ` {% render 'child' %} `
3841 - ` preset ` - the file has a preset that depends on an other file, e.g. a section that has a preset that includes ` group ` and ` text ` blocks.
3942 - ` indirect ` - the file loosely depends on the other, but not explicilty. e.g. when a file accepts all public theme blocks (` "type": "@theme" ` ))
4043
41-
4244## Algorithm overview
4345
4446To build the graph, we _ traverse_ each module in the set of entry points.
4547
4648When we _ traverse_ a module, we do the following:
49+
4750- if the module was already visited, we return early, else
4851- we extract dependencies from the module's AST, then
4952- we _ bind_ the module with its dependent modules, then
5053- we _ traverse_ the dependent modules (it's a recursive algorithm).
5154
5255When we _ bind_ a parent module with a child module, we do the following:
56+
5357- we add the child module to the parent's dependencies,
5458- we add the parent module to the child's references
5559
5660In pseudo code, it looks a bit like this:
61+
5762```
5863INPUT rootUri
5964OUTPUT graph
0 commit comments