@babel/helper-module-transforms

  • Version 8.0.1
  • Published
  • 151 kB
  • 3 dependencies
  • MIT license

Install

npm i @babel/helper-module-transforms
yarn add @babel/helper-module-transforms
pnpm add @babel/helper-module-transforms

Overview

Babel helper functions for implementing ES6 module transformations

Index

Functions

function buildDynamicImport

buildDynamicImport: (
node: types.CallExpression | types.ImportExpression,
deferToThen: boolean,
wrapWithPromise: boolean,
builder: (specifier: types.Expression) => types.Expression
) => types.Expression;

    function buildNamespaceInitStatements

    buildNamespaceInitStatements: (
    metadata: ModuleMetadata,
    sourceMetadata: SourceModuleMetadata,
    constantReexports?: boolean | void,
    wrapReference?: (
    ref: types.Identifier,
    payload: unknown
    ) => types.Expression | null
    ) => (
    | types.BlockStatement
    | types.BreakStatement
    | types.ClassDeclaration
    | types.ContinueStatement
    | types.DebuggerStatement
    | types.DeclareClass
    | types.DeclareExportAllDeclaration
    | types.DeclareExportDeclaration
    | types.DeclareFunction
    | types.DeclareInterface
    | types.DeclareModule
    | types.DeclareModuleExports
    | types.DeclareOpaqueType
    | types.DeclareTypeAlias
    | types.DeclareVariable
    | types.DoWhileStatement
    | types.EmptyStatement
    | types.EnumDeclaration
    | types.ExportAllDeclaration
    | types.ExportDefaultDeclaration
    | types.ExportNamedDeclaration
    | types.ExpressionStatement
    | types.ForInStatement
    | types.ForOfStatement
    | types.ForStatement
    | types.FunctionDeclaration
    | types.IfStatement
    | types.ImportDeclaration
    | types.InterfaceDeclaration
    | types.LabeledStatement
    | types.OpaqueType
    | types.ReturnStatement
    | types.SwitchStatement
    | types.TSDeclareFunction
    | types.TSEnumDeclaration
    | types.TSExportAssignment
    | types.TSImportEqualsDeclaration
    | types.TSInterfaceDeclaration
    | types.TSModuleDeclaration
    | types.TSNamespaceExportDeclaration
    | types.TSTypeAliasDeclaration
    | types.ThrowStatement
    | types.TryStatement
    | types.TypeAlias
    | types.VariableDeclaration
    | types.WhileStatement
    | types.WithStatement
    )[];
    • Create the runtime initialization statements for a given requested source. These will initialize all of the runtime import/export logic that can't be handled statically by the statements created by buildExportInitializationStatements().

    function ensureStatementsHoisted

    ensureStatementsHoisted: (statements: types.Statement[]) => void;
    • Flag a set of statements as hoisted above all else so that module init statements all run before user code.

    function getModuleName

    getModuleName: (
    rootOpts: RootOptions,
    pluginOpts: PluginOptions
    ) => string | null;

      function hasExports

      hasExports: (metadata: ModuleMetadata) => boolean;
      • Check if the module has any exports that need handling.

      function isSideEffectImport

      isSideEffectImport: (source: SourceModuleMetadata) => boolean;
      • Check if a given source is an anonymous import, e.g. "import 'foo';"

      function rewriteModuleStatementsAndPrepareHeader

      rewriteModuleStatementsAndPrepareHeader: (
      path: NodePath$1<types.Program>,
      {
      exportName,
      strict,
      allowTopLevelThis,
      strictMode,
      noInterop,
      importInterop,
      lazy,
      getWrapperPayload,
      wrapReference,
      esNamespaceOnly,
      filename,
      constantReexports,
      enumerableModuleMeta,
      noIncompleteNsImportDetection,
      }: RewriteModuleStatementsAndPrepareHeaderOptions
      ) => {
      meta: ModuleMetadata;
      headers: (
      | types.BlockStatement
      | types.BreakStatement
      | types.ClassDeclaration
      | types.ContinueStatement
      | types.DebuggerStatement
      | types.DeclareClass
      | types.DeclareExportAllDeclaration
      | types.DeclareExportDeclaration
      | types.DeclareFunction
      | types.DeclareInterface
      | types.DeclareModule
      | types.DeclareModuleExports
      | types.DeclareOpaqueType
      | types.DeclareTypeAlias
      | types.DeclareVariable
      | types.DoWhileStatement
      | types.EmptyStatement
      | types.EnumDeclaration
      | types.ExportAllDeclaration
      | types.ExportDefaultDeclaration
      | types.ExportNamedDeclaration
      | types.ExpressionStatement
      | types.ForInStatement
      | types.ForOfStatement
      | types.ForStatement
      | types.FunctionDeclaration
      | types.IfStatement
      | types.ImportDeclaration
      | types.InterfaceDeclaration
      | types.LabeledStatement
      | types.OpaqueType
      | types.ReturnStatement
      | types.SwitchStatement
      | types.TSDeclareFunction
      | types.TSEnumDeclaration
      | types.TSExportAssignment
      | types.TSImportEqualsDeclaration
      | types.TSInterfaceDeclaration
      | types.TSModuleDeclaration
      | types.TSNamespaceExportDeclaration
      | types.TSTypeAliasDeclaration
      | types.ThrowStatement
      | types.TryStatement
      | types.TypeAlias
      | types.VariableDeclaration
      | types.WhileStatement
      | types.WithStatement
      )[];
      };
      • Perform all of the generic ES6 module rewriting needed to handle initial module processing. This function will rewrite the majority of the given program to reference the modules described by the returned metadata, and returns a list of statements for use when initializing the module.

      function rewriteThis

      rewriteThis: (programPath: NodePath) => void;

        function wrapInterop

        wrapInterop: (
        programPath: NodePath$1<types.Program>,
        expr: types.Expression,
        type: InteropType
        ) => types.CallExpression | null;
        • Given an expression for a standard import object, like "require('foo')", wrap it in a call to the interop helpers based on the type.

        Interfaces

        interface RewriteModuleStatementsAndPrepareHeaderOptions

        interface RewriteModuleStatementsAndPrepareHeaderOptions {}

          property allowTopLevelThis

          allowTopLevelThis?: boolean;

            property constantReexports

            constantReexports?: boolean | void;

              property enumerableModuleMeta

              enumerableModuleMeta?: boolean | void;

                property esNamespaceOnly

                esNamespaceOnly?: boolean;

                  property exportName

                  exportName?: string;

                    property filename

                    filename: string | undefined;

                      property getWrapperPayload

                      getWrapperPayload?: (
                      source: string,
                      metadata: SourceModuleMetadata,
                      importNodes: types.Node[]
                      ) => unknown;

                        property importInterop

                        importInterop?: ImportInterop;

                          property lazy

                          lazy?: Lazy;

                            property loose

                            loose?: boolean;

                              property noIncompleteNsImportDetection

                              noIncompleteNsImportDetection?: boolean | void;

                                property noInterop

                                noInterop?: boolean;

                                  property strict

                                  strict?: boolean;

                                    property strictMode

                                    strictMode?: boolean;

                                      property wrapReference

                                      wrapReference?: (
                                      ref: types.Expression,
                                      payload: unknown
                                      ) => types.Expression | null;

                                        Type Aliases

                                        type PluginOptions

                                        type PluginOptions = {
                                        moduleId?: string;
                                        moduleIds?: boolean;
                                        getModuleId?: (moduleName: string) => string | null | undefined;
                                        moduleRoot?: string;
                                        };

                                          Package Files (1)

                                          Dependencies (3)

                                          Dev Dependencies (1)

                                          Peer Dependencies (1)

                                          Badge

                                          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@babel/helper-module-transforms.

                                          • Markdown
                                            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@babel/helper-module-transforms)
                                          • HTML
                                            <a href="https://www.jsdocs.io/package/@babel/helper-module-transforms"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>