@@ -936,6 +936,16 @@ export type PropNode =
936936 | t . StaticBlock ;
937937export type PropPath = NodePath < PropNode > ;
938938
939+ function isNameOrLength ( { key, computed } : t . ClassProperty ) {
940+ if ( key . type === "Identifier" ) {
941+ return ! computed && ( key . name === "name" || key . name === "length" ) ;
942+ }
943+ if ( key . type === "StringLiteral" ) {
944+ return key . value === "name" || key . value === "length" ;
945+ }
946+ return false ;
947+ }
948+
939949export function buildFieldsInitNodes (
940950 ref : t . Identifier ,
941951 superRef : t . Expression | undefined ,
@@ -1019,10 +1029,19 @@ export function buildFieldsInitNodes(
10191029 ) ;
10201030 break ;
10211031 case isStatic && isPublic && isField && setPublicClassFields :
1022- needsClassRef = true ;
1032+ // Functions always have non-writable .name and .length properties,
1033+ // so we must always use [[Define]] for them.
1034+ // It might still be possible to a computed static fields whose resulting
1035+ // key is "name" or "length", but the assumption is telling us that it's
1036+ // not going to happen.
10231037 // @ts -expect-error checked in switch
1024- staticNodes . push ( buildPublicFieldInitLoose ( t . cloneNode ( ref ) , prop ) ) ;
1025- break ;
1038+ if ( ! isNameOrLength ( prop . node ) ) {
1039+ needsClassRef = true ;
1040+ // @ts -expect-error checked in switch
1041+ staticNodes . push ( buildPublicFieldInitLoose ( t . cloneNode ( ref ) , prop ) ) ;
1042+ break ;
1043+ }
1044+ // falls through
10261045 case isStatic && isPublic && isField && ! setPublicClassFields :
10271046 needsClassRef = true ;
10281047 staticNodes . push (
0 commit comments