unplugin-typegpu 0.10.1 → 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.
- package/README.md +14 -4
- package/babel-Bnfeonoo.mjs +126 -0
- package/babel-C0RyQRMk.d.mts +14 -0
- package/babel-C1TaJd38.d.cts +14 -0
- package/babel-izRcz0Uk.cjs +134 -0
- package/babel.cjs +6 -163
- package/babel.d.cts +2 -10
- package/babel.d.mts +2 -11
- package/babel.mjs +2 -159
- package/bun-9JrHWE4u.d.mts +6 -0
- package/bun-CUGitP44.cjs +147 -0
- package/bun-ChNeklBe.d.cts +6 -0
- package/bun-DFr_PiLh.mjs +132 -0
- package/bun.cjs +6 -40
- package/bun.d.cts +1 -4
- package/bun.d.mts +1 -5
- package/bun.mjs +2 -36
- package/common-BKqBivuE.d.cts +84 -0
- package/common-BvAFT5IV.d.mts +85 -0
- package/common-Ccx_dEqH.cjs +329 -0
- package/common-e08X6w0a.mjs +272 -0
- package/esbuild.cjs +6 -6
- package/esbuild.d.cts +1 -1
- package/esbuild.d.mts +1 -1
- package/esbuild.mjs +2 -4
- package/farm.cjs +6 -6
- package/farm.d.cts +1 -1
- package/farm.d.mts +1 -1
- package/farm.mjs +2 -4
- package/index-BuKVXaph.d.mts +48 -0
- package/index-HrLja1mV.d.cts +48 -0
- package/index.cjs +19 -30
- package/index.d.cts +5 -18
- package/index.d.mts +5 -19
- package/index.mjs +4 -18
- package/package.json +13 -10
- package/rolldown.cjs +6 -6
- package/rolldown.d.cts +1 -1
- package/rolldown.d.mts +1 -1
- package/rolldown.mjs +2 -4
- package/rollup.cjs +6 -6
- package/rollup.d.cts +1 -1
- package/rollup.d.mts +1 -1
- package/rollup.mjs +2 -4
- package/rspack.cjs +6 -6
- package/rspack.d.cts +1 -1
- package/rspack.d.mts +1 -1
- package/rspack.mjs +2 -4
- package/src-2vvPp2dY.cjs +77 -0
- package/src-BV9Uh6WO.mjs +17 -0
- package/vite.cjs +6 -6
- package/vite.d.cts +1 -1
- package/vite.d.mts +1 -1
- package/vite.mjs +2 -4
- package/webpack.cjs +6 -6
- package/webpack.d.cts +1 -1
- package/webpack.d.mts +1 -1
- package/webpack.mjs +2 -4
- package/_virtual/_rolldown/runtime.cjs +0 -29
- package/common.cjs +0 -183
- package/common.d.cts +0 -25
- package/common.d.mts +0 -25
- package/common.mjs +0 -174
- package/filter.cjs +0 -63
- package/filter.mjs +0 -61
- package/rolldown-browser.cjs +0 -7
- package/rolldown-browser.d.mts +0 -1
- package/rolldown-browser.mjs +0 -7
- package/rollup-impl.cjs +0 -127
- package/rollup-impl.d.cts +0 -38
- package/rollup-impl.d.mts +0 -39
- package/rollup-impl.mjs +0 -125
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
# unplugin-typegpu
|
|
4
4
|
|
|
5
|
-
🚧 **Under Construction** 🚧 -
|
|
6
5
|
[GitHub](https://github.com/software-mansion/TypeGPU/tree/main/packages/unplugin-typegpu)
|
|
7
6
|
|
|
8
7
|
Read more about the plugin in the
|
|
@@ -10,10 +9,10 @@ Read more about the plugin in the
|
|
|
10
9
|
|
|
11
10
|
</div>
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
A set of bundler plugins that enhance [TypeGPU](https://typegpu.com) with:
|
|
14
13
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
14
|
+
- JavaScript/TypeScript shader support ('use gpu' directive)
|
|
15
|
+
- Improved debugging with automatic naming of resources
|
|
17
16
|
|
|
18
17
|
## Getting Started
|
|
19
18
|
|
|
@@ -48,6 +47,17 @@ export default defineConfig({
|
|
|
48
47
|
});
|
|
49
48
|
```
|
|
50
49
|
|
|
50
|
+
- bun
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// preload.ts
|
|
54
|
+
|
|
55
|
+
import { plugin } from 'bun';
|
|
56
|
+
import typegpu from 'unplugin-typegpu/bun';
|
|
57
|
+
|
|
58
|
+
void plugin(typegpu());
|
|
59
|
+
```
|
|
60
|
+
|
|
51
61
|
## TypeGPU is created by Software Mansion
|
|
52
62
|
|
|
53
63
|
[](https://swmansion.com)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { a as initPluginState, i as getBlockScope, r as functionVisitor, t as defaultOptions } from "./common-e08X6w0a.mjs";
|
|
2
|
+
import defu from "defu";
|
|
3
|
+
import { FORMAT_VERSION } from "tinyest";
|
|
4
|
+
import "tinyest-for-wgsl";
|
|
5
|
+
import * as t from "@babel/types";
|
|
6
|
+
import { resolve } from "pathe";
|
|
7
|
+
import picomatch from "picomatch";
|
|
8
|
+
//#region src/core/filter.ts
|
|
9
|
+
function toArray(array) {
|
|
10
|
+
const result = array || [];
|
|
11
|
+
if (Array.isArray(result)) return result;
|
|
12
|
+
return [result];
|
|
13
|
+
}
|
|
14
|
+
const BACKSLASH_REGEX = /\\/g;
|
|
15
|
+
function normalize(path) {
|
|
16
|
+
return path.replace(BACKSLASH_REGEX, "/");
|
|
17
|
+
}
|
|
18
|
+
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
|
19
|
+
function isAbsolute(path) {
|
|
20
|
+
return ABSOLUTE_PATH_REGEX.test(path);
|
|
21
|
+
}
|
|
22
|
+
function getMatcherString(glob, cwd) {
|
|
23
|
+
if (glob.startsWith("**") || isAbsolute(glob)) return normalize(glob);
|
|
24
|
+
return normalize(resolve(cwd, glob));
|
|
25
|
+
}
|
|
26
|
+
function patternToIdFilter(pattern) {
|
|
27
|
+
if (pattern instanceof RegExp) return (id) => {
|
|
28
|
+
const normalizedId = normalize(id);
|
|
29
|
+
const result = pattern.test(normalizedId);
|
|
30
|
+
pattern.lastIndex = 0;
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
const matcher = picomatch(getMatcherString(pattern, process.cwd()), { dot: true });
|
|
34
|
+
return (id) => {
|
|
35
|
+
return matcher(normalize(id));
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function createFilter(exclude, include) {
|
|
39
|
+
if (!exclude && !include) return;
|
|
40
|
+
return (input) => {
|
|
41
|
+
if (exclude === null || exclude === void 0 ? void 0 : exclude.some((filter) => filter(input))) return false;
|
|
42
|
+
if (include === null || include === void 0 ? void 0 : include.some((filter) => filter(input))) return true;
|
|
43
|
+
return !(include && include.length > 0);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function normalizeFilter(filter) {
|
|
47
|
+
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
|
48
|
+
if (Array.isArray(filter)) return { include: filter };
|
|
49
|
+
return {
|
|
50
|
+
exclude: filter.exclude ? toArray(filter.exclude) : void 0,
|
|
51
|
+
include: filter.include ? toArray(filter.include) : void 0
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createIdFilter(filter) {
|
|
55
|
+
if (!filter) return;
|
|
56
|
+
const { exclude, include } = normalizeFilter(filter);
|
|
57
|
+
return createFilter(exclude === null || exclude === void 0 ? void 0 : exclude.map(patternToIdFilter), include === null || include === void 0 ? void 0 : include.map(patternToIdFilter));
|
|
58
|
+
}
|
|
59
|
+
function createFilterForId(filter) {
|
|
60
|
+
const filterFunction = createIdFilter(filter);
|
|
61
|
+
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/babel.ts
|
|
65
|
+
function i(identifier) {
|
|
66
|
+
return t.identifier(identifier);
|
|
67
|
+
}
|
|
68
|
+
function assignMetadata(path, name, ast) {
|
|
69
|
+
const metadata = t.objectExpression([
|
|
70
|
+
t.objectProperty(i("v"), t.numericLiteral(FORMAT_VERSION)),
|
|
71
|
+
t.objectProperty(i("name"), t.valueToNode(name)),
|
|
72
|
+
t.objectProperty(i("ast"), t.valueToNode(ast)),
|
|
73
|
+
t.objectProperty(i("externals"), t.arrowFunctionExpression([], t.blockStatement([t.returnStatement(t.objectExpression(ast.externalNames.map((name) => name === "this" ? t.objectProperty(i("this"), t.thisExpression()) : t.objectProperty(i(name), i(name), false, name !== "this"))))])))
|
|
74
|
+
]);
|
|
75
|
+
let expression;
|
|
76
|
+
const visibility = t.isFunctionDeclaration(path.node) ? getBlockScope(path) : void 0;
|
|
77
|
+
if (t.isFunctionDeclaration(path.node)) expression = t.functionExpression(path.node.id, path.node.params, path.node.body);
|
|
78
|
+
else expression = path.node;
|
|
79
|
+
const callExpr = t.callExpression(t.arrowFunctionExpression([i("$")], t.logicalExpression("&&", t.callExpression(t.memberExpression(t.assignmentExpression("??=", t.memberExpression(i("globalThis"), i("__TYPEGPU_META__")), t.newExpression(i("WeakMap"), [])), i("set")), [t.assignmentExpression("=", t.memberExpression(i("$"), i("f")), expression), metadata]), t.memberExpression(i("$"), i("f")))), [t.objectExpression([])]);
|
|
80
|
+
t.addComment(callExpr, "leading", "#__PURE__");
|
|
81
|
+
let replacement = callExpr;
|
|
82
|
+
if (t.isFunctionDeclaration(path.node) && path.node.id) {
|
|
83
|
+
const declaration = t.variableDeclaration("const", [t.variableDeclarator(path.node.id, callExpr)]);
|
|
84
|
+
t.inheritLeadingComments(declaration, path.node);
|
|
85
|
+
replacement = declaration;
|
|
86
|
+
}
|
|
87
|
+
if (visibility) {
|
|
88
|
+
visibility.unshiftContainer("body", replacement);
|
|
89
|
+
this.alreadyTransformed.add(expression);
|
|
90
|
+
path.remove();
|
|
91
|
+
} else path.replaceWith(replacement);
|
|
92
|
+
path.skip();
|
|
93
|
+
}
|
|
94
|
+
function wrapInAutoName(path, name) {
|
|
95
|
+
const callExpr = t.callExpression(t.logicalExpression("??", t.memberExpression(i("globalThis"), i("__TYPEGPU_AUTONAME__")), t.arrowFunctionExpression([i("a")], i("a"))), [path.node, t.stringLiteral(name)]);
|
|
96
|
+
t.addComment(callExpr, "leading", "#__PURE__");
|
|
97
|
+
path.replaceWith(callExpr);
|
|
98
|
+
}
|
|
99
|
+
function replaceWithAssignmentOverload(path, runtimeFn) {
|
|
100
|
+
path.replaceWith(t.assignmentExpression("=", path.node.left, t.callExpression(i(runtimeFn), [path.node.left, path.node.right])));
|
|
101
|
+
}
|
|
102
|
+
function replaceWithBinaryOverload(path, runtimeFn) {
|
|
103
|
+
path.replaceWith(t.callExpression(i(runtimeFn), [path.node.left, path.node.right]));
|
|
104
|
+
}
|
|
105
|
+
function TypeGPUPlugin() {
|
|
106
|
+
return {
|
|
107
|
+
name: "typegpu",
|
|
108
|
+
pre() {
|
|
109
|
+
this.opts = defu(this.opts, defaultOptions);
|
|
110
|
+
initPluginState(this, {
|
|
111
|
+
warn: (message) => console.warn(message),
|
|
112
|
+
assignMetadata,
|
|
113
|
+
wrapInAutoName,
|
|
114
|
+
replaceWithAssignmentOverload,
|
|
115
|
+
replaceWithBinaryOverload
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
visitor: { Program(path, state) {
|
|
119
|
+
const filter = createFilterForId(state.opts);
|
|
120
|
+
if (state.filename && filter && !(filter === null || filter === void 0 ? void 0 : filter(state.filename))) return;
|
|
121
|
+
path.traverse(functionVisitor, state);
|
|
122
|
+
} }
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { TypeGPUPlugin as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as PluginState } from "./common-BvAFT5IV.mjs";
|
|
2
|
+
import { NodePath } from "@babel/traverse";
|
|
3
|
+
import * as t from "@babel/types";
|
|
4
|
+
|
|
5
|
+
//#region src/babel.d.ts
|
|
6
|
+
declare function TypeGPUPlugin(): {
|
|
7
|
+
name: string;
|
|
8
|
+
pre(this: PluginState): void;
|
|
9
|
+
visitor: {
|
|
10
|
+
Program(this: PluginState, path: NodePath<t.Program>, state: PluginState): void;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { TypeGPUPlugin as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as PluginState } from "./common-BKqBivuE.cjs";
|
|
2
|
+
import * as t from "@babel/types";
|
|
3
|
+
import { NodePath } from "@babel/traverse";
|
|
4
|
+
|
|
5
|
+
//#region src/babel.d.ts
|
|
6
|
+
declare function TypeGPUPlugin(): {
|
|
7
|
+
name: string;
|
|
8
|
+
pre(this: PluginState): void;
|
|
9
|
+
visitor: {
|
|
10
|
+
Program(this: PluginState, path: NodePath<t.Program>, state: PluginState): void;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { TypeGPUPlugin as t };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const require_common = require("./common-Ccx_dEqH.cjs");
|
|
2
|
+
let defu = require("defu");
|
|
3
|
+
defu = require_common.__toESM(defu);
|
|
4
|
+
let tinyest = require("tinyest");
|
|
5
|
+
require("tinyest-for-wgsl");
|
|
6
|
+
let _babel_types = require("@babel/types");
|
|
7
|
+
_babel_types = require_common.__toESM(_babel_types);
|
|
8
|
+
let pathe = require("pathe");
|
|
9
|
+
let picomatch = require("picomatch");
|
|
10
|
+
picomatch = require_common.__toESM(picomatch);
|
|
11
|
+
//#region src/core/filter.ts
|
|
12
|
+
function toArray(array) {
|
|
13
|
+
const result = array || [];
|
|
14
|
+
if (Array.isArray(result)) return result;
|
|
15
|
+
return [result];
|
|
16
|
+
}
|
|
17
|
+
const BACKSLASH_REGEX = /\\/g;
|
|
18
|
+
function normalize(path) {
|
|
19
|
+
return path.replace(BACKSLASH_REGEX, "/");
|
|
20
|
+
}
|
|
21
|
+
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
|
22
|
+
function isAbsolute(path) {
|
|
23
|
+
return ABSOLUTE_PATH_REGEX.test(path);
|
|
24
|
+
}
|
|
25
|
+
function getMatcherString(glob, cwd) {
|
|
26
|
+
if (glob.startsWith("**") || isAbsolute(glob)) return normalize(glob);
|
|
27
|
+
return normalize((0, pathe.resolve)(cwd, glob));
|
|
28
|
+
}
|
|
29
|
+
function patternToIdFilter(pattern) {
|
|
30
|
+
if (pattern instanceof RegExp) return (id) => {
|
|
31
|
+
const normalizedId = normalize(id);
|
|
32
|
+
const result = pattern.test(normalizedId);
|
|
33
|
+
pattern.lastIndex = 0;
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
const matcher = (0, picomatch.default)(getMatcherString(pattern, process.cwd()), { dot: true });
|
|
37
|
+
return (id) => {
|
|
38
|
+
return matcher(normalize(id));
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createFilter(exclude, include) {
|
|
42
|
+
if (!exclude && !include) return;
|
|
43
|
+
return (input) => {
|
|
44
|
+
if (exclude === null || exclude === void 0 ? void 0 : exclude.some((filter) => filter(input))) return false;
|
|
45
|
+
if (include === null || include === void 0 ? void 0 : include.some((filter) => filter(input))) return true;
|
|
46
|
+
return !(include && include.length > 0);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function normalizeFilter(filter) {
|
|
50
|
+
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
|
51
|
+
if (Array.isArray(filter)) return { include: filter };
|
|
52
|
+
return {
|
|
53
|
+
exclude: filter.exclude ? toArray(filter.exclude) : void 0,
|
|
54
|
+
include: filter.include ? toArray(filter.include) : void 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function createIdFilter(filter) {
|
|
58
|
+
if (!filter) return;
|
|
59
|
+
const { exclude, include } = normalizeFilter(filter);
|
|
60
|
+
return createFilter(exclude === null || exclude === void 0 ? void 0 : exclude.map(patternToIdFilter), include === null || include === void 0 ? void 0 : include.map(patternToIdFilter));
|
|
61
|
+
}
|
|
62
|
+
function createFilterForId(filter) {
|
|
63
|
+
const filterFunction = createIdFilter(filter);
|
|
64
|
+
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/babel.ts
|
|
68
|
+
function i(identifier) {
|
|
69
|
+
return _babel_types.identifier(identifier);
|
|
70
|
+
}
|
|
71
|
+
function assignMetadata(path, name, ast) {
|
|
72
|
+
const metadata = _babel_types.objectExpression([
|
|
73
|
+
_babel_types.objectProperty(i("v"), _babel_types.numericLiteral(tinyest.FORMAT_VERSION)),
|
|
74
|
+
_babel_types.objectProperty(i("name"), _babel_types.valueToNode(name)),
|
|
75
|
+
_babel_types.objectProperty(i("ast"), _babel_types.valueToNode(ast)),
|
|
76
|
+
_babel_types.objectProperty(i("externals"), _babel_types.arrowFunctionExpression([], _babel_types.blockStatement([_babel_types.returnStatement(_babel_types.objectExpression(ast.externalNames.map((name) => name === "this" ? _babel_types.objectProperty(i("this"), _babel_types.thisExpression()) : _babel_types.objectProperty(i(name), i(name), false, name !== "this"))))])))
|
|
77
|
+
]);
|
|
78
|
+
let expression;
|
|
79
|
+
const visibility = _babel_types.isFunctionDeclaration(path.node) ? require_common.getBlockScope(path) : void 0;
|
|
80
|
+
if (_babel_types.isFunctionDeclaration(path.node)) expression = _babel_types.functionExpression(path.node.id, path.node.params, path.node.body);
|
|
81
|
+
else expression = path.node;
|
|
82
|
+
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([])]);
|
|
83
|
+
_babel_types.addComment(callExpr, "leading", "#__PURE__");
|
|
84
|
+
let replacement = callExpr;
|
|
85
|
+
if (_babel_types.isFunctionDeclaration(path.node) && path.node.id) {
|
|
86
|
+
const declaration = _babel_types.variableDeclaration("const", [_babel_types.variableDeclarator(path.node.id, callExpr)]);
|
|
87
|
+
_babel_types.inheritLeadingComments(declaration, path.node);
|
|
88
|
+
replacement = declaration;
|
|
89
|
+
}
|
|
90
|
+
if (visibility) {
|
|
91
|
+
visibility.unshiftContainer("body", replacement);
|
|
92
|
+
this.alreadyTransformed.add(expression);
|
|
93
|
+
path.remove();
|
|
94
|
+
} else path.replaceWith(replacement);
|
|
95
|
+
path.skip();
|
|
96
|
+
}
|
|
97
|
+
function wrapInAutoName(path, name) {
|
|
98
|
+
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)]);
|
|
99
|
+
_babel_types.addComment(callExpr, "leading", "#__PURE__");
|
|
100
|
+
path.replaceWith(callExpr);
|
|
101
|
+
}
|
|
102
|
+
function replaceWithAssignmentOverload(path, runtimeFn) {
|
|
103
|
+
path.replaceWith(_babel_types.assignmentExpression("=", path.node.left, _babel_types.callExpression(i(runtimeFn), [path.node.left, path.node.right])));
|
|
104
|
+
}
|
|
105
|
+
function replaceWithBinaryOverload(path, runtimeFn) {
|
|
106
|
+
path.replaceWith(_babel_types.callExpression(i(runtimeFn), [path.node.left, path.node.right]));
|
|
107
|
+
}
|
|
108
|
+
function TypeGPUPlugin() {
|
|
109
|
+
return {
|
|
110
|
+
name: "typegpu",
|
|
111
|
+
pre() {
|
|
112
|
+
this.opts = (0, defu.default)(this.opts, require_common.defaultOptions);
|
|
113
|
+
require_common.initPluginState(this, {
|
|
114
|
+
warn: (message) => console.warn(message),
|
|
115
|
+
assignMetadata,
|
|
116
|
+
wrapInAutoName,
|
|
117
|
+
replaceWithAssignmentOverload,
|
|
118
|
+
replaceWithBinaryOverload
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
visitor: { Program(path, state) {
|
|
122
|
+
const filter = createFilterForId(state.opts);
|
|
123
|
+
if (state.filename && filter && !(filter === null || filter === void 0 ? void 0 : filter(state.filename))) return;
|
|
124
|
+
path.traverse(require_common.functionVisitor, state);
|
|
125
|
+
} }
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
Object.defineProperty(exports, "TypeGPUPlugin", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function() {
|
|
132
|
+
return TypeGPUPlugin;
|
|
133
|
+
}
|
|
134
|
+
});
|
package/babel.cjs
CHANGED
|
@@ -1,163 +1,6 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let tinyest_for_wgsl = require("tinyest-for-wgsl");
|
|
8
|
-
let tinyest = require("tinyest");
|
|
9
|
-
let _babel_standalone = require("@babel/standalone");
|
|
10
|
-
_babel_standalone = require_runtime.__toESM(_babel_standalone);
|
|
11
|
-
|
|
12
|
-
//#region src/babel.ts
|
|
13
|
-
const template = _babel_standalone.packages.template;
|
|
14
|
-
const types = _babel_standalone.packages.types;
|
|
15
|
-
function containsUseGpuDirective(node) {
|
|
16
|
-
var _node$body$directives, _node$body;
|
|
17
|
-
return ("directives" in node.body ? (_node$body$directives = (_node$body = node.body) === null || _node$body === void 0 ? void 0 : _node$body.directives) !== null && _node$body$directives !== void 0 ? _node$body$directives : [] : []).map((directive) => directive.value.value).includes(require_common.useGpuDirective);
|
|
18
|
-
}
|
|
19
|
-
function i(identifier) {
|
|
20
|
-
return types.identifier(identifier);
|
|
21
|
-
}
|
|
22
|
-
const fnNodeToOriginalMap = /* @__PURE__ */ new WeakMap();
|
|
23
|
-
function functionToTranspiled(node, parent) {
|
|
24
|
-
var _fnNodeToOriginalMap$;
|
|
25
|
-
const { params, body, externalNames } = (0, tinyest_for_wgsl.transpileFn)((_fnNodeToOriginalMap$ = fnNodeToOriginalMap.get(node)) !== null && _fnNodeToOriginalMap$ !== void 0 ? _fnNodeToOriginalMap$ : node);
|
|
26
|
-
const maybeName = require_common.getFunctionName(node, parent);
|
|
27
|
-
const metadata = types.objectExpression([
|
|
28
|
-
types.objectProperty(i("v"), types.numericLiteral(tinyest.FORMAT_VERSION)),
|
|
29
|
-
types.objectProperty(i("name"), maybeName ? types.stringLiteral(maybeName) : types.buildUndefinedNode()),
|
|
30
|
-
types.objectProperty(i("ast"), template.expression`${require_common.embedJSON({
|
|
31
|
-
params,
|
|
32
|
-
body,
|
|
33
|
-
externalNames
|
|
34
|
-
})}`()),
|
|
35
|
-
types.objectProperty(i("externals"), types.arrowFunctionExpression([], types.blockStatement([types.returnStatement(types.objectExpression(externalNames.map((name) => types.objectProperty(i(name), i(name), false, name !== "this"))))])))
|
|
36
|
-
]);
|
|
37
|
-
return types.callExpression(types.arrowFunctionExpression([i("$")], types.logicalExpression("&&", types.callExpression(types.memberExpression(types.assignmentExpression("??=", types.memberExpression(i("globalThis"), i("__TYPEGPU_META__")), types.newExpression(i("WeakMap"), [])), i("set")), [types.assignmentExpression("=", types.memberExpression(i("$"), i("f")), node), metadata]), types.memberExpression(i("$"), i("f")))), [types.objectExpression([])]);
|
|
38
|
-
}
|
|
39
|
-
function wrapInAutoName(node, name) {
|
|
40
|
-
return types.callExpression(template.expression("globalThis.__TYPEGPU_AUTONAME__ ?? (a => a)", { placeholderPattern: false })(), [node, types.stringLiteral(name)]);
|
|
41
|
-
}
|
|
42
|
-
function functionVisitor(ctx) {
|
|
43
|
-
let inUseGpuScope = false;
|
|
44
|
-
return {
|
|
45
|
-
VariableDeclarator(path) {
|
|
46
|
-
require_common.performExpressionNaming(ctx, path.node, (node, name) => {
|
|
47
|
-
path.get("init").replaceWith(wrapInAutoName(node, name));
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
AssignmentExpression(path) {
|
|
51
|
-
if (inUseGpuScope) {
|
|
52
|
-
const runtimeFn = require_common.operators[path.node.operator];
|
|
53
|
-
if (runtimeFn) path.replaceWith(types.assignmentExpression("=", path.node.left, types.callExpression(types.identifier(runtimeFn), [path.node.left, path.node.right])));
|
|
54
|
-
}
|
|
55
|
-
require_common.performExpressionNaming(ctx, path.node, (node, name) => {
|
|
56
|
-
path.get("right").replaceWith(wrapInAutoName(node, name));
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
ObjectProperty(path) {
|
|
60
|
-
require_common.performExpressionNaming(ctx, path.node, (node, name) => {
|
|
61
|
-
path.get("value").replaceWith(wrapInAutoName(node, name));
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
ClassProperty(path) {
|
|
65
|
-
require_common.performExpressionNaming(ctx, path.node, (node, name) => {
|
|
66
|
-
path.get("value").replaceWith(wrapInAutoName(node, name));
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
ImportDeclaration(path) {
|
|
70
|
-
require_common.gatherTgpuAliases(path.node, ctx);
|
|
71
|
-
},
|
|
72
|
-
BinaryExpression: { exit(path) {
|
|
73
|
-
if (!inUseGpuScope) return;
|
|
74
|
-
const runtimeFn = require_common.operators[path.node.operator];
|
|
75
|
-
if (runtimeFn) path.replaceWith(types.callExpression(types.identifier(runtimeFn), [path.node.left, path.node.right]));
|
|
76
|
-
} },
|
|
77
|
-
ArrowFunctionExpression: {
|
|
78
|
-
enter(path) {
|
|
79
|
-
if (containsUseGpuDirective(path.node)) {
|
|
80
|
-
fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
|
|
81
|
-
if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
|
|
82
|
-
inUseGpuScope = true;
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
exit(path) {
|
|
86
|
-
const node = path.node;
|
|
87
|
-
if (containsUseGpuDirective(node)) {
|
|
88
|
-
inUseGpuScope = false;
|
|
89
|
-
const parent = path.parentPath.node;
|
|
90
|
-
path.replaceWith(functionToTranspiled(node, parent));
|
|
91
|
-
path.skip();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
FunctionExpression: {
|
|
96
|
-
enter(path) {
|
|
97
|
-
if (containsUseGpuDirective(path.node)) {
|
|
98
|
-
fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
|
|
99
|
-
if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
|
|
100
|
-
inUseGpuScope = true;
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
exit(path) {
|
|
104
|
-
const node = path.node;
|
|
105
|
-
if (containsUseGpuDirective(node)) {
|
|
106
|
-
inUseGpuScope = false;
|
|
107
|
-
const parent = path.parentPath.node;
|
|
108
|
-
path.replaceWith(functionToTranspiled(node, parent));
|
|
109
|
-
path.skip();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
FunctionDeclaration: {
|
|
114
|
-
enter(path) {
|
|
115
|
-
if (containsUseGpuDirective(path.node)) {
|
|
116
|
-
fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
|
|
117
|
-
if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
|
|
118
|
-
inUseGpuScope = true;
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
exit(path) {
|
|
122
|
-
var _fnNodeToOriginalMap$2;
|
|
123
|
-
const node = (_fnNodeToOriginalMap$2 = fnNodeToOriginalMap.get(path.node)) !== null && _fnNodeToOriginalMap$2 !== void 0 ? _fnNodeToOriginalMap$2 : path.node;
|
|
124
|
-
if (containsUseGpuDirective(node)) {
|
|
125
|
-
inUseGpuScope = false;
|
|
126
|
-
if (!node.id) return;
|
|
127
|
-
const parent = path.parentPath.node;
|
|
128
|
-
const expression = types.functionExpression(node.id, node.params, node.body);
|
|
129
|
-
path.replaceWith(types.variableDeclaration("const", [types.variableDeclarator(node.id, functionToTranspiled(expression, parent))]));
|
|
130
|
-
path.skip();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
CallExpression: { exit(path) {
|
|
135
|
-
const node = path.node;
|
|
136
|
-
if (require_common.isShellImplementationCall(node, ctx)) {
|
|
137
|
-
const implementation = node.arguments[0];
|
|
138
|
-
if (implementation && (implementation.type === "FunctionExpression" || implementation.type === "ArrowFunctionExpression")) {
|
|
139
|
-
const transpiled = functionToTranspiled(implementation, null);
|
|
140
|
-
path.replaceWith(types.callExpression(node.callee, [transpiled]));
|
|
141
|
-
path.skip();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
} }
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function babel_default() {
|
|
148
|
-
return { visitor: { Program(path, state) {
|
|
149
|
-
const options = (0, defu.default)(state.opts, require_common.defaultOptions);
|
|
150
|
-
const id = state.filename;
|
|
151
|
-
const filter = require_filter.createFilterForId(options);
|
|
152
|
-
if (id && filter && !(filter === null || filter === void 0 ? void 0 : filter(id))) return;
|
|
153
|
-
const ctx = {
|
|
154
|
-
tgpuAliases: new Set(options.forceTgpuAlias ? [options.forceTgpuAlias] : []),
|
|
155
|
-
fileId: id,
|
|
156
|
-
autoNamingEnabled: options.autoNamingEnabled
|
|
157
|
-
};
|
|
158
|
-
path.traverse(functionVisitor(ctx));
|
|
159
|
-
} } };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
//#endregion
|
|
163
|
-
exports.default = babel_default;
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_babel = require("./babel-izRcz0Uk.cjs");
|
|
6
|
+
exports.default = require_babel.TypeGPUPlugin;
|
package/babel.d.cts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/babel.d.ts
|
|
5
|
-
declare function export_default(): {
|
|
6
|
-
visitor: {
|
|
7
|
-
Program(this: Node, path: _babel_traverse0.NodePath<Program>, state: Node): void;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export = export_default;
|
|
1
|
+
import { t as TypeGPUPlugin } from "./babel-C1TaJd38.cjs";
|
|
2
|
+
export = TypeGPUPlugin;
|
package/babel.d.mts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/babel.d.ts
|
|
5
|
-
declare function export_default(): {
|
|
6
|
-
visitor: {
|
|
7
|
-
Program(this: Node, path: _babel_traverse0.NodePath<Program>, state: Node): void;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
//#endregion
|
|
11
|
-
export { export_default as default };
|
|
1
|
+
import { t as TypeGPUPlugin } from "./babel-C0RyQRMk.mjs";
|
|
2
|
+
export { TypeGPUPlugin as default };
|