@babel/core

  • Version 8.0.1
  • Published
  • 545 kB
  • 16 dependencies
  • MIT license

Install

npm i @babel/core
yarn add @babel/core
pnpm add @babel/core

Overview

Babel compiler core.

Index

Variables

variable CONFIG_ITEM_BRAND

const CONFIG_ITEM_BRAND: Symbol;

    variable createConfigItemRunner

    const createConfigItemRunner: gensync.Gensync<
    [
    (
    | string
    | ConfigItem<PluginAPI>
    | ConfigItem<PresetAPI>
    | ((api: PresetAPI, options: object, dirname: string) => PresetObject)
    | {
    default: (
    api: PresetAPI,
    options: object,
    dirname: string
    ) => PresetObject;
    }
    | [PresetTarget<object>, object]
    | [PresetTarget<object>, object, string]
    | ((api: PluginAPI, options: object, dirname: string) => PluginObject)
    | {
    default: (
    api: PluginAPI,
    options: object,
    dirname: string
    ) => PluginObject;
    }
    | [PluginTarget<object>, object]
    | [PluginTarget<object>, object, string]
    ),
    { dirname?: string; type?: 'preset' | 'plugin' }?
    ],
    ConfigItem<unknown>,
    any
    >;

      variable DEFAULT_EXTENSIONS

      const DEFAULT_EXTENSIONS: readonly ['.js', '.jsx', '.es6', '.es', '.mjs', '.cjs'];
      • Recommended set of compilable extensions. Not used in @babel/core directly, but meant as as an easy source for tooling making use of @babel/core.

      variable loadOptionsRunner

      const loadOptionsRunner: gensync.Gensync<[opts: InputOptions], ResolvedOptions, any>;

        variable loadPartialConfigRunner

        const loadPartialConfigRunner: gensync.Gensync<
        [opts?: InputOptions],
        PartialConfig,
        any
        >;

          variable parse

          const parse: Parse;

            variable parseRunner

            const parseRunner: gensync.Gensync<[code: string, opts: InputOptions], any, any>;

              variable transform

              const transform: Transform;

                variable transformFileRunner

                const transformFileRunner: gensync.Gensync<
                [filename: string, opts?: InputOptions],
                FileResult,
                any
                >;

                  variable transformFromAst

                  const transformFromAst: TransformFromAst;

                    variable transformFromAstRunner

                    const transformFromAstRunner: gensync.Gensync<
                    [ast: any, code: string, opts: InputOptions],
                    FileResult,
                    any
                    >;

                      variable transformRunner

                      const transformRunner: gensync.Gensync<
                      [code: string, opts?: InputOptions],
                      FileResult,
                      any
                      >;

                        variable version

                        const version: string;

                          Functions

                          function assertVersion

                          assertVersion: (range: string | number) => void;

                            function buildExternalHelpers

                            buildExternalHelpers: (
                            allowlist?: string[],
                            outputType?: 'global' | 'module' | 'umd' | 'var'
                            ) => string;

                              function createConfigItem

                              createConfigItem: (
                              target: PluginTarget,
                              options: Parameters<typeof createConfigItem$1>[1],
                              callback?: (err: Error, val: ConfigItem<PluginAPI> | null) => void
                              ) => void;

                                function createConfigItem$1

                                createConfigItem$1: <API>(
                                value: PluginItem | PresetItem,
                                { dirname, type }?: { dirname?: string; type?: 'preset' | 'plugin' }
                                ) => Handler<ConfigItem<API>>;
                                • Create a config item using the same value format used in Babel's config files. Items returned from this function should be cached by the caller ideally, as recreating the config item will mean re-resolving the item and re-evaluating the plugin/preset function.

                                function createConfigItemAsync

                                createConfigItemAsync: (
                                ...args: Parameters<typeof createConfigItemRunner.async>
                                ) => Promise<ConfigItem<unknown>>;

                                  function createConfigItemSync

                                  createConfigItemSync: (
                                  ...args: Parameters<typeof createConfigItemRunner.sync>
                                  ) => ConfigItem<unknown>;

                                    function getEnv

                                    getEnv: (defaultValue?: string) => string;

                                      function loadOptions

                                      loadOptions: (
                                      opts: Parameters<typeof loadOptionsImpl>[0],
                                      callback?: (err: Error, val: ResolvedOptions | null) => void
                                      ) => void;

                                        function loadOptionsAsync

                                        loadOptionsAsync: (
                                        ...args: Parameters<typeof loadOptionsRunner.async>
                                        ) => Promise<ResolvedOptions | null>;

                                          function loadOptionsImpl

                                          loadOptionsImpl: (
                                          opts: InputOptions | null | undefined
                                          ) => Handler<ResolvedOptions>;

                                            function loadOptionsSync

                                            loadOptionsSync: (
                                            ...args: Parameters<typeof loadOptionsRunner.sync>
                                            ) => ResolvedOptions | null;

                                              function loadPartialConfig

                                              loadPartialConfig: (
                                              opts: Parameters<typeof loadPartialConfig$1>[0],
                                              callback?: (err: Error, val: PartialConfig | null) => void
                                              ) => void;

                                                function loadPartialConfig$1

                                                loadPartialConfig$1: (opts?: InputOptions) => Handler<PartialConfig>;

                                                  function loadPartialConfigAsync

                                                  loadPartialConfigAsync: (
                                                  ...args: Parameters<typeof loadPartialConfigRunner.async>
                                                  ) => Promise<PartialConfig | null>;

                                                    function loadPartialConfigSync

                                                    loadPartialConfigSync: (
                                                    ...args: Parameters<typeof loadPartialConfigRunner.sync>
                                                    ) => PartialConfig | null;

                                                      function parseAsync

                                                      parseAsync: (
                                                      ...args: Parameters<typeof parseRunner.async>
                                                      ) => Promise<ParseResult | null>;

                                                        function parseSync

                                                        parseSync: (...args: Parameters<typeof parseRunner.sync>) => ParseResult | null;

                                                          function resolvePlugin

                                                          resolvePlugin: (name: string, dirname: string) => string;

                                                            function resolvePreset

                                                            resolvePreset: (name: string, dirname: string) => string;

                                                              function transformAsync

                                                              transformAsync: (
                                                              ...args: Parameters<typeof transformRunner.async>
                                                              ) => Promise<FileResult | null>;

                                                                function transformFile

                                                                transformFile: {
                                                                (filename: string, callback: FileResultCallback): void;
                                                                (filename: string, opts: InputOptions, callback: FileResultCallback): void;
                                                                };

                                                                  function transformFileAsync

                                                                  transformFileAsync: (
                                                                  ...args: Parameters<typeof transformFileRunner.async>
                                                                  ) => Promise<FileResult | null>;

                                                                    function transformFileSync

                                                                    transformFileSync: (
                                                                    ...args: Parameters<typeof transformFileRunner.sync>
                                                                    ) => FileResult | null;

                                                                      function transformFromAstAsync

                                                                      transformFromAstAsync: (
                                                                      ...args: Parameters<typeof transformFromAstRunner.async>
                                                                      ) => Promise<FileResult | null>;

                                                                        function transformFromAstSync

                                                                        transformFromAstSync: (
                                                                        ...args: Parameters<typeof transformFromAstRunner.sync>
                                                                        ) => FileResult | null;

                                                                          function transformSync

                                                                          transformSync: (
                                                                          ...args: Parameters<typeof transformRunner.sync>
                                                                          ) => FileResult | null;

                                                                            Classes

                                                                            class ConfigItem

                                                                            class ConfigItem<API> {}
                                                                            • A public representation of a plugin/preset that will _eventually_ be load. Users can use this to interact with the results of a loaded Babel configuration.

                                                                              Any changes to public properties of this class should be considered a breaking change to Babel's API.

                                                                            constructor

                                                                            constructor(descriptor: UnloadedDescriptor<API, object>);

                                                                              property [CONFIG_ITEM_BRAND]

                                                                              [CONFIG_ITEM_BRAND]: boolean;
                                                                              • Used to detect ConfigItem instances from other Babel instances.

                                                                              property dirname

                                                                              dirname: string;
                                                                              • The directory that the options for this item are relative to.

                                                                              property file

                                                                              file: void | { request: string; resolved: string };
                                                                              • Data about the file that the item was loaded from, if Babel knows it.

                                                                              property name

                                                                              name: string | void;
                                                                              • Get the name of the plugin, if the user gave it one.

                                                                              property options

                                                                              options: false | void | object;
                                                                              • The options, if any, that were passed to the item. Mutating this will lead to undefined behavior.

                                                                                "false" means that this item has been disabled.

                                                                              property value

                                                                              value: object | Function;
                                                                              • The resolved value of the item itself.

                                                                              class File

                                                                              class File {}

                                                                                constructor

                                                                                constructor(options: ResolvedOptions, { code, ast, inputMap }: NormalizedFile);

                                                                                  property ast

                                                                                  ast: t.File;

                                                                                    property code

                                                                                    code: string;

                                                                                      property declarations

                                                                                      declarations: Record<string, t.Identifier>;

                                                                                        property hub

                                                                                        hub: any;

                                                                                          property inputMap

                                                                                          inputMap: any;

                                                                                            property metadata

                                                                                            metadata: Record<string, any>;

                                                                                              property opts

                                                                                              opts: ResolvedOptions;

                                                                                                property path

                                                                                                path: NodePath<t.Program>;

                                                                                                  property scope

                                                                                                  scope: Scope;

                                                                                                    property shebang

                                                                                                    shebang: string;
                                                                                                    • Provide backward-compatible access to the interpreter directive handling in Babel 6.x. If you are writing a plugin for Babel 7.x or higher, it would be best to use 'program.interpreter' directly.

                                                                                                    method addHelper

                                                                                                    addHelper: (name: string) => t.Identifier;

                                                                                                      method availableHelper

                                                                                                      availableHelper: (name: string, versionRange?: string | null) => boolean;
                                                                                                      • Check if a given helper is available in @babel/core's helper list.

                                                                                                        This _also_ allows you to pass a Babel version specifically. If the helper exists, but was not available for the full given range, it will be considered unavailable.

                                                                                                      method buildCodeFrameError

                                                                                                      buildCodeFrameError: (
                                                                                                      node: t.Node | undefined | null,
                                                                                                      msg: string,
                                                                                                      _Error?: typeof Error
                                                                                                      ) => Error;

                                                                                                        method get

                                                                                                        get: (key: unknown) => any;

                                                                                                          method has

                                                                                                          has: (key: unknown) => boolean;

                                                                                                            method set

                                                                                                            set: (key: unknown, val: unknown) => void;

                                                                                                              class PartialConfig

                                                                                                              class PartialConfig {}

                                                                                                                constructor

                                                                                                                constructor(
                                                                                                                options: NormalizedOptions,
                                                                                                                babelrc: string,
                                                                                                                ignore: string,
                                                                                                                config: string,
                                                                                                                fileHandling: FileHandling,
                                                                                                                files: Set<string>
                                                                                                                );

                                                                                                                  property babelignore

                                                                                                                  babelignore: string;

                                                                                                                    property babelrc

                                                                                                                    babelrc: string;

                                                                                                                      property config

                                                                                                                      config: string;

                                                                                                                        property fileHandling

                                                                                                                        fileHandling: FileHandling;

                                                                                                                          property files

                                                                                                                          files: Set<string>;

                                                                                                                            property options

                                                                                                                            options: NormalizedOptions;
                                                                                                                            • These properties are public, so any changes to them should be considered a breaking change to Babel's API.

                                                                                                                            method hasFilesystemConfig

                                                                                                                            hasFilesystemConfig: () => boolean;
                                                                                                                            • Returns true if there is a config file in the filesystem for this config.

                                                                                                                            class PluginPass

                                                                                                                            class PluginPass<Options = object> {}

                                                                                                                              constructor

                                                                                                                              constructor(file: File, key: string, options: {}, isAsync: boolean);

                                                                                                                                property cwd

                                                                                                                                cwd: string;
                                                                                                                                • The working directory that Babel's programmatic options are loaded relative to.

                                                                                                                                property file

                                                                                                                                file: File;

                                                                                                                                  property filename

                                                                                                                                  filename: string;
                                                                                                                                  • The absolute path of the file being compiled.

                                                                                                                                  property isAsync

                                                                                                                                  isAsync: boolean;
                                                                                                                                  • Is Babel executed in async mode or not.

                                                                                                                                  property key

                                                                                                                                  key: string;

                                                                                                                                    property opts

                                                                                                                                    opts: Partial<Options>;

                                                                                                                                      method addHelper

                                                                                                                                      addHelper: (name: string) => t.Identifier;

                                                                                                                                        method availableHelper

                                                                                                                                        availableHelper: (name: string, versionRange?: string | null) => boolean;

                                                                                                                                          method buildCodeFrameError

                                                                                                                                          buildCodeFrameError: (
                                                                                                                                          node: t.Node | undefined | null,
                                                                                                                                          msg: string,
                                                                                                                                          _Error?: typeof Error
                                                                                                                                          ) => Error;

                                                                                                                                            method get

                                                                                                                                            get: (key: unknown) => any;

                                                                                                                                              method set

                                                                                                                                              set: (key: unknown, val: unknown) => void;

                                                                                                                                                Type Aliases

                                                                                                                                                type CallerMetadata

                                                                                                                                                type CallerMetadata = {
                                                                                                                                                name: string;
                                                                                                                                                supportsStaticESM?: boolean;
                                                                                                                                                supportsDynamicImport?: boolean;
                                                                                                                                                supportsTopLevelAwait?: boolean;
                                                                                                                                                supportsExportNamespaceFrom?: boolean;
                                                                                                                                                };

                                                                                                                                                  type ConfigAPI

                                                                                                                                                  type ConfigAPI = {
                                                                                                                                                  version: string;
                                                                                                                                                  cache: SimpleCacheConfigurator;
                                                                                                                                                  env: EnvFunction;
                                                                                                                                                  async: () => boolean;
                                                                                                                                                  assertVersion: typeof assertVersion;
                                                                                                                                                  caller: CallerFactory;
                                                                                                                                                  };

                                                                                                                                                    type FileResult

                                                                                                                                                    type FileResult = {
                                                                                                                                                    metadata: Record<string, any>;
                                                                                                                                                    options: Record<string, any>;
                                                                                                                                                    ast: t.File | null;
                                                                                                                                                    code: string | null;
                                                                                                                                                    map: GeneratorResult['map'];
                                                                                                                                                    sourceType: Exclude<SourceTypeOption, 'unambiguous'>;
                                                                                                                                                    externalDependencies: Set<string>;
                                                                                                                                                    };

                                                                                                                                                      type InputOptions

                                                                                                                                                      type InputOptions = {
                                                                                                                                                      cwd?: string;
                                                                                                                                                      filename?: string;
                                                                                                                                                      filenameRelative?: string;
                                                                                                                                                      babelrc?: boolean;
                                                                                                                                                      babelrcRoots?: BabelrcSearch;
                                                                                                                                                      configFile?: ConfigFileSearch;
                                                                                                                                                      root?: string;
                                                                                                                                                      rootMode?: RootMode;
                                                                                                                                                      code?: boolean;
                                                                                                                                                      ast?: boolean;
                                                                                                                                                      cloneInputAst?: boolean;
                                                                                                                                                      inputSourceMap?: RootInputSourceMapOption;
                                                                                                                                                      envName?: string;
                                                                                                                                                      caller?: CallerMetadata;
                                                                                                                                                      extends?: string;
                                                                                                                                                      env?: EnvSet<InputOptions>;
                                                                                                                                                      ignore?: MatchItem[];
                                                                                                                                                      only?: MatchItem[];
                                                                                                                                                      overrides?: InputOptions[];
                                                                                                                                                      showIgnoredFiles?: boolean;
                                                                                                                                                      test?: ConfigApplicableTest;
                                                                                                                                                      include?: ConfigApplicableTest;
                                                                                                                                                      exclude?: ConfigApplicableTest;
                                                                                                                                                      presets?: PresetItem[];
                                                                                                                                                      plugins?: PluginItem[];
                                                                                                                                                      passPerPreset?: boolean;
                                                                                                                                                      assumptions?: Assumptions;
                                                                                                                                                      targets?: TargetsListOrObject;
                                                                                                                                                      browserslistConfigFile?: ConfigFileSearch;
                                                                                                                                                      browserslistEnv?: string;
                                                                                                                                                      retainLines?: GeneratorOptions['retainLines'];
                                                                                                                                                      comments?: GeneratorOptions['comments'];
                                                                                                                                                      shouldPrintComment?: GeneratorOptions['shouldPrintComment'];
                                                                                                                                                      compact?: GeneratorOptions['compact'];
                                                                                                                                                      minified?: GeneratorOptions['minified'];
                                                                                                                                                      auxiliaryCommentBefore?: GeneratorOptions['auxiliaryCommentBefore'];
                                                                                                                                                      auxiliaryCommentAfter?: GeneratorOptions['auxiliaryCommentAfter'];
                                                                                                                                                      sourceType?: SourceTypeOption;
                                                                                                                                                      wrapPluginVisitorMethod?: VisitWrapper | null;
                                                                                                                                                      highlightCode?: boolean;
                                                                                                                                                      sourceMaps?: SourceMapsOption;
                                                                                                                                                      sourceMap?: SourceMapsOption;
                                                                                                                                                      sourceFileName?: string;
                                                                                                                                                      sourceRoot?: string;
                                                                                                                                                      parserOpts?: ParserOptions;
                                                                                                                                                      generatorOpts?: GeneratorOptions;
                                                                                                                                                      };

                                                                                                                                                        type NormalizedOptions

                                                                                                                                                        type NormalizedOptions = Omit<InputOptions, 'presets' | 'plugins'> & {
                                                                                                                                                        assumptions: Assumptions;
                                                                                                                                                        targets: Targets;
                                                                                                                                                        cloneInputAst: boolean;
                                                                                                                                                        babelrc: false;
                                                                                                                                                        configFile: false;
                                                                                                                                                        browserslistConfigFile: false;
                                                                                                                                                        passPerPreset: false;
                                                                                                                                                        envName: string;
                                                                                                                                                        cwd: string;
                                                                                                                                                        root: string;
                                                                                                                                                        rootMode: 'root';
                                                                                                                                                        filename: string | undefined;
                                                                                                                                                        presets: ConfigItem<PresetAPI>[];
                                                                                                                                                        plugins: ConfigItem<PluginAPI>[];
                                                                                                                                                        };

                                                                                                                                                          type PluginAPI

                                                                                                                                                          type PluginAPI = PluginAPI$1 & typeof __;

                                                                                                                                                            type PluginItem

                                                                                                                                                            type PluginItem<Option = object> =
                                                                                                                                                            | ConfigItem<PluginAPI>
                                                                                                                                                            | PluginTarget<Option>
                                                                                                                                                            | [PluginTarget<Option>, Option]
                                                                                                                                                            | [PluginTarget<Option>, Option, string];

                                                                                                                                                              type PluginObject

                                                                                                                                                              type PluginObject<S extends PluginPass = PluginPass> = {
                                                                                                                                                              name?: string;
                                                                                                                                                              manipulateOptions?: (
                                                                                                                                                              options: ResolvedOptions & {
                                                                                                                                                              generatorOpts: GeneratorOptions;
                                                                                                                                                              },
                                                                                                                                                              parserOpts: ParserOptions & {
                                                                                                                                                              plugins: NonNullable<ParserOptions['plugins']>;
                                                                                                                                                              }
                                                                                                                                                              ) => void;
                                                                                                                                                              pre?: (this: S, file: File) => void | Promise<void>;
                                                                                                                                                              post?: (this: S, file: File) => void | Promise<void>;
                                                                                                                                                              inherits?: (api: PluginAPI, options: any, dirname: string) => PluginObject;
                                                                                                                                                              visitor?: Visitor$1<S>;
                                                                                                                                                              parserOverride?: (
                                                                                                                                                              ...args: [...Parameters<typeof parse$1>, typeof parse$1]
                                                                                                                                                              ) => ReturnType<typeof parse$1>;
                                                                                                                                                              generatorOverride?: (
                                                                                                                                                              ast: File['ast'],
                                                                                                                                                              generatorOpts: GeneratorOptions,
                                                                                                                                                              code: File['code'],
                                                                                                                                                              generate: typeof babelGenerator
                                                                                                                                                              ) => GeneratorResult;
                                                                                                                                                              };

                                                                                                                                                                type PluginTarget

                                                                                                                                                                type PluginTarget<Option = object> =
                                                                                                                                                                | string
                                                                                                                                                                | MaybeDefaultProperty<
                                                                                                                                                                (api: PluginAPI, options: Option, dirname: string) => PluginObject
                                                                                                                                                                >;

                                                                                                                                                                  type PresetAPI

                                                                                                                                                                  type PresetAPI = PresetAPI$1 & typeof __;

                                                                                                                                                                    type PresetItem

                                                                                                                                                                    type PresetItem<Option = object> =
                                                                                                                                                                    | ConfigItem<PresetAPI>
                                                                                                                                                                    | PresetTarget<Option>
                                                                                                                                                                    | [PresetTarget<Option>, Option]
                                                                                                                                                                    | [PresetTarget<Option>, Option, string];

                                                                                                                                                                      type PresetObject

                                                                                                                                                                      type PresetObject = {
                                                                                                                                                                      overrides?: PresetObject[];
                                                                                                                                                                      test?: ConfigApplicableTest;
                                                                                                                                                                      plugins?: PluginItem[];
                                                                                                                                                                      };

                                                                                                                                                                        type PresetTarget

                                                                                                                                                                        type PresetTarget<Option = object> =
                                                                                                                                                                        | string
                                                                                                                                                                        | MaybeDefaultProperty<
                                                                                                                                                                        (api: PresetAPI, options: Option, dirname: string) => PresetObject
                                                                                                                                                                        >;

                                                                                                                                                                          type Visitor

                                                                                                                                                                          type Visitor<S = unknown> = _babel_traverse.Visitor<S>;

                                                                                                                                                                            type VisitorBase

                                                                                                                                                                            type VisitorBase<S = unknown> = _babel_traverse.VisitorBase<S>;

                                                                                                                                                                              Package Files (1)

                                                                                                                                                                              Dependencies (16)

                                                                                                                                                                              Dev Dependencies (14)

                                                                                                                                                                              Peer Dependencies (0)

                                                                                                                                                                              No peer dependencies.

                                                                                                                                                                              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/core.

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