strudel/packages/transpiler
2026-02-18 23:47:47 +01:00
..
test refactor: localize, remove helpers file when there's no reuse 2026-02-18 23:47:47 +01:00
index.mjs refactor: localize, remove helpers file when there's no reuse 2026-02-18 23:47:47 +01:00
package.json Publish 2026-01-17 15:26:28 -08:00
plugin-kabelsalat.mjs refactor: localize, remove helpers file when there's no reuse 2026-02-18 23:47:47 +01:00
plugin-mini.mjs refactor: localize, remove helpers file when there's no reuse 2026-02-18 23:47:47 +01:00
plugin-sample.mjs refactor: localize, remove helpers file when there's no reuse 2026-02-18 23:47:47 +01:00
plugin-widgets.mjs refactor: localize, remove helpers file when there's no reuse 2026-02-18 23:47:47 +01:00
README.md fix: remove outdated feature note 2026-02-18 20:56:41 +01:00
transpiler.mjs refactor: localize, remove helpers file when there's no reuse 2026-02-18 23:47:47 +01:00
vite.config.js remove cjs builds 2024-02-08 12:19:11 +01:00

@strudel/transpiler

This package contains a JS code transpiler with a plugin system that can be used to transform the code.

A plugin can be registered via a registerTranspilerPlugin call :

registerTranspilerPlugin({
  walk: (context) => ({
    enter: function(node, parent, prop, index) {},
    leave: function(node, parent, prop, index) {}
  })
})

where the enter/leave functions (both optional) follow the estree-walker walk API.

4 plugins are currently hosted inside @strudel/transpiler

  • mini: add locations of mini notation strings (double quoted or backticked) for highlighting
  • widgets: add handling of sliders & draw widgets
  • sample: make it possible to call a sample without await
  • kabelsalat: transform the code to handle the K(..) kabelsalat notation

it also

  • adds return statement to the last expression
  • handles label capturing for block-based eval

Install

npm i @strudel/transpiler

Use

import { transpiler } from '@strudel/core';
import { evaluate } from '@strudel/core';

transpiler('note("c3 [e3,g3]")', { wrapAsync: false, addReturn: false, simpleLocs: true });
/* mini('c3 [e3,g3]').withMiniLocation(7,17) */

evaluate(note('c3 [e3,g3]'), transpiler); // returns pattern of above code