Socket
Book a DemoInstallSign in
Socket

cjs-hoist

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cjs-hoist

Transform CommonJS module, hoisting `require` and `exports` statements to top-level.

0.1.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

cjs-hoist

Build Status

Transform CommonJS module, hoisting require and exports statements to top-level.

Usage

const {parse} = require("acorn");
const {transform} = require("cjs-hoist");
const {code} = transform({
  parse,
  code: `
if (foo) {
  const bar = require("bar");
}
`
});
/* code -> `
const _require_bar_ = require("bar");
if (foo) {
  const bar = _require_bar_;
}
`

API reference

This module exports following members.

  • transform: A function which can convert CJS module synax into ES module syntax.

transform(options?: object): TransformResult object

options has following members:

  • parse: function. A parser function which can parse JavaScript code into ESTree.
  • code: string. The JavaScript source code.
  • sourceMap?: boolean. If true then generate the source map. Default: false
  • ignoreDynamicRequire?: boolean. If true then the dynamic require (i.e. Promise.resolve(require("..."))) is ignored. Default: true

The result object has following members:

  • code: string. The result JavaScript code.
  • map?: object. The source map object generated by magicString.generateMap.
  • isTouched: boolean. If false then the code isn't changed.

Changelog

  • 0.1.3 (Apr 26, 2018)

    • Dependency change: drop estraverse, ecma-variable-scope; add estree-walker, rollup-pluginutils, is-reference.
  • 0.1.2 (Apr 26, 2018)

    • Fix: require-in-module.
  • 0.1.1 (Apr 26, 2018)

    • Add: isTouched prop.
  • 0.1.0 (Apr 26, 2018)

    • Initial release.

Keywords

cjs

FAQs

Package last updated on 26 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.