Skip to content

Commit f8eee24

Browse files
committed
todos
1 parent 4d1bd54 commit f8eee24

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

documentation/docs/98-reference/.generated/compile-errors.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,24 @@ A `<textarea>` can have either a value attribute or (equivalently) child content
958958
`<title>` can only contain text and {tags}
959959
```
960960

961+
### trace_rune_duplicate
962+
963+
```
964+
`$track` must only be used once within the same block statement
965+
```
966+
967+
### trace_rune_invalid_argument
968+
969+
```
970+
`$track` requires a string argument for the trace name
971+
```
972+
973+
### trace_rune_invalid_location
974+
975+
```
976+
`$track` must be placed directly inside a block statement
977+
```
978+
961979
### transition_conflict
962980

963981
```

packages/svelte/messages/compile-errors/script.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ It's possible to export a snippet from a `<script module>` block, but only if it
186186
187187
Using a `$` prefix to refer to the value of a store is only possible inside `.svelte` files, where Svelte can automatically create subscriptions when a component is mounted and unsubscribe when the component is unmounted. Consider migrating to runes instead.
188188

189+
## trace_rune_duplicate
190+
191+
> `$track` must only be used once within the same block statement
192+
193+
## trace_rune_invalid_argument
194+
195+
> `$track` requires a string argument for the trace name
196+
197+
## trace_rune_invalid_location
198+
199+
> `$track` must be placed directly inside a block statement
200+
189201
## typescript_invalid_feature
190202

191203
> TypeScript language features like %feature% are not natively supported, and their use is generally discouraged. Outside of `<script>` tags, these features are not supported. For use within `<script>` tags, you will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler. If you are using `vitePreprocess`, make sure to specifically enable preprocessing script tags (`vitePreprocess({ script: true })`)

packages/svelte/src/compiler/errors.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,33 @@ export function store_invalid_subscription_module(node) {
469469
e(node, "store_invalid_subscription_module", "Cannot reference store value outside a `.svelte` file");
470470
}
471471

472+
/**
473+
* `$track` requires a string argument for the trace name
474+
* @param {null | number | NodeLike} node
475+
* @returns {never}
476+
*/
477+
export function trace_rune_invalid_argument(node) {
478+
e(node, "trace_rune_invalid_argument", "`$track` requires a string argument for the trace name");
479+
}
480+
481+
/**
482+
* `$track` must be placed directly inside a block statement
483+
* @param {null | number | NodeLike} node
484+
* @returns {never}
485+
*/
486+
export function trace_rune_invalid_location(node) {
487+
e(node, "trace_rune_invalid_location", "`$track` must be placed directly inside a block statement");
488+
}
489+
490+
/**
491+
* `$track` must only be used once within the same block statement
492+
* @param {null | number | NodeLike} node
493+
* @returns {never}
494+
*/
495+
export function trace_rune_duplicate(node) {
496+
e(node, "trace_rune_duplicate", "`$track` must only be used once within the same block statement");
497+
}
498+
472499
/**
473500
* TypeScript language features like %feature% are not natively supported, and their use is generally discouraged. Outside of `<script>` tags, these features are not supported. For use within `<script>` tags, you will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler. If you are using `vitePreprocess`, make sure to specifically enable preprocessing script tags (`vitePreprocess({ script: true })`)
474501
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/2-analyze/visitors/CallExpression.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,16 @@ export function CallExpression(node, context) {
141141
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
142142
}
143143
if (node.arguments[0].type !== 'Literal' || typeof node.arguments[0].value !== 'string') {
144-
throw new Error('TODO: $track requires a string argument');
144+
e.trace_rune_invalid_argument(node);
145145
}
146146
if (parent.type !== 'ExpressionStatement' || context.path.at(-2)?.type !== 'BlockStatement') {
147-
throw new Error('TODO: $track must be inside a block statement');
147+
e.trace_rune_invalid_location(node);
148148
}
149-
150149
if (context.state.scope.tracing) {
151-
throw new Error('TODO: $track must only be used once within the same block statement');
150+
e.trace_rune_duplicate(node);
152151
}
153152

154153
if (dev) {
155-
// TODO should we validate if tracing is already enabled in this or a parent scope?
156154
context.state.scope.tracing = node.arguments[0].value;
157155
}
158156

0 commit comments

Comments
 (0)