@@ -145,22 +145,55 @@ function mergeInto(obj, other, options = null) {
145145 }
146146
147147 for ( const key of Object . keys ( other ) ) {
148- if ( key . endsWith ( '__sig' ) ) {
149- if ( obj . hasOwnProperty ( key ) ) {
150- const oldsig = obj [ key ] ;
151- const newsig = other [ key ] ;
152- if ( oldsig == newsig ) {
153- warn ( `signature redefinition for: ${ key } ` ) ;
154- } else {
155- error ( `signature redefinition for: ${ key } . (old=${ oldsig } vs new=${ newsig } )` ) ;
148+ if ( isDecorator ( key ) ) {
149+ if ( key . endsWith ( '__sig' ) ) {
150+ if ( obj . hasOwnProperty ( key ) ) {
151+ const oldsig = obj [ key ] ;
152+ const newsig = other [ key ] ;
153+ if ( oldsig == newsig ) {
154+ warn ( `signature redefinition for: ${ key } ` ) ;
155+ } else {
156+ error ( `signature redefinition for: ${ key } . (old=${ oldsig } vs new=${ newsig } )` ) ;
157+ }
156158 }
157159 }
158- }
159160
160- if ( key . endsWith ( '__deps' ) ) {
161- const deps = other [ key ] ;
162- if ( ! Array . isArray ( deps ) ) {
163- error ( `JS library directive ${ key } =${ deps . toString ( ) } is of type ${ typeof deps } , but it should be an array` ) ;
161+ const index = key . lastIndexOf ( '__' ) ;
162+ const decoratorName = key . slice ( index ) ;
163+ const type = typeof other [ key ] ;
164+
165+ // Specific type checking for `__deps` which is expected to be an array
166+ // (not just any old `object`)
167+ if ( decoratorName === '__deps' ) {
168+ const deps = other [ key ] ;
169+ if ( ! Array . isArray ( deps ) ) {
170+ error ( `JS library directive ${ key } =${ deps . toString ( ) } is of type '${ type } ', but it should be an array` ) ;
171+ }
172+ for ( let dep of deps ) {
173+ if ( dep && typeof dep !== 'string' && typeof dep !== 'function' ) {
174+ error ( `__deps entries must be of type 'string' or 'function' not '${ typeof dep } ': ${ key } ` )
175+ }
176+ }
177+ } else {
178+ // General type checking for all other decorators
179+ const decoratorTypes = {
180+ '__sig' : 'string' ,
181+ '__proxy' : 'string' ,
182+ '__asm' : 'boolean' ,
183+ '__inline' : 'boolean' ,
184+ '__postset' : [ 'string' , 'function' ] ,
185+ '__docs' : 'string' ,
186+ '__nothrow' : 'boolean' ,
187+ '__noleakcheck' : 'boolean' ,
188+ '__internal' : 'boolean' ,
189+ '__user' : 'boolean' ,
190+ '__async' : 'boolean' ,
191+ '__i53abi' : 'boolean' ,
192+ } ;
193+ const expected = decoratorTypes [ decoratorName ] ;
194+ if ( type !== expected && ! expected . includes ( type ) ) {
195+ error ( `Decorator (${ key } } has wrong type. Expected '${ expected } ' not '${ type } '` ) ;
196+ }
164197 }
165198 }
166199 }
0 commit comments