You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DEVELOPER_GUIDE.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ If you want to familiarize yourself with the Svelte AST, you can go [to the play
46
46
47
47
## Phase 2: Analysis
48
48
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 etc. This information will be later used during the third phase to properly transform and optimizing 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 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).
50
50
51
51
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
52
52
@@ -75,9 +75,9 @@ Depending on where you read `count` it will refer to a different variable that h
75
75
This is done by walking the AST and manually create a `new Scope` class every time we encounter a node that creates one.
76
76
77
77
<details>
78
-
<summary>What does walking the AST means?</summary>
78
+
<summary>What does walking the AST mean?</summary>
79
79
80
-
As we've seen, the AST is basically a giant Javascript object with a `type` property to indicate the node type and a series of extra properties.
80
+
As we've seen, the AST is basically a giant JavaScript object with a `type` property to indicate the node type and a series of extra properties.
81
81
82
82
For example, a `$state(1)` node will look like this (excluding position information):
83
83
@@ -120,9 +120,9 @@ walk(ast, state, {
120
120
121
121
What this snippet of code is doing is:
122
122
123
-
- checking if the function declaration has an identifier (basically if it's a named or anonymous function)
124
-
- if it has one it's declaring a new variable in the current scope
125
-
- creating a new scope (since in Javascript when you create a function you are creating a new lexical scope) with the current scope as the parent
123
+
- checking if the function declaration has an identifier (i.e. if it's a named function - not an anonymous function)
124
+
- if it does have an identifier, it's declaring a new variable in the current scope
125
+
- creating a new scope (since in JavaScript when you create a function you are creating a new lexical scope) with the current scope as the parent
126
126
- declare every argument of the function in the newly created scope
127
127
- invoking the next method that will continue the AST traversal, with the brand new scope as the current scope
128
128
@@ -196,7 +196,7 @@ export function Component(node, context) {
196
196
197
197
We invoke `scope.get` passing `node.name` (or the substring that goes from the start to the first `.` in case the component looks like this `<Component.Value />`)... what we get back is a `Binding` which contains the information about where the variable for that component was declared (or imported).
198
198
199
-
If we are in runes mode, the binding is not null and the binding.kindnot `normal` (which means a regular non stateful variable) then we set the `metadata.dynamic` for this component to `true`...we will use this during the transformation phase to generate the proper code to remount the component when the variable changes.
199
+
If we are in runes mode, the `binding` is not `null`, and the `binding.kind` is not `normal` (which means a regular non stateful variable) then we set the `metadata.dynamic` for this component to `true`. We will use this during the transformation phase to generate the proper code to remount the component when the variable changes.
200
200
201
201
The analysis phase is also the moment most of the compiler warnings/errors are emitted. For example if we notice that some top level reference starts with `$$` (which is prohibited) we throw a `global_reference_invalid`
0 commit comments