Skip to content

Commit

Permalink
chore: DRY out assignment validation (#15360)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Feb 24, 2025
1 parent 51337f2 commit 5f3b4d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
is_text_attribute,
object
} from '../../../utils/ast.js';
import { validate_no_const_assignment } from './shared/utils.js';
import { validate_assignment } from './shared/utils.js';
import * as e from '../../../errors.js';
import * as w from '../../../warnings.js';
import { binding_properties } from '../../bindings.js';
Expand Down Expand Up @@ -158,7 +158,7 @@ export function BindDirective(node, context) {
return;
}

validate_no_const_assignment(node, node.expression, context.state.scope, true);
validate_assignment(node, node.expression, context.state);

const assignee = node.expression;
const left = object(assignee);
Expand All @@ -184,14 +184,6 @@ export function BindDirective(node, context) {
) {
e.bind_invalid_value(node.expression);
}

if (context.state.analysis.runes && binding?.kind === 'each') {
e.each_item_invalid_assignment(node);
}

if (binding?.kind === 'snippet') {
e.snippet_parameter_assignment(node);
}
}

if (node.name === 'group') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import * as b from '../../../../utils/builders.js';
import { get_rune } from '../../../scope.js';

/**
* @param {AssignmentExpression | UpdateExpression} node
* @param {AssignmentExpression | UpdateExpression | AST.BindDirective} node
* @param {Pattern | Expression} argument
* @param {AnalysisState} state
*/
export function validate_assignment(node, argument, state) {
validate_no_const_assignment(node, argument, state.scope, false);
validate_no_const_assignment(node, argument, state.scope, node.type === 'BindDirective');

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

0 comments on commit 5f3b4d5

Please sign in to comment.