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.
- 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 -161
- package/babel.d.cts +2 -10
- package/babel.d.mts +2 -11
- package/babel.mjs +2 -158
- 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 -39
- 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 -29
- package/index.d.cts +5 -17
- package/index.d.mts +5 -17
- package/index.mjs +4 -17
- package/package.json +11 -8
- 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/common-CRPQ2KE6.d.mts +0 -25
- package/common-Dpl8jppn.d.cts +0 -25
- package/filter-6T-5w4kG.mjs +0 -234
- package/filter-CKmD4HRk.cjs +0 -327
- package/index-legacy-DRI9LQiG.d.mts +0 -1488
- package/index-legacy-xKi5C2ga.d.cts +0 -1488
- package/rolldown-browser-DKeiFM_e.mjs +0 -129
- package/rolldown-browser-DUanNY-R.cjs +0 -141
- package/rolldown-browser-JYqfNLQ8.d.mts +0 -1247
- package/rollup-impl-DqC_d-_W.d.cts +0 -1246
package/common-CRPQ2KE6.d.mts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { FilterPattern } from "unplugin";
|
|
2
|
-
|
|
3
|
-
//#region src/common.d.ts
|
|
4
|
-
interface Options {
|
|
5
|
-
/** @default [/\.m?[jt]sx?$/] */
|
|
6
|
-
include?: FilterPattern;
|
|
7
|
-
/** @default undefined */
|
|
8
|
-
exclude?: FilterPattern;
|
|
9
|
-
/** @default undefined */
|
|
10
|
-
enforce?: 'post' | 'pre' | undefined;
|
|
11
|
-
/** @default undefined */
|
|
12
|
-
forceTgpuAlias?: string | undefined;
|
|
13
|
-
/** @default true */
|
|
14
|
-
autoNamingEnabled?: boolean | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* Skipping files that don't contain "typegpu", "tgpu" or "use gpu".
|
|
17
|
-
* In case this early pruning hinders transformation, you
|
|
18
|
-
* can disable it.
|
|
19
|
-
*
|
|
20
|
-
* @default true
|
|
21
|
-
*/
|
|
22
|
-
earlyPruning?: boolean | undefined;
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { Options as t };
|
package/common-Dpl8jppn.d.cts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { FilterPattern } from "unplugin";
|
|
2
|
-
|
|
3
|
-
//#region src/common.d.ts
|
|
4
|
-
interface Options {
|
|
5
|
-
/** @default [/\.m?[jt]sx?$/] */
|
|
6
|
-
include?: FilterPattern;
|
|
7
|
-
/** @default undefined */
|
|
8
|
-
exclude?: FilterPattern;
|
|
9
|
-
/** @default undefined */
|
|
10
|
-
enforce?: 'post' | 'pre' | undefined;
|
|
11
|
-
/** @default undefined */
|
|
12
|
-
forceTgpuAlias?: string | undefined;
|
|
13
|
-
/** @default true */
|
|
14
|
-
autoNamingEnabled?: boolean | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* Skipping files that don't contain "typegpu", "tgpu" or "use gpu".
|
|
17
|
-
* In case this early pruning hinders transformation, you
|
|
18
|
-
* can disable it.
|
|
19
|
-
*
|
|
20
|
-
* @default true
|
|
21
|
-
*/
|
|
22
|
-
earlyPruning?: boolean | undefined;
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { Options as t };
|
package/filter-6T-5w4kG.mjs
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { resolve } from "pathe";
|
|
2
|
-
import picomatch from "picomatch";
|
|
3
|
-
|
|
4
|
-
//#region src/common.ts
|
|
5
|
-
const defaultOptions = {
|
|
6
|
-
include: /\.m?[jt]sx?(?:\?.*)?$/,
|
|
7
|
-
autoNamingEnabled: true,
|
|
8
|
-
earlyPruning: true
|
|
9
|
-
};
|
|
10
|
-
function embedJSON(jsValue) {
|
|
11
|
-
return JSON.stringify(jsValue).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Checks if `node` is an alias for the 'tgpu' object, traditionally
|
|
15
|
-
* available via `import tgpu from 'typegpu'`.
|
|
16
|
-
*/
|
|
17
|
-
function isTgpu(ctx, node) {
|
|
18
|
-
let path = "";
|
|
19
|
-
let tail = node;
|
|
20
|
-
while (true) if (tail.type === "MemberExpression") {
|
|
21
|
-
if ((tail.property.type === "Literal" || tail.property.type === "StringLiteral") && tail.property.value === "~unstable") {
|
|
22
|
-
tail = tail.object;
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
if (tail.property.type !== "Identifier") break;
|
|
26
|
-
path = path ? `${tail.property.name}.${path}` : tail.property.name;
|
|
27
|
-
tail = tail.object;
|
|
28
|
-
} else if (tail.type === "Identifier") {
|
|
29
|
-
path = path ? `${tail.name}.${path}` : tail.name;
|
|
30
|
-
break;
|
|
31
|
-
} else break;
|
|
32
|
-
return ctx.tgpuAliases.has(path);
|
|
33
|
-
}
|
|
34
|
-
function gatherTgpuAliases(node, ctx) {
|
|
35
|
-
if (node.source.value === "typegpu") {
|
|
36
|
-
for (const spec of node.specifiers) if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && spec.imported.name === "tgpu") ctx.tgpuAliases.add(spec.local.name);
|
|
37
|
-
else if (spec.type === "ImportNamespaceSpecifier") ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const fnShellFunctionNames = [
|
|
41
|
-
"fn",
|
|
42
|
-
"vertexFn",
|
|
43
|
-
"fragmentFn",
|
|
44
|
-
"computeFn"
|
|
45
|
-
];
|
|
46
|
-
function isShellImplementationCall(node, ctx) {
|
|
47
|
-
return node.callee.type === "CallExpression" && node.callee.callee.type === "MemberExpression" && node.callee.callee.property.type === "Identifier" && fnShellFunctionNames.includes(node.callee.callee.property.name) && node.arguments.length === 1 && isTgpu(ctx, node.callee.callee.object);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Extracts a name and expression from nodes that contain a label and an expression,
|
|
51
|
-
* such as VariableDeclarator or PropertyDefinition.
|
|
52
|
-
* Returns a tuple of [name, expression] if found, otherwise undefined.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* extractLabelledExpression(node`let name = tgpu.bindGroupLayout({});`)
|
|
56
|
-
* // ["name", node`tgpu.bindGroupLayout({})`]
|
|
57
|
-
*/
|
|
58
|
-
function extractLabelledExpression(node) {
|
|
59
|
-
if (node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.init) return [node.id.name, node.init];
|
|
60
|
-
else if (node.type === "AssignmentExpression") {
|
|
61
|
-
const maybeName = tryFindIdentifier(node.left);
|
|
62
|
-
if (maybeName) return [maybeName, node.right];
|
|
63
|
-
} else if ((node.type === "Property" || node.type === "ObjectProperty") && node.key.type === "Identifier") return [node.key.name, node.value];
|
|
64
|
-
else if ((node.type === "ClassProperty" || node.type === "PropertyDefinition") && node.value && node.key.type === "Identifier") return [node.key.name, node.value];
|
|
65
|
-
}
|
|
66
|
-
function getFunctionName(node, parent) {
|
|
67
|
-
var _extractLabelledExpre, _node$id;
|
|
68
|
-
const maybeName = parent ? (_extractLabelledExpre = extractLabelledExpression(parent)) === null || _extractLabelledExpre === void 0 ? void 0 : _extractLabelledExpre[0] : void 0;
|
|
69
|
-
return maybeName !== null && maybeName !== void 0 ? maybeName : node.type === "FunctionDeclaration" || node.type === "FunctionExpression" ? (_node$id = node.id) === null || _node$id === void 0 ? void 0 : _node$id.name : void 0;
|
|
70
|
-
}
|
|
71
|
-
const resourceConstructors = [
|
|
72
|
-
"bindGroupLayout",
|
|
73
|
-
"vertexLayout",
|
|
74
|
-
"privateVar",
|
|
75
|
-
"workgroupVar",
|
|
76
|
-
"const",
|
|
77
|
-
"slot",
|
|
78
|
-
"accessor",
|
|
79
|
-
"comptime",
|
|
80
|
-
...fnShellFunctionNames,
|
|
81
|
-
"createBuffer",
|
|
82
|
-
"createMutable",
|
|
83
|
-
"createReadonly",
|
|
84
|
-
"createUniform",
|
|
85
|
-
"createQuerySet",
|
|
86
|
-
"createPipeline",
|
|
87
|
-
"createComputePipeline",
|
|
88
|
-
"createGuardedComputePipeline",
|
|
89
|
-
"createRenderPipeline",
|
|
90
|
-
"createTexture",
|
|
91
|
-
"createSampler",
|
|
92
|
-
"createComparisonSampler",
|
|
93
|
-
"struct",
|
|
94
|
-
"unstruct",
|
|
95
|
-
"createView"
|
|
96
|
-
];
|
|
97
|
-
/**
|
|
98
|
-
* Checks if `node` should be wrapped in an autoname function.
|
|
99
|
-
* Since it is mostly for debugging and clean WGSL generation,
|
|
100
|
-
* some false positives and false negatives are admissible.
|
|
101
|
-
*/
|
|
102
|
-
function containsResourceConstructorCall(node, ctx) {
|
|
103
|
-
if (node.type === "CallExpression") {
|
|
104
|
-
if (isShellImplementationCall(node, ctx)) return true;
|
|
105
|
-
if (node.callee.type === "Identifier" && resourceConstructors.includes(node.callee.name)) return true;
|
|
106
|
-
if (node.callee.type === "MemberExpression") {
|
|
107
|
-
if (node.callee.property.type === "Identifier") {
|
|
108
|
-
if (resourceConstructors.includes(node.callee.property.name)) return true;
|
|
109
|
-
if (node.callee.property.name === "$name") return false;
|
|
110
|
-
}
|
|
111
|
-
return containsResourceConstructorCall(node.callee.object, ctx);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (node.type === "TaggedTemplateExpression") return containsResourceConstructorCall(node.tag, ctx);
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Tries to find an identifier in a node.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* // syntax is simplified, imagine the arguments are appropriate nodes instead
|
|
122
|
-
* tryFindIdentifier('myBuffer'); // 'myBuffer'
|
|
123
|
-
* tryFindIdentifier('buffers.myBuffer'); // 'myBuffer'
|
|
124
|
-
* tryFindIdentifier('this.myBuffer'); // 'myBuffer'
|
|
125
|
-
* tryFindIdentifier('[a, b]'); // undefined
|
|
126
|
-
*/
|
|
127
|
-
function tryFindIdentifier(node) {
|
|
128
|
-
if (node.type === "Identifier") return node.name;
|
|
129
|
-
if (node.type === "PrivateName") return tryFindIdentifier(node.id);
|
|
130
|
-
if (node.type === "PrivateIdentifier") return node.name;
|
|
131
|
-
if (node.type === "MemberExpression") return tryFindIdentifier(node.property);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Checks if `node` contains a label and a tgpu expression that could be named.
|
|
135
|
-
* If so, it calls the provided callback. Nodes selected for naming include:
|
|
136
|
-
*
|
|
137
|
-
* `let name = tgpu.bindGroupLayout({});` (VariableDeclarator)
|
|
138
|
-
*
|
|
139
|
-
* `name = tgpu.bindGroupLayout({});` (AssignmentExpression)
|
|
140
|
-
*
|
|
141
|
-
* `property: tgpu.bindGroupLayout({})` (Property/ObjectProperty)
|
|
142
|
-
*
|
|
143
|
-
* Since it is mostly for debugging and clean WGSL generation,
|
|
144
|
-
* some false positives and false negatives are admissible.
|
|
145
|
-
*
|
|
146
|
-
* This function is NOT used for auto-naming shell-less functions.
|
|
147
|
-
* Those are handled separately.
|
|
148
|
-
*
|
|
149
|
-
* @privateRemarks
|
|
150
|
-
* When adding new checks, you need to call this method in the corresponding node in Babel.
|
|
151
|
-
*/
|
|
152
|
-
function performExpressionNaming(ctx, node, namingCallback) {
|
|
153
|
-
if (!ctx.autoNamingEnabled) return;
|
|
154
|
-
const labelledExpression = extractLabelledExpression(node);
|
|
155
|
-
if (labelledExpression) {
|
|
156
|
-
const [label, expression] = labelledExpression;
|
|
157
|
-
if (containsResourceConstructorCall(expression, ctx)) namingCallback(expression, label);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const useGpuDirective = "use gpu";
|
|
161
|
-
/** Regular expressions used for early pruning (to avoid unnecessary parsing, which is expensive) */
|
|
162
|
-
const earlyPruneRegex = [/["']use gpu["']/, /t(ype)?gpu/];
|
|
163
|
-
const operators = {
|
|
164
|
-
"+": "__tsover_add",
|
|
165
|
-
"-": "__tsover_sub",
|
|
166
|
-
"*": "__tsover_mul",
|
|
167
|
-
"/": "__tsover_div",
|
|
168
|
-
"%": "__tsover_mod",
|
|
169
|
-
"+=": "__tsover_add",
|
|
170
|
-
"-=": "__tsover_sub",
|
|
171
|
-
"*=": "__tsover_mul",
|
|
172
|
-
"/=": "__tsover_div",
|
|
173
|
-
"%=": "__tsover_mod"
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region src/filter.ts
|
|
178
|
-
function toArray(array) {
|
|
179
|
-
const result = array || [];
|
|
180
|
-
if (Array.isArray(result)) return result;
|
|
181
|
-
return [result];
|
|
182
|
-
}
|
|
183
|
-
const BACKSLASH_REGEX = /\\/g;
|
|
184
|
-
function normalize(path) {
|
|
185
|
-
return path.replace(BACKSLASH_REGEX, "/");
|
|
186
|
-
}
|
|
187
|
-
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
|
188
|
-
function isAbsolute(path) {
|
|
189
|
-
return ABSOLUTE_PATH_REGEX.test(path);
|
|
190
|
-
}
|
|
191
|
-
function getMatcherString(glob, cwd) {
|
|
192
|
-
if (glob.startsWith("**") || isAbsolute(glob)) return normalize(glob);
|
|
193
|
-
return normalize(resolve(cwd, glob));
|
|
194
|
-
}
|
|
195
|
-
function patternToIdFilter(pattern) {
|
|
196
|
-
if (pattern instanceof RegExp) return (id) => {
|
|
197
|
-
const normalizedId = normalize(id);
|
|
198
|
-
const result = pattern.test(normalizedId);
|
|
199
|
-
pattern.lastIndex = 0;
|
|
200
|
-
return result;
|
|
201
|
-
};
|
|
202
|
-
const matcher = picomatch(getMatcherString(pattern, process.cwd()), { dot: true });
|
|
203
|
-
return (id) => {
|
|
204
|
-
return matcher(normalize(id));
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function createFilter(exclude, include) {
|
|
208
|
-
if (!exclude && !include) return;
|
|
209
|
-
return (input) => {
|
|
210
|
-
if (exclude === null || exclude === void 0 ? void 0 : exclude.some((filter) => filter(input))) return false;
|
|
211
|
-
if (include === null || include === void 0 ? void 0 : include.some((filter) => filter(input))) return true;
|
|
212
|
-
return !(include && include.length > 0);
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function normalizeFilter(filter) {
|
|
216
|
-
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
|
217
|
-
if (Array.isArray(filter)) return { include: filter };
|
|
218
|
-
return {
|
|
219
|
-
exclude: filter.exclude ? toArray(filter.exclude) : void 0,
|
|
220
|
-
include: filter.include ? toArray(filter.include) : void 0
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function createIdFilter(filter) {
|
|
224
|
-
if (!filter) return;
|
|
225
|
-
const { exclude, include } = normalizeFilter(filter);
|
|
226
|
-
return createFilter(exclude === null || exclude === void 0 ? void 0 : exclude.map(patternToIdFilter), include === null || include === void 0 ? void 0 : include.map(patternToIdFilter));
|
|
227
|
-
}
|
|
228
|
-
function createFilterForId(filter) {
|
|
229
|
-
const filterFunction = createIdFilter(filter);
|
|
230
|
-
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
//#endregion
|
|
234
|
-
export { gatherTgpuAliases as a, operators as c, embedJSON as i, performExpressionNaming as l, defaultOptions as n, getFunctionName as o, earlyPruneRegex as r, isShellImplementationCall as s, createFilterForId as t, useGpuDirective as u };
|
package/filter-CKmD4HRk.cjs
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
let pathe = require("pathe");
|
|
29
|
-
let picomatch = require("picomatch");
|
|
30
|
-
picomatch = __toESM(picomatch);
|
|
31
|
-
|
|
32
|
-
//#region src/common.ts
|
|
33
|
-
const defaultOptions = {
|
|
34
|
-
include: /\.m?[jt]sx?(?:\?.*)?$/,
|
|
35
|
-
autoNamingEnabled: true,
|
|
36
|
-
earlyPruning: true
|
|
37
|
-
};
|
|
38
|
-
function embedJSON(jsValue) {
|
|
39
|
-
return JSON.stringify(jsValue).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Checks if `node` is an alias for the 'tgpu' object, traditionally
|
|
43
|
-
* available via `import tgpu from 'typegpu'`.
|
|
44
|
-
*/
|
|
45
|
-
function isTgpu(ctx, node) {
|
|
46
|
-
let path = "";
|
|
47
|
-
let tail = node;
|
|
48
|
-
while (true) if (tail.type === "MemberExpression") {
|
|
49
|
-
if ((tail.property.type === "Literal" || tail.property.type === "StringLiteral") && tail.property.value === "~unstable") {
|
|
50
|
-
tail = tail.object;
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (tail.property.type !== "Identifier") break;
|
|
54
|
-
path = path ? `${tail.property.name}.${path}` : tail.property.name;
|
|
55
|
-
tail = tail.object;
|
|
56
|
-
} else if (tail.type === "Identifier") {
|
|
57
|
-
path = path ? `${tail.name}.${path}` : tail.name;
|
|
58
|
-
break;
|
|
59
|
-
} else break;
|
|
60
|
-
return ctx.tgpuAliases.has(path);
|
|
61
|
-
}
|
|
62
|
-
function gatherTgpuAliases(node, ctx) {
|
|
63
|
-
if (node.source.value === "typegpu") {
|
|
64
|
-
for (const spec of node.specifiers) if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && spec.imported.name === "tgpu") ctx.tgpuAliases.add(spec.local.name);
|
|
65
|
-
else if (spec.type === "ImportNamespaceSpecifier") ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const fnShellFunctionNames = [
|
|
69
|
-
"fn",
|
|
70
|
-
"vertexFn",
|
|
71
|
-
"fragmentFn",
|
|
72
|
-
"computeFn"
|
|
73
|
-
];
|
|
74
|
-
function isShellImplementationCall(node, ctx) {
|
|
75
|
-
return node.callee.type === "CallExpression" && node.callee.callee.type === "MemberExpression" && node.callee.callee.property.type === "Identifier" && fnShellFunctionNames.includes(node.callee.callee.property.name) && node.arguments.length === 1 && isTgpu(ctx, node.callee.callee.object);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Extracts a name and expression from nodes that contain a label and an expression,
|
|
79
|
-
* such as VariableDeclarator or PropertyDefinition.
|
|
80
|
-
* Returns a tuple of [name, expression] if found, otherwise undefined.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* extractLabelledExpression(node`let name = tgpu.bindGroupLayout({});`)
|
|
84
|
-
* // ["name", node`tgpu.bindGroupLayout({})`]
|
|
85
|
-
*/
|
|
86
|
-
function extractLabelledExpression(node) {
|
|
87
|
-
if (node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.init) return [node.id.name, node.init];
|
|
88
|
-
else if (node.type === "AssignmentExpression") {
|
|
89
|
-
const maybeName = tryFindIdentifier(node.left);
|
|
90
|
-
if (maybeName) return [maybeName, node.right];
|
|
91
|
-
} else if ((node.type === "Property" || node.type === "ObjectProperty") && node.key.type === "Identifier") return [node.key.name, node.value];
|
|
92
|
-
else if ((node.type === "ClassProperty" || node.type === "PropertyDefinition") && node.value && node.key.type === "Identifier") return [node.key.name, node.value];
|
|
93
|
-
}
|
|
94
|
-
function getFunctionName(node, parent) {
|
|
95
|
-
var _extractLabelledExpre, _node$id;
|
|
96
|
-
const maybeName = parent ? (_extractLabelledExpre = extractLabelledExpression(parent)) === null || _extractLabelledExpre === void 0 ? void 0 : _extractLabelledExpre[0] : void 0;
|
|
97
|
-
return maybeName !== null && maybeName !== void 0 ? maybeName : node.type === "FunctionDeclaration" || node.type === "FunctionExpression" ? (_node$id = node.id) === null || _node$id === void 0 ? void 0 : _node$id.name : void 0;
|
|
98
|
-
}
|
|
99
|
-
const resourceConstructors = [
|
|
100
|
-
"bindGroupLayout",
|
|
101
|
-
"vertexLayout",
|
|
102
|
-
"privateVar",
|
|
103
|
-
"workgroupVar",
|
|
104
|
-
"const",
|
|
105
|
-
"slot",
|
|
106
|
-
"accessor",
|
|
107
|
-
"comptime",
|
|
108
|
-
...fnShellFunctionNames,
|
|
109
|
-
"createBuffer",
|
|
110
|
-
"createMutable",
|
|
111
|
-
"createReadonly",
|
|
112
|
-
"createUniform",
|
|
113
|
-
"createQuerySet",
|
|
114
|
-
"createPipeline",
|
|
115
|
-
"createComputePipeline",
|
|
116
|
-
"createGuardedComputePipeline",
|
|
117
|
-
"createRenderPipeline",
|
|
118
|
-
"createTexture",
|
|
119
|
-
"createSampler",
|
|
120
|
-
"createComparisonSampler",
|
|
121
|
-
"struct",
|
|
122
|
-
"unstruct",
|
|
123
|
-
"createView"
|
|
124
|
-
];
|
|
125
|
-
/**
|
|
126
|
-
* Checks if `node` should be wrapped in an autoname function.
|
|
127
|
-
* Since it is mostly for debugging and clean WGSL generation,
|
|
128
|
-
* some false positives and false negatives are admissible.
|
|
129
|
-
*/
|
|
130
|
-
function containsResourceConstructorCall(node, ctx) {
|
|
131
|
-
if (node.type === "CallExpression") {
|
|
132
|
-
if (isShellImplementationCall(node, ctx)) return true;
|
|
133
|
-
if (node.callee.type === "Identifier" && resourceConstructors.includes(node.callee.name)) return true;
|
|
134
|
-
if (node.callee.type === "MemberExpression") {
|
|
135
|
-
if (node.callee.property.type === "Identifier") {
|
|
136
|
-
if (resourceConstructors.includes(node.callee.property.name)) return true;
|
|
137
|
-
if (node.callee.property.name === "$name") return false;
|
|
138
|
-
}
|
|
139
|
-
return containsResourceConstructorCall(node.callee.object, ctx);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (node.type === "TaggedTemplateExpression") return containsResourceConstructorCall(node.tag, ctx);
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Tries to find an identifier in a node.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* // syntax is simplified, imagine the arguments are appropriate nodes instead
|
|
150
|
-
* tryFindIdentifier('myBuffer'); // 'myBuffer'
|
|
151
|
-
* tryFindIdentifier('buffers.myBuffer'); // 'myBuffer'
|
|
152
|
-
* tryFindIdentifier('this.myBuffer'); // 'myBuffer'
|
|
153
|
-
* tryFindIdentifier('[a, b]'); // undefined
|
|
154
|
-
*/
|
|
155
|
-
function tryFindIdentifier(node) {
|
|
156
|
-
if (node.type === "Identifier") return node.name;
|
|
157
|
-
if (node.type === "PrivateName") return tryFindIdentifier(node.id);
|
|
158
|
-
if (node.type === "PrivateIdentifier") return node.name;
|
|
159
|
-
if (node.type === "MemberExpression") return tryFindIdentifier(node.property);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Checks if `node` contains a label and a tgpu expression that could be named.
|
|
163
|
-
* If so, it calls the provided callback. Nodes selected for naming include:
|
|
164
|
-
*
|
|
165
|
-
* `let name = tgpu.bindGroupLayout({});` (VariableDeclarator)
|
|
166
|
-
*
|
|
167
|
-
* `name = tgpu.bindGroupLayout({});` (AssignmentExpression)
|
|
168
|
-
*
|
|
169
|
-
* `property: tgpu.bindGroupLayout({})` (Property/ObjectProperty)
|
|
170
|
-
*
|
|
171
|
-
* Since it is mostly for debugging and clean WGSL generation,
|
|
172
|
-
* some false positives and false negatives are admissible.
|
|
173
|
-
*
|
|
174
|
-
* This function is NOT used for auto-naming shell-less functions.
|
|
175
|
-
* Those are handled separately.
|
|
176
|
-
*
|
|
177
|
-
* @privateRemarks
|
|
178
|
-
* When adding new checks, you need to call this method in the corresponding node in Babel.
|
|
179
|
-
*/
|
|
180
|
-
function performExpressionNaming(ctx, node, namingCallback) {
|
|
181
|
-
if (!ctx.autoNamingEnabled) return;
|
|
182
|
-
const labelledExpression = extractLabelledExpression(node);
|
|
183
|
-
if (labelledExpression) {
|
|
184
|
-
const [label, expression] = labelledExpression;
|
|
185
|
-
if (containsResourceConstructorCall(expression, ctx)) namingCallback(expression, label);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
const useGpuDirective = "use gpu";
|
|
189
|
-
/** Regular expressions used for early pruning (to avoid unnecessary parsing, which is expensive) */
|
|
190
|
-
const earlyPruneRegex = [/["']use gpu["']/, /t(ype)?gpu/];
|
|
191
|
-
const operators = {
|
|
192
|
-
"+": "__tsover_add",
|
|
193
|
-
"-": "__tsover_sub",
|
|
194
|
-
"*": "__tsover_mul",
|
|
195
|
-
"/": "__tsover_div",
|
|
196
|
-
"%": "__tsover_mod",
|
|
197
|
-
"+=": "__tsover_add",
|
|
198
|
-
"-=": "__tsover_sub",
|
|
199
|
-
"*=": "__tsover_mul",
|
|
200
|
-
"/=": "__tsover_div",
|
|
201
|
-
"%=": "__tsover_mod"
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
//#endregion
|
|
205
|
-
//#region src/filter.ts
|
|
206
|
-
function toArray(array) {
|
|
207
|
-
const result = array || [];
|
|
208
|
-
if (Array.isArray(result)) return result;
|
|
209
|
-
return [result];
|
|
210
|
-
}
|
|
211
|
-
const BACKSLASH_REGEX = /\\/g;
|
|
212
|
-
function normalize(path) {
|
|
213
|
-
return path.replace(BACKSLASH_REGEX, "/");
|
|
214
|
-
}
|
|
215
|
-
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
|
216
|
-
function isAbsolute(path) {
|
|
217
|
-
return ABSOLUTE_PATH_REGEX.test(path);
|
|
218
|
-
}
|
|
219
|
-
function getMatcherString(glob, cwd) {
|
|
220
|
-
if (glob.startsWith("**") || isAbsolute(glob)) return normalize(glob);
|
|
221
|
-
return normalize((0, pathe.resolve)(cwd, glob));
|
|
222
|
-
}
|
|
223
|
-
function patternToIdFilter(pattern) {
|
|
224
|
-
if (pattern instanceof RegExp) return (id) => {
|
|
225
|
-
const normalizedId = normalize(id);
|
|
226
|
-
const result = pattern.test(normalizedId);
|
|
227
|
-
pattern.lastIndex = 0;
|
|
228
|
-
return result;
|
|
229
|
-
};
|
|
230
|
-
const matcher = (0, picomatch.default)(getMatcherString(pattern, process.cwd()), { dot: true });
|
|
231
|
-
return (id) => {
|
|
232
|
-
return matcher(normalize(id));
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
function createFilter(exclude, include) {
|
|
236
|
-
if (!exclude && !include) return;
|
|
237
|
-
return (input) => {
|
|
238
|
-
if (exclude === null || exclude === void 0 ? void 0 : exclude.some((filter) => filter(input))) return false;
|
|
239
|
-
if (include === null || include === void 0 ? void 0 : include.some((filter) => filter(input))) return true;
|
|
240
|
-
return !(include && include.length > 0);
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
function normalizeFilter(filter) {
|
|
244
|
-
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
|
245
|
-
if (Array.isArray(filter)) return { include: filter };
|
|
246
|
-
return {
|
|
247
|
-
exclude: filter.exclude ? toArray(filter.exclude) : void 0,
|
|
248
|
-
include: filter.include ? toArray(filter.include) : void 0
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
function createIdFilter(filter) {
|
|
252
|
-
if (!filter) return;
|
|
253
|
-
const { exclude, include } = normalizeFilter(filter);
|
|
254
|
-
return createFilter(exclude === null || exclude === void 0 ? void 0 : exclude.map(patternToIdFilter), include === null || include === void 0 ? void 0 : include.map(patternToIdFilter));
|
|
255
|
-
}
|
|
256
|
-
function createFilterForId(filter) {
|
|
257
|
-
const filterFunction = createIdFilter(filter);
|
|
258
|
-
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
//#endregion
|
|
262
|
-
Object.defineProperty(exports, '__toESM', {
|
|
263
|
-
enumerable: true,
|
|
264
|
-
get: function () {
|
|
265
|
-
return __toESM;
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
Object.defineProperty(exports, 'createFilterForId', {
|
|
269
|
-
enumerable: true,
|
|
270
|
-
get: function () {
|
|
271
|
-
return createFilterForId;
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
Object.defineProperty(exports, 'defaultOptions', {
|
|
275
|
-
enumerable: true,
|
|
276
|
-
get: function () {
|
|
277
|
-
return defaultOptions;
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
Object.defineProperty(exports, 'earlyPruneRegex', {
|
|
281
|
-
enumerable: true,
|
|
282
|
-
get: function () {
|
|
283
|
-
return earlyPruneRegex;
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
Object.defineProperty(exports, 'embedJSON', {
|
|
287
|
-
enumerable: true,
|
|
288
|
-
get: function () {
|
|
289
|
-
return embedJSON;
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
Object.defineProperty(exports, 'gatherTgpuAliases', {
|
|
293
|
-
enumerable: true,
|
|
294
|
-
get: function () {
|
|
295
|
-
return gatherTgpuAliases;
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
Object.defineProperty(exports, 'getFunctionName', {
|
|
299
|
-
enumerable: true,
|
|
300
|
-
get: function () {
|
|
301
|
-
return getFunctionName;
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
Object.defineProperty(exports, 'isShellImplementationCall', {
|
|
305
|
-
enumerable: true,
|
|
306
|
-
get: function () {
|
|
307
|
-
return isShellImplementationCall;
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
Object.defineProperty(exports, 'operators', {
|
|
311
|
-
enumerable: true,
|
|
312
|
-
get: function () {
|
|
313
|
-
return operators;
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
Object.defineProperty(exports, 'performExpressionNaming', {
|
|
317
|
-
enumerable: true,
|
|
318
|
-
get: function () {
|
|
319
|
-
return performExpressionNaming;
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
Object.defineProperty(exports, 'useGpuDirective', {
|
|
323
|
-
enumerable: true,
|
|
324
|
-
get: function () {
|
|
325
|
-
return useGpuDirective;
|
|
326
|
-
}
|
|
327
|
-
});
|