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 count = 0;
function onClickButton(event) {
console.log(count);
}
</script>
<button on:click={onClickButton}>Clicked {count}</button>
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';

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

export default function App($$anchor) {
let count = 0;

function onClickButton(event) {
console.log(count);
}

var button = root();

button.textContent = `Clicked ${count ?? ''}`;
$.event('click', button, onClickButton);
$.append($$anchor, button);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 98
    • end: 155
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 97
          • end: 98
          • raw: "\n"
          • data: "\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 98
          • end: 155
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 106
              • end: 130
              • type: "OnDirective"
              • name: "click"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 116
                • end: 129
                • loc: {...}
                  • start: {...}
                    • line: 7
                    • column: 18
                    }
                  • end: {...}
                    • line: 7
                    • column: 31
                    }
                  }
                • name: "onClickButton"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (2)
              • Text {...}
                • type: "Text"
                • start: 131
                • end: 139
                • raw: "Clicked "
                • data: "Clicked "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 139
                • end: 146
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 140
                  • end: 145
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 42
                      }
                    • end: {...}
                      • line: 7
                      • column: 47
                      }
                    }
                  • name: "count"
                  }
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 97
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 88
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 6
            • column: 0
            }
          }
        • body: [...] (2)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 11
            • end: 25
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 2
                }
              • end: {...}
                • line: 2
                • column: 16
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 15
                • end: 24
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 6
                    }
                  • end: {...}
                    • line: 2
                    • column: 15
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 15
                  • end: 20
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 6
                      }
                    • end: {...}
                      • line: 2
                      • column: 11
                      }
                    }
                  • name: "count"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 23
                  • end: 24
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 14
                      }
                    • end: {...}
                      • line: 2
                      • column: 15
                      }
                    }
                  • value: 0
                  • raw: "0"
                  }
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 28
            • end: 87
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 2
                }
              • end: {...}
                • line: 5
                • column: 3
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 37
              • end: 50
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 11
                  }
                • end: {...}
                  • line: 3
                  • column: 24
                  }
                }
              • name: "onClickButton"
              }
            • expression: false
            • generator: false
            • async: false
            • params: [...] (1)
              • Identifier {...}
                • type: "Identifier"
                • start: 51
                • end: 56
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 25
                    }
                  • end: {...}
                    • line: 3
                    • column: 30
                    }
                  }
                • name: "event"
                }
              ]
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 58
              • end: 87
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 32
                  }
                • end: {...}
                  • line: 5
                  • column: 3
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 64
                  • end: 83
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 4
                      }
                    • end: {...}
                      • line: 4
                      • column: 23
                      }
                    }
                  • expression: CallExpression {...}
                    • type: "CallExpression"
                    • start: 64
                    • end: 82
                    • loc: {...}
                      • start: {...}
                        • line: 4
                        • column: 4
                        }
                      • end: {...}
                        • line: 4
                        • column: 22
                        }
                      }
                    • callee: MemberExpression {...}
                      • type: "MemberExpression"
                      • start: 64
                      • end: 75
                      • loc: {...}
                        • start: {...}
                          • line: 4
                          • column: 4
                          }
                        • end: {...}
                          • line: 4
                          • column: 15
                          }
                        }
                      • object: Identifier {...}
                        • type: "Identifier"
                        • start: 64
                        • end: 71
                        • loc: {...}
                          • start: {...}
                            • line: 4
                            • column: 4
                            }
                          • end: {...}
                            • line: 4
                            • column: 11
                            }
                          }
                        • name: "console"
                        }
                      • property: Identifier {...}
                        • type: "Identifier"
                        • start: 72
                        • end: 75
                        • loc: {...}
                          • start: {...}
                            • line: 4
                            • column: 12
                            }
                          • end: {...}
                            • line: 4
                            • column: 15
                            }
                          }
                        • name: "log"
                        }
                      • computed: false
                      • optional: false
                      }
                    • arguments: [...] (1)
                      • Identifier {...}
                        • type: "Identifier"
                        • start: 76
                        • end: 81
                        • loc: {...}
                          • start: {...}
                            • line: 4
                            • column: 16
                            }
                          • end: {...}
                            • line: 4
                            • column: 21
                            }
                          }
                        • name: "count"
                        }
                      ]
                    • optional: false
                    }
                  }
                ]
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Compile Svelte in your Head - Hello World event handler • Playground • Svelte