How to use the lua-types.forGenericStatement function in lua-types

To help you get started, we’ve selected a few lua-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ark120202 / babel-lua / packages / babel-plugin-lua-generator / src / transformers / statements.js View on Github external
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),
  );
}
github ark120202 / babel-lua / packages / babel-plugin-lua-generator / src / transformers / statements.js View on Github external
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),
  );
}