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 = 4;
let b = 9;
let sum;
function calcSum() {
sum = a + b;
}
function sendSumToServer() {
console.log("sending", sum);
}
$: {
calcSum();
sendSumToServer();
}
</script>
<label>a: <input type="number" bind:value={a}></label>
<label>b: <input type="number" bind:value={b}></label>
<p>{sum}</p>
sending 13
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

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

export default function App($$anchor, $$props) {
$.push($$props, false);

let a = $.mutable_state(4);
let b = $.mutable_state(9);
let sum = $.mutable_state();

function calcSum() {
$.set(sum, $.get(a) + $.get(b));
}

function sendSumToServer() {
console.log("sending", $.get(sum));
}

$.legacy_pre_effect(() => {}, () => {
calcSum();
sendSumToServer();
});

$.legacy_pre_effect_reset();

var fragment = root();
var label = $.first_child(fragment);
var input = $.sibling($.child(label));

$.remove_input_defaults(input);
$.reset(label);

var label_1 = $.sibling(label, 2);
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 200
    • end: 324
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (6)
        • Text {...}
          • type: "Text"
          • start: 199
          • end: 200
          • raw: "\n"
          • data: "\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 200
          • end: 254
          • name: "label"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (2)
              • Text {...}
                • type: "Text"
                • start: 207
                • end: 210
                • raw: "a: "
                • data: "a: "
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 210
                • end: 246
                • name: "input"
                • attributes: [...] (2)
                  • Attribute {...}
                    • type: "Attribute"
                    • start: 217
                    • end: 230
                    • name: "type"
                    • value: [...] (1)
                      • Text {...}
                        • start: 223
                        • end: 229
                        • type: "Text"
                        • raw: "number"
                        • data: "number"
                        }
                      ]
                    }
                  • BindDirective {...}
                    • start: 231
                    • end: 245
                    • type: "BindDirective"
                    • name: "value"
                    • expression: Identifier {...}
                      • type: "Identifier"
                      • start: 243
                      • end: 244
                      • loc: {...}
                        • start: {...}
                          • line: 16
                          • column: 43
                          }
                        • end: {...}
                          • line: 16
                          • column: 44
                          }
                        }
                      • name: "a"
                      }
                    • modifiers: []
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: []
                  }
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 254
          • end: 256
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 256
          • end: 310
          • name: "label"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (2)
              • Text {...}
                • type: "Text"
                • start: 263
                • end: 266
                • raw: "b: "
                • data: "b: "
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 266
                • end: 302
                • name: "input"
                • attributes: [...] (2)
                  • Attribute {...}
                    • type: "Attribute"
                    • start: 273
                    • end: 286
                    • name: "type"
                    • value: [...] (1)
                      • Text {...}
                        • start: 279
                        • end: 285
                        • type: "Text"
                        • raw: "number"
                        • data: "number"
                        }
                      ]
                    }
                  • BindDirective {...}
                    • start: 287
                    • end: 301
                    • type: "BindDirective"
                    • name: "value"
                    • expression: Identifier {...}
                      • type: "Identifier"
                      • start: 299
                      • end: 300
                      • loc: {...}
                        • start: {...}
                          • line: 17
                          • column: 43
                          }
                        • end: {...}
                          • line: 17
                          • column: 44
                          }
                        }
                      • name: "b"
                      }
                    • modifiers: []
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: []
                  }
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 310
          • end: 312
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 312
          • end: 324
          • name: "p"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 315
                • end: 320
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 316
                  • end: 319
                  • loc: {...}
                    • start: {...}
                      • line: 18
                      • column: 4
                      }
                    • end: {...}
                      • line: 18
                      • column: 7
                      }
                    }
                  • name: "sum"
                  }
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 199
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 190
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 15
            • column: 0
            }
          }
        • body: [...] (6)
          • 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: 4
                  • raw: "4"
                  }
                }
              ]
            • 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: 9
                  • raw: "9"
                  }
                }
              ]
            • kind: "let"
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 34
            • end: 42
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 4
                • column: 9
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 38
                • end: 41
                • loc: {...}
                  • start: {...}
                    • line: 4
                    • column: 5
                    }
                  • end: {...}
                    • line: 4
                    • column: 8
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 38
                  • end: 41
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 5
                      }
                    • end: {...}
                      • line: 4
                      • column: 8
                      }
                    }
                  • name: "sum"
                  }
                • init: null
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 44
            • end: 82
            • loc: {...}
              • start: {...}
                • line: 5
                • column: 1
                }
              • end: {...}
                • line: 7
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 53
              • end: 60
              • loc: {...}
                • start: {...}
                  • line: 5
                  • column: 10
                  }
                • end: {...}
                  • line: 5
                  • column: 17
                  }
                }
              • name: "calcSum"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 63
              • end: 82
              • loc: {...}
                • start: {...}
                  • line: 5
                  • column: 20
                  }
                • end: {...}
                  • line: 7
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 67
                  • end: 79
                  • loc: {...}
                    • start: {...}
                      • line: 6
                      • column: 2
                      }
                    • end: {...}
                      • line: 6
                      • column: 14
                      }
                    }
                  • expression: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 67
                    • end: 78
                    • loc: {...}
                      • start: {...}
                        • line: 6
                        • column: 2
                        }
                      • end: {...}
                        • line: 6
                        • column: 13
                        }
                      }
                    • operator: "="
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 67
                      • end: 70
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 2
                          }
                        • end: {...}
                          • line: 6
                          • column: 5
                          }
                        }
                      • name: "sum"
                      }
                    • right: BinaryExpression {...}
                      • type: "BinaryExpression"
                      • start: 73
                      • end: 78
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 8
                          }
                        • end: {...}
                          • line: 6
                          • column: 13
                          }
                        }
                      • left: Identifier {...}
                        • type: "Identifier"
                        • start: 73
                        • end: 74
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 8
                            }
                          • end: {...}
                            • line: 6
                            • column: 9
                            }
                          }
                        • name: "a"
                        }
                      • operator: "+"
                      • right: Identifier {...}
                        • type: "Identifier"
                        • start: 77
                        • end: 78
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 12
                            }
                          • end: {...}
                            • line: 6
                            • column: 13
                            }
                          }
                        • name: "b"
                        }
                      }
                    }
                  }
                ]
              }
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 84
            • end: 146
            • loc: {...}
              • start: {...}
                • line: 8
                • column: 1
                }
              • end: {...}
                • line: 10
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 93
              • end: 108
              • loc: {...}
                • start: {...}
                  • line: 8
                  • column: 10
                  }
                • end: {...}
                  • line: 8
                  • column: 25
                  }
                }
              • name: "sendSumToServer"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 111
              • end: 146
              • loc: {...}
                • start: {...}
                  • line: 8
                  • column: 28
                  }
                • end: {...}
                  • line: 10
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 115
                  • end: 143
                  • loc: {...}
                    • start: {...}
                      • line: 9
                      • column: 2
                      }
                    • end: {...}
                      • line: 9
                      • column: 30
                      }
                    }
                  • expression: CallExpression {...}
                    • type: "CallExpression"
                    • start: 115
                    • end: 142
                    • loc: {...}
                      • start: {...}
                        • line: 9
                        • column: 2
                        }
                      • end: {...}
                        • line: 9
                        • column: 29
                        }
                      }
                    • callee: MemberExpression {...}
                      • type: "MemberExpression"
                      • start: 115
                      • end: 126
                      • loc: {...}
                        • start: {...}
                          • line: 9
                          • column: 2
                          }
                        • end: {...}
                          • line: 9
                          • column: 13
                          }
                        }
                      • object: Identifier {...}
                        • type: "Identifier"
                        • start: 115
                        • end: 122
                        • loc: {...}
                          • start: {...}
                            • line: 9
                            • column: 2
                            }
                          • end: {...}
                            • line: 9
                            • column: 9
                            }
                          }
                        • name: "console"
                        }
                      • property: Identifier {...}
                        • type: "Identifier"
                        • start: 123
                        • end: 126
                        • loc: {...}
                          • start: {...}
                            • line: 9
                            • column: 10
                            }
                          • end: {...}
                            • line: 9
                            • column: 13
                            }
                          }
                        • name: "log"
                        }
                      • computed: false
                      • optional: false
                      }
                    • arguments: [...] (2)
                      • Literal {...}
                        • type: "Literal"
                        • start: 127
                        • end: 136
                        • loc: {...}
                          • start: {...}
                            • line: 9
                            • column: 14
                            }
                          • end: {...}
                            • line: 9
                            • column: 23
                            }
                          }
                        • value: "sending"
                        • raw: "\"sending\""
                        }
                      • Identifier {...}
                        • type: "Identifier"
                        • start: 138
                        • end: 141
                        • loc: {...}
                          • start: {...}
                            • line: 9
                            • column: 25
                            }
                          • end: {...}
                            • line: 9
                            • column: 28
                            }
                          }
                        • name: "sum"
                        }
                      ]
                    • optional: false
                    }
                  }
                ]
              }
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 148
            • end: 189
            • loc: {...}
              • start: {...}
                • line: 11
                • column: 1
                }
              • end: {...}
                • line: 14
                • column: 2
                }
              }
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 151
              • end: 189
              • loc: {...}
                • start: {...}
                  • line: 11
                  • column: 4
                  }
                • end: {...}
                  • line: 14
                  • column: 2
                  }
                }
              • body: [...] (2)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 155
                  • end: 165
                  • loc: {...}
                    • start: {...}
                      • line: 12
                      • column: 2
                      }
                    • end: {...}
                      • line: 12
                      • column: 12
                      }
                    }
                  • expression: CallExpression {...}
                    • type: "CallExpression"
                    • start: 155
                    • end: 164
                    • loc: {...}
                      • start: {...}
                        • line: 12
                        • column: 2
                        }
                      • end: {...}
                        • line: 12
                        • column: 11
                        }
                      }
                    • callee: Identifier {...}
                      • type: "Identifier"
                      • start: 155
                      • end: 162
                      • loc: {...}
                        • start: {...}
                          • line: 12
                          • column: 2
                          }
                        • end: {...}
                          • line: 12
                          • column: 9
                          }
                        }
                      • name: "calcSum"
                      }
                    • arguments: []
                    • optional: false
                    }
                  }
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 168
                  • end: 186
                  • loc: {...}
                    • start: {...}
                      • line: 13
                      • column: 2
                      }
                    • end: {...}
                      • line: 13
                      • column: 20
                      }
                    }
                  • expression: CallExpression {...}
                    • type: "CallExpression"
                    • start: 168
                    • end: 185
                    • loc: {...}
                      • start: {...}
                        • line: 13
                        • column: 2
                        }
                      • end: {...}
                        • line: 13
                        • column: 19
                        }
                      }
                    • callee: Identifier {...}
                      • type: "Identifier"
                      • start: 168
                      • end: 183
                      • loc: {...}
                        • start: {...}
                          • line: 13
                          • column: 2
                          }
                        • end: {...}
                          • line: 13
                          • column: 17
                          }
                        }
                      • name: "sendSumToServer"
                      }
                    • arguments: []
                    • optional: false
                    }
                  }
                ]
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 148
              • end: 149
              • loc: {...}
                • start: {...}
                  • line: 11
                  • column: 1
                  }
                • end: {...}
                  • line: 11
                  • column: 2
                  }
                }
              • name: "$"
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
implicit deps broken • Playground • Svelte