mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 05:28:41 +00:00
automatically add await to samples call
This commit is contained in:
parent
a468ddb85b
commit
ebdca32c80
@ -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 { getLeafLocations } from '@strudel/mini';
|
||||||
|
import { parse } from 'acorn';
|
||||||
|
import escodegen from 'escodegen';
|
||||||
|
import { walk } from 'estree-walker';
|
||||||
|
|
||||||
export function transpiler(input, options = {}) {
|
export function transpiler(input, options = {}) {
|
||||||
const { wrapAsync = false, addReturn = true, emitMiniLocations = true, emitWidgets = true } = 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));
|
return this.replace(widgetWithLocation(node));
|
||||||
}
|
}
|
||||||
|
if (isBareSamplesCall(node, parent)) {
|
||||||
|
return this.replace(withAwait(node));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
leave(node, parent, prop, index) {},
|
leave(node, parent, prop, index) {},
|
||||||
});
|
});
|
||||||
@ -119,3 +121,14 @@ function widgetWithLocation(node) {
|
|||||||
node.callee.name = 'sliderWithID';
|
node.callee.name = 'sliderWithID';
|
||||||
return node;
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user