Skip to content

Commit e9ab932

Browse files
committed
relax const requirement, validate assignments instead
1 parent 7b8b095 commit e9ab932

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @import { ArrowFunctionExpression, CallExpression, Expression, FunctionDeclaration, FunctionExpression, Identifier, VariableDeclarator } from 'estree' */
2-
/** @import { AST } from '#compiler' */
2+
/** @import { AST, Binding } from '#compiler' */
33
/** @import { Context } from '../types' */
44
import { get_rune } from '../../scope.js';
55
import * as e from '../../../errors.js';
@@ -86,8 +86,7 @@ export function CallExpression(node, context) {
8686
parent.id.type !== 'Identifier' ||
8787
context.state.ast_type !== 'instance' ||
8888
context.state.scope !== context.state.analysis.instance.scope ||
89-
grand_parent.type !== 'VariableDeclaration' ||
90-
grand_parent.kind !== 'const'
89+
grand_parent.type !== 'VariableDeclaration'
9190
) {
9291
e.props_id_invalid_placement(node);
9392
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export function validate_assignment(node, argument, state) {
2525
e.constant_assignment(node, 'derived state');
2626
}
2727

28+
if (binding?.node === state.analysis.props_id) {
29+
e.constant_assignment(node, '$props.id()');
30+
}
31+
2832
if (binding?.kind === 'each') {
2933
e.each_item_invalid_assignment(node);
3034
}

0 commit comments

Comments
 (0)