Skip to content

Commit 5f3b4d5

Browse files
authored
chore: DRY out assignment validation (#15360)
1 parent 51337f2 commit 5f3b4d5

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
is_text_attribute,
66
object
77
} from '../../../utils/ast.js';
8-
import { validate_no_const_assignment } from './shared/utils.js';
8+
import { validate_assignment } from './shared/utils.js';
99
import * as e from '../../../errors.js';
1010
import * as w from '../../../warnings.js';
1111
import { binding_properties } from '../../bindings.js';
@@ -158,7 +158,7 @@ export function BindDirective(node, context) {
158158
return;
159159
}
160160

161-
validate_no_const_assignment(node, node.expression, context.state.scope, true);
161+
validate_assignment(node, node.expression, context.state);
162162

163163
const assignee = node.expression;
164164
const left = object(assignee);
@@ -184,14 +184,6 @@ export function BindDirective(node, context) {
184184
) {
185185
e.bind_invalid_value(node.expression);
186186
}
187-
188-
if (context.state.analysis.runes && binding?.kind === 'each') {
189-
e.each_item_invalid_assignment(node);
190-
}
191-
192-
if (binding?.kind === 'snippet') {
193-
e.snippet_parameter_assignment(node);
194-
}
195187
}
196188

197189
if (node.name === 'group') {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import * as b from '../../../../utils/builders.js';
1010
import { get_rune } from '../../../scope.js';
1111

1212
/**
13-
* @param {AssignmentExpression | UpdateExpression} node
13+
* @param {AssignmentExpression | UpdateExpression | AST.BindDirective} node
1414
* @param {Pattern | Expression} argument
1515
* @param {AnalysisState} state
1616
*/
1717
export function validate_assignment(node, argument, state) {
18-
validate_no_const_assignment(node, argument, state.scope, false);
18+
validate_no_const_assignment(node, argument, state.scope, node.type === 'BindDirective');
1919

2020
if (argument.type === 'Identifier') {
2121
const binding = state.scope.get(argument.name);

0 commit comments

Comments
 (0)