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>
function sum() {
return a + b;
}
$: sum = sum();//a + b;
let a = 5;
$: b = a + 3;
</script>

<h1>The sum of {a} and {b} is {sum}!</h1>
get(...) is not a function in App.svelte
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

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

export default function App($$anchor, $$props) {
$.push($$props, false);

const b = $.mutable_state();

function sum() {
return a + $.get(b);
}

let a = 5;

$.legacy_pre_effect(() => ($.get(sum)), () => {
$.set(sum, $.get(sum)());
});

$.legacy_pre_effect(() => {}, () => {
$.set(b, a + 3);
});

$.legacy_pre_effect_reset();

var h1 = root();
var text = $.child(h1);

$.reset(h1);
$.template_effect(() => $.set_text(text, `The sum of ${a ?? ''} and ${$.get(b) ?? ''} is ${$.get(sum) ?? ''}!`));
$.append($$anchor, h1);
$.pop();
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 109
    • end: 150
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 107
          • end: 109
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 109
          • end: 150
          • name: "h1"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (7)
              • Text {...}
                • type: "Text"
                • start: 113
                • end: 124
                • raw: "The sum of "
                • data: "The sum of "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 124
                • end: 127
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 125
                  • end: 126
                  • loc: {...}
                    • start: {...}
                      • line: 10
                      • column: 16
                      }
                    • end: {...}
                      • line: 10
                      • column: 17
                      }
                    }
                  • name: "a"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 127
                • end: 132
                • raw: " and "
                • data: " and "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 132
                • end: 135
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 133
                  • end: 134
                  • loc: {...}
                    • start: {...}
                      • line: 10
                      • column: 24
                      }
                    • end: {...}
                      • line: 10
                      • column: 25
                      }
                    }
                  • name: "b"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 135
                • end: 139
                • raw: " is "
                • data: " is "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 139
                • end: 144
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 140
                  • end: 143
                  • loc: {...}
                    • start: {...}
                      • line: 10
                      • column: 31
                      }
                    • end: {...}
                      • line: 10
                      • column: 34
                      }
                    }
                  • name: "sum"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 144
                • end: 145
                • raw: "!"
                • data: "!"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 107
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 98
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 8
            • column: 0
            }
          }
        • body: [...] (4)
          • FunctionDeclaration {...}
            • type: "FunctionDeclaration"
            • start: 10
            • end: 45
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 4
                • column: 2
                }
              }
            • id: Identifier {...}
              • type: "Identifier"
              • start: 19
              • end: 22
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 10
                  }
                • end: {...}
                  • line: 2
                  • column: 13
                  }
                }
              • name: "sum"
              }
            • expression: false
            • generator: false
            • async: false
            • params: []
            • body: BlockStatement {...}
              • type: "BlockStatement"
              • start: 25
              • end: 45
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 16
                  }
                • end: {...}
                  • line: 4
                  • column: 2
                  }
                }
              • body: [...] (1)
                • ReturnStatement {...}
                  • type: "ReturnStatement"
                  • start: 29
                  • end: 42
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 2
                      }
                    • end: {...}
                      • line: 3
                      • column: 15
                      }
                    }
                  • argument: BinaryExpression {...}
                    • type: "BinaryExpression"
                    • start: 36
                    • end: 41
                    • loc: {...}
                      • start: {...}
                        • line: 3
                        • column: 9
                        }
                      • end: {...}
                        • line: 3
                        • column: 14
                        }
                      }
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 36
                      • end: 37
                      • loc: {...}
                        • start: {...}
                          • line: 3
                          • column: 9
                          }
                        • end: {...}
                          • line: 3
                          • column: 10
                          }
                        }
                      • name: "a"
                      }
                    • operator: "+"
                    • right: Identifier {...}
                      • type: "Identifier"
                      • start: 40
                      • end: 41
                      • loc: {...}
                        • start: {...}
                          • line: 3
                          • column: 13
                          }
                        • end: {...}
                          • line: 3
                          • column: 14
                          }
                        }
                      • name: "b"
                      }
                    }
                  }
                ]
              }
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 47
            • end: 62
            • loc: {...}
              • start: {...}
                • line: 5
                • column: 1
                }
              • end: {...}
                • line: 5
                • column: 16
                }
              }
            • body: ExpressionStatement {...}
              • type: "ExpressionStatement"
              • start: 50
              • end: 62
              • loc: {...}
                • start: {...}
                  • line: 5
                  • column: 4
                  }
                • end: {...}
                  • line: 5
                  • column: 16
                  }
                }
              • expression: AssignmentExpression {...}
                • type: "AssignmentExpression"
                • start: 50
                • end: 61
                • loc: {...}
                  • start: {...}
                    • line: 5
                    • column: 4
                    }
                  • end: {...}
                    • line: 5
                    • column: 15
                    }
                  }
                • operator: "="
                • left: Identifier {...}
                  • type: "Identifier"
                  • start: 50
                  • end: 53
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 4
                      }
                    • end: {...}
                      • line: 5
                      • column: 7
                      }
                    }
                  • name: "sum"
                  }
                • right: CallExpression {...}
                  • type: "CallExpression"
                  • start: 56
                  • end: 61
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 10
                      }
                    • end: {...}
                      • line: 5
                      • column: 15
                      }
                    }
                  • callee: Identifier {...}
                    • type: "Identifier"
                    • start: 56
                    • end: 59
                    • loc: {...}
                      • start: {...}
                        • line: 5
                        • column: 10
                        }
                      • end: {...}
                        • line: 5
                        • column: 13
                        }
                      }
                    • name: "sum"
                    }
                  • arguments: []
                  • optional: false
                  }
                }
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 47
              • end: 48
              • loc: {...}
                • start: {...}
                  • line: 5
                  • column: 1
                  }
                • end: {...}
                  • line: 5
                  • column: 2
                  }
                }
              • name: "$"
              }
            • trailingComments: [...] (1)
              • Line {...}
                • type: "Line"
                • value: "a + b;"
                • start: 62
                • end: 70
                }
              ]
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 72
            • end: 82
            • loc: {...}
              • start: {...}
                • line: 6
                • column: 1
                }
              • end: {...}
                • line: 6
                • column: 11
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 76
                • end: 81
                • loc: {...}
                  • start: {...}
                    • line: 6
                    • column: 5
                    }
                  • end: {...}
                    • line: 6
                    • column: 10
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 76
                  • end: 77
                  • loc: {...}
                    • start: {...}
                      • line: 6
                      • column: 5
                      }
                    • end: {...}
                      • line: 6
                      • column: 6
                      }
                    }
                  • name: "a"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 80
                  • end: 81
                  • loc: {...}
                    • start: {...}
                      • line: 6
                      • column: 9
                      }
                    • end: {...}
                      • line: 6
                      • column: 10
                      }
                    }
                  • value: 5
                  • raw: "5"
                  }
                }
              ]
            • kind: "let"
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 84
            • end: 97
            • loc: {...}
              • start: {...}
                • line: 7
                • column: 1
                }
              • end: {...}
                • line: 7
                • column: 14
                }
              }
            • body: ExpressionStatement {...}
              • type: "ExpressionStatement"
              • start: 87
              • end: 97
              • loc: {...}
                • start: {...}
                  • line: 7
                  • column: 4
                  }
                • end: {...}
                  • line: 7
                  • column: 14
                  }
                }
              • expression: AssignmentExpression {...}
                • type: "AssignmentExpression"
                • start: 87
                • end: 96
                • loc: {...}
                  • start: {...}
                    • line: 7
                    • column: 4
                    }
                  • end: {...}
                    • line: 7
                    • column: 13
                    }
                  }
                • operator: "="
                • left: Identifier {...}
                  • type: "Identifier"
                  • start: 87
                  • end: 88
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 4
                      }
                    • end: {...}
                      • line: 7
                      • column: 5
                      }
                    }
                  • name: "b"
                  }
                • right: BinaryExpression {...}
                  • type: "BinaryExpression"
                  • start: 91
                  • end: 96
                  • loc: {...}
                    • start: {...}
                      • line: 7
                      • column: 8
                      }
                    • end: {...}
                      • line: 7
                      • column: 13
                      }
                    }
                  • left: Identifier {...}
                    • type: "Identifier"
                    • start: 91
                    • end: 92
                    • loc: {...}
                      • start: {...}
                        • line: 7
                        • column: 8
                        }
                      • end: {...}
                        • line: 7
                        • column: 9
                        }
                      }
                    • name: "a"
                    }
                  • operator: "+"
                  • right: Literal {...}
                    • type: "Literal"
                    • start: 95
                    • end: 96
                    • loc: {...}
                      • start: {...}
                        • line: 7
                        • column: 12
                        }
                      • end: {...}
                        • line: 7
                        • column: 13
                        }
                      }
                    • value: 3
                    • raw: "3"
                    }
                  }
                }
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 84
              • end: 85
              • loc: {...}
                • start: {...}
                  • line: 7
                  • column: 1
                  }
                • end: {...}
                  • line: 7
                  • column: 2
                  }
                }
              • name: "$"
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
order matters with lost deps • Playground • Svelte