fix: correctly differentiate static fields before emitting `duplicate_class_field`

pull/16526/head
ComputerGuy 1 month ago
parent d82edf6b1d
commit a3fdd3d8b7

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly differentiate static fields before emitting `duplicate_class_field`

@ -57,7 +57,10 @@ export function ClassBody(node, context) {
e.state_field_duplicate(node, name);
}
const _key = (key.type === 'PrivateIdentifier' ? '#' : '') + name;
const _key =
(node.type === 'AssignmentExpression' || !node.static ? '' : '@') +
(key.type === 'PrivateIdentifier' ? '#' : '') +
name;
const field = fields.get(_key);
// if there's already a method or assigned field, error
@ -91,7 +94,10 @@ export function ClassBody(node, context) {
if (child.kind === 'constructor') {
constructor = child;
} else if (!child.computed) {
const key = (child.key.type === 'PrivateIdentifier' ? '#' : '') + get_name(child.key);
const key =
(child.static ? '@' : '') +
(child.key.type === 'PrivateIdentifier' ? '#' : '') +
get_name(child.key);
const field = fields.get(key);
if (!field) {
fields.set(key, [child.kind]);

Loading…
Cancel
Save