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 user = $state({ loggedIn: false });

function toggle() {
user.loggedIn = !user.loggedIn;
}
</script>

{#if user.loggedIn}
<button onclick={toggle}> Log out </button>
{/if}

{#if !user.loggedIn}
<button onclick={toggle}> Log in </button>
{/if}

Error compiling component

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

function toggle(_, user) {
user.loggedIn = !user.loggedIn;
}

var root_1 = $.template(`<button>Log out</button>`);
var root_2 = $.template(`<button>Log in</button>`);
var root = $.template(`<!> <!>`, 1);

export default function App($$anchor) {
let user = $.proxy({ loggedIn: false });
var fragment = root();
var node = $.first_child(fragment);

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

button.__click = [toggle, user];
$.append($$anchor, button);
};

$.if(node, ($$render) => {
if (user.loggedIn) $$render(consequent);
});
}

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

{
var consequent_1 = ($$anchor) => {
var button_1 = root_2();

button_1.__click = [toggle, user];
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 120
    • end: 262
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (4)
        • Text {...}
          • type: "Text"
          • start: 118
          • end: 120
          • raw: "\n\n"
          • data: "\n\n"
          }
        • IfBlock {...}
          • type: "IfBlock"
          • elseif: false
          • start: 120
          • end: 190
          • test: MemberExpression {...}
            • type: "MemberExpression"
            • start: 125
            • end: 138
            • loc: {...}
              • start: {...}
                • line: 9
                • column: 5
                }
              • end: {...}
                • line: 9
                • column: 18
                }
              }
            • object: Identifier {...}
              • type: "Identifier"
              • start: 125
              • end: 129
              • loc: {...}
                • start: {...}
                  • line: 9
                  • column: 5
                  }
                • end: {...}
                  • line: 9
                  • column: 9
                  }
                }
              • name: "user"
              }
            • property: Identifier {...}
              • type: "Identifier"
              • start: 130
              • end: 138
              • loc: {...}
                • start: {...}
                  • line: 9
                  • column: 10
                  }
                • end: {...}
                  • line: 9
                  • column: 18
                  }
                }
              • name: "loggedIn"
              }
            • computed: false
            • optional: false
            }
          • consequent: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 139
                • end: 141
                • raw: "\n\t"
                • data: "\n\t"
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 141
                • end: 184
                • name: "button"
                • attributes: [...] (1)
                  • Attribute {...}
                    • type: "Attribute"
                    • start: 149
                    • end: 165
                    • name: "onclick"
                    • value: ExpressionTag {...}
                      • type: "ExpressionTag"
                      • start: 157
                      • end: 165
                      • expression: Identifier {...}
                        • type: "Identifier"
                        • start: 158
                        • end: 164
                        • loc: {...}
                          • start: {...}
                            • line: 10
                            • column: 18
                            }
                          • end: {...}
                            • line: 10
                            • column: 24
                            }
                          }
                        • name: "toggle"
                        }
                      }
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (1)
                    • Text {...}
                      • type: "Text"
                      • start: 166
                      • end: 175
                      • raw: "Log out"
                      • data: "Log out"
                      }
                    ]
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 184
                • end: 185
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          • alternate: null
          }
        • Text {...}
          • type: "Text"
          • start: 190
          • end: 192
          • raw: " "
          • data: " "
          }
        • IfBlock {...}
          • type: "IfBlock"
          • elseif: false
          • start: 192
          • end: 262
          • test: UnaryExpression {...}
            • type: "UnaryExpression"
            • start: 197
            • end: 211
            • loc: {...}
              • start: {...}
                • line: 13
                • column: 5
                }
              • end: {...}
                • line: 13
                • column: 19
                }
              }
            • operator: "!"
            • prefix: true
            • argument: MemberExpression {...}
              • type: "MemberExpression"
              • start: 198
              • end: 211
              • loc: {...}
                • start: {...}
                  • line: 13
                  • column: 6
                  }
                • end: {...}
                  • line: 13
                  • column: 19
                  }
                }
              • object: Identifier {...}
                • type: "Identifier"
                • start: 198
                • end: 202
                • loc: {...}
                  • start: {...}
                    • line: 13
                    • column: 6
                    }
                  • end: {...}
                    • line: 13
                    • column: 10
                    }
                  }
                • name: "user"
                }
              • property: Identifier {...}
                • type: "Identifier"
                • start: 203
                • end: 211
                • loc: {...}
                  • start: {...}
                    • line: 13
                    • column: 11
                    }
                  • end: {...}
                    • line: 13
                    • column: 19
                    }
                  }
                • name: "loggedIn"
                }
              • computed: false
              • optional: false
              }
            }
          • consequent: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 212
                • end: 214
                • raw: "\n\t"
                • data: "\n\t"
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 214
                • end: 256
                • name: "button"
                • attributes: [...] (1)
                  • Attribute {...}
                    • type: "Attribute"
                    • start: 222
                    • end: 238
                    • name: "onclick"
                    • value: ExpressionTag {...}
                      • type: "ExpressionTag"
                      • start: 230
                      • end: 238
                      • expression: Identifier {...}
                        • type: "Identifier"
                        • start: 231
                        • end: 237
                        • loc: {...}
                          • start: {...}
                            • line: 14
                            • column: 18
                            }
                          • end: {...}
                            • line: 14
                            • column: 24
                            }
                          }
                        • name: "toggle"
                        }
                      }
                    }
                  ]
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (1)
                    • Text {...}
                      • type: "Text"
                      • start: 239
                      • end: 247
                      • raw: "Log in"
                      • data: "Log in"
                      }
                    ]
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 256
                • end: 257
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          • alternate: null
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 118
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 109
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 7
            • column: 0
            }
          }
        • body: [...] (2)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 49
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 40
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 48
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 39
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 18
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 9
                      }
                    }
                  • name: "user"
                  }
                • init: CallExpression {...}
                  • type: "CallExpression"
                  • start: 21
                  • end: 48
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 12
                      }
                    • end: {...}
                      • line: 2
                      • column: 39
                      }
                    }
                  • callee: Identifier {...}
                    • type: "Identifier"
                    • start: 21
                    • end: 27
                    • loc: {...}
                      • start: {...}
                        • line: 2
                        • column: 12
                        }
                      • end: {...}
                        • line: 2
                        • column: 18
                        }
                      }
                    • name: "$state"
                    }
                  • arguments: [...] (1)
                    • ObjectExpression {...}
                      • type: "ObjectExpression"
                      • start: 28
                      • end: 47
                      • loc: {...}
                        • start: {...}
                          • line: 2
                          • column: 19
                          }
                        • end: {...}
                          • line: 2
                          • column: 38
                          }
                        }
                      • properties: [...] (1)
                        • Property {...}
                          • type: "Property"
                          • start: 30
                          • end: 45
                          • loc: {...}
                            • start: {...}
                              • line: 2
                              • column: 21
                              }
                            • end: {...}
                              • line: 2
                              • column: 36
                              }
                            }
                          • method: false
                          • shorthand: false
                          • computed: false
                          • key: Identifier {...}
                            • type: "Identifier"
                            • start: 30
                            • end: 38
                            • loc: {...}
                              • start: {...}
                                • line: 2
                                • column: 21
                                }
                              • end: {...}
                                • line: 2
                                • column: 29
                                }
                              }
                            • name: "loggedIn"
                            }
                          • value: Literal {...}
                            • type: "Literal"
                            • start: 40
                            • end: 45
                            • loc: {...}
                              • start: {...}
                                • line: 2
                                • column: 31
                                }
                              • end: {...}
                                • line: 2
                                • column: 36
                                }
                              }
                            • value: false
                            • raw: "false"
                            }
                          • kind: "init"
                          }
                        ]
                      }
                    ]
                  • optional: false
                  }
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 52
            • end: 108
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 6
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 61
              • end: 67
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 10
                  }
                • end: {...}
                  • line: 4
                  • column: 16
                  }
                }
              • name: "toggle"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 70
              • end: 108
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 19
                  }
                • end: {...}
                  • line: 6
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 74
                  • end: 105
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 2
                      }
                    • end: {...}
                      • line: 5
                      • column: 33
                      }
                    }
                  • expression: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 74
                    • end: 104
                    • loc: {...}
                      • start: {...}
                        • line: 5
                        • column: 2
                        }
                      • end: {...}
                        • line: 5
                        • column: 32
                        }
                      }
                    • operator: "="
                    • left: MemberExpression {...}
                      • type: "MemberExpression"
                      • start: 74
                      • end: 87
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 2
                          }
                        • end: {...}
                          • line: 5
                          • column: 15
                          }
                        }
                      • object: Identifier {...}
                        • type: "Identifier"
                        • start: 74
                        • end: 78
                        • loc: {...}
                          • start: {...}
                            • line: 5
                            • column: 2
                            }
                          • end: {...}
                            • line: 5
                            • column: 6
                            }
                          }
                        • name: "user"
                        }
                      • property: Identifier {...}
                        • type: "Identifier"
                        • start: 79
                        • end: 87
                        • loc: {...}
                          • start: {...}
                            • line: 5
                            • column: 7
                            }
                          • end: {...}
                            • line: 5
                            • column: 15
                            }
                          }
                        • name: "loggedIn"
                        }
                      • computed: false
                      • optional: false
                      }
                    • right: UnaryExpression {...}
                      • type: "UnaryExpression"
                      • start: 90
                      • end: 104
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 18
                          }
                        • end: {...}
                          • line: 5
                          • column: 32
                          }
                        }
                      • operator: "!"
                      • prefix: true
                      • argument: MemberExpression {...}
                        • type: "MemberExpression"
                        • start: 91
                        • end: 104
                        • loc: {...}
                          • start: {...}
                            • line: 5
                            • column: 19
                            }
                          • end: {...}
                            • line: 5
                            • column: 32
                            }
                          }
                        • object: Identifier {...}
                          • type: "Identifier"
                          • start: 91
                          • end: 95
                          • loc: {...}
                            • start: {...}
                              • line: 5
                              • column: 19
                              }
                            • end: {...}
                              • line: 5
                              • column: 23
                              }
                            }
                          • name: "user"
                          }
                        • property: Identifier {...}
                          • type: "Identifier"
                          • start: 96
                          • end: 104
                          • loc: {...}
                            • start: {...}
                              • line: 5
                              • column: 24
                              }
                            • end: {...}
                              • line: 5
                              • column: 32
                              }
                            }
                          • name: "loggedIn"
                          }
                        • computed: false
                        • optional: false
                        }
                      }
                    }
                  }
                ]
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
If blocks • Playground • Svelte