function ensureConstructor (path: NodePath) {
  let lastProperty;
  const [existing] = path.get('body.body').filter(
    item => {
      if (item.isClassProperty()) {
        lastProperty = item;
        return false;
      }
      return item.node.kind === 'constructor';
    }
  );
  if (existing) {
    return existing;
  }
  let constructorNode;
  if (path.has('superClass')) {
    const args = t.identifier('args');
    constructorNode = t.classMethod(
      'constructor',
      t.identifier('constructor'),
      [t.restElement(args)],
      t.blockStatement([
        t.expressionStatement(
          t.callExpression(
            t.super(),
            [t.spreadElement(args)]
          )
        )
      ])
    );

  }
  else {
    constructorNode = t.classMethod(
      'constructor',
      t.identifier('constructor'),
      [],
      t.blockStatement([])
    );
  }

  if (lastProperty) {
    lastProperty.insertAfter(constructorNode);
  }
  else {
    path.get('body').unshiftContainer('body', constructorNode);
  }
}
function ensureConstructor (path: NodePath) {
  let lastProperty;
  const [existing] = path.get('body.body').filter(
    item => {
      if (item.isClassProperty()) {
        lastProperty = item;
        return false;
      }
      return item.node.kind === 'constructor';
    }
  );
  if (existing) {
    return existing;
  }
  let constructorNode;
  if (path.has('superClass')) {
    const args = t.identifier('args');
    constructorNode = t.classMethod(
      'constructor',
      t.identifier('constructor'),
      [t.restElement(args)],
      t.blockStatement([
        t.expressionStatement(
          t.callExpression(
            t.super(),
            [t.spreadElement(args)]
          )
        )
      ])
    );

  }
  else {
    constructorNode = t.classMethod(
      'constructor',
      t.identifier('constructor'),
      [],
      t.blockStatement([])
    );
  }

  if (lastProperty) {
    lastProperty.insertAfter(constructorNode);
  }
  else {
    path.get('body').unshiftContainer('body', constructorNode);
  }
}
function ensureConstructor ( path : NodePath ) { let lastProperty ; const [ existing ] = path . get ( 'body.body' ) . filter ( item => { if ( item . isClassProperty ( ) ) { lastProperty = item ; return false ; } return item . node . kind === 'constructor' ; } ) ; if ( existing ) { return existing ; } let constructorNode ; if ( path . has ( 'superClass' ) ) { const args = t . identifier ( 'args' ) ; constructorNode = t . classMethod ( 'constructor' , t . identifier ( 'constructor' ) , [ t . restElement ( args ) ] , t . blockStatement ( [ t . expressionStatement ( t . callExpression ( t . super ( ) , [ t . spreadElement ( args ) ] ) ) ] ) ) ; } else { constructorNode = t . classMethod ( 'constructor' , t . identifier ( 'constructor' ) , [ ] , t . blockStatement ( [ ] ) ) ; } if ( lastProperty ) { lastProperty . insertAfter ( constructorNode ) ; } else { path . get ( 'body' ) . unshiftContainer ( 'body' , constructorNode ) ; } }
Ensure that the given class contains a constructor.
Ensure that the given class contains a constructor .