From b8d2701d9be4e4e2e36c133f26b71385ee8ef8d7 Mon Sep 17 00:00:00 2001 From: Cameron Yan Date: Wed, 25 Sep 2019 03:11:08 +1000 Subject: [PATCH] Updated typings for @babel/generator@^7.6.0. (#38477) --- .../babel__generator-tests.ts | 16 ++++-- types/babel__generator/index.d.ts | 51 ++++++++++++++----- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/types/babel__generator/babel__generator-tests.ts b/types/babel__generator/babel__generator-tests.ts index 728638c868..a70eaececf 100644 --- a/types/babel__generator/babel__generator-tests.ts +++ b/types/babel__generator/babel__generator-tests.ts @@ -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; diff --git a/types/babel__generator/index.d.ts b/types/babel__generator/index.d.ts index d229c9855f..f98a49ef2d 100644 --- a/types/babel__generator/index.d.ts +++ b/types/babel__generator/index.d.ts @@ -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 // Johnny Estilles // Melvin Groenhoff +// Cameron Yan // 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;