Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function UnaryExpression(node) {
switch (node.operator) {
case 'void':
return t.binaryExpression('and', this.transform(node.argument), t.nilLiteral());
case 'delete':
return t.assignmentStatement([this.transform(node.argument)], [t.nilLiteral()]);
case '!':
return t.unaryExpression('not', this.transform(node.argument));
case '+':
return t.callExpression(t.identifier('tonumber'), [this.transform(node.argument)]);
case '-':
case '~':
return t.unaryExpression(node.operator, this.transform(node.argument));
default:
// FIXME: Use path.buildCodeFrameError
throw new Error(`${node.operator} is unsupported unary operator`);
}
}
export function UpdateExpression(node, parent) {
if (!bt.isExpressionStatement(parent)) {
// FIXME: Use path.buildCodeFrameError
throw new Error("UpdateExpression's not in ExpressionStatement's are not supported.");
}
if (node.operator !== '++' && node.operator !== '--') {
// FIXME: Use path.buildCodeFrameError
throw new Error(`Invalid UpdateExpression operator ${node.operator}`);
}
const right = t.binaryExpression(
node.operator === '++' ? '+' : '-',
this.transform(node.argument),
t.numericLiteral(1),
);
return t.assignmentStatement([this.transform(node.argument)], [right]);
}
export function AssignmentExpression(node, parent) {
if (!bt.isExpressionStatement(parent)) {
// FIXME: Use path.buildCodeFrameError
throw new Error("AssignmentExpression's not in ExpressionStatement's are not supported.");
}
if (node.operator !== '=') {
// FIXME: Use path.buildCodeFrameError
throw new Error(`${node.operator} is unsupported assignment expression operator`);
}
return t.assignmentStatement([this.transform(node.left)], [this.transform(node.right)]);
}