diff --git a/packages/typegpu/tests/internal/autoname.test.ts b/packages/typegpu/tests/internal/autoname.test.ts index de3b55d8cc..d66680aa95 100644 --- a/packages/typegpu/tests/internal/autoname.test.ts +++ b/packages/typegpu/tests/internal/autoname.test.ts @@ -195,7 +195,7 @@ describe('autonaming', () => { expect(scope.toString()).toMatchInlineSnapshot(` "() => { const myFun = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function myFun() { - "use gpu"; + return 0; }), { v: 1, diff --git a/packages/unplugin-typegpu/src/babel.ts b/packages/unplugin-typegpu/src/babel.ts index 371323aba7..ae10acab24 100644 --- a/packages/unplugin-typegpu/src/babel.ts +++ b/packages/unplugin-typegpu/src/babel.ts @@ -4,6 +4,7 @@ import { transpileFn } from 'tinyest-for-wgsl'; import * as t from '@babel/types'; import { METADATA_FORMAT_VERSION, + type MetadatableFunction, type PluginState, defaultOptions, functionVisitor, @@ -101,7 +102,6 @@ function assignMetadata( if (visibility) { // Hoisting the declaration to the top of the scope visibility.unshiftContainer('body', replacement as t.Statement); - this.alreadyTransformed.add(expression); const id = t.isFunctionDeclaration(path.node) ? path.node.id : undefined; if (id && path.parentPath.isExportNamedDeclaration()) { @@ -148,6 +148,12 @@ function replaceWithAssignmentOverload( ); } +function removeUseGpuDirective(this: PluginState, path: NodePath) { + const directives = path.get('body').get('directives'); + const maybeUseGpu = directives.find((directive) => directive.node.value.value === 'use gpu'); + maybeUseGpu?.remove(); +} + function replaceWithBinaryOverload(path: NodePath, runtimeFn: string): void { path.replaceWith( t.callExpression(i(runtimeFn), [path.node.left as t.Expression, path.node.right]), @@ -165,6 +171,7 @@ export default function TypeGPUPlugin() { wrapInAutoName, replaceWithAssignmentOverload, replaceWithBinaryOverload, + removeUseGpuDirective, }); }, visitor: { diff --git a/packages/unplugin-typegpu/src/core/common.ts b/packages/unplugin-typegpu/src/core/common.ts index 2a2de42f9d..696e5ed996 100644 --- a/packages/unplugin-typegpu/src/core/common.ts +++ b/packages/unplugin-typegpu/src/core/common.ts @@ -85,6 +85,8 @@ export interface TransformMethods { replaceWithAssignmentOverload(path: NodePath, runtimeFn: string): void; replaceWithBinaryOverload(path: NodePath, runtimeFn: string): void; + + removeUseGpuDirective(this: PluginState, path: NodePath): void; } export interface PluginState extends TransformMethods { @@ -107,8 +109,6 @@ export interface PluginState extends TransformMethods { opts: Options; inUseGpuScope: boolean; - - alreadyTransformed: WeakSet; } export interface NodeLocation { @@ -127,7 +127,6 @@ export function initPluginState(state: PluginState, methods: TransformMethods): state.tgpuAliases = new Set(state.opts.forceTgpuAlias ? [state.opts.forceTgpuAlias] : []); state.autoNamingEnabled = state.opts.autoNamingEnabled ?? true; state.inUseGpuScope = false; - state.alreadyTransformed = new WeakSet(); Object.assign(state, methods); } @@ -450,20 +449,16 @@ function functionOnExit( if (!containsUseGpuDirective(node)) { return; } + state.removeUseGpuDirective(path); state.inUseGpuScope = false; - if (state.alreadyTransformed.has(node)) { - return; - } - const ast = fnNodeToTranspiledMap.get(path.node); const maybeName = getFunctionName(path); if (!ast) { throw new Error(`No metadata found for function ${maybeName ?? ''}`); } state.assignMetadata(path, maybeName, ast); - state.alreadyTransformed.add(node); path.skip(); } diff --git a/packages/unplugin-typegpu/src/core/factory.ts b/packages/unplugin-typegpu/src/core/factory.ts index 3005352573..27e1d11401 100644 --- a/packages/unplugin-typegpu/src/core/factory.ts +++ b/packages/unplugin-typegpu/src/core/factory.ts @@ -127,6 +127,15 @@ function replaceWithBinaryOverload( this.overwrite(path.node, `${runtimeFn}(${lhs}, ${rhs})`); } +function removeUseGpuDirective(this: UnpluginPluginState, path: NodePath) { + const directives = 'directives' in path.node.body ? (path.node.body?.directives ?? []) : []; + for (const directive of directives) { + if (directive.value.value === 'use gpu') { + this.remove(directive); + } + } +} + const NodeUtils = { slice(this: UnpluginPluginState, node: NodeLocation): string { return this.magicString.slice(node.start ?? 0, node.end ?? 0); @@ -188,6 +197,7 @@ export const unpluginFactory = ((rawOptions, _meta) => { wrapInAutoName, replaceWithAssignmentOverload, replaceWithBinaryOverload, + removeUseGpuDirective, }); traverse(ast, functionVisitor, undefined, state); diff --git a/packages/unplugin-typegpu/test/auto-naming.test.ts b/packages/unplugin-typegpu/test/auto-naming.test.ts index 9c1fc89193..880e335f42 100644 --- a/packages/unplugin-typegpu/test/auto-naming.test.ts +++ b/packages/unplugin-typegpu/test/auto-naming.test.ts @@ -327,8 +327,6 @@ describe('[BABEL] auto naming', () => { expect(babelTransform(code, { autoNamingEnabled: true })).toMatchInlineSnapshot(` "const myFun3 = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function myFun3() { - 'use gpu'; - return 0; }, { v: 1, @@ -343,8 +341,6 @@ describe('[BABEL] auto naming', () => { } }) && $.f)({}); const myFun1 = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => { - 'use gpu'; - return 0; }, { v: 1, @@ -359,8 +355,6 @@ describe('[BABEL] auto naming', () => { } }) && $.f)({}); const myFun2 = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function () { - 'use gpu'; - return 0; }, { v: 1, @@ -510,9 +504,7 @@ describe('[BABEL] auto naming', () => { expect(babelTransform(code, { autoNamingEnabled: true })).toMatchInlineSnapshot(` "import { tgpu } from 'typegpu'; const root = await tgpu.init(); - const myGuardedPipeline = /*#__PURE__*/(globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(root.createGuardedComputePipeline(/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => { - 'use gpu'; - }, { + const myGuardedPipeline = /*#__PURE__*/(globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(root.createGuardedComputePipeline(/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => {}, { v: 1, name: undefined, ast: { @@ -524,9 +516,7 @@ describe('[BABEL] auto naming', () => { return {}; } }) && $.f)({})), "myGuardedPipeline"); - const anotherGuardedPipeline = /*#__PURE__*/(globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(root.createGuardedComputePipeline(/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => { - 'use gpu'; - }, { + const anotherGuardedPipeline = /*#__PURE__*/(globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(root.createGuardedComputePipeline(/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => {}, { v: 1, name: undefined, ast: { @@ -829,7 +819,7 @@ describe('[ROLLUP] auto naming', () => { expect(await rollupTransform(code, { autoNamingEnabled: true })).toMatchInlineSnapshot(` "const myFun3 = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function myFun3() { - 'use gpu'; + return 0; }), { v: 1, @@ -839,7 +829,7 @@ describe('[ROLLUP] auto naming', () => { }) && $.f)({})); const myFun1 = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (() => { - 'use gpu'; + return 0; }), { v: 1, @@ -849,7 +839,7 @@ describe('[ROLLUP] auto naming', () => { }) && $.f)({})); const myFun2 = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function () { - 'use gpu'; + return 0; }), { v: 1, @@ -1027,7 +1017,7 @@ describe('[ROLLUP] auto naming', () => { const root = await tgpu.init(); const myGuardedPipeline = (/*#__PURE__*/(globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(root.createGuardedComputePipeline((/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (() => { - 'use gpu'; + }), { v: 1, name: undefined, @@ -1037,7 +1027,7 @@ describe('[ROLLUP] auto naming', () => { const anotherGuardedPipeline = (/*#__PURE__*/(globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(root .createGuardedComputePipeline((/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (() => { - 'use gpu'; + }), { v: 1, name: undefined, diff --git a/packages/unplugin-typegpu/test/typescript-syntax.test.ts b/packages/unplugin-typegpu/test/typescript-syntax.test.ts index b6af6fbff9..d539afa3cb 100644 --- a/packages/unplugin-typegpu/test/typescript-syntax.test.ts +++ b/packages/unplugin-typegpu/test/typescript-syntax.test.ts @@ -14,8 +14,6 @@ describe('as type', () => { expect(babelTransform(code)).toMatchInlineSnapshot(` "const hello = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (a: number, b: number | undefined) => { - 'use gpu'; - return __tsover_add(a, b as number); }, { v: 1, diff --git a/packages/unplugin-typegpu/test/use-gpu-directive.test.ts b/packages/unplugin-typegpu/test/use-gpu-directive.test.ts index 9e8dea4ea2..db39d007cd 100644 --- a/packages/unplugin-typegpu/test/use-gpu-directive.test.ts +++ b/packages/unplugin-typegpu/test/use-gpu-directive.test.ts @@ -1,6 +1,152 @@ import { describe, expect, test } from 'vitest'; import { babelTransform, rollupTransform } from './transform.ts'; +describe('"use gpu" is removed after transform', () => { + const code = `\ + const fn1 = () => { + 'use gpu'; + }; + + const fn2 = () => { + 'use gpu'; + 'worklet'; + }; + + const fn3 = () => { + 'worklet'; + 'use gpu'; + }; + + console.log(fn1, fn2, fn3); + `; + + test('babel', () => { + expect(babelTransform(code)).toMatchInlineSnapshot(` + "const fn1 = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => {}, { + v: 1, + name: "fn1", + ast: { + params: [], + body: [0, []], + externalNames: [] + }, + externals: () => { + return {}; + } + }) && $.f)({}); + const fn2 = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => { + 'worklet'; + }, { + v: 1, + name: "fn2", + ast: { + params: [], + body: [0, []], + externalNames: [] + }, + externals: () => { + return {}; + } + }) && $.f)({}); + const fn3 = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => { + 'worklet'; + }, { + v: 1, + name: "fn3", + ast: { + params: [], + body: [0, []], + externalNames: [] + }, + externals: () => { + return {}; + } + }) && $.f)({}); + console.log(fn1, fn2, fn3);" + `); + }); + + test('rollup', async () => { + expect(await rollupTransform(code)).toMatchInlineSnapshot(` + "const fn1 = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (() => { + + }), { + v: 1, + name: "fn1", + ast: {"params":[],"body":[0,[]],"externalNames":[]}, + externals: () => ({}), + }) && $.f)({})); + + const fn2 = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (() => { + + 'worklet'; + }), { + v: 1, + name: "fn2", + ast: {"params":[],"body":[0,[]],"externalNames":[]}, + externals: () => ({}), + }) && $.f)({})); + + const fn3 = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (() => { + 'worklet'; + + }), { + v: 1, + name: "fn3", + ast: {"params":[],"body":[0,[]],"externalNames":[]}, + externals: () => ({}), + }) && $.f)({})); + + console.log(fn1, fn2, fn3); + " + `); + }); +}); + +describe('double transformation', () => { + const code = `\ + const fn = () => { + 'use gpu'; + }; + + console.log(fn); + `; + + test('babel', () => { + expect(babelTransform(babelTransform(code) ?? '')).toMatchInlineSnapshot(` + "const fn = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = () => {}, { + v: 1, + name: "fn", + ast: { + params: [], + body: [0, []], + externalNames: [] + }, + externals: () => { + return {}; + } + }) && $.f)({}); + console.log(fn);" + `); + }); + + test('rollup', async () => { + expect(await rollupTransform(await rollupTransform(code))).toMatchInlineSnapshot(` + "const fn = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (() => { + + }), { + v: 1, + name: "fn", + ast: {"params":[],"body":[0,[]],"externalNames":[]}, + externals: () => ({}), + }) && $.f)({})); + + console.log(fn); + " + `); + }); +}); + describe('"use gpu" marked arrow function, assigned to a const', () => { const code = `\ /** ADD */ @@ -22,8 +168,6 @@ describe('"use gpu" marked arrow function, assigned to a const', () => { "/** ADD */ // another comment const addGPU = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (a, b) => { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -55,7 +199,7 @@ describe('"use gpu" marked arrow function, assigned to a const', () => { "/** ADD */ // another comment const addGPU = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((a, b) => { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -95,8 +239,6 @@ describe('marked arrow functions passed to shells', () => { "import { tgpu } from 'typegpu'; const shell = tgpu.fn([]); shell(/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (a, b) => { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -129,7 +271,7 @@ describe('marked arrow functions passed to shells', () => { const shell = tgpu.fn([]); shell((/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((a, b) => { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -167,8 +309,6 @@ describe('marked anonymous function expressions passed to shells', () => { "import { tgpu } from 'typegpu'; const shell = tgpu.fn([]); shell(/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function (a, b) { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -201,7 +341,7 @@ describe('marked anonymous function expressions passed to shells', () => { const shell = tgpu.fn([]); shell((/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function(a, b){ - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -239,8 +379,6 @@ describe('marked named function expressions passed to shells', () => { "import { tgpu } from 'typegpu'; const shell = tgpu.fn([]); shell(/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function addGPU(a, b) { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -273,7 +411,7 @@ describe('marked named function expressions passed to shells', () => { const shell = tgpu.fn([]); shell((/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function addGPU(a, b){ - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -311,8 +449,6 @@ describe('marked function statements', () => { expect(babelTransform(code)).toMatchInlineSnapshot(` "/** ADD */ const addGPU = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function addGPU(a, b) { - 'use gpu'; - // hello there return __tsover_add(a, b); }, { @@ -344,7 +480,7 @@ describe('marked function statements', () => { expect(await rollupTransform(code)).toMatchInlineSnapshot(` "/** ADD */ const addGPU = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function addGPU(a, b) { - 'use gpu'; + // hello there return __tsover_add(a, b); }), { @@ -400,8 +536,6 @@ describe('marked object methods', () => { "const obj = { /** MOD */ mod: /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (a, b) => { - 'use gpu'; - return __tsover_mod(a, b); }, { v: 1, @@ -425,8 +559,6 @@ describe('marked object methods', () => { /** PRIME */ const isPrime = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = n => { - 'use gpu'; - if (n <= 1) { return false; } @@ -462,7 +594,7 @@ describe('marked object methods', () => { "const obj = { /** MOD */ mod: (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((a, b) => { - 'use gpu'; + return __tsover_mod(a, b); }), { v: 1, @@ -474,7 +606,7 @@ describe('marked object methods', () => { /** PRIME */ const isPrime = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((n) => { - 'use gpu'; + if (n <= 1) { return false; } @@ -526,8 +658,6 @@ describe('transforms numeric operations', () => { /** the main function */ // another comment const main = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (a, b) => { - 'use gpu'; - let c = __tsover_add(__tsover_add(a, b), 2); c = __tsover_add(c, __tsover_mul(2, b)); countMutable.$ = __tsover_add(countMutable.$, 3); @@ -565,7 +695,7 @@ describe('transforms numeric operations', () => { /** the main function */ // another comment const main = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((a, b) => { - 'use gpu'; + let c = __tsover_add(__tsover_add(a, b), 2); c = __tsover_add(c, __tsover_mul(2, b)); countMutable.$ = __tsover_add(countMutable.$, 3); @@ -607,8 +737,6 @@ describe('hoists global function statements marked with "use gpu"', () => { "/** MUL */ // another comment const mul = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function mul(a, b) { - 'use gpu'; - return __tsover_mul(a, b); }, { v: 1, @@ -631,8 +759,6 @@ describe('hoists global function statements marked with "use gpu"', () => { /** ADD */ // another comment const add = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function add(a, b) { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -661,7 +787,7 @@ describe('hoists global function statements marked with "use gpu"', () => { "/** MUL */ // another comment const mul = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function mul(a, b) { - 'use gpu'; + return __tsover_mul(a, b); }), { v: 1, @@ -673,7 +799,7 @@ describe('hoists global function statements marked with "use gpu"', () => { /** ADD */ // another comment const add = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function add(a, b) { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -715,8 +841,6 @@ describe('hoists function statements marked with "use gpu", scoped inside anothe /** MUL */ // another comment const mul = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function mul(a, b) { - 'use gpu'; - return __tsover_mul(a, b); }, { v: 1, @@ -739,8 +863,6 @@ describe('hoists function statements marked with "use gpu", scoped inside anothe /** ADD */ // another comment const add = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function add(a, b) { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -771,7 +893,7 @@ describe('hoists function statements marked with "use gpu", scoped inside anothe /** MUL */ // another comment const mul = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function mul(a, b) { - 'use gpu'; + return __tsover_mul(a, b); }), { v: 1, @@ -783,7 +905,7 @@ describe('hoists function statements marked with "use gpu", scoped inside anothe /** ADD */ // another comment const add = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function add(a, b) { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -836,8 +958,6 @@ describe('hoists function statements marked with "use gpu", scoped inside an arr /** MUL */ // another comment const mul = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function mul(a, b) { - 'use gpu'; - return __tsover_mul(a, b); }, { v: 1, @@ -860,8 +980,6 @@ describe('hoists function statements marked with "use gpu", scoped inside an arr /** ADD */ // another comment const add = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function add(a, b) { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -892,7 +1010,7 @@ describe('hoists function statements marked with "use gpu", scoped inside an arr /** MUL */ // another comment const mul = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function mul(a, b) { - 'use gpu'; + return __tsover_mul(a, b); }), { v: 1, @@ -904,7 +1022,7 @@ describe('hoists function statements marked with "use gpu", scoped inside an arr /** ADD */ // another comment const add = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function add(a, b) { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -959,8 +1077,6 @@ describe('hoists function statements marked with "use gpu", scoped inside an if /** MUL */ // another comment const mul = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function mul(a, b) { - 'use gpu'; - return __tsover_mul(__tsover_mul(a, b), c); }, { v: 1, @@ -985,8 +1101,6 @@ describe('hoists function statements marked with "use gpu", scoped inside an if /** ADD */ // another comment const add = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function add(a, b) { - 'use gpu'; - return __tsover_add(__tsover_add(a, b), c); }, { v: 1, @@ -1020,7 +1134,7 @@ describe('hoists function statements marked with "use gpu", scoped inside an if /** MUL */ // another comment const mul = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function mul(a, b) { - 'use gpu'; + return __tsover_mul(__tsover_mul(a, b), c); }), { v: 1, @@ -1032,7 +1146,7 @@ describe('hoists function statements marked with "use gpu", scoped inside an if /** ADD */ // another comment const add = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function add(a, b) { - 'use gpu'; + return __tsover_add(__tsover_add(a, b), c); }), { v: 1, @@ -1091,8 +1205,6 @@ describe('replaces function statements marked with "use gpu" in place when condi /** ADD */ // another comment const add = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function add(a, b) { - 'use gpu'; - return __tsover_add(__tsover_add(a, b), c); }, { v: 1, @@ -1119,8 +1231,6 @@ describe('replaces function statements marked with "use gpu" in place when condi /** MUL */ // another comment const mul = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function mul(a, b) { - 'use gpu'; - return __tsover_mul(__tsover_mul(a, b), c); }, { v: 1, @@ -1157,7 +1267,7 @@ describe('replaces function statements marked with "use gpu" in place when condi /** ADD */ // another comment const add = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function add(a, b) { - 'use gpu'; + return __tsover_add(__tsover_add(a, b), c); }), { v: 1, @@ -1172,7 +1282,7 @@ describe('replaces function statements marked with "use gpu" in place when condi /** MUL */ // another comment const mul = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function mul(a, b) { - 'use gpu'; + return __tsover_mul(__tsover_mul(a, b), c); }), { v: 1, @@ -1211,8 +1321,6 @@ describe('hoists exported marked function statements', () => { expect(babelTransform(code)).toMatchInlineSnapshot(` "/** MUL */ const mul = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function mul(a, b) { - 'use gpu'; - return __tsover_mul(a, b); }, { v: 1, @@ -1234,8 +1342,6 @@ describe('hoists exported marked function statements', () => { }) && $.f)({}); /** ADD */ const add = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function add(a, b) { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -1266,7 +1372,7 @@ describe('hoists exported marked function statements', () => { expect(await rollupTransform(code)).toMatchInlineSnapshot(` "/** MUL */ const mul = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function mul(a, b) { - 'use gpu'; + return __tsover_mul(a, b); }), { v: 1, @@ -1277,7 +1383,7 @@ describe('hoists exported marked function statements', () => { /** ADD */ const add = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function add(a, b) { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -1310,8 +1416,6 @@ describe('hoists default exported marked function statement', () => { expect(babelTransform(code)).toMatchInlineSnapshot(` "/** ADD */ const add = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function add(a, b) { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -1340,7 +1444,7 @@ describe('hoists default exported marked function statement', () => { expect(await rollupTransform(code)).toMatchInlineSnapshot(` "/** ADD */ const add = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function add(a, b) { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -1381,8 +1485,6 @@ describe('export marked arrow function', () => { test('babel', () => { expect(babelTransform(code)).toMatchInlineSnapshot(` "export const add = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (a, b) => { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -1403,8 +1505,6 @@ describe('export marked arrow function', () => { } }) && $.f)({}); const increment = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = n => { - 'use gpu'; - return __tsover_add(n, 1); }, { v: 1, @@ -1423,8 +1523,6 @@ describe('export marked arrow function', () => { }) && $.f)({}); export { increment }; const mul = /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (a, b) => { - 'use gpu'; - return __tsover_mul(a, b); }, { v: 1, @@ -1451,7 +1549,7 @@ describe('export marked arrow function', () => { test('rollup', async () => { expect(await rollupTransform(code)).toMatchInlineSnapshot(` "const add = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((a, b) => { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -1461,7 +1559,7 @@ describe('export marked arrow function', () => { }) && $.f)({})); const increment = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((n) => { - 'use gpu'; + return __tsover_add(n, 1); }), { v: 1, @@ -1471,7 +1569,7 @@ describe('export marked arrow function', () => { }) && $.f)({})); const mul = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((a, b) => { - 'use gpu'; + return __tsover_mul(a, b); }), { v: 1, @@ -1497,8 +1595,6 @@ describe('anonymous default export marked function statement', () => { test('babel', () => { expect(babelTransform(code)).toMatchInlineSnapshot(` "export default /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = function (a, b) { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -1524,7 +1620,7 @@ describe('anonymous default export marked function statement', () => { test('rollup', async () => { expect(await rollupTransform(code)).toMatchInlineSnapshot(` "var _virtual_code = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function (a, b) { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1, @@ -1550,8 +1646,6 @@ describe('anonymous default export marked arrow function', () => { test('babel', () => { expect(babelTransform(code)).toMatchInlineSnapshot(` "export default /*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (a, b) => { - 'use gpu'; - return __tsover_add(a, b); }, { v: 1, @@ -1577,7 +1671,7 @@ describe('anonymous default export marked arrow function', () => { test('rollup', async () => { expect(await rollupTransform(code)).toMatchInlineSnapshot(` "var _virtual_code = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = ((a, b) => { - 'use gpu'; + return __tsover_add(a, b); }), { v: 1,