How to use the acorn.tokTypes._import function in acorn

To help you get started, we’ve selected a few acorn 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 flaviuse / mern-authentication / client / node_modules / acorn-dynamic-import / src / index.js View on Github external
/* eslint-disable no-underscore-dangle */
import { tokTypes as tt } from 'acorn';

export const DynamicImportKey = 'Import';

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

function parseDynamicImport() {
  const 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));
}

export default function dynamicImport(Parser) {
  return class extends Parser {
github kesne / acorn-dynamic-import / src / index.js View on Github external
/* eslint-disable no-underscore-dangle */
import { tokTypes as tt } from 'acorn';

export const DynamicImportKey = 'Import';

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

function parseDynamicImport() {
  const 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));
}

export default function dynamicImport(Parser) {
  return class extends Parser {
github observablehq / parser / src / dynamic-import.js View on Github external
// A more accurate version of acorn-dynamic-import.
// Copyright Jordan Gensler. Released under MIT license:
// https://github.com/kesne/acorn-dynamic-import
// https://github.com/standard-things/esm/blob/0.18.0/src/acorn-ext/dynamic-import.js

import {tokTypes as tt} from "acorn";

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

function parseImportCall(parser) {
  const node = parser.startNode();
  const {start} = parser;
  const callExpr = parser.startNode();
  const callee = parser.parseExprAtom();
  parser.expect(tt.parenL);
  callExpr.arguments = [parser.parseMaybeAssign()];
  callExpr.callee = callee;
  parser.finishNode(callExpr, "CallExpression");
  parser.expect(tt.parenR);
  const expr = parser.parseSubscripts(callExpr, start);
  return parser.parseExpressionStatement(node, expr);
}

function parseImportCallAtom(parser) {
github cloudflare / ipfs-ext / node_modules / acorn-dynamic-import / src / index.js View on Github external
parseExprAtom(refDestructuringErrors) {
      if (this.type === tt._import) {
        return parseDynamicImport.call(this);
      }
      return super.parseExprAtom(refDestructuringErrors);
    }
  };
github wrleskovec / react-week-scheduler / node_modules / acorn / src / loose / statement.js View on Github external
this.next()
    node.object = this.parseParenExpression()
    node.body = this.parseStatement()
    return this.finishNode(node, "WithStatement")

  case tt.braceL:
    return this.parseBlock()

  case tt.semi:
    this.next()
    return this.finishNode(node, "EmptyStatement")

  case tt._class:
    return this.parseClass(true)

  case tt._import:
    return this.parseImport()

  case tt._export:
    return this.parseExport()

  default:
    let expr = this.parseExpression()
    if (isDummy(expr)) {
      this.next()
      if (this.tok.type === tt.eof) return this.finishNode(node, "EmptyStatement")
      return this.parseStatement()
    } else if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) {
      node.body = this.parseStatement()
      node.label = expr
      return this.finishNode(node, "LabeledStatement")
    } else {
github cloudflare / ipfs-ext / node_modules / acorn-node / lib / import-meta / index.js View on Github external
anonymous.prototype.parseExprAtom = function parseExprAtom (refDestructuringErrors) {
      if (this.type !== tt._import || !nextTokenIsDot(this)) { return Parser.prototype.parseExprAtom.call(this, refDestructuringErrors) }

      if (!this.options.allowImportExportEverywhere && !this.inModule) {
        this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'")
      }

      var node = this.startNode()
      node.meta = this.parseIdent(true)
      this.expect(tt.dot)
      node.property = this.parseIdent(true)
      if (node.property.name !== "meta") {
        this.raiseRecoverable(node.property.start, "The only valid meta property for import is import.meta")
      }
      return this.finishNode(node, "MetaProperty")
    };
github acornjs / acorn / acorn-loose / src / statement.js View on Github external
this.next()
    node.object = this.parseParenExpression()
    node.body = this.parseStatement()
    return this.finishNode(node, "WithStatement")

  case tt.braceL:
    return this.parseBlock()

  case tt.semi:
    this.next()
    return this.finishNode(node, "EmptyStatement")

  case tt._class:
    return this.parseClass(true)

  case tt._import:
    if (this.options.ecmaVersion > 10 && this.lookAhead(1).type === tt.parenL) {
      node.expression = this.parseExpression()
      this.semicolon()
      return this.finishNode(node, "ExpressionStatement")
    }

    return this.parseImport()

  case tt._export:
    return this.parseExport()

  default:
    if (this.toks.isAsyncFunction()) {
      this.next()
      this.next()
      return this.parseFunction(node, true, true)
github flaviuse / mern-authentication / client / node_modules / acorn-dynamic-import / src / index.js View on Github external
parseStatement(context, topLevel, exports) {
      if (this.type === tt._import && parenAfter.call(this)) {
        return this.parseExpressionStatement(this.startNode(), this.parseExpression());
      }
      return super.parseStatement(context, topLevel, exports);
    }
github kesne / acorn-dynamic-import / src / index.js View on Github external
parseStatement(context, topLevel, exports) {
      if (this.type === tt._import && parenAfter.call(this)) {
        return this.parseExpressionStatement(this.startNode(), this.parseExpression());
      }
      return super.parseStatement(context, topLevel, exports);
    }