Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup plugin #409

Merged
merged 9 commits into from
Oct 3, 2024
Merged

Rollup plugin #409

merged 9 commits into from
Oct 3, 2024

Conversation

iwoplaza
Copy link
Collaborator

@iwoplaza iwoplaza commented Oct 2, 2024

Changes

  • @typegpu/tgsl-tools no longer act on raw JS code as a string, but rather process an estree-compliant JavaScript AST. This allows the rollup plugin to plugin the ast it generated to transpile it to SMoL. The JIT is now responsible for generating an AST from the raw JS code with acorn.
  • Anonymous functions (function() {}) are now supported as parameters to .implement and .procedure

Usage

// @ts-check
import { defineConfig } from 'vite';
import typegpu from 'rollup-plugin-typegpu';

export default defineConfig({
  plugins: [
    typegpu(),
  ],
});

Functionality

  • Targets files that import typegpu or any submodule typegpu/*.
  • Gathers how the tgpu object is imported, and how it is aliased.
  • Augments every tgpu function creation with calls to $__ast and $uses.

image

Further work

@iwoplaza iwoplaza changed the title Vite plugin Rollup plugin Oct 3, 2024
@iwoplaza iwoplaza marked this pull request as ready for review October 3, 2024 10:19
@iwoplaza iwoplaza linked an issue Oct 3, 2024 that may be closed by this pull request
Comment on lines +268 to +269
| acorn.FunctionExpression
| acorn.FunctionDeclaration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what's the difference between these expressions vs declarations. couldn't find acorn docs, could you please link it if you have it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FunctionDeclaration nodes are statements, so when we just declare a function, instead of e.g., passing that declaration immediately as an argument. FunctionExpressions are the opposite.

Example of FunctionDeclaration:

function foo() {}

Example of FunctionExpression:

bar(function foo() {})
//  ^ here

packages/rollup-plugin/src/index.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@reczkok reczkok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job 👏🆙

packages/rollup-plugin/src/index.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@mhawryluk mhawryluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@iwoplaza iwoplaza merged commit 1d3ef13 into main Oct 3, 2024
4 checks passed
@iwoplaza iwoplaza deleted the feat/vite-plugin branch October 3, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a Vite plugin.
3 participants