@@ -3,7 +3,7 @@ import { undecorate } from '../../data/dataTypes.ts';
33import { type ResolvedSnippet , snip } from '../../data/snippet.ts' ;
44import { type BaseData , isWgslData , isWgslStruct , Void } from '../../data/wgslTypes.ts' ;
55import { MissingLinksError } from '../../errors.ts' ;
6- import { getMetaData , getName } from '../../shared/meta.ts' ;
6+ import { getMetaData , getName , type Externals2 } from '../../shared/meta.ts' ;
77import { $getNameForward } from '../../shared/symbols.ts' ;
88import type { ResolutionCtx } from '../../types.ts' ;
99import { applyExternals , type ExternalMap , replaceExternalsInWgsl } from '../resolve/externals.ts' ;
@@ -148,11 +148,14 @@ export function createFnCore(implementation: Implementation, fnAttribute = ''):
148148 const pluginData = getMetaData ( implementation ) ;
149149
150150 // Passing a record happens prior to version 0.9.0
151+ // Passing a function happens prior to version 0.12.0
151152 // TODO: Support for this can be removed down the line
152- const pluginExternals =
153- typeof pluginData ?. externals === 'function'
154- ? pluginData . externals ( )
155- : pluginData ?. externals ;
153+ let pluginExternals : ExternalMap | Record < string , unknown > | undefined =
154+ pluginData ?. externals2
155+ ? externals2ToExternalMap ( pluginData . externals2 )
156+ : typeof pluginData ?. externals === 'function'
157+ ? pluginData . externals ( )
158+ : pluginData ?. externals ;
156159
157160 if ( pluginExternals ) {
158161 const missing = Object . fromEntries (
@@ -220,6 +223,22 @@ export function createFnCore(implementation: Implementation, fnAttribute = ''):
220223 return core ;
221224}
222225
226+ // TODO: deslopify, document, make sure it works as intended
227+ function externals2ToExternalMap ( ext2 : Externals2 ) : ExternalMap {
228+ const result : ExternalMap = { } ;
229+ for ( const [ key , value ] of Object . entries ( ext2 ) ) {
230+ if ( typeof value === 'function' ) {
231+ Object . defineProperty ( result , key , {
232+ get : value ,
233+ enumerable : true ,
234+ } ) ;
235+ } else {
236+ result [ key ] = externals2ToExternalMap ( value ) ;
237+ }
238+ }
239+ return result ;
240+ }
241+
223242function isArgUsedInBody ( argName : string , body : string ) : boolean {
224243 return new RegExp ( `\\b${ argName } \\b` ) . test ( body ) ;
225244}
0 commit comments