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 givenName = '', familyName = '';
function update() {
givenName = 'Li Hau';
familyName = 'Tan';
}
$: name = givenName + " " + familyName;
$: console.log('name', name);
</script>
<button on:click={update}>Click Me</button>
resolving https://unpkg.com/svelte@5.20.5/src/internal/client/dev/console-log.js
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

var root = $.template(`<button>Click Me</button>`);

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

const name = $.mutable_state();

let givenName = $.mutable_state(''),
familyName = $.mutable_state('');

function update() {
$.set(givenName, 'Li Hau');
$.set(familyName, 'Tan');
}

$.legacy_pre_effect(() => ($.get(givenName), $.get(familyName)), () => {
$.set(name, $.get(givenName) + " " + $.get(familyName));
});

$.legacy_pre_effect(() => ($.get(name)), () => {
console.log('name', $.get(name));
});

$.legacy_pre_effect_reset();

var button = root();

$.event('click', button, update);
$.append($$anchor, button);
$.pop();
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 208
    • end: 251
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 207
          • end: 208
          • raw: "\n"
          • data: "\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 208
          • end: 251
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 216
              • end: 233
              • type: "OnDirective"
              • name: "click"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 226
                • end: 232
                • loc: {...}
                  • start: {...}
                    • line: 10
                    • column: 18
                    }
                  • end: {...}
                    • line: 10
                    • column: 24
                    }
                  }
                • name: "update"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • Text {...}
                • type: "Text"
                • start: 234
                • end: 242
                • raw: "Click Me"
                • data: "Click Me"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 207
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 198
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 9
            • column: 0
            }
          }
        • body: [...] (4)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 11
            • end: 47
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 2
                }
              • end: {...}
                • line: 2
                • column: 38
                }
              }
            • declarations: [...] (2)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 15
                • end: 29
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 6
                    }
                  • end: {...}
                    • line: 2
                    • column: 20
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 15
                  • end: 24
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 6
                      }
                    • end: {...}
                      • line: 2
                      • column: 15
                      }
                    }
                  • name: "givenName"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 27
                  • end: 29
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 18
                      }
                    • end: {...}
                      • line: 2
                      • column: 20
                      }
                    }
                  • value: ""
                  • raw: "''"
                  }
                }
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 31
                • end: 46
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 22
                    }
                  • end: {...}
                    • line: 2
                    • column: 37
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 31
                  • end: 41
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 22
                      }
                    • end: {...}
                      • line: 2
                      • column: 32
                      }
                    }
                  • name: "familyName"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 44
                  • end: 46
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 35
                      }
                    • end: {...}
                      • line: 2
                      • column: 37
                      }
                    }
                  • value: ""
                  • raw: "''"
                  }
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 50
            • end: 123
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 2
                }
              • end: {...}
                • line: 6
                • column: 3
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 59
              • end: 65
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 11
                  }
                • end: {...}
                  • line: 3
                  • column: 17
                  }
                }
              • name: "update"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 68
              • end: 123
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 20
                  }
                • end: {...}
                  • line: 6
                  • column: 3
                  }
                }
              • body: [...] (2)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 74
                  • end: 95
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 4
                      }
                    • end: {...}
                      • line: 4
                      • column: 25
                      }
                    }
                  • expression: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 74
                    • end: 94
                    • loc: {...}
                      • start: {...}
                        • line: 4
                        • column: 4
                        }
                      • end: {...}
                        • line: 4
                        • column: 24
                        }
                      }
                    • operator: "="
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 74
                      • end: 83
                      • loc: {...}
                        • start: {...}
                          • line: 4
                          • column: 4
                          }
                        • end: {...}
                          • line: 4
                          • column: 13
                          }
                        }
                      • name: "givenName"
                      }
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 86
                      • end: 94
                      • loc: {...}
                        • start: {...}
                          • line: 4
                          • column: 16
                          }
                        • end: {...}
                          • line: 4
                          • column: 24
                          }
                        }
                      • value: "Li Hau"
                      • raw: "'Li Hau'"
                      }
                    }
                  }
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 100
                  • end: 119
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 4
                      }
                    • end: {...}
                      • line: 5
                      • column: 23
                      }
                    }
                  • expression: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 100
                    • end: 118
                    • loc: {...}
                      • start: {...}
                        • line: 5
                        • column: 4
                        }
                      • end: {...}
                        • line: 5
                        • column: 22
                        }
                      }
                    • operator: "="
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 100
                      • end: 110
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 4
                          }
                        • end: {...}
                          • line: 5
                          • column: 14
                          }
                        }
                      • name: "familyName"
                      }
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 113
                      • end: 118
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 17
                          }
                        • end: {...}
                          • line: 5
                          • column: 22
                          }
                        }
                      • value: "Tan"
                      • raw: "'Tan'"
                      }
                    }
                  }
                ]
              }
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 126
            • end: 165
            • loc: {...}
              • start: {...}
                • line: 7
                • column: 2
                }
              • end: {...}
                • line: 7
                • column: 41
                }
              }
            • body: ExpressionStatement {...}
              • type: "ExpressionStatement"
              • start: 129
              • end: 165
              • loc: {...}
                • start: {...}
                  • line: 7
                  • column: 5
                  }
                • end: {...}
                  • line: 7
                  • column: 41
                  }
                }
              • expression: AssignmentExpression {...}
                • type: "AssignmentExpression"
                • start: 129
                • end: 164
                • loc: {...}
                  • start: {...}
                    • line: 7
                    • column: 5
                    }
                  • end: {...}
                    • line: 7
                    • column: 40
                    }
                  }
                • operator: "="
                • left: Identifier {...}
                  • type: "Identifier"
                  • start: 129
                  • end: 133
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 5
                      }
                    • end: {...}
                      • line: 7
                      • column: 9
                      }
                    }
                  • name: "name"
                  }
                • right: BinaryExpression {...}
                  • type: "BinaryExpression"
                  • start: 136
                  • end: 164
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 12
                      }
                    • end: {...}
                      • line: 7
                      • column: 40
                      }
                    }
                  • left: BinaryExpression {...}
                    • type: "BinaryExpression"
                    • start: 136
                    • end: 151
                    • loc: {...}
                      • start: {...}
                        • line: 7
                        • column: 12
                        }
                      • end: {...}
                        • line: 7
                        • column: 27
                        }
                      }
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 136
                      • end: 145
                      • loc: {...}
                        • start: {...}
                          • line: 7
                          • column: 12
                          }
                        • end: {...}
                          • line: 7
                          • column: 21
                          }
                        }
                      • name: "givenName"
                      }
                    • operator: "+"
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 148
                      • end: 151
                      • loc: {...}
                        • start: {...}
                          • line: 7
                          • column: 24
                          }
                        • end: {...}
                          • line: 7
                          • column: 27
                          }
                        }
                      • value: " "
                      • raw: "\" \""
                      }
                    }
                  • operator: "+"
                  • right: Identifier {...}
                    • type: "Identifier"
                    • start: 154
                    • end: 164
                    • loc: {...}
                      • start: {...}
                        • line: 7
                        • column: 30
                        }
                      • end: {...}
                        • line: 7
                        • column: 40
                        }
                      }
                    • name: "familyName"
                    }
                  }
                }
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 126
              • end: 127
              • loc: {...}
                • start: {...}
                  • line: 7
                  • column: 2
                  }
                • end: {...}
                  • line: 7
                  • column: 3
                  }
                }
              • name: "$"
              }
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 168
            • end: 197
            • loc: {...}
              • start: {...}
                • line: 8
                • column: 2
                }
              • end: {...}
                • line: 8
                • column: 31
                }
              }
            • body: ExpressionStatement {...}
              • type: "ExpressionStatement"
              • start: 171
              • end: 197
              • loc: {...}
                • start: {...}
                  • line: 8
                  • column: 5
                  }
                • end: {...}
                  • line: 8
                  • column: 31
                  }
                }
              • expression: CallExpression {...}
                • type: "CallExpression"
                • start: 171
                • end: 196
                • loc: {...}
                  • start: {...}
                    • line: 8
                    • column: 5
                    }
                  • end: {...}
                    • line: 8
                    • column: 30
                    }
                  }
                • callee: MemberExpression {...}
                  • type: "MemberExpression"
                  • start: 171
                  • end: 182
                  • loc: {...}
                    • start: {...}
                      • line: 8
                      • column: 5
                      }
                    • end: {...}
                      • line: 8
                      • column: 16
                      }
                    }
                  • object: Identifier {...}
                    • type: "Identifier"
                    • start: 171
                    • end: 178
                    • loc: {...}
                      • start: {...}
                        • line: 8
                        • column: 5
                        }
                      • end: {...}
                        • line: 8
                        • column: 12
                        }
                      }
                    • name: "console"
                    }
                  • property: Identifier {...}
                    • type: "Identifier"
                    • start: 179
                    • end: 182
                    • loc: {...}
                      • start: {...}
                        • line: 8
                        • column: 13
                        }
                      • end: {...}
                        • line: 8
                        • column: 16
                        }
                      }
                    • name: "log"
                    }
                  • computed: false
                  • optional: false
                  }
                • arguments: [...] (2)
                  • Literal {...}
                    • type: "Literal"
                    • start: 183
                    • end: 189
                    • loc: {...}
                      • start: {...}
                        • line: 8
                        • column: 17
                        }
                      • end: {...}
                        • line: 8
                        • column: 23
                        }
                      }
                    • value: "name"
                    • raw: "'name'"
                    }
                  • Identifier {...}
                    • type: "Identifier"
                    • start: 191
                    • end: 195
                    • loc: {...}
                      • start: {...}
                        • line: 8
                        • column: 25
                        }
                      • end: {...}
                        • line: 8
                        • column: 29
                        }
                      }
                    • name: "name"
                    }
                  ]
                • optional: false
                }
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 168
              • end: 169
              • loc: {...}
                • start: {...}
                  • line: 8
                  • column: 2
                  }
                • end: {...}
                  • line: 8
                  • column: 3
                  }
                }
              • name: "$"
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Compile Svelte in your Head - Reactive Declarations Batched • Playground • Svelte