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 x = 7;
</script>

{#if x > 10}
<p>{x} is greater than 10</p>
{:else if 5 > x}
<p>{x} is less than 5</p>
{:else}
<p>{x} is between 5 and 10</p>
{/if}

Error compiling component

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

var root_1 = $.template(`<p></p>`);
var root_3 = $.template(`<p></p>`);
var root_4 = $.template(`<p></p>`);

export default function App($$anchor) {
let x = 7;
var fragment = $.comment();
var node = $.first_child(fragment);

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

p.textContent = `${x ?? ''} is greater than 10`;
$.append($$anchor, p);
};

var alternate_1 = ($$anchor) => {
var fragment_1 = $.comment();
var node_1 = $.first_child(fragment_1);

{
var consequent_1 = ($$anchor) => {
var p_1 = root_3();

p_1.textContent = `${x ?? ''} is less than 5`;
$.append($$anchor, p_1);
};

var alternate = ($$anchor) => {
var p_2 = root_4();

result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 32
    • end: 165
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 30
          • end: 32
          • raw: "\n\n"
          • data: "\n\n"
          }
        • IfBlock {...}
          • type: "IfBlock"
          • elseif: false
          • start: 32
          • end: 165
          • test: BinaryExpression {...}
            • type: "BinaryExpression"
            • start: 37
            • end: 43
            • loc: {...}
              • start: {...}
                • line: 5
                • column: 5
                }
              • end: {...}
                • line: 5
                • column: 11
                }
              }
            • left: Identifier {...}
              • type: "Identifier"
              • start: 37
              • end: 38
              • loc: {...}
                • start: {...}
                  • line: 5
                  • column: 5
                  }
                • end: {...}
                  • line: 5
                  • column: 6
                  }
                }
              • name: "x"
              }
            • operator: ">"
            • right: Literal {...}
              • type: "Literal"
              • start: 41
              • end: 43
              • loc: {...}
                • start: {...}
                  • line: 5
                  • column: 9
                  }
                • end: {...}
                  • line: 5
                  • column: 11
                  }
                }
              • value: 10
              • raw: "10"
              }
            }
          • consequent: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 44
                • end: 46
                • raw: "\n\t"
                • data: "\n\t"
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 46
                • end: 75
                • name: "p"
                • attributes: []
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (2)
                    • ExpressionTag {...}
                      • type: "ExpressionTag"
                      • start: 49
                      • end: 52
                      • expression: Identifier {...}
                        • type: "Identifier"
                        • start: 50
                        • end: 51
                        • loc: {...}
                          • start: {...}
                            • line: 6
                            • column: 5
                            }
                          • end: {...}
                            • line: 6
                            • column: 6
                            }
                          }
                        • name: "x"
                        }
                      }
                    • Text {...}
                      • type: "Text"
                      • start: 52
                      • end: 71
                      • raw: " is greater than 10"
                      • data: " is greater than 10"
                      }
                    ]
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 75
                • end: 76
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          • alternate: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • IfBlock {...}
                • start: 76
                • end: 165
                • type: "IfBlock"
                • elseif: true
                • test: BinaryExpression {...}
                  • type: "BinaryExpression"
                  • start: 86
                  • end: 91
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 10
                      }
                    • end: {...}
                      • line: 7
                      • column: 15
                      }
                    }
                  • left: Literal {...}
                    • type: "Literal"
                    • start: 86
                    • end: 87
                    • loc: {...}
                      • start: {...}
                        • line: 7
                        • column: 10
                        }
                      • end: {...}
                        • line: 7
                        • column: 11
                        }
                      }
                    • value: 5
                    • raw: "5"
                    }
                  • operator: ">"
                  • right: Identifier {...}
                    • type: "Identifier"
                    • start: 90
                    • end: 91
                    • loc: {...}
                      • start: {...}
                        • line: 7
                        • column: 14
                        }
                      • end: {...}
                        • line: 7
                        • column: 15
                        }
                      }
                    • name: "x"
                    }
                  }
                • consequent: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (3)
                    • Text {...}
                      • type: "Text"
                      • start: 92
                      • end: 94
                      • raw: "\n\t"
                      • data: "\n\t"
                      }
                    • RegularElement {...}
                      • type: "RegularElement"
                      • start: 94
                      • end: 119
                      • name: "p"
                      • attributes: []
                      • fragment: Fragment {...}
                        • type: "Fragment"
                        • nodes: [...] (2)
                          • ExpressionTag {...}
                            • type: "ExpressionTag"
                            • start: 97
                            • end: 100
                            • expression: Identifier {...}
                              • type: "Identifier"
                              • start: 98
                              • end: 99
                              • loc: {...}
                                • start: {...}
                                  • line: 8
                                  • column: 5
                                  }
                                • end: {...}
                                  • line: 8
                                  • column: 6
                                  }
                                }
                              • name: "x"
                              }
                            }
                          • Text {...}
                            • type: "Text"
                            • start: 100
                            • end: 115
                            • raw: " is less than 5"
                            • data: " is less than 5"
                            }
                          ]
                        }
                      }
                    • Text {...}
                      • type: "Text"
                      • start: 119
                      • end: 120
                      • raw: "\n"
                      • data: "\n"
                      }
                    ]
                  }
                • alternate: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (3)
                    • Text {...}
                      • type: "Text"
                      • start: 127
                      • end: 129
                      • raw: "\n\t"
                      • data: "\n\t"
                      }
                    • RegularElement {...}
                      • type: "RegularElement"
                      • start: 129
                      • end: 159
                      • name: "p"
                      • attributes: []
                      • fragment: Fragment {...}
                        • type: "Fragment"
                        • nodes: [...] (2)
                          • ExpressionTag {...}
                            • type: "ExpressionTag"
                            • start: 132
                            • end: 135
                            • expression: Identifier {...}
                              • type: "Identifier"
                              • start: 133
                              • end: 134
                              • loc: {...}
                                • start: {...}
                                  • line: 10
                                  • column: 5
                                  }
                                • end: {...}
                                  • line: 10
                                  • column: 6
                                  }
                                }
                              • name: "x"
                              }
                            }
                          • Text {...}
                            • type: "Text"
                            • start: 135
                            • end: 155
                            • raw: " is between 5 and 10"
                            • data: " is between 5 and 10"
                            }
                          ]
                        }
                      }
                    • Text {...}
                      • type: "Text"
                      • start: 159
                      • end: 160
                      • raw: "\n"
                      • data: "\n"
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 30
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 21
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 3
            • column: 0
            }
          }
        • body: [...] (1)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 20
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 11
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 19
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 10
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 15
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 6
                      }
                    }
                  • name: "x"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 18
                  • end: 19
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 9
                      }
                    • end: {...}
                      • line: 2
                      • column: 10
                      }
                    }
                  • value: 7
                  • raw: "7"
                  }
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Else-if blocks • Playground • Svelte