unplugin-typegpu 0.1.0-alpha.7 → 0.1.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.cjs +1 -1
- package/babel.cjs.map +1 -1
- package/babel.d.cts +2 -2
- package/babel.d.ts +2 -2
- package/babel.js +1 -1
- package/chunk-D2NWA2J7.js +2 -0
- package/chunk-D2NWA2J7.js.map +1 -0
- package/chunk-IA2CUGWD.cjs +2 -0
- package/chunk-IA2CUGWD.cjs.map +1 -0
- package/chunk-JKPGDPK3.js +2 -0
- package/chunk-JKPGDPK3.js.map +1 -0
- package/chunk-TCJABTWK.cjs +2 -0
- package/chunk-TCJABTWK.cjs.map +1 -0
- package/esbuild.cjs +1 -1
- package/esbuild.cjs.map +1 -1
- package/esbuild.js +1 -1
- package/esbuild.js.map +1 -1
- package/farm.cjs +1 -1
- package/farm.cjs.map +1 -1
- package/farm.js +1 -1
- package/farm.js.map +1 -1
- package/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.js +1 -1
- package/package.json +5 -2
- package/rolldown.cjs +1 -1
- package/rolldown.cjs.map +1 -1
- package/rolldown.js +1 -1
- package/rolldown.js.map +1 -1
- package/rollup.cjs +1 -1
- package/rollup.cjs.map +1 -1
- package/rollup.js +1 -1
- package/rollup.js.map +1 -1
- package/rspack.cjs +1 -1
- package/rspack.cjs.map +1 -1
- package/rspack.js +1 -1
- package/rspack.js.map +1 -1
- package/vite.cjs +1 -1
- package/vite.cjs.map +1 -1
- package/vite.js +1 -1
- package/vite.js.map +1 -1
- package/webpack.cjs +1 -1
- package/webpack.cjs.map +1 -1
- package/webpack.js +1 -1
- package/webpack.js.map +1 -1
- package/chunk-3NAE3BLV.js +0 -2
- package/chunk-3NAE3BLV.js.map +0 -1
- package/chunk-4AAFAGPC.cjs +0 -2
- package/chunk-4AAFAGPC.cjs.map +0 -1
- package/chunk-EBLN5KE7.js +0 -2
- package/chunk-EBLN5KE7.js.map +0 -1
- package/chunk-KPVZYMM6.cjs +0 -2
- package/chunk-KPVZYMM6.cjs.map +0 -1
package/babel.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkTCJABTWKcjs = require('./chunk-TCJABTWK.cjs');exports.default = _chunkTCJABTWKcjs.f;
|
|
2
2
|
//# sourceMappingURL=babel.cjs.map
|
package/babel.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/babel.cjs"],"names":[],"mappings":"AAAA,iIAAwC,sCAAqB","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/babel.cjs"}
|
package/babel.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _babel_traverse from '@babel/traverse';
|
|
2
|
-
import * as
|
|
2
|
+
import * as babel from '@babel/types';
|
|
3
3
|
|
|
4
4
|
declare function export_default(): {
|
|
5
5
|
visitor: {
|
|
6
|
-
Program(this:
|
|
6
|
+
Program(this: babel.Node, path: _babel_traverse.NodePath<babel.Program>, state: babel.Node): void;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
9
|
|
package/babel.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _babel_traverse from '@babel/traverse';
|
|
2
|
-
import * as
|
|
2
|
+
import * as babel from '@babel/types';
|
|
3
3
|
|
|
4
4
|
declare function export_default(): {
|
|
5
5
|
visitor: {
|
|
6
|
-
Program(this:
|
|
6
|
+
Program(this: babel.Node, path: _babel_traverse.NodePath<babel.Program>, state: babel.Node): void;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
9
|
|
package/babel.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{f as a}from"./chunk-D2NWA2J7.js";export{a as default};
|
|
2
2
|
//# sourceMappingURL=babel.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import*as m from"@babel/standalone";import{transpileFn as k}from"tinyest-for-wgsl";function f(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function y(e,n){let t="",r=n;for(;;)if(r.type==="MemberExpression"){if(r.property.type!=="Identifier")break;t=t?`${r.property.name}.${t}`:r.property.name,r=r.object}else if(r.type==="Identifier"){t=t?`${r.name}.${t}`:r.name;break}else break;return e.tgpuAliases.has(t)}var A=/import.*from\s*['"]typegpu.*['"]/,D=/import\s*\(\s*['"]\s*typegpu.*['"]/,F=/require\s*\(\s*['"]\s*typegpu.*['"]\s*\)/;function b(e,n,t){if(t&&!(e!=null&&e.include)){if(!A.test(t)&&!F.test(t)&&!D.test(t))return!0}else if(e!=null&&e.include&&e.include!=="all"&&(!n||!e.include.some(r=>r.test(n))))return!0;return!1}function x(e,n){if(e.source.value==="typegpu")for(let t of e.specifiers)t.type==="ImportDefaultSpecifier"||t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&t.imported.name==="tgpu"?n.tgpuAliases.add(t.local.name):t.type==="ImportNamespaceSpecifier"&&n.tgpuAliases.add(`${t.local.name}.tgpu`)}var T=["fn","vertexFn","fragmentFn","computeFn"];function v(e,n){return e.callee.type==="CallExpression"&&e.callee.callee.type==="MemberExpression"&&e.callee.callee.property.type==="Identifier"&&T.includes(e.callee.callee.property.name)&&e.arguments.length===1&&(e.callee.callee.object.type==="MemberExpression"?y(n,e.callee.callee.object.object):y(n,e.callee.callee.object))||e.callee.type==="MemberExpression"&&e.arguments.length===1&&e.callee.property.type==="Identifier"&&e.callee.property.name==="does"}var E=["kernel","kernel & js"];var c=m.packages.template,s=m.packages.types;function I(e){var t,r;let n=("directives"in e.body?(r=(t=e.body)==null?void 0:t.directives)!=null?r:[]:[]).map(i=>i.value.value);for(let i of E)if(n.includes(i))return i}function d(e,n,t){var p;let r=I(e);if(!r)return null;let{argNames:i,body:o,externalNames:a}=k(e),l=n.tgpuAliases.values().next().value;if(l===void 0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${(p=n.fileId)!=null?p:""}`);return s.callExpression(c.expression(`${l}.__assignAst`)(),[r==="kernel & js"?e:c.expression`${l}.__removedJsImpl(${t?`"${t}"`:""})`(),c.expression`${f({argNames:i,body:o,externalNames:a})}`(),s.objectExpression(a.map(u=>s.objectProperty(s.identifier(u),s.identifier(u))))])}function C(e){return{ImportDeclaration(n){x(n.node,e)},ArrowFunctionExpression(n){let t=d(n.node,e,n.parentPath.node.type==="VariableDeclarator"&&n.parentPath.node.id.type==="Identifier"?n.parentPath.node.id.name:void 0);t&&(n.replaceWith(t),n.skip())},FunctionExpression(n){var r;let t=d(n.node,e,(r=n.node.id)!=null&&r.name?n.node.id.name:n.parentPath.node.type==="VariableDeclarator"&&n.parentPath.node.id.type==="Identifier"?n.parentPath.node.id.name:void 0);t&&(n.replaceWith(t),n.skip())},FunctionDeclaration(n){var o;let t=n.node,r=s.functionExpression(t.id,t.params,t.body),i=d(r,e,(o=t.id)==null?void 0:o.name);i&&t.id&&(n.replaceWith(s.variableDeclaration("const",[s.variableDeclarator(t.id,i)])),n.skip())},CallExpression(n){var r;let t=n.node;if(v(t,e)){let i=t.arguments[0];if(i&&(i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression")){let{argNames:o,body:a,externalNames:l}=k(i),p=e.tgpuAliases.values().next().value;if(p===void 0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${(r=e.fileId)!=null?r:""}`);let u=I(i);n.replaceWith(s.callExpression(t.callee,[s.callExpression(c.expression(`${p}.__assignAst`)(),[u!=="kernel & js"?c.expression`${p}.__removedJsImpl()`():i,c.expression`${f({argNames:o,body:a,externalNames:l})}`(),s.objectExpression(l.map(g=>s.objectProperty(s.identifier(g),s.identifier(g))))])])),n.skip()}}}}}function P(){return{visitor:{Program(e,n){var a;let t=(a=n.file)==null?void 0:a.code,r=n.opts,i=n.filename;if(b(r,i,t))return;let o={tgpuAliases:new Set(r!=null&&r.forceTgpuAlias?[r.forceTgpuAlias]:[]),fileId:i};e.traverse(C(o))}}}}export{f as a,b,x as c,v as d,E as e,P as f};
|
|
2
|
+
//# sourceMappingURL=chunk-D2NWA2J7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/babel.ts","../src/common.ts"],"sourcesContent":["import * as Babel from '@babel/standalone';\nimport type TemplateGenerator from '@babel/template';\nimport type { TraverseOptions } from '@babel/traverse';\nimport type * as babel from '@babel/types';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type KernelDirective,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isShellImplementationCall,\n kernelDirectives,\n shouldSkipFile,\n} from './common.ts';\n\n// NOTE: @babel/standalone does expose internal packages, as specified in the docs, but the\n// typing for @babel/standalone does not expose them.\nconst template = (\n Babel as unknown as { packages: { template: typeof TemplateGenerator } }\n).packages.template;\nconst types = (Babel as unknown as { packages: { types: typeof babel } })\n .packages.types;\n\nfunction getKernelDirective(\n node:\n | babel.FunctionDeclaration\n | babel.FunctionExpression\n | babel.ArrowFunctionExpression,\n): KernelDirective | undefined {\n const directives = (\n 'directives' in node.body ? (node.body?.directives ?? []) : []\n ).map((directive) => directive.value.value);\n\n for (const directive of kernelDirectives) {\n if (directives.includes(directive)) {\n return directive;\n }\n }\n}\n\nfunction functionToTranspiled(\n node: babel.ArrowFunctionExpression | babel.FunctionExpression,\n ctx: Context,\n name?: string | undefined,\n): babel.CallExpression | null {\n const directive = getKernelDirective(node);\n if (!directive) {\n return null;\n }\n\n const { argNames, body, externalNames } = transpileFn(node);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n if (tgpuAlias === undefined) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${ctx.fileId ?? ''}`,\n );\n }\n\n return types.callExpression(\n template.expression(`${tgpuAlias}.__assignAst`)(),\n [\n directive === 'kernel & js'\n ? node\n : template.expression`${tgpuAlias}.__removedJsImpl(${name ? `\"${name}\"` : ''})`(),\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(types.identifier(name), types.identifier(name)),\n ),\n ),\n ],\n );\n}\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n ArrowFunctionExpression(path) {\n const transpiled = functionToTranspiled(\n path.node,\n ctx,\n path.parentPath.node.type === 'VariableDeclarator'\n ? path.parentPath.node.id.type === 'Identifier'\n ? path.parentPath.node.id.name\n : undefined\n : undefined,\n );\n if (transpiled) {\n path.replaceWith(transpiled);\n path.skip();\n }\n },\n\n FunctionExpression(path) {\n const transpiled = functionToTranspiled(\n path.node,\n ctx,\n path.node.id?.name\n ? path.node.id.name\n : path.parentPath.node.type === 'VariableDeclarator'\n ? path.parentPath.node.id.type === 'Identifier'\n ? path.parentPath.node.id.name\n : undefined\n : undefined,\n );\n if (transpiled) {\n path.replaceWith(transpiled);\n path.skip();\n }\n },\n\n FunctionDeclaration(path) {\n const node = path.node;\n const expression = types.functionExpression(\n node.id,\n node.params,\n node.body,\n );\n const transpiled = functionToTranspiled(expression, ctx, node.id?.name);\n if (transpiled && node.id) {\n path.replaceWith(\n types.variableDeclaration('const', [\n types.variableDeclarator(node.id, transpiled),\n ]),\n );\n path.skip();\n }\n },\n\n CallExpression(path) {\n const node = path.node;\n\n if (isShellImplementationCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const { argNames, body, externalNames } = transpileFn(implementation);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n if (tgpuAlias === undefined) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${ctx.fileId ?? ''}`,\n );\n }\n\n const directive = getKernelDirective(implementation);\n\n path.replaceWith(\n types.callExpression(node.callee, [\n types.callExpression(\n template.expression(`${tgpuAlias}.__assignAst`)(),\n [\n directive !== 'kernel & js'\n ? template.expression`${tgpuAlias}.__removedJsImpl()`()\n : implementation,\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(\n types.identifier(name),\n types.identifier(name),\n ),\n ),\n ),\n ],\n ),\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // @ts-ignore\n const code: string | undefined = state.file?.code;\n // @ts-ignore\n const options: TypegpuPluginOptions | undefined = state.opts;\n // @ts-ignore\n const id: string | undefined = state.filename;\n\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options?.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n };\n\n path.traverse(functionVisitor(ctx));\n },\n } satisfies TraverseOptions,\n };\n}\n","import type * as babel from '@babel/types';\nimport type * as acorn from 'acorn';\n\nexport type Context = {\n /**\n * How the `tgpu` object is used in code. Since it can be aliased, we\n * need to catch that and act accordingly.\n */\n tgpuAliases: Set<string>;\n fileId?: string | undefined;\n};\n\nexport interface TypegpuPluginOptions {\n include?: 'all' | RegExp[];\n forceTgpuAlias?: string;\n}\n\nexport function embedJSON(jsValue: unknown) {\n return JSON.stringify(jsValue)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n\n/**\n * Checks if `node` is an alias for the 'tgpu' object, traditionally\n * available via `import tgpu from 'typegpu'`.\n */\nfunction isTgpu(ctx: Context, node: babel.Node | acorn.AnyNode): boolean {\n let path = '';\n\n let tail = node;\n while (true) {\n if (tail.type === 'MemberExpression') {\n if (tail.property.type !== 'Identifier') {\n // Not handling computed expressions.\n break;\n }\n\n path = path ? `${tail.property.name}.${path}` : tail.property.name;\n tail = tail.object;\n } else if (tail.type === 'Identifier') {\n path = path ? `${tail.name}.${path}` : tail.name;\n break;\n } else {\n break;\n }\n }\n\n return ctx.tgpuAliases.has(path);\n}\n\nconst typegpuImportRegex = /import.*from\\s*['\"]typegpu.*['\"]/;\nconst typegpuDynamicImportRegex = /import\\s*\\(\\s*['\"]\\s*typegpu.*['\"]/;\nconst typegpuRequireRegex = /require\\s*\\(\\s*['\"]\\s*typegpu.*['\"]\\s*\\)/;\n\nexport function shouldSkipFile(\n options: TypegpuPluginOptions | undefined,\n id: string | undefined,\n code: string | undefined,\n) {\n if (code && !options?.include) {\n if (\n !typegpuImportRegex.test(code) &&\n !typegpuRequireRegex.test(code) &&\n !typegpuDynamicImportRegex.test(code)\n ) {\n // No imports to `typegpu` or its sub modules, exiting early.\n return true;\n }\n } else if (\n options?.include &&\n options.include !== 'all' &&\n (!id || !options.include.some((pattern) => pattern.test(id)))\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function gatherTgpuAliases(\n node: acorn.ImportDeclaration | babel.ImportDeclaration,\n ctx: Context,\n) {\n if (node.source.value === 'typegpu') {\n for (const spec of node.specifiers) {\n if (\n // The default export of 'typegpu' is the `tgpu` object.\n spec.type === 'ImportDefaultSpecifier' ||\n // Aliasing 'tgpu' while importing, e.g. import { tgpu as t } from 'typegpu';\n (spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === 'tgpu')\n ) {\n ctx.tgpuAliases.add(spec.local.name);\n } else if (spec.type === 'ImportNamespaceSpecifier') {\n // Importing everything, e.g. import * as t from 'typegpu';\n ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);\n }\n }\n }\n}\n\nconst fnShellFunctionNames = ['fn', 'vertexFn', 'fragmentFn', 'computeFn'];\n\nexport function isShellImplementationCall(\n node: acorn.CallExpression | babel.CallExpression,\n ctx: Context,\n) {\n return (\n (node.callee.type === 'CallExpression' &&\n node.callee.callee.type === 'MemberExpression' &&\n node.callee.callee.property.type === 'Identifier' &&\n fnShellFunctionNames.includes(node.callee.callee.property.name) &&\n node.arguments.length === 1 &&\n (node.callee.callee.object.type === 'MemberExpression'\n ? isTgpu(ctx, node.callee.callee.object.object)\n : isTgpu(ctx, node.callee.callee.object))) || // TODO: remove along with the deprecated 'does' method\n (node.callee.type === 'MemberExpression' &&\n node.arguments.length === 1 &&\n node.callee.property.type === 'Identifier' &&\n // Assuming that every call to `.does` is related to TypeGPU\n // because shells can be created separately from calls to `tgpu`,\n // making it hard to detect.\n node.callee.property.name === 'does')\n );\n}\n\nexport const kernelDirectives = ['kernel', 'kernel & js'] as const;\nexport type KernelDirective = (typeof kernelDirectives)[number];\n"],"mappings":"AAAA,UAAYA,MAAW,oBAIvB,OAAS,eAAAC,MAAmB,mBCarB,SAASC,EAAUC,EAAkB,CAC1C,OAAO,KAAK,UAAUA,CAAO,EAC1B,QAAQ,UAAW,SAAS,EAC5B,QAAQ,UAAW,SAAS,CACjC,CAMA,SAASC,EAAOC,EAAcC,EAA2C,CACvE,IAAIC,EAAO,GAEPC,EAAOF,EACX,OACE,GAAIE,EAAK,OAAS,mBAAoB,CACpC,GAAIA,EAAK,SAAS,OAAS,aAEzB,MAGFD,EAAOA,EAAO,GAAGC,EAAK,SAAS,IAAI,IAAID,CAAI,GAAKC,EAAK,SAAS,KAC9DA,EAAOA,EAAK,MACd,SAAWA,EAAK,OAAS,aAAc,CACrCD,EAAOA,EAAO,GAAGC,EAAK,IAAI,IAAID,CAAI,GAAKC,EAAK,KAC5C,KACF,KACE,OAIJ,OAAOH,EAAI,YAAY,IAAIE,CAAI,CACjC,CAEA,IAAME,EAAqB,mCACrBC,EAA4B,qCAC5BC,EAAsB,2CAErB,SAASC,EACdC,EACAC,EACAC,EACA,CACA,GAAIA,GAAQ,EAACF,GAAA,MAAAA,EAAS,UACpB,GACE,CAACJ,EAAmB,KAAKM,CAAI,GAC7B,CAACJ,EAAoB,KAAKI,CAA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AGgB,CAAS,cAAc,EAAE,EAChD,CACET,IAAc,cACVP,EAAS,aAAagB,CAAS,qBAAqB,EACpDQ,EACJxB,EAAS,aAAaiB,EAAU,CAAE,SAAAL,EAAU,KAAAC,EAAM,cAAAC,CAAc,CAAC,CAAC,GAAG,EACrEb,EAAM,iBACJa,EAAc,IAAKH,GACjBV,EAAM,eACJA,EAAM,WAAWU,CAAI,EACrBV,EAAM,WAAWU,CAAI,CACvB,CACF,CACF,CACF,CACF,CACF,CAAC,CACH,EAEAQ,EAAK,KAAK,CACZ,CACF,CACF,CACF,CACF,CAEe,SAARM,GAAoB,CACzB,MAAO,CACL,QAAS,CACP,QAAQN,EAAMO,EAAO,CA1L3B,IAAAtB,EA4LQ,IAAMuB,GAA2BvB,EAAAsB,EAAM,OAAN,YAAAtB,EAAY,KAEvCwB,EAA4CF,EAAM,KAElDG,EAAyBH,EAAM,SAErC,GAAII,EAAeF,EAASC,EAAIF,CAAI,EAClC,OAGF,IAAMjB,EAAe,CACnB,YAAa,IAAI,IACfkB,GAAA,MAAAA,EAAS,eAAiB,CAACA,EAAQ,cAAc,EAAI,CAAC,CACxD,EACA,OAAQC,CACV,EAEAV,EAAK,SAASD,EAAgBR,CAAG,CAAC,CACpC,CACF,CACF,CACF","names":["Babel","transpileFn","embedJSON","jsValue","isTgpu","ctx","node","path","tail","typegpuImportRegex","typegpuDynamicImportRegex","typegpuRequireRegex","shouldSkipFile","options","id","code","pattern","gatherTgpuAliases","spec","fnShellFunctionNames","isShellImplementationCall","kernelDirectives","template","types","getKernelDirective","node","_a","_b","directives","directive","kernelDirectives","functionToTranspiled","ctx","name","argNames","body","externalNames","transpileFn","tgpuAlias","embedJSON","functionVisitor","path","gatherTgpuAliases","transpiled","expression","isShellImplementationCall","implementation","babel_default","state","code","options","id","shouldSkipFile"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkTCJABTWKcjs = require('./chunk-TCJABTWK.cjs');var _estreewalker = require('estree-walker');var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);var _tinyestforwgsl = require('tinyest-for-wgsl');var _unplugin = require('unplugin');function w(o){if(o.body.type==="BlockStatement"){for(let t of o.body.body)if(t.type==="ExpressionStatement"&&_chunkTCJABTWKcjs.e.includes(t.directive))return t.directive}}function h(o){return o.body.type==="BlockStatement"&&(o.body.body=o.body.body.filter(t=>!(t.type==="ExpressionStatement"&&t.directive&&_chunkTCJABTWKcjs.e.includes(t.directive)))),o}var S=(o={})=>({name:"unplugin-typegpu",transform(t,c){if(_chunkTCJABTWKcjs.b.call(void 0, o,c,t))return;let u={tgpuAliases:new Set(o.forceTgpuAlias?[o.forceTgpuAlias]:[]),fileId:c},D=this.parse(t,{allowReturnOutsideFunction:!0}),l=[];_estreewalker.walk.call(void 0, D,{enter(r,n,d,g){var a;let e=r;if(e.type==="ImportDeclaration"&&_chunkTCJABTWKcjs.c.call(void 0, e,u),e.type==="CallExpression"&&_chunkTCJABTWKcjs.d.call(void 0, e,u)){let i=e.arguments[0];if(i&&(i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression")){let $=w(i);l.push({def:h(i),removeJsImplementation:$!=="kernel & js"})}}if(e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"||e.type==="FunctionDeclaration"){let i=w(e);i&&l.push({def:h(e),name:e.type==="FunctionDeclaration"||e.type==="FunctionExpression"?(a=e.id)==null?void 0:a.name:(n==null?void 0:n.type)==="VariableDeclarator"&&n.id.type==="Identifier"?n.id.name:void 0,removeJsImplementation:i!=="kernel & js"})}}});let p=new (0, _magicstring2.default)(t),m=u.tgpuAliases.values().next().value;if(m===void 0&&l.length>0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${c}`);for(let{def:r,name:n,removeJsImplementation:d}of l){let{argNames:g,body:e,externalNames:a}=_tinyestforwgsl.transpileFn.call(void 0, r),i=r.type==="FunctionDeclaration";if(i&&n&&t.slice(0,r.start).search(new RegExp(`(?<![\\w_.])${n}(?![\\w_])`))!==-1)throw new Error(`File ${c}: function "${n}", containing ${d?"kernel":"kernel & js"} directive, is referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);p.appendLeft(r.start,`${i&&n?`const ${n} = `:""}${m}.__assignAst(`),p.appendRight(r.end,`, ${_chunkTCJABTWKcjs.a.call(void 0, {argNames:g,body:e,externalNames:a})}`),a.length>0?p.appendRight(r.end,`, {${a.join(", ")}})`):p.appendRight(r.end,`)${i&&n?";":""}`),d&&p.overwrite(r.start,r.end,`${m}.__removedJsImpl(${n?`"${n}"`:""})`)}return{code:p.toString(),map:p.generateMap()}}}),s=_unplugin.createUnplugin.call(void 0, S),R= exports.a =s,j= exports.b =s.vite,C= exports.c =s.rollup,U= exports.d =s.rolldown,B= exports.e =s.webpack,M= exports.f =s.rspack,L= exports.g =s.esbuild,V= exports.h =s.farm,q= exports.i =_chunkTCJABTWKcjs.f;exports.a = R; exports.b = j; exports.c = C; exports.d = U; exports.e = B; exports.f = M; exports.g = L; exports.h = V; exports.i = q;
|
|
2
|
+
//# sourceMappingURL=chunk-IA2CUGWD.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/chunk-IA2CUGWD.cjs","../src/index.ts"],"names":["getKernelDirective","node","statement","kernelDirectives","removeKernelDirective","typegpu","options","code","id","shouldSkipFile","ctx","ast","tgslFunctionDefs","walk","_node","_parent","prop","index","_a","gatherTgpuAliases","isShellImplementationCall","implementation","directive","magicString","MagicString","tgpuAlias"],"mappings":"AAAA,iOAA2E,6CCC3C,qGACR,kDACI,oCACyB,SAmB5CA,CAAAA,CAAmBC,CAAAA,CAAiD,CAC3E,EAAA,CAAIA,CAAAA,CAAK,IAAA,CAAK,IAAA,GAAS,gBAAA,CAAA,CACrB,GAAA,CAAA,IAAWC,EA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AAA,CAAG,IAAA,GAAS,YAAA,CAClBA,CAAAA,CAAQ,EAAA,CAAG,IAAA,CAEb,KAAA,CAAA,CACR,sBAAA,CAAwBO,CAAAA,GAAc,aACxC,CAAC,CAEL,CACF,CACF,CAAC,CAAA,CAED,IAAMC,CAAAA,CAAc,IAAIC,0BAAAA,CAAYjB,CAAI,CAAA,CAClCkB,CAAAA,CAAYf,CAAAA,CAAI,WAAA,CAAY,MAAA,CAAO,CAAA,CAAE,IAAA,CAAK,CAAA,CAAE,KAAA,CAElD,EAAA,CAAIe,CAAAA,GAAc,KAAA,CAAA,EAAab,CAAAA,CAAiB,MAAA,CAAS,CAAA,CACvD,MAAM,IAAI,KAAA,CACR,CAAA,6DAAA,EAAgEJ,CAAE,CAAA,CAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/chunk-IA2CUGWD.cjs","sourcesContent":[null,"import type * as acorn from 'acorn';\nimport { type Node, walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { type UnpluginFactory, createUnplugin } from 'unplugin';\nimport babel from './babel.ts';\nimport {\n type Context,\n type KernelDirective,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isShellImplementationCall,\n kernelDirectives,\n shouldSkipFile,\n} from './common.ts';\n\ntype FunctionNode =\n | acorn.FunctionDeclaration\n | acorn.AnonymousFunctionDeclaration\n | acorn.FunctionExpression\n | acorn.ArrowFunctionExpression;\n\nfunction getKernelDirective(node: FunctionNode): KernelDirective | undefined {\n if (node.body.type === 'BlockStatement') {\n for (const statement of node.body.body) {\n if (statement.type === 'ExpressionStatement') {\n if (kernelDirectives.includes(statement.directive as KernelDirective)) {\n return statement.directive as KernelDirective;\n }\n }\n }\n }\n}\n\nfunction removeKernelDirective(node: FunctionNode) {\n if (node.body.type === 'BlockStatement') {\n node.body.body = node.body.body.filter(\n (statement) =>\n !(\n statement.type === 'ExpressionStatement' &&\n statement.directive &&\n kernelDirectives.includes(statement.directive as KernelDirective)\n ),\n );\n }\n\n return node;\n}\n\nconst typegpu: UnpluginFactory<TypegpuPluginOptions> = (\n options: TypegpuPluginOptions = {},\n) => ({\n name: 'unplugin-typegpu' as const,\n transform(code, id) {\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n };\n\n const ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n }) as Node;\n\n const tgslFunctionDefs: {\n def: FunctionNode;\n name?: string | undefined;\n removeJsImplementation: boolean;\n }[] = [];\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as acorn.AnyNode;\n\n if (node.type === 'ImportDeclaration') {\n gatherTgpuAliases(node, ctx);\n }\n\n if (node.type === 'CallExpression') {\n if (isShellImplementationCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const directive = getKernelDirective(implementation);\n tgslFunctionDefs.push({\n def: removeKernelDirective(implementation),\n removeJsImplementation: directive !== 'kernel & js',\n });\n }\n }\n }\n\n if (\n node.type === 'ArrowFunctionExpression' ||\n node.type === 'FunctionExpression' ||\n node.type === 'FunctionDeclaration'\n ) {\n const directive = getKernelDirective(node);\n if (directive) {\n tgslFunctionDefs.push({\n def: removeKernelDirective(node),\n name:\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression'\n ? node.id?.name\n : _parent?.type === 'VariableDeclarator'\n ? _parent.id.type === 'Identifier'\n ? _parent.id.name\n : undefined\n : undefined,\n removeJsImplementation: directive !== 'kernel & js',\n });\n }\n }\n },\n });\n\n const magicString = new MagicString(code);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n\n if (tgpuAlias === undefined && tgslFunctionDefs.length > 0) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${id}`,\n );\n }\n\n for (const { def, name, removeJsImplementation } of tgslFunctionDefs) {\n const { argNames, body, externalNames } = transpileFn(def);\n const isFunctionStatement = def.type === 'FunctionDeclaration';\n\n if (\n isFunctionStatement &&\n name &&\n code\n .slice(0, def.start)\n .search(new RegExp(`(?<![\\\\w_.])${name}(?![\\\\w_])`)) !== -1\n ) {\n throw new Error(\n `File ${id}: function \"${name}\", containing ${removeJsImplementation ? 'kernel' : 'kernel & js'} directive, is referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`,\n );\n }\n\n // Wrap the implementation in a call to `tgpu.__assignAst` to associate the AST with the implementation.\n magicString.appendLeft(\n def.start,\n `${isFunctionStatement && name ? `const ${name} = ` : ''}${tgpuAlias}.__assignAst(`,\n );\n magicString.appendRight(\n def.end,\n `, ${embedJSON({ argNames, body, externalNames })}`,\n );\n\n if (externalNames.length > 0) {\n magicString.appendRight(def.end, `, {${externalNames.join(', ')}})`);\n } else {\n magicString.appendRight(\n def.end,\n `)${isFunctionStatement && name ? ';' : ''}`,\n );\n }\n\n if (removeJsImplementation) {\n magicString.overwrite(\n def.start,\n def.end,\n `${tgpuAlias}.__removedJsImpl(${name ? `\"${name}\"` : ''})`,\n );\n }\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap(),\n };\n },\n});\n\nconst unplugin = createUnplugin(typegpu);\n\nexport type { TypegpuPluginOptions } from './common.ts';\n\nexport default unplugin;\n\nexport const vitePlugin = unplugin.vite;\nexport const rollupPlugin = unplugin.rollup;\nexport const rolldownPlugin = unplugin.rolldown;\nexport const webpackPlugin = unplugin.webpack;\nexport const rspackPlugin = unplugin.rspack;\nexport const esbuildPlugin = unplugin.esbuild;\nexport const farmPlugin = unplugin.farm;\nexport const babelPlugin = babel;\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as y,b as x,c as v,d as F,e as f,f as b}from"./chunk-D2NWA2J7.js";import{walk as k}from"estree-walker";import E from"magic-string";import{transpileFn as A}from"tinyest-for-wgsl";import{createUnplugin as P}from"unplugin";function w(o){if(o.body.type==="BlockStatement"){for(let t of o.body.body)if(t.type==="ExpressionStatement"&&f.includes(t.directive))return t.directive}}function h(o){return o.body.type==="BlockStatement"&&(o.body.body=o.body.body.filter(t=>!(t.type==="ExpressionStatement"&&t.directive&&f.includes(t.directive)))),o}var S=(o={})=>({name:"unplugin-typegpu",transform(t,c){if(x(o,c,t))return;let u={tgpuAliases:new Set(o.forceTgpuAlias?[o.forceTgpuAlias]:[]),fileId:c},D=this.parse(t,{allowReturnOutsideFunction:!0}),l=[];k(D,{enter(r,n,d,g){var a;let e=r;if(e.type==="ImportDeclaration"&&v(e,u),e.type==="CallExpression"&&F(e,u)){let i=e.arguments[0];if(i&&(i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression")){let $=w(i);l.push({def:h(i),removeJsImplementation:$!=="kernel & js"})}}if(e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"||e.type==="FunctionDeclaration"){let i=w(e);i&&l.push({def:h(e),name:e.type==="FunctionDeclaration"||e.type==="FunctionExpression"?(a=e.id)==null?void 0:a.name:(n==null?void 0:n.type)==="VariableDeclarator"&&n.id.type==="Identifier"?n.id.name:void 0,removeJsImplementation:i!=="kernel & js"})}}});let p=new E(t),m=u.tgpuAliases.values().next().value;if(m===void 0&&l.length>0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${c}`);for(let{def:r,name:n,removeJsImplementation:d}of l){let{argNames:g,body:e,externalNames:a}=A(r),i=r.type==="FunctionDeclaration";if(i&&n&&t.slice(0,r.start).search(new RegExp(`(?<![\\w_.])${n}(?![\\w_])`))!==-1)throw new Error(`File ${c}: function "${n}", containing ${d?"kernel":"kernel & js"} directive, is referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);p.appendLeft(r.start,`${i&&n?`const ${n} = `:""}${m}.__assignAst(`),p.appendRight(r.end,`, ${y({argNames:g,body:e,externalNames:a})}`),a.length>0?p.appendRight(r.end,`, {${a.join(", ")}})`):p.appendRight(r.end,`)${i&&n?";":""}`),d&&p.overwrite(r.start,r.end,`${m}.__removedJsImpl(${n?`"${n}"`:""})`)}return{code:p.toString(),map:p.generateMap()}}}),s=P(S),R=s,j=s.vite,C=s.rollup,U=s.rolldown,B=s.webpack,M=s.rspack,L=s.esbuild,V=s.farm,q=b;export{R as a,j as b,C as c,U as d,B as e,M as f,L as g,V as h,q as i};
|
|
2
|
+
//# sourceMappingURL=chunk-JKPGDPK3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type * as acorn from 'acorn';\nimport { type Node, walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { type UnpluginFactory, createUnplugin } from 'unplugin';\nimport babel from './babel.ts';\nimport {\n type Context,\n type KernelDirective,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isShellImplementationCall,\n kernelDirectives,\n shouldSkipFile,\n} from './common.ts';\n\ntype FunctionNode =\n | acorn.FunctionDeclaration\n | acorn.AnonymousFunctionDeclaration\n | acorn.FunctionExpression\n | acorn.ArrowFunctionExpression;\n\nfunction getKernelDirective(node: FunctionNode): KernelDirective | undefined {\n if (node.body.type === 'BlockStatement') {\n for (const statement of node.body.body) {\n if (statement.type === 'ExpressionStatement') {\n if (kernelDirectives.includes(statement.directive as KernelDirective)) {\n return statement.directive as KernelDirective;\n }\n }\n }\n }\n}\n\nfunction removeKernelDirective(node: FunctionNode) {\n if (node.body.type === 'BlockStatement') {\n node.body.body = node.body.body.filter(\n (statement) =>\n !(\n statement.type === 'ExpressionStatement' &&\n statement.directive &&\n kernelDirectives.includes(statement.directive as KernelDirective)\n ),\n );\n }\n\n return node;\n}\n\nconst typegpu: UnpluginFactory<TypegpuPluginOptions> = (\n options: TypegpuPluginOptions = {},\n) => ({\n name: 'unplugin-typegpu' as const,\n transform(code, id) {\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n };\n\n const ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n }) as Node;\n\n const tgslFunctionDefs: {\n def: FunctionNode;\n name?: string | undefined;\n removeJsImplementation: boolean;\n }[] = [];\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as acorn.AnyNode;\n\n if (node.type === 'ImportDeclaration') {\n gatherTgpuAliases(node, ctx);\n }\n\n if (node.type === 'CallExpression') {\n if (isShellImplementationCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const directive = getKernelDirective(implementation);\n tgslFunctionDefs.push({\n def: removeKernelDirective(implementation),\n removeJsImplementation: directive !== 'kernel & js',\n });\n }\n }\n }\n\n if (\n node.type === 'ArrowFunctionExpression' ||\n node.type === 'FunctionExpression' ||\n node.type === 'FunctionDeclaration'\n ) {\n const directive = getKernelDirective(node);\n if (directive) {\n tgslFunctionDefs.push({\n def: removeKernelDirective(node),\n name:\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression'\n ? node.id?.name\n : _parent?.type === 'VariableDeclarator'\n ? _parent.id.type === 'Identifier'\n ? _parent.id.name\n : undefined\n : undefined,\n removeJsImplementation: directive !== 'kernel & js',\n });\n }\n }\n },\n });\n\n const magicString = new MagicString(code);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n\n if (tgpuAlias === undefined && tgslFunctionDefs.length > 0) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${id}`,\n );\n }\n\n for (const { def, name, removeJsImplementation } of tgslFunctionDefs) {\n const { argNames, body, externalNames } = transpileFn(def);\n const isFunctionStatement = def.type === 'FunctionDeclaration';\n\n if (\n isFunctionStatement &&\n name &&\n code\n .slice(0, def.start)\n .search(new RegExp(`(?<![\\\\w_.])${name}(?![\\\\w_])`)) !== -1\n ) {\n throw new Error(\n `File ${id}: function \"${name}\", containing ${removeJsImplementation ? 'kernel' : 'kernel & js'} directive, is referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`,\n );\n }\n\n // Wrap the implementation in a call to `tgpu.__assignAst` to associate the AST with the implementation.\n magicString.appendLeft(\n def.start,\n `${isFunctionStatement && name ? `const ${name} = ` : ''}${tgpuAlias}.__assignAst(`,\n );\n magicString.appendRight(\n def.end,\n `, ${embedJSON({ argNames, body, externalNames })}`,\n );\n\n if (externalNames.length > 0) {\n magicString.appendRight(def.end, `, {${externalNames.join(', ')}})`);\n } else {\n magicString.appendRight(\n def.end,\n `)${isFunctionStatement && name ? ';' : ''}`,\n );\n }\n\n if (removeJsImplementation) {\n magicString.overwrite(\n def.start,\n def.end,\n `${tgpuAlias}.__removedJsImpl(${name ? `\"${name}\"` : ''})`,\n );\n }\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap(),\n };\n },\n});\n\nconst unplugin = createUnplugin(typegpu);\n\nexport type { TypegpuPluginOptions } from './common.ts';\n\nexport default unplugin;\n\nexport const vitePlugin = unplugin.vite;\nexport const rollupPlugin = unplugin.rollup;\nexport const rolldownPlugin = unplugin.rolldown;\nexport const webpackPlugin = unplugin.webpack;\nexport const rspackPlugin = unplugin.rspack;\nexport const esbuildPlugin = unplugin.esbuild;\nexport const farmPlugin = unplugin.farm;\nexport const babelPlugin = babel;\n"],"mappings":"2EACA,OAAoB,QAAAA,MAAY,gBAChC,OAAOC,MAAiB,eACxB,OAAS,eAAAC,MAAmB,mBAC5B,OAA+B,kBAAAC,MAAsB,WAmBrD,SAASC,EAAmBC,EAAiD,CAC3E,GAAIA,EAAK,KAAK,OAAS,kBACrB,QAAWC,KAAaD,EAAK,KAAK,KAChC,GAAIC,EAAU,OAAS,uBACjBC,EAAiB,SAASD,EAAU,SAA4B,EAClE,OAAOA,EAAU,UAK3B,CAEA,SAASE,EAAsBH,EAAoB,CACjD,OA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AAe/B,CAAO,EAIhCgC,EAAQF,EAEFG,EAAaH,EAAS,KACtBI,EAAeJ,EAAS,OACxBK,EAAiBL,EAAS,SAC1BM,EAAgBN,EAAS,QACzBO,EAAeP,EAAS,OACxBQ,EAAgBR,EAAS,QACzBS,EAAaT,EAAS,KACtBU,EAAcC","names":["walk","MagicString","transpileFn","createUnplugin","getKernelDirective","node","statement","kernelDirectives","removeKernelDirective","typegpu","options","code","id","shouldSkipFile","ctx","ast","tgslFunctionDefs","walk","_node","_parent","prop","index","_a","gatherTgpuAliases","isShellImplementationCall","implementation","directive","magicString","MagicString","tgpuAlias","def","name","removeJsImplementation","argNames","body","externalNames","transpileFn","isFunctionStatement","embedJSON","unplugin","createUnplugin","index_default","vitePlugin","rollupPlugin","rolldownPlugin","webpackPlugin","rspackPlugin","esbuildPlugin","farmPlugin","babelPlugin","babel_default"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _standalone = require('@babel/standalone'); var m = _interopRequireWildcard(_standalone);var _tinyestforwgsl = require('tinyest-for-wgsl');function f(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function y(e,n){let t="",r=n;for(;;)if(r.type==="MemberExpression"){if(r.property.type!=="Identifier")break;t=t?`${r.property.name}.${t}`:r.property.name,r=r.object}else if(r.type==="Identifier"){t=t?`${r.name}.${t}`:r.name;break}else break;return e.tgpuAliases.has(t)}var A=/import.*from\s*['"]typegpu.*['"]/,D=/import\s*\(\s*['"]\s*typegpu.*['"]/,F=/require\s*\(\s*['"]\s*typegpu.*['"]\s*\)/;function b(e,n,t){if(t&&!(e!=null&&e.include)){if(!A.test(t)&&!F.test(t)&&!D.test(t))return!0}else if(e!=null&&e.include&&e.include!=="all"&&(!n||!e.include.some(r=>r.test(n))))return!0;return!1}function x(e,n){if(e.source.value==="typegpu")for(let t of e.specifiers)t.type==="ImportDefaultSpecifier"||t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&t.imported.name==="tgpu"?n.tgpuAliases.add(t.local.name):t.type==="ImportNamespaceSpecifier"&&n.tgpuAliases.add(`${t.local.name}.tgpu`)}var T=["fn","vertexFn","fragmentFn","computeFn"];function v(e,n){return e.callee.type==="CallExpression"&&e.callee.callee.type==="MemberExpression"&&e.callee.callee.property.type==="Identifier"&&T.includes(e.callee.callee.property.name)&&e.arguments.length===1&&(e.callee.callee.object.type==="MemberExpression"?y(n,e.callee.callee.object.object):y(n,e.callee.callee.object))||e.callee.type==="MemberExpression"&&e.arguments.length===1&&e.callee.property.type==="Identifier"&&e.callee.property.name==="does"}var E=["kernel","kernel & js"];var c=m.packages.template,s=m.packages.types;function I(e){var t,r;let n=("directives"in e.body?(r=(t=e.body)==null?void 0:t.directives)!=null?r:[]:[]).map(i=>i.value.value);for(let i of E)if(n.includes(i))return i}function d(e,n,t){var p;let r=I(e);if(!r)return null;let{argNames:i,body:o,externalNames:a}=_tinyestforwgsl.transpileFn.call(void 0, e),l=n.tgpuAliases.values().next().value;if(l===void 0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${(p=n.fileId)!=null?p:""}`);return s.callExpression(c.expression(`${l}.__assignAst`)(),[r==="kernel & js"?e:c.expression`${l}.__removedJsImpl(${t?`"${t}"`:""})`(),c.expression`${f({argNames:i,body:o,externalNames:a})}`(),s.objectExpression(a.map(u=>s.objectProperty(s.identifier(u),s.identifier(u))))])}function C(e){return{ImportDeclaration(n){x(n.node,e)},ArrowFunctionExpression(n){let t=d(n.node,e,n.parentPath.node.type==="VariableDeclarator"&&n.parentPath.node.id.type==="Identifier"?n.parentPath.node.id.name:void 0);t&&(n.replaceWith(t),n.skip())},FunctionExpression(n){var r;let t=d(n.node,e,(r=n.node.id)!=null&&r.name?n.node.id.name:n.parentPath.node.type==="VariableDeclarator"&&n.parentPath.node.id.type==="Identifier"?n.parentPath.node.id.name:void 0);t&&(n.replaceWith(t),n.skip())},FunctionDeclaration(n){var o;let t=n.node,r=s.functionExpression(t.id,t.params,t.body),i=d(r,e,(o=t.id)==null?void 0:o.name);i&&t.id&&(n.replaceWith(s.variableDeclaration("const",[s.variableDeclarator(t.id,i)])),n.skip())},CallExpression(n){var r;let t=n.node;if(v(t,e)){let i=t.arguments[0];if(i&&(i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression")){let{argNames:o,body:a,externalNames:l}=_tinyestforwgsl.transpileFn.call(void 0, i),p=e.tgpuAliases.values().next().value;if(p===void 0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${(r=e.fileId)!=null?r:""}`);let u=I(i);n.replaceWith(s.callExpression(t.callee,[s.callExpression(c.expression(`${p}.__assignAst`)(),[u!=="kernel & js"?c.expression`${p}.__removedJsImpl()`():i,c.expression`${f({argNames:o,body:a,externalNames:l})}`(),s.objectExpression(l.map(g=>s.objectProperty(s.identifier(g),s.identifier(g))))])])),n.skip()}}}}}function P(){return{visitor:{Program(e,n){var a;let t=(a=n.file)==null?void 0:a.code,r=n.opts,i=n.filename;if(b(r,i,t))return;let o={tgpuAliases:new Set(r!=null&&r.forceTgpuAlias?[r.forceTgpuAlias]:[]),fileId:i};e.traverse(C(o))}}}}exports.a = f; exports.b = b; exports.c = x; exports.d = v; exports.e = E; exports.f = P;
|
|
2
|
+
//# sourceMappingURL=chunk-TCJABTWK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/babel.ts","../src/common.ts"],"names":["embedJSON","jsValue","isTgpu","ctx","node","path","tail"],"mappings":"AAAA,wbAAuB,kDAIK,SCaZA,CAAAA,CAAUC,CAAAA,CAAkB,CAC1C,OAAO,IAAA,CAAK,SAAA,CAAUA,CAAO,CAAA,CAC1B,OAAA,CAAQ,SAAA,CAAW,SAAS,CAAA,CAC5B,OAAA,CAAQ,SAAA,CAAW,SAAS,CACjC,CAMA,SAASC,CAAAA,CAAOC,CAAAA,CAAcC,CAAAA,CAA2C,CACvE,IAAIC,CAAAA,CAAO,EAAA,CAEPC,CAAAA,CAAOF,CAAAA,CACX,GAAA,CAAA,CAAA,CAAA,CACE,EAAA,CAAIE,CAAAA,CAAK,IAAA,GAAS,kBAAA,CAAoB,CACpC,EAAA,CAAIA,CAAAA,CAAK,QAAA,CAAS,IAAA,GAAS,YAAA,CAEzB,KAAA,CAGFD,CAAAA,CAAOA,CAAAA,CAAO,CAAA,EAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/chunk-TCJABTWK.cjs","sourcesContent":["import * as Babel from '@babel/standalone';\nimport type TemplateGenerator from '@babel/template';\nimport type { TraverseOptions } from '@babel/traverse';\nimport type * as babel from '@babel/types';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type KernelDirective,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isShellImplementationCall,\n kernelDirectives,\n shouldSkipFile,\n} from './common.ts';\n\n// NOTE: @babel/standalone does expose internal packages, as specified in the docs, but the\n// typing for @babel/standalone does not expose them.\nconst template = (\n Babel as unknown as { packages: { template: typeof TemplateGenerator } }\n).packages.template;\nconst types = (Babel as unknown as { packages: { types: typeof babel } })\n .packages.types;\n\nfunction getKernelDirective(\n node:\n | babel.FunctionDeclaration\n | babel.FunctionExpression\n | babel.ArrowFunctionExpression,\n): KernelDirective | undefined {\n const directives = (\n 'directives' in node.body ? (node.body?.directives ?? []) : []\n ).map((directive) => directive.value.value);\n\n for (const directive of kernelDirectives) {\n if (directives.includes(directive)) {\n return directive;\n }\n }\n}\n\nfunction functionToTranspiled(\n node: babel.ArrowFunctionExpression | babel.FunctionExpression,\n ctx: Context,\n name?: string | undefined,\n): babel.CallExpression | null {\n const directive = getKernelDirective(node);\n if (!directive) {\n return null;\n }\n\n const { argNames, body, externalNames } = transpileFn(node);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n if (tgpuAlias === undefined) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${ctx.fileId ?? ''}`,\n );\n }\n\n return types.callExpression(\n template.expression(`${tgpuAlias}.__assignAst`)(),\n [\n directive === 'kernel & js'\n ? node\n : template.expression`${tgpuAlias}.__removedJsImpl(${name ? `\"${name}\"` : ''})`(),\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(types.identifier(name), types.identifier(name)),\n ),\n ),\n ],\n );\n}\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n ArrowFunctionExpression(path) {\n const transpiled = functionToTranspiled(\n path.node,\n ctx,\n path.parentPath.node.type === 'VariableDeclarator'\n ? path.parentPath.node.id.type === 'Identifier'\n ? path.parentPath.node.id.name\n : undefined\n : undefined,\n );\n if (transpiled) {\n path.replaceWith(transpiled);\n path.skip();\n }\n },\n\n FunctionExpression(path) {\n const transpiled = functionToTranspiled(\n path.node,\n ctx,\n path.node.id?.name\n ? path.node.id.name\n : path.parentPath.node.type === 'VariableDeclarator'\n ? path.parentPath.node.id.type === 'Identifier'\n ? path.parentPath.node.id.name\n : undefined\n : undefined,\n );\n if (transpiled) {\n path.replaceWith(transpiled);\n path.skip();\n }\n },\n\n FunctionDeclaration(path) {\n const node = path.node;\n const expression = types.functionExpression(\n node.id,\n node.params,\n node.body,\n );\n const transpiled = functionToTranspiled(expression, ctx, node.id?.name);\n if (transpiled && node.id) {\n path.replaceWith(\n types.variableDeclaration('const', [\n types.variableDeclarator(node.id, transpiled),\n ]),\n );\n path.skip();\n }\n },\n\n CallExpression(path) {\n const node = path.node;\n\n if (isShellImplementationCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const { argNames, body, externalNames } = transpileFn(implementation);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n if (tgpuAlias === undefined) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${ctx.fileId ?? ''}`,\n );\n }\n\n const directive = getKernelDirective(implementation);\n\n path.replaceWith(\n types.callExpression(node.callee, [\n types.callExpression(\n template.expression(`${tgpuAlias}.__assignAst`)(),\n [\n directive !== 'kernel & js'\n ? template.expression`${tgpuAlias}.__removedJsImpl()`()\n : implementation,\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(\n types.identifier(name),\n types.identifier(name),\n ),\n ),\n ),\n ],\n ),\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // @ts-ignore\n const code: string | undefined = state.file?.code;\n // @ts-ignore\n const options: TypegpuPluginOptions | undefined = state.opts;\n // @ts-ignore\n const id: string | undefined = state.filename;\n\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options?.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n };\n\n path.traverse(functionVisitor(ctx));\n },\n } satisfies TraverseOptions,\n };\n}\n","import type * as babel from '@babel/types';\nimport type * as acorn from 'acorn';\n\nexport type Context = {\n /**\n * How the `tgpu` object is used in code. Since it can be aliased, we\n * need to catch that and act accordingly.\n */\n tgpuAliases: Set<string>;\n fileId?: string | undefined;\n};\n\nexport interface TypegpuPluginOptions {\n include?: 'all' | RegExp[];\n forceTgpuAlias?: string;\n}\n\nexport function embedJSON(jsValue: unknown) {\n return JSON.stringify(jsValue)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n\n/**\n * Checks if `node` is an alias for the 'tgpu' object, traditionally\n * available via `import tgpu from 'typegpu'`.\n */\nfunction isTgpu(ctx: Context, node: babel.Node | acorn.AnyNode): boolean {\n let path = '';\n\n let tail = node;\n while (true) {\n if (tail.type === 'MemberExpression') {\n if (tail.property.type !== 'Identifier') {\n // Not handling computed expressions.\n break;\n }\n\n path = path ? `${tail.property.name}.${path}` : tail.property.name;\n tail = tail.object;\n } else if (tail.type === 'Identifier') {\n path = path ? `${tail.name}.${path}` : tail.name;\n break;\n } else {\n break;\n }\n }\n\n return ctx.tgpuAliases.has(path);\n}\n\nconst typegpuImportRegex = /import.*from\\s*['\"]typegpu.*['\"]/;\nconst typegpuDynamicImportRegex = /import\\s*\\(\\s*['\"]\\s*typegpu.*['\"]/;\nconst typegpuRequireRegex = /require\\s*\\(\\s*['\"]\\s*typegpu.*['\"]\\s*\\)/;\n\nexport function shouldSkipFile(\n options: TypegpuPluginOptions | undefined,\n id: string | undefined,\n code: string | undefined,\n) {\n if (code && !options?.include) {\n if (\n !typegpuImportRegex.test(code) &&\n !typegpuRequireRegex.test(code) &&\n !typegpuDynamicImportRegex.test(code)\n ) {\n // No imports to `typegpu` or its sub modules, exiting early.\n return true;\n }\n } else if (\n options?.include &&\n options.include !== 'all' &&\n (!id || !options.include.some((pattern) => pattern.test(id)))\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function gatherTgpuAliases(\n node: acorn.ImportDeclaration | babel.ImportDeclaration,\n ctx: Context,\n) {\n if (node.source.value === 'typegpu') {\n for (const spec of node.specifiers) {\n if (\n // The default export of 'typegpu' is the `tgpu` object.\n spec.type === 'ImportDefaultSpecifier' ||\n // Aliasing 'tgpu' while importing, e.g. import { tgpu as t } from 'typegpu';\n (spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === 'tgpu')\n ) {\n ctx.tgpuAliases.add(spec.local.name);\n } else if (spec.type === 'ImportNamespaceSpecifier') {\n // Importing everything, e.g. import * as t from 'typegpu';\n ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);\n }\n }\n }\n}\n\nconst fnShellFunctionNames = ['fn', 'vertexFn', 'fragmentFn', 'computeFn'];\n\nexport function isShellImplementationCall(\n node: acorn.CallExpression | babel.CallExpression,\n ctx: Context,\n) {\n return (\n (node.callee.type === 'CallExpression' &&\n node.callee.callee.type === 'MemberExpression' &&\n node.callee.callee.property.type === 'Identifier' &&\n fnShellFunctionNames.includes(node.callee.callee.property.name) &&\n node.arguments.length === 1 &&\n (node.callee.callee.object.type === 'MemberExpression'\n ? isTgpu(ctx, node.callee.callee.object.object)\n : isTgpu(ctx, node.callee.callee.object))) || // TODO: remove along with the deprecated 'does' method\n (node.callee.type === 'MemberExpression' &&\n node.arguments.length === 1 &&\n node.callee.property.type === 'Identifier' &&\n // Assuming that every call to `.does` is related to TypeGPU\n // because shells can be created separately from calls to `tgpu`,\n // making it hard to detect.\n node.callee.property.name === 'does')\n );\n}\n\nexport const kernelDirectives = ['kernel', 'kernel & js'] as const;\nexport type KernelDirective = (typeof kernelDirectives)[number];\n"]}
|
package/esbuild.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIA2CUGWDcjs = require('./chunk-IA2CUGWD.cjs');require('./chunk-TCJABTWK.cjs');var l=_chunkIA2CUGWDcjs.g;exports.default = l;
|
|
2
2
|
//# sourceMappingURL=esbuild.cjs.map
|
package/esbuild.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/esbuild.cjs","../src/esbuild.ts"],"names":["esbuild_default","esbuildPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/esbuild.cjs","sourcesContent":[null,"import { esbuildPlugin } from './index.ts';\n\nexport default esbuildPlugin;\n"]}
|
package/esbuild.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as e}from"./chunk-
|
|
1
|
+
import{g as e}from"./chunk-JKPGDPK3.js";import"./chunk-D2NWA2J7.js";var l=e;export{l as default};
|
|
2
2
|
//# sourceMappingURL=esbuild.js.map
|
package/esbuild.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/esbuild.ts"],"sourcesContent":["import { esbuildPlugin } from './index';\n\nexport default esbuildPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["esbuild_default","esbuildPlugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/esbuild.ts"],"sourcesContent":["import { esbuildPlugin } from './index.ts';\n\nexport default esbuildPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["esbuild_default","esbuildPlugin"]}
|
package/farm.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIA2CUGWDcjs = require('./chunk-IA2CUGWD.cjs');require('./chunk-TCJABTWK.cjs');var m=_chunkIA2CUGWDcjs.h;exports.default = m;
|
|
2
2
|
//# sourceMappingURL=farm.cjs.map
|
package/farm.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/farm.cjs","../src/farm.ts"],"names":["farm_default","farmPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/farm.cjs","sourcesContent":[null,"import { farmPlugin } from './index.ts';\n\nexport default farmPlugin;\n"]}
|
package/farm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{h as r}from"./chunk-
|
|
1
|
+
import{h as r}from"./chunk-JKPGDPK3.js";import"./chunk-D2NWA2J7.js";var m=r;export{m as default};
|
|
2
2
|
//# sourceMappingURL=farm.js.map
|
package/farm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/farm.ts"],"sourcesContent":["import { farmPlugin } from './index';\n\nexport default farmPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["farm_default","farmPlugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/farm.ts"],"sourcesContent":["import { farmPlugin } from './index.ts';\n\nexport default farmPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["farm_default","farmPlugin"]}
|
package/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIA2CUGWDcjs = require('./chunk-IA2CUGWD.cjs');require('./chunk-TCJABTWK.cjs');exports.babelPlugin = _chunkIA2CUGWDcjs.i; exports.default = _chunkIA2CUGWDcjs.a; exports.esbuildPlugin = _chunkIA2CUGWDcjs.g; exports.farmPlugin = _chunkIA2CUGWDcjs.h; exports.rolldownPlugin = _chunkIA2CUGWDcjs.d; exports.rollupPlugin = _chunkIA2CUGWDcjs.c; exports.rspackPlugin = _chunkIA2CUGWDcjs.f; exports.vitePlugin = _chunkIA2CUGWDcjs.b; exports.webpackPlugin = _chunkIA2CUGWDcjs.e;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/index.cjs"],"names":[],"mappings":"AAAA,iIAAmD,gCAA6B,qYAAoK","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/index.cjs"}
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i}from"./chunk-JKPGDPK3.js";import"./chunk-D2NWA2J7.js";export{i as babelPlugin,a as default,g as esbuildPlugin,h as farmPlugin,d as rolldownPlugin,c as rollupPlugin,f as rspackPlugin,b as vitePlugin,e as webpackPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-typegpu",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.9",
|
|
4
4
|
"description": "Build plugins for TypeGPU, enabling seamless JavaScript -> WGSL transpilation and improved debugging.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rollup-plugin",
|
|
@@ -86,9 +86,12 @@
|
|
|
86
86
|
"@babel/standalone": "^7.26.6",
|
|
87
87
|
"estree-walker": "^3.0.3",
|
|
88
88
|
"magic-string": "^0.30.11",
|
|
89
|
-
"tinyest-for-wgsl": "~0.1.0-alpha.
|
|
89
|
+
"tinyest-for-wgsl": "~0.1.0-alpha.9",
|
|
90
90
|
"unplugin": "^2.2.0"
|
|
91
91
|
},
|
|
92
|
+
"peerDependencies": {
|
|
93
|
+
"typegpu": "^0.5.4"
|
|
94
|
+
},
|
|
92
95
|
"main": "./index.js",
|
|
93
96
|
"types": "./index.d.ts",
|
|
94
97
|
"private": false,
|
package/rolldown.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIA2CUGWDcjs = require('./chunk-IA2CUGWD.cjs');require('./chunk-TCJABTWK.cjs');var r=_chunkIA2CUGWDcjs.d;exports.default = r;
|
|
2
2
|
//# sourceMappingURL=rolldown.cjs.map
|
package/rolldown.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rolldown.cjs","../src/rolldown.ts"],"names":["rolldown_default","rolldownPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rolldown.cjs","sourcesContent":[null,"import { rolldownPlugin } from './index.ts';\n\nexport default rolldownPlugin;\n"]}
|
package/rolldown.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{d as o}from"./chunk-
|
|
1
|
+
import{d as o}from"./chunk-JKPGDPK3.js";import"./chunk-D2NWA2J7.js";var r=o;export{r as default};
|
|
2
2
|
//# sourceMappingURL=rolldown.js.map
|
package/rolldown.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rolldown.ts"],"sourcesContent":["import { rolldownPlugin } from './index';\n\nexport default rolldownPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["rolldown_default","rolldownPlugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/rolldown.ts"],"sourcesContent":["import { rolldownPlugin } from './index.ts';\n\nexport default rolldownPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["rolldown_default","rolldownPlugin"]}
|
package/rollup.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIA2CUGWDcjs = require('./chunk-IA2CUGWD.cjs');require('./chunk-TCJABTWK.cjs');var r=_chunkIA2CUGWDcjs.c;exports.default = r;
|
|
2
2
|
//# sourceMappingURL=rollup.cjs.map
|
package/rollup.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rollup.cjs","../src/rollup.ts"],"names":["rollup_default","rollupPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rollup.cjs","sourcesContent":[null,"import { rollupPlugin } from './index.ts';\n\nexport default rollupPlugin;\n"]}
|
package/rollup.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as l}from"./chunk-
|
|
1
|
+
import{c as l}from"./chunk-JKPGDPK3.js";import"./chunk-D2NWA2J7.js";var r=l;export{r as default};
|
|
2
2
|
//# sourceMappingURL=rollup.js.map
|
package/rollup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rollup.ts"],"sourcesContent":["import { rollupPlugin } from './index';\n\nexport default rollupPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["rollup_default","rollupPlugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/rollup.ts"],"sourcesContent":["import { rollupPlugin } from './index.ts';\n\nexport default rollupPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["rollup_default","rollupPlugin"]}
|
package/rspack.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIA2CUGWDcjs = require('./chunk-IA2CUGWD.cjs');require('./chunk-TCJABTWK.cjs');var p=_chunkIA2CUGWDcjs.f;exports.default = p;
|
|
2
2
|
//# sourceMappingURL=rspack.cjs.map
|
package/rspack.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rspack.cjs","../src/rspack.ts"],"names":["rspack_default","rspackPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rspack.cjs","sourcesContent":[null,"import { rspackPlugin } from './index.ts';\n\nexport default rspackPlugin;\n"]}
|
package/rspack.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as r}from"./chunk-
|
|
1
|
+
import{f as r}from"./chunk-JKPGDPK3.js";import"./chunk-D2NWA2J7.js";var p=r;export{p as default};
|
|
2
2
|
//# sourceMappingURL=rspack.js.map
|
package/rspack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rspack.ts"],"sourcesContent":["import { rspackPlugin } from './index';\n\nexport default rspackPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["rspack_default","rspackPlugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/rspack.ts"],"sourcesContent":["import { rspackPlugin } from './index.ts';\n\nexport default rspackPlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["rspack_default","rspackPlugin"]}
|
package/vite.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIA2CUGWDcjs = require('./chunk-IA2CUGWD.cjs');require('./chunk-TCJABTWK.cjs');var i=_chunkIA2CUGWDcjs.b;exports.default = i;
|
|
2
2
|
//# sourceMappingURL=vite.cjs.map
|
package/vite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/vite.cjs","../src/vite.ts"],"names":["vite_default","vitePlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/vite.cjs","sourcesContent":[null,"import { vitePlugin } from './index.ts';\n\nexport default vitePlugin;\n"]}
|
package/vite.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as t}from"./chunk-
|
|
1
|
+
import{b as t}from"./chunk-JKPGDPK3.js";import"./chunk-D2NWA2J7.js";var i=t;export{i as default};
|
|
2
2
|
//# sourceMappingURL=vite.js.map
|
package/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vite.ts"],"sourcesContent":["import { vitePlugin } from './index';\n\nexport default vitePlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["vite_default","vitePlugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/vite.ts"],"sourcesContent":["import { vitePlugin } from './index.ts';\n\nexport default vitePlugin;\n"],"mappings":"oEAEA,IAAOA,EAAQC","names":["vite_default","vitePlugin"]}
|
package/webpack.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIA2CUGWDcjs = require('./chunk-IA2CUGWD.cjs');require('./chunk-TCJABTWK.cjs');var p=_chunkIA2CUGWDcjs.e;exports.default = p;
|
|
2
2
|
//# sourceMappingURL=webpack.cjs.map
|
package/webpack.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/webpack.cjs","../src/webpack.ts"],"names":["webpack_default","webpackPlugin"],"mappings":"AAAA,iIAAmC,gCAA6B,ICEzDA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/webpack.cjs","sourcesContent":[null,"import { webpackPlugin } from './index.ts';\n\nexport default webpackPlugin;\n"]}
|
package/webpack.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{e}from"./chunk-
|
|
1
|
+
import{e}from"./chunk-JKPGDPK3.js";import"./chunk-D2NWA2J7.js";var p=e;export{p as default};
|
|
2
2
|
//# sourceMappingURL=webpack.js.map
|
package/webpack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/webpack.ts"],"sourcesContent":["import { webpackPlugin } from './index';\n\nexport default webpackPlugin;\n"],"mappings":"+DAEA,IAAOA,EAAQC","names":["webpack_default","webpackPlugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/webpack.ts"],"sourcesContent":["import { webpackPlugin } from './index.ts';\n\nexport default webpackPlugin;\n"],"mappings":"+DAEA,IAAOA,EAAQC","names":["webpack_default","webpackPlugin"]}
|
package/chunk-3NAE3BLV.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as f,b as d,c as y,d as x,e as P}from"./chunk-EBLN5KE7.js";import{walk as h}from"estree-walker";import w from"magic-string";import{transpileFn as A}from"tinyest-for-wgsl";import{createUnplugin as T}from"unplugin";var N=(r={})=>({name:"unplugin-typegpu",transform(l,s){if(d(r,s,l))return;let a={tgpuAliases:new Set(r.forceTgpuAlias?[r.forceTgpuAlias]:[]),fileId:s},b=this.parse(l,{allowReturnOutsideFunction:!0}),u=[];h(b,{enter(e,m,c,p){let o=e;if(o.type==="ImportDeclaration"&&y(o,a),o.type==="CallExpression"&&x(o,a)){let i=o.arguments[0];i&&i.type!=="TemplateLiteral"&&i.type!=="Literal"&&u.push({varDecl:o,implementation:i})}}});let n=new w(l),g=a.tgpuAliases.values().next().value;if(g===void 0&&u.length>0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${s}`);for(let e of u){let{argNames:m,body:c,externalNames:p}=A(e.implementation);n.appendLeft(e.implementation.start,`${g}.__assignAst(`),n.appendRight(e.implementation.end,`, ${f({argNames:m,body:c,externalNames:p})}`),p.length>0?n.appendRight(e.implementation.end,`, {${p.join(", ")}})`):n.appendRight(e.implementation.end,")")}return{code:n.toString(),map:n.generateMap()}}}),t=T(N),S=t,E=t.vite,R=t.rollup,$=t.rolldown,L=t.webpack,U=t.rspack,_=t.esbuild,I=t.farm,M=P;export{S as a,E as b,R as c,$ as d,L as e,U as f,_ as g,I as h,M as i};
|
|
2
|
-
//# sourceMappingURL=chunk-3NAE3BLV.js.map
|
package/chunk-3NAE3BLV.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AnyNode, CallExpression } from 'acorn';\nimport { type Node, walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { type UnpluginFactory, createUnplugin } from 'unplugin';\nimport babel from './babel';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\ntype TgslFunctionDef = {\n varDecl: CallExpression;\n implementation: AnyNode;\n};\n\nconst typegpu: UnpluginFactory<TypegpuPluginOptions> = (\n options: TypegpuPluginOptions = {},\n) => ({\n name: 'unplugin-typegpu' as const,\n transform(code, id) {\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n };\n\n const ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n }) as Node;\n\n const tgslFunctionDefs: TgslFunctionDef[] = [];\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as AnyNode;\n\n if (node.type === 'ImportDeclaration') {\n gatherTgpuAliases(node, ctx);\n }\n\n if (node.type === 'CallExpression') {\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n !(implementation.type === 'TemplateLiteral') &&\n !(implementation.type === 'Literal')\n ) {\n tgslFunctionDefs.push({\n varDecl: node,\n implementation,\n });\n }\n }\n }\n },\n });\n\n const magicString = new MagicString(code);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n\n if (tgpuAlias === undefined && tgslFunctionDefs.length > 0) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${id}`,\n );\n }\n\n for (const expr of tgslFunctionDefs) {\n const { argNames, body, externalNames } = transpileFn(\n expr.implementation,\n );\n\n // Wrap the implementation in a call to `tgpu.__assignAst` to associate the AST with the implementation.\n magicString.appendLeft(\n expr.implementation.start,\n `${tgpuAlias}.__assignAst(`,\n );\n magicString.appendRight(\n expr.implementation.end,\n `, ${embedJSON({ argNames, body, externalNames })}`,\n );\n\n if (externalNames.length > 0) {\n magicString.appendRight(\n expr.implementation.end,\n `, {${externalNames.join(', ')}})`,\n );\n } else {\n magicString.appendRight(expr.implementation.end, ')');\n }\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap(),\n };\n },\n});\n\nconst unplugin = createUnplugin(typegpu);\n\nexport type { TypegpuPluginOptions } from './common';\n\nexport default unplugin;\n\nexport const vitePlugin = unplugin.vite;\nexport const rollupPlugin = unplugin.rollup;\nexport const rolldownPlugin = unplugin.rolldown;\nexport const webpackPlugin = unplugin.webpack;\nexport const rspackPlugin = unplugin.rspack;\nexport const esbuildPlugin = unplugin.esbuild;\nexport const farmPlugin = unplugin.farm;\nexport const babelPlugin = babel;\n"],"mappings":"oEACA,OAAoB,QAAAA,MAAY,gBAChC,OAAOC,MAAiB,eACxB,OAAS,eAAAC,MAAmB,mBAC5B,OAA+B,kBAAAC,MAAsB,WAgBrD,IAAMC,EAAiD,CAC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AAYG,EAAK,eAAe,IAAK,GAAG,CAExD,CAEA,MAAO,CACL,KAAMH,EAAY,SAAS,EAC3B,IAAKA,EAAY,YAAY,CAC/B,CACF,CACF,GAEMS,EAAWC,EAAe3B,CAAO,EAIhC4B,EAAQF,EAEFG,EAAaH,EAAS,KACtBI,EAAeJ,EAAS,OACxBK,EAAiBL,EAAS,SAC1BM,EAAgBN,EAAS,QACzBO,EAAeP,EAAS,OACxBQ,EAAgBR,EAAS,QACzBS,EAAaT,EAAS,KACtBU,EAAcC","names":["walk","MagicString","transpileFn","createUnplugin","typegpu","options","code","id","shouldSkipFile","ctx","ast","tgslFunctionDefs","walk","_node","_parent","prop","index","node","gatherTgpuAliases","isDoesCall","implementation","magicString","MagicString","tgpuAlias","expr","argNames","body","externalNames","transpileFn","embedJSON","unplugin","createUnplugin","index_default","vitePlugin","rollupPlugin","rolldownPlugin","webpackPlugin","rspackPlugin","esbuildPlugin","farmPlugin","babelPlugin","babel_default"]}
|
package/chunk-4AAFAGPC.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkKPVZYMM6cjs = require('./chunk-KPVZYMM6.cjs');var _estreewalker = require('estree-walker');var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);var _tinyestforwgsl = require('tinyest-for-wgsl');var _unplugin = require('unplugin');var N=(r={})=>({name:"unplugin-typegpu",transform(l,s){if(_chunkKPVZYMM6cjs.b.call(void 0, r,s,l))return;let a={tgpuAliases:new Set(r.forceTgpuAlias?[r.forceTgpuAlias]:[]),fileId:s},b=this.parse(l,{allowReturnOutsideFunction:!0}),u=[];_estreewalker.walk.call(void 0, b,{enter(e,m,c,p){let o=e;if(o.type==="ImportDeclaration"&&_chunkKPVZYMM6cjs.c.call(void 0, o,a),o.type==="CallExpression"&&_chunkKPVZYMM6cjs.d.call(void 0, o,a)){let i=o.arguments[0];i&&i.type!=="TemplateLiteral"&&i.type!=="Literal"&&u.push({varDecl:o,implementation:i})}}});let n=new (0, _magicstring2.default)(l),g=a.tgpuAliases.values().next().value;if(g===void 0&&u.length>0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${s}`);for(let e of u){let{argNames:m,body:c,externalNames:p}=_tinyestforwgsl.transpileFn.call(void 0, e.implementation);n.appendLeft(e.implementation.start,`${g}.__assignAst(`),n.appendRight(e.implementation.end,`, ${_chunkKPVZYMM6cjs.a.call(void 0, {argNames:m,body:c,externalNames:p})}`),p.length>0?n.appendRight(e.implementation.end,`, {${p.join(", ")}})`):n.appendRight(e.implementation.end,")")}return{code:n.toString(),map:n.generateMap()}}}),t=_unplugin.createUnplugin.call(void 0, N),S= exports.a =t,E= exports.b =t.vite,R= exports.c =t.rollup,$= exports.d =t.rolldown,L= exports.e =t.webpack,U= exports.f =t.rspack,_= exports.g =t.esbuild,I= exports.h =t.farm,M= exports.i =_chunkKPVZYMM6cjs.e;exports.a = S; exports.b = E; exports.c = R; exports.d = $; exports.e = L; exports.f = U; exports.g = _; exports.h = I; exports.i = M;
|
|
2
|
-
//# sourceMappingURL=chunk-4AAFAGPC.cjs.map
|
package/chunk-4AAFAGPC.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/iwo/Projects/wigsill/packages/unplugin-typegpu/dist/chunk-4AAFAGPC.cjs","../src/index.ts"],"names":["typegpu","options","code","id","shouldSkipFile","ctx","ast","tgslFunctionDefs","walk","_node","_parent","prop","index","node","gatherTgpuAliases","isDoesCall","implementation","magicString","MagicString","tgpuAlias"],"mappings":"AAAA,iOAAoE,6CCCpC,qGACR,kDACI,oCACyB,IAgB/CA,CAAAA,CAAiD,CACrDC,CAAAA,CAAgC,CAAC,CAAA,CAAA,EAAA,CAC7B,CACJ,IAAA,CAAM,kBAAA,CACN,SAAA,CAAUC,CAAAA,CAAMC,CAAAA,CAAI,CAClB,E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CAAA,CACvD,MAAM,IAAI,KAAA,CACR,CAAA,6DAAA,EAAgEJ,CAAE,CAAA,CAAA","file":"/Users/iwo/Projects/wigsill/packages/unplugin-typegpu/dist/chunk-4AAFAGPC.cjs","sourcesContent":[null,"import type { AnyNode, CallExpression } from 'acorn';\nimport { type Node, walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { type UnpluginFactory, createUnplugin } from 'unplugin';\nimport babel from './babel';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\ntype TgslFunctionDef = {\n varDecl: CallExpression;\n implementation: AnyNode;\n};\n\nconst typegpu: UnpluginFactory<TypegpuPluginOptions> = (\n options: TypegpuPluginOptions = {},\n) => ({\n name: 'unplugin-typegpu' as const,\n transform(code, id) {\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n };\n\n const ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n }) as Node;\n\n const tgslFunctionDefs: TgslFunctionDef[] = [];\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as AnyNode;\n\n if (node.type === 'ImportDeclaration') {\n gatherTgpuAliases(node, ctx);\n }\n\n if (node.type === 'CallExpression') {\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n !(implementation.type === 'TemplateLiteral') &&\n !(implementation.type === 'Literal')\n ) {\n tgslFunctionDefs.push({\n varDecl: node,\n implementation,\n });\n }\n }\n }\n },\n });\n\n const magicString = new MagicString(code);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n\n if (tgpuAlias === undefined && tgslFunctionDefs.length > 0) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${id}`,\n );\n }\n\n for (const expr of tgslFunctionDefs) {\n const { argNames, body, externalNames } = transpileFn(\n expr.implementation,\n );\n\n // Wrap the implementation in a call to `tgpu.__assignAst` to associate the AST with the implementation.\n magicString.appendLeft(\n expr.implementation.start,\n `${tgpuAlias}.__assignAst(`,\n );\n magicString.appendRight(\n expr.implementation.end,\n `, ${embedJSON({ argNames, body, externalNames })}`,\n );\n\n if (externalNames.length > 0) {\n magicString.appendRight(\n expr.implementation.end,\n `, {${externalNames.join(', ')}})`,\n );\n } else {\n magicString.appendRight(expr.implementation.end, ')');\n }\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap(),\n };\n },\n});\n\nconst unplugin = createUnplugin(typegpu);\n\nexport type { TypegpuPluginOptions } from './common';\n\nexport default unplugin;\n\nexport const vitePlugin = unplugin.vite;\nexport const rollupPlugin = unplugin.rollup;\nexport const rolldownPlugin = unplugin.rolldown;\nexport const webpackPlugin = unplugin.webpack;\nexport const rspackPlugin = unplugin.rspack;\nexport const esbuildPlugin = unplugin.esbuild;\nexport const farmPlugin = unplugin.farm;\nexport const babelPlugin = babel;\n"]}
|
package/chunk-EBLN5KE7.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import*as o from"@babel/standalone";import{transpileFn as T}from"tinyest-for-wgsl";function f(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function b(e,n){let t="",r=n;for(;;)if(r.type==="MemberExpression"){if(r.property.type!=="Identifier")break;t=t?`${r.property.name}.${t}`:r.property.name,r=r.object}else if(r.type==="Identifier"){t=t?`${r.name}.${t}`:r.name;break}else break;return e.tgpuAliases.has(t)}var x=/import.*from\s*['"]typegpu.*['"]/,A=/import\s*\(\s*['"]\s*typegpu.*['"]/,I=/require\s*\(\s*['"]\s*typegpu.*['"]\s*\)/;function m(e,n,t){if(t&&!(e!=null&&e.include)){if(!x.test(t)&&!I.test(t)&&!A.test(t))return!0}else if(e!=null&&e.include&&e.include!=="all"&&(!n||!e.include.some(r=>r.test(n))))return!0;return!1}function g(e,n){if(e.source.value==="typegpu")for(let t of e.specifiers)t.type==="ImportDefaultSpecifier"||t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&t.imported.name==="tgpu"?n.tgpuAliases.add(t.local.name):t.type==="ImportNamespaceSpecifier"&&n.tgpuAliases.add(`${t.local.name}.tgpu`)}function y(e,n){return e.callee.type==="MemberExpression"&&e.arguments.length===1&&e.callee.property.type==="Identifier"&&(e.callee.property.name==="procedure"&&b(n,e.callee.object)||e.callee.property.name==="does")}var d=o.packages.template,p=o.packages.types;function k(e){return{ImportDeclaration(n){g(n.node,e)},CallExpression(n){var r;let t=n.node;if(y(t,e)){let i=t.arguments[0];if(i&&(i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression")){let{argNames:a,body:s,externalNames:l}=T(i),u=e.tgpuAliases.values().next().value;if(u===void 0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${(r=e.fileId)!=null?r:""}`);n.replaceWith(p.callExpression(t.callee,[p.callExpression(d.expression(`${u}.__assignAst`)(),[i,d.expression`${f({argNames:a,body:s,externalNames:l})}`(),p.objectExpression(l.map(c=>p.objectProperty(p.identifier(c),p.identifier(c))))])])),n.skip()}}}}}function S(){return{visitor:{Program(e,n){var s;let t=(s=n.file)==null?void 0:s.code,r=n.opts,i=n.filename;if(m(r,i,t))return;let a={tgpuAliases:new Set(r!=null&&r.forceTgpuAlias?[r.forceTgpuAlias]:[]),fileId:i};e.traverse(k(a))}}}}export{f as a,m as b,g as c,y as d,S as e};
|
|
2
|
-
//# sourceMappingURL=chunk-EBLN5KE7.js.map
|
package/chunk-EBLN5KE7.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/babel.ts","../src/common.ts"],"sourcesContent":["import * as Babel from '@babel/standalone';\nimport type TemplateGenerator from '@babel/template';\nimport type { TraverseOptions } from '@babel/traverse';\nimport type * as t from '@babel/types';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\n// NOTE: @babel/standalone does expose internal packages, as specified in the docs, but the\n// typing for @babel/standalone does not expose them.\nconst template = (\n Babel as unknown as { packages: { template: typeof TemplateGenerator } }\n).packages.template;\nconst types = (Babel as unknown as { packages: { types: typeof t } }).packages\n .types;\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n CallExpression(path) {\n const node = path.node;\n\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const { argNames, body, externalNames } = transpileFn(implementation);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n if (tgpuAlias === undefined) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${ctx.fileId ?? ''}`,\n );\n }\n\n path.replaceWith(\n types.callExpression(node.callee, [\n types.callExpression(\n template.expression(`${tgpuAlias}.__assignAst`)(),\n [\n implementation,\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(\n types.identifier(name),\n types.identifier(name),\n ),\n ),\n ),\n ],\n ),\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // @ts-ignore\n const code: string | undefined = state.file?.code;\n // @ts-ignore\n const options: TypegpuPluginOptions | undefined = state.opts;\n // @ts-ignore\n const id: string | undefined = state.filename;\n\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options?.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n };\n\n path.traverse(functionVisitor(ctx));\n },\n } satisfies TraverseOptions,\n };\n}\n","import type * as babel from '@babel/types';\nimport type * as acorn from 'acorn';\n\nexport type Context = {\n /**\n * How the `tgpu` object is used in code. Since it can be aliased, we\n * need to catch that and act accordingly.\n */\n tgpuAliases: Set<string>;\n fileId?: string | undefined;\n};\n\nexport interface TypegpuPluginOptions {\n include?: 'all' | RegExp[];\n forceTgpuAlias?: string;\n}\n\nexport function embedJSON(jsValue: unknown) {\n return JSON.stringify(jsValue)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n\n/**\n * Checks if `node` is an alias for the 'tgpu' object, traditionally\n * available via `import tgpu from 'typegpu'`.\n */\nfunction isTgpu(ctx: Context, node: babel.Node | acorn.AnyNode): boolean {\n let path = '';\n\n let tail = node;\n while (true) {\n if (tail.type === 'MemberExpression') {\n if (tail.property.type !== 'Identifier') {\n // Not handling computed expressions.\n break;\n }\n\n path = path ? `${tail.property.name}.${path}` : tail.property.name;\n tail = tail.object;\n } else if (tail.type === 'Identifier') {\n path = path ? `${tail.name}.${path}` : tail.name;\n break;\n } else {\n break;\n }\n }\n\n return ctx.tgpuAliases.has(path);\n}\n\nconst typegpuImportRegex = /import.*from\\s*['\"]typegpu.*['\"]/;\nconst typegpuDynamicImportRegex = /import\\s*\\(\\s*['\"]\\s*typegpu.*['\"]/;\nconst typegpuRequireRegex = /require\\s*\\(\\s*['\"]\\s*typegpu.*['\"]\\s*\\)/;\n\nexport function shouldSkipFile(\n options: TypegpuPluginOptions | undefined,\n id: string | undefined,\n code: string | undefined,\n) {\n if (code && !options?.include) {\n if (\n !typegpuImportRegex.test(code) &&\n !typegpuRequireRegex.test(code) &&\n !typegpuDynamicImportRegex.test(code)\n ) {\n // No imports to `typegpu` or its sub modules, exiting early.\n return true;\n }\n } else if (\n options?.include &&\n options.include !== 'all' &&\n (!id || !options.include.some((pattern) => pattern.test(id)))\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function gatherTgpuAliases(\n node: acorn.ImportDeclaration | babel.ImportDeclaration,\n ctx: Context,\n) {\n if (node.source.value === 'typegpu') {\n for (const spec of node.specifiers) {\n if (\n // The default export of 'typegpu' is the `tgpu` object.\n spec.type === 'ImportDefaultSpecifier' ||\n // Aliasing 'tgpu' while importing, e.g. import { tgpu as t } from 'typegpu';\n (spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === 'tgpu')\n ) {\n ctx.tgpuAliases.add(spec.local.name);\n } else if (spec.type === 'ImportNamespaceSpecifier') {\n // Importing everything, e.g. import * as t from 'typegpu';\n ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);\n }\n }\n }\n}\n\nexport function isDoesCall(\n node: acorn.CallExpression | babel.CallExpression,\n ctx: Context,\n) {\n return (\n node.callee.type === 'MemberExpression' &&\n node.arguments.length === 1 &&\n node.callee.property.type === 'Identifier' &&\n ((node.callee.property.name === 'procedure' &&\n isTgpu(ctx, node.callee.object)) ||\n // Assuming that every call to `.does` is related to TypeGPU\n // because shells can be created separately from calls to `tgpu`,\n // making it hard to detect.\n node.callee.property.name === 'does')\n );\n}\n"],"mappings":"AAAA,UAAYA,MAAW,oBAIvB,OAAS,eAAAC,MAAmB,mBCarB,SAASC,EAAUC,EAAkB,CAC1C,OAAO,KAAK,UAAUA,CAAO,EAC1B,QAAQ,UAAW,SAAS,EAC5B,QAAQ,UAAW,SAAS,CACjC,CAMA,SAASC,EAAOC,EAAcC,EAA2C,CACvE,IAAIC,EAAO,GAEPC,EAAOF,EACX,OACE,GAAIE,EAAK,OAAS,mBAAoB,CACpC,GAAIA,EAAK,SAAS,OAAS,aAEzB,MAGFD,EAAOA,EAAO,GAAGC,EAAK,SAAS,IAAI,IAAID,CAAI,GAAKC,EAAK,SAAS,KAC9DA,EAAOA,EAAK,MACd,SAAWA,EAAK,OAAS,aAAc,CACrCD,EAAOA,EAAO,GAAGC,EAAK,IAAI,IAAID,CAAI,GAAKC,EAAK,KAC5C,KACF,KACE,OAIJ,OAAOH,EAAI,YAAY,IAAIE,CAAI,CACjC,CAEA,IAAME,EAAqB,mCACrBC,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Ae,OAAS,sBACvBA,EAAe,OAAS,2BAC1B,CACA,GAAM,CAAE,SAAAC,EAAU,KAAAC,EAAM,cAAAC,CAAc,EAAIC,EAAYJ,CAAc,EAC9DK,EAAYX,EAAI,YAAY,OAAO,EAAE,KAAK,EAAE,MAClD,GAAIW,IAAc,OAChB,MAAM,IAAI,MACR,iEAAgER,EAAAH,EAAI,SAAJ,KAAAG,EAAc,EAAE,EAClF,EAGFF,EAAK,YACHH,EAAM,eAAeM,EAAK,OAAQ,CAChCN,EAAM,eACJD,EAAS,WAAW,GAAGc,CAAS,cAAc,EAAE,EAChD,CACEL,EACAT,EAAS,aAAae,EAAU,CAAE,SAAAL,EAAU,KAAAC,EAAM,cAAAC,CAAc,CAAC,CAAC,GAAG,EACrEX,EAAM,iBACJW,EAAc,IAAKI,GACjBf,EAAM,eACJA,EAAM,WAAWe,CAAI,EACrBf,EAAM,WAAWe,CAAI,CACvB,CACF,CACF,CACF,CACF,CACF,CAAC,CACH,EAEAZ,EAAK,KAAK,CACZ,CACF,CACF,CACF,CACF,CAEe,SAARa,GAAoB,CACzB,MAAO,CACL,QAAS,CACP,QAAQb,EAAMc,EAAO,CA7E3B,IAAAZ,EA+EQ,IAAMa,GAA2Bb,EAAAY,EAAM,OAAN,YAAAZ,EAAY,KAEvCc,EAA4CF,EAAM,KAElDG,EAAyBH,EAAM,SAErC,GAAII,EAAeF,EAASC,EAAIF,CAAI,EAClC,OAGF,IAAMhB,EAAe,CACnB,YAAa,IAAI,IACfiB,GAAA,MAAAA,EAAS,eAAiB,CAACA,EAAQ,cAAc,EAAI,CAAC,CACxD,EACA,OAAQC,CACV,EAEAjB,EAAK,SAASF,EAAgBC,CAAG,CAAC,CACpC,CACF,CACF,CACF","names":["Babel","transpileFn","embedJSON","jsValue","isTgpu","ctx","node","path","tail","typegpuImportRegex","typegpuDynamicImportRegex","typegpuRequireRegex","shouldSkipFile","options","id","code","pattern","gatherTgpuAliases","spec","isDoesCall","template","types","functionVisitor","ctx","path","gatherTgpuAliases","_a","node","isDoesCall","implementation","argNames","body","externalNames","transpileFn","tgpuAlias","embedJSON","name","babel_default","state","code","options","id","shouldSkipFile"]}
|
package/chunk-KPVZYMM6.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _standalone = require('@babel/standalone'); var o = _interopRequireWildcard(_standalone);var _tinyestforwgsl = require('tinyest-for-wgsl');function f(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function b(e,n){let t="",r=n;for(;;)if(r.type==="MemberExpression"){if(r.property.type!=="Identifier")break;t=t?`${r.property.name}.${t}`:r.property.name,r=r.object}else if(r.type==="Identifier"){t=t?`${r.name}.${t}`:r.name;break}else break;return e.tgpuAliases.has(t)}var x=/import.*from\s*['"]typegpu.*['"]/,A=/import\s*\(\s*['"]\s*typegpu.*['"]/,I=/require\s*\(\s*['"]\s*typegpu.*['"]\s*\)/;function m(e,n,t){if(t&&!(e!=null&&e.include)){if(!x.test(t)&&!I.test(t)&&!A.test(t))return!0}else if(e!=null&&e.include&&e.include!=="all"&&(!n||!e.include.some(r=>r.test(n))))return!0;return!1}function g(e,n){if(e.source.value==="typegpu")for(let t of e.specifiers)t.type==="ImportDefaultSpecifier"||t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&t.imported.name==="tgpu"?n.tgpuAliases.add(t.local.name):t.type==="ImportNamespaceSpecifier"&&n.tgpuAliases.add(`${t.local.name}.tgpu`)}function y(e,n){return e.callee.type==="MemberExpression"&&e.arguments.length===1&&e.callee.property.type==="Identifier"&&(e.callee.property.name==="procedure"&&b(n,e.callee.object)||e.callee.property.name==="does")}var d=o.packages.template,p=o.packages.types;function k(e){return{ImportDeclaration(n){g(n.node,e)},CallExpression(n){var r;let t=n.node;if(y(t,e)){let i=t.arguments[0];if(i&&(i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression")){let{argNames:a,body:s,externalNames:l}=_tinyestforwgsl.transpileFn.call(void 0, i),u=e.tgpuAliases.values().next().value;if(u===void 0)throw new Error(`No tgpu import found, cannot assign ast to function in file: ${(r=e.fileId)!=null?r:""}`);n.replaceWith(p.callExpression(t.callee,[p.callExpression(d.expression(`${u}.__assignAst`)(),[i,d.expression`${f({argNames:a,body:s,externalNames:l})}`(),p.objectExpression(l.map(c=>p.objectProperty(p.identifier(c),p.identifier(c))))])])),n.skip()}}}}}function S(){return{visitor:{Program(e,n){var s;let t=(s=n.file)==null?void 0:s.code,r=n.opts,i=n.filename;if(m(r,i,t))return;let a={tgpuAliases:new Set(r!=null&&r.forceTgpuAlias?[r.forceTgpuAlias]:[]),fileId:i};e.traverse(k(a))}}}}exports.a = f; exports.b = m; exports.c = g; exports.d = y; exports.e = S;
|
|
2
|
-
//# sourceMappingURL=chunk-KPVZYMM6.cjs.map
|
package/chunk-KPVZYMM6.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/babel.ts","../src/common.ts"],"names":["embedJSON","jsValue","isTgpu","ctx","node","path","tail"],"mappings":"AAAA,wbAAuB,kDAIK,SCaZA,CAAAA,CAAUC,CAAAA,CAAkB,CAC1C,OAAO,IAAA,CAAK,SAAA,CAAUA,CAAO,CAAA,CAC1B,OAAA,CAAQ,SAAA,CAAW,SAAS,CAAA,CAC5B,OAAA,CAAQ,SAAA,CAAW,SAAS,CACjC,CAMA,SAASC,CAAAA,CAAOC,CAAAA,CAAcC,CAAAA,CAA2C,CACvE,IAAIC,CAAAA,CAAO,EAAA,CAEPC,CAAAA,CAAOF,CAAAA,CACX,GAAA,CAAA,CAAA,CAAA,CACE,EAAA,CAAIE,CAAAA,CAAK,IAAA,GAAS,kBAAA,CAAoB,CACpC,EAAA,CAAIA,CAAAA,CAAK,QAAA,CAAS,IAAA,GAAS,YAAA,CAEzB,KAAA,CAGFD,CAAAA,CAAOA,CAAAA,CAAO,CAAA,EAAA","file":"/Users/iwo/Projects/wigsill/packages/unplugin-typegpu/dist/chunk-KPVZYMM6.cjs","sourcesContent":["import * as Babel from '@babel/standalone';\nimport type TemplateGenerator from '@babel/template';\nimport type { TraverseOptions } from '@babel/traverse';\nimport type * as t from '@babel/types';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\n// NOTE: @babel/standalone does expose internal packages, as specified in the docs, but the\n// typing for @babel/standalone does not expose them.\nconst template = (\n Babel as unknown as { packages: { template: typeof TemplateGenerator } }\n).packages.template;\nconst types = (Babel as unknown as { packages: { types: typeof t } }).packages\n .types;\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n CallExpression(path) {\n const node = path.node;\n\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const { argNames, body, externalNames } = transpileFn(implementation);\n const tgpuAlias = ctx.tgpuAliases.values().next().value;\n if (tgpuAlias === undefined) {\n throw new Error(\n `No tgpu import found, cannot assign ast to function in file: ${ctx.fileId ?? ''}`,\n );\n }\n\n path.replaceWith(\n types.callExpression(node.callee, [\n types.callExpression(\n template.expression(`${tgpuAlias}.__assignAst`)(),\n [\n implementation,\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(\n types.identifier(name),\n types.identifier(name),\n ),\n ),\n ),\n ],\n ),\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // @ts-ignore\n const code: string | undefined = state.file?.code;\n // @ts-ignore\n const options: TypegpuPluginOptions | undefined = state.opts;\n // @ts-ignore\n const id: string | undefined = state.filename;\n\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options?.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n };\n\n path.traverse(functionVisitor(ctx));\n },\n } satisfies TraverseOptions,\n };\n}\n","import type * as babel from '@babel/types';\nimport type * as acorn from 'acorn';\n\nexport type Context = {\n /**\n * How the `tgpu` object is used in code. Since it can be aliased, we\n * need to catch that and act accordingly.\n */\n tgpuAliases: Set<string>;\n fileId?: string | undefined;\n};\n\nexport interface TypegpuPluginOptions {\n include?: 'all' | RegExp[];\n forceTgpuAlias?: string;\n}\n\nexport function embedJSON(jsValue: unknown) {\n return JSON.stringify(jsValue)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n\n/**\n * Checks if `node` is an alias for the 'tgpu' object, traditionally\n * available via `import tgpu from 'typegpu'`.\n */\nfunction isTgpu(ctx: Context, node: babel.Node | acorn.AnyNode): boolean {\n let path = '';\n\n let tail = node;\n while (true) {\n if (tail.type === 'MemberExpression') {\n if (tail.property.type !== 'Identifier') {\n // Not handling computed expressions.\n break;\n }\n\n path = path ? `${tail.property.name}.${path}` : tail.property.name;\n tail = tail.object;\n } else if (tail.type === 'Identifier') {\n path = path ? `${tail.name}.${path}` : tail.name;\n break;\n } else {\n break;\n }\n }\n\n return ctx.tgpuAliases.has(path);\n}\n\nconst typegpuImportRegex = /import.*from\\s*['\"]typegpu.*['\"]/;\nconst typegpuDynamicImportRegex = /import\\s*\\(\\s*['\"]\\s*typegpu.*['\"]/;\nconst typegpuRequireRegex = /require\\s*\\(\\s*['\"]\\s*typegpu.*['\"]\\s*\\)/;\n\nexport function shouldSkipFile(\n options: TypegpuPluginOptions | undefined,\n id: string | undefined,\n code: string | undefined,\n) {\n if (code && !options?.include) {\n if (\n !typegpuImportRegex.test(code) &&\n !typegpuRequireRegex.test(code) &&\n !typegpuDynamicImportRegex.test(code)\n ) {\n // No imports to `typegpu` or its sub modules, exiting early.\n return true;\n }\n } else if (\n options?.include &&\n options.include !== 'all' &&\n (!id || !options.include.some((pattern) => pattern.test(id)))\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function gatherTgpuAliases(\n node: acorn.ImportDeclaration | babel.ImportDeclaration,\n ctx: Context,\n) {\n if (node.source.value === 'typegpu') {\n for (const spec of node.specifiers) {\n if (\n // The default export of 'typegpu' is the `tgpu` object.\n spec.type === 'ImportDefaultSpecifier' ||\n // Aliasing 'tgpu' while importing, e.g. import { tgpu as t } from 'typegpu';\n (spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === 'tgpu')\n ) {\n ctx.tgpuAliases.add(spec.local.name);\n } else if (spec.type === 'ImportNamespaceSpecifier') {\n // Importing everything, e.g. import * as t from 'typegpu';\n ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);\n }\n }\n }\n}\n\nexport function isDoesCall(\n node: acorn.CallExpression | babel.CallExpression,\n ctx: Context,\n) {\n return (\n node.callee.type === 'MemberExpression' &&\n node.arguments.length === 1 &&\n node.callee.property.type === 'Identifier' &&\n ((node.callee.property.name === 'procedure' &&\n isTgpu(ctx, node.callee.object)) ||\n // Assuming that every call to `.does` is related to TypeGPU\n // because shells can be created separately from calls to `tgpu`,\n // making it hard to detect.\n node.callee.property.name === 'does')\n );\n}\n"]}
|