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 onClick() {
i++;
}
</script>

<button on:click|preventDefault={onClick} />
<button on:change|stopPropagation={onClick} />
<button on:change|once={onClick} />
<button on:change|capture={onClick} />

<button on:click|preventDefault|stopPropagation|once|capture={onClick} />
resolving svelte/internal/client
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

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

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

function onClick() {
i++;
}

var fragment = root();
var button = $.first_child(fragment);
var button_1 = $.sibling(button, 2);
var button_2 = $.sibling(button_1, 2);
var button_3 = $.sibling(button_2, 2);
var button_4 = $.sibling(button_3, 2);

$.event('click', button, $.preventDefault(onClick));
$.event('change', button_1, $.stopPropagation(onClick));
$.event('change', button_2, $.once(onClick));
$.event('change', button_3, onClick, true);
$.event('click', button_4, $.once($.preventDefault($.stopPropagation(onClick))), true);
$.append($$anchor, fragment);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 62
    • end: 303
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (10)
        • Text {...}
          • type: "Text"
          • start: 60
          • end: 62
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 62
          • end: 106
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 70
              • end: 103
              • type: "OnDirective"
              • name: "click"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 95
                • end: 102
                • loc: {...}
                  • start: {...}
                    • line: 8
                    • column: 33
                    }
                  • end: {...}
                    • line: 8
                    • column: 40
                    }
                  }
                • name: "onClick"
                }
              • modifiers: [...] (1)
                • "preventDefault"
                ]
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 106
          • end: 107
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 107
          • end: 153
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 115
              • end: 150
              • type: "OnDirective"
              • name: "change"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 142
                • end: 149
                • loc: {...}
                  • start: {...}
                    • line: 9
                    • column: 35
                    }
                  • end: {...}
                    • line: 9
                    • column: 42
                    }
                  }
                • name: "onClick"
                }
              • modifiers: [...] (1)
                • "stopPropagation"
                ]
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 153
          • end: 154
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 154
          • end: 189
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 162
              • end: 186
              • type: "OnDirective"
              • name: "change"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 178
                • end: 185
                • loc: {...}
                  • start: {...}
                    • line: 10
                    • column: 24
                    }
                  • end: {...}
                    • line: 10
                    • column: 31
                    }
                  }
                • name: "onClick"
                }
              • modifiers: [...] (1)
                • "once"
                ]
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 189
          • end: 190
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 190
          • end: 228
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 198
              • end: 225
              • type: "OnDirective"
              • name: "change"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 217
                • end: 224
                • loc: {...}
                  • start: {...}
                    • line: 11
                    • column: 27
                    }
                  • end: {...}
                    • line: 11
                    • column: 34
                    }
                  }
                • name: "onClick"
                }
              • modifiers: [...] (1)
                • "capture"
                ]
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 228
          • end: 230
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 230
          • end: 303
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 238
              • end: 300
              • type: "OnDirective"
              • name: "click"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 292
                • end: 299
                • loc: {...}
                  • start: {...}
                    • line: 13
                    • column: 62
                    }
                  • end: {...}
                    • line: 13
                    • column: 69
                    }
                  }
                • name: "onClick"
                }
              • modifiers: [...] (4)
                • "preventDefault"
                • "stopPropagation"
                • "once"
                • "capture"
                ]
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 60
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 51
        • 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: 50
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 5
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 29
              • end: 36
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 10
                  }
                • end: {...}
                  • line: 3
                  • column: 17
                  }
                }
              • name: "onClick"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 39
              • end: 50
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 20
                  }
                • end: {...}
                  • line: 5
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 43
                  • end: 47
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 2
                      }
                    • end: {...}
                      • line: 4
                      • column: 6
                      }
                    }
                  • expression: UpdateExpression {...}
                    • type: "UpdateExpression"
                    • start: 43
                    • end: 46
                    • loc: {...}
                      • start: {...}
                        • line: 4
                        • column: 2
                        }
                      • end: {...}
                        • line: 4
                        • column: 5
                        }
                      }
                    • operator: "++"
                    • prefix: false
                    • argument: Identifier {...}
                      • type: "Identifier"
                      • start: 43
                      • end: 44
                      • 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: modifiers • Playground • Svelte