Skip to content

Latest commit

 

History

History
186 lines (127 loc) · 4.67 KB

File metadata and controls

186 lines (127 loc) · 4.67 KB

transmute (exported Transmute)

The transmute function; star of the library. See Transmute.

const transmute: Transmute;

Transmute (exported interface)

The interface of the transmute function, which has 4 different call signatures.

interface Transmute {
  (code: string, transform: (ast: AST) => Promise<void>): Promise<Result>;
  (
    code: string,
    options: Options,
    transform: (ast: types.Node) => Promise<void>,
  ): Promise<Result>;
  (code: string, transform: (ast: AST) => void): Result;
  (
    code: string,
    options: Options,
    transform: (ast: types.Node) => void,
  ): Result;
}

Transmute(...) (call signature)

Parses code into an AST, then passes that to transform, which is expected to mutate the AST somehow.

Once the Promise returned by transform has resolved, it converts the AST back into a string, and returns you a Result, which has the transformed string on it as its code property.

(code: string, transform: (ast: AST) => Promise<void>): Promise<Result>;

Transmute(...) (call signature)

Parses code into an AST, then passes that to transform, which is expected to mutate the AST somehow.

Once the Promise returned by transform has resolved, it converts the AST back into a string, and returns you a Result, which has the transformed string on it as its code property.

The contents of options will determine what syntax options to use to parse the code, and whether to consume/generate source maps. See Options for more details.

(code: string, options: Options, transform: (ast: types.Node) => Promise<void>): Promise<Result>;

Transmute(...) (call signature)

Parses code into an AST, then passes that to transform, which is expected to mutate the AST somehow.

Then, it converts the AST back into a string, and returns you a Result, which has the transformed string on it as its code property.

(code: string, transform: (ast: AST) => void): Result;

Transmute(...) (call signature)

Parses code into an AST, then passes that to transform, which is expected to mutate the AST somehow.

Then, it converts the AST back into a string, and returns you a Result, which has the transformed string on it as its code property.

The contents of options will determine what syntax options to use to parse the code, and whether to consume/generate source maps. See Options for more details.

(code: string, options: Options, transform: (ast: types.Node) => void): Result;

parse (exported binding)

Parser (code-to-AST) function used by transmute. See parse.

export { parse };

Parse (exported binding)

Type of the parse function. See Parse.

export { Parse };

print (exported binding)

Printer (AST-to-code) function used by transmute. See print.

export { print };

traverse (exported binding)

Re-export of @babel/traverse's default export.

export { traverse };

types (exported binding)

Contains the named exports of both @babel/types and @babel/traverse.

export { types };

template (exported binding)

Re-export of @babel/template's default export.

export { template };

AST (exported type)

Type returned by parse. See AST.

export { type AST };

Options (exported type)

Type used by transmute, parse, and print. See Options.

export { type Options };

Result (exported type)

Type returned by print. See Result.

export { type Result };

clone (exported binding)

AST node cloner utility function. See clone.

export { clone };

hasShape (exported binding)

Deep object property comparison checker utility function. See hasShape.

export { hasShape };

mapFiles (exported binding)

Bulk file content transform utility functions. See mapFiles.fromPaths.

export { mapFiles };