@@ -38,23 +38,26 @@ For example, if you enter `*.svelte` template to listen for input events:
38
38
39
39
``` svelte
40
40
<script lang="ts">
41
- function inputHandler () {
42
- // process
43
- }
41
+ function inputHandler() {
42
+ // process
43
+ }
44
44
</script>
45
- <input on:input={inputHandler}>
45
+
46
+ <input on:input={inputHandler} />
46
47
```
47
48
48
49
Parse the following virtual script code as a script:
49
50
50
51
``` ts
51
-
52
- function inputHandler () {
53
- // process
54
- }
55
- ;function $_render1(){
56
-
57
- (inputHandler ) as ((e : ' input' extends keyof HTMLElementEventMap ? HTMLElementEventMap [' input' ] : CustomEvent <any >) => void );
52
+ function inputHandler() {
53
+ // process
54
+ }
55
+ function $_render1() {
56
+ inputHandler as (
57
+ e : " input" extends keyof HTMLElementEventMap
58
+ ? HTMLElementEventMap [" input" ]
59
+ : CustomEvent <any >,
60
+ ) => void ;
58
61
}
59
62
```
60
63
@@ -78,25 +81,24 @@ For example, when using `{#each}` and `{@const}`:
78
81
79
82
``` svelte
80
83
<script lang="ts">
81
- const array = [1, 2, 3]
84
+ const array = [1, 2, 3];
82
85
</script>
86
+
83
87
{#each array as e}
84
- {@const ee = e * 2}
85
- {ee}
88
+ {@const ee = e * 2}
89
+ {ee}
86
90
{/each}
87
91
```
88
92
89
93
Parse the following virtual script code as a script:
90
94
91
95
``` ts
92
-
93
- const array = [1 , 2 , 3 ]
94
- ;function $_render1(){
95
-
96
- Array .from (array ).forEach ((e ) => {
96
+ const array = [1 , 2 , 3 ];
97
+ function $_render1() {
98
+ Array .from (array ).forEach ((e ) => {
97
99
const ee = e * 2 ;
98
- ( ee ) ;
99
- });
100
+ ee ;
101
+ });
100
102
}
101
103
```
102
104
@@ -121,8 +123,9 @@ TypeScript's type inference is pretty good, so parsing Svelte as-is gives some w
121
123
122
124
e.g.
123
125
126
+ <!-- prettier-ignore -->
124
127
``` ts
125
- export let foo: { bar: number } | null = null
128
+ export let foo: { bar: number } | null = null ;
126
129
127
130
$ : console .log (foo && foo .bar );
128
131
// ^ never type
@@ -139,13 +142,13 @@ For example:
139
142
140
143
``` svelte
141
144
<script lang="ts">
142
- export let foo: { bar: number } | null = null
145
+ export let foo: { bar: number } | null = null;
143
146
144
- $: console.log(foo && foo.bar);
147
+ $: console.log(foo && foo.bar);
145
148
146
- $: r = foo && foo.bar;
149
+ $: r = foo && foo.bar;
147
150
148
- $: ({ bar: n } = foo || { bar: 42 });
151
+ $: ({ bar: n } = foo || { bar: 42 });
149
152
</script>
150
153
151
154
{foo && foo.bar}
@@ -154,26 +157,24 @@ $: ({ bar: n } = foo || { bar: 42 });
154
157
Parse the following virtual script code as a script:
155
158
156
159
``` ts
157
-
158
- export let foo: { bar: number } | null = null
160
+ export let foo: { bar: number } | null = null ;
159
161
160
- $ : function $_reactiveStatementScopeFunction1(){
161
- console .log (foo && foo .bar );
162
+ $ : function $_reactiveStatementScopeFunction1() {
163
+ console .log (foo && foo .bar );
162
164
}
163
165
164
- $ : let r = $_reactiveVariableScopeFunction2 ();
165
- function $_reactiveVariableScopeFunction2(){
166
- let $_tmpVar3;
167
- return ($_tmpVar3 = foo && foo .bar );
166
+ $ : let r = $_reactiveVariableScopeFunction2 ();
167
+ function $_reactiveVariableScopeFunction2() {
168
+ let $_tmpVar3;
169
+ return ($_tmpVar3 = foo && foo .bar );
168
170
}
169
171
170
- $ : let { bar : n } = $_reactiveVariableScopeFunction4 ();
171
- function $_reactiveVariableScopeFunction4(){
172
- let $_tmpVar5;
173
- return ($_tmpVar5 = foo || { bar: 42 });
172
+ $ : let { bar : n } = $_reactiveVariableScopeFunction4 ();
173
+ function $_reactiveVariableScopeFunction4() {
174
+ let $_tmpVar5;
175
+ return ($_tmpVar5 = foo || { bar: 42 });
174
176
}
175
- ;function $_render6(){
176
-
177
- (foo && foo .bar );
177
+ function $_render6() {
178
+ foo && foo .bar ;
178
179
}
179
180
```
0 commit comments