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 ForOfStatement(node) {
const variable = bt.isVariableDeclaration(node.left)
? this.transform(node.left.declarations[0].id)
: this.transform(node.left);
const helper = t.memberExpression(t.identifier('Reflect'), ':', t.identifier('__forOf'));
let uid = node[FOR_OF_UID];
// TODO: Apply visitor before transform in testing
if (uid == null && process.env.NODE_ENV === 'test') uid = bt.identifier('_');
if (uid == null) throw new Error('UID not found for ForOfStatement transform');
return t.forGenericStatement(
[this.transform(uid), variable],
[t.callExpression(helper, [this.transform(node.right)])],
this.transformBlock(node.body),
);
}
export function ForInStatement(node) {
const variable = bt.isVariableDeclaration(node.left)
? this.transform(node.left.declarations[0].id)
: this.transform(node.left);
return t.forGenericStatement(
[variable],
[t.callExpression(t.identifier('pairs'), [this.transform(node.right)])],
this.transformBlock(node.body),
);
}