unplugin-typegpu 0.11.2 → 0.11.4

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.
Files changed (70) hide show
  1. package/{babel-C8UzthFd.d.cts → babel-CXwXwwOE.d.ts} +2 -1
  2. package/{babel-B-IcpMR7.cjs → babel-D-TCImIi.cjs} +20 -18
  3. package/{babel-CbManzjz.js → babel-dNT1_5hS.js} +2 -1
  4. package/{babel-CmCnq-43.d.ts → babel-mqeTZT8y.d.cts} +2 -1
  5. package/babel.cjs +2 -2
  6. package/babel.d.cts +2 -2
  7. package/babel.d.ts +2 -2
  8. package/babel.js +2 -2
  9. package/{bun-ovScJ4Es.d.ts → bun-C6usJAus.d.ts} +1 -1
  10. package/bun-DY6XE5xi.js +33 -0
  11. package/{bun-cwXs2EDP.d.cts → bun-Df2nJEmj.d.cts} +1 -1
  12. package/bun-o6QmlVaS.cjs +39 -0
  13. package/bun.cjs +3 -2
  14. package/bun.d.cts +2 -2
  15. package/bun.d.ts +2 -2
  16. package/bun.js +3 -2
  17. package/{common-CElmMmuq.js → common-B8nnr-Iq.js} +2 -7
  18. package/{common-BlvLUwEz.d.ts → common-BLW8Fy4P.d.ts} +2 -2
  19. package/{common-DZ2cLtbe.d.cts → common-BaikgpzR.d.cts} +1 -1
  20. package/{common-B8wsLJUq.cjs → common-DPfAcXic.cjs} +2 -13
  21. package/esbuild.cjs +6 -4
  22. package/esbuild.d.cts +5 -4
  23. package/esbuild.d.ts +5 -4
  24. package/esbuild.js +6 -4
  25. package/factory-B0CnGO9P.cjs +208 -0
  26. package/{bun-CDECNeIU.js → factory-CnVNvO57.js} +109 -48
  27. package/farm.cjs +6 -4
  28. package/farm.d.cts +5 -4
  29. package/farm.d.ts +5 -4
  30. package/farm.js +6 -4
  31. package/index-Dq70sYN7.d.cts +15 -0
  32. package/index-rnHwqPEN.d.ts +15 -0
  33. package/index.cjs +7 -5
  34. package/index.d.cts +5 -4
  35. package/index.d.ts +5 -4
  36. package/index.js +6 -4
  37. package/package.json +3 -3
  38. package/rolldown-browser-BzaTpeZq.cjs +12 -0
  39. package/rolldown-browser-C8OHaYCP.d.ts +40 -0
  40. package/rolldown-browser-D0pxy7TZ.js +7 -0
  41. package/rolldown-browser-XXZriqjg.d.cts +40 -0
  42. package/rolldown-browser.cjs +6 -0
  43. package/rolldown-browser.d.cts +3 -0
  44. package/rolldown-browser.d.ts +3 -0
  45. package/rolldown-browser.js +5 -0
  46. package/rolldown.cjs +6 -4
  47. package/rolldown.d.cts +5 -4
  48. package/rolldown.d.ts +5 -4
  49. package/rolldown.js +6 -4
  50. package/rollup.cjs +6 -4
  51. package/rollup.d.cts +5 -4
  52. package/rollup.d.ts +5 -4
  53. package/rollup.js +6 -4
  54. package/rspack.cjs +6 -4
  55. package/rspack.d.cts +5 -4
  56. package/rspack.d.ts +5 -4
  57. package/rspack.js +6 -4
  58. package/{src-CDZ6lHsg.cjs → src-BljgtpqS.cjs} +3 -13
  59. package/{src-D84rmPxv.js → src-DZP2_1Gn.js} +2 -6
  60. package/vite.cjs +6 -4
  61. package/vite.d.cts +5 -4
  62. package/vite.d.ts +5 -4
  63. package/vite.js +6 -4
  64. package/webpack.cjs +6 -4
  65. package/webpack.d.cts +5 -4
  66. package/webpack.d.ts +5 -4
  67. package/webpack.js +6 -4
  68. package/bun-DU5xZoDJ.cjs +0 -152
  69. package/index-COIv1oYx.d.cts +0 -48
  70. package/index-PPreQbn5.d.ts +0 -48
@@ -1,4 +1,5 @@
1
- import { n as PluginState, r as t } from "./common-DZ2cLtbe.cjs";
1
+ import { n as PluginState } from "./common-BLW8Fy4P.js";
2
+ import * as t from "@babel/types";
2
3
  import { NodePath } from "@babel/traverse";
3
4
 
4
5
  //#region src/babel.d.ts
@@ -1,10 +1,12 @@
1
- const require_common = require('./common-B8wsLJUq.cjs');
1
+ const require_common = require('./common-DPfAcXic.cjs');
2
2
  let defu = require("defu");
3
3
  defu = require_common.__toESM(defu);
4
4
  let tinyest_for_wgsl = require("tinyest-for-wgsl");
5
5
  tinyest_for_wgsl = require_common.__toESM(tinyest_for_wgsl);
6
6
  let tinyest = require("tinyest");
7
7
  tinyest = require_common.__toESM(tinyest);
8
+ let __babel_types = require("@babel/types");
9
+ __babel_types = require_common.__toESM(__babel_types);
8
10
  let pathe = require("pathe");
9
11
  pathe = require_common.__toESM(pathe);
10
12
  let picomatch = require("picomatch");
@@ -69,25 +71,25 @@ function createFilterForId(filter) {
69
71
  //#endregion
70
72
  //#region src/babel.ts
71
73
  function i(identifier) {
72
- return require_common.t.identifier(identifier);
74
+ return __babel_types.identifier(identifier);
73
75
  }
74
76
  function assignMetadata(path, name, ast) {
75
- const metadata = require_common.t.objectExpression([
76
- require_common.t.objectProperty(i("v"), require_common.t.numericLiteral(tinyest.FORMAT_VERSION)),
77
- require_common.t.objectProperty(i("name"), require_common.t.valueToNode(name)),
78
- require_common.t.objectProperty(i("ast"), require_common.t.valueToNode(ast)),
79
- require_common.t.objectProperty(i("externals"), require_common.t.arrowFunctionExpression([], require_common.t.blockStatement([require_common.t.returnStatement(require_common.t.objectExpression(ast.externalNames.map((name$1) => name$1 === "this" ? require_common.t.objectProperty(i("this"), require_common.t.thisExpression()) : require_common.t.objectProperty(i(name$1), i(name$1), false, name$1 !== "this"))))])))
77
+ const metadata = __babel_types.objectExpression([
78
+ __babel_types.objectProperty(i("v"), __babel_types.numericLiteral(tinyest.FORMAT_VERSION)),
79
+ __babel_types.objectProperty(i("name"), __babel_types.valueToNode(name)),
80
+ __babel_types.objectProperty(i("ast"), __babel_types.valueToNode(ast)),
81
+ __babel_types.objectProperty(i("externals"), __babel_types.arrowFunctionExpression([], __babel_types.blockStatement([__babel_types.returnStatement(__babel_types.objectExpression(ast.externalNames.map((name$1) => name$1 === "this" ? __babel_types.objectProperty(i("this"), __babel_types.thisExpression()) : __babel_types.objectProperty(i(name$1), i(name$1), false, name$1 !== "this"))))])))
80
82
  ]);
81
83
  let expression;
82
- const visibility = require_common.t.isFunctionDeclaration(path.node) ? require_common.getBlockScope(path) : void 0;
83
- if (require_common.t.isFunctionDeclaration(path.node)) expression = require_common.t.functionExpression(path.node.id, path.node.params, path.node.body);
84
+ const visibility = __babel_types.isFunctionDeclaration(path.node) ? require_common.getBlockScope(path) : void 0;
85
+ if (__babel_types.isFunctionDeclaration(path.node)) expression = __babel_types.functionExpression(path.node.id, path.node.params, path.node.body);
84
86
  else expression = path.node;
85
- const callExpr = require_common.t.callExpression(require_common.t.arrowFunctionExpression([i("$")], require_common.t.logicalExpression("&&", require_common.t.callExpression(require_common.t.memberExpression(require_common.t.assignmentExpression("??=", require_common.t.memberExpression(i("globalThis"), i("__TYPEGPU_META__")), require_common.t.newExpression(i("WeakMap"), [])), i("set")), [require_common.t.assignmentExpression("=", require_common.t.memberExpression(i("$"), i("f")), expression), metadata]), require_common.t.memberExpression(i("$"), i("f")))), [require_common.t.objectExpression([])]);
86
- require_common.t.addComment(callExpr, "leading", "#__PURE__");
87
+ const callExpr = __babel_types.callExpression(__babel_types.arrowFunctionExpression([i("$")], __babel_types.logicalExpression("&&", __babel_types.callExpression(__babel_types.memberExpression(__babel_types.assignmentExpression("??=", __babel_types.memberExpression(i("globalThis"), i("__TYPEGPU_META__")), __babel_types.newExpression(i("WeakMap"), [])), i("set")), [__babel_types.assignmentExpression("=", __babel_types.memberExpression(i("$"), i("f")), expression), metadata]), __babel_types.memberExpression(i("$"), i("f")))), [__babel_types.objectExpression([])]);
88
+ __babel_types.addComment(callExpr, "leading", "#__PURE__");
87
89
  let replacement = callExpr;
88
- if (require_common.t.isFunctionDeclaration(path.node) && path.node.id) {
89
- const declaration = require_common.t.variableDeclaration("const", [require_common.t.variableDeclarator(path.node.id, callExpr)]);
90
- require_common.t.inheritLeadingComments(declaration, path.node);
90
+ if (__babel_types.isFunctionDeclaration(path.node) && path.node.id) {
91
+ const declaration = __babel_types.variableDeclaration("const", [__babel_types.variableDeclarator(path.node.id, callExpr)]);
92
+ __babel_types.inheritLeadingComments(declaration, path.node);
91
93
  replacement = declaration;
92
94
  }
93
95
  if (visibility) {
@@ -98,15 +100,15 @@ function assignMetadata(path, name, ast) {
98
100
  path.skip();
99
101
  }
100
102
  function wrapInAutoName(path, name) {
101
- const callExpr = require_common.t.callExpression(require_common.t.logicalExpression("??", require_common.t.memberExpression(i("globalThis"), i("__TYPEGPU_AUTONAME__")), require_common.t.arrowFunctionExpression([i("a")], i("a"))), [path.node, require_common.t.stringLiteral(name)]);
102
- require_common.t.addComment(callExpr, "leading", "#__PURE__");
103
+ const callExpr = __babel_types.callExpression(__babel_types.logicalExpression("??", __babel_types.memberExpression(i("globalThis"), i("__TYPEGPU_AUTONAME__")), __babel_types.arrowFunctionExpression([i("a")], i("a"))), [path.node, __babel_types.stringLiteral(name)]);
104
+ __babel_types.addComment(callExpr, "leading", "#__PURE__");
103
105
  path.replaceWith(callExpr);
104
106
  }
105
107
  function replaceWithAssignmentOverload(path, runtimeFn) {
106
- path.replaceWith(require_common.t.assignmentExpression("=", path.node.left, require_common.t.callExpression(i(runtimeFn), [path.node.left, path.node.right])));
108
+ path.replaceWith(__babel_types.assignmentExpression("=", path.node.left, __babel_types.callExpression(i(runtimeFn), [path.node.left, path.node.right])));
107
109
  }
108
110
  function replaceWithBinaryOverload(path, runtimeFn) {
109
- path.replaceWith(require_common.t.callExpression(i(runtimeFn), [path.node.left, path.node.right]));
111
+ path.replaceWith(__babel_types.callExpression(i(runtimeFn), [path.node.left, path.node.right]));
110
112
  }
111
113
  function TypeGPUPlugin() {
112
114
  return {
@@ -1,7 +1,8 @@
1
- import { a as initPluginState, i as getBlockScope, o as t, r as functionVisitor, t as defaultOptions } from "./common-CElmMmuq.js";
1
+ import { a as initPluginState, i as getBlockScope, r as functionVisitor, t as defaultOptions } from "./common-B8nnr-Iq.js";
2
2
  import defu from "defu";
3
3
  import { transpileFn } from "tinyest-for-wgsl";
4
4
  import { FORMAT_VERSION } from "tinyest";
5
+ import * as t from "@babel/types";
5
6
  import { resolve } from "pathe";
6
7
  import picomatch from "picomatch";
7
8
 
@@ -1,5 +1,6 @@
1
- import { n as PluginState, r as t } from "./common-BlvLUwEz.js";
1
+ import { n as PluginState } from "./common-BaikgpzR.cjs";
2
2
  import { NodePath } from "@babel/traverse";
3
+ import * as t from "@babel/types";
3
4
 
4
5
  //#region src/babel.d.ts
5
6
  declare function TypeGPUPlugin(): {
package/babel.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- require('./common-B8wsLJUq.cjs');
3
- const require_babel = require('./babel-B-IcpMR7.cjs');
2
+ require('./common-DPfAcXic.cjs');
3
+ const require_babel = require('./babel-D-TCImIi.cjs');
4
4
 
5
5
  exports.default = require_babel.TypeGPUPlugin;
package/babel.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import "./common-DZ2cLtbe.cjs";
2
- import { t as TypeGPUPlugin } from "./babel-C8UzthFd.cjs";
1
+ import "./common-BaikgpzR.cjs";
2
+ import { t as TypeGPUPlugin } from "./babel-mqeTZT8y.cjs";
3
3
  export = TypeGPUPlugin;
package/babel.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import "./common-BlvLUwEz.js";
2
- import { t as TypeGPUPlugin } from "./babel-CmCnq-43.js";
1
+ import "./common-BLW8Fy4P.js";
2
+ import { t as TypeGPUPlugin } from "./babel-CXwXwwOE.js";
3
3
  export { TypeGPUPlugin as default };
package/babel.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./common-CElmMmuq.js";
2
- import { t as TypeGPUPlugin } from "./babel-CbManzjz.js";
1
+ import "./common-B8nnr-Iq.js";
2
+ import { t as TypeGPUPlugin } from "./babel-dNT1_5hS.js";
3
3
 
4
4
  export { TypeGPUPlugin as default };
@@ -1,4 +1,4 @@
1
- import { t as Options } from "./common-BlvLUwEz.js";
1
+ import { t as Options } from "./common-BLW8Fy4P.js";
2
2
 
3
3
  //#region src/bun.d.ts
4
4
  declare const _default: (rawOptions?: Options) => Bun.BunPlugin;
@@ -0,0 +1,33 @@
1
+ import { n as earlyPruneRegex, t as defaultOptions } from "./common-B8nnr-Iq.js";
2
+ import { t as unpluginFactory } from "./factory-CnVNvO57.js";
3
+ import defu from "defu";
4
+
5
+ //#region src/bun.ts
6
+ var bun_default = (rawOptions) => {
7
+ const options = defu(rawOptions, defaultOptions);
8
+ const include = options.include;
9
+ if (!(include instanceof RegExp)) throw new Error(`Unsupported 'include' options in Bun plugin. Please provide a single regular expression`);
10
+ if (options.exclude) throw new Error(`Unsupported 'exclude' option in Bun plugin`);
11
+ const rawPlugin = unpluginFactory(rawOptions, { framework: "bun" });
12
+ return {
13
+ name: "unplugin-typegpu",
14
+ setup(build) {
15
+ build.onLoad({ filter: include }, async (args) => {
16
+ var _result$code;
17
+ const codeIn = await Bun.file(args.path).text();
18
+ if (earlyPruneRegex.every((pattern) => !pattern.test(codeIn))) return {
19
+ contents: codeIn,
20
+ loader: args.loader
21
+ };
22
+ const result = rawPlugin.transform.handler.apply({}, [codeIn, args.path]);
23
+ return {
24
+ contents: (_result$code = result === null || result === void 0 ? void 0 : result.code) !== null && _result$code !== void 0 ? _result$code : codeIn,
25
+ loader: args.loader
26
+ };
27
+ });
28
+ }
29
+ };
30
+ };
31
+
32
+ //#endregion
33
+ export { bun_default as t };
@@ -1,4 +1,4 @@
1
- import { t as Options } from "./common-DZ2cLtbe.cjs";
1
+ import { t as Options } from "./common-BaikgpzR.cjs";
2
2
 
3
3
  //#region src/bun.d.ts
4
4
  declare const _default: (rawOptions?: Options) => Bun.BunPlugin;
@@ -0,0 +1,39 @@
1
+ const require_common = require('./common-DPfAcXic.cjs');
2
+ const require_factory = require('./factory-B0CnGO9P.cjs');
3
+ let defu = require("defu");
4
+ defu = require_common.__toESM(defu);
5
+
6
+ //#region src/bun.ts
7
+ var bun_default = (rawOptions) => {
8
+ const options = (0, defu.default)(rawOptions, require_common.defaultOptions);
9
+ const include = options.include;
10
+ if (!(include instanceof RegExp)) throw new Error(`Unsupported 'include' options in Bun plugin. Please provide a single regular expression`);
11
+ if (options.exclude) throw new Error(`Unsupported 'exclude' option in Bun plugin`);
12
+ const rawPlugin = require_factory.unpluginFactory(rawOptions, { framework: "bun" });
13
+ return {
14
+ name: "unplugin-typegpu",
15
+ setup(build) {
16
+ build.onLoad({ filter: include }, async (args) => {
17
+ var _result$code;
18
+ const codeIn = await Bun.file(args.path).text();
19
+ if (require_common.earlyPruneRegex.every((pattern) => !pattern.test(codeIn))) return {
20
+ contents: codeIn,
21
+ loader: args.loader
22
+ };
23
+ const result = rawPlugin.transform.handler.apply({}, [codeIn, args.path]);
24
+ return {
25
+ contents: (_result$code = result === null || result === void 0 ? void 0 : result.code) !== null && _result$code !== void 0 ? _result$code : codeIn,
26
+ loader: args.loader
27
+ };
28
+ });
29
+ }
30
+ };
31
+ };
32
+
33
+ //#endregion
34
+ Object.defineProperty(exports, 'bun_default', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return bun_default;
38
+ }
39
+ });
package/bun.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- require('./common-B8wsLJUq.cjs');
3
- const require_bun = require('./bun-DU5xZoDJ.cjs');
2
+ require('./common-DPfAcXic.cjs');
3
+ require('./factory-B0CnGO9P.cjs');
4
+ const require_bun = require('./bun-o6QmlVaS.cjs');
4
5
 
5
6
  exports.default = require_bun.bun_default;
package/bun.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import "./common-DZ2cLtbe.cjs";
2
- import { t as _default } from "./bun-cwXs2EDP.cjs";
1
+ import "./common-BaikgpzR.cjs";
2
+ import { t as _default } from "./bun-Df2nJEmj.cjs";
3
3
  export = _default;
package/bun.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import "./common-BlvLUwEz.js";
2
- import { t as _default } from "./bun-ovScJ4Es.js";
1
+ import "./common-BLW8Fy4P.js";
2
+ import { t as _default } from "./bun-C6usJAus.js";
3
3
  export { _default as default };
package/bun.js CHANGED
@@ -1,4 +1,5 @@
1
- import "./common-CElmMmuq.js";
2
- import { t as bun_default } from "./bun-CDECNeIU.js";
1
+ import "./common-B8nnr-Iq.js";
2
+ import "./factory-CnVNvO57.js";
3
+ import { t as bun_default } from "./bun-DY6XE5xi.js";
3
4
 
4
5
  export { bun_default as default };
@@ -1,12 +1,7 @@
1
1
  import { transpileFn } from "tinyest-for-wgsl";
2
2
  import * as t from "@babel/types";
3
- import { MagicStringAST } from "magic-string-ast";
3
+ import MagicString from "magic-string";
4
4
 
5
- //#region src/core/polyfill-process.ts
6
- if (typeof globalThis.process === "undefined") globalThis.process = {};
7
- if (typeof globalThis.process.env === "undefined") globalThis.process.env = {};
8
-
9
- //#endregion
10
5
  //#region src/core/common.ts
11
6
  function initPluginState(state, methods) {
12
7
  var _state$opts$autoNamin;
@@ -276,4 +271,4 @@ const functionVisitor = {
276
271
  };
277
272
 
278
273
  //#endregion
279
- export { initPluginState as a, getBlockScope as i, earlyPruneRegex as n, t as o, functionVisitor as r, defaultOptions as t };
274
+ export { initPluginState as a, getBlockScope as i, earlyPruneRegex as n, functionVisitor as r, defaultOptions as t };
@@ -1,6 +1,6 @@
1
1
  import { transpileFn } from "tinyest-for-wgsl";
2
2
  import * as t from "@babel/types";
3
- import { MagicStringAST } from "magic-string-ast";
3
+ import MagicString from "magic-string";
4
4
  import { NodePath } from "@babel/traverse";
5
5
  import { FilterPattern } from "unplugin";
6
6
 
@@ -82,4 +82,4 @@ interface PluginState extends TransformMethods {
82
82
  alreadyTransformed: WeakSet<t.Node>;
83
83
  }
84
84
  //#endregion
85
- export { PluginState as n, t as r, Options as t };
85
+ export { PluginState as n, Options as t };
@@ -81,4 +81,4 @@ interface PluginState extends TransformMethods {
81
81
  alreadyTransformed: WeakSet<t.Node>;
82
82
  }
83
83
  //#endregion
84
- export { PluginState as n, t as r, Options as t };
84
+ export { PluginState as n, Options as t };
@@ -25,14 +25,9 @@ let tinyest_for_wgsl = require("tinyest-for-wgsl");
25
25
  tinyest_for_wgsl = __toESM(tinyest_for_wgsl);
26
26
  let __babel_types = require("@babel/types");
27
27
  __babel_types = __toESM(__babel_types);
28
- let magic_string_ast = require("magic-string-ast");
29
- magic_string_ast = __toESM(magic_string_ast);
28
+ let magic_string = require("magic-string");
29
+ magic_string = __toESM(magic_string);
30
30
 
31
- //#region src/core/polyfill-process.ts
32
- if (typeof globalThis.process === "undefined") globalThis.process = {};
33
- if (typeof globalThis.process.env === "undefined") globalThis.process.env = {};
34
-
35
- //#endregion
36
31
  //#region src/core/common.ts
37
32
  function initPluginState(state, methods) {
38
33
  var _state$opts$autoNamin;
@@ -337,10 +332,4 @@ Object.defineProperty(exports, 'initPluginState', {
337
332
  get: function () {
338
333
  return initPluginState;
339
334
  }
340
- });
341
- Object.defineProperty(exports, 't', {
342
- enumerable: true,
343
- get: function () {
344
- return t;
345
- }
346
335
  });
package/esbuild.cjs CHANGED
@@ -1,8 +1,10 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- require('./common-B8wsLJUq.cjs');
3
- require('./babel-B-IcpMR7.cjs');
4
- require('./bun-DU5xZoDJ.cjs');
5
- const require_src = require('./src-CDZ6lHsg.cjs');
2
+ require('./common-DPfAcXic.cjs');
3
+ require('./babel-D-TCImIi.cjs');
4
+ require('./factory-B0CnGO9P.cjs');
5
+ require('./bun-o6QmlVaS.cjs');
6
+ require('./rolldown-browser-BzaTpeZq.cjs');
7
+ const require_src = require('./src-BljgtpqS.cjs');
6
8
 
7
9
  //#region src/esbuild.ts
8
10
  var esbuild_default = require_src.esbuildPlugin;
package/esbuild.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import "./common-DZ2cLtbe.cjs";
2
- import "./babel-C8UzthFd.cjs";
3
- import "./bun-cwXs2EDP.cjs";
4
- import { t as esbuildPlugin } from "./index-COIv1oYx.cjs";
1
+ import "./common-BaikgpzR.cjs";
2
+ import "./babel-mqeTZT8y.cjs";
3
+ import "./bun-Df2nJEmj.cjs";
4
+ import "./rolldown-browser-XXZriqjg.cjs";
5
+ import { t as esbuildPlugin } from "./index-Dq70sYN7.cjs";
5
6
  export = esbuildPlugin;
package/esbuild.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import "./common-BlvLUwEz.js";
2
- import "./babel-CmCnq-43.js";
3
- import "./bun-ovScJ4Es.js";
4
- import { t as esbuildPlugin } from "./index-PPreQbn5.js";
1
+ import "./common-BLW8Fy4P.js";
2
+ import "./babel-CXwXwwOE.js";
3
+ import "./bun-C6usJAus.js";
4
+ import "./rolldown-browser-C8OHaYCP.js";
5
+ import { t as esbuildPlugin } from "./index-rnHwqPEN.js";
5
6
  export { esbuildPlugin as default };
package/esbuild.js CHANGED
@@ -1,7 +1,9 @@
1
- import "./common-CElmMmuq.js";
2
- import "./babel-CbManzjz.js";
3
- import "./bun-CDECNeIU.js";
4
- import { t as esbuildPlugin } from "./src-D84rmPxv.js";
1
+ import "./common-B8nnr-Iq.js";
2
+ import "./babel-dNT1_5hS.js";
3
+ import "./factory-CnVNvO57.js";
4
+ import "./bun-DY6XE5xi.js";
5
+ import "./rolldown-browser-D0pxy7TZ.js";
6
+ import { t as esbuildPlugin } from "./src-DZP2_1Gn.js";
5
7
 
6
8
  //#region src/esbuild.ts
7
9
  var esbuild_default = esbuildPlugin;
@@ -0,0 +1,208 @@
1
+ const require_common = require('./common-DPfAcXic.cjs');
2
+ let defu = require("defu");
3
+ defu = require_common.__toESM(defu);
4
+ let tinyest_for_wgsl = require("tinyest-for-wgsl");
5
+ tinyest_for_wgsl = require_common.__toESM(tinyest_for_wgsl);
6
+ let tinyest = require("tinyest");
7
+ tinyest = require_common.__toESM(tinyest);
8
+ let __babel_types = require("@babel/types");
9
+ __babel_types = require_common.__toESM(__babel_types);
10
+ let magic_string = require("magic-string");
11
+ magic_string = require_common.__toESM(magic_string);
12
+ let ast_kit = require("ast-kit");
13
+ ast_kit = require_common.__toESM(ast_kit);
14
+ let __babel_traverse = require("@babel/traverse");
15
+ __babel_traverse = require_common.__toESM(__babel_traverse);
16
+ let __babel_parser = require("@babel/parser");
17
+ __babel_parser = require_common.__toESM(__babel_parser);
18
+
19
+ //#region \0@oxc-project+runtime@0.95.0/helpers/typeof.js
20
+ function _typeof(o) {
21
+ "@babel/helpers - typeof";
22
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
23
+ return typeof o$1;
24
+ } : function(o$1) {
25
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
26
+ }, _typeof(o);
27
+ }
28
+
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.95.0/helpers/toPrimitive.js
31
+ function toPrimitive(t, r) {
32
+ if ("object" != _typeof(t) || !t) return t;
33
+ var e = t[Symbol.toPrimitive];
34
+ if (void 0 !== e) {
35
+ var i = e.call(t, r || "default");
36
+ if ("object" != _typeof(i)) return i;
37
+ throw new TypeError("@@toPrimitive must return a primitive value.");
38
+ }
39
+ return ("string" === r ? String : Number)(t);
40
+ }
41
+
42
+ //#endregion
43
+ //#region \0@oxc-project+runtime@0.95.0/helpers/toPropertyKey.js
44
+ function toPropertyKey(t) {
45
+ var i = toPrimitive(t, "string");
46
+ return "symbol" == _typeof(i) ? i : i + "";
47
+ }
48
+
49
+ //#endregion
50
+ //#region \0@oxc-project+runtime@0.95.0/helpers/defineProperty.js
51
+ function _defineProperty(e, r, t) {
52
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
53
+ value: t,
54
+ enumerable: !0,
55
+ configurable: !0,
56
+ writable: !0
57
+ }) : e[r] = t, e;
58
+ }
59
+
60
+ //#endregion
61
+ //#region \0@oxc-project+runtime@0.95.0/helpers/objectSpread2.js
62
+ function ownKeys(e, r) {
63
+ var t = Object.keys(e);
64
+ if (Object.getOwnPropertySymbols) {
65
+ var o = Object.getOwnPropertySymbols(e);
66
+ r && (o = o.filter(function(r$1) {
67
+ return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
68
+ })), t.push.apply(t, o);
69
+ }
70
+ return t;
71
+ }
72
+ function _objectSpread2(e) {
73
+ for (var r = 1; r < arguments.length; r++) {
74
+ var t = null != arguments[r] ? arguments[r] : {};
75
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
76
+ _defineProperty(e, r$1, t[r$1]);
77
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
78
+ Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
79
+ });
80
+ }
81
+ return e;
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/core/factory.ts
86
+ let traverse = __babel_traverse.default;
87
+ if (typeof traverse.default === "function") traverse = traverse.default;
88
+ const fnWrapperTemplate = (fnCode, metadata) => `(/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (${fnCode}), ${metadata}) && $.f)({}))`;
89
+ function embedJSON(jsValue) {
90
+ return JSON.stringify(jsValue).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
91
+ }
92
+ function assignMetadata(path, name, ast) {
93
+ var _path$node$start, _path$node$start2;
94
+ const metadata = `{
95
+ v: ${tinyest.FORMAT_VERSION},
96
+ name: ${name ? `"${name}"` : "undefined"},
97
+ ast: ${embedJSON(ast)},
98
+ externals: () => ({${ast.externalNames.map((e) => e === "this" ? "\"this\": this" : e).join(", ")}}),
99
+ }`;
100
+ const visibility = __babel_types.isFunctionDeclaration(path.node) ? require_common.getBlockScope(path) : void 0;
101
+ const fnCode = this.slice(path.node);
102
+ let nodeToOverride = path.node;
103
+ let code = fnWrapperTemplate(fnCode, metadata);
104
+ let insertPos = (_path$node$start = path.node.start) !== null && _path$node$start !== void 0 ? _path$node$start : 0;
105
+ if (__babel_types.isFunctionDeclaration(path.node) && path.node.id) code = `const ${path.node.id.name} = ${code};\n\n`;
106
+ if (visibility) {
107
+ var _visibility$node$body, _visibility$node$body2;
108
+ insertPos = (_visibility$node$body = (_visibility$node$body2 = visibility.node.body[0]) === null || _visibility$node$body2 === void 0 ? void 0 : _visibility$node$body2.start) !== null && _visibility$node$body !== void 0 ? _visibility$node$body : insertPos;
109
+ if (__babel_types.isExportNamedDeclaration(path.parent)) {
110
+ nodeToOverride = path.parent;
111
+ code = `export ${code}`;
112
+ }
113
+ }
114
+ if (insertPos < ((_path$node$start2 = path.node.start) !== null && _path$node$start2 !== void 0 ? _path$node$start2 : 0)) {
115
+ var _nodeToOverride$leadi, _nodeToOverride$leadi2;
116
+ for (const comment of (_nodeToOverride$leadi = (_nodeToOverride$leadi2 = nodeToOverride.leadingComments) === null || _nodeToOverride$leadi2 === void 0 ? void 0 : _nodeToOverride$leadi2.toReversed()) !== null && _nodeToOverride$leadi !== void 0 ? _nodeToOverride$leadi : []) if (comment) {
117
+ code = `${this.slice(comment)}\n${code}`;
118
+ this.remove(comment);
119
+ }
120
+ this.remove(nodeToOverride);
121
+ this.magicString.prependLeft(insertPos, code);
122
+ } else this.overwrite(nodeToOverride, code);
123
+ }
124
+ function wrapInAutoName(path, name) {
125
+ var _path$node$start3, _path$node$end;
126
+ this.magicString.appendLeft((_path$node$start3 = path.node.start) !== null && _path$node$start3 !== void 0 ? _path$node$start3 : 0, "(/*#__PURE__*/(globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").prependRight((_path$node$end = path.node.end) !== null && _path$node$end !== void 0 ? _path$node$end : 0, `, "${name}"))`);
127
+ }
128
+ function replaceWithAssignmentOverload(path, runtimeFn) {
129
+ const lhs = this.slice(path.node.left);
130
+ const rhs = this.slice(path.node.right);
131
+ this.overwrite(path.node, `${lhs} = ${runtimeFn}(${lhs}, ${rhs})`);
132
+ }
133
+ function replaceWithBinaryOverload(path, runtimeFn) {
134
+ const lhs = this.slice(path.node.left);
135
+ const rhs = this.slice(path.node.right);
136
+ this.overwrite(path.node, `${runtimeFn}(${lhs}, ${rhs})`);
137
+ }
138
+ const NodeUtils = {
139
+ slice(node) {
140
+ var _node$start, _node$end;
141
+ return this.magicString.slice((_node$start = node.start) !== null && _node$start !== void 0 ? _node$start : 0, (_node$end = node.end) !== null && _node$end !== void 0 ? _node$end : 0);
142
+ },
143
+ remove(node) {
144
+ var _node$start2, _node$end2;
145
+ this.magicString.remove((_node$start2 = node.start) !== null && _node$start2 !== void 0 ? _node$start2 : 0, (_node$end2 = node.end) !== null && _node$end2 !== void 0 ? _node$end2 : 0);
146
+ },
147
+ overwrite(node, content) {
148
+ var _node$start3, _node$end3;
149
+ this.magicString.overwrite((_node$start3 = node.start) !== null && _node$start3 !== void 0 ? _node$start3 : 0, (_node$end3 = node.end) !== null && _node$end3 !== void 0 ? _node$end3 : 0, content);
150
+ }
151
+ };
152
+ const unpluginFactory = ((rawOptions, _meta) => {
153
+ const options = (0, defu.default)(rawOptions, require_common.defaultOptions);
154
+ return {
155
+ name: "unplugin-typegpu",
156
+ enforce: options.enforce,
157
+ transform: {
158
+ filter: options.earlyPruning ? {
159
+ id: options,
160
+ code: require_common.earlyPruneRegex
161
+ } : { id: options },
162
+ handler(code, id) {
163
+ let ast;
164
+ try {
165
+ ast = __babel_parser.parse(code, (0, ast_kit.getBabelParserOptions)((0, ast_kit.getLang)(id), {
166
+ sourceType: "module",
167
+ allowReturnOutsideFunction: true
168
+ }));
169
+ } catch (cause) {
170
+ console.warn(`[unplugin-typegpu] Failed to parse ${id}. Cause: ${typeof cause === "object" && cause && "message" in cause ? cause.message : cause}`);
171
+ return;
172
+ }
173
+ const magicString = new magic_string.default(code);
174
+ const state = _objectSpread2({
175
+ filename: id,
176
+ magicString,
177
+ opts: options
178
+ }, NodeUtils);
179
+ require_common.initPluginState(state, {
180
+ warn: (message) => this.warn(message),
181
+ assignMetadata,
182
+ wrapInAutoName,
183
+ replaceWithAssignmentOverload,
184
+ replaceWithBinaryOverload
185
+ });
186
+ traverse(ast, require_common.functionVisitor, void 0, state);
187
+ if (magicString.hasChanged()) return {
188
+ code: magicString.toString(),
189
+ get map() {
190
+ return magicString.generateMap({
191
+ source: id,
192
+ includeContent: true,
193
+ hires: "boundary"
194
+ });
195
+ }
196
+ };
197
+ }
198
+ }
199
+ };
200
+ });
201
+
202
+ //#endregion
203
+ Object.defineProperty(exports, 'unpluginFactory', {
204
+ enumerable: true,
205
+ get: function () {
206
+ return unpluginFactory;
207
+ }
208
+ });