Skip to content

Commit d6ea09d

Browse files
committed
docs: add CSS analysis paragraph
1 parent 425e68a commit d6ea09d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

DEVELOPER_GUIDE.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ If you want to familiarize yourself with the Svelte AST, you can go [to the play
4646

4747
## Phase 2: Analysis
4848

49-
Once we have a AST we need to perform analysis on it. During this phase we will collect information about which variables are used, where are they used, if they are stores, etc. This information will be used later during the third phase to transform and optimize your component (for example if you declare a stateful variable but never reassign to it or never use it in a reactive context we will not bother with creating a stateful variable at all).
49+
Once we have a AST we need to perform analysis on it. During this phase we will:
50+
51+
- create the scopes for the component
52+
- throw compiler warnings and errors (for things like wrong usage of runes, wrong usage of globals etc)
53+
- detect which branches of the template are completely static or dynamic
54+
- detect which snippets are hoistable
55+
- analyze the css to determine unused css
56+
57+
This information will be used later during the third phase to transform and optimize your component (for example if you declare a stateful variable but never reassign to it or never use it in a reactive context we will not bother with creating a stateful variable at all).
5058

5159
The very first thing to do is to create the scopes for every variable. What this operation does is to create a map from a node to a specific set of references, declarations and declarators. This is useful because if you have a situation like this
5260

@@ -256,3 +264,7 @@ for (const scope of [module.scope, instance.scope]) {
256264
}
257265
}
258266
```
267+
268+
### CSS Analysis
269+
270+
While we didn't go deep in how the analysis works for every single step of the analysis it's worth exploring the CSS analysis a bit more in depth. This phase in itself is subdivided in three phases: we first analyze the css, during this phase we validate the structure of svelte specific css (eg. the `:global` selector) is valid also marking every node within global as `used`. We then proceed to `prune` the css. In this phase we match every selector with the html structure...if a selector doesn't match any element we `prune` it away either by commenting it out in dev (so that the users can actually see what's being removed) or by completely remove it in prod. Finally we walk the css AST once more to warn about all the `unused` css nodes accessing the metadata we collected in those two phases.

0 commit comments

Comments
 (0)