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/rollup-impl.cjs
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
const require_common = require('./common.cjs');
|
|
3
|
-
let defu = require("defu");
|
|
4
|
-
defu = require_runtime.__toESM(defu);
|
|
5
|
-
let magic_string_ast = require("magic-string-ast");
|
|
6
|
-
let estree_walker = require("estree-walker");
|
|
7
|
-
let tinyest_for_wgsl = require("tinyest-for-wgsl");
|
|
8
|
-
let tinyest = require("tinyest");
|
|
9
|
-
|
|
10
|
-
//#region src/rollup-impl.ts
|
|
11
|
-
function containsUseGpuDirective(node) {
|
|
12
|
-
if (node.body.type === "BlockStatement") {
|
|
13
|
-
for (const statement of node.body.body) if (statement.type === "ExpressionStatement" && statement.directive === require_common.useGpuDirective) return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
function removeUseGpuDirective(node) {
|
|
18
|
-
const cloned = structuredClone(node);
|
|
19
|
-
if (cloned.body.type === "BlockStatement") cloned.body.body = cloned.body.body.filter((statement) => !(statement.type === "ExpressionStatement" && statement.directive === require_common.useGpuDirective));
|
|
20
|
-
return cloned;
|
|
21
|
-
}
|
|
22
|
-
function assignMetadata(magicString, node, metadata) {
|
|
23
|
-
magicString.prependLeft(node.start, "(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(node.end, `), ${metadata}) && $.f)({}))`);
|
|
24
|
-
}
|
|
25
|
-
function wrapInAutoName(magicString, node, name) {
|
|
26
|
-
magicString.prependLeft(node.start, "((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(node.end, `, "${name}"))`);
|
|
27
|
-
}
|
|
28
|
-
const rollUpImpl = (rawOptions) => {
|
|
29
|
-
const options = (0, defu.default)(rawOptions, require_common.defaultOptions);
|
|
30
|
-
return {
|
|
31
|
-
name: "unplugin-typegpu",
|
|
32
|
-
enforce: options.enforce,
|
|
33
|
-
transform: {
|
|
34
|
-
filter: options.earlyPruning ? {
|
|
35
|
-
id: options,
|
|
36
|
-
code: require_common.earlyPruneRegex
|
|
37
|
-
} : { id: options },
|
|
38
|
-
handler(code, id) {
|
|
39
|
-
const ctx = {
|
|
40
|
-
tgpuAliases: new Set(options.forceTgpuAlias ? [options.forceTgpuAlias] : []),
|
|
41
|
-
fileId: id,
|
|
42
|
-
autoNamingEnabled: options.autoNamingEnabled
|
|
43
|
-
};
|
|
44
|
-
let ast;
|
|
45
|
-
try {
|
|
46
|
-
ast = this.parse(code, {
|
|
47
|
-
lang: "ts",
|
|
48
|
-
allowReturnOutsideFunction: true
|
|
49
|
-
});
|
|
50
|
-
} catch (cause) {
|
|
51
|
-
console.warn(`[unplugin-typegpu] Failed to parse ${id}. Cause: ${typeof cause === "object" && cause && "message" in cause ? cause.message : cause}`);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const tgslFunctionDefs = [];
|
|
55
|
-
const magicString = new magic_string_ast.MagicStringAST(code);
|
|
56
|
-
(0, estree_walker.walk)(ast, { enter(_node, _parent) {
|
|
57
|
-
const node = _node;
|
|
58
|
-
const parent = _parent;
|
|
59
|
-
require_common.performExpressionNaming(ctx, node, (node, name) => {
|
|
60
|
-
wrapInAutoName(magicString, node, name);
|
|
61
|
-
});
|
|
62
|
-
if (node.type === "ImportDeclaration") require_common.gatherTgpuAliases(node, ctx);
|
|
63
|
-
if (node.type === "CallExpression") {
|
|
64
|
-
if (require_common.isShellImplementationCall(node, ctx)) {
|
|
65
|
-
const implementation = node.arguments[0];
|
|
66
|
-
if (implementation && (implementation.type === "FunctionExpression" || implementation.type === "ArrowFunctionExpression")) {
|
|
67
|
-
tgslFunctionDefs.push({ def: removeUseGpuDirective(implementation) });
|
|
68
|
-
this.skip();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
|
|
73
|
-
if (containsUseGpuDirective(node)) {
|
|
74
|
-
tgslFunctionDefs.push({
|
|
75
|
-
def: removeUseGpuDirective(node),
|
|
76
|
-
name: require_common.getFunctionName(node, parent)
|
|
77
|
-
});
|
|
78
|
-
this.skip();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
} });
|
|
82
|
-
for (const { def, name } of tgslFunctionDefs) {
|
|
83
|
-
const { params, body, externalNames } = (0, tinyest_for_wgsl.transpileFn)(def);
|
|
84
|
-
const isFunctionStatement = def.type === "FunctionDeclaration";
|
|
85
|
-
(0, estree_walker.walk)(def, { leave(_node) {
|
|
86
|
-
const node = _node;
|
|
87
|
-
if (node.type === "AssignmentExpression") {
|
|
88
|
-
const runtimeFn = require_common.operators[node.operator];
|
|
89
|
-
if (runtimeFn) {
|
|
90
|
-
const left = node.left;
|
|
91
|
-
const right = node.right;
|
|
92
|
-
const lhs = magicString.sliceNode(left);
|
|
93
|
-
const rhs = magicString.sliceNode(right);
|
|
94
|
-
magicString.overwriteNode(node, `${lhs} = ${runtimeFn}(${lhs}, ${rhs})`);
|
|
95
|
-
}
|
|
96
|
-
} else if (node.type === "BinaryExpression") {
|
|
97
|
-
const runtimeFn = require_common.operators[node.operator];
|
|
98
|
-
if (runtimeFn) {
|
|
99
|
-
const left = node.left;
|
|
100
|
-
const right = node.right;
|
|
101
|
-
const lhs = magicString.sliceNode(left);
|
|
102
|
-
const rhs = magicString.sliceNode(right);
|
|
103
|
-
magicString.overwriteNode(node, `${runtimeFn}(${lhs}, ${rhs})`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} });
|
|
107
|
-
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.`);
|
|
108
|
-
assignMetadata(magicString, def, `{
|
|
109
|
-
v: ${tinyest.FORMAT_VERSION},
|
|
110
|
-
name: ${name ? `"${name}"` : "undefined"},
|
|
111
|
-
ast: ${require_common.embedJSON({
|
|
112
|
-
params,
|
|
113
|
-
body,
|
|
114
|
-
externalNames
|
|
115
|
-
})},
|
|
116
|
-
externals: () => ({${externalNames.map((e) => e === "this" ? "\"this\": this" : e).join(", ")}}),
|
|
117
|
-
}`);
|
|
118
|
-
if (isFunctionStatement && name) magicString.prependLeft(def.start, `const ${name} = `);
|
|
119
|
-
}
|
|
120
|
-
return (0, magic_string_ast.generateTransform)(magicString, id);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
//#endregion
|
|
127
|
-
exports.rollUpImpl = rollUpImpl;
|
package/rollup-impl.d.cts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Options } from "./common.cjs";
|
|
2
|
-
import * as unplugin from "unplugin";
|
|
3
|
-
import { UnpluginBuildContext, UnpluginContext } from "unplugin";
|
|
4
|
-
import * as magic_string_ast0 from "magic-string-ast";
|
|
5
|
-
|
|
6
|
-
//#region src/rollup-impl.d.ts
|
|
7
|
-
declare const rollUpImpl: (rawOptions: Options) => {
|
|
8
|
-
name: "unplugin-typegpu";
|
|
9
|
-
enforce: "post" | "pre" | undefined;
|
|
10
|
-
transform: {
|
|
11
|
-
filter: {
|
|
12
|
-
id: Omit<Options, "include" | "autoNamingEnabled" | "earlyPruning"> & Omit<{
|
|
13
|
-
include: RegExp;
|
|
14
|
-
autoNamingEnabled: boolean;
|
|
15
|
-
earlyPruning: boolean;
|
|
16
|
-
}, "include" | "autoNamingEnabled" | "earlyPruning"> & {
|
|
17
|
-
include: string | RegExp | unplugin.StringOrRegExp[];
|
|
18
|
-
autoNamingEnabled: boolean;
|
|
19
|
-
earlyPruning: boolean;
|
|
20
|
-
};
|
|
21
|
-
code: RegExp[];
|
|
22
|
-
} | {
|
|
23
|
-
id: Omit<Options, "include" | "autoNamingEnabled" | "earlyPruning"> & Omit<{
|
|
24
|
-
include: RegExp;
|
|
25
|
-
autoNamingEnabled: boolean;
|
|
26
|
-
earlyPruning: boolean;
|
|
27
|
-
}, "include" | "autoNamingEnabled" | "earlyPruning"> & {
|
|
28
|
-
include: string | RegExp | unplugin.StringOrRegExp[];
|
|
29
|
-
autoNamingEnabled: boolean;
|
|
30
|
-
earlyPruning: boolean;
|
|
31
|
-
};
|
|
32
|
-
code?: never;
|
|
33
|
-
};
|
|
34
|
-
handler(this: UnpluginBuildContext & UnpluginContext, code: string, id: string): magic_string_ast0.CodeTransform | undefined;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
//#endregion
|
|
38
|
-
export { rollUpImpl };
|
package/rollup-impl.d.mts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Options } from "./common.mjs";
|
|
2
|
-
import * as unplugin from "unplugin";
|
|
3
|
-
import { UnpluginBuildContext, UnpluginContext } from "unplugin";
|
|
4
|
-
import * as magic_string_ast0 from "magic-string-ast";
|
|
5
|
-
import { MagicStringAST } from "magic-string-ast";
|
|
6
|
-
|
|
7
|
-
//#region src/rollup-impl.d.ts
|
|
8
|
-
declare const rollUpImpl: (rawOptions: Options) => {
|
|
9
|
-
name: "unplugin-typegpu";
|
|
10
|
-
enforce: "post" | "pre" | undefined;
|
|
11
|
-
transform: {
|
|
12
|
-
filter: {
|
|
13
|
-
id: Omit<Options, "include" | "autoNamingEnabled" | "earlyPruning"> & Omit<{
|
|
14
|
-
include: RegExp;
|
|
15
|
-
autoNamingEnabled: boolean;
|
|
16
|
-
earlyPruning: boolean;
|
|
17
|
-
}, "include" | "autoNamingEnabled" | "earlyPruning"> & {
|
|
18
|
-
include: string | RegExp | unplugin.StringOrRegExp[];
|
|
19
|
-
autoNamingEnabled: boolean;
|
|
20
|
-
earlyPruning: boolean;
|
|
21
|
-
};
|
|
22
|
-
code: RegExp[];
|
|
23
|
-
} | {
|
|
24
|
-
id: Omit<Options, "include" | "autoNamingEnabled" | "earlyPruning"> & Omit<{
|
|
25
|
-
include: RegExp;
|
|
26
|
-
autoNamingEnabled: boolean;
|
|
27
|
-
earlyPruning: boolean;
|
|
28
|
-
}, "include" | "autoNamingEnabled" | "earlyPruning"> & {
|
|
29
|
-
include: string | RegExp | unplugin.StringOrRegExp[];
|
|
30
|
-
autoNamingEnabled: boolean;
|
|
31
|
-
earlyPruning: boolean;
|
|
32
|
-
};
|
|
33
|
-
code?: never;
|
|
34
|
-
};
|
|
35
|
-
handler(this: UnpluginBuildContext & UnpluginContext, code: string, id: string): magic_string_ast0.CodeTransform | undefined;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
//#endregion
|
|
39
|
-
export { rollUpImpl };
|
package/rollup-impl.mjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { defaultOptions, earlyPruneRegex, embedJSON, gatherTgpuAliases, getFunctionName, isShellImplementationCall, operators, performExpressionNaming, useGpuDirective } from "./common.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
|
-
export { rollUpImpl };
|