unplugin-typegpu
Version:
Build plugins for TypeGPU, enabling seamless JavaScript -> WGSL transpilation and improved debugging.
10 lines • 3.46 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkG6NIIU55cjs = require('./chunk-G6NIIU55.cjs');var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);var _estreewalker = require('estree-walker');var _magicstringast = require('magic-string-ast');var _tinyest = require('tinyest');var _tinyestforwgsl = require('tinyest-for-wgsl');var _unplugin = require('unplugin');function D(c){if(c.body.type==="BlockStatement"){for(let n of c.body.body)if(n.type==="ExpressionStatement"&&_chunkG6NIIU55cjs.e.includes(n.directive))return n.directive}}function E(c){let n=structuredClone(c);return n.body.type==="BlockStatement"&&(n.body.body=n.body.body.filter(s=>!(s.type==="ExpressionStatement"&&s.directive&&_chunkG6NIIU55cjs.e.includes(s.directive)))),n}var r=_unplugin.createUnplugin.call(void 0, c=>{let n=_defu2.default.call(void 0, c,_chunkG6NIIU55cjs.a);return{name:"unplugin-typegpu",enforce:n.enforce,transform:{filter:{id:n},handler(s,p){let g={tgpuAliases:new Set(n.forceTgpuAlias?[n.forceTgpuAlias]:[]),fileId:p},k=this.parse(s,{allowReturnOutsideFunction:!0}),l=[],u=new (0, _magicstringast.MagicStringAST)(s);_estreewalker.walk.call(void 0, k,{enter(i,t,m,y){var a;let e=i;if(e.type==="ImportDeclaration"&&_chunkG6NIIU55cjs.c.call(void 0, e,g),e.type==="CallExpression"&&_chunkG6NIIU55cjs.d.call(void 0, e,g)){let o=e.arguments[0];if(o&&(o.type==="FunctionExpression"||o.type==="ArrowFunctionExpression")){let f=D(o);l.push({def:E(o),removeJsImplementation:f!=="kernel & js"}),this.skip()}}if(e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"||e.type==="FunctionDeclaration"){let o=D(e);o&&(l.push({def:E(e),name:e.type==="FunctionDeclaration"||e.type==="FunctionExpression"?(a=e.id)==null?void 0:a.name:(t==null?void 0:t.type)==="VariableDeclarator"&&t.id.type==="Identifier"?t.id.name:void 0,removeJsImplementation:o!=="kernel & js"}),this.skip())}}});for(let{def:i,name:t,removeJsImplementation:m}of l){let{params:y,body:e,externalNames:a}=_tinyestforwgsl.transpileFn.call(void 0, i),o=i.type==="FunctionDeclaration";o&&t&&s.slice(0,i.start).search(new RegExp(`(?<![\\w_.])${t}(?![\\w_])`))!==-1&&console.warn(`File ${p}: function "${t}", containing ${m?"kernel":"kernel & js"} directive, might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);let f=`{
v: ${_tinyest.FORMAT_VERSION},
ast: ${_chunkG6NIIU55cjs.b.call(void 0, {params:y,body:e,externalNames:a})},
externals: {${a.join(", ")}},
}`;u.appendLeft(i.start,`${o&&t?`const ${t} = `:""}
(($) => ((globalThis.__TYPEGPU_META__ ??= new WeakMap()).set(
$.f = (`).appendRight(i.end,`) , ${f}) && $.f))({})`),m&&u.overwriteNode(i,`() => {
throw new Error(\`${_chunkG6NIIU55cjs.f.call(void 0, t)}\`);
}`)}return _magicstringast.generateTransform.call(void 0, u,p)}}}}),B= exports.a =r,V= exports.b =r.vite,_= exports.c =r.rollup,G= exports.d =r.rolldown,L= exports.e =r.webpack,W= exports.f =r.rspack,Y= exports.g =r.esbuild,q= exports.h =r.farm,z= exports.i =_chunkG6NIIU55cjs.g;exports.a = B; exports.b = V; exports.c = _; exports.d = G; exports.e = L; exports.f = W; exports.g = Y; exports.h = q; exports.i = z;
//# sourceMappingURL=chunk-LI2BURW4.cjs.map