Updated typings for @babel/generator@^7.6.0. (#38477)

This commit is contained in:
Cameron Yan 2019-09-25 03:11:08 +10:00 committed by Ben Lichtman
parent d14ef7bddd
commit b8d2701d9b
2 changed files with 48 additions and 19 deletions

View File

@ -10,14 +10,20 @@ ast.loc!.start;
const output = generate(ast, { /* options */ }, code);
// Example from https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-generator
const result = generate(ast, {
// Example (originally) from https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-generator
const result = generate(
ast,
{
retainLines: false,
compact: "auto",
compact: 'auto',
concise: false,
quotes: "double",
jsescOption: {
quotes: 'double',
},
jsonCompatibleStrings: true,
// ...
}, code);
},
code,
);
result.code;
result.map;

View File

@ -1,12 +1,13 @@
// Type definitions for @babel/generator 7.0
// Type definitions for @babel/generator 7.6
// Project: https://github.com/babel/babel/tree/master/packages/babel-generator, https://babeljs.io
// Definitions by: Troy Gerwien <https://github.com/yortus>
// Johnny Estilles <https://github.com/johnnyestilles>
// Melvin Groenhoff <https://github.com/mgroenhoff>
// Cameron Yan <https://github.com/khell>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
import * as t from "@babel/types";
import * as t from '@babel/types';
export interface GeneratorOptions {
/**
@ -32,6 +33,12 @@ export interface GeneratorOptions {
*/
retainLines?: boolean;
/**
* Retain parens around function expressions (could be used to change engine parsing behavior)
* Defaults to `false`.
*/
retainFunctionParens?: boolean;
/**
* Should comments be included in output? Defaults to `true`.
*/
@ -40,7 +47,7 @@ export interface GeneratorOptions {
/**
* Set to true to avoid adding whitespace for formatting. Defaults to the value of `opts.minified`.
*/
compact?: boolean | "auto";
compact?: boolean | 'auto';
/**
* Should the output be minified. Defaults to `false`.
@ -52,11 +59,6 @@ export interface GeneratorOptions {
*/
concise?: boolean;
/**
* The type of quote to use in the output. If omitted, autodetects based on `ast.tokens`.
*/
quotes?: "single" | "double";
/**
* Used in warning messages
*/
@ -67,11 +69,6 @@ export interface GeneratorOptions {
*/
sourceMaps?: boolean;
/**
* The filename of the generated code that the source map will be associated with.
*/
sourceMapTarget?: string;
/**
* A root for all relative URLs in the source map.
*/
@ -87,6 +84,28 @@ export interface GeneratorOptions {
* Set to true to run jsesc with "json": true to print "\u00A9" vs. "©";
*/
jsonCompatibleStrings?: boolean;
/**
* Set to true to enable support for experimental decorators syntax before module exports.
* Defaults to `false`.
*/
decoratorsBeforeExport?: boolean;
/**
* Options for outputting jsesc representation.
*/
jsescOption?: {
/**
* The type of quote to use in the output. If omitted, autodetects based on `ast.tokens`.
*/
quotes?: 'single' | 'double';
/**
* When enabled, the output is a valid JavaScript string literal wrapped in quotes. The type of quotes can be specified through the quotes setting.
* Defaults to `true`.
*/
wrap?: boolean;
};
}
export class CodeGenerator {
@ -101,7 +120,11 @@ export class CodeGenerator {
* @param code - the original source code, used for source maps.
* @returns - an object containing the output code and source map.
*/
export default function generate(ast: t.Node, opts?: GeneratorOptions, code?: string | { [filename: string]: string; }): GeneratorResult;
export default function generate(
ast: t.Node,
opts?: GeneratorOptions,
code?: string | { [filename: string]: string },
): GeneratorResult;
export interface GeneratorResult {
code: string;