unplugin-typegpu 0.1.4 → 0.2.0
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.js +1 -1
- package/chunk-4DTTWQTW.cjs +6 -0
- package/chunk-4DTTWQTW.cjs.map +1 -0
- package/chunk-HGJBG4QQ.js +6 -0
- package/chunk-HGJBG4QQ.js.map +1 -0
- package/chunk-RRLX57NP.js +6 -0
- package/chunk-RRLX57NP.js.map +1 -0
- package/chunk-XXTHHPRC.cjs +6 -0
- package/chunk-XXTHHPRC.cjs.map +1 -0
- package/esbuild.cjs +1 -1
- package/esbuild.cjs.map +1 -1
- package/esbuild.d.cts +2 -1
- package/esbuild.d.ts +2 -1
- package/esbuild.js +1 -1
- package/farm.cjs +1 -1
- package/farm.cjs.map +1 -1
- package/farm.d.cts +2 -1
- package/farm.d.ts +2 -1
- package/farm.js +1 -1
- package/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.d.cts +4 -2
- package/index.d.ts +4 -2
- package/index.js +1 -1
- package/package.json +2 -2
- package/rolldown.cjs +1 -1
- package/rolldown.cjs.map +1 -1
- package/rolldown.d.cts +2 -1
- package/rolldown.d.ts +2 -1
- package/rolldown.js +1 -1
- package/rollup.cjs +1 -1
- package/rollup.cjs.map +1 -1
- package/rollup.d.cts +2 -1
- package/rollup.d.ts +2 -1
- package/rollup.js +1 -1
- package/rspack.cjs +1 -1
- package/rspack.cjs.map +1 -1
- package/rspack.d.cts +2 -1
- package/rspack.d.ts +2 -1
- package/rspack.js +1 -1
- package/vite.cjs +1 -1
- package/vite.cjs.map +1 -1
- package/vite.d.cts +2 -1
- package/vite.d.ts +2 -1
- package/vite.js +1 -1
- package/webpack.cjs +1 -1
- package/webpack.cjs.map +1 -1
- package/webpack.d.cts +2 -1
- package/webpack.d.ts +2 -1
- package/webpack.js +1 -1
- package/chunk-DO6SOWHC.js +0 -6
- package/chunk-DO6SOWHC.js.map +0 -1
- package/chunk-G6NIIU55.cjs +0 -6
- package/chunk-G6NIIU55.cjs.map +0 -1
- package/chunk-LI2BURW4.cjs +0 -10
- package/chunk-LI2BURW4.cjs.map +0 -1
- package/chunk-LML6XL7I.js +0 -10
- package/chunk-LML6XL7I.js.map +0 -1
- /package/{LICENSE.md → LICENSE} +0 -0
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 _chunk4DTTWQTWcjs = require('./chunk-4DTTWQTW.cjs');exports.default = _chunk4DTTWQTWcjs.g;
|
|
2
2
|
//# sourceMappingURL=babel.cjs.map
|
package/babel.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/babel.cjs"],"names":[],"mappings":"AAAA,iIAAwC,sCAAqB","file":"/Users/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/babel.cjs"}
|
package/babel.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as a}from"./chunk-
|
|
1
|
+
import{g as a}from"./chunk-HGJBG4QQ.js";export{a as default};
|
|
2
2
|
//# sourceMappingURL=babel.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
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; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _standalone = require('@babel/standalone'); var b = _interopRequireWildcard(_standalone);var _tinyest = require('tinyest');var _tinyestforwgsl = require('tinyest-for-wgsl');var L={include:[/\.m?[jt]sx?$/],autoNamingEnabled:!0};function F(r){return JSON.stringify(r).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function k(r,e){let t="",n=e;for(;;)if(n.type==="MemberExpression"){if((n.property.type==="Literal"||n.property.type==="StringLiteral")&&n.property.value==="~unstable"){n=n.object;continue}if(n.property.type!=="Identifier")break;t=t?`${n.property.name}.${t}`:n.property.name,n=n.object}else if(n.type==="Identifier"){t=t?`${n.name}.${t}`:n.name;break}else break;return r.tgpuAliases.has(t)}function T(r,e){if(r.source.value==="typegpu")for(let t of r.specifiers)t.type==="ImportDefaultSpecifier"||t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&t.imported.name==="tgpu"?e.tgpuAliases.add(t.local.name):t.type==="ImportNamespaceSpecifier"&&e.tgpuAliases.add(`${t.local.name}.tgpu`)}var A=["fn","vertexFn","fragmentFn","computeFn"];function m(r,e){return r.callee.type==="CallExpression"&&r.callee.callee.type==="MemberExpression"&&r.callee.callee.property.type==="Identifier"&&A.includes(r.callee.callee.property.name)&&r.arguments.length===1&&k(e,r.callee.callee.object)}var E=["bindGroupLayout","vertexLayout","slot","accessor","privateVar","workgroupVar","const",...A,"struct","unstruct","createBuffer","createMutable","createReadonly","createUniform","createQuerySet","createPipeline","createTexture","sampler","comparisonSampler"];function l(r,e){if(r.type==="CallExpression"){if(m(r,e)||r.callee.type==="Identifier"&&E.includes(r.callee.name))return!0;if(r.callee.type==="MemberExpression"){if(r.callee.property.type==="Identifier"){if(E.includes(r.callee.property.name))return!0;if(r.callee.property.name==="$name")return!1}return l(r.callee.object,e)}}return r.type==="TaggedTemplateExpression"?l(r.tag,e):!1}function p(r,e,t){r.autoNamingEnabled&&(e.type==="VariableDeclarator"&&e.id.type==="Identifier"&&e.init&&l(e.init,r)?t(e.init,e.id.name):e.type==="AssignmentExpression"&&e.left.type==="Identifier"&&l(e.right,r)?t(e.right,e.left.name):(e.type==="Property"||e.type==="ObjectProperty")&&e.key.type==="Identifier"&&l(e.value,r)&&t(e.value,e.key.name))}var S="kernel";var _path = require('path');var _picomatch = require('picomatch'); var _picomatch2 = _interopRequireDefault(_picomatch);function I(r){let e=r||[];return Array.isArray(e)?e:[e]}var w=/\\/g;function u(r){return r.replace(w,"/")}var R=/^(?:\/|(?:[A-Z]:)?[/\\|])/i;function _(r){return R.test(r)}function $(r,e){if(r.startsWith("**")||_(r))return u(r);let t=_path.resolve.call(void 0, e,r);return u(t)}function N(r){if(r instanceof RegExp)return o=>{let a=u(o),f=r.test(a);return r.lastIndex=0,f};let e=process.cwd(),t=$(r,e),n=_picomatch2.default.call(void 0, t,{dot:!0});return o=>{let a=u(o);return n(a)}}function h(r,e){if(!(!r&&!e))return t=>r!=null&&r.some(n=>n(t))?!1:e!=null&&e.some(n=>n(t))?!0:!(e&&e.length>0)}function D(r){return typeof r=="string"||r instanceof RegExp?{include:[r]}:Array.isArray(r)?{include:r}:{exclude:r.exclude?I(r.exclude):void 0,include:r.include?I(r.include):void 0}}function j(r){if(!r)return;let{exclude:e,include:t}=D(r),n=e==null?void 0:e.map(N),o=t==null?void 0:t.map(N);return h(n,o)}function v(r){let e=j(r);return e?t=>!!e(t):void 0}var P=b.packages.template,i=b.packages.types;function d(r){var e,t;return("directives"in r.body?(t=(e=r.body)==null?void 0:e.directives)!=null?t:[]:[]).map(n=>n.value.value).includes(S)}function s(r){return i.identifier(r)}function c(r){let{params:e,body:t,externalNames:n}=_tinyestforwgsl.transpileFn.call(void 0, r),o=`{
|
|
2
|
+
v: ${_tinyest.FORMAT_VERSION},
|
|
3
|
+
ast: ${F({params:e,body:t,externalNames:n})},
|
|
4
|
+
externals: {${n.join(", ")}},
|
|
5
|
+
}`;return i.callExpression(i.arrowFunctionExpression([s("$")],i.logicalExpression("&&",i.callExpression(i.memberExpression(i.assignmentExpression("??=",i.memberExpression(s("globalThis"),s("__TYPEGPU_META__")),i.newExpression(s("WeakMap"),[])),s("set")),[i.assignmentExpression("=",i.memberExpression(s("$"),s("f")),r),P.expression`${o}`()]),i.memberExpression(s("$"),s("f")))),[i.objectExpression([])])}function g(r,e){return i.callExpression(P.expression("globalThis.__TYPEGPU_AUTONAME__ ?? (a => a)",{placeholderPattern:!1})(),[r,i.stringLiteral(e)])}function G(r){return{VariableDeclarator(e){p(r,e.node,(t,n)=>{e.get("init").replaceWith(g(t,n))})},AssignmentExpression(e){p(r,e.node,(t,n)=>{e.get("right").replaceWith(g(t,n))})},ObjectProperty(e){p(r,e.node,(t,n)=>{e.get("value").replaceWith(g(t,n))})},ImportDeclaration(e){T(e.node,r)},ArrowFunctionExpression(e){d(e.node)&&(e.replaceWith(c(e.node)),e.skip())},FunctionExpression(e){d(e.node)&&(e.replaceWith(c(e.node)),e.skip())},FunctionDeclaration(e){let t=e.node,n=i.functionExpression(t.id,t.params,t.body);if(d(e.node)&&t.id){let o=c(n);e.replaceWith(i.variableDeclaration("const",[i.variableDeclarator(t.id,o)])),e.skip()}},CallExpression(e){let t=e.node;if(m(t,r)){let n=t.arguments[0];if(n&&(n.type==="FunctionExpression"||n.type==="ArrowFunctionExpression")){let o=c(n);e.replaceWith(i.callExpression(t.callee,[o])),e.skip()}}}}}function Y(){return{visitor:{Program(r,e){var y,x;let t=(y=e.file)==null?void 0:y.code,n=e.opts,o=e.filename,a=v(n);if(o&&a&&!(a!=null&&a(o)))return;let f={tgpuAliases:new Set(n!=null&&n.forceTgpuAlias?[n.forceTgpuAlias]:[]),fileId:o,autoNamingEnabled:(x=n==null?void 0:n.autoNamingEnabled)!=null?x:!0};r.traverse(G(f))}}}}exports.a = L; exports.b = F; exports.c = T; exports.d = m; exports.e = p; exports.f = S; exports.g = Y;
|
|
6
|
+
//# sourceMappingURL=chunk-4DTTWQTW.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/babel.ts","../src/common.ts"],"names":["defaultOptions","embedJSON","jsValue","isTgpu","ctx","node","path","tail"],"mappings":"AAAA,whBAAuB,kCAIQ,kDACH,ICiBfA,CAAAA,CAAiB,CAC5B,OAAA,CAAS,CAAC,cAAc,CAAA,CACxB,iBAAA,CAAmB,CAAA,CACrB,CAAA,CAEO,SAASC,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,CAAA,CACGA,CAAAA,CAAK,QAAA,CAAS,IAAA,GAAS,SAAA,EACtBA,CAAAA,CAAK,QAAA,CAAS,IAAA,GAAS,eAAA,CAAA,EACzBA,CAAAA,CAAK,QAAA,CAAS,KAAA,GAAU,WAAA,CACxB,CAEAA,CAAAA,CAAOA,CAAAA,CAAK,MAAA,CACZ,QACF,CAEA,EAAA,CAAIA,CAAAA,CAAK,QAAA,CAAS,IAAA,GAAS,YAAA,CAEzB,KAAA,CAGFD,CAAAA,CAAOA,CAAAA,CAAO,CAAA,EAAA;ADVG,OAAA;AAC8B,SAAA;AACX,gBAAA;AAuCpC,GAAA","file":"/Users/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/chunk-4DTTWQTW.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 { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n embedJSON,\n gatherTgpuAliases,\n isShellImplementationCall,\n kernelDirective,\n type Options,\n performExpressionNaming,\n} from './common.ts';\nimport { createFilterForId } from './filter.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 containsKernelDirective(\n node:\n | babel.FunctionDeclaration\n | babel.FunctionExpression\n | babel.ArrowFunctionExpression,\n): boolean {\n return ((\n 'directives' in node.body ? (node.body?.directives ?? []) : []\n )\n .map((directive) => directive.value.value))\n .includes(kernelDirective);\n}\n\nfunction i(identifier: string): babel.Identifier {\n return types.identifier(identifier);\n}\n\nfunction functionToTranspiled(\n node: babel.ArrowFunctionExpression | babel.FunctionExpression,\n): babel.CallExpression {\n const { params, body, externalNames } = transpileFn(node);\n\n const metadata = `{\n v: ${FORMAT_VERSION},\n ast: ${embedJSON({ params, body, externalNames })},\n externals: {${externalNames.join(', ')}},\n }`;\n\n return types.callExpression(\n types.arrowFunctionExpression(\n [i('$')],\n types.logicalExpression(\n '&&',\n types.callExpression(\n types.memberExpression(\n types.assignmentExpression(\n '??=',\n types.memberExpression(i('globalThis'), i('__TYPEGPU_META__')),\n types.newExpression(i('WeakMap'), []),\n ),\n i('set'),\n ),\n [\n types.assignmentExpression(\n '=',\n types.memberExpression(i('$'), i('f')),\n node,\n ),\n template.expression`${metadata}`(),\n ],\n ),\n types.memberExpression(i('$'), i('f')),\n ),\n ),\n [types.objectExpression([])],\n );\n}\n\nfunction wrapInAutoName(\n node: babel.Expression,\n name: string,\n) {\n return types.callExpression(\n template.expression('globalThis.__TYPEGPU_AUTONAME__ ?? (a => a)', {\n placeholderPattern: false,\n })(),\n [node, types.stringLiteral(name)],\n );\n}\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n VariableDeclarator(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('init').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n AssignmentExpression(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('right').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n ObjectProperty(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('value').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n ArrowFunctionExpression(path) {\n if (containsKernelDirective(path.node)) {\n path.replaceWith(functionToTranspiled(path.node));\n path.skip();\n }\n },\n\n FunctionExpression(path) {\n if (containsKernelDirective(path.node)) {\n path.replaceWith(functionToTranspiled(path.node));\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\n if (containsKernelDirective(path.node) && node.id) {\n const transpiled = functionToTranspiled(expression);\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 transpiled = functionToTranspiled(\n implementation,\n ) as babel.CallExpression;\n\n path.replaceWith(\n types.callExpression(node.callee, [\n transpiled,\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const code: string | undefined = (state as any).file?.code;\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const options: Options | undefined = (state as any).opts;\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const id: string | undefined = (state as any).filename;\n\n const filter = createFilterForId(options);\n if (id && filter && !filter?.(id)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options?.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n autoNamingEnabled: options?.autoNamingEnabled ?? true,\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';\nimport type { FilterPattern } from 'unplugin';\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 autoNamingEnabled: boolean;\n};\n\nexport interface Options {\n include?: FilterPattern;\n exclude?: FilterPattern;\n enforce?: 'post' | 'pre' | undefined;\n forceTgpuAlias?: string;\n autoNamingEnabled?: boolean;\n}\n\nexport const defaultOptions = {\n include: [/\\.m?[jt]sx?$/],\n autoNamingEnabled: true,\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 (\n (tail.property.type === 'Literal' ||\n tail.property.type === 'StringLiteral') &&\n tail.property.value === '~unstable'\n ) {\n // Bypassing the '~unstable' property.\n tail = tail.object;\n continue;\n }\n\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\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 && isTgpu(ctx, node.callee.callee.object)\n );\n}\n\nconst resourceConstructors: string[] = [\n // tgpu\n 'bindGroupLayout',\n 'vertexLayout',\n // tgpu['~unstable']\n 'slot',\n 'accessor',\n 'privateVar',\n 'workgroupVar',\n 'const',\n ...fnShellFunctionNames,\n // d\n 'struct',\n 'unstruct',\n // root\n 'createBuffer',\n 'createMutable',\n 'createReadonly',\n 'createUniform',\n 'createQuerySet',\n // root['~unstable']\n 'createPipeline',\n 'createTexture',\n 'sampler',\n 'comparisonSampler',\n];\n\n/**\n * Checks if `node` should be wrapped in an autoname function.\n * Since it is mostly for debugging and clean WGSL generation,\n * some false positives and false negatives are admissible.\n */\nfunction containsResourceConstructorCall(\n node: acorn.AnyNode | babel.Node,\n ctx: Context,\n) {\n if (node.type === 'CallExpression') {\n if (isShellImplementationCall(node, ctx)) {\n return true;\n }\n // struct({...})\n if (\n node.callee.type === 'Identifier' &&\n resourceConstructors.includes(node.callee.name)\n ) {\n return true;\n }\n if (node.callee.type === 'MemberExpression') {\n if (node.callee.property.type === 'Identifier') {\n // root.createBuffer({...})\n if (resourceConstructors.includes(node.callee.property.name)) {\n return true;\n }\n if (node.callee.property.name === '$name') {\n return false;\n }\n }\n // root.createBuffer(d.f32).$usage('storage')\n return containsResourceConstructorCall(node.callee.object, ctx);\n }\n }\n if (node.type === 'TaggedTemplateExpression') {\n return containsResourceConstructorCall(node.tag, ctx);\n }\n return false;\n}\n\ntype ExpressionFor<T extends acorn.AnyNode | babel.Node> = T extends\n acorn.AnyNode ? acorn.Expression : babel.Expression;\n\n/**\n * Checks if `node` contains a label and a tgpu expression that could be named.\n * If so, it calls the provided callback. Nodes selected for naming include:\n *\n * `let name = tgpu.bindGroupLayout({});` (VariableDeclarator)\n *\n * `name = tgpu.bindGroupLayout({});` (AssignmentExpression)\n *\n * `property: tgpu.bindGroupLayout({})` (Property/ObjectProperty)\n *\n * Since it is mostly for debugging and clean WGSL generation,\n * some false positives and false negatives are admissible.\n *\n * @privateRemarks\n * When adding new checks, you need to call this method in the corresponding node in Babel.\n */\nexport function performExpressionNaming<T extends acorn.AnyNode | babel.Node>(\n ctx: Context,\n node: T,\n namingCallback: (node: ExpressionFor<T>, name: string) => void,\n) {\n if (!ctx.autoNamingEnabled) {\n return;\n }\n\n if (\n node.type === 'VariableDeclarator' &&\n node.id.type === 'Identifier' &&\n node.init &&\n containsResourceConstructorCall(node.init, ctx)\n ) {\n namingCallback(node.init as ExpressionFor<T>, node.id.name);\n } else if (\n node.type === 'AssignmentExpression' &&\n node.left.type === 'Identifier' &&\n containsResourceConstructorCall(node.right, ctx)\n ) {\n namingCallback(node.right as ExpressionFor<T>, node.left.name);\n } else if (\n (node.type === 'Property' || node.type === 'ObjectProperty') &&\n node.key.type === 'Identifier' &&\n containsResourceConstructorCall(node.value, ctx)\n ) {\n namingCallback(node.value as ExpressionFor<T>, node.key.name);\n }\n}\n\nexport const kernelDirective = 'kernel';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import*as b from"@babel/standalone";import{FORMAT_VERSION as M}from"tinyest";import{transpileFn as W}from"tinyest-for-wgsl";var L={include:[/\.m?[jt]sx?$/],autoNamingEnabled:!0};function F(r){return JSON.stringify(r).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function k(r,e){let t="",n=e;for(;;)if(n.type==="MemberExpression"){if((n.property.type==="Literal"||n.property.type==="StringLiteral")&&n.property.value==="~unstable"){n=n.object;continue}if(n.property.type!=="Identifier")break;t=t?`${n.property.name}.${t}`:n.property.name,n=n.object}else if(n.type==="Identifier"){t=t?`${n.name}.${t}`:n.name;break}else break;return r.tgpuAliases.has(t)}function T(r,e){if(r.source.value==="typegpu")for(let t of r.specifiers)t.type==="ImportDefaultSpecifier"||t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&t.imported.name==="tgpu"?e.tgpuAliases.add(t.local.name):t.type==="ImportNamespaceSpecifier"&&e.tgpuAliases.add(`${t.local.name}.tgpu`)}var A=["fn","vertexFn","fragmentFn","computeFn"];function m(r,e){return r.callee.type==="CallExpression"&&r.callee.callee.type==="MemberExpression"&&r.callee.callee.property.type==="Identifier"&&A.includes(r.callee.callee.property.name)&&r.arguments.length===1&&k(e,r.callee.callee.object)}var E=["bindGroupLayout","vertexLayout","slot","accessor","privateVar","workgroupVar","const",...A,"struct","unstruct","createBuffer","createMutable","createReadonly","createUniform","createQuerySet","createPipeline","createTexture","sampler","comparisonSampler"];function l(r,e){if(r.type==="CallExpression"){if(m(r,e)||r.callee.type==="Identifier"&&E.includes(r.callee.name))return!0;if(r.callee.type==="MemberExpression"){if(r.callee.property.type==="Identifier"){if(E.includes(r.callee.property.name))return!0;if(r.callee.property.name==="$name")return!1}return l(r.callee.object,e)}}return r.type==="TaggedTemplateExpression"?l(r.tag,e):!1}function p(r,e,t){r.autoNamingEnabled&&(e.type==="VariableDeclarator"&&e.id.type==="Identifier"&&e.init&&l(e.init,r)?t(e.init,e.id.name):e.type==="AssignmentExpression"&&e.left.type==="Identifier"&&l(e.right,r)?t(e.right,e.left.name):(e.type==="Property"||e.type==="ObjectProperty")&&e.key.type==="Identifier"&&l(e.value,r)&&t(e.value,e.key.name))}var S="kernel";import{resolve as C}from"path";import O from"picomatch";function I(r){let e=r||[];return Array.isArray(e)?e:[e]}var w=/\\/g;function u(r){return r.replace(w,"/")}var R=/^(?:\/|(?:[A-Z]:)?[/\\|])/i;function _(r){return R.test(r)}function $(r,e){if(r.startsWith("**")||_(r))return u(r);let t=C(e,r);return u(t)}function N(r){if(r instanceof RegExp)return o=>{let a=u(o),f=r.test(a);return r.lastIndex=0,f};let e=process.cwd(),t=$(r,e),n=O(t,{dot:!0});return o=>{let a=u(o);return n(a)}}function h(r,e){if(!(!r&&!e))return t=>r!=null&&r.some(n=>n(t))?!1:e!=null&&e.some(n=>n(t))?!0:!(e&&e.length>0)}function D(r){return typeof r=="string"||r instanceof RegExp?{include:[r]}:Array.isArray(r)?{include:r}:{exclude:r.exclude?I(r.exclude):void 0,include:r.include?I(r.include):void 0}}function j(r){if(!r)return;let{exclude:e,include:t}=D(r),n=e==null?void 0:e.map(N),o=t==null?void 0:t.map(N);return h(n,o)}function v(r){let e=j(r);return e?t=>!!e(t):void 0}var P=b.packages.template,i=b.packages.types;function d(r){var e,t;return("directives"in r.body?(t=(e=r.body)==null?void 0:e.directives)!=null?t:[]:[]).map(n=>n.value.value).includes(S)}function s(r){return i.identifier(r)}function c(r){let{params:e,body:t,externalNames:n}=W(r),o=`{
|
|
2
|
+
v: ${M},
|
|
3
|
+
ast: ${F({params:e,body:t,externalNames:n})},
|
|
4
|
+
externals: {${n.join(", ")}},
|
|
5
|
+
}`;return i.callExpression(i.arrowFunctionExpression([s("$")],i.logicalExpression("&&",i.callExpression(i.memberExpression(i.assignmentExpression("??=",i.memberExpression(s("globalThis"),s("__TYPEGPU_META__")),i.newExpression(s("WeakMap"),[])),s("set")),[i.assignmentExpression("=",i.memberExpression(s("$"),s("f")),r),P.expression`${o}`()]),i.memberExpression(s("$"),s("f")))),[i.objectExpression([])])}function g(r,e){return i.callExpression(P.expression("globalThis.__TYPEGPU_AUTONAME__ ?? (a => a)",{placeholderPattern:!1})(),[r,i.stringLiteral(e)])}function G(r){return{VariableDeclarator(e){p(r,e.node,(t,n)=>{e.get("init").replaceWith(g(t,n))})},AssignmentExpression(e){p(r,e.node,(t,n)=>{e.get("right").replaceWith(g(t,n))})},ObjectProperty(e){p(r,e.node,(t,n)=>{e.get("value").replaceWith(g(t,n))})},ImportDeclaration(e){T(e.node,r)},ArrowFunctionExpression(e){d(e.node)&&(e.replaceWith(c(e.node)),e.skip())},FunctionExpression(e){d(e.node)&&(e.replaceWith(c(e.node)),e.skip())},FunctionDeclaration(e){let t=e.node,n=i.functionExpression(t.id,t.params,t.body);if(d(e.node)&&t.id){let o=c(n);e.replaceWith(i.variableDeclaration("const",[i.variableDeclarator(t.id,o)])),e.skip()}},CallExpression(e){let t=e.node;if(m(t,r)){let n=t.arguments[0];if(n&&(n.type==="FunctionExpression"||n.type==="ArrowFunctionExpression")){let o=c(n);e.replaceWith(i.callExpression(t.callee,[o])),e.skip()}}}}}function Y(){return{visitor:{Program(r,e){var y,x;let t=(y=e.file)==null?void 0:y.code,n=e.opts,o=e.filename,a=v(n);if(o&&a&&!(a!=null&&a(o)))return;let f={tgpuAliases:new Set(n!=null&&n.forceTgpuAlias?[n.forceTgpuAlias]:[]),fileId:o,autoNamingEnabled:(x=n==null?void 0:n.autoNamingEnabled)!=null?x:!0};r.traverse(G(f))}}}}export{L as a,F as b,T as c,m as d,p as e,S as f,Y as g};
|
|
6
|
+
//# sourceMappingURL=chunk-HGJBG4QQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/babel.ts","../src/common.ts","../src/filter.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 { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n embedJSON,\n gatherTgpuAliases,\n isShellImplementationCall,\n kernelDirective,\n type Options,\n performExpressionNaming,\n} from './common.ts';\nimport { createFilterForId } from './filter.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 containsKernelDirective(\n node:\n | babel.FunctionDeclaration\n | babel.FunctionExpression\n | babel.ArrowFunctionExpression,\n): boolean {\n return ((\n 'directives' in node.body ? (node.body?.directives ?? []) : []\n )\n .map((directive) => directive.value.value))\n .includes(kernelDirective);\n}\n\nfunction i(identifier: string): babel.Identifier {\n return types.identifier(identifier);\n}\n\nfunction functionToTranspiled(\n node: babel.ArrowFunctionExpression | babel.FunctionExpression,\n): babel.CallExpression {\n const { params, body, externalNames } = transpileFn(node);\n\n const metadata = `{\n v: ${FORMAT_VERSION},\n ast: ${embedJSON({ params, body, externalNames })},\n externals: {${externalNames.join(', ')}},\n }`;\n\n return types.callExpression(\n types.arrowFunctionExpression(\n [i('$')],\n types.logicalExpression(\n '&&',\n types.callExpression(\n types.memberExpression(\n types.assignmentExpression(\n '??=',\n types.memberExpression(i('globalThis'), i('__TYPEGPU_META__')),\n types.newExpression(i('WeakMap'), []),\n ),\n i('set'),\n ),\n [\n types.assignmentExpression(\n '=',\n types.memberExpression(i('$'), i('f')),\n node,\n ),\n template.expression`${metadata}`(),\n ],\n ),\n types.memberExpression(i('$'), i('f')),\n ),\n ),\n [types.objectExpression([])],\n );\n}\n\nfunction wrapInAutoName(\n node: babel.Expression,\n name: string,\n) {\n return types.callExpression(\n template.expression('globalThis.__TYPEGPU_AUTONAME__ ?? (a => a)', {\n placeholderPattern: false,\n })(),\n [node, types.stringLiteral(name)],\n );\n}\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n VariableDeclarator(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('init').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n AssignmentExpression(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('right').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n ObjectProperty(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('value').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n ArrowFunctionExpression(path) {\n if (containsKernelDirective(path.node)) {\n path.replaceWith(functionToTranspiled(path.node));\n path.skip();\n }\n },\n\n FunctionExpression(path) {\n if (containsKernelDirective(path.node)) {\n path.replaceWith(functionToTranspiled(path.node));\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\n if (containsKernelDirective(path.node) && node.id) {\n const transpiled = functionToTranspiled(expression);\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 transpiled = functionToTranspiled(\n implementation,\n ) as babel.CallExpression;\n\n path.replaceWith(\n types.callExpression(node.callee, [\n transpiled,\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const code: string | undefined = (state as any).file?.code;\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const options: Options | undefined = (state as any).opts;\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const id: string | undefined = (state as any).filename;\n\n const filter = createFilterForId(options);\n if (id && filter && !filter?.(id)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options?.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n autoNamingEnabled: options?.autoNamingEnabled ?? true,\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';\nimport type { FilterPattern } from 'unplugin';\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 autoNamingEnabled: boolean;\n};\n\nexport interface Options {\n include?: FilterPattern;\n exclude?: FilterPattern;\n enforce?: 'post' | 'pre' | undefined;\n forceTgpuAlias?: string;\n autoNamingEnabled?: boolean;\n}\n\nexport const defaultOptions = {\n include: [/\\.m?[jt]sx?$/],\n autoNamingEnabled: true,\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 (\n (tail.property.type === 'Literal' ||\n tail.property.type === 'StringLiteral') &&\n tail.property.value === '~unstable'\n ) {\n // Bypassing the '~unstable' property.\n tail = tail.object;\n continue;\n }\n\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\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 && isTgpu(ctx, node.callee.callee.object)\n );\n}\n\nconst resourceConstructors: string[] = [\n // tgpu\n 'bindGroupLayout',\n 'vertexLayout',\n // tgpu['~unstable']\n 'slot',\n 'accessor',\n 'privateVar',\n 'workgroupVar',\n 'const',\n ...fnShellFunctionNames,\n // d\n 'struct',\n 'unstruct',\n // root\n 'createBuffer',\n 'createMutable',\n 'createReadonly',\n 'createUniform',\n 'createQuerySet',\n // root['~unstable']\n 'createPipeline',\n 'createTexture',\n 'sampler',\n 'comparisonSampler',\n];\n\n/**\n * Checks if `node` should be wrapped in an autoname function.\n * Since it is mostly for debugging and clean WGSL generation,\n * some false positives and false negatives are admissible.\n */\nfunction containsResourceConstructorCall(\n node: acorn.AnyNode | babel.Node,\n ctx: Context,\n) {\n if (node.type === 'CallExpression') {\n if (isShellImplementationCall(node, ctx)) {\n return true;\n }\n // struct({...})\n if (\n node.callee.type === 'Identifier' &&\n resourceConstructors.includes(node.callee.name)\n ) {\n return true;\n }\n if (node.callee.type === 'MemberExpression') {\n if (node.callee.property.type === 'Identifier') {\n // root.createBuffer({...})\n if (resourceConstructors.includes(node.callee.property.name)) {\n return true;\n }\n if (node.callee.property.name === '$name') {\n return false;\n }\n }\n // root.createBuffer(d.f32).$usage('storage')\n return containsResourceConstructorCall(node.callee.object, ctx);\n }\n }\n if (node.type === 'TaggedTemplateExpression') {\n return containsResourceConstructorCall(node.tag, ctx);\n }\n return false;\n}\n\ntype ExpressionFor<T extends acorn.AnyNode | babel.Node> = T extends\n acorn.AnyNode ? acorn.Expression : babel.Expression;\n\n/**\n * Checks if `node` contains a label and a tgpu expression that could be named.\n * If so, it calls the provided callback. Nodes selected for naming include:\n *\n * `let name = tgpu.bindGroupLayout({});` (VariableDeclarator)\n *\n * `name = tgpu.bindGroupLayout({});` (AssignmentExpression)\n *\n * `property: tgpu.bindGroupLayout({})` (Property/ObjectProperty)\n *\n * Since it is mostly for debugging and clean WGSL generation,\n * some false positives and false negatives are admissible.\n *\n * @privateRemarks\n * When adding new checks, you need to call this method in the corresponding node in Babel.\n */\nexport function performExpressionNaming<T extends acorn.AnyNode | babel.Node>(\n ctx: Context,\n node: T,\n namingCallback: (node: ExpressionFor<T>, name: string) => void,\n) {\n if (!ctx.autoNamingEnabled) {\n return;\n }\n\n if (\n node.type === 'VariableDeclarator' &&\n node.id.type === 'Identifier' &&\n node.init &&\n containsResourceConstructorCall(node.init, ctx)\n ) {\n namingCallback(node.init as ExpressionFor<T>, node.id.name);\n } else if (\n node.type === 'AssignmentExpression' &&\n node.left.type === 'Identifier' &&\n containsResourceConstructorCall(node.right, ctx)\n ) {\n namingCallback(node.right as ExpressionFor<T>, node.left.name);\n } else if (\n (node.type === 'Property' || node.type === 'ObjectProperty') &&\n node.key.type === 'Identifier' &&\n containsResourceConstructorCall(node.value, ctx)\n ) {\n namingCallback(node.value as ExpressionFor<T>, node.key.name);\n }\n}\n\nexport const kernelDirective = 'kernel';\n","// Copied from https://github.com/unjs/unplugin/blob/f514bf8e2d751b48b3a5acb1077eb1292d9711b3/src/utils/filter.ts#L2\n// Used only in the babel version of the plugin, since others can rely on native unplugin functionality.\n\nimport { resolve } from 'node:path';\nimport picomatch from 'picomatch';\nimport type {\n Arrayable,\n Nullable,\n StringFilter,\n StringOrRegExp,\n} from 'unplugin';\n\nfunction toArray<T>(array?: Nullable<Arrayable<T>>): Array<T> {\n const result = array || [];\n if (Array.isArray(result)) return result;\n return [result];\n}\n\nconst BACKSLASH_REGEX = /\\\\/g;\nfunction normalize(path: string): string {\n return path.replace(BACKSLASH_REGEX, '/');\n}\n\nconst ABSOLUTE_PATH_REGEX = /^(?:\\/|(?:[A-Z]:)?[/\\\\|])/i;\nfunction isAbsolute(path: string): boolean {\n return ABSOLUTE_PATH_REGEX.test(path);\n}\n\nexport type PluginFilter = (input: string) => boolean;\nexport type TransformHookFilter = (id: string, code: string) => boolean;\n\ninterface NormalizedStringFilter {\n include?: StringOrRegExp[] | undefined;\n exclude?: StringOrRegExp[] | undefined;\n}\n\nfunction getMatcherString(glob: string, cwd: string) {\n if (glob.startsWith('**') || isAbsolute(glob)) {\n return normalize(glob);\n }\n\n const resolved = resolve(cwd, glob);\n return normalize(resolved);\n}\n\nfunction patternToIdFilter(pattern: StringOrRegExp): PluginFilter {\n if (pattern instanceof RegExp) {\n return (id: string) => {\n const normalizedId = normalize(id);\n const result = pattern.test(normalizedId);\n pattern.lastIndex = 0;\n return result;\n };\n }\n const cwd = process.cwd();\n const glob = getMatcherString(pattern, cwd);\n const matcher = picomatch(glob, { dot: true });\n return (id: string) => {\n const normalizedId = normalize(id);\n return matcher(normalizedId);\n };\n}\n\nfunction patternToCodeFilter(pattern: StringOrRegExp): PluginFilter {\n if (pattern instanceof RegExp) {\n return (code: string) => {\n const result = pattern.test(code);\n pattern.lastIndex = 0;\n return result;\n };\n }\n return (code: string) => code.includes(pattern);\n}\n\nfunction createFilter(\n exclude: PluginFilter[] | undefined,\n include: PluginFilter[] | undefined,\n): PluginFilter | undefined {\n if (!exclude && !include) {\n return;\n }\n\n return (input) => {\n if (exclude?.some((filter) => filter(input))) {\n return false;\n }\n if (include?.some((filter) => filter(input))) {\n return true;\n }\n return !(include && include.length > 0);\n };\n}\n\nfunction normalizeFilter(filter: StringFilter): NormalizedStringFilter {\n if (typeof filter === 'string' || filter instanceof RegExp) {\n return {\n include: [filter],\n };\n }\n if (Array.isArray(filter)) {\n return {\n include: filter,\n };\n }\n return {\n exclude: filter.exclude ? toArray(filter.exclude) : undefined,\n include: filter.include ? toArray(filter.include) : undefined,\n };\n}\n\nfunction createIdFilter(\n filter: StringFilter | undefined,\n): PluginFilter | undefined {\n if (!filter) return;\n const { exclude, include } = normalizeFilter(filter);\n const excludeFilter = exclude?.map(patternToIdFilter);\n const includeFilter = include?.map(patternToIdFilter);\n return createFilter(excludeFilter, includeFilter);\n}\n\nfunction createCodeFilter(\n filter: StringFilter | undefined,\n): PluginFilter | undefined {\n if (!filter) return;\n const { exclude, include } = normalizeFilter(filter);\n const excludeFilter = exclude?.map(patternToCodeFilter);\n const includeFilter = include?.map(patternToCodeFilter);\n return createFilter(excludeFilter, includeFilter);\n}\n\nexport function createFilterForId(\n filter: StringFilter | undefined,\n): PluginFilter | undefined {\n const filterFunction = createIdFilter(filter);\n return filterFunction ? (id) => !!filterFunction(id) : undefined;\n}\n\nfunction createFilterForTransform(\n idFilter: StringFilter | undefined,\n codeFilter: StringFilter | undefined,\n): TransformHookFilter | undefined {\n if (!idFilter && !codeFilter) return;\n const idFilterFunction = createIdFilter(idFilter);\n const codeFilterFunction = createCodeFilter(codeFilter);\n return (id, code) => {\n let fallback = true;\n if (idFilterFunction) {\n fallback &&= idFilterFunction(id);\n }\n if (!fallback) {\n return false;\n }\n\n if (codeFilterFunction) {\n fallback &&= codeFilterFunction(code);\n }\n return fallback;\n };\n}\n"],"mappings":"AAAA,UAAYA,MAAW,oBAIvB,OAAS,kBAAAC,MAAsB,UAC/B,OAAS,eAAAC,MAAmB,mBCiBrB,IAAMC,EAAiB,CAC5B,QAAS,CAAC,cAAc,EACxB,kBAAmB,EACrB,EAEO,SAASC,EAAUC,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,OAAQC,EACR,mBAAmB5B,EAAA2B,GAAA,YAAAA,EAAS,oBAAT,KAAA3B,EAA8B,EACnD,EAEAiB,EAAK,SAASF,EAAgBC,CAAG,CAAC,CACpC,CACF,CACF,CACF","names":["Babel","FORMAT_VERSION","transpileFn","defaultOptions","embedJSON","jsValue","isTgpu","ctx","node","path","tail","gatherTgpuAliases","spec","fnShellFunctionNames","isShellImplementationCall","resourceConstructors","containsResourceConstructorCall","performExpressionNaming","namingCallback","kernelDirective","resolve","picomatch","toArray","array","result","BACKSLASH_REGEX","normalize","path","ABSOLUTE_PATH_REGEX","isAbsolute","getMatcherString","glob","cwd","resolved","patternToIdFilter","pattern","id","normalizedId","matcher","createFilter","exclude","include","input","filter","normalizeFilter","toArray","createIdFilter","excludeFilter","patternToIdFilter","includeFilter","createFilterForId","filter","filterFunction","createIdFilter","id","template","types","containsKernelDirective","node","_a","_b","directive","kernelDirective","i","identifier","functionToTranspiled","params","body","externalNames","transpileFn","metadata","FORMAT_VERSION","embedJSON","wrapInAutoName","name","functionVisitor","ctx","path","performExpressionNaming","gatherTgpuAliases","expression","transpiled","isShellImplementationCall","implementation","babel_default","state","code","options","id","filter","createFilterForId"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as y,b,c as x,d as F,e as E,f as d,g as A}from"./chunk-HGJBG4QQ.js";import S from"defu";import{walk as T}from"estree-walker";import{generateTransform as P,MagicStringAST as $}from"magic-string-ast";import{FORMAT_VERSION as k}from"tinyest";import{transpileFn as D}from"tinyest-for-wgsl";import{createUnplugin as v}from"unplugin";function O(o){if(o.body.type==="BlockStatement"){for(let e of o.body.body)if(e.type==="ExpressionStatement"&&e.directive===d)return!0}return!1}function h(o){let e=structuredClone(o);return e.body.type==="BlockStatement"&&(e.body.body=e.body.body.filter(i=>!(i.type==="ExpressionStatement"&&i.directive===d))),e}function I(o,e,i){o.prependLeft(e.start,"(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(e.end,`), ${i}) && $.f)({}))`)}function M(o,e,i){o.prependLeft(e.start,"((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(e.end,`, "${i}"))`)}var s=v(o=>{let e=S(o,y);return{name:"unplugin-typegpu",enforce:e.enforce,transform:{filter:{id:e},handler(i,l){let u={tgpuAliases:new Set(e.forceTgpuAlias?[e.forceTgpuAlias]:[]),fileId:l,autoNamingEnabled:e.autoNamingEnabled},w=this.parse(i,{allowReturnOutsideFunction:!0}),f=[],c=new $(i);T(w,{enter(a,t,m,g){var p;let n=a;if(E(u,n,(r,N)=>{M(c,r,N)}),n.type==="ImportDeclaration"&&x(n,u),n.type==="CallExpression"&&F(n,u)){let r=n.arguments[0];r&&(r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression")&&(f.push({def:h(r)}),this.skip())}(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression"||n.type==="FunctionDeclaration")&&O(n)&&(f.push({def:h(n),name:n.type==="FunctionDeclaration"||n.type==="FunctionExpression"?(p=n.id)==null?void 0:p.name:(t==null?void 0:t.type)==="VariableDeclarator"&&t.id.type==="Identifier"?t.id.name:void 0}),this.skip())}});for(let{def:a,name:t}of f){let{params:m,body:g,externalNames:n}=D(a),p=a.type==="FunctionDeclaration";p&&t&&i.slice(0,a.start).search(new RegExp(`(?<![\\w_.])${t}(?![\\w_])`))!==-1&&console.warn(`File ${l}: function "${t}" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);let r=`{
|
|
2
|
+
v: ${k},
|
|
3
|
+
ast: ${b({params:m,body:g,externalNames:n})},
|
|
4
|
+
externals: {${n.join(", ")}},
|
|
5
|
+
}`;I(c,a,r),p&&t&&c.prependLeft(a.start,`const ${t} = `)}return P(c,l)}}}}),V=s,Y=s.vite,j=s.rollup,J=s.rolldown,W=s.webpack,q=s.rspack,z=s.esbuild,H=s.farm,Q=A;export{V as a,Y as b,j as c,J as d,W as e,q as f,z as g,H as h,Q as i};
|
|
6
|
+
//# sourceMappingURL=chunk-RRLX57NP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type * as acorn from 'acorn';\nimport defu from 'defu';\nimport { type Node, walk } from 'estree-walker';\nimport { generateTransform, MagicStringAST } from 'magic-string-ast';\nimport { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { createUnplugin, type UnpluginInstance } from 'unplugin';\nimport babel from './babel.ts';\nimport {\n type Context,\n defaultOptions,\n embedJSON,\n gatherTgpuAliases,\n isShellImplementationCall,\n kernelDirective,\n type Options,\n performExpressionNaming,\n} from './common.ts';\n\ntype FunctionNode =\n | acorn.FunctionDeclaration\n | acorn.AnonymousFunctionDeclaration\n | acorn.FunctionExpression\n | acorn.ArrowFunctionExpression;\n\nfunction containsKernelDirective(node: FunctionNode): boolean {\n if (node.body.type === 'BlockStatement') {\n for (const statement of node.body.body) {\n if (\n statement.type === 'ExpressionStatement' &&\n statement.directive === kernelDirective\n ) {\n return true;\n }\n }\n }\n return false;\n}\n\nfunction removeKernelDirective(node: FunctionNode) {\n const cloned = structuredClone(node);\n\n if (cloned.body.type === 'BlockStatement') {\n cloned.body.body = cloned.body.body.filter(\n (statement) =>\n !(\n statement.type === 'ExpressionStatement' &&\n statement.directive === kernelDirective\n ),\n );\n }\n\n return cloned;\n}\n\nfunction assignMetadata(\n magicString: MagicStringAST,\n node: acorn.AnyNode,\n metadata: string,\n) {\n magicString.prependLeft(\n node.start,\n '(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (',\n ).appendRight(\n node.end,\n `), ${metadata}) && $.f)({}))`,\n );\n}\n\nfunction wrapInAutoName(\n magicString: MagicStringAST,\n node: acorn.Node,\n name: string,\n) {\n magicString\n .prependLeft(\n node.start,\n '((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(',\n )\n .appendRight(node.end, `, \"${name}\"))`);\n}\n\nconst typegpu: UnpluginInstance<Options, false> = createUnplugin(\n (rawOptions) => {\n const options = defu(rawOptions, defaultOptions);\n\n return {\n name: 'unplugin-typegpu' as const,\n enforce: options.enforce,\n transform: {\n filter: {\n id: options,\n },\n handler(code, id) {\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n autoNamingEnabled: options.autoNamingEnabled,\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 }[] = [];\n\n const magicString = new MagicStringAST(code);\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as acorn.AnyNode;\n\n performExpressionNaming(ctx, node, (node, name) => {\n wrapInAutoName(magicString, node, name);\n });\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 tgslFunctionDefs.push({\n def: removeKernelDirective(implementation),\n });\n this.skip();\n }\n }\n }\n\n if (\n node.type === 'ArrowFunctionExpression' ||\n node.type === 'FunctionExpression' ||\n node.type === 'FunctionDeclaration'\n ) {\n if (containsKernelDirective(node)) {\n tgslFunctionDefs.push({\n def: removeKernelDirective(node),\n name: 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 });\n this.skip();\n }\n }\n },\n });\n\n for (\n const {\n def,\n name,\n } of tgslFunctionDefs\n ) {\n const { params, 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 console.warn(\n `File ${id}: function \"${name}\" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`,\n );\n }\n\n const metadata = `{\n v: ${FORMAT_VERSION},\n ast: ${embedJSON({ params, body, externalNames })},\n externals: {${externalNames.join(', ')}},\n }`;\n\n assignMetadata(magicString, def, metadata);\n\n if (isFunctionStatement && name) {\n magicString.prependLeft(def.start, `const ${name} = `);\n }\n }\n\n return generateTransform(magicString, id);\n },\n },\n };\n },\n);\n\nexport type { Options } from './common.ts';\n\nexport default typegpu;\n\nexport const vitePlugin = typegpu.vite;\nexport const rollupPlugin = typegpu.rollup;\nexport const rolldownPlugin = typegpu.rolldown;\nexport const webpackPlugin = typegpu.webpack;\nexport const rspackPlugin = typegpu.rspack;\nexport const esbuildPlugin = typegpu.esbuild;\nexport const farmPlugin = typegpu.farm;\nexport const babelPlugin = babel;\n"],"mappings":"6EACA,OAAOA,MAAU,OACjB,OAAoB,QAAAC,MAAY,gBAChC,OAAS,qBAAAC,EAAmB,kBAAAC,MAAsB,mBAClD,OAAS,kBAAAC,MAAsB,UAC/B,OAAS,eAAAC,MAAmB,mBAC5B,OAAS,kBAAAC,MAA6C,WAmBtD,SAASC,EAAwBC,EAA6B,CAC5D,GAAIA,EAAK,KAAK,OAAS,kBACrB,QAAWC,KAAaD,EAAK,KAAK,KAChC,GACEC,EAAU,OAAS,uBACnBA,EAAU,YAAcC,EAExB,MAAO,GAIb,MAAO,EACT,CAEA,SAASC,EAAsBH,EAAoB,CACjD,IAAMI,EAAS,gBAAgBJ,CAAI,EAEnC,OAAII,EAAO,KAAK,OAAS,mBACvBA,EAAO,KAAK,KAAOA,EAAO,KAAK,KAAK,OACjCH,GACC,EACEA,EAAU,OAAS,uBACnBA,EAAU,YAAcC,EAE9B,GAGKE,CACT,CAEA,SAASC,EACPC,EACAN,EACAO,EACA,CACAD,EAAY,YACVN,EAAK,MACL,oEACF,EAAE,YACAA,EAAK,IACL,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AAS,uBAChBA,EAAK,OAAS,sBACd2B,EAAA3B,EAAK,KAAL,YAAA2B,EAAS,MACTH,GAAA,YAAAA,EAAS,QAAS,sBAClBA,EAAQ,GAAG,OAAS,aAClBA,EAAQ,GAAG,KAEb,MACN,CAAC,EACD,KAAK,KAAK,EAGhB,CACF,CAAC,EAED,OACQ,CACJ,IAAAQ,EACA,KAAAvB,CACF,IAAKW,EACL,CACA,GAAM,CAAE,OAAAa,EAAQ,KAAAC,EAAM,cAAAC,CAAc,EAAIC,EAAYJ,CAAG,EACjDK,EAAsBL,EAAI,OAAS,sBAGvCK,GACA5B,GACAO,EACK,MAAM,EAAGgB,EAAI,KAAK,EAClB,OAAO,IAAI,OAAO,eAAevB,CAAI,YAAY,CAAC,IAAM,IAE7D,QAAQ,KACN,QAAQQ,CAAE,eAAeR,CAAI,iIAC/B,EAGF,IAAMF,EAAW;AAAA,mBACV+B,CAAc;AAAA,qBACZC,EAAU,CAAE,OAAAN,EAAQ,KAAAC,EAAM,cAAAC,CAAc,CAAC,CAAC;AAAA,4BACnCA,EAAc,KAAK,IAAI,CAAC;AAAA,eAGxC9B,EAAeC,EAAa0B,EAAKzB,CAAQ,EAErC8B,GAAuB5B,GACzBH,EAAY,YAAY0B,EAAI,MAAO,SAASvB,CAAI,KAAK,CAEzD,CAEA,OAAO+B,EAAkBlC,EAAaW,CAAE,CAC1C,CACF,CACF,CACF,CACF,EAIOwB,EAAQ/B,EAEFgC,EAAahC,EAAQ,KACrBiC,EAAejC,EAAQ,OACvBkC,EAAiBlC,EAAQ,SACzBmC,EAAgBnC,EAAQ,QACxBoC,EAAepC,EAAQ,OACvBqC,EAAgBrC,EAAQ,QACxBsC,EAAatC,EAAQ,KACrBuC,EAAcC","names":["defu","walk","generateTransform","MagicStringAST","FORMAT_VERSION","transpileFn","createUnplugin","containsKernelDirective","node","statement","kernelDirective","removeKernelDirective","cloned","assignMetadata","magicString","metadata","wrapInAutoName","name","typegpu","createUnplugin","rawOptions","options","defu","defaultOptions","code","id","ctx","ast","tgslFunctionDefs","MagicStringAST","walk","_node","_parent","prop","index","_a","performExpressionNaming","gatherTgpuAliases","isShellImplementationCall","implementation","def","params","body","externalNames","transpileFn","isFunctionStatement","FORMAT_VERSION","embedJSON","generateTransform","index_default","vitePlugin","rollupPlugin","rolldownPlugin","webpackPlugin","rspackPlugin","esbuildPlugin","farmPlugin","babelPlugin","babel_default"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunk4DTTWQTWcjs = require('./chunk-4DTTWQTW.cjs');var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);var _estreewalker = require('estree-walker');var _magicstringast = require('magic-string-ast');var _tinyest = require('tinyest');var _tinyestforwgsl = require('tinyest-for-wgsl');var _unplugin = require('unplugin');function O(o){if(o.body.type==="BlockStatement"){for(let e of o.body.body)if(e.type==="ExpressionStatement"&&e.directive===_chunk4DTTWQTWcjs.f)return!0}return!1}function h(o){let e=structuredClone(o);return e.body.type==="BlockStatement"&&(e.body.body=e.body.body.filter(i=>!(i.type==="ExpressionStatement"&&i.directive===_chunk4DTTWQTWcjs.f))),e}function I(o,e,i){o.prependLeft(e.start,"(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(e.end,`), ${i}) && $.f)({}))`)}function M(o,e,i){o.prependLeft(e.start,"((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(e.end,`, "${i}"))`)}var s=_unplugin.createUnplugin.call(void 0, o=>{let e=_defu2.default.call(void 0, o,_chunk4DTTWQTWcjs.a);return{name:"unplugin-typegpu",enforce:e.enforce,transform:{filter:{id:e},handler(i,l){let u={tgpuAliases:new Set(e.forceTgpuAlias?[e.forceTgpuAlias]:[]),fileId:l,autoNamingEnabled:e.autoNamingEnabled},w=this.parse(i,{allowReturnOutsideFunction:!0}),f=[],c=new (0, _magicstringast.MagicStringAST)(i);_estreewalker.walk.call(void 0, w,{enter(a,t,m,g){var p;let n=a;if(_chunk4DTTWQTWcjs.e.call(void 0, u,n,(r,N)=>{M(c,r,N)}),n.type==="ImportDeclaration"&&_chunk4DTTWQTWcjs.c.call(void 0, n,u),n.type==="CallExpression"&&_chunk4DTTWQTWcjs.d.call(void 0, n,u)){let r=n.arguments[0];r&&(r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression")&&(f.push({def:h(r)}),this.skip())}(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression"||n.type==="FunctionDeclaration")&&O(n)&&(f.push({def:h(n),name:n.type==="FunctionDeclaration"||n.type==="FunctionExpression"?(p=n.id)==null?void 0:p.name:(t==null?void 0:t.type)==="VariableDeclarator"&&t.id.type==="Identifier"?t.id.name:void 0}),this.skip())}});for(let{def:a,name:t}of f){let{params:m,body:g,externalNames:n}=_tinyestforwgsl.transpileFn.call(void 0, a),p=a.type==="FunctionDeclaration";p&&t&&i.slice(0,a.start).search(new RegExp(`(?<![\\w_.])${t}(?![\\w_])`))!==-1&&console.warn(`File ${l}: function "${t}" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);let r=`{
|
|
2
|
+
v: ${_tinyest.FORMAT_VERSION},
|
|
3
|
+
ast: ${_chunk4DTTWQTWcjs.b.call(void 0, {params:m,body:g,externalNames:n})},
|
|
4
|
+
externals: {${n.join(", ")}},
|
|
5
|
+
}`;I(c,a,r),p&&t&&c.prependLeft(a.start,`const ${t} = `)}return _magicstringast.generateTransform.call(void 0, c,l)}}}}),V= exports.a =s,Y= exports.b =s.vite,j= exports.c =s.rollup,J= exports.d =s.rolldown,W= exports.e =s.webpack,q= exports.f =s.rspack,z= exports.g =s.esbuild,H= exports.h =s.farm,Q= exports.i =_chunk4DTTWQTWcjs.g;exports.a = V; exports.b = Y; exports.c = j; exports.d = J; exports.e = W; exports.f = q; exports.g = z; exports.h = H; exports.i = Q;
|
|
6
|
+
//# sourceMappingURL=chunk-XXTHHPRC.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/chunk-XXTHHPRC.cjs","../src/index.ts"],"names":["containsKernelDirective","node","statement","kernelDirective","removeKernelDirective","cloned","assignMetadata","magicString","metadata","wrapInAutoName","name","typegpu","createUnplugin","rawOptions","options","defu","defaultOptions","code","id","ctx","ast","tgslFunctionDefs","MagicStringAST","walk","_node","_parent","prop","index","_a","performExpressionNaming","gatherTgpuAliases","isShellImplementationCall","implementation","def","params","body","externalNames","transpileFn","isFunctionStatement","FORMAT_VERSION","embedJSON","generateTransform","index_default","vitePlugin","rollupPlugin","rolldownPlugin","webpackPlugin","rspackPlugin","esbuildPlugin","farmPlugin","babelPlugin","babel_default"],"mappings":"AAAA,iOAA6E,wECC5D,6CACe,kDACkB,kCACnB,kDACH,oCAC0B,SAmB7CA,CAAAA,CAAwBC,CAAAA,CAA6B,CAC5D,EAAA,CAAIA,CAAAA,CAAK,IAAA,CAAK,IAAA,GAAS,gBAAA,CAAA,CACrB,GAAA,CAAA,IAAWC,EAAAA,GAAaD,CAAAA,CAAK,IAAA,CAAK,IAAA,CAChC,EAAA,CACEC,CAAAA,CAAU,IAAA,GAAS,qBAAA,EACnBA,CAAAA,CAAU,SAAA,GAAcC,mBAAAA,CAExB,MAAO,CAAA,CAAA,CAIb,MAAO,CAAA,CACT,CAEA,SAASC,CAAAA,CAAsBH,CAAAA,CAAoB,CACjD,IAAMI,CAAAA,CAAS,eAAA,CAAgBJ,CAAI,CAAA,CAEnC,OAAII,CAAAA,CAAO,IAAA,CAAK,IAAA,GAAS,gBAAA,EAAA,CACvBA,CAAAA,CAAO,IAAA,CAAK,IAAA,CAAOA,CAAAA,CAAO,IAAA,CAAK,IAAA,CAAK,MAAA,CACjCH,CAAAA,EACC,CAAA,CACEA,CAAAA,CAAU,IAAA,GAAS,qBAAA,EACnBA,CAAAA,CAAU,S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,CAAAA,CAAKzB,CAAQ,CAAA,CAErC8B,CAAAA,EAAuB5B,CAAAA,EACzBH,CAAAA,CAAY,WAAA,CAAY0B,CAAAA,CAAI,KAAA,CAAO,CAAA,MAAA,EAASvB,CAAI,CAAA,GAAA,CAAK,CAEzD,CAEA,OAAO+B,+CAAAA,CAAkBlC,CAAaW,CAAE,CAC1C,CACF,CACF,CACF,CACF,CAAA,CAIOwB,CAAAA,aAAQ/B,CAAAA,CAEFgC,CAAAA,aAAahC,CAAAA,CAAQ,IAAA,CACrBiC,CAAAA,aAAejC,CAAAA,CAAQ,MAAA,CACvBkC,CAAAA,aAAiBlC,CAAAA,CAAQ,QAAA,CACzBmC,CAAAA,aAAgBnC,CAAAA,CAAQ,OAAA,CACxBoC,CAAAA,aAAepC,CAAAA,CAAQ,MAAA,CACvBqC,CAAAA,aAAgBrC,CAAAA,CAAQ,OAAA,CACxBsC,CAAAA,aAAatC,CAAAA,CAAQ,IAAA,CACrBuC,CAAAA,aAAcC,mBAAAA,CAAAA,sIAAAA","file":"/Users/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/chunk-XXTHHPRC.cjs","sourcesContent":[null,"import type * as acorn from 'acorn';\nimport defu from 'defu';\nimport { type Node, walk } from 'estree-walker';\nimport { generateTransform, MagicStringAST } from 'magic-string-ast';\nimport { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { createUnplugin, type UnpluginInstance } from 'unplugin';\nimport babel from './babel.ts';\nimport {\n type Context,\n defaultOptions,\n embedJSON,\n gatherTgpuAliases,\n isShellImplementationCall,\n kernelDirective,\n type Options,\n performExpressionNaming,\n} from './common.ts';\n\ntype FunctionNode =\n | acorn.FunctionDeclaration\n | acorn.AnonymousFunctionDeclaration\n | acorn.FunctionExpression\n | acorn.ArrowFunctionExpression;\n\nfunction containsKernelDirective(node: FunctionNode): boolean {\n if (node.body.type === 'BlockStatement') {\n for (const statement of node.body.body) {\n if (\n statement.type === 'ExpressionStatement' &&\n statement.directive === kernelDirective\n ) {\n return true;\n }\n }\n }\n return false;\n}\n\nfunction removeKernelDirective(node: FunctionNode) {\n const cloned = structuredClone(node);\n\n if (cloned.body.type === 'BlockStatement') {\n cloned.body.body = cloned.body.body.filter(\n (statement) =>\n !(\n statement.type === 'ExpressionStatement' &&\n statement.directive === kernelDirective\n ),\n );\n }\n\n return cloned;\n}\n\nfunction assignMetadata(\n magicString: MagicStringAST,\n node: acorn.AnyNode,\n metadata: string,\n) {\n magicString.prependLeft(\n node.start,\n '(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (',\n ).appendRight(\n node.end,\n `), ${metadata}) && $.f)({}))`,\n );\n}\n\nfunction wrapInAutoName(\n magicString: MagicStringAST,\n node: acorn.Node,\n name: string,\n) {\n magicString\n .prependLeft(\n node.start,\n '((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(',\n )\n .appendRight(node.end, `, \"${name}\"))`);\n}\n\nconst typegpu: UnpluginInstance<Options, false> = createUnplugin(\n (rawOptions) => {\n const options = defu(rawOptions, defaultOptions);\n\n return {\n name: 'unplugin-typegpu' as const,\n enforce: options.enforce,\n transform: {\n filter: {\n id: options,\n },\n handler(code, id) {\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n autoNamingEnabled: options.autoNamingEnabled,\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 }[] = [];\n\n const magicString = new MagicStringAST(code);\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as acorn.AnyNode;\n\n performExpressionNaming(ctx, node, (node, name) => {\n wrapInAutoName(magicString, node, name);\n });\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 tgslFunctionDefs.push({\n def: removeKernelDirective(implementation),\n });\n this.skip();\n }\n }\n }\n\n if (\n node.type === 'ArrowFunctionExpression' ||\n node.type === 'FunctionExpression' ||\n node.type === 'FunctionDeclaration'\n ) {\n if (containsKernelDirective(node)) {\n tgslFunctionDefs.push({\n def: removeKernelDirective(node),\n name: 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 });\n this.skip();\n }\n }\n },\n });\n\n for (\n const {\n def,\n name,\n } of tgslFunctionDefs\n ) {\n const { params, 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 console.warn(\n `File ${id}: function \"${name}\" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`,\n );\n }\n\n const metadata = `{\n v: ${FORMAT_VERSION},\n ast: ${embedJSON({ params, body, externalNames })},\n externals: {${externalNames.join(', ')}},\n }`;\n\n assignMetadata(magicString, def, metadata);\n\n if (isFunctionStatement && name) {\n magicString.prependLeft(def.start, `const ${name} = `);\n }\n }\n\n return generateTransform(magicString, id);\n },\n },\n };\n },\n);\n\nexport type { Options } from './common.ts';\n\nexport default typegpu;\n\nexport const vitePlugin = typegpu.vite;\nexport const rollupPlugin = typegpu.rollup;\nexport const rolldownPlugin = typegpu.rolldown;\nexport const webpackPlugin = typegpu.webpack;\nexport const rspackPlugin = typegpu.rspack;\nexport const esbuildPlugin = typegpu.esbuild;\nexport const farmPlugin = typegpu.farm;\nexport const babelPlugin = babel;\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 _chunkXXTHHPRCcjs = require('./chunk-XXTHHPRC.cjs');require('./chunk-4DTTWQTW.cjs');var l=_chunkXXTHHPRCcjs.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/konradreczko/TypeGPU/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/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/esbuild.cjs","sourcesContent":[null,"import { esbuildPlugin } from './index.ts';\n\nexport default esbuildPlugin;\n"]}
|
package/esbuild.d.cts
CHANGED
package/esbuild.d.ts
CHANGED
package/esbuild.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as e}from"./chunk-
|
|
1
|
+
import{g as e}from"./chunk-RRLX57NP.js";import"./chunk-HGJBG4QQ.js";var l=e;export{l as default};
|
|
2
2
|
//# sourceMappingURL=esbuild.js.map
|
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 _chunkXXTHHPRCcjs = require('./chunk-XXTHHPRC.cjs');require('./chunk-4DTTWQTW.cjs');var m=_chunkXXTHHPRCcjs.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/konradreczko/TypeGPU/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/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/farm.cjs","sourcesContent":[null,"import { farmPlugin } from './index.ts';\n\nexport default farmPlugin;\n"]}
|
package/farm.d.cts
CHANGED
package/farm.d.ts
CHANGED
package/farm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{h as r}from"./chunk-
|
|
1
|
+
import{h as r}from"./chunk-RRLX57NP.js";import"./chunk-HGJBG4QQ.js";var m=r;export{m as default};
|
|
2
2
|
//# sourceMappingURL=farm.js.map
|
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 _chunkXXTHHPRCcjs = require('./chunk-XXTHHPRC.cjs');require('./chunk-4DTTWQTW.cjs');exports.babelPlugin = _chunkXXTHHPRCcjs.i; exports.default = _chunkXXTHHPRCcjs.a; exports.esbuildPlugin = _chunkXXTHHPRCcjs.g; exports.farmPlugin = _chunkXXTHHPRCcjs.h; exports.rolldownPlugin = _chunkXXTHHPRCcjs.d; exports.rollupPlugin = _chunkXXTHHPRCcjs.c; exports.rspackPlugin = _chunkXXTHHPRCcjs.f; exports.vitePlugin = _chunkXXTHHPRCcjs.b; exports.webpackPlugin = _chunkXXTHHPRCcjs.e;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/index.cjs"],"names":[],"mappings":"AAAA,iIAAmD,gCAA6B,qYAAoK","file":"/Users/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/index.cjs"}
|
package/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import * as rollup from 'rollup';
|
|
2
1
|
import * as unplugin from 'unplugin';
|
|
3
2
|
import { FilterPattern, UnpluginInstance } from 'unplugin';
|
|
3
|
+
import * as rollup from 'rollup';
|
|
4
|
+
import * as vite from 'vite';
|
|
4
5
|
import export_default from './babel.cjs';
|
|
5
6
|
import '@babel/traverse';
|
|
6
7
|
import '@babel/types';
|
|
@@ -10,11 +11,12 @@ interface Options {
|
|
|
10
11
|
exclude?: FilterPattern;
|
|
11
12
|
enforce?: 'post' | 'pre' | undefined;
|
|
12
13
|
forceTgpuAlias?: string;
|
|
14
|
+
autoNamingEnabled?: boolean;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
declare const typegpu: UnpluginInstance<Options, false>;
|
|
16
18
|
|
|
17
|
-
declare const vitePlugin: (options: Options) =>
|
|
19
|
+
declare const vitePlugin: (options: Options) => vite.Plugin<any>;
|
|
18
20
|
declare const rollupPlugin: (options: Options) => rollup.Plugin<any>;
|
|
19
21
|
declare const rolldownPlugin: (options: Options) => Plugin$3;
|
|
20
22
|
declare const webpackPlugin: (options: Options) => WebpackPluginInstance;
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import * as rollup from 'rollup';
|
|
2
1
|
import * as unplugin from 'unplugin';
|
|
3
2
|
import { FilterPattern, UnpluginInstance } from 'unplugin';
|
|
3
|
+
import * as rollup from 'rollup';
|
|
4
|
+
import * as vite from 'vite';
|
|
4
5
|
import export_default from './babel.js';
|
|
5
6
|
import '@babel/traverse';
|
|
6
7
|
import '@babel/types';
|
|
@@ -10,11 +11,12 @@ interface Options {
|
|
|
10
11
|
exclude?: FilterPattern;
|
|
11
12
|
enforce?: 'post' | 'pre' | undefined;
|
|
12
13
|
forceTgpuAlias?: string;
|
|
14
|
+
autoNamingEnabled?: boolean;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
declare const typegpu: UnpluginInstance<Options, false>;
|
|
16
18
|
|
|
17
|
-
declare const vitePlugin: (options: Options) =>
|
|
19
|
+
declare const vitePlugin: (options: Options) => vite.Plugin<any>;
|
|
18
20
|
declare const rollupPlugin: (options: Options) => rollup.Plugin<any>;
|
|
19
21
|
declare const rolldownPlugin: (options: Options) => Plugin$3;
|
|
20
22
|
declare const webpackPlugin: (options: Options) => WebpackPluginInstance;
|
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-RRLX57NP.js";import"./chunk-HGJBG4QQ.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.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Build plugins for TypeGPU, enabling seamless JavaScript -> WGSL transpilation and improved debugging.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rollup-plugin",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"unplugin": "^2.3.1"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"typegpu": "^0.
|
|
97
|
+
"typegpu": "^0.6.0"
|
|
98
98
|
},
|
|
99
99
|
"main": "./index.js",
|
|
100
100
|
"types": "./index.d.ts",
|
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 _chunkXXTHHPRCcjs = require('./chunk-XXTHHPRC.cjs');require('./chunk-4DTTWQTW.cjs');var r=_chunkXXTHHPRCcjs.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/konradreczko/TypeGPU/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/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/rolldown.cjs","sourcesContent":[null,"import { rolldownPlugin } from './index.ts';\n\nexport default rolldownPlugin;\n"]}
|
package/rolldown.d.cts
CHANGED
package/rolldown.d.ts
CHANGED
package/rolldown.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{d as o}from"./chunk-
|
|
1
|
+
import{d as o}from"./chunk-RRLX57NP.js";import"./chunk-HGJBG4QQ.js";var r=o;export{r as default};
|
|
2
2
|
//# sourceMappingURL=rolldown.js.map
|
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 _chunkXXTHHPRCcjs = require('./chunk-XXTHHPRC.cjs');require('./chunk-4DTTWQTW.cjs');var r=_chunkXXTHHPRCcjs.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/konradreczko/TypeGPU/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/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/rollup.cjs","sourcesContent":[null,"import { rollupPlugin } from './index.ts';\n\nexport default rollupPlugin;\n"]}
|
package/rollup.d.cts
CHANGED
package/rollup.d.ts
CHANGED
package/rollup.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as l}from"./chunk-
|
|
1
|
+
import{c as l}from"./chunk-RRLX57NP.js";import"./chunk-HGJBG4QQ.js";var r=l;export{r as default};
|
|
2
2
|
//# sourceMappingURL=rollup.js.map
|
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 _chunkXXTHHPRCcjs = require('./chunk-XXTHHPRC.cjs');require('./chunk-4DTTWQTW.cjs');var p=_chunkXXTHHPRCcjs.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/konradreczko/TypeGPU/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/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/rspack.cjs","sourcesContent":[null,"import { rspackPlugin } from './index.ts';\n\nexport default rspackPlugin;\n"]}
|
package/rspack.d.cts
CHANGED
package/rspack.d.ts
CHANGED
package/rspack.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as r}from"./chunk-
|
|
1
|
+
import{f as r}from"./chunk-RRLX57NP.js";import"./chunk-HGJBG4QQ.js";var p=r;export{p as default};
|
|
2
2
|
//# sourceMappingURL=rspack.js.map
|
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 _chunkXXTHHPRCcjs = require('./chunk-XXTHHPRC.cjs');require('./chunk-4DTTWQTW.cjs');var i=_chunkXXTHHPRCcjs.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/konradreczko/TypeGPU/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/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/vite.cjs","sourcesContent":[null,"import { vitePlugin } from './index.ts';\n\nexport default vitePlugin;\n"]}
|
package/vite.d.cts
CHANGED
package/vite.d.ts
CHANGED
package/vite.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as t}from"./chunk-
|
|
1
|
+
import{b as t}from"./chunk-RRLX57NP.js";import"./chunk-HGJBG4QQ.js";var i=t;export{i as default};
|
|
2
2
|
//# sourceMappingURL=vite.js.map
|
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 _chunkXXTHHPRCcjs = require('./chunk-XXTHHPRC.cjs');require('./chunk-4DTTWQTW.cjs');var p=_chunkXXTHHPRCcjs.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/konradreczko/TypeGPU/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/konradreczko/TypeGPU/wigsill/packages/unplugin-typegpu/dist/webpack.cjs","sourcesContent":[null,"import { webpackPlugin } from './index.ts';\n\nexport default webpackPlugin;\n"]}
|
package/webpack.d.cts
CHANGED
package/webpack.d.ts
CHANGED
package/webpack.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{e}from"./chunk-
|
|
1
|
+
import{e}from"./chunk-RRLX57NP.js";import"./chunk-HGJBG4QQ.js";var p=e;export{p as default};
|
|
2
2
|
//# sourceMappingURL=webpack.js.map
|
package/chunk-DO6SOWHC.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import*as f from"@babel/standalone";import{FORMAT_VERSION as h}from"tinyest";import{transpileFn as N}from"tinyest-for-wgsl";var M={include:[/\.m?[jt]sx?$/]};function g(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function m(e,n){let r="",t=n;for(;;)if(t.type==="MemberExpression"){if(t.property.type!=="Identifier")break;r=r?`${t.property.name}.${r}`:t.property.name,t=t.object}else if(t.type==="Identifier"){r=r?`${t.name}.${r}`:t.name;break}else break;return e.tgpuAliases.has(r)}function b(e,n){if(e.source.value==="typegpu")for(let r of e.specifiers)r.type==="ImportDefaultSpecifier"||r.type==="ImportSpecifier"&&r.imported.type==="Identifier"&&r.imported.name==="tgpu"?n.tgpuAliases.add(r.local.name):r.type==="ImportNamespaceSpecifier"&&n.tgpuAliases.add(`${r.local.name}.tgpu`)}var k=["fn","vertexFn","fragmentFn","computeFn"];function y(e,n){return e.callee.type==="CallExpression"&&e.callee.callee.type==="MemberExpression"&&e.callee.callee.property.type==="Identifier"&&k.includes(e.callee.callee.property.name)&&e.arguments.length===1&&(e.callee.callee.object.type==="MemberExpression"?m(n,e.callee.callee.object.object):m(n,e.callee.callee.object))||e.callee.type==="MemberExpression"&&e.arguments.length===1&&e.callee.property.type==="Identifier"&&e.callee.property.name==="does"}var x=["kernel","kernel & js"];function F(e){return`The function "${e!=null?e:"<unnamed>"}" is invokable only on the GPU. If you want to use it on the CPU, mark it with the "kernel & js" directive.`}import{resolve as I}from"path";import v from"picomatch";function E(e){let n=e||[];return Array.isArray(n)?n:[n]}var T=/\\/g;function c(e){return e.replace(T,"/")}var P=/^(?:\/|(?:[A-Z]:)?[/\\|])/i;function C(e){return P.test(e)}function w(e,n){if(e.startsWith("**")||C(e))return c(e);let r=I(n,e);return c(r)}function S(e){if(e instanceof RegExp)return i=>{let s=c(i),l=e.test(s);return e.lastIndex=0,l};let n=process.cwd(),r=w(e,n),t=v(r,{dot:!0});return i=>{let s=c(i);return t(s)}}function D(e,n){if(!(!e&&!n))return r=>e!=null&&e.some(t=>t(r))?!1:n!=null&&n.some(t=>t(r))?!0:!(n&&n.length>0)}function O(e){return typeof e=="string"||e instanceof RegExp?{include:[e]}:Array.isArray(e)?{include:e}:{exclude:e.exclude?E(e.exclude):void 0,include:e.include?E(e.include):void 0}}function $(e){if(!e)return;let{exclude:n,include:r}=O(e),t=n==null?void 0:n.map(S),i=r==null?void 0:r.map(S);return D(t,i)}function A(e){let n=$(e);return n?r=>!!n(r):void 0}var j=f.packages.template,o=f.packages.types;function u(e){var r,t;let n=("directives"in e.body?(t=(r=e.body)==null?void 0:r.directives)!=null?t:[]:[]).map(i=>i.value.value);for(let i of x)if(n.includes(i))return i}function a(e){return o.identifier(e)}function d(e,n,r){if(!n)return null;let{params:t,body:i,externalNames:s}=N(e),l=`{
|
|
2
|
-
v: ${h},
|
|
3
|
-
ast: ${g({params:t,body:i,externalNames:s})},
|
|
4
|
-
externals: {${s.join(", ")}},
|
|
5
|
-
}`,p=n==="kernel & js"?e:o.arrowFunctionExpression([],o.blockStatement([o.throwStatement(o.newExpression(a("Error"),[o.stringLiteral(F(r))]))]));return o.callExpression(o.arrowFunctionExpression([a("$")],o.logicalExpression("&&",o.callExpression(o.memberExpression(o.assignmentExpression("??=",o.memberExpression(a("globalThis"),a("__TYPEGPU_META__")),o.newExpression(a("WeakMap"),[])),a("set")),[o.assignmentExpression("=",o.memberExpression(a("$"),a("f")),p),j.expression`${l}`()]),o.memberExpression(a("$"),a("f")))),[o.objectExpression([])])}function R(e){return{ImportDeclaration(n){b(n.node,e)},ArrowFunctionExpression(n){let r=d(n.node,u(n.node),n.parentPath.node.type==="VariableDeclarator"&&n.parentPath.node.id.type==="Identifier"?n.parentPath.node.id.name:void 0);r&&(n.replaceWith(r),n.skip())},FunctionExpression(n){var t;let r=d(n.node,u(n.node),(t=n.node.id)!=null&&t.name?n.node.id.name:n.parentPath.node.type==="VariableDeclarator"&&n.parentPath.node.id.type==="Identifier"?n.parentPath.node.id.name:void 0);r&&(n.replaceWith(r),n.skip())},FunctionDeclaration(n){var s;let r=n.node,t=o.functionExpression(r.id,r.params,r.body),i=d(t,u(n.node),(s=r.id)==null?void 0:s.name);i&&r.id&&(n.replaceWith(o.variableDeclaration("const",[o.variableDeclarator(r.id,i)])),n.skip())},CallExpression(n){var t;let r=n.node;if(y(r,e)){let i=r.arguments[0];if(i&&(i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression")){let s=d(i,(t=u(i))!=null?t:"kernel");n.replaceWith(o.callExpression(r.callee,[s])),n.skip()}}}}}function V(){return{visitor:{Program(e,n){var p;let r=(p=n.file)==null?void 0:p.code,t=n.opts,i=n.filename,s=A(t);if(i&&s&&!(s!=null&&s(i)))return;let l={tgpuAliases:new Set(t!=null&&t.forceTgpuAlias?[t.forceTgpuAlias]:[]),fileId:i};e.traverse(R(l))}}}}export{M as a,g as b,b as c,y as d,x as e,F as f,V as g};
|
|
6
|
-
//# sourceMappingURL=chunk-DO6SOWHC.js.map
|
package/chunk-DO6SOWHC.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/babel.ts","../src/common.ts","../src/filter.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 { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n embedJSON,\n gatherTgpuAliases,\n getErrorMessage,\n isShellImplementationCall,\n type KernelDirective,\n kernelDirectives,\n type Options,\n} from './common.ts';\nimport { createFilterForId } from './filter.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 i(identifier: string): babel.Identifier {\n return types.identifier(identifier);\n}\n\nfunction functionToTranspiled(\n node: babel.ArrowFunctionExpression | babel.FunctionExpression,\n directive: KernelDirective | undefined,\n name?: string | undefined,\n): babel.CallExpression | null {\n if (!directive) {\n return null;\n }\n\n const { params, body, externalNames } = transpileFn(node);\n\n const metadata = `{\n v: ${FORMAT_VERSION},\n ast: ${embedJSON({ params, body, externalNames })},\n externals: {${externalNames.join(', ')}},\n }`;\n\n const jsImpl = directive === 'kernel & js'\n ? node\n : types.arrowFunctionExpression(\n [],\n types.blockStatement(\n [types.throwStatement(\n types.newExpression(i('Error'), [\n types.stringLiteral(getErrorMessage(name)),\n ]),\n )],\n ),\n );\n\n return types.callExpression(\n types.arrowFunctionExpression(\n [i('$')],\n types.logicalExpression(\n '&&',\n types.callExpression(\n types.memberExpression(\n types.assignmentExpression(\n '??=',\n types.memberExpression(i('globalThis'), i('__TYPEGPU_META__')),\n types.newExpression(i('WeakMap'), []),\n ),\n i('set'),\n ),\n [\n types.assignmentExpression(\n '=',\n types.memberExpression(i('$'), i('f')),\n jsImpl,\n ),\n template.expression`${metadata}`(),\n ],\n ),\n types.memberExpression(i('$'), i('f')),\n ),\n ),\n [types.objectExpression([])],\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 getKernelDirective(path.node),\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 getKernelDirective(path.node),\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(\n expression,\n getKernelDirective(path.node),\n node.id?.name,\n );\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 transpiled = functionToTranspiled(\n implementation,\n getKernelDirective(implementation) ?? 'kernel',\n ) as babel.CallExpression;\n\n path.replaceWith(\n types.callExpression(node.callee, [\n transpiled,\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const code: string | undefined = (state as any).file?.code;\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const options: Options | undefined = (state as any).opts;\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const id: string | undefined = (state as any).filename;\n\n const filter = createFilterForId(options);\n if (id && filter && !filter?.(id)) {\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';\nimport type { FilterPattern } from 'unplugin';\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 Options {\n include?: FilterPattern;\n exclude?: FilterPattern;\n enforce?: 'post' | 'pre' | undefined;\n forceTgpuAlias?: string;\n}\n\nexport const defaultOptions = {\n include: [/\\.m?[jt]sx?$/],\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\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\nexport function getErrorMessage(name: string | undefined) {\n return `The function \"${\n name ?? '<unnamed>'\n }\" is invokable only on the GPU. If you want to use it on the CPU, mark it with the \"kernel & js\" directive.`;\n}\n","// Copied from https://github.com/unjs/unplugin/blob/f514bf8e2d751b48b3a5acb1077eb1292d9711b3/src/utils/filter.ts#L2\n// Used only in the babel version of the plugin, since others can rely on native unplugin functionality.\n\nimport { resolve } from 'node:path';\nimport picomatch from 'picomatch';\nimport type {\n Arrayable,\n Nullable,\n StringFilter,\n StringOrRegExp,\n} from 'unplugin';\n\nfunction toArray<T>(array?: Nullable<Arrayable<T>>): Array<T> {\n const result = array || [];\n if (Array.isArray(result)) return result;\n return [result];\n}\n\nconst BACKSLASH_REGEX = /\\\\/g;\nfunction normalize(path: string): string {\n return path.replace(BACKSLASH_REGEX, '/');\n}\n\nconst ABSOLUTE_PATH_REGEX = /^(?:\\/|(?:[A-Z]:)?[/\\\\|])/i;\nfunction isAbsolute(path: string): boolean {\n return ABSOLUTE_PATH_REGEX.test(path);\n}\n\nexport type PluginFilter = (input: string) => boolean;\nexport type TransformHookFilter = (id: string, code: string) => boolean;\n\ninterface NormalizedStringFilter {\n include?: StringOrRegExp[] | undefined;\n exclude?: StringOrRegExp[] | undefined;\n}\n\nfunction getMatcherString(glob: string, cwd: string) {\n if (glob.startsWith('**') || isAbsolute(glob)) {\n return normalize(glob);\n }\n\n const resolved = resolve(cwd, glob);\n return normalize(resolved);\n}\n\nfunction patternToIdFilter(pattern: StringOrRegExp): PluginFilter {\n if (pattern instanceof RegExp) {\n return (id: string) => {\n const normalizedId = normalize(id);\n const result = pattern.test(normalizedId);\n pattern.lastIndex = 0;\n return result;\n };\n }\n const cwd = process.cwd();\n const glob = getMatcherString(pattern, cwd);\n const matcher = picomatch(glob, { dot: true });\n return (id: string) => {\n const normalizedId = normalize(id);\n return matcher(normalizedId);\n };\n}\n\nfunction patternToCodeFilter(pattern: StringOrRegExp): PluginFilter {\n if (pattern instanceof RegExp) {\n return (code: string) => {\n const result = pattern.test(code);\n pattern.lastIndex = 0;\n return result;\n };\n }\n return (code: string) => code.includes(pattern);\n}\n\nfunction createFilter(\n exclude: PluginFilter[] | undefined,\n include: PluginFilter[] | undefined,\n): PluginFilter | undefined {\n if (!exclude && !include) {\n return;\n }\n\n return (input) => {\n if (exclude?.some((filter) => filter(input))) {\n return false;\n }\n if (include?.some((filter) => filter(input))) {\n return true;\n }\n return !(include && include.length > 0);\n };\n}\n\nfunction normalizeFilter(filter: StringFilter): NormalizedStringFilter {\n if (typeof filter === 'string' || filter instanceof RegExp) {\n return {\n include: [filter],\n };\n }\n if (Array.isArray(filter)) {\n return {\n include: filter,\n };\n }\n return {\n exclude: filter.exclude ? toArray(filter.exclude) : undefined,\n include: filter.include ? toArray(filter.include) : undefined,\n };\n}\n\nfunction createIdFilter(\n filter: StringFilter | undefined,\n): PluginFilter | undefined {\n if (!filter) return;\n const { exclude, include } = normalizeFilter(filter);\n const excludeFilter = exclude?.map(patternToIdFilter);\n const includeFilter = include?.map(patternToIdFilter);\n return createFilter(excludeFilter, includeFilter);\n}\n\nfunction createCodeFilter(\n filter: StringFilter | undefined,\n): PluginFilter | undefined {\n if (!filter) return;\n const { exclude, include } = normalizeFilter(filter);\n const excludeFilter = exclude?.map(patternToCodeFilter);\n const includeFilter = include?.map(patternToCodeFilter);\n return createFilter(excludeFilter, includeFilter);\n}\n\nexport function createFilterForId(\n filter: StringFilter | undefined,\n): PluginFilter | undefined {\n const filterFunction = createIdFilter(filter);\n return filterFunction ? (id) => !!filterFunction(id) : undefined;\n}\n\nfunction createFilterForTransform(\n idFilter: StringFilter | undefined,\n codeFilter: StringFilter | undefined,\n): TransformHookFilter | undefined {\n if (!idFilter && !codeFilter) return;\n const idFilterFunction = createIdFilter(idFilter);\n const codeFilterFunction = createCodeFilter(codeFilter);\n return (id, code) => {\n let fallback = true;\n if (idFilterFunction) {\n fallback &&= idFilterFunction(id);\n }\n if (!fallback) {\n return false;\n }\n\n if (codeFilterFunction) {\n fallback &&= codeFilterFunction(code);\n }\n return fallback;\n };\n}\n"],"mappings":"AAAA,UAAYA,MAAW,oBAIvB,OAAS,kBAAAC,MAAsB,UAC/B,OAAS,eAAAC,MAAmB,mBCerB,IAAMC,EAAiB,CAC5B,QAAS,CAAC,cAAc,CAC1B,EAEO,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,CAEO,SAASE,EACdH,EACAD,EACA,CACA,GAAIC,EAAK,OAAO,QAAU,UACxB,QAAWI,KAAQJ,EAAK,WAGpBI,EAAK,OAAS,0BAEbA,EAAK,OAAS,mBACbA,EAAK,SAAS,OAAS,cACvBA,EAAK,SAAS,OAAS,OAEzBL,EAAI,YAAY,IAAIK,EAAK,MAAM,IAAI,EAC1BA,EAAK,OAAS,4BAEvBL,EAAI,YAAY,IAAI,GAAGK,EAAK,MAAM,IAAI,OAAO,CAIrD,CAEA,IAAMC,EAAuB,CAAC,KAAM,WAAY,aAAc,WAAW,EAElE,SAASC,EACdN,EACAD,EACA,CACA,OACGC,EAAK,OAAO,OAAS,kBACpBA,EAAK,OAAO,OAAO,OAAS,oBAC5BA,EAAK,OAAO,OAAO,SAAS,OAAS,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EvC,GACE0B,IACCA,EAAe,OAAS,sBACvBA,EAAe,OAAS,2BAC1B,CACA,IAAMH,EAAaf,EACjBkB,GACAzB,EAAAF,EAAmB2B,CAAc,IAAjC,KAAAzB,EAAsC,QACxC,EAEAoB,EAAK,YACHvB,EAAM,eAAeE,EAAK,OAAQ,CAChCuB,CACF,CAAC,CACH,EAEAF,EAAK,KAAK,CACZ,CACF,CACF,CACF,CACF,CAEe,SAARM,GAAoB,CACzB,MAAO,CACL,QAAS,CACP,QAAQN,EAAMO,EAAO,CAzM3B,IAAA3B,EA2MQ,IAAM4B,GAA4B5B,EAAA2B,EAAc,OAAd,YAAA3B,EAAoB,KAEhD6B,EAAgCF,EAAc,KAE9CG,EAA0BH,EAAc,SAExCI,EAASC,EAAkBH,CAAO,EACxC,GAAIC,GAAMC,GAAU,EAACA,GAAA,MAAAA,EAASD,IAC5B,OAGF,IAAMX,EAAe,CACnB,YAAa,IAAI,IACfU,GAAA,MAAAA,EAAS,eAAiB,CAACA,EAAQ,cAAc,EAAI,CAAC,CACxD,EACA,OAAQC,CACV,EAEAV,EAAK,SAASF,EAAgBC,CAAG,CAAC,CACpC,CACF,CACF,CACF","names":["Babel","FORMAT_VERSION","transpileFn","defaultOptions","embedJSON","jsValue","isTgpu","ctx","node","path","tail","gatherTgpuAliases","spec","fnShellFunctionNames","isShellImplementationCall","kernelDirectives","getErrorMessage","name","resolve","picomatch","toArray","array","result","BACKSLASH_REGEX","normalize","path","ABSOLUTE_PATH_REGEX","isAbsolute","getMatcherString","glob","cwd","resolved","patternToIdFilter","pattern","id","normalizedId","matcher","createFilter","exclude","include","input","filter","normalizeFilter","toArray","createIdFilter","excludeFilter","patternToIdFilter","includeFilter","createFilterForId","filter","filterFunction","createIdFilter","id","template","types","getKernelDirective","node","_a","_b","directives","directive","kernelDirectives","i","identifier","functionToTranspiled","name","params","body","externalNames","transpileFn","metadata","FORMAT_VERSION","embedJSON","jsImpl","getErrorMessage","functionVisitor","ctx","path","gatherTgpuAliases","transpiled","expression","isShellImplementationCall","implementation","babel_default","state","code","options","id","filter","createFilterForId"]}
|
package/chunk-G6NIIU55.cjs
DELETED
|
@@ -1,6 +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; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _standalone = require('@babel/standalone'); var f = _interopRequireWildcard(_standalone);var _tinyest = require('tinyest');var _tinyestforwgsl = require('tinyest-for-wgsl');var M={include:[/\.m?[jt]sx?$/]};function g(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function m(e,n){let r="",t=n;for(;;)if(t.type==="MemberExpression"){if(t.property.type!=="Identifier")break;r=r?`${t.property.name}.${r}`:t.property.name,t=t.object}else if(t.type==="Identifier"){r=r?`${t.name}.${r}`:t.name;break}else break;return e.tgpuAliases.has(r)}function b(e,n){if(e.source.value==="typegpu")for(let r of e.specifiers)r.type==="ImportDefaultSpecifier"||r.type==="ImportSpecifier"&&r.imported.type==="Identifier"&&r.imported.name==="tgpu"?n.tgpuAliases.add(r.local.name):r.type==="ImportNamespaceSpecifier"&&n.tgpuAliases.add(`${r.local.name}.tgpu`)}var k=["fn","vertexFn","fragmentFn","computeFn"];function y(e,n){return e.callee.type==="CallExpression"&&e.callee.callee.type==="MemberExpression"&&e.callee.callee.property.type==="Identifier"&&k.includes(e.callee.callee.property.name)&&e.arguments.length===1&&(e.callee.callee.object.type==="MemberExpression"?m(n,e.callee.callee.object.object):m(n,e.callee.callee.object))||e.callee.type==="MemberExpression"&&e.arguments.length===1&&e.callee.property.type==="Identifier"&&e.callee.property.name==="does"}var x=["kernel","kernel & js"];function F(e){return`The function "${e!=null?e:"<unnamed>"}" is invokable only on the GPU. If you want to use it on the CPU, mark it with the "kernel & js" directive.`}var _path = require('path');var _picomatch = require('picomatch'); var _picomatch2 = _interopRequireDefault(_picomatch);function E(e){let n=e||[];return Array.isArray(n)?n:[n]}var T=/\\/g;function c(e){return e.replace(T,"/")}var P=/^(?:\/|(?:[A-Z]:)?[/\\|])/i;function C(e){return P.test(e)}function w(e,n){if(e.startsWith("**")||C(e))return c(e);let r=_path.resolve.call(void 0, n,e);return c(r)}function S(e){if(e instanceof RegExp)return i=>{let s=c(i),l=e.test(s);return e.lastIndex=0,l};let n=process.cwd(),r=w(e,n),t=_picomatch2.default.call(void 0, r,{dot:!0});return i=>{let s=c(i);return t(s)}}function D(e,n){if(!(!e&&!n))return r=>e!=null&&e.some(t=>t(r))?!1:n!=null&&n.some(t=>t(r))?!0:!(n&&n.length>0)}function O(e){return typeof e=="string"||e instanceof RegExp?{include:[e]}:Array.isArray(e)?{include:e}:{exclude:e.exclude?E(e.exclude):void 0,include:e.include?E(e.include):void 0}}function $(e){if(!e)return;let{exclude:n,include:r}=O(e),t=n==null?void 0:n.map(S),i=r==null?void 0:r.map(S);return D(t,i)}function A(e){let n=$(e);return n?r=>!!n(r):void 0}var j=f.packages.template,o=f.packages.types;function u(e){var r,t;let n=("directives"in e.body?(t=(r=e.body)==null?void 0:r.directives)!=null?t:[]:[]).map(i=>i.value.value);for(let i of x)if(n.includes(i))return i}function a(e){return o.identifier(e)}function d(e,n,r){if(!n)return null;let{params:t,body:i,externalNames:s}=_tinyestforwgsl.transpileFn.call(void 0, e),l=`{
|
|
2
|
-
v: ${_tinyest.FORMAT_VERSION},
|
|
3
|
-
ast: ${g({params:t,body:i,externalNames:s})},
|
|
4
|
-
externals: {${s.join(", ")}},
|
|
5
|
-
}`,p=n==="kernel & js"?e:o.arrowFunctionExpression([],o.blockStatement([o.throwStatement(o.newExpression(a("Error"),[o.stringLiteral(F(r))]))]));return o.callExpression(o.arrowFunctionExpression([a("$")],o.logicalExpression("&&",o.callExpression(o.memberExpression(o.assignmentExpression("??=",o.memberExpression(a("globalThis"),a("__TYPEGPU_META__")),o.newExpression(a("WeakMap"),[])),a("set")),[o.assignmentExpression("=",o.memberExpression(a("$"),a("f")),p),j.expression`${l}`()]),o.memberExpression(a("$"),a("f")))),[o.objectExpression([])])}function R(e){return{ImportDeclaration(n){b(n.node,e)},ArrowFunctionExpression(n){let r=d(n.node,u(n.node),n.parentPath.node.type==="VariableDeclarator"&&n.parentPath.node.id.type==="Identifier"?n.parentPath.node.id.name:void 0);r&&(n.replaceWith(r),n.skip())},FunctionExpression(n){var t;let r=d(n.node,u(n.node),(t=n.node.id)!=null&&t.name?n.node.id.name:n.parentPath.node.type==="VariableDeclarator"&&n.parentPath.node.id.type==="Identifier"?n.parentPath.node.id.name:void 0);r&&(n.replaceWith(r),n.skip())},FunctionDeclaration(n){var s;let r=n.node,t=o.functionExpression(r.id,r.params,r.body),i=d(t,u(n.node),(s=r.id)==null?void 0:s.name);i&&r.id&&(n.replaceWith(o.variableDeclaration("const",[o.variableDeclarator(r.id,i)])),n.skip())},CallExpression(n){var t;let r=n.node;if(y(r,e)){let i=r.arguments[0];if(i&&(i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression")){let s=d(i,(t=u(i))!=null?t:"kernel");n.replaceWith(o.callExpression(r.callee,[s])),n.skip()}}}}}function V(){return{visitor:{Program(e,n){var p;let r=(p=n.file)==null?void 0:p.code,t=n.opts,i=n.filename,s=A(t);if(i&&s&&!(s!=null&&s(i)))return;let l={tgpuAliases:new Set(t!=null&&t.forceTgpuAlias?[t.forceTgpuAlias]:[]),fileId:i};e.traverse(R(l))}}}}exports.a = M; exports.b = g; exports.c = b; exports.d = y; exports.e = x; exports.f = F; exports.g = V;
|
|
6
|
-
//# sourceMappingURL=chunk-G6NIIU55.cjs.map
|
package/chunk-G6NIIU55.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/babel.ts","../src/common.ts"],"names":["defaultOptions","embedJSON","jsValue","isTgpu","ctx","node","path","tail"],"mappings":"AAAA,whBAAuB,kCAIQ,kDACH,ICefA,CAAAA,CAAiB,CAC5B,OAAA,CAAS,CAAC,cAAc,CAC1B,CAAA,CAEO,SAASC,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;ADcG,OAAA;AAC8B,SAAA;AACX,gBAAA;AA0BtB,GAAA","file":"/Users/iwo/Projects/wigsill/packages/unplugin-typegpu/dist/chunk-G6NIIU55.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 { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n embedJSON,\n gatherTgpuAliases,\n getErrorMessage,\n isShellImplementationCall,\n type KernelDirective,\n kernelDirectives,\n type Options,\n} from './common.ts';\nimport { createFilterForId } from './filter.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 i(identifier: string): babel.Identifier {\n return types.identifier(identifier);\n}\n\nfunction functionToTranspiled(\n node: babel.ArrowFunctionExpression | babel.FunctionExpression,\n directive: KernelDirective | undefined,\n name?: string | undefined,\n): babel.CallExpression | null {\n if (!directive) {\n return null;\n }\n\n const { params, body, externalNames } = transpileFn(node);\n\n const metadata = `{\n v: ${FORMAT_VERSION},\n ast: ${embedJSON({ params, body, externalNames })},\n externals: {${externalNames.join(', ')}},\n }`;\n\n const jsImpl = directive === 'kernel & js'\n ? node\n : types.arrowFunctionExpression(\n [],\n types.blockStatement(\n [types.throwStatement(\n types.newExpression(i('Error'), [\n types.stringLiteral(getErrorMessage(name)),\n ]),\n )],\n ),\n );\n\n return types.callExpression(\n types.arrowFunctionExpression(\n [i('$')],\n types.logicalExpression(\n '&&',\n types.callExpression(\n types.memberExpression(\n types.assignmentExpression(\n '??=',\n types.memberExpression(i('globalThis'), i('__TYPEGPU_META__')),\n types.newExpression(i('WeakMap'), []),\n ),\n i('set'),\n ),\n [\n types.assignmentExpression(\n '=',\n types.memberExpression(i('$'), i('f')),\n jsImpl,\n ),\n template.expression`${metadata}`(),\n ],\n ),\n types.memberExpression(i('$'), i('f')),\n ),\n ),\n [types.objectExpression([])],\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 getKernelDirective(path.node),\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 getKernelDirective(path.node),\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(\n expression,\n getKernelDirective(path.node),\n node.id?.name,\n );\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 transpiled = functionToTranspiled(\n implementation,\n getKernelDirective(implementation) ?? 'kernel',\n ) as babel.CallExpression;\n\n path.replaceWith(\n types.callExpression(node.callee, [\n transpiled,\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const code: string | undefined = (state as any).file?.code;\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const options: Options | undefined = (state as any).opts;\n // biome-ignore lint/suspicious/noExplicitAny: <oh babel babel...>\n const id: string | undefined = (state as any).filename;\n\n const filter = createFilterForId(options);\n if (id && filter && !filter?.(id)) {\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';\nimport type { FilterPattern } from 'unplugin';\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 Options {\n include?: FilterPattern;\n exclude?: FilterPattern;\n enforce?: 'post' | 'pre' | undefined;\n forceTgpuAlias?: string;\n}\n\nexport const defaultOptions = {\n include: [/\\.m?[jt]sx?$/],\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\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\nexport function getErrorMessage(name: string | undefined) {\n return `The function \"${\n name ?? '<unnamed>'\n }\" is invokable only on the GPU. If you want to use it on the CPU, mark it with the \"kernel & js\" directive.`;\n}\n"]}
|
package/chunk-LI2BURW4.cjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkG6NIIU55cjs = require('./chunk-G6NIIU55.cjs');var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);var _estreewalker = require('estree-walker');var _magicstringast = require('magic-string-ast');var _tinyest = require('tinyest');var _tinyestforwgsl = require('tinyest-for-wgsl');var _unplugin = require('unplugin');function D(c){if(c.body.type==="BlockStatement"){for(let n of c.body.body)if(n.type==="ExpressionStatement"&&_chunkG6NIIU55cjs.e.includes(n.directive))return n.directive}}function E(c){let n=structuredClone(c);return n.body.type==="BlockStatement"&&(n.body.body=n.body.body.filter(s=>!(s.type==="ExpressionStatement"&&s.directive&&_chunkG6NIIU55cjs.e.includes(s.directive)))),n}var r=_unplugin.createUnplugin.call(void 0, c=>{let n=_defu2.default.call(void 0, c,_chunkG6NIIU55cjs.a);return{name:"unplugin-typegpu",enforce:n.enforce,transform:{filter:{id:n},handler(s,p){let g={tgpuAliases:new Set(n.forceTgpuAlias?[n.forceTgpuAlias]:[]),fileId:p},k=this.parse(s,{allowReturnOutsideFunction:!0}),l=[],u=new (0, _magicstringast.MagicStringAST)(s);_estreewalker.walk.call(void 0, k,{enter(i,t,m,y){var a;let e=i;if(e.type==="ImportDeclaration"&&_chunkG6NIIU55cjs.c.call(void 0, e,g),e.type==="CallExpression"&&_chunkG6NIIU55cjs.d.call(void 0, e,g)){let o=e.arguments[0];if(o&&(o.type==="FunctionExpression"||o.type==="ArrowFunctionExpression")){let f=D(o);l.push({def:E(o),removeJsImplementation:f!=="kernel & js"}),this.skip()}}if(e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"||e.type==="FunctionDeclaration"){let o=D(e);o&&(l.push({def:E(e),name:e.type==="FunctionDeclaration"||e.type==="FunctionExpression"?(a=e.id)==null?void 0:a.name:(t==null?void 0:t.type)==="VariableDeclarator"&&t.id.type==="Identifier"?t.id.name:void 0,removeJsImplementation:o!=="kernel & js"}),this.skip())}}});for(let{def:i,name:t,removeJsImplementation:m}of l){let{params:y,body:e,externalNames:a}=_tinyestforwgsl.transpileFn.call(void 0, i),o=i.type==="FunctionDeclaration";o&&t&&s.slice(0,i.start).search(new RegExp(`(?<![\\w_.])${t}(?![\\w_])`))!==-1&&console.warn(`File ${p}: function "${t}", containing ${m?"kernel":"kernel & js"} directive, might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);let f=`{
|
|
2
|
-
v: ${_tinyest.FORMAT_VERSION},
|
|
3
|
-
ast: ${_chunkG6NIIU55cjs.b.call(void 0, {params:y,body:e,externalNames:a})},
|
|
4
|
-
externals: {${a.join(", ")}},
|
|
5
|
-
}`;u.appendLeft(i.start,`${o&&t?`const ${t} = `:""}
|
|
6
|
-
(($) => ((globalThis.__TYPEGPU_META__ ??= new WeakMap()).set(
|
|
7
|
-
$.f = (`).appendRight(i.end,`) , ${f}) && $.f))({})`),m&&u.overwriteNode(i,`() => {
|
|
8
|
-
throw new Error(\`${_chunkG6NIIU55cjs.f.call(void 0, t)}\`);
|
|
9
|
-
}`)}return _magicstringast.generateTransform.call(void 0, u,p)}}}}),B= exports.a =r,V= exports.b =r.vite,_= exports.c =r.rollup,G= exports.d =r.rolldown,L= exports.e =r.webpack,W= exports.f =r.rspack,Y= exports.g =r.esbuild,q= exports.h =r.farm,z= exports.i =_chunkG6NIIU55cjs.g;exports.a = B; exports.b = V; exports.c = _; exports.d = G; exports.e = L; exports.f = W; exports.g = Y; exports.h = q; exports.i = z;
|
|
10
|
-
//# sourceMappingURL=chunk-LI2BURW4.cjs.map
|
package/chunk-LI2BURW4.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/iwo/Projects/wigsill/packages/unplugin-typegpu/dist/chunk-LI2BURW4.cjs","../src/index.ts"],"names":["getKernelDirective","node","statement","kernelDirectives","removeKernelDirective","cloned","typegpu","createUnplugin","rawOptions","options","defu","defaultOptions","code","id","ctx","ast","tgslFunctionDefs","magicString","MagicStringAST","walk","_node","_parent","prop","index","_a","gatherTgpuAliases","isShellImplementationCall","implementation","directive","def","name","removeJsImplementation","params","body","externalNames","transpileFn","isFunctionStatement","metadata","FORMAT_VERSION","embedJSON"],"mappings":"AAAA,iOAA6E,wECC5D,6CACe,kDACkB,kCACnB,kDACH,oCAC0B,SAoB7CA,CAAAA,CAAmBC,CAAAA,CAAiD,CAC3E,EAAA,CAAIA,CAAAA,CAAK,IAAA,CAAK,IAAA,GAAS,gBAAA,CAAA,CACrB,GAAA,CAAA,IAAWC,EAAAA,GAAaD,CAAAA,CAAK,IAAA,CAAK,IAAA,CAChC,EAAA,CAAIC,CAAAA,CAAU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,EACnCA,CAAAA,CAAc,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,aAAA,CAAA,CAIxCjB,CAAAA,CAAY,UAAA,CACVY,CAAAA,CAAI,KAAA,CACJ,CAAA,EAAA;AAAwD;AAGxD,uBAAA;AAQE,oCAAA;AAYhB,iBAAA","file":"/Users/iwo/Projects/wigsill/packages/unplugin-typegpu/dist/chunk-LI2BURW4.cjs","sourcesContent":[null,"import type * as acorn from 'acorn';\nimport defu from 'defu';\nimport { type Node, walk } from 'estree-walker';\nimport { generateTransform, MagicStringAST } from 'magic-string-ast';\nimport { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { createUnplugin, type UnpluginInstance } from 'unplugin';\nimport babel from './babel.ts';\nimport {\n type Context,\n defaultOptions,\n embedJSON,\n gatherTgpuAliases,\n getErrorMessage,\n isShellImplementationCall,\n type KernelDirective,\n kernelDirectives,\n type Options,\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 const cloned = structuredClone(node);\n\n if (cloned.body.type === 'BlockStatement') {\n cloned.body.body = cloned.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 cloned;\n}\n\nconst typegpu: UnpluginInstance<Options, false> = createUnplugin(\n (rawOptions) => {\n const options = defu(rawOptions, defaultOptions);\n\n return {\n name: 'unplugin-typegpu' as const,\n enforce: options.enforce,\n transform: {\n filter: {\n id: options,\n },\n handler(code, id) {\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 const magicString = new MagicStringAST(code);\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 this.skip();\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: 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 this.skip();\n }\n }\n },\n });\n\n for (\n const {\n def,\n name,\n removeJsImplementation,\n } of tgslFunctionDefs\n ) {\n const { params, 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 console.warn(\n `File ${id}: function \"${name}\", containing ${\n removeJsImplementation ? 'kernel' : 'kernel & js'\n } directive, might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`,\n );\n }\n\n const metadata = `{\n v: ${FORMAT_VERSION},\n ast: ${embedJSON({ params, body, externalNames })},\n externals: {${externalNames.join(', ')}},\n }`;\n\n // Wrap the implementation in a set to `globalThis` to associate the name, AST and externals with the implementation.\n magicString.appendLeft(\n def.start,\n `${isFunctionStatement && name ? `const ${name} = ` : ''}\n (($) => ((globalThis.__TYPEGPU_META__ ??= new WeakMap()).set(\n $.f = (`,\n ).appendRight(\n def.end,\n `) , ${metadata}) && $.f))({})`,\n );\n\n if (removeJsImplementation) {\n magicString.overwriteNode(\n def,\n `() => {\n throw new Error(\\`${getErrorMessage(name)}\\`);\n }`,\n );\n }\n }\n\n return generateTransform(magicString, id);\n },\n },\n };\n },\n);\n\nexport type { Options } from './common.ts';\n\nexport default typegpu;\n\nexport const vitePlugin = typegpu.vite;\nexport const rollupPlugin = typegpu.rollup;\nexport const rolldownPlugin = typegpu.rolldown;\nexport const webpackPlugin = typegpu.webpack;\nexport const rspackPlugin = typegpu.rspack;\nexport const esbuildPlugin = typegpu.esbuild;\nexport const farmPlugin = typegpu.farm;\nexport const babelPlugin = babel;\n"]}
|
package/chunk-LML6XL7I.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import{a as x,b,c as v,d as F,e as d,f as w,g as h}from"./chunk-DO6SOWHC.js";import $ from"defu";import{walk as A}from"estree-walker";import{generateTransform as S,MagicStringAST as I}from"magic-string-ast";import{FORMAT_VERSION as N}from"tinyest";import{transpileFn as P}from"tinyest-for-wgsl";import{createUnplugin as T}from"unplugin";function D(c){if(c.body.type==="BlockStatement"){for(let n of c.body.body)if(n.type==="ExpressionStatement"&&d.includes(n.directive))return n.directive}}function E(c){let n=structuredClone(c);return n.body.type==="BlockStatement"&&(n.body.body=n.body.body.filter(s=>!(s.type==="ExpressionStatement"&&s.directive&&d.includes(s.directive)))),n}var r=T(c=>{let n=$(c,x);return{name:"unplugin-typegpu",enforce:n.enforce,transform:{filter:{id:n},handler(s,p){let g={tgpuAliases:new Set(n.forceTgpuAlias?[n.forceTgpuAlias]:[]),fileId:p},k=this.parse(s,{allowReturnOutsideFunction:!0}),l=[],u=new I(s);A(k,{enter(i,t,m,y){var a;let e=i;if(e.type==="ImportDeclaration"&&v(e,g),e.type==="CallExpression"&&F(e,g)){let o=e.arguments[0];if(o&&(o.type==="FunctionExpression"||o.type==="ArrowFunctionExpression")){let f=D(o);l.push({def:E(o),removeJsImplementation:f!=="kernel & js"}),this.skip()}}if(e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"||e.type==="FunctionDeclaration"){let o=D(e);o&&(l.push({def:E(e),name:e.type==="FunctionDeclaration"||e.type==="FunctionExpression"?(a=e.id)==null?void 0:a.name:(t==null?void 0:t.type)==="VariableDeclarator"&&t.id.type==="Identifier"?t.id.name:void 0,removeJsImplementation:o!=="kernel & js"}),this.skip())}}});for(let{def:i,name:t,removeJsImplementation:m}of l){let{params:y,body:e,externalNames:a}=P(i),o=i.type==="FunctionDeclaration";o&&t&&s.slice(0,i.start).search(new RegExp(`(?<![\\w_.])${t}(?![\\w_])`))!==-1&&console.warn(`File ${p}: function "${t}", containing ${m?"kernel":"kernel & js"} directive, might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);let f=`{
|
|
2
|
-
v: ${N},
|
|
3
|
-
ast: ${b({params:y,body:e,externalNames:a})},
|
|
4
|
-
externals: {${a.join(", ")}},
|
|
5
|
-
}`;u.appendLeft(i.start,`${o&&t?`const ${t} = `:""}
|
|
6
|
-
(($) => ((globalThis.__TYPEGPU_META__ ??= new WeakMap()).set(
|
|
7
|
-
$.f = (`).appendRight(i.end,`) , ${f}) && $.f))({})`),m&&u.overwriteNode(i,`() => {
|
|
8
|
-
throw new Error(\`${w(t)}\`);
|
|
9
|
-
}`)}return S(u,p)}}}}),B=r,V=r.vite,_=r.rollup,G=r.rolldown,L=r.webpack,W=r.rspack,Y=r.esbuild,q=r.farm,z=h;export{B as a,V as b,_ as c,G as d,L as e,W as f,Y as g,q as h,z as i};
|
|
10
|
-
//# sourceMappingURL=chunk-LML6XL7I.js.map
|
package/chunk-LML6XL7I.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type * as acorn from 'acorn';\nimport defu from 'defu';\nimport { type Node, walk } from 'estree-walker';\nimport { generateTransform, MagicStringAST } from 'magic-string-ast';\nimport { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { createUnplugin, type UnpluginInstance } from 'unplugin';\nimport babel from './babel.ts';\nimport {\n type Context,\n defaultOptions,\n embedJSON,\n gatherTgpuAliases,\n getErrorMessage,\n isShellImplementationCall,\n type KernelDirective,\n kernelDirectives,\n type Options,\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 const cloned = structuredClone(node);\n\n if (cloned.body.type === 'BlockStatement') {\n cloned.body.body = cloned.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 cloned;\n}\n\nconst typegpu: UnpluginInstance<Options, false> = createUnplugin(\n (rawOptions) => {\n const options = defu(rawOptions, defaultOptions);\n\n return {\n name: 'unplugin-typegpu' as const,\n enforce: options.enforce,\n transform: {\n filter: {\n id: options,\n },\n handler(code, id) {\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 const magicString = new MagicStringAST(code);\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 this.skip();\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: 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 this.skip();\n }\n }\n },\n });\n\n for (\n const {\n def,\n name,\n removeJsImplementation,\n } of tgslFunctionDefs\n ) {\n const { params, 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 console.warn(\n `File ${id}: function \"${name}\", containing ${\n removeJsImplementation ? 'kernel' : 'kernel & js'\n } directive, might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`,\n );\n }\n\n const metadata = `{\n v: ${FORMAT_VERSION},\n ast: ${embedJSON({ params, body, externalNames })},\n externals: {${externalNames.join(', ')}},\n }`;\n\n // Wrap the implementation in a set to `globalThis` to associate the name, AST and externals with the implementation.\n magicString.appendLeft(\n def.start,\n `${isFunctionStatement && name ? `const ${name} = ` : ''}\n (($) => ((globalThis.__TYPEGPU_META__ ??= new WeakMap()).set(\n $.f = (`,\n ).appendRight(\n def.end,\n `) , ${metadata}) && $.f))({})`,\n );\n\n if (removeJsImplementation) {\n magicString.overwriteNode(\n def,\n `() => {\n throw new Error(\\`${getErrorMessage(name)}\\`);\n }`,\n );\n }\n }\n\n return generateTransform(magicString, id);\n },\n },\n };\n },\n);\n\nexport type { Options } from './common.ts';\n\nexport default typegpu;\n\nexport const vitePlugin = typegpu.vite;\nexport const rollupPlugin = typegpu.rollup;\nexport const rolldownPlugin = typegpu.rolldown;\nexport const webpackPlugin = typegpu.webpack;\nexport const rspackPlugin = typegpu.rspack;\nexport const esbuildPlugin = typegpu.esbuild;\nexport const farmPlugin = typegpu.farm;\nexport const babelPlugin = babel;\n"],"mappings":"6EACA,OAAOA,MAAU,OACjB,OAAoB,QAAAC,MAAY,gBAChC,OAAS,qBAAAC,EAAmB,kBAAAC,MAAsB,mBAClD,OAAS,kBAAAC,MAAsB,UAC/B,OAAS,eAAAC,MAAmB,mBAC5B,OAAS,kBAAAC,MAA6C,WAoBtD,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,IAAMI,EAAS,gBAAgBJ,CAAI,EAEnC,OAAII,EAAO,KAAK,OAAS,mBACvBA,EAAO,KAAK,KAAOA,EAAO,KAAK,KAAK,OACjCH,GACC,EACEA,EAAU,OAAS,uBACnBA,EAAU,WAC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OAAS,aAClBA,EAAQ,GAAG,KAEb,OACJ,uBAAwBO,IAAc,aACxC,CAAC,EACD,KAAK,KAAK,EAEd,CACF,CACF,CAAC,EAED,OACQ,CACJ,IAAAC,EACA,KAAAC,EACA,uBAAAC,CACF,IAAKf,EACL,CACA,GAAM,CAAE,OAAAgB,EAAQ,KAAAC,EAAM,cAAAC,CAAc,EAAIC,EAAYN,CAAG,EACjDO,EAAsBP,EAAI,OAAS,sBAGvCO,GACAN,GACAlB,EACK,MAAM,EAAGiB,EAAI,KAAK,EAClB,OAAO,IAAI,OAAO,eAAeC,CAAI,YAAY,CAAC,IAAM,IAE7D,QAAQ,KACN,QAAQjB,CAAE,eAAeiB,CAAI,iBAC3BC,EAAyB,SAAW,aACtC,2IACF,EAGF,IAAMM,EAAW;AAAA,mBACVC,CAAc;AAAA,qBACZC,EAAU,CAAE,OAAAP,EAAQ,KAAAC,EAAM,cAAAC,CAAc,CAAC,CAAC;AAAA,4BACnCA,EAAc,KAAK,IAAI,CAAC;AAAA,eAIxCjB,EAAY,WACVY,EAAI,MACJ,GAAGO,GAAuBN,EAAO,SAASA,CAAI,MAAQ,EAAE;AAAA;AAAA,wBAG1D,EAAE,YACAD,EAAI,IACJ,OAAOQ,CAAQ,gBACjB,EAEIN,GACFd,EAAY,cACVY,EACA;AAAA,sCACsBW,EAAgBV,CAAI,CAAC;AAAA,kBAE7C,CAEJ,CAEA,OAAOW,EAAkBxB,EAAaJ,CAAE,CAC1C,CACF,CACF,CACF,CACF,EAIO6B,EAAQpC,EAEFqC,EAAarC,EAAQ,KACrBsC,EAAetC,EAAQ,OACvBuC,EAAiBvC,EAAQ,SACzBwC,EAAgBxC,EAAQ,QACxByC,EAAezC,EAAQ,OACvB0C,EAAgB1C,EAAQ,QACxB2C,EAAa3C,EAAQ,KACrB4C,EAAcC","names":["defu","walk","generateTransform","MagicStringAST","FORMAT_VERSION","transpileFn","createUnplugin","getKernelDirective","node","statement","kernelDirectives","removeKernelDirective","cloned","typegpu","createUnplugin","rawOptions","options","defu","defaultOptions","code","id","ctx","ast","tgslFunctionDefs","magicString","MagicStringAST","walk","_node","_parent","prop","index","_a","gatherTgpuAliases","isShellImplementationCall","implementation","directive","def","name","removeJsImplementation","params","body","externalNames","transpileFn","isFunctionStatement","metadata","FORMAT_VERSION","embedJSON","getErrorMessage","generateTransform","index_default","vitePlugin","rollupPlugin","rolldownPlugin","webpackPlugin","rspackPlugin","esbuildPlugin","farmPlugin","babelPlugin","babel_default"]}
|
/package/{LICENSE.md → LICENSE}
RENAMED
|
File without changes
|