Create new
Bindings
Transitions
Animations
Easing
Component composition
Context API
Special elements
Module context
Debugging
Miscellaneous
App.svelte
runes
This component is not in runes mode.
To enable runes mode, either start using runes in your code, or add the following to the top of your component:
<svelte:options runes />
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
›
⌄
⌄
⌄
⌄
<script>
let agility = 0;
let power = 0;
function incrementAgility() {
agility ++;
}
function incrementPower() {
power ++;
}
function levelUp() {
agility += 5;
power += 7;
}
</script>
Agility: {agility}
Power: {power}
Stats: {agility * power}
<button on:click={incrementAgility}>+ Agility</button>
<button on:click={incrementPower}>+ Power</button>
<button on:click={levelUp}>Level Up</button>
fetching https://unpkg.com/svelte@5.20.5/src/internal/client/index.js
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
⌄
⌄
⌄
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';
var root = $.template(` <button>+ Agility</button> <button>+ Power</button> <button>Level Up</button>`, 1);
export default function App($$anchor) {
let agility = $.mutable_state(0);
let power = $.mutable_state(0);
function incrementAgility() {
$.update(agility);
}
function incrementPower() {
$.update(power);
}
function levelUp() {
$.set(agility, $.get(agility) + 5);
$.set(power, $.get(power) + 7);
}
$.next();
var fragment = root();
var text = $.first_child(fragment);
var button = $.sibling(text);
var button_1 = $.sibling(button, 2);
var button_2 = $.sibling(button_1, 2);
$.template_effect(() => $.set_text(text, `Agility: ${$.get(agility) ?? ''}
Power: ${$.get(power) ?? ''}
Stats: ${$.get(agility) * $.get(power)} `));
$.event('click', button, incrementAgility);
result = svelte.compile(source, {
generate: ,
});9
1
›
/* Add a <style> tag to see the CSS output */
Root {
- css: null
- js: []
- start: 217
- end: 427
- type: "Root"
fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (12)
Text {...}
- type: "Text"
- start: 215
- end: 226
- raw: "Agility: "
- data: "Agility: "
} ExpressionTag {...}
- type: "ExpressionTag"
- start: 226
- end: 235
expression: Identifier {...}
- type: "Identifier"
- start: 227
- end: 234
loc: {...}
start: {...}
- line: 16
- column: 10
}end: {...}
- line: 16
- column: 17
}
}- name: "agility"
}
} Text {...}
- type: "Text"
- start: 235
- end: 243
- raw: "\nPower: "
- data: "\nPower: "
} ExpressionTag {...}
- type: "ExpressionTag"
- start: 243
- end: 250
expression: Identifier {...}
- type: "Identifier"
- start: 244
- end: 249
loc: {...}
start: {...}
- line: 17
- column: 8
}end: {...}
- line: 17
- column: 13
}
}- name: "power"
}
} Text {...}
- type: "Text"
- start: 250
- end: 258
- raw: "\nStats: "
- data: "\nStats: "
} ExpressionTag {...}
- type: "ExpressionTag"
- start: 258
- end: 275
expression: BinaryExpression {...}
- type: "BinaryExpression"
- start: 259
- end: 274
loc: {...}
start: {...}
- line: 18
- column: 8
}end: {...}
- line: 18
- column: 23
}
}left: Identifier {...}
- type: "Identifier"
- start: 259
- end: 266
loc: {...}
start: {...}
- line: 18
- column: 8
}end: {...}
- line: 18
- column: 15
}
}- name: "agility"
}- operator: "*"
right: Identifier {...}
- type: "Identifier"
- start: 269
- end: 274
loc: {...}
start: {...}
- line: 18
- column: 18
}end: {...}
- line: 18
- column: 23
}
}- name: "power"
}
}
} Text {...}
- type: "Text"
- start: 275
- end: 277
- raw: " "
- data: " "
} RegularElement {...}
- type: "RegularElement"
- start: 277
- end: 331
- name: "button"
attributes: [...] (1)
OnDirective {...}
- start: 285
- end: 312
- type: "OnDirective"
- name: "click"
expression: Identifier {...}
- type: "Identifier"
- start: 295
- end: 311
loc: {...}
start: {...}
- line: 20
- column: 18
}end: {...}
- line: 20
- column: 34
}
}- name: "incrementAgility"
}- modifiers: []
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (1)
Text {...}
- type: "Text"
- start: 313
- end: 322
- raw: "+ Agility"
- data: "+ Agility"
}
]
}
} Text {...}
- type: "Text"
- start: 331
- end: 332
- raw: " "
- data: " "
} RegularElement {...}
- type: "RegularElement"
- start: 332
- end: 382
- name: "button"
attributes: [...] (1)
OnDirective {...}
- start: 340
- end: 365
- type: "OnDirective"
- name: "click"
expression: Identifier {...}
- type: "Identifier"
- start: 350
- end: 364
loc: {...}
start: {...}
- line: 21
- column: 18
}end: {...}
- line: 21
- column: 32
}
}- name: "incrementPower"
}- modifiers: []
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (1)
Text {...}
- type: "Text"
- start: 366
- end: 373
- raw: "+ Power"
- data: "+ Power"
}
]
}
} Text {...}
- type: "Text"
- start: 382
- end: 383
- raw: " "
- data: " "
} RegularElement {...}
- type: "RegularElement"
- start: 383
- end: 427
- name: "button"
attributes: [...] (1)
OnDirective {...}
- start: 391
- end: 409
- type: "OnDirective"
- name: "click"
expression: Identifier {...}
- type: "Identifier"
- start: 401
- end: 408
loc: {...}
start: {...}
- line: 22
- column: 18
}end: {...}
- line: 22
- column: 25
}
}- name: "levelUp"
}- modifiers: []
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (1)
Text {...}
- type: "Text"
- start: 410
- end: 418
- raw: "Level Up"
- data: "Level Up"
}
]
}
}
]
}- options: null
instance: Script {...}
- type: "Script"
- start: 0
- end: 215
- context: "default"
content: Program {...}
- type: "Program"
- start: 8
- end: 206
loc: {...}
start: {...}
- line: 1
- column: 0
}end: {...}
- line: 14
- column: 0
}
}body: [...] (5)
VariableDeclaration {...}
- type: "VariableDeclaration"
- start: 11
- end: 27
loc: {...}
start: {...}
- line: 2
- column: 2
}end: {...}
- line: 2
- column: 18
}
}declarations: [...] (1)
VariableDeclarator {...}
- type: "VariableDeclarator"
- start: 15
- end: 26
loc: {...}
start: {...}
- line: 2
- column: 6
}end: {...}
- line: 2
- column: 17
}
}id: Identifier {...}
- type: "Identifier"
- start: 15
- end: 22
loc: {...}
start: {...}
- line: 2
- column: 6
}end: {...}
- line: 2
- column: 13
}
}- name: "agility"
}init: Literal {...}
- type: "Literal"
- start: 25
- end: 26
loc: {...}
start: {...}
- line: 2
- column: 16
}end: {...}
- line: 2
- column: 17
}
}- value: 0
- raw: "0"
}
}
]- kind: "let"
} VariableDeclaration {...}
- type: "VariableDeclaration"
- start: 30
- end: 44
loc: {...}
start: {...}
- line: 3
- column: 2
}end: {...}
- line: 3
- column: 16
}
}declarations: [...] (1)
VariableDeclarator {...}
- type: "VariableDeclarator"
- start: 34
- end: 43
loc: {...}
start: {...}
- line: 3
- column: 6
}end: {...}
- line: 3
- column: 15
}
}id: Identifier {...}
- type: "Identifier"
- start: 34
- end: 39
loc: {...}
start: {...}
- line: 3
- column: 6
}end: {...}
- line: 3
- column: 11
}
}- name: "power"
}init: Literal {...}
- type: "Literal"
- start: 42
- end: 43
loc: {...}
start: {...}
- line: 3
- column: 14
}end: {...}
- line: 3
- column: 15
}
}- value: 0
- raw: "0"
}
}
]- kind: "let"
} FunctionDeclaration {...}
- type: "FunctionDeclaration"
- start: 47
- end: 96
loc: {...}
start: {...}
- line: 4
- column: 2
}end: {...}
- line: 6
- column: 3
}
}id: Identifier {...}
- type: "Identifier"
- start: 56
- end: 72
loc: {...}
start: {...}
- line: 4
- column: 11
}end: {...}
- line: 4
- column: 27
}
}- name: "incrementAgility"
}- expression: false
- generator: false
- async: false
- params: []
body: BlockStatement {...}
- type: "BlockStatement"
- start: 75
- end: 96
loc: {...}
start: {...}
- line: 4
- column: 30
}end: {...}
- line: 6
- column: 3
}
}body: [...] (1)
ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 81
- end: 92
loc: {...}
start: {...}
- line: 5
- column: 4
}end: {...}
- line: 5
- column: 15
}
}expression: UpdateExpression {...}
- type: "UpdateExpression"
- start: 81
- end: 91
loc: {...}
start: {...}
- line: 5
- column: 4
}end: {...}
- line: 5
- column: 14
}
}- operator: "++"
- prefix: false
argument: Identifier {...}
- type: "Identifier"
- start: 81
- end: 88
loc: {...}
start: {...}
- line: 5
- column: 4
}end: {...}
- line: 5
- column: 11
}
}- name: "agility"
}
}
}
]
}
} FunctionDeclaration {...}
- type: "FunctionDeclaration"
- start: 99
- end: 144
loc: {...}
start: {...}
- line: 7
- column: 2
}end: {...}
- line: 9
- column: 3
}
}id: Identifier {...}
- type: "Identifier"
- start: 108
- end: 122
loc: {...}
start: {...}
- line: 7
- column: 11
}end: {...}
- line: 7
- column: 25
}
}- name: "incrementPower"
}- expression: false
- generator: false
- async: false
- params: []
body: BlockStatement {...}
- type: "BlockStatement"
- start: 125
- end: 144
loc: {...}
start: {...}
- line: 7
- column: 28
}end: {...}
- line: 9
- column: 3
}
}body: [...] (1)
ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 131
- end: 140
loc: {...}
start: {...}
- line: 8
- column: 4
}end: {...}
- line: 8
- column: 13
}
}expression: UpdateExpression {...}
- type: "UpdateExpression"
- start: 131
- end: 139
loc: {...}
start: {...}
- line: 8
- column: 4
}end: {...}
- line: 8
- column: 12
}
}- operator: "++"
- prefix: false
argument: Identifier {...}
- type: "Identifier"
- start: 131
- end: 136
loc: {...}
start: {...}
- line: 8
- column: 4
}end: {...}
- line: 8
- column: 9
}
}- name: "power"
}
}
}
]
}
} FunctionDeclaration {...}
- type: "FunctionDeclaration"
- start: 147
- end: 205
loc: {...}
start: {...}
- line: 10
- column: 2
}end: {...}
- line: 13
- column: 3
}
}id: Identifier {...}
- type: "Identifier"
- start: 156
- end: 163
loc: {...}
start: {...}
- line: 10
- column: 11
}end: {...}
- line: 10
- column: 18
}
}- name: "levelUp"
}- expression: false
- generator: false
- async: false
- params: []
body: BlockStatement {...}
- type: "BlockStatement"
- start: 166
- end: 205
loc: {...}
start: {...}
- line: 10
- column: 21
}end: {...}
- line: 13
- column: 3
}
}body: [...] (2)
ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 172
- end: 185
loc: {...}
start: {...}
- line: 11
- column: 4
}end: {...}
- line: 11
- column: 17
}
}expression: AssignmentExpression {...}
- type: "AssignmentExpression"
- start: 172
- end: 184
loc: {...}
start: {...}
- line: 11
- column: 4
}end: {...}
- line: 11
- column: 16
}
}- operator: "+="
left: Identifier {...}
- type: "Identifier"
- start: 172
- end: 179
loc: {...}
start: {...}
- line: 11
- column: 4
}end: {...}
- line: 11
- column: 11
}
}- name: "agility"
}right: Literal {...}
- type: "Literal"
- start: 183
- end: 184
loc: {...}
start: {...}
- line: 11
- column: 15
}end: {...}
- line: 11
- column: 16
}
}- value: 5
- raw: "5"
}
}
} ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 190
- end: 201
loc: {...}
start: {...}
- line: 12
- column: 4
}end: {...}
- line: 12
- column: 15
}
}expression: AssignmentExpression {...}
- type: "AssignmentExpression"
- start: 190
- end: 200
loc: {...}
start: {...}
- line: 12
- column: 4
}end: {...}
- line: 12
- column: 14
}
}- operator: "+="
left: Identifier {...}
- type: "Identifier"
- start: 190
- end: 195
loc: {...}
start: {...}
- line: 12
- column: 4
}end: {...}
- line: 12
- column: 9
}
}- name: "power"
}right: Literal {...}
- type: "Literal"
- start: 199
- end: 200
loc: {...}
start: {...}
- line: 12
- column: 13
}end: {...}
- line: 12
- column: 14
}
}- value: 7
- raw: "7"
}
}
}
]
}
}
]- sourceType: "module"
}- attributes: []
}
}
The AST is not public API and may change at any point in time