11type PropertyType = 'field' | 'getter' | 'setter' | 'method'
2- type PropertyDecorator = ( proto : object , key : PropertyKey ) => void
2+ interface PropertyDecorator {
3+ ( proto : object , key : PropertyKey , descriptor ?: PropertyDescriptor ) : void
4+ readonly static : unique symbol
5+ }
36type GetMarks = ( instance : object ) => Set < PropertyKey >
47export function createMark ( validate : ( key : PropertyKey , type : PropertyType ) => void ) : [ PropertyDecorator , GetMarks ] {
58 const marks = new WeakMap < object , Set < PropertyKey > > ( )
6- const sym = Symbol ( )
79 function get ( proto : object ) : Set < PropertyKey > {
810 if ( ! marks . has ( proto ) ) {
911 const parent = Object . getPrototypeOf ( proto )
@@ -22,13 +24,15 @@ export function createMark(validate: (key: PropertyKey, type: PropertyType) => v
2224 validate ( key , type )
2325 get ( proto ) . add ( key )
2426 }
25- marker . static = sym
27+ marker . static = Symbol ( )
2628
2729 return [
28- marker ,
30+ marker as PropertyDecorator ,
2931 ( instance : object ) : Set < PropertyKey > => {
3032 const proto = Object . getPrototypeOf ( instance )
31- for ( const key of proto . constructor [ sym ] || [ ] ) marker ( proto , key , Object . getOwnPropertyDescriptor ( proto , key ) )
33+ for ( const key of proto . constructor [ marker . static ] || [ ] ) {
34+ marker ( proto , key , Object . getOwnPropertyDescriptor ( proto , key ) )
35+ }
3236 return new Set ( get ( proto ) )
3337 }
3438 ]
0 commit comments