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>
export let condition;
</script>

{#if condition}
<div />
{/if}

loading Svelte compiler...
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

var root_1 = $.template(`<div></div>`);

export default function App($$anchor, $$props) {
let condition = $.prop($$props, 'condition', 8);
var fragment = $.comment();
var node = $.first_child(fragment);

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

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

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

$.append($$anchor, fragment);
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 43
    • end: 72
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 41
          • end: 43
          • raw: "\n\n"
          • data: "\n\n"
          }
        • IfBlock {...}
          • type: "IfBlock"
          • elseif: false
          • start: 43
          • end: 72
          • test: Identifier {...}
            • type: "Identifier"
            • start: 48
            • end: 57
            • loc: {...}
              • start: {...}
                • line: 5
                • column: 5
                }
              • end: {...}
                • line: 5
                • column: 14
                }
              }
            • name: "condition"
            }
          • consequent: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 58
                • end: 59
                • raw: "\n"
                • data: "\n"
                }
              • RegularElement {...}
                • type: "RegularElement"
                • start: 59
                • end: 66
                • name: "div"
                • attributes: []
                • fragment: Fragment {...}
                  • type: "Fragment"
                  • nodes: []
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 66
                • end: 67
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          • alternate: null
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 41
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 32
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 3
            • column: 0
            }
          }
        • body: [...] (1)
          • ExportNamedDeclaration {...}
            • type: "ExportNamedDeclaration"
            • start: 10
            • end: 31
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 22
                }
              }
            • declaration: VariableDeclaration {...}
              • type: "VariableDeclaration"
              • start: 17
              • end: 31
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 8
                  }
                • end: {...}
                  • line: 2
                  • column: 22
                  }
                }
              • declarations: [...] (1)
                • VariableDeclarator {...}
                  • type: "VariableDeclarator"
                  • start: 21
                  • end: 30
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 12
                      }
                    • end: {...}
                      • line: 2
                      • column: 21
                      }
                    }
                  • id: Identifier {...}
                    • type: "Identifier"
                    • start: 21
                    • end: 30
                    • loc: {...}
                      • start: {...}
                        • line: 2
                        • column: 12
                        }
                      • end: {...}
                        • line: 2
                        • column: 21
                        }
                      }
                    • name: "condition"
                    }
                  • init: null
                  }
                ]
              • kind: "let"
              }
            • specifiers: []
            • source: null
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Compile Svelte in your Head - {#if} • Playground • Svelte