pull/15185/head
adiguba 2 years ago
parent 74daf21e48
commit 6698a34917

@ -573,7 +573,13 @@ Unrecognised compiler option %keypath%
### props_duplicate
```
Cannot use `%rune%` more than once
Cannot use `%rune%()` more than once
```
### props_id_invalid_placement
```
`$props.id()` can only be affected at the top level of components as a const declaration initializer
```
### props_illegal_name
@ -597,7 +603,7 @@ Declaring or accessing a prop starting with `$$` is illegal (they are reserved f
### props_invalid_placement
```
`%rune%` can only be used at the top level of components as a variable declaration initializer
`$props()` can only be used at the top level of components as a variable declaration initializer
```
### reactive_declaration_cycle

@ -120,7 +120,11 @@ This turned out to be buggy and unpredictable, particularly when working with de
## props_duplicate
> Cannot use `%rune%` more than once
> Cannot use `%rune%()` more than once
## props_id_invalid_placement
> `$props.id()` can only be affected at the top level of components as a const declaration initializer
## props_illegal_name
@ -136,7 +140,7 @@ This turned out to be buggy and unpredictable, particularly when working with de
## props_invalid_placement
> `%rune%` can only be used at the top level of components as a variable declaration initializer
> `$props()` can only be used at the top level of components as a variable declaration initializer
## reactive_declaration_cycle

@ -279,13 +279,22 @@ export function module_illegal_default_export(node) {
}
/**
* Cannot use `%rune%` more than once
* Cannot use `%rune%()` more than once
* @param {null | number | NodeLike} node
* @param {string} rune
* @returns {never}
*/
export function props_duplicate(node, rune) {
e(node, 'props_duplicate', `Cannot use \`${rune}\` more than once\nhttps://svelte.dev/e/props_duplicate`);
e(node, 'props_duplicate', `Cannot use \`${rune}()\` more than once\nhttps://svelte.dev/e/props_duplicate`);
}
/**
* `$props.id()` can only be affected at the top level of components as a const declaration initializer
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function props_id_invalid_placement(node) {
e(node, 'props_id_invalid_placement', `\`$props.id()\` can only be affected at the top level of components as a const declaration initializer\nhttps://svelte.dev/e/props_id_invalid_placement`);
}
/**
@ -316,13 +325,12 @@ export function props_invalid_pattern(node) {
}
/**
* `%rune%` can only be used at the top level of components as a variable declaration initializer
* `$props()` can only be used at the top level of components as a variable declaration initializer
* @param {null | number | NodeLike} node
* @param {string} rune
* @returns {never}
*/
export function props_invalid_placement(node, rune) {
e(node, 'props_invalid_placement', `\`${rune}\` can only be used at the top level of components as a variable declaration initializer\nhttps://svelte.dev/e/props_invalid_placement`);
export function props_invalid_placement(node) {
e(node, 'props_invalid_placement', `\`$props()\` can only be used at the top level of components as a variable declaration initializer\nhttps://svelte.dev/e/props_invalid_placement`);
}
/**

@ -65,7 +65,7 @@ export function CallExpression(node, context) {
context.state.ast_type !== 'instance' ||
context.state.scope !== context.state.analysis.instance.scope
) {
e.props_invalid_placement(node, rune);
e.props_invalid_placement(node);
}
if (node.arguments.length > 0) {
@ -74,7 +74,9 @@ export function CallExpression(node, context) {
break;
case '$props.id':
case '$props.id': {
const grand_parent = get_parent(context.path, -2);
if (context.state.analysis.props_id) {
e.props_duplicate(node, rune);
}
@ -83,9 +85,11 @@ export function CallExpression(node, context) {
parent.type !== 'VariableDeclarator' ||
parent.id.type !== 'Identifier' ||
context.state.ast_type !== 'instance' ||
context.state.scope !== context.state.analysis.instance.scope
context.state.scope !== context.state.analysis.instance.scope ||
grand_parent.type !== 'VariableDeclaration' ||
grand_parent.kind !== 'const'
) {
e.props_invalid_placement(node, rune);
e.props_id_invalid_placement(node);
}
if (node.arguments.length > 0) {
@ -95,6 +99,7 @@ export function CallExpression(node, context) {
context.state.analysis.props_id = parent.id;
break;
}
case '$state':
case '$state.raw':

Loading…
Cancel
Save