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: packages/svelte/src/compiler/phases/scope.js
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1698,25 +1698,25 @@ function evaluate_function(fn, binding, stack = new Set(), [...seen_bindings] =
1698
1698
/**
1699
1699
* This big blob of comments is for my (https://github.com/Ocean-OS) sanity and for that of anyone who tries working with this function. Feel free to modify this as the function evolves.
1700
1700
* So, when evaluating functions at compile-time, there are a few things you have to avoid evaluating:
1701
-
*
1701
+
*
1702
1702
* - Side effects
1703
1703
* A function that modifies state from outside of its scope should not be evaluated.
1704
1704
* Additionally, since `$effect`s and `$derived`s exist, any reference to an external value could lead to a missed dependency if the function is evaluated by the compiler.
1705
1705
* - Errors
1706
1706
* A function that could throw an error should not be evaluated. Additionally, `$derived`s could be reevaluated upon reading, which could throw an error.
1707
1707
* The purpose of a compile-time evaluator is to replicate the behavior the function would have at runtime, but in compile time.
1708
1708
* If an error is/could be thrown, that can not be replicated.
1709
-
*
1709
+
*
1710
1710
* So, how do we figure out if either of these things (could) happen in a function?
1711
1711
* Well, for errors, it's relatively simple. If a `throw` statement is used in the function, then we assume that the error could be thrown at any time.
1712
1712
* For side effects, it gets a bit tricky. External `Identifier`s that change their value are definitely side effects, but also any `MemberExpression` that isn't a known global constant could have a side effect, due to getters and `Proxy`s.
1713
1713
* Additionally, since a function can call other functions, we check each individual function call: if it's a known global, we know its pure, and if we can find its definition, the parent function inherits its throwability and purity. If we cannot find its definition, we assume it is impure and could throw.
1714
-
*
1714
+
*
1715
1715
* A few other things to note/remember:
1716
1716
* - Not all functions rely on return statements to determine the return value.
1717
1717
* Arrow functions without a `BlockStatement` for a body use their expression body as an implicit `ReturnStatement`.
1718
1718
* - While currently all the globals we have are pure and error-free, that could change, so we shouldn't be too dependent on that in the future.
1719
-
* Things like `JSON.stringify` and a *lot* of array methods are prime examples.
1719
+
* Things like `JSON.stringify` and a *lot* of array methods are prime examples.
1720
1720
*/
1721
1721
letthing;
1722
1722
constanalysis={
@@ -1811,7 +1811,7 @@ function evaluate_function(fn, binding, stack = new Set(), [...seen_bindings] =
0 commit comments