Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
<script>
// NOTE: use `count` in a reactive declaration before `count` is declared
$: doubled = count * 2;
let count = 1;
</script>

{count} * 2 = {doubled}
fetching https://unpkg.com/svelte@5.20.5/src/internal/client/index.js
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

export default function App($$anchor, $$props) {
$.push($$props, false);

const doubled = $.mutable_state();
let count = 1;

$.legacy_pre_effect(() => {}, () => {
$.set(doubled, count * 2);
});

$.legacy_pre_effect_reset();
$.next();

var text = $.text();

$.template_effect(() => $.set_text(text, `${count ?? ''} * 2 = ${$.get(doubled) ?? ''}`));
$.append($$anchor, text);
$.pop();
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 136
    • end: 159
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (4)
        • Text {...}
          • type: "Text"
          • start: 134
          • end: 136
          • raw: "\n\n"
          • data: "\n\n"
          }
        • ExpressionTag {...}
          • type: "ExpressionTag"
          • start: 136
          • end: 143
          • expression: Identifier {...}
            • type: "Identifier"
            • start: 137
            • end: 142
            • loc: {...}
              • start: {...}
                • line: 7
                • column: 1
                }
              • end: {...}
                • line: 7
                • column: 6
                }
              }
            • name: "count"
            }
          }
        • Text {...}
          • type: "Text"
          • start: 143
          • end: 150
          • raw: " * 2 = "
          • data: " * 2 = "
          }
        • ExpressionTag {...}
          • type: "ExpressionTag"
          • start: 150
          • end: 159
          • expression: Identifier {...}
            • type: "Identifier"
            • start: 151
            • end: 158
            • loc: {...}
              • start: {...}
                • line: 7
                • column: 15
                }
              • end: {...}
                • line: 7
                • column: 22
                }
              }
            • name: "doubled"
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 134
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 125
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 5
            • column: 0
            }
          }
        • body: [...] (2)
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 85
            • end: 108
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 3
                • column: 24
                }
              }
            • body: ExpressionStatement {...}
              • type: "ExpressionStatement"
              • start: 88
              • end: 108
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 4
                  }
                • end: {...}
                  • line: 3
                  • column: 24
                  }
                }
              • expression: AssignmentExpression {...}
                • type: "AssignmentExpression"
                • start: 88
                • end: 107
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 4
                    }
                  • end: {...}
                    • line: 3
                    • column: 23
                    }
                  }
                • operator: "="
                • left: Identifier {...}
                  • type: "Identifier"
                  • start: 88
                  • end: 95
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 4
                      }
                    • end: {...}
                      • line: 3
                      • column: 11
                      }
                    }
                  • name: "doubled"
                  }
                • right: BinaryExpression {...}
                  • type: "BinaryExpression"
                  • start: 98
                  • end: 107
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 14
                      }
                    • end: {...}
                      • line: 3
                      • column: 23
                      }
                    }
                  • left: Identifier {...}
                    • type: "Identifier"
                    • start: 98
                    • end: 103
                    • loc: {...}
                      • start: {...}
                        • line: 3
                        • column: 14
                        }
                      • end: {...}
                        • line: 3
                        • column: 19
                        }
                      }
                    • name: "count"
                    }
                  • operator: "*"
                  • right: Literal {...}
                    • type: "Literal"
                    • start: 106
                    • end: 107
                    • loc: {...}
                      • start: {...}
                        • line: 3
                        • column: 22
                        }
                      • end: {...}
                        • line: 3
                        • column: 23
                        }
                      }
                    • value: 2
                    • raw: "2"
                    }
                  }
                }
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 85
              • end: 86
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 1
                  }
                • end: {...}
                  • line: 3
                  • column: 2
                  }
                }
              • name: "$"
              }
            • leadingComments: [...] (1)
              • Line {...}
                • type: "Line"
                • value: " NOTE: use `count` in a reactive declaration before `count` is declared"
                • start: 10
                • end: 83
                }
              ]
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 110
            • end: 124
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 4
                • column: 15
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 114
                • end: 123
                • loc: {...}
                  • start: {...}
                    • line: 4
                    • column: 5
                    }
                  • end: {...}
                    • line: 4
                    • column: 14
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 114
                  • end: 119
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 5
                      }
                    • end: {...}
                      • line: 4
                      • column: 10
                      }
                    }
                  • name: "count"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 122
                  • end: 123
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 13
                      }
                    • end: {...}
                      • line: 4
                      • column: 14
                      }
                    }
                  • value: 1
                  • raw: "1"
                  }
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Compile Svelte in your Head - Reactive Declarations Reordered 2 • Playground • Svelte