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 a = 1;
let b = 2;
</script>

<input type="number" bind:value={a}>
<input type="number" bind:value={b}>

<p>{a} + {b} = {a + b}</p>
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

var root = $.template(`<input type="number"> <input type="number"> <p> </p>`, 1);

export default function App($$anchor) {
let a = $.mutable_state(1);
let b = $.mutable_state(2);
var fragment = root();
var input = $.first_child(fragment);

$.remove_input_defaults(input);

var input_1 = $.sibling(input, 2);

$.remove_input_defaults(input_1);

var p = $.sibling(input_1, 2);
var text = $.child(p);

$.reset(p);
$.template_effect(() => $.set_text(text, `${$.get(a) ?? ''} + ${$.get(b) ?? ''} = ${$.get(a) + $.get(b)}`));
$.bind_value(input, () => $.get(a), ($$value) => $.set(a, $$value));
$.bind_value(input_1, () => $.get(b), ($$value) => $.set(b, $$value));
$.append($$anchor, fragment);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 44
    • end: 145
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (6)
        • Text {...}
          • type: "Text"
          • start: 42
          • end: 44
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 44
          • end: 80
          • name: "input"
          • attributes: [...] (2)
            • Attribute {...}
              • type: "Attribute"
              • start: 51
              • end: 64
              • name: "type"
              • value: [...] (1)
                • Text {...}
                  • start: 57
                  • end: 63
                  • type: "Text"
                  • raw: "number"
                  • data: "number"
                  }
                ]
              }
            • BindDirective {...}
              • start: 65
              • end: 79
              • type: "BindDirective"
              • name: "value"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 77
                • end: 78
                • loc: {...}
                  • start: {...}
                    • line: 6
                    • column: 33
                    }
                  • end: {...}
                    • line: 6
                    • column: 34
                    }
                  }
                • name: "a"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 80
          • end: 81
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 81
          • end: 117
          • name: "input"
          • attributes: [...] (2)
            • Attribute {...}
              • type: "Attribute"
              • start: 88
              • end: 101
              • name: "type"
              • value: [...] (1)
                • Text {...}
                  • start: 94
                  • end: 100
                  • type: "Text"
                  • raw: "number"
                  • data: "number"
                  }
                ]
              }
            • BindDirective {...}
              • start: 102
              • end: 116
              • type: "BindDirective"
              • name: "value"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 114
                • end: 115
                • loc: {...}
                  • start: {...}
                    • line: 7
                    • column: 33
                    }
                  • end: {...}
                    • line: 7
                    • column: 34
                    }
                  }
                • name: "b"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 117
          • end: 119
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 119
          • end: 145
          • name: "p"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (5)
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 122
                • end: 125
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 123
                  • end: 124
                  • loc: {...}
                    • start: {...}
                      • line: 9
                      • column: 4
                      }
                    • end: {...}
                      • line: 9
                      • column: 5
                      }
                    }
                  • name: "a"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 125
                • end: 128
                • raw: " + "
                • data: " + "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 128
                • end: 131
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 129
                  • end: 130
                  • loc: {...}
                    • start: {...}
                      • line: 9
                      • column: 10
                      }
                    • end: {...}
                      • line: 9
                      • column: 11
                      }
                    }
                  • name: "b"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 131
                • end: 134
                • raw: " = "
                • data: " = "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 134
                • end: 141
                • expression: BinaryExpression {...}
                  • type: "BinaryExpression"
                  • start: 135
                  • end: 140
                  • loc: {...}
                    • start: {...}
                      • line: 9
                      • column: 16
                      }
                    • end: {...}
                      • line: 9
                      • column: 21
                      }
                    }
                  • left: Identifier {...}
                    • type: "Identifier"
                    • start: 135
                    • end: 136
                    • loc: {...}
                      • start: {...}
                        • line: 9
                        • column: 16
                        }
                      • end: {...}
                        • line: 9
                        • column: 17
                        }
                      }
                    • name: "a"
                    }
                  • operator: "+"
                  • right: Identifier {...}
                    • type: "Identifier"
                    • start: 139
                    • end: 140
                    • loc: {...}
                      • start: {...}
                        • line: 9
                        • column: 20
                        }
                      • end: {...}
                        • line: 9
                        • column: 21
                        }
                      }
                    • name: "b"
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 42
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 33
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 4
            • column: 0
            }
          }
        • body: [...] (2)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 20
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 11
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 19
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 10
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 15
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 6
                      }
                    }
                  • name: "a"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 18
                  • end: 19
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 9
                      }
                    • end: {...}
                      • line: 2
                      • column: 10
                      }
                    }
                  • value: 1
                  • raw: "1"
                  }
                }
              ]
            • kind: "let"
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 22
            • end: 32
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 3
                • column: 11
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 26
                • end: 31
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 5
                    }
                  • end: {...}
                    • line: 3
                    • column: 10
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 26
                  • end: 27
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 5
                      }
                    • end: {...}
                      • line: 3
                      • column: 6
                      }
                    }
                  • name: "b"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 30
                  • end: 31
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 9
                      }
                    • end: {...}
                      • line: 3
                      • column: 10
                      }
                    }
                  • value: 2
                  • raw: "2"
                  }
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Hello world • Playground • Svelte