UNPKG

unplugin-typegpu

Version:

Build plugins for TypeGPU, enabling seamless JavaScript -> WGSL transpilation and improved debugging.

7 lines 3.49 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkDEVVEJF4cjs = require('./chunk-DEVVEJF4.cjs');var _unplugin = require('unplugin');var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);var _magicstringast = require('magic-string-ast');var _estreewalker = require('estree-walker');var _tinyestforwgsl = require('tinyest-for-wgsl');var _tinyest = require('tinyest');function C(o){if(o.body.type==="BlockStatement"){for(let e of o.body.body)if(e.type==="ExpressionStatement"&&e.directive===_chunkDEVVEJF4cjs.g)return!0}return!1}function S(o){let e=structuredClone(o);return e.body.type==="BlockStatement"&&(e.body.body=e.body.body.filter(r=>!(r.type==="ExpressionStatement"&&r.directive===_chunkDEVVEJF4cjs.g))),e}function D(o,e,r){o.prependLeft(e.start,"(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(e.end,`), ${r}) && $.f)({}))`)}function O(o,e,r){o.prependLeft(e.start,"((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(e.end,`, "${r}"))`)}var f=o=>{let e=_defu2.default.call(void 0, o,_chunkDEVVEJF4cjs.a);return{name:"unplugin-typegpu",enforce:e.enforce,transform:{filter:e.earlyPruning?{id:e,code:_chunkDEVVEJF4cjs.h}:{id:e},handler(r,p){let m={tgpuAliases:new Set(e.forceTgpuAlias?[e.forceTgpuAlias]:[]),fileId:p,autoNamingEnabled:e.autoNamingEnabled},x;try{x=this.parse(r,{lang:"ts",allowReturnOutsideFunction:!0})}catch(n){console.warn(`[unplugin-typegpu] Failed to parse ${p}. Cause: ${typeof n=="object"&&n&&"message"in n?n.message:n}`);return}let d=[],l=new (0, _magicstringast.MagicStringAST)(r);_estreewalker.walk.call(void 0, x,{enter(n,i,y,b){let t=n,u=i;if(_chunkDEVVEJF4cjs.f.call(void 0, m,t,(s,c)=>{O(l,s,c)}),t.type==="ImportDeclaration"&&_chunkDEVVEJF4cjs.c.call(void 0, t,m),t.type==="CallExpression"&&_chunkDEVVEJF4cjs.d.call(void 0, t,m)){let s=t.arguments[0];s&&(s.type==="FunctionExpression"||s.type==="ArrowFunctionExpression")&&(d.push({def:S(s)}),this.skip())}(t.type==="ArrowFunctionExpression"||t.type==="FunctionExpression"||t.type==="FunctionDeclaration")&&C(t)&&(d.push({def:S(t),name:_chunkDEVVEJF4cjs.e.call(void 0, t,u)}),this.skip())}});for(let{def:n,name:i}of d){let{params:y,body:b,externalNames:t}=_tinyestforwgsl.transpileFn.call(void 0, n),u=n.type==="FunctionDeclaration";u&&i&&r.slice(0,n.start).search(new RegExp(`(?<![\\w_.])${i}(?![\\w_])`))!==-1&&console.warn(`File ${p}: function "${i}" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);let s=`{ v: ${_tinyest.FORMAT_VERSION}, name: ${i?`"${i}"`:"undefined"}, ast: ${_chunkDEVVEJF4cjs.b.call(void 0, {params:y,body:b,externalNames:t})}, externals: () => ({${t.map(c=>c==="this"?'"this": this':c).join(", ")}}), }`;D(l,n,s),u&&i&&l.prependLeft(n.start,`const ${i} = `)}return _magicstringast.generateTransform.call(void 0, l,p)}}}};var I=f;var a=_unplugin.createUnplugin.call(void 0, f),Q= exports.b =a,X= exports.c =a.vite,Z= exports.d =a.rollup,ee= exports.e =a.rolldown,te= exports.f =a.webpack,ne= exports.g =a.rspack,oe= exports.h =a.esbuild,re= exports.i =a.farm;exports.a = I; exports.b = Q; exports.c = X; exports.d = Z; exports.e = ee; exports.f = te; exports.g = ne; exports.h = oe; exports.i = re; //# sourceMappingURL=chunk-LJXNN2RM.cjs.map