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>
let name = 'world';
function update() {
name = 'Svelte';
}
</script>
<h1 on:click={update}>Hello {name}</h1>
loading Svelte compiler...
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) {
let name = $.mutable_state('world');

function update() {
$.set(name, 'Svelte');
}

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

$.reset(h1);
$.template_effect(() => $.set_text(text, `Hello ${$.get(name) ?? ''}`));
$.event('click', h1, update);
$.append($$anchor, h1);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 83
    • end: 122
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 82
          • end: 83
          • raw: "\n"
          • data: "\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 83
          • end: 122
          • name: "h1"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 87
              • end: 104
              • type: "OnDirective"
              • name: "click"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 97
                • end: 103
                • loc: {...}
                  • start: {...}
                    • line: 7
                    • column: 14
                    }
                  • end: {...}
                    • line: 7
                    • column: 20
                    }
                  }
                • name: "update"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (2)
              • Text {...}
                • type: "Text"
                • start: 105
                • end: 111
                • raw: "Hello "
                • data: "Hello "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 111
                • end: 117
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 112
                  • end: 116
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 29
                      }
                    • end: {...}
                      • line: 7
                      • column: 33
                      }
                    }
                  • name: "name"
                  }
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 82
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 73
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 6
            • column: 0
            }
          }
        • body: [...] (2)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 29
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 20
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 28
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 19
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 18
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 9
                      }
                    }
                  • name: "name"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 21
                  • end: 28
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 12
                      }
                    • end: {...}
                      • line: 2
                      • column: 19
                      }
                    }
                  • value: "world"
                  • raw: "'world'"
                  }
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 31
            • end: 72
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 5
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 40
              • end: 46
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 10
                  }
                • end: {...}
                  • line: 3
                  • column: 16
                  }
                }
              • name: "update"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 49
              • end: 72
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 19
                  }
                • end: {...}
                  • line: 5
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 53
                  • end: 69
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 2
                      }
                    • end: {...}
                      • line: 4
                      • column: 18
                      }
                    }
                  • expression: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 53
                    • end: 68
                    • loc: {...}
                      • start: {...}
                        • line: 4
                        • column: 2
                        }
                      • end: {...}
                        • line: 4
                        • column: 17
                        }
                      }
                    • operator: "="
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 53
                      • end: 57
                      • loc: {...}
                        • start: {...}
                          • line: 4
                          • column: 2
                          }
                        • end: {...}
                          • line: 4
                          • column: 6
                          }
                        }
                      • name: "name"
                      }
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 60
                      • end: 68
                      • loc: {...}
                        • start: {...}
                          • line: 4
                          • column: 9
                          }
                        • end: {...}
                          • line: 4
                          • column: 17
                          }
                        }
                      • value: "Svelte"
                      • raw: "'Svelte'"
                      }
                    }
                  }
                ]
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Compile Svelte in your Head - adding event listener • Playground • Svelte