unplugin-typegpu
Version:
Build plugins for TypeGPU, enabling seamless JavaScript -> WGSL transpilation and improved debugging.
6 lines • 3.35 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunk4DTTWQTWcjs = require('./chunk-4DTTWQTW.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 O(o){if(o.body.type==="BlockStatement"){for(let e of o.body.body)if(e.type==="ExpressionStatement"&&e.directive===_chunk4DTTWQTWcjs.f)return!0}return!1}function h(o){let e=structuredClone(o);return e.body.type==="BlockStatement"&&(e.body.body=e.body.body.filter(i=>!(i.type==="ExpressionStatement"&&i.directive===_chunk4DTTWQTWcjs.f))),e}function I(o,e,i){o.prependLeft(e.start,"(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(e.end,`), ${i}) && $.f)({}))`)}function M(o,e,i){o.prependLeft(e.start,"((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(e.end,`, "${i}"))`)}var s=_unplugin.createUnplugin.call(void 0, o=>{let e=_defu2.default.call(void 0, o,_chunk4DTTWQTWcjs.a);return{name:"unplugin-typegpu",enforce:e.enforce,transform:{filter:{id:e},handler(i,l){let u={tgpuAliases:new Set(e.forceTgpuAlias?[e.forceTgpuAlias]:[]),fileId:l,autoNamingEnabled:e.autoNamingEnabled},w=this.parse(i,{allowReturnOutsideFunction:!0}),f=[],c=new (0, _magicstringast.MagicStringAST)(i);_estreewalker.walk.call(void 0, w,{enter(a,t,m,g){var p;let n=a;if(_chunk4DTTWQTWcjs.e.call(void 0, u,n,(r,N)=>{M(c,r,N)}),n.type==="ImportDeclaration"&&_chunk4DTTWQTWcjs.c.call(void 0, n,u),n.type==="CallExpression"&&_chunk4DTTWQTWcjs.d.call(void 0, n,u)){let r=n.arguments[0];r&&(r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression")&&(f.push({def:h(r)}),this.skip())}(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression"||n.type==="FunctionDeclaration")&&O(n)&&(f.push({def:h(n),name:n.type==="FunctionDeclaration"||n.type==="FunctionExpression"?(p=n.id)==null?void 0:p.name:(t==null?void 0:t.type)==="VariableDeclarator"&&t.id.type==="Identifier"?t.id.name:void 0}),this.skip())}});for(let{def:a,name:t}of f){let{params:m,body:g,externalNames:n}=_tinyestforwgsl.transpileFn.call(void 0, a),p=a.type==="FunctionDeclaration";p&&t&&i.slice(0,a.start).search(new RegExp(`(?<![\\w_.])${t}(?![\\w_])`))!==-1&&console.warn(`File ${l}: function "${t}" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);let r=`{
v: ${_tinyest.FORMAT_VERSION},
ast: ${_chunk4DTTWQTWcjs.b.call(void 0, {params:m,body:g,externalNames:n})},
externals: {${n.join(", ")}},
}`;I(c,a,r),p&&t&&c.prependLeft(a.start,`const ${t} = `)}return _magicstringast.generateTransform.call(void 0, c,l)}}}}),V= exports.a =s,Y= exports.b =s.vite,j= exports.c =s.rollup,J= exports.d =s.rolldown,W= exports.e =s.webpack,q= exports.f =s.rspack,z= exports.g =s.esbuild,H= exports.h =s.farm,Q= exports.i =_chunk4DTTWQTWcjs.g;exports.a = V; exports.b = Y; exports.c = j; exports.d = J; exports.e = W; exports.f = q; exports.g = z; exports.h = H; exports.i = Q;
//# sourceMappingURL=chunk-XXTHHPRC.cjs.map