unplugin-typegpu 0.10.2 → 0.11.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.
Files changed (68) hide show
  1. package/README.md +14 -4
  2. package/babel-Bnfeonoo.mjs +126 -0
  3. package/babel-C0RyQRMk.d.mts +14 -0
  4. package/babel-C1TaJd38.d.cts +14 -0
  5. package/babel-izRcz0Uk.cjs +134 -0
  6. package/babel.cjs +6 -161
  7. package/babel.d.cts +2 -10
  8. package/babel.d.mts +2 -11
  9. package/babel.mjs +2 -158
  10. package/bun-9JrHWE4u.d.mts +6 -0
  11. package/bun-CUGitP44.cjs +147 -0
  12. package/bun-ChNeklBe.d.cts +6 -0
  13. package/bun-DFr_PiLh.mjs +132 -0
  14. package/bun.cjs +6 -39
  15. package/bun.d.cts +1 -4
  16. package/bun.d.mts +1 -5
  17. package/bun.mjs +2 -36
  18. package/common-BKqBivuE.d.cts +84 -0
  19. package/common-BvAFT5IV.d.mts +85 -0
  20. package/common-Ccx_dEqH.cjs +329 -0
  21. package/common-e08X6w0a.mjs +272 -0
  22. package/esbuild.cjs +6 -6
  23. package/esbuild.d.cts +1 -1
  24. package/esbuild.d.mts +1 -1
  25. package/esbuild.mjs +2 -4
  26. package/farm.cjs +6 -6
  27. package/farm.d.cts +1 -1
  28. package/farm.d.mts +1 -1
  29. package/farm.mjs +2 -4
  30. package/index-BuKVXaph.d.mts +48 -0
  31. package/index-HrLja1mV.d.cts +48 -0
  32. package/index.cjs +19 -29
  33. package/index.d.cts +5 -17
  34. package/index.d.mts +5 -17
  35. package/index.mjs +4 -17
  36. package/package.json +11 -8
  37. package/rolldown.cjs +6 -6
  38. package/rolldown.d.cts +1 -1
  39. package/rolldown.d.mts +1 -1
  40. package/rolldown.mjs +2 -4
  41. package/rollup.cjs +6 -6
  42. package/rollup.d.cts +1 -1
  43. package/rollup.d.mts +1 -1
  44. package/rollup.mjs +2 -4
  45. package/rspack.cjs +6 -6
  46. package/rspack.d.cts +1 -1
  47. package/rspack.d.mts +1 -1
  48. package/rspack.mjs +2 -4
  49. package/src-2vvPp2dY.cjs +77 -0
  50. package/src-BV9Uh6WO.mjs +17 -0
  51. package/vite.cjs +6 -6
  52. package/vite.d.cts +1 -1
  53. package/vite.d.mts +1 -1
  54. package/vite.mjs +2 -4
  55. package/webpack.cjs +6 -6
  56. package/webpack.d.cts +1 -1
  57. package/webpack.d.mts +1 -1
  58. package/webpack.mjs +2 -4
  59. package/common-CRPQ2KE6.d.mts +0 -25
  60. package/common-Dpl8jppn.d.cts +0 -25
  61. package/filter-6T-5w4kG.mjs +0 -234
  62. package/filter-CKmD4HRk.cjs +0 -327
  63. package/index-legacy-DRI9LQiG.d.mts +0 -1488
  64. package/index-legacy-xKi5C2ga.d.cts +0 -1488
  65. package/rolldown-browser-DKeiFM_e.mjs +0 -129
  66. package/rolldown-browser-DUanNY-R.cjs +0 -141
  67. package/rolldown-browser-JYqfNLQ8.d.mts +0 -1247
  68. package/rollup-impl-DqC_d-_W.d.cts +0 -1246
@@ -1,129 +0,0 @@
1
- import { a as gatherTgpuAliases, c as operators, i as embedJSON, l as performExpressionNaming, n as defaultOptions, o as getFunctionName, r as earlyPruneRegex, s as isShellImplementationCall, u as useGpuDirective } from "./filter-6T-5w4kG.mjs";
2
- import defu from "defu";
3
- import { MagicStringAST, generateTransform } from "magic-string-ast";
4
- import { walk } from "estree-walker";
5
- import { transpileFn } from "tinyest-for-wgsl";
6
- import { FORMAT_VERSION } from "tinyest";
7
-
8
- //#region src/rollup-impl.ts
9
- function containsUseGpuDirective(node) {
10
- if (node.body.type === "BlockStatement") {
11
- for (const statement of node.body.body) if (statement.type === "ExpressionStatement" && statement.directive === useGpuDirective) return true;
12
- }
13
- return false;
14
- }
15
- function removeUseGpuDirective(node) {
16
- const cloned = structuredClone(node);
17
- if (cloned.body.type === "BlockStatement") cloned.body.body = cloned.body.body.filter((statement) => !(statement.type === "ExpressionStatement" && statement.directive === useGpuDirective));
18
- return cloned;
19
- }
20
- function assignMetadata(magicString, node, metadata) {
21
- magicString.prependLeft(node.start, "(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(node.end, `), ${metadata}) && $.f)({}))`);
22
- }
23
- function wrapInAutoName(magicString, node, name) {
24
- magicString.prependLeft(node.start, "((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(node.end, `, "${name}"))`);
25
- }
26
- const rollUpImpl = (rawOptions) => {
27
- const options = defu(rawOptions, defaultOptions);
28
- return {
29
- name: "unplugin-typegpu",
30
- enforce: options.enforce,
31
- transform: {
32
- filter: options.earlyPruning ? {
33
- id: options,
34
- code: earlyPruneRegex
35
- } : { id: options },
36
- handler(code, id) {
37
- const ctx = {
38
- tgpuAliases: new Set(options.forceTgpuAlias ? [options.forceTgpuAlias] : []),
39
- fileId: id,
40
- autoNamingEnabled: options.autoNamingEnabled
41
- };
42
- let ast;
43
- try {
44
- ast = this.parse(code, {
45
- lang: "ts",
46
- allowReturnOutsideFunction: true
47
- });
48
- } catch (cause) {
49
- console.warn(`[unplugin-typegpu] Failed to parse ${id}. Cause: ${typeof cause === "object" && cause && "message" in cause ? cause.message : cause}`);
50
- return;
51
- }
52
- const tgslFunctionDefs = [];
53
- const magicString = new MagicStringAST(code);
54
- walk(ast, { enter(_node, _parent) {
55
- const node = _node;
56
- const parent = _parent;
57
- performExpressionNaming(ctx, node, (node, name) => {
58
- wrapInAutoName(magicString, node, name);
59
- });
60
- if (node.type === "ImportDeclaration") gatherTgpuAliases(node, ctx);
61
- if (node.type === "CallExpression") {
62
- if (isShellImplementationCall(node, ctx)) {
63
- const implementation = node.arguments[0];
64
- if (implementation && (implementation.type === "FunctionExpression" || implementation.type === "ArrowFunctionExpression")) {
65
- tgslFunctionDefs.push({ def: removeUseGpuDirective(implementation) });
66
- this.skip();
67
- }
68
- }
69
- }
70
- if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
71
- if (containsUseGpuDirective(node)) {
72
- tgslFunctionDefs.push({
73
- def: removeUseGpuDirective(node),
74
- name: getFunctionName(node, parent)
75
- });
76
- this.skip();
77
- }
78
- }
79
- } });
80
- for (const { def, name } of tgslFunctionDefs) {
81
- const { params, body, externalNames } = transpileFn(def);
82
- const isFunctionStatement = def.type === "FunctionDeclaration";
83
- walk(def, { leave(_node) {
84
- const node = _node;
85
- if (node.type === "AssignmentExpression") {
86
- const runtimeFn = operators[node.operator];
87
- if (runtimeFn) {
88
- const left = node.left;
89
- const right = node.right;
90
- const lhs = magicString.sliceNode(left);
91
- const rhs = magicString.sliceNode(right);
92
- magicString.overwriteNode(node, `${lhs} = ${runtimeFn}(${lhs}, ${rhs})`);
93
- }
94
- } else if (node.type === "BinaryExpression") {
95
- const runtimeFn = operators[node.operator];
96
- if (runtimeFn) {
97
- const left = node.left;
98
- const right = node.right;
99
- const lhs = magicString.sliceNode(left);
100
- const rhs = magicString.sliceNode(right);
101
- magicString.overwriteNode(node, `${runtimeFn}(${lhs}, ${rhs})`);
102
- }
103
- }
104
- } });
105
- if (isFunctionStatement && name && code.slice(0, def.start).search(new RegExp(`(?<![\\w_.])${name}(?![\\w_])`)) !== -1) console.warn(`File ${id}: function "${name}" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);
106
- assignMetadata(magicString, def, `{
107
- v: ${FORMAT_VERSION},
108
- name: ${name ? `"${name}"` : "undefined"},
109
- ast: ${embedJSON({
110
- params,
111
- body,
112
- externalNames
113
- })},
114
- externals: () => ({${externalNames.map((e) => e === "this" ? "\"this\": this" : e).join(", ")}}),
115
- }`);
116
- if (isFunctionStatement && name) magicString.prependLeft(def.start, `const ${name} = `);
117
- }
118
- return generateTransform(magicString, id);
119
- }
120
- }
121
- };
122
- };
123
-
124
- //#endregion
125
- //#region src/rolldown-browser.ts
126
- var rolldown_browser_default = rollUpImpl;
127
-
128
- //#endregion
129
- export { rollUpImpl as n, rolldown_browser_default as t };
@@ -1,141 +0,0 @@
1
- const require_filter = require('./filter-CKmD4HRk.cjs');
2
- let defu = require("defu");
3
- defu = require_filter.__toESM(defu);
4
- let magic_string_ast = require("magic-string-ast");
5
- let estree_walker = require("estree-walker");
6
- let tinyest_for_wgsl = require("tinyest-for-wgsl");
7
- let tinyest = require("tinyest");
8
-
9
- //#region src/rollup-impl.ts
10
- function containsUseGpuDirective(node) {
11
- if (node.body.type === "BlockStatement") {
12
- for (const statement of node.body.body) if (statement.type === "ExpressionStatement" && statement.directive === require_filter.useGpuDirective) return true;
13
- }
14
- return false;
15
- }
16
- function removeUseGpuDirective(node) {
17
- const cloned = structuredClone(node);
18
- if (cloned.body.type === "BlockStatement") cloned.body.body = cloned.body.body.filter((statement) => !(statement.type === "ExpressionStatement" && statement.directive === require_filter.useGpuDirective));
19
- return cloned;
20
- }
21
- function assignMetadata(magicString, node, metadata) {
22
- magicString.prependLeft(node.start, "(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(node.end, `), ${metadata}) && $.f)({}))`);
23
- }
24
- function wrapInAutoName(magicString, node, name) {
25
- magicString.prependLeft(node.start, "((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(node.end, `, "${name}"))`);
26
- }
27
- const rollUpImpl = (rawOptions) => {
28
- const options = (0, defu.default)(rawOptions, require_filter.defaultOptions);
29
- return {
30
- name: "unplugin-typegpu",
31
- enforce: options.enforce,
32
- transform: {
33
- filter: options.earlyPruning ? {
34
- id: options,
35
- code: require_filter.earlyPruneRegex
36
- } : { id: options },
37
- handler(code, id) {
38
- const ctx = {
39
- tgpuAliases: new Set(options.forceTgpuAlias ? [options.forceTgpuAlias] : []),
40
- fileId: id,
41
- autoNamingEnabled: options.autoNamingEnabled
42
- };
43
- let ast;
44
- try {
45
- ast = this.parse(code, {
46
- lang: "ts",
47
- allowReturnOutsideFunction: true
48
- });
49
- } catch (cause) {
50
- console.warn(`[unplugin-typegpu] Failed to parse ${id}. Cause: ${typeof cause === "object" && cause && "message" in cause ? cause.message : cause}`);
51
- return;
52
- }
53
- const tgslFunctionDefs = [];
54
- const magicString = new magic_string_ast.MagicStringAST(code);
55
- (0, estree_walker.walk)(ast, { enter(_node, _parent) {
56
- const node = _node;
57
- const parent = _parent;
58
- require_filter.performExpressionNaming(ctx, node, (node, name) => {
59
- wrapInAutoName(magicString, node, name);
60
- });
61
- if (node.type === "ImportDeclaration") require_filter.gatherTgpuAliases(node, ctx);
62
- if (node.type === "CallExpression") {
63
- if (require_filter.isShellImplementationCall(node, ctx)) {
64
- const implementation = node.arguments[0];
65
- if (implementation && (implementation.type === "FunctionExpression" || implementation.type === "ArrowFunctionExpression")) {
66
- tgslFunctionDefs.push({ def: removeUseGpuDirective(implementation) });
67
- this.skip();
68
- }
69
- }
70
- }
71
- if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
72
- if (containsUseGpuDirective(node)) {
73
- tgslFunctionDefs.push({
74
- def: removeUseGpuDirective(node),
75
- name: require_filter.getFunctionName(node, parent)
76
- });
77
- this.skip();
78
- }
79
- }
80
- } });
81
- for (const { def, name } of tgslFunctionDefs) {
82
- const { params, body, externalNames } = (0, tinyest_for_wgsl.transpileFn)(def);
83
- const isFunctionStatement = def.type === "FunctionDeclaration";
84
- (0, estree_walker.walk)(def, { leave(_node) {
85
- const node = _node;
86
- if (node.type === "AssignmentExpression") {
87
- const runtimeFn = require_filter.operators[node.operator];
88
- if (runtimeFn) {
89
- const left = node.left;
90
- const right = node.right;
91
- const lhs = magicString.sliceNode(left);
92
- const rhs = magicString.sliceNode(right);
93
- magicString.overwriteNode(node, `${lhs} = ${runtimeFn}(${lhs}, ${rhs})`);
94
- }
95
- } else if (node.type === "BinaryExpression") {
96
- const runtimeFn = require_filter.operators[node.operator];
97
- if (runtimeFn) {
98
- const left = node.left;
99
- const right = node.right;
100
- const lhs = magicString.sliceNode(left);
101
- const rhs = magicString.sliceNode(right);
102
- magicString.overwriteNode(node, `${runtimeFn}(${lhs}, ${rhs})`);
103
- }
104
- }
105
- } });
106
- if (isFunctionStatement && name && code.slice(0, def.start).search(new RegExp(`(?<![\\w_.])${name}(?![\\w_])`)) !== -1) console.warn(`File ${id}: function "${name}" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);
107
- assignMetadata(magicString, def, `{
108
- v: ${tinyest.FORMAT_VERSION},
109
- name: ${name ? `"${name}"` : "undefined"},
110
- ast: ${require_filter.embedJSON({
111
- params,
112
- body,
113
- externalNames
114
- })},
115
- externals: () => ({${externalNames.map((e) => e === "this" ? "\"this\": this" : e).join(", ")}}),
116
- }`);
117
- if (isFunctionStatement && name) magicString.prependLeft(def.start, `const ${name} = `);
118
- }
119
- return (0, magic_string_ast.generateTransform)(magicString, id);
120
- }
121
- }
122
- };
123
- };
124
-
125
- //#endregion
126
- //#region src/rolldown-browser.ts
127
- var rolldown_browser_default = rollUpImpl;
128
-
129
- //#endregion
130
- Object.defineProperty(exports, 'rollUpImpl', {
131
- enumerable: true,
132
- get: function () {
133
- return rollUpImpl;
134
- }
135
- });
136
- Object.defineProperty(exports, 'rolldown_browser_default', {
137
- enumerable: true,
138
- get: function () {
139
- return rolldown_browser_default;
140
- }
141
- });