Create new
Bindings
Transitions
Animations
Easing
Component composition
Context API
Special elements
Module context
Debugging
Miscellaneous
App.svelte
runes
This component is in runes mode.
To disable runes mode, add the following to the top of your component:
<svelte:options runes={false} />
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
›
⌄
⌄
⌄
<script>
import { untrack } from 'svelte';
let value = $state();
let derivedArr = $state([]);
$effect.pre(() => {
if (value)
untrack(() => derivedArr.push(value))
});
function random () {
value = Math.floor(1 + Math.random() * 10)
}
</script>
<button onclick={random}>Generate Random Value</button>
<p>value: {value}</p>
<p>derivedArr: {derivedArr}</p>
resolving https://unpkg.com/svelte@5.1.13/src/internal/client/dev/console-log.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 * as $ from "svelte/internal/client";
import { untrack } from 'svelte';
function random(_, value) {
$.set(value, $.proxy(Math.floor(1 + Math.random() * 10)));
}
var root = $.template(`<button>Generate Random Value</button> <p> </p> <p> </p>`, 1);
export default function App($$anchor, $$props) {
$.push($$props, true);
let value = $.state(undefined);
let derivedArr = $.proxy([]);
$.user_pre_effect(() => {
if ($.get(value)) untrack(() => derivedArr.push($.get(value)));
});
var fragment = root();
var button = $.first_child(fragment);
button.__click = [random, value];
var p = $.sibling(button, 2);
var text = $.child(p);
$.reset(p);
var p_1 = $.sibling(p, 2);
var text_1 = $.child(p_1);
$.reset(p_1);
$.template_effect(() => {
result = svelte.compile(source, {
generate: ,
});9
1
›
/* Add a <style> tag to see the CSS output */
Root {
- css: null
- js: []
- start: 261
- end: 370
- type: "Root"
fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (6)
Text {...}
- type: "Text"
- start: 259
- end: 261
- raw: "\n\n"
- data: "\n\n"
} RegularElement {...}
- type: "RegularElement"
- start: 261
- end: 316
- name: "button"
attributes: [...] (1)
Attribute {...}
- type: "Attribute"
- start: 269
- end: 285
- name: "onclick"
value: ExpressionTag {...}
- type: "ExpressionTag"
- start: 277
- end: 285
expression: Identifier {...}
- type: "Identifier"
- start: 278
- end: 284
loc: {...}
start: {...}
- line: 17
- column: 17
}end: {...}
- line: 17
- column: 23
}
}- name: "random"
}
}
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (1)
Text {...}
- type: "Text"
- start: 286
- end: 307
- raw: "Generate Random Value"
- data: "Generate Random Value"
}
]
}
} Text {...}
- type: "Text"
- start: 316
- end: 317
- raw: " "
- data: " "
} RegularElement {...}
- type: "RegularElement"
- start: 317
- end: 338
- name: "p"
- attributes: []
fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (2)
Text {...}
- type: "Text"
- start: 320
- end: 327
- raw: "value: "
- data: "value: "
} ExpressionTag {...}
- type: "ExpressionTag"
- start: 327
- end: 334
expression: Identifier {...}
- type: "Identifier"
- start: 328
- end: 333
loc: {...}
start: {...}
- line: 18
- column: 11
}end: {...}
- line: 18
- column: 16
}
}- name: "value"
}
}
]
}
} Text {...}
- type: "Text"
- start: 338
- end: 339
- raw: " "
- data: " "
} RegularElement {...}
- type: "RegularElement"
- start: 339
- end: 370
- name: "p"
- attributes: []
fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (2)
Text {...}
- type: "Text"
- start: 342
- end: 354
- raw: "derivedArr: "
- data: "derivedArr: "
} ExpressionTag {...}
- type: "ExpressionTag"
- start: 354
- end: 366
expression: Identifier {...}
- type: "Identifier"
- start: 355
- end: 365
loc: {...}
start: {...}
- line: 19
- column: 16
}end: {...}
- line: 19
- column: 26
}
}- name: "derivedArr"
}
}
]
}
}
]
}- options: null
instance: Script {...}
- type: "Script"
- start: 0
- end: 259
- context: "default"
content: Program {...}
- type: "Program"
- start: 8
- end: 250
loc: {...}
start: {...}
- line: 1
- column: 0
}end: {...}
- line: 15
- column: 0
}
}body: [...] (5)
ImportDeclaration {...}
- type: "ImportDeclaration"
- start: 10
- end: 43
loc: {...}
start: {...}
- line: 2
- column: 1
}end: {...}
- line: 2
- column: 34
}
}specifiers: [...] (1)
ImportSpecifier {...}
- type: "ImportSpecifier"
- start: 19
- end: 26
loc: {...}
start: {...}
- line: 2
- column: 10
}end: {...}
- line: 2
- column: 17
}
}imported: Identifier {...}
- type: "Identifier"
- start: 19
- end: 26
loc: {...}
start: {...}
- line: 2
- column: 10
}end: {...}
- line: 2
- column: 17
}
}- name: "untrack"
}local: Identifier {...}
- type: "Identifier"
- start: 19
- end: 26
loc: {...}
start: {...}
- line: 2
- column: 10
}end: {...}
- line: 2
- column: 17
}
}- name: "untrack"
}
}
]source: Literal {...}
- type: "Literal"
- start: 34
- end: 42
loc: {...}
start: {...}
- line: 2
- column: 25
}end: {...}
- line: 2
- column: 33
}
}- value: "svelte"
- raw: "'svelte'"
}
} VariableDeclaration {...}
- type: "VariableDeclaration"
- start: 46
- end: 67
loc: {...}
start: {...}
- line: 4
- column: 1
}end: {...}
- line: 4
- column: 22
}
}declarations: [...] (1)
VariableDeclarator {...}
- type: "VariableDeclarator"
- start: 50
- end: 66
loc: {...}
start: {...}
- line: 4
- column: 5
}end: {...}
- line: 4
- column: 21
}
}id: Identifier {...}
- type: "Identifier"
- start: 50
- end: 55
loc: {...}
start: {...}
- line: 4
- column: 5
}end: {...}
- line: 4
- column: 10
}
}- name: "value"
}init: CallExpression {...}
- type: "CallExpression"
- start: 58
- end: 66
loc: {...}
start: {...}
- line: 4
- column: 13
}end: {...}
- line: 4
- column: 21
}
}callee: Identifier {...}
- type: "Identifier"
- start: 58
- end: 64
loc: {...}
start: {...}
- line: 4
- column: 13
}end: {...}
- line: 4
- column: 19
}
}- name: "$state"
}- arguments: []
- optional: false
}
}
]- kind: "let"
} VariableDeclaration {...}
- type: "VariableDeclaration"
- start: 69
- end: 97
loc: {...}
start: {...}
- line: 5
- column: 1
}end: {...}
- line: 5
- column: 29
}
}declarations: [...] (1)
VariableDeclarator {...}
- type: "VariableDeclarator"
- start: 73
- end: 96
loc: {...}
start: {...}
- line: 5
- column: 5
}end: {...}
- line: 5
- column: 28
}
}id: Identifier {...}
- type: "Identifier"
- start: 73
- end: 83
loc: {...}
start: {...}
- line: 5
- column: 5
}end: {...}
- line: 5
- column: 15
}
}- name: "derivedArr"
}init: CallExpression {...}
- type: "CallExpression"
- start: 86
- end: 96
loc: {...}
start: {...}
- line: 5
- column: 18
}end: {...}
- line: 5
- column: 28
}
}callee: Identifier {...}
- type: "Identifier"
- start: 86
- end: 92
loc: {...}
start: {...}
- line: 5
- column: 18
}end: {...}
- line: 5
- column: 24
}
}- name: "$state"
}arguments: [...] (1)
ArrayExpression {...}
- type: "ArrayExpression"
- start: 93
- end: 95
loc: {...}
start: {...}
- line: 5
- column: 25
}end: {...}
- line: 5
- column: 27
}
}- elements: []
}
]- optional: false
}
}
]- kind: "let"
} ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 100
- end: 178
loc: {...}
start: {...}
- line: 7
- column: 1
}end: {...}
- line: 10
- column: 4
}
}expression: CallExpression {...}
- type: "CallExpression"
- start: 100
- end: 177
loc: {...}
start: {...}
- line: 7
- column: 1
}end: {...}
- line: 10
- column: 3
}
}callee: MemberExpression {...}
- type: "MemberExpression"
- start: 100
- end: 111
loc: {...}
start: {...}
- line: 7
- column: 1
}end: {...}
- line: 7
- column: 12
}
}object: Identifier {...}
- type: "Identifier"
- start: 100
- end: 107
loc: {...}
start: {...}
- line: 7
- column: 1
}end: {...}
- line: 7
- column: 8
}
}- name: "$effect"
}property: Identifier {...}
- type: "Identifier"
- start: 108
- end: 111
loc: {...}
start: {...}
- line: 7
- column: 9
}end: {...}
- line: 7
- column: 12
}
}- name: "pre"
}- computed: false
- optional: false
}arguments: [...] (1)
ArrowFunctionExpression {...}
- type: "ArrowFunctionExpression"
- start: 112
- end: 176
loc: {...}
start: {...}
- line: 7
- column: 13
}end: {...}
- line: 10
- column: 2
}
}- id: null
- expression: false
- generator: false
- async: false
- params: []
body: BlockStatement {...}
- type: "BlockStatement"
- start: 118
- end: 176
loc: {...}
start: {...}
- line: 7
- column: 19
}end: {...}
- line: 10
- column: 2
}
}body: [...] (1)
IfStatement {...}
- type: "IfStatement"
- start: 122
- end: 173
loc: {...}
start: {...}
- line: 8
- column: 2
}end: {...}
- line: 9
- column: 40
}
}test: Identifier {...}
- type: "Identifier"
- start: 126
- end: 131
loc: {...}
start: {...}
- line: 8
- column: 6
}end: {...}
- line: 8
- column: 11
}
}- name: "value"
}consequent: ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 136
- end: 173
loc: {...}
start: {...}
- line: 9
- column: 3
}end: {...}
- line: 9
- column: 40
}
}expression: CallExpression {...}
- type: "CallExpression"
- start: 136
- end: 173
loc: {...}
start: {...}
- line: 9
- column: 3
}end: {...}
- line: 9
- column: 40
}
}callee: Identifier {...}
- type: "Identifier"
- start: 136
- end: 143
loc: {...}
start: {...}
- line: 9
- column: 3
}end: {...}
- line: 9
- column: 10
}
}- name: "untrack"
}arguments: [...] (1)
ArrowFunctionExpression {...}
- type: "ArrowFunctionExpression"
- start: 144
- end: 172
loc: {...}
start: {...}
- line: 9
- column: 11
}end: {...}
- line: 9
- column: 39
}
}- id: null
- expression: true
- generator: false
- async: false
- params: []
body: CallExpression {...}
- type: "CallExpression"
- start: 150
- end: 172
loc: {...}
start: {...}
- line: 9
- column: 17
}end: {...}
- line: 9
- column: 39
}
}callee: MemberExpression {...}
- type: "MemberExpression"
- start: 150
- end: 165
loc: {...}
start: {...}
- line: 9
- column: 17
}end: {...}
- line: 9
- column: 32
}
}object: Identifier {...}
- type: "Identifier"
- start: 150
- end: 160
loc: {...}
start: {...}
- line: 9
- column: 17
}end: {...}
- line: 9
- column: 27
}
}- name: "derivedArr"
}property: Identifier {...}
- type: "Identifier"
- start: 161
- end: 165
loc: {...}
start: {...}
- line: 9
- column: 28
}end: {...}
- line: 9
- column: 32
}
}- name: "push"
}- computed: false
- optional: false
}arguments: [...] (1)
Identifier {...}
- type: "Identifier"
- start: 166
- end: 171
loc: {...}
start: {...}
- line: 9
- column: 33
}end: {...}
- line: 9
- column: 38
}
}- name: "value"
}
]- optional: false
}
}
]- optional: false
}
}- alternate: null
}
]
}
}
]- optional: false
}
} FunctionDeclaration {...}
- type: "FunctionDeclaration"
- start: 181
- end: 249
loc: {...}
start: {...}
- line: 12
- column: 1
}end: {...}
- line: 14
- column: 2
}
}id: Identifier {...}
- type: "Identifier"
- start: 190
- end: 196
loc: {...}
start: {...}
- line: 12
- column: 10
}end: {...}
- line: 12
- column: 16
}
}- name: "random"
}- expression: false
- generator: false
- async: false
- params: []
body: BlockStatement {...}
- type: "BlockStatement"
- start: 200
- end: 249
loc: {...}
start: {...}
- line: 12
- column: 20
}end: {...}
- line: 14
- column: 2
}
}body: [...] (1)
ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 204
- end: 246
loc: {...}
start: {...}
- line: 13
- column: 2
}end: {...}
- line: 13
- column: 44
}
}expression: AssignmentExpression {...}
- type: "AssignmentExpression"
- start: 204
- end: 246
loc: {...}
start: {...}
- line: 13
- column: 2
}end: {...}
- line: 13
- column: 44
}
}- operator: "="
left: Identifier {...}
- type: "Identifier"
- start: 204
- end: 209
loc: {...}
start: {...}
- line: 13
- column: 2
}end: {...}
- line: 13
- column: 7
}
}- name: "value"
}right: CallExpression {...}
- type: "CallExpression"
- start: 212
- end: 246
loc: {...}
start: {...}
- line: 13
- column: 10
}end: {...}
- line: 13
- column: 44
}
}callee: MemberExpression {...}
- type: "MemberExpression"
- start: 212
- end: 222
loc: {...}
start: {...}
- line: 13
- column: 10
}end: {...}
- line: 13
- column: 20
}
}object: Identifier {...}
- type: "Identifier"
- start: 212
- end: 216
loc: {...}
start: {...}
- line: 13
- column: 10
}end: {...}
- line: 13
- column: 14
}
}- name: "Math"
}property: Identifier {...}
- type: "Identifier"
- start: 217
- end: 222
loc: {...}
start: {...}
- line: 13
- column: 15
}end: {...}
- line: 13
- column: 20
}
}- name: "floor"
}- computed: false
- optional: false
}arguments: [...] (1)
BinaryExpression {...}
- type: "BinaryExpression"
- start: 223
- end: 245
loc: {...}
start: {...}
- line: 13
- column: 21
}end: {...}
- line: 13
- column: 43
}
}left: Literal {...}
- type: "Literal"
- start: 223
- end: 224
loc: {...}
start: {...}
- line: 13
- column: 21
}end: {...}
- line: 13
- column: 22
}
}- value: 1
- raw: "1"
}- operator: "+"
right: BinaryExpression {...}
- type: "BinaryExpression"
- start: 227
- end: 245
loc: {...}
start: {...}
- line: 13
- column: 25
}end: {...}
- line: 13
- column: 43
}
}left: CallExpression {...}
- type: "CallExpression"
- start: 227
- end: 240
loc: {...}
start: {...}
- line: 13
- column: 25
}end: {...}
- line: 13
- column: 38
}
}callee: MemberExpression {...}
- type: "MemberExpression"
- start: 227
- end: 238
loc: {...}
start: {...}
- line: 13
- column: 25
}end: {...}
- line: 13
- column: 36
}
}object: Identifier {...}
- type: "Identifier"
- start: 227
- end: 231
loc: {...}
start: {...}
- line: 13
- column: 25
}end: {...}
- line: 13
- column: 29
}
}- name: "Math"
}property: Identifier {...}
- type: "Identifier"
- start: 232
- end: 238
loc: {...}
start: {...}
- line: 13
- column: 30
}end: {...}
- line: 13
- column: 36
}
}- name: "random"
}- computed: false
- optional: false
}- arguments: []
- optional: false
}- operator: "*"
right: Literal {...}
- type: "Literal"
- start: 243
- end: 245
loc: {...}
start: {...}
- line: 13
- column: 41
}end: {...}
- line: 13
- column: 43
}
}- value: 10
- raw: "10"
}
}
}
]- optional: false
}
}
}
]
}
}
]- sourceType: "module"
}- attributes: []
}
}
The AST is not public API and may change at any point in time