or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-babel--plugin-proposal-export-namespace-from

Babel plugin that transforms export namespace from syntax to ES2015 compatible code

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@babel/plugin-proposal-export-namespace-from@7.18.x

To install, run

npx @tessl/cli install tessl/npm-babel--plugin-proposal-export-namespace-from@7.18.0

index.mddocs/

@babel/plugin-proposal-export-namespace-from

Babel plugin that transforms export namespace from syntax to ES2015-compatible code. It converts export * as ns from "module" statements into separate import and export declarations for broader browser compatibility.

Package Information

  • Package Name: @babel/plugin-proposal-export-namespace-from
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install --save-dev @babel/plugin-proposal-export-namespace-from

Core Imports

const plugin = require("@babel/plugin-proposal-export-namespace-from");

ESM:

import plugin from "@babel/plugin-proposal-export-namespace-from";

Basic Usage

Add to your Babel configuration:

{
  "plugins": ["@babel/plugin-proposal-export-namespace-from"]
}

Or programmatically:

import { transform } from "@babel/core";
import exportNamespaceFrom from "@babel/plugin-proposal-export-namespace-from";

const result = transform(code, {
  plugins: [exportNamespaceFrom]
});

Capabilities

Plugin Function

The main exported plugin function that integrates with Babel's transformation pipeline.

/**
 * Creates a Babel plugin for transforming export namespace syntax
 * @param api - Babel's plugin API object with utility methods
 * @returns Plugin object with visitor pattern implementation
 */
declare function exportNamespaceFromPlugin(api: PluginAPI): PluginObject;
export default exportNamespaceFromPlugin;

// From @babel/core
interface PluginAPI {
  version: string;
  assertVersion(version: number | string): void;
  types: typeof import("@babel/types");
  template: any;
  env: (name?: string) => string | undefined;
}

interface PluginObject {
  name: string;
  inherits?: any;
  visitor: {
    ExportNamedDeclaration(path: NodePath<ExportNamedDeclaration>): void;
  };
}

// From @babel/traverse
interface NodePath<T = Node> {
  node: T;
  scope: Scope;
  replaceWithMultiple(nodes: Node[]): NodePath[];
}

// From @babel/types
interface Node {
  type: string;
}

Transformation Behavior

The plugin transforms the following syntax patterns:

Basic Export Namespace

Input:

export * as foo from "bar";

Output:

import * as _foo from "bar";
export { _foo as foo };

Export Default Namespace

Input:

export * as default from "foo";

Output:

import * as _default from "foo";
export { _default as default };

Export Namespace with String Literal

Input:

export * as "some exports" from "foo";

Output:

import * as _someExports from "foo";
export { _someExports as "some exports" };

Compound Export with Named Specifiers

Input:

export * as foo, { bar } from "bar";

Output:

import * as _foo from "bar";
export { _foo as foo };
export { bar } from "bar";

Types

// From @babel/types
interface ExportNamedDeclaration extends Node {
  type: "ExportNamedDeclaration";
  specifiers: (ExportSpecifier | ExportNamespaceSpecifier | ExportDefaultSpecifier)[];
  source: StringLiteral | null;
  declaration?: Declaration | null;
}

interface ExportNamespaceSpecifier extends Node {
  type: "ExportNamespaceSpecifier";
  exported: Identifier | StringLiteral;
}

interface ExportDefaultSpecifier extends Node {
  type: "ExportDefaultSpecifier";
  exported: Identifier;
}

interface ExportSpecifier extends Node {
  type: "ExportSpecifier";
  local: Identifier;
  exported: Identifier | StringLiteral;
}

interface ImportDeclaration extends Node {
  type: "ImportDeclaration";
  specifiers: (ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[];
  source: StringLiteral;
}

interface ImportNamespaceSpecifier extends Node {
  type: "ImportNamespaceSpecifier";
  local: Identifier;
}

// From @babel/traverse
interface Scope {
  generateUidIdentifier(name?: string): Identifier;
  registerDeclaration(path: NodePath): void;
}

interface Identifier extends Node {
  type: "Identifier";
  name: string;
}

interface StringLiteral extends Node {
  type: "StringLiteral";
  value: string;
}

interface Declaration extends Node {}

Plugin Configuration

This plugin does not accept any configuration options. It automatically detects and transforms all export namespace declarations in the source code.

Dependencies

  • @babel/helper-plugin-utils: Provides the declare helper for plugin creation
  • @babel/plugin-syntax-export-namespace-from: Provides syntax parsing support
  • @babel/core: ^7.0.0-0 (peer dependency)

Error Handling

The plugin operates at the AST level and will only transform valid export namespace syntax. Invalid syntax will be handled by Babel's parser before reaching this plugin.

Node.js Compatibility

  • Minimum Node Version: >=6.9.0
  • Module System: CommonJS with ESM exports map