/* Generated by `npm run build`, do not edit! */

/* eslint-disable no-underscore-dangle */

var DynamicImportKey = 'Import';

var ref = require('acorn');
var tt = ref.tokTypes;

// NOTE: This allows `yield import()` to parse correctly.
tt._import.startsExpr = true;

function parseDynamicImport() {
  var node = this.startNode();
  this.next();
  if (this.type !== tt.parenL) {
    this.unexpected();
  }
  return this.finishNode(node, DynamicImportKey);
}

function parenAfter() {
  return /^(\s|\/\/.*|\/\*[^]*?\*\/)*\(/.test(this.input.slice(this.pos));
}

function dynamicImport(Parser) {
  return (function (Parser) {
    function anonymous () {
      Parser.apply(this, arguments);
    }

    if ( Parser ) anonymous.__proto__ = Parser;
    anonymous.prototype = Object.create( Parser && Parser.prototype );
    anonymous.prototype.constructor = anonymous;

    anonymous.prototype.parseStatement = function parseStatement (context, topLevel, exports) {
      if (this.type === tt._import && parenAfter.call(this)) {
        return this.parseExpressionStatement(this.startNode(), this.parseExpression());
      }
      return Parser.prototype.parseStatement.call(this, context, topLevel, exports)
    };

    anonymous.prototype.parseExprAtom = function parseExprAtom (refDestructuringErrors) {
      if (this.type === tt._import) {
        return parseDynamicImport.call(this);
      }
      return Parser.prototype.parseExprAtom.call(this, refDestructuringErrors);
    };

    return anonymous;
  }(Parser));
};

module.exports = dynamicImport
dynamicImport.DynamicImportKey = DynamicImportKey
