jevstrudel.git / packages / transpiler / plugin-sample.mjs
1/*
2plugin-sample.mjs - <short description TODO>
3Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/src/branch/main/packages/superdough/superdough.mjs>
4This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program.  If not, see <https://www.gnu.org/licenses/>.
5*/
6
7import { registerTranspilerPlugin } from './transpiler.mjs';
8
9export function withAwait(node) {
10  return {
11    type: 'AwaitExpression',
12    argument: node,
13  };
14}
15
16const bareSample = {
17  walk: (context) => ({
18    enter: function (node, parent, prop, index) {
19      if (!isBareSamplesCall(node, parent)) return;
20      this.replace(withAwait(node));
21    },
22  }),
23};
24
25function isBareSamplesCall(node, parent) {
26  return node.type === 'CallExpression' && node.callee.name === 'samples' && parent.type !== 'AwaitExpression';
27}
28
29registerTranspilerPlugin(bareSample);