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 isSmallerThan10 = true;
let count = {a:1};
$: if (count.a) {
if (count.a < 10) {
console.error("smaller", count.a);
// this should trigger this reactive block again and enter the "else" but it doesn't
count = {a: 11};
} else {
console.error("larger", count.a);
isSmallerThan10 = false;
}
}
</script>

<p>
count is {count.a}
</p>
<p>
isSmallerThan10 is {isSmallerThan10}
</p>

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

var root = $.template(`<p> </p> <p> </p>`, 1);

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

let isSmallerThan10 = $.mutable_state(true);
let count = $.mutable_state({ a: 1 });

$.legacy_pre_effect(() => ($.get(count)), () => {
if ($.get(count).a) {
if ($.get(count).a < 10) {
console.error("smaller", $.get(count).a);
// this should trigger this reactive block again and enter the "else" but it doesn't
$.set(count, { a: 11 });
} else {
console.error("larger", $.get(count).a);
$.set(isSmallerThan10, false);
}
}
});

$.legacy_pre_effect_reset();

var fragment = root();
var p = $.first_child(fragment);
var text = $.child(p);

$.reset(p);

var p_1 = $.sibling(p, 2);
var text_1 = $.child(p_1);

result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 340
    • end: 415
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (4)
        • Text {...}
          • type: "Text"
          • start: 338
          • end: 340
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 340
          • end: 368
          • name: "p"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 343
                • end: 354
                • raw: "count is "
                • data: "count is "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 354
                • end: 363
                • expression: MemberExpression {...}
                  • type: "MemberExpression"
                  • start: 355
                  • end: 362
                  • loc: {...}
                    • start: {...}
                      • line: 17
                      • column: 11
                      }
                    • end: {...}
                      • line: 17
                      • column: 18
                      }
                    }
                  • object: Identifier {...}
                    • type: "Identifier"
                    • start: 355
                    • end: 360
                    • loc: {...}
                      • start: {...}
                        • line: 17
                        • column: 11
                        }
                      • end: {...}
                        • line: 17
                        • column: 16
                        }
                      }
                    • name: "count"
                    }
                  • property: Identifier {...}
                    • type: "Identifier"
                    • start: 361
                    • end: 362
                    • loc: {...}
                      • start: {...}
                        • line: 17
                        • column: 17
                        }
                      • end: {...}
                        • line: 17
                        • column: 18
                        }
                      }
                    • name: "a"
                    }
                  • computed: false
                  • optional: false
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 363
                • end: 364
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 368
          • end: 369
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 369
          • end: 415
          • name: "p"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 372
                • end: 393
                • raw: "isSmallerThan10 is "
                • data: "isSmallerThan10 is "
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 393
                • end: 410
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 394
                  • end: 409
                  • loc: {...}
                    • start: {...}
                      • line: 20
                      • column: 21
                      }
                    • end: {...}
                      • line: 20
                      • column: 36
                      }
                    }
                  • name: "isSmallerThan10"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 410
                • end: 411
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 338
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 329
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 14
            • column: 0
            }
          }
        • body: [...] (3)
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 10
            • end: 37
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 28
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 14
                • end: 36
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 5
                    }
                  • end: {...}
                    • line: 2
                    • column: 27
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 14
                  • end: 29
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 5
                      }
                    • end: {...}
                      • line: 2
                      • column: 20
                      }
                    }
                  • name: "isSmallerThan10"
                  }
                • init: Literal {...}
                  • type: "Literal"
                  • start: 32
                  • end: 36
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 23
                      }
                    • end: {...}
                      • line: 2
                      • column: 27
                      }
                    }
                  • value: true
                  • raw: "true"
                  }
                }
              ]
            • kind: "let"
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 39
            • end: 57
            • loc: {...}
              • start: {...}
                • line: 3
                • column: 1
                }
              • end: {...}
                • line: 3
                • column: 19
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 43
                • end: 56
                • loc: {...}
                  • start: {...}
                    • line: 3
                    • column: 5
                    }
                  • end: {...}
                    • line: 3
                    • column: 18
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 43
                  • end: 48
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 5
                      }
                    • end: {...}
                      • line: 3
                      • column: 10
                      }
                    }
                  • name: "count"
                  }
                • init: ObjectExpression {...}
                  • type: "ObjectExpression"
                  • start: 51
                  • end: 56
                  • loc: {...}
                    • start: {...}
                      • line: 3
                      • column: 13
                      }
                    • end: {...}
                      • line: 3
                      • column: 18
                      }
                    }
                  • properties: [...] (1)
                    • Property {...}
                      • type: "Property"
                      • start: 52
                      • end: 55
                      • loc: {...}
                        • start: {...}
                          • line: 3
                          • column: 14
                          }
                        • end: {...}
                          • line: 3
                          • column: 17
                          }
                        }
                      • method: false
                      • shorthand: false
                      • computed: false
                      • key: Identifier {...}
                        • type: "Identifier"
                        • start: 52
                        • end: 53
                        • loc: {...}
                          • start: {...}
                            • line: 3
                            • column: 14
                            }
                          • end: {...}
                            • line: 3
                            • column: 15
                            }
                          }
                        • name: "a"
                        }
                      • value: Literal {...}
                        • type: "Literal"
                        • start: 54
                        • end: 55
                        • loc: {...}
                          • start: {...}
                            • line: 3
                            • column: 16
                            }
                          • end: {...}
                            • line: 3
                            • column: 17
                            }
                          }
                        • value: 1
                        • raw: "1"
                        }
                      • kind: "init"
                      }
                    ]
                  }
                }
              ]
            • kind: "let"
            }
          • LabeledStatement {...}
            • type: "LabeledStatement"
            • start: 59
            • end: 328
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 13
                • column: 2
                }
              }
            • body: IfStatement {...}
              • type: "IfStatement"
              • start: 62
              • end: 328
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 4
                  }
                • end: {...}
                  • line: 13
                  • column: 2
                  }
                }
              • test: MemberExpression {...}
                • type: "MemberExpression"
                • start: 66
                • end: 73
                • loc: {...}
                  • start: {...}
                    • line: 4
                    • column: 8
                    }
                  • end: {...}
                    • line: 4
                    • column: 15
                    }
                  }
                • object: Identifier {...}
                  • type: "Identifier"
                  • start: 66
                  • end: 71
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 8
                      }
                    • end: {...}
                      • line: 4
                      • column: 13
                      }
                    }
                  • name: "count"
                  }
                • property: Identifier {...}
                  • type: "Identifier"
                  • start: 72
                  • end: 73
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 14
                      }
                    • end: {...}
                      • line: 4
                      • column: 15
                      }
                    }
                  • name: "a"
                  }
                • computed: false
                • optional: false
                }
              • consequent: BlockStatement {...}
                • type: "BlockStatement"
                • start: 75
                • end: 328
                • loc: {...}
                  • start: {...}
                    • line: 4
                    • column: 17
                    }
                  • end: {...}
                    • line: 13
                    • column: 2
                    }
                  }
                • body: [...] (1)
                  • IfStatement {...}
                    • type: "IfStatement"
                    • start: 79
                    • end: 325
                    • loc: {...}
                      • start: {...}
                        • line: 5
                        • column: 2
                        }
                      • end: {...}
                        • line: 12
                        • column: 3
                        }
                      }
                    • test: BinaryExpression {...}
                      • type: "BinaryExpression"
                      • start: 83
                      • end: 95
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 6
                          }
                        • end: {...}
                          • line: 5
                          • column: 18
                          }
                        }
                      • left: MemberExpression {...}
                        • type: "MemberExpression"
                        • start: 83
                        • end: 90
                        • loc: {...}
                          • start: {...}
                            • line: 5
                            • column: 6
                            }
                          • end: {...}
                            • line: 5
                            • column: 13
                            }
                          }
                        • object: Identifier {...}
                          • type: "Identifier"
                          • start: 83
                          • end: 88
                          • loc: {...}
                            • start: {...}
                              • line: 5
                              • column: 6
                              }
                            • end: {...}
                              • line: 5
                              • column: 11
                              }
                            }
                          • name: "count"
                          }
                        • property: Identifier {...}
                          • type: "Identifier"
                          • start: 89
                          • end: 90
                          • loc: {...}
                            • start: {...}
                              • line: 5
                              • column: 12
                              }
                            • end: {...}
                              • line: 5
                              • column: 13
                              }
                            }
                          • name: "a"
                          }
                        • computed: false
                        • optional: false
                        }
                      • operator: "<"
                      • right: Literal {...}
                        • type: "Literal"
                        • start: 93
                        • end: 95
                        • loc: {...}
                          • start: {...}
                            • line: 5
                            • column: 16
                            }
                          • end: {...}
                            • line: 5
                            • column: 18
                            }
                          }
                        • value: 10
                        • raw: "10"
                        }
                      }
                    • consequent: BlockStatement {...}
                      • type: "BlockStatement"
                      • start: 97
                      • end: 249
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 20
                          }
                        • end: {...}
                          • line: 9
                          • column: 3
                          }
                        }
                      • body: [...] (2)
                        • ExpressionStatement {...}
                          • type: "ExpressionStatement"
                          • start: 102
                          • end: 136
                          • loc: {...}
                            • start: {...}
                              • line: 6
                              • column: 3
                              }
                            • end: {...}
                              • line: 6
                              • column: 37
                              }
                            }
                          • expression: CallExpression {...}
                            • type: "CallExpression"
                            • start: 102
                            • end: 135
                            • loc: {...}
                              • start: {...}
                                • line: 6
                                • column: 3
                                }
                              • end: {...}
                                • line: 6
                                • column: 36
                                }
                              }
                            • callee: MemberExpression {...}
                              • type: "MemberExpression"
                              • start: 102
                              • end: 115
                              • loc: {...}
                                • start: {...}
                                  • line: 6
                                  • column: 3
                                  }
                                • end: {...}
                                  • line: 6
                                  • column: 16
                                  }
                                }
                              • object: Identifier {...}
                                • type: "Identifier"
                                • start: 102
                                • end: 109
                                • loc: {...}
                                  • start: {...}
                                    • line: 6
                                    • column: 3
                                    }
                                  • end: {...}
                                    • line: 6
                                    • column: 10
                                    }
                                  }
                                • name: "console"
                                }
                              • property: Identifier {...}
                                • type: "Identifier"
                                • start: 110
                                • end: 115
                                • loc: {...}
                                  • start: {...}
                                    • line: 6
                                    • column: 11
                                    }
                                  • end: {...}
                                    • line: 6
                                    • column: 16
                                    }
                                  }
                                • name: "error"
                                }
                              • computed: false
                              • optional: false
                              }
                            • arguments: [...] (2)
                              • Literal {...}
                                • type: "Literal"
                                • start: 116
                                • end: 125
                                • loc: {...}
                                  • start: {...}
                                    • line: 6
                                    • column: 17
                                    }
                                  • end: {...}
                                    • line: 6
                                    • column: 26
                                    }
                                  }
                                • value: "smaller"
                                • raw: "\"smaller\""
                                }
                              • MemberExpression {...}
                                • type: "MemberExpression"
                                • start: 127
                                • end: 134
                                • loc: {...}
                                  • start: {...}
                                    • line: 6
                                    • column: 28
                                    }
                                  • end: {...}
                                    • line: 6
                                    • column: 35
                                    }
                                  }
                                • object: Identifier {...}
                                  • type: "Identifier"
                                  • start: 127
                                  • end: 132
                                  • loc: {...}
                                    • start: {...}
                                      • line: 6
                                      • column: 28
                                      }
                                    • end: {...}
                                      • line: 6
                                      • column: 33
                                      }
                                    }
                                  • name: "count"
                                  }
                                • property: Identifier {...}
                                  • type: "Identifier"
                                  • start: 133
                                  • end: 134
                                  • loc: {...}
                                    • start: {...}
                                      • line: 6
                                      • column: 34
                                      }
                                    • end: {...}
                                      • line: 6
                                      • column: 35
                                      }
                                    }
                                  • name: "a"
                                  }
                                • computed: false
                                • optional: false
                                }
                              ]
                            • optional: false
                            }
                          }
                        • ExpressionStatement {...}
                          • type: "ExpressionStatement"
                          • start: 228
                          • end: 244
                          • loc: {...}
                            • start: {...}
                              • line: 8
                              • column: 3
                              }
                            • end: {...}
                              • line: 8
                              • column: 19
                              }
                            }
                          • expression: AssignmentExpression {...}
                            • type: "AssignmentExpression"
                            • start: 228
                            • end: 243
                            • loc: {...}
                              • start: {...}
                                • line: 8
                                • column: 3
                                }
                              • end: {...}
                                • line: 8
                                • column: 18
                                }
                              }
                            • operator: "="
                            • left: Identifier {...}
                              • type: "Identifier"
                              • start: 228
                              • end: 233
                              • loc: {...}
                                • start: {...}
                                  • line: 8
                                  • column: 3
                                  }
                                • end: {...}
                                  • line: 8
                                  • column: 8
                                  }
                                }
                              • name: "count"
                              }
                            • right: ObjectExpression {...}
                              • type: "ObjectExpression"
                              • start: 236
                              • end: 243
                              • loc: {...}
                                • start: {...}
                                  • line: 8
                                  • column: 11
                                  }
                                • end: {...}
                                  • line: 8
                                  • column: 18
                                  }
                                }
                              • properties: [...] (1)
                                • Property {...}
                                  • type: "Property"
                                  • start: 237
                                  • end: 242
                                  • loc: {...}
                                    • start: {...}
                                      • line: 8
                                      • column: 12
                                      }
                                    • end: {...}
                                      • line: 8
                                      • column: 17
                                      }
                                    }
                                  • method: false
                                  • shorthand: false
                                  • computed: false
                                  • key: Identifier {...}
                                    • type: "Identifier"
                                    • start: 237
                                    • end: 238
                                    • loc: {...}
                                      • start: {...}
                                        • line: 8
                                        • column: 12
                                        }
                                      • end: {...}
                                        • line: 8
                                        • column: 13
                                        }
                                      }
                                    • name: "a"
                                    }
                                  • value: Literal {...}
                                    • type: "Literal"
                                    • start: 240
                                    • end: 242
                                    • loc: {...}
                                      • start: {...}
                                        • line: 8
                                        • column: 15
                                        }
                                      • end: {...}
                                        • line: 8
                                        • column: 17
                                        }
                                      }
                                    • value: 11
                                    • raw: "11"
                                    }
                                  • kind: "init"
                                  }
                                ]
                              }
                            }
                          • leadingComments: [...] (1)
                            • Line {...}
                              • type: "Line"
                              • value: " this should trigger this reactive block again and enter the \"else\" but it doesn't"
                              • start: 140
                              • end: 224
                              }
                            ]
                          }
                        ]
                      }
                    • alternate: BlockStatement {...}
                      • type: "BlockStatement"
                      • start: 255
                      • end: 325
                      • loc: {...}
                        • start: {...}
                          • line: 9
                          • column: 9
                          }
                        • end: {...}
                          • line: 12
                          • column: 3
                          }
                        }
                      • body: [...] (2)
                        • ExpressionStatement {...}
                          • type: "ExpressionStatement"
                          • start: 260
                          • end: 293
                          • loc: {...}
                            • start: {...}
                              • line: 10
                              • column: 3
                              }
                            • end: {...}
                              • line: 10
                              • column: 36
                              }
                            }
                          • expression: CallExpression {...}
                            • type: "CallExpression"
                            • start: 260
                            • end: 292
                            • loc: {...}
                              • start: {...}
                                • line: 10
                                • column: 3
                                }
                              • end: {...}
                                • line: 10
                                • column: 35
                                }
                              }
                            • callee: MemberExpression {...}
                              • type: "MemberExpression"
                              • start: 260
                              • end: 273
                              • loc: {...}
                                • start: {...}
                                  • line: 10
                                  • column: 3
                                  }
                                • end: {...}
                                  • line: 10
                                  • column: 16
                                  }
                                }
                              • object: Identifier {...}
                                • type: "Identifier"
                                • start: 260
                                • end: 267
                                • loc: {...}
                                  • start: {...}
                                    • line: 10
                                    • column: 3
                                    }
                                  • end: {...}
                                    • line: 10
                                    • column: 10
                                    }
                                  }
                                • name: "console"
                                }
                              • property: Identifier {...}
                                • type: "Identifier"
                                • start: 268
                                • end: 273
                                • loc: {...}
                                  • start: {...}
                                    • line: 10
                                    • column: 11
                                    }
                                  • end: {...}
                                    • line: 10
                                    • column: 16
                                    }
                                  }
                                • name: "error"
                                }
                              • computed: false
                              • optional: false
                              }
                            • arguments: [...] (2)
                              • Literal {...}
                                • type: "Literal"
                                • start: 274
                                • end: 282
                                • loc: {...}
                                  • start: {...}
                                    • line: 10
                                    • column: 17
                                    }
                                  • end: {...}
                                    • line: 10
                                    • column: 25
                                    }
                                  }
                                • value: "larger"
                                • raw: "\"larger\""
                                }
                              • MemberExpression {...}
                                • type: "MemberExpression"
                                • start: 284
                                • end: 291
                                • loc: {...}
                                  • start: {...}
                                    • line: 10
                                    • column: 27
                                    }
                                  • end: {...}
                                    • line: 10
                                    • column: 34
                                    }
                                  }
                                • object: Identifier {...}
                                  • type: "Identifier"
                                  • start: 284
                                  • end: 289
                                  • loc: {...}
                                    • start: {...}
                                      • line: 10
                                      • column: 27
                                      }
                                    • end: {...}
                                      • line: 10
                                      • column: 32
                                      }
                                    }
                                  • name: "count"
                                  }
                                • property: Identifier {...}
                                  • type: "Identifier"
                                  • start: 290
                                  • end: 291
                                  • loc: {...}
                                    • start: {...}
                                      • line: 10
                                      • column: 33
                                      }
                                    • end: {...}
                                      • line: 10
                                      • column: 34
                                      }
                                    }
                                  • name: "a"
                                  }
                                • computed: false
                                • optional: false
                                }
                              ]
                            • optional: false
                            }
                          }
                        • ExpressionStatement {...}
                          • type: "ExpressionStatement"
                          • start: 297
                          • end: 321
                          • loc: {...}
                            • start: {...}
                              • line: 11
                              • column: 3
                              }
                            • end: {...}
                              • line: 11
                              • column: 27
                              }
                            }
                          • expression: AssignmentExpression {...}
                            • type: "AssignmentExpression"
                            • start: 297
                            • end: 320
                            • loc: {...}
                              • start: {...}
                                • line: 11
                                • column: 3
                                }
                              • end: {...}
                                • line: 11
                                • column: 26
                                }
                              }
                            • operator: "="
                            • left: Identifier {...}
                              • type: "Identifier"
                              • start: 297
                              • end: 312
                              • loc: {...}
                                • start: {...}
                                  • line: 11
                                  • column: 3
                                  }
                                • end: {...}
                                  • line: 11
                                  • column: 18
                                  }
                                }
                              • name: "isSmallerThan10"
                              }
                            • right: Literal {...}
                              • type: "Literal"
                              • start: 315
                              • end: 320
                              • loc: {...}
                                • start: {...}
                                  • line: 11
                                  • column: 21
                                  }
                                • end: {...}
                                  • line: 11
                                  • column: 26
                                  }
                                }
                              • value: false
                              • raw: "false"
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              • alternate: null
              }
            • label: Identifier {...}
              • type: "Identifier"
              • start: 59
              • end: 60
              • loc: {...}
                • start: {...}
                  • line: 4
                  • column: 1
                  }
                • end: {...}
                  • line: 4
                  • column: 2
                  }
                }
              • name: "$"
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
No recursion for you • Playground • Svelte