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 = '';
function action() {}
function updateI() {
i++;
}
</script>

<div use:action={i} />
loading Svelte compiler...
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

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

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

function action() {}

function updateI() {
$.update(i);
}

var div = root();

$.action(div, ($$node, $$action_arg) => action?.($$node, $$action_arg), () => $.get(i));
$.append($$anchor, div);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 91
    • end: 113
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 89
          • end: 91
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 91
          • end: 113
          • name: "div"
          • attributes: [...] (1)
            • UseDirective {...}
              • start: 96
              • end: 110
              • type: "UseDirective"
              • name: "action"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 108
                • end: 109
                • loc: {...}
                  • start: {...}
                    • line: 9
                    • column: 17
                    }
                  • end: {...}
                    • line: 9
                    • column: 18
                    }
                  }
                • name: "i"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 89
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 80
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 7
            • column: 0
            }
          }
        • body: [...] (3)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 21
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 12
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 20
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 11
                    }
                  }
                • 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: 18
                  • end: 20
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 9
                      }
                    • end: {...}
                      • line: 2
                      • column: 11
                      }
                    }
                  • value: ""
                  • raw: "''"
                  }
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 23
            • end: 43
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 3
                • column: 21
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 32
              • end: 38
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 10
                  }
                • end: {...}
                  • line: 3
                  • column: 16
                  }
                }
              • name: "action"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 41
              • end: 43
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 19
                  }
                • end: {...}
                  • line: 3
                  • column: 21
                  }
                }
              • body: []
              }
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 46
            • end: 79
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 2
                }
              • end: {...}
                • line: 6
                • column: 3
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 55
              • end: 62
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 11
                  }
                • end: {...}
                  • line: 4
                  • column: 18
                  }
                }
              • name: "updateI"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 65
              • end: 79
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 21
                  }
                • end: {...}
                  • line: 6
                  • column: 3
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 71
                  • end: 75
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 4
                      }
                    • end: {...}
                      • line: 5
                      • column: 8
                      }
                    }
                  • expression: UpdateExpression {...}
                    • type: "UpdateExpression"
                    • start: 71
                    • end: 74
                    • loc: {...}
                      • start: {...}
                        • line: 5
                        • column: 4
                        }
                      • end: {...}
                        • line: 5
                        • column: 7
                        }
                      }
                    • operator: "++"
                    • prefix: false
                    • argument: Identifier {...}
                      • type: "Identifier"
                      • start: 71
                      • end: 72
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 4
                          }
                        • end: {...}
                          • line: 5
                          • column: 5
                          }
                        }
                      • name: "i"
                      }
                    }
                  }
                ]
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Compile Svelte in your Head - use: • Playground • Svelte