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

<label>
<input type="checkbox" bind:checked={big} />
big
</label>

<div class:big>
some {big ? 'big' : 'small'} text
</div>

<style>
.big {
font-size: 4em;
}
</style>

Error compiling component

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

var root = $.template(`<label><input type="checkbox"> big</label> <div class="svelte-crddqb"> </div>`, 1);

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

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

var div = $.sibling(label, 2);
var text = $.child(div);

$.reset(div);

$.template_effect(() => {
$.toggle_class(div, 'big', $.get(big));
$.set_text(text, `some ${($.get(big) ? 'big' : 'small') ?? ''} text`);
});

$.bind_checked(input, () => $.get(big), ($$value) => $.set(big, $$value));
$.append($$anchor, fragment);
}
result = svelte.compile(source, {
generate: ,
});

.big.svelte-crddqb {
font-size: 4em;
}

		
			
				
  • Root {
    • css: StyleSheet {...}
      • type: "StyleSheet"
      • start: 174
      • end: 219
      • attributes: []
      • children: [...] (1)
        • Rule {...}
          • type: "Rule"
          • prelude: SelectorList {...}
            • type: "SelectorList"
            • start: 183
            • end: 187
            • children: [...] (1)
              • ComplexSelector {...}
                • type: "ComplexSelector"
                • start: 183
                • end: 187
                • children: [...] (1)
                  • RelativeSelector {...}
                    • type: "RelativeSelector"
                    • combinator: null
                    • selectors: [...] (1)
                      • ClassSelector {...}
                        • type: "ClassSelector"
                        • name: "big"
                        • start: 183
                        • end: 187
                        }
                      ]
                    • start: 183
                    • end: 187
                    }
                  ]
                }
              ]
            }
          • block: Block {...}
            • type: "Block"
            • start: 188
            • end: 210
            • children: [...] (1)
              • Declaration {...}
                • type: "Declaration"
                • start: 192
                • end: 206
                • property: "font-size"
                • value: "4em"
                }
              ]
            }
          • start: 183
          • end: 210
          }
        ]
      • content: {...}
        • start: 181
        • end: 211
        • styles: "\n\t.big {\n\t\tfont-size: 4em;\n\t}\n"
        • comment: null
        }
      }
    • js: []
    • start: 46
    • end: 172
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (5)
        • Text {...}
          • type: "Text"
          • start: 44
          • end: 46
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 46
          • end: 113
          • 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: "big"
                      }
                    • modifiers: []
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: []
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 99
                • end: 105
                • raw: " big"
                • data: " big"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 113
          • end: 115
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 115
          • end: 172
          • name: "div"
          • attributes: [...] (2)
            • ClassDirective {...}
              • start: 120
              • end: 129
              • type: "ClassDirective"
              • name: "big"
              • expression: Identifier {...}
                • start: 126
                • end: 129
                • type: "Identifier"
                • name: "big"
                }
              • modifiers: []
              }
            • Attribute {...}
              • type: "Attribute"
              • start: -1
              • end: -1
              • name: "class"
              • value: [...] (1)
                • Text {...}
                  • type: "Text"
                  • data: "svelte-crddqb"
                  • raw: "svelte-crddqb"
                  • start: -1
                  • end: -1
                  }
                ]
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 130
                • end: 137
                • raw: "some "
                • data: "some "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 137
                • end: 160
                • expression: ConditionalExpression {...}
                  • type: "ConditionalExpression"
                  • start: 138
                  • end: 159
                  • loc: {...}
                    • start: {...}
                      • line: 11
                      • column: 7
                      }
                    • end: {...}
                      • line: 11
                      • column: 28
                      }
                    }
                  • test: Identifier {...}
                    • type: "Identifier"
                    • start: 138
                    • end: 141
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 7
                        }
                      • end: {...}
                        • line: 11
                        • column: 10
                        }
                      }
                    • name: "big"
                    }
                  • consequent: Literal {...}
                    • type: "Literal"
                    • start: 144
                    • end: 149
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 13
                        }
                      • end: {...}
                        • line: 11
                        • column: 18
                        }
                      }
                    • value: "big"
                    • raw: "'big'"
                    }
                  • alternate: Literal {...}
                    • type: "Literal"
                    • start: 152
                    • end: 159
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 21
                        }
                      • end: {...}
                        • line: 11
                        • column: 28
                        }
                      }
                    • value: "small"
                    • raw: "'small'"
                    }
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 160
                • end: 166
                • raw: " text"
                • data: " text"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 172
          • end: 174
          • raw: "\n\n"
          • data: "\n\n"
          }
        ]
      }
    • 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: "big"
                  }
                • 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
Shorthand class directive • Playground • Svelte