1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@babel/helper-module-imports
詹力 1a19ec897f 删除无关模块 2024-01-16 21:26:16 +08:00
..
lib i4 2023-12-18 13:12:25 +08:00
README.md i4 2023-12-18 13:12:25 +08:00
package.json 删除无关模块 2024-01-16 21:26:16 +08:00

README.md

@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);
      }
    },
  };
}