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';
console.log('name', name);
}
$: name = givenName + " " + familyName;
</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');
console.log('name', $.get(name));
}

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

$.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: 205
    • end: 248
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 204
          • end: 205
          • raw: "\n"
          • data: "\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 205
          • end: 248
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 213
              • end: 230
              • type: "OnDirective"
              • name: "click"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 223
                • end: 229
                • loc: {...}
                  • start: {...}
                    • line: 10
                    • column: 18
                    }
                  • end: {...}
                    • line: 10
                    • column: 24
                    }
                  }
                • name: "update"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • Text {...}
                • type: "Text"
                • start: 231
                • end: 239
                • raw: "Click Me"
                • data: "Click Me"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 204
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 195
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 9
            • column: 0
            }
          }
        • body: [...] (3)
          • 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: 152
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 2
                }
              • end: {...}
                • line: 7
                • 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: 152
              • loc: {...}
                • start: {...}
                  • line: 3
                  • column: 20
                  }
                • end: {...}
                  • line: 7
                  • column: 3
                  }
                }
              • body: [...] (3)
                • 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'"
                      }
                    }
                  }
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 122
                  • end: 148
                  • loc: {...}
                    • start: {...}
                      • line: 6
                      • column: 2
                      }
                    • end: {...}
                      • line: 6
                      • column: 28
                      }
                    }
                  • expression: CallExpression {...}
                    • type: "CallExpression"
                    • start: 122
                    • end: 147
                    • loc: {...}
                      • start: {...}
                        • line: 6
                        • column: 2
                        }
                      • end: {...}
                        • line: 6
                        • column: 27
                        }
                      }
                    • callee: MemberExpression {...}
                      • type: "MemberExpression"
                      • start: 122
                      • end: 133
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 2
                          }
                        • end: {...}
                          • line: 6
                          • column: 13
                          }
                        }
                      • object: Identifier {...}
                        • type: "Identifier"
                        • start: 122
                        • end: 129
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 2
                            }
                          • end: {...}
                            • line: 6
                            • column: 9
                            }
                          }
                        • name: "console"
                        }
                      • property: Identifier {...}
                        • type: "Identifier"
                        • start: 130
                        • end: 133
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 10
                            }
                          • end: {...}
                            • line: 6
                            • column: 13
                            }
                          }
                        • name: "log"
                        }
                      • computed: false
                      • optional: false
                      }
                    • arguments: [...] (2)
                      • Literal {...}
                        • type: "Literal"
                        • start: 134
                        • end: 140
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 14
                            }
                          • end: {...}
                            • line: 6
                            • column: 20
                            }
                          }
                        • value: "name"
                        • raw: "'name'"
                        }
                      • Identifier {...}
                        • type: "Identifier"
                        • start: 142
                        • end: 146
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 22
                            }
                          • end: {...}
                            • line: 6
                            • column: 26
                            }
                          }
                        • name: "name"
                        }
                      ]
                    • optional: false
                    }
                  }
                ]
              }
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 155
            • end: 194
            • loc: {...}
              • start: {...}
                • line: 8
                • column: 2
                }
              • end: {...}
                • line: 8
                • column: 41
                }
              }
            • body: ExpressionStatement {...}
              • type: "ExpressionStatement"
              • start: 158
              • end: 194
              • loc: {...}
                • start: {...}
                  • line: 8
                  • column: 5
                  }
                • end: {...}
                  • line: 8
                  • column: 41
                  }
                }
              • expression: AssignmentExpression {...}
                • type: "AssignmentExpression"
                • start: 158
                • end: 193
                • loc: {...}
                  • start: {...}
                    • line: 8
                    • column: 5
                    }
                  • end: {...}
                    • line: 8
                    • column: 40
                    }
                  }
                • operator: "="
                • left: Identifier {...}
                  • type: "Identifier"
                  • start: 158
                  • end: 162
                  • loc: {...}
                    • start: {...}
                      • line: 8
                      • column: 5
                      }
                    • end: {...}
                      • line: 8
                      • column: 9
                      }
                    }
                  • name: "name"
                  }
                • right: BinaryExpression {...}
                  • type: "BinaryExpression"
                  • start: 165
                  • end: 193
                  • loc: {...}
                    • start: {...}
                      • line: 8
                      • column: 12
                      }
                    • end: {...}
                      • line: 8
                      • column: 40
                      }
                    }
                  • left: BinaryExpression {...}
                    • type: "BinaryExpression"
                    • start: 165
                    • end: 180
                    • loc: {...}
                      • start: {...}
                        • line: 8
                        • column: 12
                        }
                      • end: {...}
                        • line: 8
                        • column: 27
                        }
                      }
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 165
                      • end: 174
                      • loc: {...}
                        • start: {...}
                          • line: 8
                          • column: 12
                          }
                        • end: {...}
                          • line: 8
                          • column: 21
                          }
                        }
                      • name: "givenName"
                      }
                    • operator: "+"
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 177
                      • end: 180
                      • loc: {...}
                        • start: {...}
                          • line: 8
                          • column: 24
                          }
                        • end: {...}
                          • line: 8
                          • column: 27
                          }
                        }
                      • value: " "
                      • raw: "\" \""
                      }
                    }
                  • operator: "+"
                  • right: Identifier {...}
                    • type: "Identifier"
                    • start: 183
                    • end: 193
                    • loc: {...}
                      • start: {...}
                        • line: 8
                        • column: 30
                        }
                      • end: {...}
                        • line: 8
                        • column: 40
                        }
                      }
                    • name: "familyName"
                    }
                  }
                }
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 155
              • end: 156
              • 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 value • Playground • Svelte