From ebdca32c806e89d6d5648462b7c200ae2c9226c5 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 21 Feb 2024 09:48:26 +0100 Subject: [PATCH 1/3] automatically add await to samples call --- packages/transpiler/transpiler.mjs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/transpiler/transpiler.mjs b/packages/transpiler/transpiler.mjs index aedf8f3a..72f2e851 100644 --- a/packages/transpiler/transpiler.mjs +++ b/packages/transpiler/transpiler.mjs @@ -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, + }; +} From 38d389b83899046b190f594155fb7c374d4b596f Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 21 Feb 2024 09:50:21 +0100 Subject: [PATCH 2/3] add test --- packages/transpiler/test/transpiler.test.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/transpiler/test/transpiler.test.mjs b/packages/transpiler/test/transpiler.test.mjs index 5f1b754f..988479b4 100644 --- a/packages/transpiler/test/transpiler.test.mjs +++ b/packages/transpiler/test/transpiler.test.mjs @@ -23,6 +23,9 @@ describe('transpiler', () => { it('supports top level await', () => { expect(transpiler("await samples('xxx');", simple).output).toEqual("await samples('xxx');"); }); + it('adds await to bare samples call', () => { + expect(transpiler("samples('xxx');", simple).output).toEqual("await samples('xxx');"); + }); /* it('parses dynamic imports', () => { expect( transpiler("const { default: foo } = await import('https://bar.com/foo.js');", { From bf63b716af91cf512f3de83758a3b8463f346a0d Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 21 Feb 2024 10:17:45 +0100 Subject: [PATCH 3/3] refactor: remove await before samples calls in docs etc.. + remove /master from dirt-samples calls (there is now a main branch) + remove /main endings from some places --- examples/buildless/headless-with-samples.html | 2 +- examples/buildless/minimal-repl.html | 2 +- examples/codemirror-repl/tunes.mjs | 12 +++++------ examples/headless-repl/index.html | 2 +- examples/minimal-repl/tune.mjs | 2 +- examples/superdough/index.html | 2 +- packages/core/controls.mjs | 2 +- packages/core/pattern.mjs | 6 +++--- packages/superdough/README.md | 4 ++-- packages/superdough/sampler.mjs | 2 +- packages/web/README.md | 2 +- .../blog/release-0.8.0-himbeermuffin.mdx | 2 +- website/src/examples.mjs | 4 ++-- website/src/pages/learn/getting-started.mdx | 2 +- website/src/pages/learn/samples.mdx | 20 +++++++++---------- website/src/pages/recipes/recipes.mdx | 20 +++++++++---------- website/src/pages/recipes/rhythms.mdx | 2 +- website/src/repl/prebake.mjs | 3 +-- website/src/repl/tunes.mjs | 10 +++++----- 19 files changed, 50 insertions(+), 51 deletions(-) diff --git a/examples/buildless/headless-with-samples.html b/examples/buildless/headless-with-samples.html index 40073d70..2ac7aa71 100644 --- a/examples/buildless/headless-with-samples.html +++ b/examples/buildless/headless-with-samples.html @@ -6,7 +6,7 @@