limit to first statement of function

pull/14290/head
Dominic Gannaway 2 years ago
parent fa941f72d8
commit c02bab8817

@ -985,7 +985,7 @@ A `<textarea>` can have either a value attribute or (equivalently) child content
### trace_rune_invalid_location
```
`$inspect.trace` must be placed directly inside a block statement
`$inspect.trace` must be placed directly inside a function and be the first statement
```
### transition_conflict

@ -196,7 +196,7 @@ Using a `$` prefix to refer to the value of a store is only possible inside `.sv
## trace_rune_invalid_location
> `$inspect.trace` must be placed directly inside a block statement
> `$inspect.trace` must be placed directly inside a function and be the first statement
## typescript_invalid_feature

@ -373,8 +373,8 @@ declare function $inspect<T extends any[]>(
declare namespace $inspect {
/**
* Traces the reactive graph of the tracking reactive context. Must be placed directly within a function body.
* Example:
* Traces the reactive graph of the tracking reactive context. Must be placed directly
* inside a function and be the first statement. Example:
*
* ```svelte
* <script>

@ -488,12 +488,12 @@ export function trace_rune_invalid_argument(node) {
}
/**
* `$inspect.trace` must be placed directly inside a block statement
* `$inspect.trace` must be placed directly inside a function and be the first statement
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function trace_rune_invalid_location(node) {
e(node, "trace_rune_invalid_location", `\`$inspect.trace\` must be placed directly inside a block statement\nhttps://svelte.dev/e/trace_rune_invalid_location`);
e(node, "trace_rune_invalid_location", `\`$inspect.trace\` must be placed directly inside a function and be the first statement\nhttps://svelte.dev/e/trace_rune_invalid_location`);
}
/**

@ -136,21 +136,24 @@ export function CallExpression(node, context) {
break;
case '$inspect.trace':
case '$inspect.trace': {
if (node.arguments.length !== 1) {
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
}
if (node.arguments[0].type !== 'Literal' || typeof node.arguments[0].value !== 'string') {
e.trace_rune_invalid_argument(node);
}
const grand_parent = context.path.at(-2);
if (
parent.type !== 'ExpressionStatement' ||
context.path.at(-2)?.type !== 'BlockStatement' ||
grand_parent?.type !== 'BlockStatement' ||
!(
context.path.at(-3)?.type === 'FunctionDeclaration' ||
context.path.at(-3)?.type === 'FunctionExpression' ||
context.path.at(-3)?.type === 'ArrowFunctionExpression'
)
) ||
grand_parent.body[0] !== parent
) {
e.trace_rune_invalid_location(node);
}
@ -163,7 +166,7 @@ export function CallExpression(node, context) {
}
break;
}
case '$state.snapshot':
if (node.arguments.length !== 1) {
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');

@ -3031,8 +3031,8 @@ declare function $inspect<T extends any[]>(
declare namespace $inspect {
/**
* Traces the reactive graph of the tracking reactive context. Must be placed directly within a function body.
* Example:
* Traces the reactive graph of the tracking reactive context. Must be placed directly
* inside a function and be the first statement. Example:
*
* ```svelte
* <script>

Loading…
Cancel
Save