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
utils.js
<script>
import { onInterval } from './utils.js';

let seconds = $state(0);
onInterval(() => (seconds += 1), 1000);
</script>

<p>
The page has been open for
{seconds}
{seconds === 1 ? 'second' : 'seconds'}
</p>

Error compiling component

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

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

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

let seconds = $.state(0);

onInterval(() => $.set(seconds, $.get(seconds) + 1), 1000);

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

$.reset(p);

$.template_effect(() => $.set_text(text, `The page has been open for
${$.get(seconds) ?? ''}
${($.get(seconds) === 1 ? 'second' : 'seconds') ?? ''}`));

$.append($$anchor, p);
$.pop();
}
result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 130
    • end: 217
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (2)
        • Text {...}
          • type: "Text"
          • start: 128
          • end: 130
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 130
          • end: 217
          • name: "p"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (5)
              • Text {...}
                • type: "Text"
                • start: 133
                • end: 163
                • raw: "The page has been open for\n\t"
                • data: "The page has been open for\n\t"
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 163
                • end: 172
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 164
                  • end: 171
                  • loc: {...}
                    • start: {...}
                      • line: 10
                      • column: 2
                      }
                    • end: {...}
                      • line: 10
                      • column: 9
                      }
                    }
                  • name: "seconds"
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 172
                • end: 174
                • raw: "\n\t"
                • data: "\n\t"
                }
              • ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 174
                • end: 212
                • expression: ConditionalExpression {...}
                  • type: "ConditionalExpression"
                  • start: 175
                  • end: 211
                  • loc: {...}
                    • start: {...}
                      • line: 11
                      • column: 2
                      }
                    • end: {...}
                      • line: 11
                      • column: 38
                      }
                    }
                  • test: BinaryExpression {...}
                    • type: "BinaryExpression"
                    • start: 175
                    • end: 188
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 2
                        }
                      • end: {...}
                        • line: 11
                        • column: 15
                        }
                      }
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 175
                      • end: 182
                      • loc: {...}
                        • start: {...}
                          • line: 11
                          • column: 2
                          }
                        • end: {...}
                          • line: 11
                          • column: 9
                          }
                        }
                      • name: "seconds"
                      }
                    • operator: "==="
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 187
                      • end: 188
                      • loc: {...}
                        • start: {...}
                          • line: 11
                          • column: 14
                          }
                        • end: {...}
                          • line: 11
                          • column: 15
                          }
                        }
                      • value: 1
                      • raw: "1"
                      }
                    }
                  • consequent: Literal {...}
                    • type: "Literal"
                    • start: 191
                    • end: 199
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 18
                        }
                      • end: {...}
                        • line: 11
                        • column: 26
                        }
                      }
                    • value: "second"
                    • raw: "'second'"
                    }
                  • alternate: Literal {...}
                    • type: "Literal"
                    • start: 202
                    • end: 211
                    • loc: {...}
                      • start: {...}
                        • line: 11
                        • column: 29
                        }
                      • end: {...}
                        • line: 11
                        • column: 38
                        }
                      }
                    • value: "seconds"
                    • raw: "'seconds'"
                    }
                  }
                }
              • Text {...}
                • type: "Text"
                • start: 212
                • end: 213
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 128
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 119
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 6
            • column: 0
            }
          }
        • body: [...] (3)
          • ImportDeclaration {...}
            • type: "ImportDeclaration"
            • start: 10
            • end: 50
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 41
                }
              }
            • specifiers: [...] (1)
              • ImportSpecifier {...}
                • type: "ImportSpecifier"
                • start: 19
                • end: 29
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 10
                    }
                  • end: {...}
                    • line: 2
                    • column: 20
                    }
                  }
                • imported: Identifier {...}
                  • type: "Identifier"
                  • start: 19
                  • end: 29
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 10
                      }
                    • end: {...}
                      • line: 2
                      • column: 20
                      }
                    }
                  • name: "onInterval"
                  }
                • local: Identifier {...}
                  • type: "Identifier"
                  • start: 19
                  • end: 29
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 10
                      }
                    • end: {...}
                      • line: 2
                      • column: 20
                      }
                    }
                  • name: "onInterval"
                  }
                }
              ]
            • source: Literal {...}
              • type: "Literal"
              • start: 37
              • end: 49
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 28
                  }
                • end: {...}
                  • line: 2
                  • column: 40
                  }
                }
              • value: "./utils.js"
              • raw: "'./utils.js'"
              }
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 53
            • end: 77
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 4
                • column: 25
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 57
                • end: 76
                • loc: {...}
                  • start: {...}
                    • line: 4
                    • column: 5
                    }
                  • end: {...}
                    • line: 4
                    • column: 24
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 57
                  • end: 64
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 5
                      }
                    • end: {...}
                      • line: 4
                      • column: 12
                      }
                    }
                  • name: "seconds"
                  }
                • init: CallExpression {...}
                  • type: "CallExpression"
                  • start: 67
                  • end: 76
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 15
                      }
                    • end: {...}
                      • line: 4
                      • column: 24
                      }
                    }
                  • callee: Identifier {...}
                    • type: "Identifier"
                    • start: 67
                    • end: 73
                    • loc: {...}
                      • start: {...}
                        • line: 4
                        • column: 15
                        }
                      • end: {...}
                        • line: 4
                        • column: 21
                        }
                      }
                    • name: "$state"
                    }
                  • arguments: [...] (1)
                    • Literal {...}
                      • type: "Literal"
                      • start: 74
                      • end: 75
                      • loc: {...}
                        • start: {...}
                          • line: 4
                          • column: 22
                          }
                        • end: {...}
                          • line: 4
                          • column: 23
                          }
                        }
                      • value: 0
                      • raw: "0"
                      }
                    ]
                  • optional: false
                  }
                }
              ]
            • kind: "let"
            }
          • ExpressionStatement {...}
            • type: "ExpressionStatement"
            • start: 79
            • end: 118
            • loc: {...}
              • start: {...}
                • line: 5
                • column: 1
                }
              • end: {...}
                • line: 5
                • column: 40
                }
              }
            • expression: CallExpression {...}
              • type: "CallExpression"
              • start: 79
              • end: 117
              • loc: {...}
                • start: {...}
                  • line: 5
                  • column: 1
                  }
                • end: {...}
                  • line: 5
                  • column: 39
                  }
                }
              • callee: Identifier {...}
                • type: "Identifier"
                • start: 79
                • end: 89
                • loc: {...}
                  • start: {...}
                    • line: 5
                    • column: 1
                    }
                  • end: {...}
                    • line: 5
                    • column: 11
                    }
                  }
                • name: "onInterval"
                }
              • arguments: [...] (2)
                • ArrowFunctionExpression {...}
                  • type: "ArrowFunctionExpression"
                  • start: 90
                  • end: 110
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 12
                      }
                    • end: {...}
                      • line: 5
                      • column: 32
                      }
                    }
                  • id: null
                  • expression: true
                  • generator: false
                  • async: false
                  • params: []
                  • body: AssignmentExpression {...}
                    • type: "AssignmentExpression"
                    • start: 97
                    • end: 109
                    • loc: {...}
                      • start: {...}
                        • line: 5
                        • column: 19
                        }
                      • end: {...}
                        • line: 5
                        • column: 31
                        }
                      }
                    • operator: "+="
                    • left: Identifier {...}
                      • type: "Identifier"
                      • start: 97
                      • end: 104
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 19
                          }
                        • end: {...}
                          • line: 5
                          • column: 26
                          }
                        }
                      • name: "seconds"
                      }
                    • right: Literal {...}
                      • type: "Literal"
                      • start: 108
                      • end: 109
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 30
                          }
                        • end: {...}
                          • line: 5
                          • column: 31
                          }
                        }
                      • value: 1
                      • raw: "1"
                      }
                    }
                  }
                • Literal {...}
                  • type: "Literal"
                  • start: 112
                  • end: 116
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 34
                      }
                    • end: {...}
                      • line: 5
                      • column: 38
                      }
                    }
                  • value: 1000
                  • raw: "1000"
                  }
                ]
              • optional: false
              }
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
onDestroy • Playground • Svelte