Create new
Bindings
Transitions
Animations
Easing
Component composition
Context API
Special elements
Module context
Debugging
Miscellaneous
App.svelte
utf8.js
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
›
⌄
⌄
⌄
⌄
<script>
import { encodeUtf8, decodeUtf8 } from './utf8.js';
let text = '';
$: byteArr = encodeUtf8(text);
$: console.log({ arr: Uint8Array.from(byteArr) })
</script>
<style>
p {
overflow-wrap: anywhere;
}
</style>
<input type=text bind:value={text} />
<p>
{byteArr.join(', ')}
</p>
▶ { arr: Uint8Array(0) }
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';
import { encodeUtf8, decodeUtf8 } from './utf8.js';
var root = $.template(`<input type="text"> <p class="svelte-1vwubxy"> </p>`, 1);
export default function App($$anchor, $$props) {
$.push($$props, false);
const byteArr = $.mutable_state();
let text = $.mutable_state('');
$.legacy_pre_effect(() => (encodeUtf8, $.get(text)), () => {
$.set(byteArr, encodeUtf8($.get(text)));
});
$.legacy_pre_effect(() => ($.get(byteArr)), () => {
console.log({ arr: Uint8Array.from($.get(byteArr)) });
});
$.legacy_pre_effect_reset();
$.init();
var fragment = root();
var input = $.first_child(fragment);
$.remove_input_defaults(input);
var p = $.sibling(input, 2);
var text_1 = $.child(p, true);
$.reset(p);
$.template_effect(($0) => $.set_text(text_1, $0), [() => $.get(byteArr).join(', ')], $.derived_safe_equal);
$.bind_value(input, () => $.get(text), ($$value) => $.set(text, $$value));
$.append($$anchor, fragment);
result = svelte.compile(source, {
generate: ,
});9
1
2
3
4
5
›
p.svelte-1vwubxy {
overflow-wrap: anywhere;
}
Root {
css: StyleSheet {...}
- type: "StyleSheet"
- start: 174
- end: 225
- attributes: []
children: [...] (1)
Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 183
- end: 184
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 183
- end: 184
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "p"
- start: 183
- end: 184
}
]- start: 183
- end: 184
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 185
- end: 216
children: [...] (1)
Declaration {...}
- type: "Declaration"
- start: 189
- end: 212
- property: "overflow-wrap"
- value: "anywhere"
}
]
}- start: 183
- end: 216
}
]content: {...}
- start: 181
- end: 217
- styles: "\n\tp {\n\t\toverflow-wrap: anywhere;\n\t}\n"
- comment: null
}
}- js: []
- start: 174
- end: 295
- type: "Root"
fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (5)
Text {...}
- type: "Text"
- start: 172
- end: 174
- raw: "\n\n"
- data: "\n\n"
} Text {...}
- type: "Text"
- start: 225
- end: 227
- raw: "\n\n"
- data: "\n\n"
} RegularElement {...}
- type: "RegularElement"
- start: 227
- end: 264
- name: "input"
attributes: [...] (2)
Attribute {...}
- type: "Attribute"
- start: 234
- end: 243
- name: "type"
value: [...] (1)
Text {...}
- start: 239
- end: 243
- type: "Text"
- raw: "text"
- data: "text"
}
]
} BindDirective {...}
- start: 244
- end: 261
- type: "BindDirective"
- name: "value"
expression: Identifier {...}
- type: "Identifier"
- start: 256
- end: 260
loc: {...}
start: {...}
- line: 15
- column: 29
}end: {...}
- line: 15
- column: 33
}
}- name: "text"
}- modifiers: []
}
]fragment: Fragment {...}
- type: "Fragment"
- nodes: []
}
} Text {...}
- type: "Text"
- start: 264
- end: 265
- raw: " "
- data: " "
} RegularElement {...}
- type: "RegularElement"
- start: 265
- end: 295
- name: "p"
attributes: [...] (1)
Attribute {...}
- type: "Attribute"
- start: -1
- end: -1
- name: "class"
value: [...] (1)
Text {...}
- type: "Text"
- data: ""
- raw: ""
- start: -1
- end: -1
}
]
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (3)
Text {...}
- type: "Text"
- start: 268
- end: 270
- raw: "\n\t"
- data: "\n\t"
} ExpressionTag {...}
- type: "ExpressionTag"
- start: 270
- end: 290
expression: CallExpression {...}
- type: "CallExpression"
- start: 271
- end: 289
loc: {...}
start: {...}
- line: 17
- column: 2
}end: {...}
- line: 17
- column: 20
}
}callee: MemberExpression {...}
- type: "MemberExpression"
- start: 271
- end: 283
loc: {...}
start: {...}
- line: 17
- column: 2
}end: {...}
- line: 17
- column: 14
}
}object: Identifier {...}
- type: "Identifier"
- start: 271
- end: 278
loc: {...}
start: {...}
- line: 17
- column: 2
}end: {...}
- line: 17
- column: 9
}
}- name: "byteArr"
}property: Identifier {...}
- type: "Identifier"
- start: 279
- end: 283
loc: {...}
start: {...}
- line: 17
- column: 10
}end: {...}
- line: 17
- column: 14
}
}- name: "join"
}- computed: false
- optional: false
}arguments: [...] (1)
Literal {...}
- type: "Literal"
- start: 284
- end: 288
loc: {...}
start: {...}
- line: 17
- column: 15
}end: {...}
- line: 17
- column: 19
}
}- value: ", "
- raw: "', '"
}
]- optional: false
}
} Text {...}
- type: "Text"
- start: 290
- end: 291
- raw: "\n"
- data: "\n"
}
]
}
}
]
}- options: null
instance: Script {...}
- type: "Script"
- start: 0
- end: 172
- context: "default"
content: Program {...}
- type: "Program"
- start: 8
- end: 163
loc: {...}
start: {...}
- line: 1
- column: 0
}end: {...}
- line: 7
- column: 0
}
}body: [...] (4)
ImportDeclaration {...}
- type: "ImportDeclaration"
- start: 10
- end: 61
loc: {...}
start: {...}
- line: 2
- column: 1
}end: {...}
- line: 2
- column: 52
}
}specifiers: [...] (2)
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: "encodeUtf8"
}local: Identifier {...}
- type: "Identifier"
- start: 19
- end: 29
loc: {...}
start: {...}
- line: 2
- column: 10
}end: {...}
- line: 2
- column: 20
}
}- name: "encodeUtf8"
}
} ImportSpecifier {...}
- type: "ImportSpecifier"
- start: 31
- end: 41
loc: {...}
start: {...}
- line: 2
- column: 22
}end: {...}
- line: 2
- column: 32
}
}imported: Identifier {...}
- type: "Identifier"
- start: 31
- end: 41
loc: {...}
start: {...}
- line: 2
- column: 22
}end: {...}
- line: 2
- column: 32
}
}- name: "decodeUtf8"
}local: Identifier {...}
- type: "Identifier"
- start: 31
- end: 41
loc: {...}
start: {...}
- line: 2
- column: 22
}end: {...}
- line: 2
- column: 32
}
}- name: "decodeUtf8"
}
}
]source: Literal {...}
- type: "Literal"
- start: 49
- end: 60
loc: {...}
start: {...}
- line: 2
- column: 40
}end: {...}
- line: 2
- column: 51
}
}- value: "./utf8.js"
- raw: "'./utf8.js'"
}
} VariableDeclaration {...}
- type: "VariableDeclaration"
- start: 65
- end: 79
loc: {...}
start: {...}
- line: 4
- column: 1
}end: {...}
- line: 4
- column: 15
}
}declarations: [...] (1)
VariableDeclarator {...}
- type: "VariableDeclarator"
- start: 69
- end: 78
loc: {...}
start: {...}
- line: 4
- column: 5
}end: {...}
- line: 4
- column: 14
}
}id: Identifier {...}
- type: "Identifier"
- start: 69
- end: 73
loc: {...}
start: {...}
- line: 4
- column: 5
}end: {...}
- line: 4
- column: 9
}
}- name: "text"
}init: Literal {...}
- type: "Literal"
- start: 76
- end: 78
loc: {...}
start: {...}
- line: 4
- column: 12
}end: {...}
- line: 4
- column: 14
}
}- value: ""
- raw: "''"
}
}
]- kind: "let"
} LabeledStatement {...}
- type: "LabeledStatement"
- start: 81
- end: 111
loc: {...}
start: {...}
- line: 5
- column: 1
}end: {...}
- line: 5
- column: 31
}
}body: ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 84
- end: 111
loc: {...}
start: {...}
- line: 5
- column: 4
}end: {...}
- line: 5
- column: 31
}
}expression: AssignmentExpression {...}
- type: "AssignmentExpression"
- start: 84
- end: 110
loc: {...}
start: {...}
- line: 5
- column: 4
}end: {...}
- line: 5
- column: 30
}
}- operator: "="
left: Identifier {...}
- type: "Identifier"
- start: 84
- end: 91
loc: {...}
start: {...}
- line: 5
- column: 4
}end: {...}
- line: 5
- column: 11
}
}- name: "byteArr"
}right: CallExpression {...}
- type: "CallExpression"
- start: 94
- end: 110
loc: {...}
start: {...}
- line: 5
- column: 14
}end: {...}
- line: 5
- column: 30
}
}callee: Identifier {...}
- type: "Identifier"
- start: 94
- end: 104
loc: {...}
start: {...}
- line: 5
- column: 14
}end: {...}
- line: 5
- column: 24
}
}- name: "encodeUtf8"
}arguments: [...] (1)
Identifier {...}
- type: "Identifier"
- start: 105
- end: 109
loc: {...}
start: {...}
- line: 5
- column: 25
}end: {...}
- line: 5
- column: 29
}
}- name: "text"
}
]- optional: false
}
}
}label: Identifier {...}
- type: "Identifier"
- start: 81
- end: 82
loc: {...}
start: {...}
- line: 5
- column: 1
}end: {...}
- line: 5
- column: 2
}
}- name: "$"
}
} LabeledStatement {...}
- type: "LabeledStatement"
- start: 113
- end: 162
loc: {...}
start: {...}
- line: 6
- column: 1
}end: {...}
- line: 6
- column: 50
}
}body: ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 116
- end: 162
loc: {...}
start: {...}
- line: 6
- column: 4
}end: {...}
- line: 6
- column: 50
}
}expression: CallExpression {...}
- type: "CallExpression"
- start: 116
- end: 162
loc: {...}
start: {...}
- line: 6
- column: 4
}end: {...}
- line: 6
- column: 50
}
}callee: MemberExpression {...}
- type: "MemberExpression"
- start: 116
- end: 127
loc: {...}
start: {...}
- line: 6
- column: 4
}end: {...}
- line: 6
- column: 15
}
}object: Identifier {...}
- type: "Identifier"
- start: 116
- end: 123
loc: {...}
start: {...}
- line: 6
- column: 4
}end: {...}
- line: 6
- column: 11
}
}- name: "console"
}property: Identifier {...}
- type: "Identifier"
- start: 124
- end: 127
loc: {...}
start: {...}
- line: 6
- column: 12
}end: {...}
- line: 6
- column: 15
}
}- name: "log"
}- computed: false
- optional: false
}arguments: [...] (1)
ObjectExpression {...}
- type: "ObjectExpression"
- start: 128
- end: 161
loc: {...}
start: {...}
- line: 6
- column: 16
}end: {...}
- line: 6
- column: 49
}
}properties: [...] (1)
Property {...}
- type: "Property"
- start: 130
- end: 159
loc: {...}
start: {...}
- line: 6
- column: 18
}end: {...}
- line: 6
- column: 47
}
}- method: false
- shorthand: false
- computed: false
key: Identifier {...}
- type: "Identifier"
- start: 130
- end: 133
loc: {...}
start: {...}
- line: 6
- column: 18
}end: {...}
- line: 6
- column: 21
}
}- name: "arr"
}value: CallExpression {...}
- type: "CallExpression"
- start: 135
- end: 159
loc: {...}
start: {...}
- line: 6
- column: 23
}end: {...}
- line: 6
- column: 47
}
}callee: MemberExpression {...}
- type: "MemberExpression"
- start: 135
- end: 150
loc: {...}
start: {...}
- line: 6
- column: 23
}end: {...}
- line: 6
- column: 38
}
}object: Identifier {...}
- type: "Identifier"
- start: 135
- end: 145
loc: {...}
start: {...}
- line: 6
- column: 23
}end: {...}
- line: 6
- column: 33
}
}- name: "Uint8Array"
}property: Identifier {...}
- type: "Identifier"
- start: 146
- end: 150
loc: {...}
start: {...}
- line: 6
- column: 34
}end: {...}
- line: 6
- column: 38
}
}- name: "from"
}- computed: false
- optional: false
}arguments: [...] (1)
Identifier {...}
- type: "Identifier"
- start: 151
- end: 158
loc: {...}
start: {...}
- line: 6
- column: 39
}end: {...}
- line: 6
- column: 46
}
}- name: "byteArr"
}
]- optional: false
}- kind: "init"
}
]
}
]- optional: false
}
}label: Identifier {...}
- type: "Identifier"
- start: 113
- end: 114
loc: {...}
start: {...}
- line: 6
- column: 1
}end: {...}
- line: 6
- column: 2
}
}- name: "$"
}
}
]- sourceType: "module"
}- attributes: []
}
}
The AST is not public API and may change at any point in time