Merge branch 'labeled-statements' into claviature
This commit is contained in:
commit
0978fbb15e
23 changed files with 1744 additions and 1393 deletions
|
|
@ -64,6 +64,9 @@ export function transpiler(input, options = {}) {
|
|||
if (isBareSamplesCall(node, parent)) {
|
||||
return this.replace(withAwait(node));
|
||||
}
|
||||
if (isLabelStatement(node)) {
|
||||
return this.replace(labelToP(node));
|
||||
}
|
||||
},
|
||||
leave(node, parent, prop, index) {},
|
||||
});
|
||||
|
|
@ -172,3 +175,33 @@ function withAwait(node) {
|
|||
argument: node,
|
||||
};
|
||||
}
|
||||
|
||||
function isLabelStatement(node) {
|
||||
return node.type === 'LabeledStatement';
|
||||
}
|
||||
|
||||
// converts label expressions to p calls: "x: y" to "y.p('x')"
|
||||
// see https://github.com/tidalcycles/strudel/issues/990
|
||||
function labelToP(node) {
|
||||
return {
|
||||
type: 'ExpressionStatement',
|
||||
expression: {
|
||||
type: 'CallExpression',
|
||||
callee: {
|
||||
type: 'MemberExpression',
|
||||
object: node.body.expression,
|
||||
property: {
|
||||
type: 'Identifier',
|
||||
name: 'p',
|
||||
},
|
||||
},
|
||||
arguments: [
|
||||
{
|
||||
type: 'Literal',
|
||||
value: node.label.name,
|
||||
raw: `'${node.label.name}'`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue