Skip to content

Commit 1b0fd52

Browse files
committed
move validation to visitor
1 parent 68a3dfd commit 1b0fd52

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { create_attribute, create_expression_metadata } from '../../nodes.js';
1313
import { get_attribute_expression, is_expression_attribute } from '../../../utils/ast.js';
1414
import { closing_tag_omitted } from '../../../../html-tree-validation.js';
1515
import { list } from '../../../utils/string.js';
16-
import { parse_expression_at } from '../acorn.js';
1716

1817
const regex_invalid_unquoted_attribute_value = /^(\/>|[\s"'=<>`])/;
1918
const regex_closing_textarea_tag = /^<\/textarea(\s[^>]*)?>/i;
@@ -526,21 +525,6 @@ function read_attribute(parser) {
526525
}
527526

528527
value = read_attribute_value(parser);
529-
530-
// bind can use a getter/setter pair {a, b}, so the attribute parsing above will capture
531-
// a SequenceExpression. To ensure this is handled correctly, we use wrap the expression
532-
// again in square brackets and parse it again. This should ensure it's an ArrayExpression
533-
// with two elements and if not we can throw an appropiate error
534-
if (
535-
name.startsWith('bind:') &&
536-
!Array.isArray(value) &&
537-
value.expression.type === 'SequenceExpression'
538-
) {
539-
if (value.expression.expressions.length !== 2) {
540-
e.invalid_bind_directive(value);
541-
}
542-
}
543-
544528
end = parser.index;
545529
} else if (parser.match_regex(regex_starts_with_quote_characters)) {
546530
e.expected_token(parser.index, '=');

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ export function BindDirective(node, context) {
129129
if (node.name === 'group') {
130130
e.bind_group_invalid_expression(node);
131131
}
132+
133+
if (node.expression.expressions.length !== 2) {
134+
e.invalid_bind_directive(node);
135+
}
136+
132137
return;
133138
}
134139

0 commit comments

Comments
 (0)