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>
$: sum = a + b;
let a = 5;
$: b = a + 3;
</script>

<h1>the sum of {a} and {b} is {sum}!</h1>
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

var root = $.template(`<h1> </h1>`);

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

const sum = $.mutable_state();
const b = $.mutable_state();
let a = 5;

$.legacy_pre_effect(() => {}, () => {
$.set(b, a + 3);
});

$.legacy_pre_effect(() => ($.get(b)), () => {
$.set(sum, a + $.get(b));
});

$.legacy_pre_effect_reset();

var h1 = root();
var text = $.child(h1);

$.reset(h1);
$.template_effect(() => $.set_text(text, `the sum of ${a ?? ''} and ${$.get(b) ?? ''} is ${$.get(sum) ?? ''}!`));
$.append($$anchor, h1);
$.pop();
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 64
    • end: 105
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 62
          • end: 64
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 64
          • end: 105
          • name: "h1"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (7)
              • Text {...}
                • type: "Text"
                • start: 68
                • end: 79
                • raw: "the sum of "
                • data: "the sum of "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 79
                • end: 82
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 80
                  • end: 81
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 16
                      }
                    • end: {...}
                      • line: 7
                      • column: 17
                      }
                    }
                  • name: "a"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 82
                • end: 87
                • raw: " and "
                • data: " and "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 87
                • end: 90
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 88
                  • end: 89
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 24
                      }
                    • end: {...}
                      • line: 7
                      • column: 25
                      }
                    }
                  • name: "b"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 90
                • end: 94
                • raw: " is "
                • data: " is "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 94
                • end: 99
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 95
                  • end: 98
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 31
                      }
                    • end: {...}
                      • line: 7
                      • column: 34
                      }
                    }
                  • name: "sum"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 99
                • end: 100
                • raw: "!"
                • data: "!"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 62
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 53
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 5
            • column: 0
            }
          }
        • body: [...] (3)
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 10
            • end: 25
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 16
                }
              }
            • body: ExpressionStatement {...}
              • type: "ExpressionStatement"
              • start: 13
              • end: 25
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 4
                  }
                • end: {...}
                  • line: 2
                  • column: 16
                  }
                }
              • expression: AssignmentExpression {...}
                • type: "AssignmentExpression"
                • start: 13
                • end: 24
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 4
                    }
                  • end: {...}
                    • line: 2
                    • column: 15
                    }
                  }
                • operator: "="
                • left: Identifier {...}
                  • type: "Identifier"
                  • start: 13
                  • end: 16
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 4
                      }
                    • end: {...}
                      • line: 2
                      • column: 7
                      }
                    }
                  • name: "sum"
                  }
                • right: BinaryExpression {...}
                  • type: "BinaryExpression"
                  • start: 19
                  • end: 24
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 10
                      }
                    • end: {...}
                      • line: 2
                      • column: 15
                      }
                    }
                  • left: Identifier {...}
                    • type: "Identifier"
                    • start: 19
                    • end: 20
                    • loc: {...}
                      • start: {...}
                        • line: 2
                        • column: 10
                        }
                      • end: {...}
                        • line: 2
                        • column: 11
                        }
                      }
                    • name: "a"
                    }
                  • operator: "+"
                  • right: Identifier {...}
                    • type: "Identifier"
                    • start: 23
                    • end: 24
                    • loc: {...}
                      • start: {...}
                        • line: 2
                        • column: 14
                        }
                      • end: {...}
                        • line: 2
                        • column: 15
                        }
                      }
                    • name: "b"
                    }
                  }
                }
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 10
              • end: 11
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 1
                  }
                • end: {...}
                  • line: 2
                  • column: 2
                  }
                }
              • name: "$"
              }
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 27
            • end: 37
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 3
                • column: 11
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 31
                • end: 36
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 5
                    }
                  • end: {...}
                    • line: 3
                    • column: 10
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 31
                  • end: 32
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 5
                      }
                    • end: {...}
                      • line: 3
                      • column: 6
                      }
                    }
                  • name: "a"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 35
                  • end: 36
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 9
                      }
                    • end: {...}
                      • line: 3
                      • column: 10
                      }
                    }
                  • value: 5
                  • raw: "5"
                  }
                }
              ]
            • kind: "let"
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 39
            • end: 52
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 4
                • column: 14
                }
              }
            • body: ExpressionStatement {...}
              • type: "ExpressionStatement"
              • start: 42
              • end: 52
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 4
                  }
                • end: {...}
                  • line: 4
                  • column: 14
                  }
                }
              • expression: AssignmentExpression {...}
                • type: "AssignmentExpression"
                • start: 42
                • end: 51
                • loc: {...}
                  • start: {...}
                    • line: 4
                    • column: 4
                    }
                  • end: {...}
                    • line: 4
                    • column: 13
                    }
                  }
                • operator: "="
                • left: Identifier {...}
                  • type: "Identifier"
                  • start: 42
                  • end: 43
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 4
                      }
                    • end: {...}
                      • line: 4
                      • column: 5
                      }
                    }
                  • name: "b"
                  }
                • right: BinaryExpression {...}
                  • type: "BinaryExpression"
                  • start: 46
                  • end: 51
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 8
                      }
                    • end: {...}
                      • line: 4
                      • column: 13
                      }
                    }
                  • left: Identifier {...}
                    • type: "Identifier"
                    • start: 46
                    • end: 47
                    • loc: {...}
                      • start: {...}
                        • line: 4
                        • column: 8
                        }
                      • end: {...}
                        • line: 4
                        • column: 9
                        }
                      }
                    • name: "a"
                    }
                  • operator: "+"
                  • right: Literal {...}
                    • type: "Literal"
                    • start: 50
                    • end: 51
                    • loc: {...}
                      • start: {...}
                        • line: 4
                        • column: 12
                        }
                      • end: {...}
                        • line: 4
                        • column: 13
                        }
                      }
                    • value: 3
                    • raw: "3"
                    }
                  }
                }
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 39
              • end: 40
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 1
                  }
                • end: {...}
                  • line: 4
                  • column: 2
                  }
                }
              • name: "$"
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
order doesn't matter • Playground • Svelte