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 inputValue = ''
</script>

<Child bind:value="{inputValue}" />

<p>Input value is: {inputValue}</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 inputValue = $.mutable_state('');
var fragment = root();
var node = $.first_child(fragment);

Child(node, {
get value() {
return $.get(inputValue);
},
set value($$value) {
$.set(inputValue, $$value);
},
$$legacy: true
});

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

$.reset(p);
$.template_effect(() => $.set_text(text, `Input value is: ${$.get(inputValue) ?? ''}`));
$.append($$anchor, fragment);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 79
    • end: 151
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (4)
        • Text {...}
          • type: "Text"
          • start: 77
          • end: 79
          • raw: "\n\n"
          • data: "\n\n"
          }
        • Component {...}
          • type: "Component"
          • start: 79
          • end: 114
          • name: "Child"
          • attributes: [...] (1)
            • BindDirective {...}
              • start: 86
              • end: 111
              • type: "BindDirective"
              • name: "value"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 99
                • end: 109
                • loc: {...}
                  • start: {...}
                    • line: 6
                    • column: 20
                    }
                  • end: {...}
                    • line: 6
                    • column: 30
                    }
                  }
                • name: "inputValue"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 114
          • end: 116
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 116
          • end: 151
          • name: "p"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (2)
              • Text {...}
                • type: "Text"
                • start: 119
                • end: 135
                • raw: "Input value is: "
                • data: "Input value is: "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 135
                • end: 147
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 136
                  • end: 146
                  • loc: {...}
                    • start: {...}
                      • line: 8
                      • column: 20
                      }
                    • end: {...}
                      • line: 8
                      • column: 30
                      }
                    }
                  • name: "inputValue"
                  }
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 77
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 68
        • 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: 67
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 2
                }
              • end: {...}
                • line: 3
                • column: 21
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 52
                • end: 67
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 6
                    }
                  • end: {...}
                    • line: 3
                    • column: 21
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 52
                  • end: 62
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 6
                      }
                    • end: {...}
                      • line: 3
                      • column: 16
                      }
                    }
                  • name: "inputValue"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 65
                  • end: 67
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 19
                      }
                    • end: {...}
                      • line: 3
                      • column: 21
                      }
                    }
                  • value: ""
                  • raw: "''"
                  }
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Using `bind:value` • Playground • Svelte