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 yes = $state(false);
</script>

<label>
<input type="checkbox" bind:checked={yes} />
Yes! Send me regular email spam
</label>

{#if yes}
<p>Thank you. We will bombard your inbox and sell your personal details.</p>
{:else}
<p>You must opt-in to continue. If you're not paying, you're the product.</p>
{/if}

<button disabled={!yes}> Subscribe </button>

Error compiling component

WebAssembly.instantiateStreaming(): value type opcode @+13
import 'svelte/internal/disclose-version';
import * as $ from 'svelte/internal/client';

var root_1 = $.template(`<p>Thank you. We will bombard your inbox and sell your personal details.</p>`);
var root_2 = $.template(`<p>You must opt-in to continue. If you're not paying, you're the product.</p>`);
var root = $.template(`<label><input type="checkbox"> Yes! Send me regular email spam</label> <!> <button>Subscribe</button>`, 1);

export default function App($$anchor) {
let yes = $.state(false);
var fragment = root();
var label = $.first_child(fragment);
var input = $.child(label);

$.remove_input_defaults(input);
$.next();
$.reset(label);

var node = $.sibling(label, 2);

{
var consequent = ($$anchor) => {
var p = root_1();

$.append($$anchor, p);
};

var alternate = ($$anchor) => {
var p_1 = root_2();

$.append($$anchor, p_1);
};

$.if(node, ($$render) => {
if ($.get(yes)) $$render(consequent); else $$render(alternate, false);
});
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 46
    • end: 369
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (6)
        • Text {...}
          • type: "Text"
          • start: 44
          • end: 46
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 46
          • end: 141
          • name: "label"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 53
                • end: 55
                • raw: "\n\t"
                • data: "\n\t"
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 55
                • end: 99
                • name: "input"
                • attributes: [...] (2)
                  • Attribute {...}
                    • type: "Attribute"
                    • start: 62
                    • end: 77
                    • name: "type"
                    • value: [...] (1)
                      • Text {...}
                        • start: 68
                        • end: 76
                        • type: "Text"
                        • raw: "checkbox"
                        • data: "checkbox"
                        }
                      ]
                    }
                  • BindDirective {...}
                    • start: 78
                    • end: 96
                    • type: "BindDirective"
                    • name: "checked"
                    • expression: Identifier {...}
                      • type: "Identifier"
                      • start: 92
                      • end: 95
                      • loc: {...}
                        • start: {...}
                          • line: 6
                          • column: 38
                          }
                        • end: {...}
                          • line: 6
                          • column: 41
                          }
                        }
                      • name: "yes"
                      }
                    • modifiers: []
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: []
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 99
                • end: 133
                • raw: " Yes! Send me regular email spam"
                • data: " Yes! Send me regular email spam"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 141
          • end: 143
          • raw: " "
          • data: " "
          }
        • IfBlock {...}
          • type: "IfBlock"
          • elseif: false
          • start: 143
          • end: 323
          • test: Identifier {...}
            • type: "Identifier"
            • start: 148
            • end: 151
            • loc: {...}
              • start: {...}
                • line: 10
                • column: 5
                }
              • end: {...}
                • line: 10
                • column: 8
                }
              }
            • name: "yes"
            }
          • consequent: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 152
                • end: 154
                • raw: "\n\t"
                • data: "\n\t"
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 154
                • end: 230
                • name: "p"
                • attributes: []
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (1)
                    • Text {...}
                      • type: "Text"
                      • start: 157
                      • end: 226
                      • raw: "Thank you. We will bombard your inbox and sell your personal details."
                      • data: "Thank you. We will bombard your inbox and sell your personal details."
                      }
                    ]
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 230
                • end: 231
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          • alternate: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 238
                • end: 240
                • raw: "\n\t"
                • data: "\n\t"
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 240
                • end: 317
                • name: "p"
                • attributes: []
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (1)
                    • Text {...}
                      • type: "Text"
                      • start: 243
                      • end: 313
                      • raw: "You must opt-in to continue. If you're not paying, you're the product."
                      • data: "You must opt-in to continue. If you're not paying, you're the product."
                      }
                    ]
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 317
                • end: 318
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 323
          • end: 325
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 325
          • end: 369
          • name: "button"
          • attributes: [...] (1)
            • Attribute {...}
              • type: "Attribute"
              • start: 333
              • end: 348
              • name: "disabled"
              • value: ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 342
                • end: 348
                • expression: UnaryExpression {...}
                  • type: "UnaryExpression"
                  • start: 343
                  • end: 347
                  • loc: {...}
                    • start: {...}
                      • line: 16
                      • column: 18
                      }
                    • end: {...}
                      • line: 16
                      • column: 22
                      }
                    }
                  • operator: "!"
                  • prefix: true
                  • argument: Identifier {...}
                    • type: "Identifier"
                    • start: 344
                    • end: 347
                    • loc: {...}
                      • start: {...}
                        • line: 16
                        • column: 19
                        }
                      • end: {...}
                        • line: 16
                        • column: 22
                        }
                      }
                    • name: "yes"
                    }
                  }
                }
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • Text {...}
                • type: "Text"
                • start: 349
                • end: 360
                • raw: "Subscribe"
                • data: "Subscribe"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 44
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 35
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 3
            • column: 0
            }
          }
        • body: [...] (1)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 34
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 25
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 33
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 24
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 17
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 8
                      }
                    }
                  • name: "yes"
                  }
                • init: CallExpression {...}
                  • type: "CallExpression"
                  • start: 20
                  • end: 33
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 11
                      }
                    • end: {...}
                      • line: 2
                      • column: 24
                      }
                    }
                  • callee: Identifier {...}
                    • type: "Identifier"
                    • start: 20
                    • end: 26
                    • loc: {...}
                      • start: {...}
                        • line: 2
                        • column: 11
                        }
                      • end: {...}
                        • line: 2
                        • column: 17
                        }
                      }
                    • name: "$state"
                    }
                  • arguments: [...] (1)
                    • Literal {...}
                      • type: "Literal"
                      • start: 27
                      • end: 32
                      • loc: {...}
                        • start: {...}
                          • line: 2
                          • column: 18
                          }
                        • end: {...}
                          • line: 2
                          • column: 23
                          }
                        }
                      • value: false
                      • raw: "false"
                      }
                    ]
                  • optional: false
                  }
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Checkbox inputs • Playground • Svelte