@babel/generator

  • Version 8.0.0
  • Published
  • 456 kB
  • 6 dependencies
  • MIT license

Install

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

Overview

Turns an AST into code.

Index

Functions

function generate

generate: (
ast: t.Node,
opts?: GeneratorOptions,
code?: string | Record<string, string>
) => GeneratorResult;
  • Turns an AST into code, maintaining sourcemaps, user preferences, and valid output.

    Parameter ast

    the abstract syntax tree from which to generate output code.

    Parameter opts

    used for specifying options for code generation.

    Parameter code

    the original source code, used for source maps.

    Returns

    - an object containing the output code and source map.

Interfaces

interface GeneratorOptions

interface GeneratorOptions {}

    property auxiliaryCommentAfter

    auxiliaryCommentAfter?: string;
    • Optional string to add as a block comment at the end of the output file.

    property auxiliaryCommentBefore

    auxiliaryCommentBefore?: string;
    • Optional string to add as a block comment at the start of the output file.

    property comments

    comments?: boolean;
    • Should comments be included in output? Defaults to true.

    property compact

    compact?: boolean | 'auto';
    • Set to true to avoid adding whitespace for formatting. Defaults to the value of opts.minified.

    property concise

    concise?: boolean;
    • Set to true to reduce whitespace (but not as much as opts.compact). Defaults to false.

    property experimental_preserveFormat

    experimental_preserveFormat?: boolean;
    • Preserve the input code format while printing the transformed code. This is experimental, and may have breaking changes in future patch releases. It will be removed in a future minor release, when it will graduate to stable.

    property filename

    filename?: string;
    • Used in warning messages

    property inputSourceMap

    inputSourceMap?: any;

      property jsescOption

      jsescOption?: Opts;
      • Options for outputting jsesc representation.

      property minified

      minified?: boolean;
      • Should the output be minified. Defaults to false.

      property retainFunctionParens

      retainFunctionParens?: boolean;
      • Retain parens around function expressions (could be used to change engine parsing behavior) Defaults to false.

      property retainLines

      retainLines?: boolean;
      • Attempt to use the same line numbers in the output code as in the source code (helps preserve stack traces). Defaults to false.

      property sourceFileName

      sourceFileName?: string;
      • The filename for the source code (i.e. the code in the code argument). This will only be used if code is a string.

      property sourceMaps

      sourceMaps?: boolean;
      • Enable generating source maps. Defaults to false.

      property sourceRoot

      sourceRoot?: string;
      • A root for all relative URLs in the source map.

      property topicToken

      topicToken?: '%' | '#' | '@@' | '^^' | '^';
      • For use with the Hack-style pipe operator. Changes what token is used for pipe bodies’ topic references.

      method shouldPrintComment

      shouldPrintComment: (comment: string) => boolean;
      • Function that takes a comment (as a string) and returns true if the comment should be included in the output. By default, comments are included if opts.comments is true or if opts.minified is false and the comment contains @preserve or @license.

      interface GeneratorResult

      interface GeneratorResult {}

        property code

        code: string;

          property decodedMap

          decodedMap: DecodedSourceMap | undefined;

            property map

            map: EncodedSourceMap | null;

              property rawMappings

              rawMappings: Mapping[] | undefined;

                Package Files (1)

                Dependencies (6)

                Dev Dependencies (5)

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

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