Skip to content

Commit 6698a34

Browse files
committed
fix errors
1 parent 74daf21 commit 6698a34

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,13 @@ Unrecognised compiler option %keypath%
573573
### props_duplicate
574574

575575
```
576-
Cannot use `%rune%` more than once
576+
Cannot use `%rune%()` more than once
577+
```
578+
579+
### props_id_invalid_placement
580+
581+
```
582+
`$props.id()` can only be affected at the top level of components as a const declaration initializer
577583
```
578584

579585
### props_illegal_name
@@ -597,7 +603,7 @@ Declaring or accessing a prop starting with `$$` is illegal (they are reserved f
597603
### props_invalid_placement
598604

599605
```
600-
`%rune%` can only be used at the top level of components as a variable declaration initializer
606+
`$props()` can only be used at the top level of components as a variable declaration initializer
601607
```
602608

603609
### reactive_declaration_cycle

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ This turned out to be buggy and unpredictable, particularly when working with de
120120
121121
## props_duplicate
122122

123-
> Cannot use `%rune%` more than once
123+
> Cannot use `%rune%()` more than once
124+
125+
## props_id_invalid_placement
126+
127+
> `$props.id()` can only be affected at the top level of components as a const declaration initializer
124128
125129
## props_illegal_name
126130

@@ -136,7 +140,7 @@ This turned out to be buggy and unpredictable, particularly when working with de
136140
137141
## props_invalid_placement
138142

139-
> `%rune%` can only be used at the top level of components as a variable declaration initializer
143+
> `$props()` can only be used at the top level of components as a variable declaration initializer
140144
141145
## reactive_declaration_cycle
142146

packages/svelte/src/compiler/errors.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,22 @@ export function module_illegal_default_export(node) {
279279
}
280280

281281
/**
282-
* Cannot use `%rune%` more than once
282+
* Cannot use `%rune%()` more than once
283283
* @param {null | number | NodeLike} node
284284
* @param {string} rune
285285
* @returns {never}
286286
*/
287287
export function props_duplicate(node, rune) {
288-
e(node, 'props_duplicate', `Cannot use \`${rune}\` more than once\nhttps://svelte.dev/e/props_duplicate`);
288+
e(node, 'props_duplicate', `Cannot use \`${rune}()\` more than once\nhttps://svelte.dev/e/props_duplicate`);
289+
}
290+
291+
/**
292+
* `$props.id()` can only be affected at the top level of components as a const declaration initializer
293+
* @param {null | number | NodeLike} node
294+
* @returns {never}
295+
*/
296+
export function props_id_invalid_placement(node) {
297+
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`);
289298
}
290299

291300
/**
@@ -316,13 +325,12 @@ export function props_invalid_pattern(node) {
316325
}
317326

318327
/**
319-
* `%rune%` can only be used at the top level of components as a variable declaration initializer
328+
* `$props()` can only be used at the top level of components as a variable declaration initializer
320329
* @param {null | number | NodeLike} node
321-
* @param {string} rune
322330
* @returns {never}
323331
*/
324-
export function props_invalid_placement(node, rune) {
325-
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`);
332+
export function props_invalid_placement(node) {
333+
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`);
326334
}
327335

328336
/**

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function CallExpression(node, context) {
6565
context.state.ast_type !== 'instance' ||
6666
context.state.scope !== context.state.analysis.instance.scope
6767
) {
68-
e.props_invalid_placement(node, rune);
68+
e.props_invalid_placement(node);
6969
}
7070

7171
if (node.arguments.length > 0) {
@@ -74,7 +74,9 @@ export function CallExpression(node, context) {
7474

7575
break;
7676

77-
case '$props.id':
77+
case '$props.id': {
78+
const grand_parent = get_parent(context.path, -2);
79+
7880
if (context.state.analysis.props_id) {
7981
e.props_duplicate(node, rune);
8082
}
@@ -83,9 +85,11 @@ export function CallExpression(node, context) {
8385
parent.type !== 'VariableDeclarator' ||
8486
parent.id.type !== 'Identifier' ||
8587
context.state.ast_type !== 'instance' ||
86-
context.state.scope !== context.state.analysis.instance.scope
88+
context.state.scope !== context.state.analysis.instance.scope ||
89+
grand_parent.type !== 'VariableDeclaration' ||
90+
grand_parent.kind !== 'const'
8791
) {
88-
e.props_invalid_placement(node, rune);
92+
e.props_id_invalid_placement(node);
8993
}
9094

9195
if (node.arguments.length > 0) {
@@ -95,6 +99,7 @@ export function CallExpression(node, context) {
9599
context.state.analysis.props_id = parent.id;
96100

97101
break;
102+
}
98103

99104
case '$state':
100105
case '$state.raw':

0 commit comments

Comments
 (0)