automatically add await to samples call

This commit is contained in:
Felix Roos 2024-02-21 09:48:26 +01:00
parent a468ddb85b
commit ebdca32c80

View File

@ -1,8 +1,7 @@
import escodegen from 'escodegen';
import { parse } from 'acorn';
import { walk } from 'estree-walker';
import { isNoteWithOctave } from '@strudel/core';
import { getLeafLocations } from '@strudel/mini';
import { parse } from 'acorn';
import escodegen from 'escodegen';
import { walk } from 'estree-walker';
export function transpiler(input, options = {}) {
const { wrapAsync = false, addReturn = true, emitMiniLocations = true, emitWidgets = true } = options;
@ -47,6 +46,9 @@ export function transpiler(input, options = {}) {
});
return this.replace(widgetWithLocation(node));
}
if (isBareSamplesCall(node, parent)) {
return this.replace(withAwait(node));
}
},
leave(node, parent, prop, index) {},
});
@ -119,3 +121,14 @@ function widgetWithLocation(node) {
node.callee.name = 'sliderWithID';
return node;
}
function isBareSamplesCall(node, parent) {
return node.type === 'CallExpression' && node.callee.name === 'samples' && parent.type !== 'AwaitExpression';
}
function withAwait(node) {
return {
type: 'AwaitExpression',
argument: node,
};
}