transpile label statements to p calls
This commit is contained in:
parent
d1c713fa29
commit
6359bbe139
1 changed files with 32 additions and 1 deletions
|
|
@ -9,7 +9,7 @@ export function transpiler(input, options = {}) {
|
||||||
let ast = parse(input, {
|
let ast = parse(input, {
|
||||||
ecmaVersion: 2022,
|
ecmaVersion: 2022,
|
||||||
allowAwaitOutsideFunction: true,
|
allowAwaitOutsideFunction: true,
|
||||||
locations: true,
|
locations: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
let miniLocations = [];
|
let miniLocations = [];
|
||||||
|
|
@ -49,6 +49,9 @@ export function transpiler(input, options = {}) {
|
||||||
if (isBareSamplesCall(node, parent)) {
|
if (isBareSamplesCall(node, parent)) {
|
||||||
return this.replace(withAwait(node));
|
return this.replace(withAwait(node));
|
||||||
}
|
}
|
||||||
|
if (isLabelStatement(node)) {
|
||||||
|
return this.replace(labelToP(node));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
leave(node, parent, prop, index) {},
|
leave(node, parent, prop, index) {},
|
||||||
});
|
});
|
||||||
|
|
@ -132,3 +135,31 @@ function withAwait(node) {
|
||||||
argument: 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…
Add table
Add a link
Reference in a new issue