fix: Added missing context of `svelte.js` for validation (#9394)

* fix

* add changeset

* Update .changeset/eighty-bikes-camp.md

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>

* Update .changeset/eighty-bikes-camp.md

---------

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Rich Harris <hello@rich-harris.dev>
pull/9431/head
Yuichiro Yamashita 1 year ago committed by GitHub
parent 555e8f845f
commit 19f84ca730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: handle private fields in `class` in `.svelte.js` files

@ -546,6 +546,28 @@ export const validation_runes_js = {
},
UpdateExpression(node, { state }) {
validate_assignment(node, node.argument, state);
},
ClassBody(node, context) {
/** @type {string[]} */
const private_derived_state = [];
for (const definition of node.body) {
if (
definition.type === 'PropertyDefinition' &&
definition.key.type === 'PrivateIdentifier' &&
definition.value?.type === 'CallExpression'
) {
const rune = get_rune(definition.value, context.state.scope);
if (rune === '$derived') {
private_derived_state.push(definition.key.name);
}
}
}
context.next({
...context.state,
private_derived_state
});
}
};
@ -688,26 +710,5 @@ export const validation_runes = merge(validation, a11y_validators, {
}
}
},
ClassBody(node, context) {
/** @type {string[]} */
const private_derived_state = [];
for (const definition of node.body) {
if (
definition.type === 'PropertyDefinition' &&
definition.key.type === 'PrivateIdentifier' &&
definition.value?.type === 'CallExpression'
) {
const rune = get_rune(definition.value, context.state.scope);
if (rune === '$derived') {
private_derived_state.push(definition.key.name);
}
}
}
context.next({
...context.state,
private_derived_state
});
}
ClassBody: validation_runes_js.ClassBody
});

Loading…
Cancel
Save