Skip to content

Commit 19f84ca

Browse files
baseballyamabenmccannRich-Harris
authored
fix: Added missing context of svelte.js for validation (#9394)
* fix * add changeset * Update .changeset/eighty-bikes-camp.md Co-authored-by: Ben McCann <[email protected]> * Update .changeset/eighty-bikes-camp.md --------- Co-authored-by: Ben McCann <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 555e8f8 commit 19f84ca

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

.changeset/eighty-bikes-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: handle private fields in `class` in `.svelte.js` files

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,28 @@ export const validation_runes_js = {
546546
},
547547
UpdateExpression(node, { state }) {
548548
validate_assignment(node, node.argument, state);
549+
},
550+
ClassBody(node, context) {
551+
/** @type {string[]} */
552+
const private_derived_state = [];
553+
554+
for (const definition of node.body) {
555+
if (
556+
definition.type === 'PropertyDefinition' &&
557+
definition.key.type === 'PrivateIdentifier' &&
558+
definition.value?.type === 'CallExpression'
559+
) {
560+
const rune = get_rune(definition.value, context.state.scope);
561+
if (rune === '$derived') {
562+
private_derived_state.push(definition.key.name);
563+
}
564+
}
565+
}
566+
567+
context.next({
568+
...context.state,
569+
private_derived_state
570+
});
549571
}
550572
};
551573

@@ -688,26 +710,5 @@ export const validation_runes = merge(validation, a11y_validators, {
688710
}
689711
}
690712
},
691-
ClassBody(node, context) {
692-
/** @type {string[]} */
693-
const private_derived_state = [];
694-
695-
for (const definition of node.body) {
696-
if (
697-
definition.type === 'PropertyDefinition' &&
698-
definition.key.type === 'PrivateIdentifier' &&
699-
definition.value?.type === 'CallExpression'
700-
) {
701-
const rune = get_rune(definition.value, context.state.scope);
702-
if (rune === '$derived') {
703-
private_derived_state.push(definition.key.name);
704-
}
705-
}
706-
}
707-
708-
context.next({
709-
...context.state,
710-
private_derived_state
711-
});
712-
}
713+
ClassBody: validation_runes_js.ClassBody
713714
});

0 commit comments

Comments
 (0)