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
Child.svelte
<script>
import Child from './Child.svelte'
let inputBoxValue = ''
</script>

<Child onChange={newValue => inputBoxValue = newValue} />

<p>Input box value is: {inputBoxValue}</p>
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';
import Child from './Child.svelte';

var root = $.template(`<!> <p> </p>`, 1);

export default function App($$anchor) {
let inputBoxValue = $.mutable_state('');
var fragment = root();
var node = $.first_child(fragment);

Child(node, {
onChange: (newValue) => $.set(inputBoxValue, newValue)
});

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

$.reset(p);
$.template_effect(() => $.set_text(text, `Input box value is: ${$.get(inputBoxValue) ?? ''}`));
$.append($$anchor, fragment);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 82
    • end: 183
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (4)
        • Text {...}
          • type: "Text"
          • start: 80
          • end: 82
          • raw: "\n\n"
          • data: "\n\n"
          }
        • Component {...}
          • type: "Component"
          • start: 82
          • end: 139
          • name: "Child"
          • attributes: [...] (1)
            • Attribute {...}
              • type: "Attribute"
              • start: 89
              • end: 136
              • name: "onChange"
              • value: ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 98
                • end: 136
                • expression: ArrowFunctionExpression {...}
                  • type: "ArrowFunctionExpression"
                  • start: 99
                  • end: 135
                  • loc: {...}
                    • start: {...}
                      • line: 6
                      • column: 17
                      }
                    • end: {...}
                      • line: 6
                      • column: 53
                      }
                    }
                  • id: null
                  • expression: true
                  • generator: false
                  • async: false
                  • params: [...] (1)
                    • Identifier {...}
                      • type: "Identifier"
                      • start: 99
                      • end: 107
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 17
                          }
                        • end: {...}
                          • line: 6
                          • column: 25
                          }
                        }
                      • name: "newValue"
                      }
                    ]
                  • body: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 111
                    • end: 135
                    • loc: {...}
                      • start: {...}
                        • line: 6
                        • column: 29
                        }
                      • end: {...}
                        • line: 6
                        • column: 53
                        }
                      }
                    • operator: "="
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 111
                      • end: 124
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 29
                          }
                        • end: {...}
                          • line: 6
                          • column: 42
                          }
                        }
                      • name: "inputBoxValue"
                      }
                    • right: Identifier {...}
                      • type: "Identifier"
                      • start: 127
                      • end: 135
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 45
                          }
                        • end: {...}
                          • line: 6
                          • column: 53
                          }
                        }
                      • name: "newValue"
                      }
                    }
                  }
                }
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 139
          • end: 141
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 141
          • end: 183
          • name: "p"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (2)
              • Text {...}
                • type: "Text"
                • start: 144
                • end: 164
                • raw: "Input box value is: "
                • data: "Input box value is: "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 164
                • end: 179
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 165
                  • end: 178
                  • loc: {...}
                    • start: {...}
                      • line: 8
                      • column: 24
                      }
                    • end: {...}
                      • line: 8
                      • column: 37
                      }
                    }
                  • name: "inputBoxValue"
                  }
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 80
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 71
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 4
            • column: 0
            }
          }
        • body: [...] (2)
          • ImportDeclaration {...}
            • type: "ImportDeclaration"
            • start: 11
            • end: 45
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 2
                }
              • end: {...}
                • line: 2
                • column: 36
                }
              }
            • specifiers: [...] (1)
              • ImportDefaultSpecifier {...}
                • type: "ImportDefaultSpecifier"
                • start: 18
                • end: 23
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 9
                    }
                  • end: {...}
                    • line: 2
                    • column: 14
                    }
                  }
                • local: Identifier {...}
                  • type: "Identifier"
                  • start: 18
                  • end: 23
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 9
                      }
                    • end: {...}
                      • line: 2
                      • column: 14
                      }
                    }
                  • name: "Child"
                  }
                }
              ]
            • source: Literal {...}
              • type: "Literal"
              • start: 29
              • end: 45
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 20
                  }
                • end: {...}
                  • line: 2
                  • column: 36
                  }
                }
              • value: "./Child.svelte"
              • raw: "'./Child.svelte'"
              }
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 48
            • end: 70
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 2
                }
              • end: {...}
                • line: 3
                • column: 24
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 52
                • end: 70
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 6
                    }
                  • end: {...}
                    • line: 3
                    • column: 24
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 52
                  • end: 65
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 6
                      }
                    • end: {...}
                      • line: 3
                      • column: 19
                      }
                    }
                  • name: "inputBoxValue"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 68
                  • end: 70
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 22
                      }
                    • end: {...}
                      • line: 3
                      • column: 24
                      }
                    }
                  • value: ""
                  • raw: "''"
                  }
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Using a callback • Playground • Svelte