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 count = $state(0);

function handleClick() {
count += 1;
}
</script>

<button onclick={handleClick}>
Clicked {count}
{count === 1 ? 'time' : 'times'}
</button>

Error compiling component

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

function handleClick(_, count) {
$.set(count, $.get(count) + 1);
}

var root = $.template(`<button> </button>`);

export default function App($$anchor) {
let count = $.state(0);
var button = root();

button.__click = [handleClick, count];

var text = $.child(button);

$.reset(button);

$.template_effect(() => $.set_text(text, `Clicked ${$.get(count) ?? ''}
${($.get(count) === 1 ? 'time' : 'times') ?? ''}`));

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

$.delegate(['click']);
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 88
    • end: 179
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 86
          • end: 88
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 88
          • end: 179
          • name: "button"
          • attributes: [...] (1)
            • Attribute {...}
              • type: "Attribute"
              • start: 96
              • end: 117
              • name: "onclick"
              • value: ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 104
                • end: 117
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 105
                  • end: 116
                  • loc: {...}
                    • start: {...}
                      • line: 9
                      • column: 17
                      }
                    • end: {...}
                      • line: 9
                      • column: 28
                      }
                    }
                  • name: "handleClick"
                  }
                }
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (5)
              • Text {...}
                • type: "Text"
                • start: 118
                • end: 128
                • raw: "Clicked "
                • data: "Clicked "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 128
                • end: 135
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 129
                  • end: 134
                  • loc: {...}
                    • start: {...}
                      • line: 10
                      • column: 10
                      }
                    • end: {...}
                      • line: 10
                      • column: 15
                      }
                    }
                  • name: "count"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 135
                • end: 137
                • raw: "\n\t"
                • data: "\n\t"
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 137
                • end: 169
                • expression: ConditionalExpression {...}
                  • type: "ConditionalExpression"
                  • start: 138
                  • end: 168
                  • loc: {...}
                    • start: {...}
                      • line: 11
                      • column: 2
                      }
                    • end: {...}
                      • line: 11
                      • column: 32
                      }
                    }
                  • test: BinaryExpression {...}
                    • type: "BinaryExpression"
                    • start: 138
                    • end: 149
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 2
                        }
                      • end: {...}
                        • line: 11
                        • column: 13
                        }
                      }
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 138
                      • end: 143
                      • loc: {...}
                        • start: {...}
                          • line: 11
                          • column: 2
                          }
                        • end: {...}
                          • line: 11
                          • column: 7
                          }
                        }
                      • name: "count"
                      }
                    • operator: "==="
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 148
                      • end: 149
                      • loc: {...}
                        • start: {...}
                          • line: 11
                          • column: 12
                          }
                        • end: {...}
                          • line: 11
                          • column: 13
                          }
                        }
                      • value: 1
                      • raw: "1"
                      }
                    }
                  • consequent: Literal {...}
                    • type: "Literal"
                    • start: 152
                    • end: 158
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 16
                        }
                      • end: {...}
                        • line: 11
                        • column: 22
                        }
                      }
                    • value: "time"
                    • raw: "'time'"
                    }
                  • alternate: Literal {...}
                    • type: "Literal"
                    • start: 161
                    • end: 168
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 25
                        }
                      • end: {...}
                        • line: 11
                        • column: 32
                        }
                      }
                    • value: "times"
                    • raw: "'times'"
                    }
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 169
                • end: 170
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 86
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 77
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 7
            • column: 0
            }
          }
        • body: [...] (2)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 32
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 23
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 31
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 22
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 19
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 10
                      }
                    }
                  • name: "count"
                  }
                • init: CallExpression {...}
                  • type: "CallExpression"
                  • start: 22
                  • end: 31
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 13
                      }
                    • end: {...}
                      • line: 2
                      • column: 22
                      }
                    }
                  • callee: Identifier {...}
                    • type: "Identifier"
                    • start: 22
                    • end: 28
                    • loc: {...}
                      • start: {...}
                        • line: 2
                        • column: 13
                        }
                      • end: {...}
                        • line: 2
                        • column: 19
                        }
                      }
                    • name: "$state"
                    }
                  • arguments: [...] (1)
                    • Literal {...}
                      • type: "Literal"
                      • start: 29
                      • end: 30
                      • loc: {...}
                        • start: {...}
                          • line: 2
                          • column: 20
                          }
                        • end: {...}
                          • line: 2
                          • column: 21
                          }
                        }
                      • value: 0
                      • raw: "0"
                      }
                    ]
                  • optional: false
                  }
                }
              ]
            • kind: "let"
            }
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 35
            • end: 76
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 6
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 44
              • end: 55
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 10
                  }
                • end: {...}
                  • line: 4
                  • column: 21
                  }
                }
              • name: "handleClick"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 58
              • end: 76
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 24
                  }
                • end: {...}
                  • line: 6
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ExpressionStatement {...}
                  • type: "ExpressionStatement"
                  • start: 62
                  • end: 73
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 2
                      }
                    • end: {...}
                      • line: 5
                      • column: 13
                      }
                    }
                  • expression: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 62
                    • end: 72
                    • loc: {...}
                      • start: {...}
                        • line: 5
                        • column: 2
                        }
                      • end: {...}
                        • line: 5
                        • column: 12
                        }
                      }
                    • operator: "+="
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 62
                      • end: 67
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 2
                          }
                        • end: {...}
                          • line: 5
                          • column: 7
                          }
                        }
                      • name: "count"
                      }
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 71
                      • end: 72
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 11
                          }
                        • end: {...}
                          • line: 5
                          • column: 12
                          }
                        }
                      • value: 1
                      • raw: "1"
                      }
                    }
                  }
                ]
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Reactive assignments • Playground • Svelte