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>
const options = ['h1', 'h3', 'p'];
let selected = $state(options[0]);
</script>

<select bind:value={selected}>
{#each options as option}
<option value={option}>{option}</option>
{/each}
</select>

<svelte:element this={selected}>I'm a {selected} tag</svelte:element>

Error compiling component

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

var root_1 = $.template(`<option> </option>`);
var root = $.template(`<select></select> <!>`, 1);

export default function App($$anchor) {
const options = ['h1', 'h3', 'p'];
let selected = $.state($.proxy(options[0]));
var fragment = root();
var select = $.first_child(fragment);

$.each(select, 21, () => options, $.index, ($$anchor, option) => {
var option_1 = root_1();
var option_1_value = {};
var text = $.child(option_1, true);

$.reset(option_1);

$.template_effect(() => {
if (option_1_value !== (option_1_value = $.get(option))) {
option_1.value = null == (option_1.__value = $.get(option)) ? '' : $.get(option);
}

$.set_text(text, $.get(option));
});

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

$.reset(select);

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

$.element(node, () => $.get(selected), false, ($$element, $$anchor) => {
var text_1 = $.text();
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 92
    • end: 282
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (4)
        • Text {...}
          • type: "Text"
          • start: 90
          • end: 92
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 92
          • end: 211
          • name: "select"
          • attributes: [...] (1)
            • BindDirective {...}
              • start: 100
              • end: 121
              • type: "BindDirective"
              • name: "value"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 112
                • end: 120
                • loc: {...}
                  • start: {...}
                    • line: 6
                    • column: 20
                    }
                  • end: {...}
                    • line: 6
                    • column: 28
                    }
                  }
                • name: "selected"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 122
                • end: 124
                • raw: "\n\t"
                • data: "\n\t"
                }
              • EachBlock {...}
                • type: "EachBlock"
                • start: 124
                • end: 201
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 131
                  • end: 138
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 8
                      }
                    • end: {...}
                      • line: 7
                      • column: 15
                      }
                    }
                  • name: "options"
                  }
                • body: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (3)
                    • Text {...}
                      • type: "Text"
                      • start: 149
                      • end: 152
                      • raw: "\n\t\t"
                      • data: "\n\t\t"
                      }
                    • RegularElement {...}
                      • type: "RegularElement"
                      • start: 152
                      • end: 192
                      • name: "option"
                      • attributes: [...] (1)
                        • Attribute {...}
                          • type: "Attribute"
                          • start: 160
                          • end: 174
                          • name: "value"
                          • value: ExpressionTag {...}
                            • type: "ExpressionTag"
                            • start: 166
                            • end: 174
                            • expression: Identifier {...}
                              • type: "Identifier"
                              • start: 167
                              • end: 173
                              • loc: {...}
                                • start: {...}
                                  • line: 8
                                  • column: 17
                                  }
                                • end: {...}
                                  • line: 8
                                  • column: 23
                                  }
                                }
                              • name: "option"
                              }
                            }
                          }
                        ]
                      • fragment: Fragment {...}
                        • type: "Fragment"
                        • nodes: [...] (1)
                          • ExpressionTag {...}
                            • type: "ExpressionTag"
                            • start: 175
                            • end: 183
                            • expression: Identifier {...}
                              • type: "Identifier"
                              • start: 176
                              • end: 182
                              • loc: {...}
                                • start: {...}
                                  • line: 8
                                  • column: 26
                                  }
                                • end: {...}
                                  • line: 8
                                  • column: 32
                                  }
                                }
                              • name: "option"
                              }
                            }
                          ]
                        }
                      }
                    • Text {...}
                      • type: "Text"
                      • start: 192
                      • end: 194
                      • raw: "\n\t"
                      • data: "\n\t"
                      }
                    ]
                  }
                • context: Identifier {...}
                  • type: "Identifier"
                  • name: "option"
                  • start: 142
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 19
                      • character: 142
                      }
                    • end: {...}
                      • line: 7
                      • column: 25
                      • character: 148
                      }
                    }
                  • end: 148
                  • typeAnnotation: undefined
                  }
                • index: undefined
                • key: undefined
                }
              • Text {...}
                • type: "Text"
                • start: 201
                • end: 202
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 211
          • end: 213
          • raw: " "
          • data: " "
          }
        • SvelteElement {...}
          • type: "SvelteElement"
          • start: 213
          • end: 282
          • name: "svelte:element"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 245
                • end: 251
                • raw: "I'm a "
                • data: "I'm a "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 251
                • end: 261
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 252
                  • end: 260
                  • loc: {...}
                    • start: {...}
                      • line: 12
                      • column: 39
                      }
                    • end: {...}
                      • line: 12
                      • column: 47
                      }
                    }
                  • name: "selected"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 261
                • end: 265
                • raw: " tag"
                • data: " tag"
                }
              ]
            }
          • tag: Identifier {...}
            • type: "Identifier"
            • start: 235
            • end: 243
            • loc: {...}
              • start: {...}
                • line: 12
                • column: 22
                }
              • end: {...}
                • line: 12
                • column: 30
                }
              }
            • name: "selected"
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 90
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 81
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 4
            • column: 0
            }
          }
        • body: [...] (2)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 44
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 35
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 16
                • end: 43
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 7
                    }
                  • end: {...}
                    • line: 2
                    • column: 34
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 16
                  • end: 23
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 7
                      }
                    • end: {...}
                      • line: 2
                      • column: 14
                      }
                    }
                  • name: "options"
                  }
                • init: ArrayExpression {...}
                  • type: "ArrayExpression"
                  • start: 26
                  • end: 43
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 17
                      }
                    • end: {...}
                      • line: 2
                      • column: 34
                      }
                    }
                  • elements: [...] (3)
                    • Literal {...}
                      • type: "Literal"
                      • start: 27
                      • end: 31
                      • loc: {...}
                        • start: {...}
                          • line: 2
                          • column: 18
                          }
                        • end: {...}
                          • line: 2
                          • column: 22
                          }
                        }
                      • value: "h1"
                      • raw: "'h1'"
                      }
                    • Literal {...}
                      • type: "Literal"
                      • start: 33
                      • end: 37
                      • loc: {...}
                        • start: {...}
                          • line: 2
                          • column: 24
                          }
                        • end: {...}
                          • line: 2
                          • column: 28
                          }
                        }
                      • value: "h3"
                      • raw: "'h3'"
                      }
                    • Literal {...}
                      • type: "Literal"
                      • start: 39
                      • end: 42
                      • loc: {...}
                        • start: {...}
                          • line: 2
                          • column: 30
                          }
                        • end: {...}
                          • line: 2
                          • column: 33
                          }
                        }
                      • value: "p"
                      • raw: "'p'"
                      }
                    ]
                  }
                }
              ]
            • kind: "const"
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 46
            • end: 80
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 3
                • column: 35
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 50
                • end: 79
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 5
                    }
                  • end: {...}
                    • line: 3
                    • column: 34
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 50
                  • end: 58
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 5
                      }
                    • end: {...}
                      • line: 3
                      • column: 13
                      }
                    }
                  • name: "selected"
                  }
                • init: CallExpression {...}
                  • type: "CallExpression"
                  • start: 61
                  • end: 79
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 16
                      }
                    • end: {...}
                      • line: 3
                      • column: 34
                      }
                    }
                  • callee: Identifier {...}
                    • type: "Identifier"
                    • start: 61
                    • end: 67
                    • loc: {...}
                      • start: {...}
                        • line: 3
                        • column: 16
                        }
                      • end: {...}
                        • line: 3
                        • column: 22
                        }
                      }
                    • name: "$state"
                    }
                  • arguments: [...] (1)
                    • MemberExpression {...}
                      • type: "MemberExpression"
                      • start: 68
                      • end: 78
                      • loc: {...}
                        • start: {...}
                          • line: 3
                          • column: 23
                          }
                        • end: {...}
                          • line: 3
                          • column: 33
                          }
                        }
                      • object: Identifier {...}
                        • type: "Identifier"
                        • start: 68
                        • end: 75
                        • loc: {...}
                          • start: {...}
                            • line: 3
                            • column: 23
                            }
                          • end: {...}
                            • line: 3
                            • column: 30
                            }
                          }
                        • name: "options"
                        }
                      • property: Literal {...}
                        • type: "Literal"
                        • start: 76
                        • end: 77
                        • loc: {...}
                          • start: {...}
                            • line: 3
                            • column: 31
                            }
                          • end: {...}
                            • line: 3
                            • column: 32
                            }
                          }
                        • value: 0
                        • raw: "0"
                        }
                      • computed: true
                      • optional: false
                      }
                    ]
                  • optional: false
                  }
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
<svelte:element> • Playground • Svelte