Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-explode-module

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-explode-module

Serialize a module into an easier format to work with

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

babel-explode-module

Serialize a module into an easier format to work with

import {foo, bar} from "mod";

export default function() {
  // ...
}

const baz = 42,
      bat = class Bat {};

export {
  baz,
  bat
};

Creating this AST:

Program
  body:
    - ImportDeclaration
        specifiers:
          - ImportSpecifier
          - ImportSpecifier
    - ExportDefaultDeclaration
        declaration: FunctionDeclaration
    - VariableDeclaration
        declarations:
          - VariableDeclarator
          - VariableDeclarator
    - ExportNamedDeclaration
        specifiers:
          - ExportSpecifier
          - ExportSpecifier

Will be exploded to this:

{
  imports: [
    { kind: "value", local: "foo", external: "foo", source: "mod", loc: {...} },
    { kind: "value", local: "bar", external: "bar", source: "mod", loc: {...} },
  ],
  exports: [
    { local: "_default", external: "default", loc: {...} },
    { local: "baz", external: "baz", loc: {...} },
    { local: "bat", external: "bat", loc: {...} },
  },
  statements: [
    { type: "FunctionDeclaration" },
    { type: "VariableDeclaration", declarations: VariableDeclarator },
    { type: "VariableDeclaration", declarations: VariableDeclarator },
  ],
}
Serializes imports/exports to an easy to work with format
// input
import a, {b} from "mod";
import * as c from "mod";
export default function d() {}
export {e, f as g};
export {default as h} from "mod";
export * from "mod";
// output
{
  imports: [
    { kind: "value", local: "a", external: "a", source: "mod" },
    { kind: "value", local: "b", external: "b", source: "mod" },
    { kind: "value", local: "c", source: "d" },
  ],
  exports: [
    { local: "d", external: "d" },
    { local: "e", external: "e" },
    { local: "f", external: "g" },
    { local: "default", external: "g", source: "mod" },
    { source: "mod" },
  ]
}
Simplifies declarations to create 1 binding per statement (i.e. variables)
// input
function a() {}
var b,
    c;
// output (printed)
function a() {}
var b;
var c;
Splits export values away from their exports
// input
export function a() {}
export default function() {}
// output (printed)
function a() {}
var _default = function() {};
export {a};
export default _default;

FAQs

Package last updated on 10 Aug 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc