mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
transpile label statements to p calls
This commit is contained in:
parent
d1c713fa29
commit
6359bbe139
@ -9,7 +9,7 @@ export function transpiler(input, options = {}) {
|
||||
let ast = parse(input, {
|
||||
ecmaVersion: 2022,
|
||||
allowAwaitOutsideFunction: true,
|
||||
locations: true,
|
||||
locations: false,
|
||||
});
|
||||
|
||||
let miniLocations = [];
|
||||
@ -49,6 +49,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) {},
|
||||
});
|
||||
@ -132,3 +135,31 @@ function withAwait(node) {
|
||||
argument: node,
|
||||
};
|
||||
}
|
||||
|
||||
function isLabelStatement(node) {
|
||||
return node.type === 'LabeledStatement';
|
||||
}
|
||||
|
||||
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…
x
Reference in New Issue
Block a user