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 i=0;
function onChange() {
i++;
}
</script>

<input on:change={onChange} />
loading Svelte compiler...
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

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

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

function onChange() {
i++;
}

var input = root();

$.event('change', input, onChange);
$.append($$anchor, input);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 63
    • end: 93
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 61
          • end: 63
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 63
          • end: 93
          • name: "input"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 70
              • end: 90
              • type: "OnDirective"
              • name: "change"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 81
                • end: 89
                • loc: {...}
                  • start: {...}
                    • line: 8
                    • column: 18
                    }
                  • end: {...}
                    • line: 8
                    • column: 26
                    }
                  }
                • name: "onChange"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 61
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 52
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 6
            • column: 0
            }
          }
        • body: [...] (2)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 18
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 9
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 17
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 8
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 15
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 6
                      }
                    }
                  • name: "i"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 16
                  • end: 17
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 7
                      }
                    • end: {...}
                      • line: 2
                      • column: 8
                      }
                    }
                  • value: 0
                  • raw: "0"
                  }
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 20
            • end: 51
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 5
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 29
              • end: 37
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 10
                  }
                • end: {...}
                  • line: 3
                  • column: 18
                  }
                }
              • name: "onChange"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 40
              • end: 51
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 21
                  }
                • end: {...}
                  • line: 5
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 44
                  • end: 48
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 2
                      }
                    • end: {...}
                      • line: 4
                      • column: 6
                      }
                    }
                  • expression: UpdateExpression {...}
                    • type: "UpdateExpression"
                    • start: 44
                    • end: 47
                    • loc: {...}
                      • start: {...}
                        • line: 4
                        • column: 2
                        }
                      • end: {...}
                        • line: 4
                        • column: 5
                        }
                      }
                    • operator: "++"
                    • prefix: false
                    • argument: Identifier {...}
                      • type: "Identifier"
                      • start: 44
                      • end: 45
                      • loc: {...}
                        • start: {...}
                          • line: 4
                          • column: 2
                          }
                        • end: {...}
                          • line: 4
                          • column: 3
                          }
                        }
                      • name: "i"
                      }
                    }
                  }
                ]
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Compile Svelte in your Head - on: • Playground • Svelte