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
Dialog.svelte
<script>
import Dialog from './Dialog.svelte'
let dialog
</script>

<button on:click={() => dialog.showModal()}>Open It!</button>

<Dialog bind:dialog on:close={() => console.log('closed')}>
This is amazingly simple! (press esc to close)
</Dialog>


bundling https://unpkg.com/clsx@2.1.1/dist/clsx.mjs
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';
import Dialog from './Dialog.svelte';

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

export default function App($$anchor) {
let dialog = $.mutable_state();
var fragment = root();
var button = $.first_child(fragment);
var node = $.sibling(button, 2);

Dialog(node, {
get dialog() {
return $.get(dialog);
},
set dialog($$value) {
$.set(dialog, $$value);
},
$$events: { close: () => console.log('closed') },
children: ($$anchor, $$slotProps) => {
$.next();

var text = $.text('This is amazingly simple! (press esc to close)');

$.append($$anchor, text);
},
$$slots: { default: true },
$$legacy: true
});

$.event('click', button, () => $.get(dialog).showModal());
$.append($$anchor, fragment);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 70
    • end: 250
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (4)
        • Text {...}
          • type: "Text"
          • start: 68
          • end: 70
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 70
          • end: 131
          • name: "button"
          • attributes: [...] (1)
            • OnDirective {...}
              • start: 78
              • end: 113
              • type: "OnDirective"
              • name: "click"
              • expression: ArrowFunctionExpression {...}
                • type: "ArrowFunctionExpression"
                • start: 88
                • end: 112
                • loc: {...}
                  • start: {...}
                    • line: 6
                    • column: 18
                    }
                  • end: {...}
                    • line: 6
                    • column: 42
                    }
                  }
                • id: null
                • expression: true
                • generator: false
                • async: false
                • params: []
                • body: CallExpression {...}
                  • type: "CallExpression"
                  • start: 94
                  • end: 112
                  • loc: {...}
                    • start: {...}
                      • line: 6
                      • column: 24
                      }
                    • end: {...}
                      • line: 6
                      • column: 42
                      }
                    }
                  • callee: MemberExpression {...}
                    • type: "MemberExpression"
                    • start: 94
                    • end: 110
                    • loc: {...}
                      • start: {...}
                        • line: 6
                        • column: 24
                        }
                      • end: {...}
                        • line: 6
                        • column: 40
                        }
                      }
                    • object: Identifier {...}
                      • type: "Identifier"
                      • start: 94
                      • end: 100
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 24
                          }
                        • end: {...}
                          • line: 6
                          • column: 30
                          }
                        }
                      • name: "dialog"
                      }
                    • property: Identifier {...}
                      • type: "Identifier"
                      • start: 101
                      • end: 110
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 31
                          }
                        • end: {...}
                          • line: 6
                          • column: 40
                          }
                        }
                      • name: "showModal"
                      }
                    • computed: false
                    • optional: false
                    }
                  • arguments: []
                  • optional: false
                  }
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • Text {...}
                • type: "Text"
                • start: 114
                • end: 122
                • raw: "Open It!"
                • data: "Open It!"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 131
          • end: 133
          • raw: " "
          • data: " "
          }
        • Component {...}
          • type: "Component"
          • start: 133
          • end: 250
          • name: "Dialog"
          • attributes: [...] (2)
            • BindDirective {...}
              • start: 141
              • end: 152
              • type: "BindDirective"
              • name: "dialog"
              • expression: Identifier {...}
                • start: 146
                • end: 152
                • type: "Identifier"
                • name: "dialog"
                }
              • modifiers: []
              }
            • OnDirective {...}
              • start: 153
              • end: 191
              • type: "OnDirective"
              • name: "close"
              • expression: ArrowFunctionExpression {...}
                • type: "ArrowFunctionExpression"
                • start: 163
                • end: 190
                • loc: {...}
                  • start: {...}
                    • line: 8
                    • column: 30
                    }
                  • end: {...}
                    • line: 8
                    • column: 57
                    }
                  }
                • id: null
                • expression: true
                • generator: false
                • async: false
                • params: []
                • body: CallExpression {...}
                  • type: "CallExpression"
                  • start: 169
                  • end: 190
                  • loc: {...}
                    • start: {...}
                      • line: 8
                      • column: 36
                      }
                    • end: {...}
                      • line: 8
                      • column: 57
                      }
                    }
                  • callee: MemberExpression {...}
                    • type: "MemberExpression"
                    • start: 169
                    • end: 180
                    • loc: {...}
                      • start: {...}
                        • line: 8
                        • column: 36
                        }
                      • end: {...}
                        • line: 8
                        • column: 47
                        }
                      }
                    • object: Identifier {...}
                      • type: "Identifier"
                      • start: 169
                      • end: 176
                      • loc: {...}
                        • start: {...}
                          • line: 8
                          • column: 36
                          }
                        • end: {...}
                          • line: 8
                          • column: 43
                          }
                        }
                      • name: "console"
                      }
                    • property: Identifier {...}
                      • type: "Identifier"
                      • start: 177
                      • end: 180
                      • loc: {...}
                        • start: {...}
                          • line: 8
                          • column: 44
                          }
                        • end: {...}
                          • line: 8
                          • column: 47
                          }
                        }
                      • name: "log"
                      }
                    • computed: false
                    • optional: false
                    }
                  • arguments: [...] (1)
                    • Literal {...}
                      • type: "Literal"
                      • start: 181
                      • end: 189
                      • loc: {...}
                        • start: {...}
                          • line: 8
                          • column: 48
                          }
                        • end: {...}
                          • line: 8
                          • column: 56
                          }
                        }
                      • value: "closed"
                      • raw: "'closed'"
                      }
                    ]
                  • optional: false
                  }
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • Text {...}
                • type: "Text"
                • start: 192
                • end: 241
                • raw: "This is amazingly simple! (press esc to close)"
                • data: "This is amazingly simple! (press esc to close)"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 68
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 59
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 4
            • column: 0
            }
          }
        • body: [...] (2)
          • ImportDeclaration {...}
            • type: "ImportDeclaration"
            • start: 10
            • end: 46
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 37
                }
              }
            • specifiers: [...] (1)
              • ImportDefaultSpecifier {...}
                • type: "ImportDefaultSpecifier"
                • start: 17
                • end: 23
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 8
                    }
                  • end: {...}
                    • line: 2
                    • column: 14
                    }
                  }
                • local: Identifier {...}
                  • type: "Identifier"
                  • start: 17
                  • end: 23
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 8
                      }
                    • end: {...}
                      • line: 2
                      • column: 14
                      }
                    }
                  • name: "Dialog"
                  }
                }
              ]
            • source: Literal {...}
              • type: "Literal"
              • start: 29
              • end: 46
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 20
                  }
                • end: {...}
                  • line: 2
                  • column: 37
                  }
                }
              • value: "./Dialog.svelte"
              • raw: "'./Dialog.svelte'"
              }
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 48
            • end: 58
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 3
                • column: 11
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 52
                • end: 58
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 5
                    }
                  • end: {...}
                    • line: 3
                    • column: 11
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 52
                  • end: 58
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 5
                      }
                    • end: {...}
                      • line: 3
                      • column: 11
                      }
                    }
                  • name: "dialog"
                  }
                • init: null
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
HTML5 Dialog Component • Playground • Svelte