@@ -35,7 +35,7 @@ export function attr<K extends string>(proto: Record<K, attrValue>, key: K): voi
3535 * `@controller` decorator it should not call this manually.
3636 */
3737export function initializeAttrs ( instance : HTMLElement , names ?: Iterable < string > ) : void {
38- if ( ! names ) names = getAttrNames ( instance )
38+ if ( ! names ) names = getAttrNames ( Object . getPrototypeOf ( instance ) )
3939 for ( const key of names ) {
4040 const value = ( < Record < PropertyKey , unknown > > ( < unknown > instance ) ) [ key ]
4141 const name = attrToAttributeName ( key )
@@ -73,16 +73,17 @@ export function initializeAttrs(instance: HTMLElement, names?: Iterable<string>)
7373 }
7474}
7575
76- function getAttrNames ( instance : HTMLElement ) : Set < string > {
77- let names : string [ ] = [ ]
78- let proto = Object . getPrototypeOf ( instance )
76+ function getAttrNames ( classObjectProto : Record < PropertyKey , unknown > ) : Set < string > {
77+ const names : Set < string > = new Set ( )
78+ let proto : Record < PropertyKey , unknown > | typeof HTMLElement = classObjectProto
7979
8080 while ( proto && proto !== HTMLElement ) {
81- names = names . concat ( attrs . get ( proto ) || [ ] )
81+ const attrNames = attrs . get ( < Record < PropertyKey , unknown > > proto ) || [ ]
82+ for ( const name of attrNames ) names . add ( name )
8283 proto = Object . getPrototypeOf ( proto )
8384 }
8485
85- return new Set ( names )
86+ return names
8687}
8788
8889function attrToAttributeName ( name : string ) : string {
@@ -93,9 +94,8 @@ export function defineObservedAttributes(classObject: CustomElement): void {
9394 let observed = classObject . observedAttributes || [ ]
9495 Object . defineProperty ( classObject , 'observedAttributes' , {
9596 get ( ) {
96- const attrMap = attrs . get ( classObject . prototype )
97- if ( ! attrMap ) return observed
98- return attrMap . map ( attrToAttributeName ) . concat ( observed )
97+ const attrMap = getAttrNames ( classObject . prototype )
98+ return [ ...attrMap ] . map ( attrToAttributeName ) . concat ( observed )
9999 } ,
100100 set ( attributes : string [ ] ) {
101101 observed = attributes
0 commit comments