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 checked;
function onChange() {}
function action() {}
</script>

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

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

export default function App($$anchor) {
let checked = $.mutable_state();

function onChange() {}
function action() {}

var input = root();

$.remove_input_defaults(input);
$.effect(() => $.bind_checked(input, () => $.get(checked), ($$value) => $.set(checked, $$value)));
$.effect(() => $.event('change', input, onChange));
$.action(input, ($$node) => action?.($$node));
$.append($$anchor, input);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 80
    • end: 152
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 78
          • end: 80
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 80
          • end: 152
          • name: "input"
          • attributes: [...] (4)
            • Attribute {...}
              • type: "Attribute"
              • start: 88
              • end: 101
              • name: "type"
              • value: [...] (1)
                • Text {...}
                  • start: 93
                  • end: 101
                  • type: "Text"
                  • raw: "checkbox"
                  • data: "checkbox"
                  }
                ]
              }
            • BindDirective {...}
              • start: 103
              • end: 115
              • type: "BindDirective"
              • name: "checked"
              • expression: Identifier {...}
                • start: 108
                • end: 115
                • type: "Identifier"
                • name: "checked"
                }
              • modifiers: []
              }
            • OnDirective {...}
              • start: 117
              • end: 137
              • type: "OnDirective"
              • name: "change"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 128
                • end: 136
                • loc: {...}
                  • start: {...}
                    • line: 10
                    • column: 12
                    }
                  • end: {...}
                    • line: 10
                    • column: 20
                    }
                  }
                • name: "onChange"
                }
              • modifiers: []
              }
            • UseDirective {...}
              • start: 139
              • end: 149
              • type: "UseDirective"
              • name: "action"
              • expression: null
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 78
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 69
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 5
            • column: 0
            }
          }
        • body: [...] (3)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 22
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 13
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 21
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 12
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 21
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 12
                      }
                    }
                  • name: "checked"
                  }
                • init: null
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 24
            • end: 46
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 3
                • column: 23
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 33
              • end: 41
              • 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: 44
              • end: 46
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 21
                  }
                • end: {...}
                  • line: 3
                  • column: 23
                  }
                }
              • body: []
              }
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 48
            • end: 68
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 4
                • column: 21
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 57
              • end: 63
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 10
                  }
                • end: {...}
                  • line: 4
                  • column: 16
                  }
                }
              • name: "action"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 66
              • end: 68
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 19
                  }
                • end: {...}
                  • line: 4
                  • column: 21
                  }
                }
              • body: []
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Compile Svelte in your Head - directive orders • Playground • Svelte