babel-helper-module-imports
Babel helper functions for inserting module loads
Last updated 7 years ago by hzoo .
MIT · Repository · Original npm · Tarball · package.json
$ gnpm install babel-helper-module-imports 
SYNC missed versions from official npm registry.

babel-helper-module-imports

Installation

npm install babel-helper-module-imports --save

Usage

import "source"

import { addSideEffect } from "babel-helper-module-imports";
addSideEffect(path, 'source');

import { named } from "source"

import { addNamed } from "babel-helper-module-imports";
addNamed(path, 'named', 'source');

import { named as _hintedName } from "source"

import { addNamed } from "babel-helper-module-imports";
addNamed(path, 'named', 'source', { nameHint: "hintedName" });

import _default from "source"

import { addDefault } from "babel-helper-module-imports";
addDefault(path, 'source');

import hintedName from "source"

import { addDefault } from "babel-helper-module-imports";
addDefault(path, 'source', { nameHint: "hintedName" })

import * as _namespace from "source"

import { addNamespace } from "babel-helper-module-imports";
addNamespace(path, 'source');

Examples

Adding a named import

import { addNamed } from "babel-helper-module-imports";

export default function({ types: t }) {
  return {
    visitor: {
      ReferencedIdentifier(path) {
        let importName = this.importName;
        if (importName) {
          importName = t.cloneDeep(importName);
        } else {
          // require('bluebird').coroutine
          importName = this.importName = addNamed(path, 'coroutine', 'bluebird');
        }

        path.replaceWith(importName);
      }
    },
  };
}

Current Tags

  • 7.0.0-beta.3                                ...           latest (7 years ago)
  • 7.0.0-beta.3                                ...           next (7 years ago)

1 Versions

  • 7.0.0-beta.3                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None

Copyright 2013 - present © cnpmjs.org | Home |