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(a,b) {
sum = a + b;
}
function sendSumToServer(sum) {
console.log("sending", sum);
}
$: {
calcSum(a,b);
sendSumToServer(sum);
}
</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(a, b) {
$.set(sum, a + b);
}

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

$.legacy_pre_effect(() => ($.get(a), $.get(b), $.get(sum)), () => {
calcSum($.get(a), $.get(b));
sendSumToServer($.get(sum));
});

$.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: 212
    • end: 336
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (6)
        • Text {...}
          • type: "Text"
          • start: 211
          • end: 212
          • raw: "\n"
          • data: "\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 212
          • end: 266
          • name: "label"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (2)
              • Text {...}
                • type: "Text"
                • start: 219
                • end: 222
                • raw: "a: "
                • data: "a: "
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 222
                • end: 258
                • name: "input"
                • attributes: [...] (2)
                  • Attribute {...}
                    • type: "Attribute"
                    • start: 229
                    • end: 242
                    • name: "type"
                    • value: [...] (1)
                      • Text {...}
                        • start: 235
                        • end: 241
                        • type: "Text"
                        • raw: "number"
                        • data: "number"
                        }
                      ]
                    }
                  • BindDirective {...}
                    • start: 243
                    • end: 257
                    • type: "BindDirective"
                    • name: "value"
                    • expression: Identifier {...}
                      • type: "Identifier"
                      • start: 255
                      • end: 256
                      • loc: {...}
                        • start: {...}
                          • line: 16
                          • column: 43
                          }
                        • end: {...}
                          • line: 16
                          • column: 44
                          }
                        }
                      • name: "a"
                      }
                    • modifiers: []
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: []
                  }
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 266
          • end: 268
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 268
          • end: 322
          • name: "label"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (2)
              • Text {...}
                • type: "Text"
                • start: 275
                • end: 278
                • raw: "b: "
                • data: "b: "
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 278
                • end: 314
                • name: "input"
                • attributes: [...] (2)
                  • Attribute {...}
                    • type: "Attribute"
                    • start: 285
                    • end: 298
                    • name: "type"
                    • value: [...] (1)
                      • Text {...}
                        • start: 291
                        • end: 297
                        • type: "Text"
                        • raw: "number"
                        • data: "number"
                        }
                      ]
                    }
                  • BindDirective {...}
                    • start: 299
                    • end: 313
                    • type: "BindDirective"
                    • name: "value"
                    • expression: Identifier {...}
                      • type: "Identifier"
                      • start: 311
                      • end: 312
                      • loc: {...}
                        • start: {...}
                          • line: 17
                          • column: 43
                          }
                        • end: {...}
                          • line: 17
                          • column: 44
                          }
                        }
                      • name: "b"
                      }
                    • modifiers: []
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: []
                  }
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 322
          • end: 324
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 324
          • end: 336
          • name: "p"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 327
                • end: 332
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 328
                  • end: 331
                  • loc: {...}
                    • start: {...}
                      • line: 18
                      • column: 4
                      }
                    • end: {...}
                      • line: 18
                      • column: 7
                      }
                    }
                  • name: "sum"
                  }
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 211
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 202
        • 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: 85
            • 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: [...] (2)
              • Identifier {...}
                • type: "Identifier"
                • start: 61
                • end: 62
                • loc: {...}
                  • start: {...}
                    • line: 5
                    • column: 18
                    }
                  • end: {...}
                    • line: 5
                    • column: 19
                    }
                  }
                • name: "a"
                }
              • Identifier {...}
                • type: "Identifier"
                • start: 63
                • end: 64
                • loc: {...}
                  • start: {...}
                    • line: 5
                    • column: 20
                    }
                  • end: {...}
                    • line: 5
                    • column: 21
                    }
                  }
                • name: "b"
                }
              ]
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 66
              • end: 85
              • loc: {...}
                • start: {...}
                  • line: 5
                  • column: 23
                  }
                • end: {...}
                  • line: 7
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 70
                  • end: 82
                  • loc: {...}
                    • start: {...}
                      • line: 6
                      • column: 2
                      }
                    • end: {...}
                      • line: 6
                      • column: 14
                      }
                    }
                  • expression: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 70
                    • end: 81
                    • loc: {...}
                      • start: {...}
                        • line: 6
                        • column: 2
                        }
                      • end: {...}
                        • line: 6
                        • column: 13
                        }
                      }
                    • operator: "="
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 70
                      • end: 73
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 2
                          }
                        • end: {...}
                          • line: 6
                          • column: 5
                          }
                        }
                      • name: "sum"
                      }
                    • right: BinaryExpression {...}
                      • type: "BinaryExpression"
                      • start: 76
                      • end: 81
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 8
                          }
                        • end: {...}
                          • line: 6
                          • column: 13
                          }
                        }
                      • left: Identifier {...}
                        • type: "Identifier"
                        • start: 76
                        • end: 77
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 8
                            }
                          • end: {...}
                            • line: 6
                            • column: 9
                            }
                          }
                        • name: "a"
                        }
                      • operator: "+"
                      • right: Identifier {...}
                        • type: "Identifier"
                        • start: 80
                        • end: 81
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 12
                            }
                          • end: {...}
                            • line: 6
                            • column: 13
                            }
                          }
                        • name: "b"
                        }
                      }
                    }
                  }
                ]
              }
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 87
            • end: 152
            • loc: {...}
              • start: {...}
                • line: 8
                • column: 1
                }
              • end: {...}
                • line: 10
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 96
              • end: 111
              • loc: {...}
                • start: {...}
                  • line: 8
                  • column: 10
                  }
                • end: {...}
                  • line: 8
                  • column: 25
                  }
                }
              • name: "sendSumToServer"
              }
            • expression: false
            • generator: false
            • async: false
            • params: [...] (1)
              • Identifier {...}
                • type: "Identifier"
                • start: 112
                • end: 115
                • loc: {...}
                  • start: {...}
                    • line: 8
                    • column: 26
                    }
                  • end: {...}
                    • line: 8
                    • column: 29
                    }
                  }
                • name: "sum"
                }
              ]
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 117
              • end: 152
              • loc: {...}
                • start: {...}
                  • line: 8
                  • column: 31
                  }
                • end: {...}
                  • line: 10
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 121
                  • end: 149
                  • loc: {...}
                    • start: {...}
                      • line: 9
                      • column: 2
                      }
                    • end: {...}
                      • line: 9
                      • column: 30
                      }
                    }
                  • expression: CallExpression {...}
                    • type: "CallExpression"
                    • start: 121
                    • end: 148
                    • loc: {...}
                      • start: {...}
                        • line: 9
                        • column: 2
                        }
                      • end: {...}
                        • line: 9
                        • column: 29
                        }
                      }
                    • callee: MemberExpression {...}
                      • type: "MemberExpression"
                      • start: 121
                      • end: 132
                      • loc: {...}
                        • start: {...}
                          • line: 9
                          • column: 2
                          }
                        • end: {...}
                          • line: 9
                          • column: 13
                          }
                        }
                      • object: Identifier {...}
                        • type: "Identifier"
                        • start: 121
                        • end: 128
                        • loc: {...}
                          • start: {...}
                            • line: 9
                            • column: 2
                            }
                          • end: {...}
                            • line: 9
                            • column: 9
                            }
                          }
                        • name: "console"
                        }
                      • property: Identifier {...}
                        • type: "Identifier"
                        • start: 129
                        • end: 132
                        • loc: {...}
                          • start: {...}
                            • line: 9
                            • column: 10
                            }
                          • end: {...}
                            • line: 9
                            • column: 13
                            }
                          }
                        • name: "log"
                        }
                      • computed: false
                      • optional: false
                      }
                    • arguments: [...] (2)
                      • Literal {...}
                        • type: "Literal"
                        • start: 133
                        • end: 142
                        • loc: {...}
                          • start: {...}
                            • line: 9
                            • column: 14
                            }
                          • end: {...}
                            • line: 9
                            • column: 23
                            }
                          }
                        • value: "sending"
                        • raw: "\"sending\""
                        }
                      • Identifier {...}
                        • type: "Identifier"
                        • start: 144
                        • end: 147
                        • loc: {...}
                          • start: {...}
                            • line: 9
                            • column: 25
                            }
                          • end: {...}
                            • line: 9
                            • column: 28
                            }
                          }
                        • name: "sum"
                        }
                      ]
                    • optional: false
                    }
                  }
                ]
              }
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 154
            • end: 201
            • loc: {...}
              • start: {...}
                • line: 11
                • column: 1
                }
              • end: {...}
                • line: 14
                • column: 2
                }
              }
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 157
              • end: 201
              • loc: {...}
                • start: {...}
                  • line: 11
                  • column: 4
                  }
                • end: {...}
                  • line: 14
                  • column: 2
                  }
                }
              • body: [...] (2)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 161
                  • end: 174
                  • loc: {...}
                    • start: {...}
                      • line: 12
                      • column: 2
                      }
                    • end: {...}
                      • line: 12
                      • column: 15
                      }
                    }
                  • expression: CallExpression {...}
                    • type: "CallExpression"
                    • start: 161
                    • end: 173
                    • loc: {...}
                      • start: {...}
                        • line: 12
                        • column: 2
                        }
                      • end: {...}
                        • line: 12
                        • column: 14
                        }
                      }
                    • callee: Identifier {...}
                      • type: "Identifier"
                      • start: 161
                      • end: 168
                      • loc: {...}
                        • start: {...}
                          • line: 12
                          • column: 2
                          }
                        • end: {...}
                          • line: 12
                          • column: 9
                          }
                        }
                      • name: "calcSum"
                      }
                    • arguments: [...] (2)
                      • Identifier {...}
                        • type: "Identifier"
                        • start: 169
                        • end: 170
                        • loc: {...}
                          • start: {...}
                            • line: 12
                            • column: 10
                            }
                          • end: {...}
                            • line: 12
                            • column: 11
                            }
                          }
                        • name: "a"
                        }
                      • Identifier {...}
                        • type: "Identifier"
                        • start: 171
                        • end: 172
                        • loc: {...}
                          • start: {...}
                            • line: 12
                            • column: 12
                            }
                          • end: {...}
                            • line: 12
                            • column: 13
                            }
                          }
                        • name: "b"
                        }
                      ]
                    • optional: false
                    }
                  }
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 177
                  • end: 198
                  • loc: {...}
                    • start: {...}
                      • line: 13
                      • column: 2
                      }
                    • end: {...}
                      • line: 13
                      • column: 23
                      }
                    }
                  • expression: CallExpression {...}
                    • type: "CallExpression"
                    • start: 177
                    • end: 197
                    • loc: {...}
                      • start: {...}
                        • line: 13
                        • column: 2
                        }
                      • end: {...}
                        • line: 13
                        • column: 22
                        }
                      }
                    • callee: Identifier {...}
                      • type: "Identifier"
                      • start: 177
                      • end: 192
                      • loc: {...}
                        • start: {...}
                          • line: 13
                          • column: 2
                          }
                        • end: {...}
                          • line: 13
                          • column: 17
                          }
                        }
                      • name: "sendSumToServer"
                      }
                    • arguments: [...] (1)
                      • Identifier {...}
                        • type: "Identifier"
                        • start: 193
                        • end: 196
                        • loc: {...}
                          • start: {...}
                            • line: 13
                            • column: 18
                            }
                          • end: {...}
                            • line: 13
                            • column: 21
                            }
                          }
                        • name: "sum"
                        }
                      ]
                    • optional: false
                    }
                  }
                ]
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 154
              • end: 155
              • 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 function with explicit args • Playground • Svelte