Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all missing babel-core option properties and alphabetize for better maintainability. #19428

Merged
merged 5 commits into from
Sep 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
134 changes: 79 additions & 55 deletions types/babel-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ export { t as types };
export type Node = t.Node;
export import template = require('babel-template');
export const version: string;
import traverse, { Visitor } from "babel-traverse";
import traverse, { Visitor, NodePath } from "babel-traverse";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This NodePath isn't used. Did you want to use it for wrapPluginVisitorMethod?

The rest looks great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over from my trying to get wrapPluginVisitorMethod to have better specified types – was going to ask about that actually. The callback function it takes and the function it returns can take any NodePath variant. I couldn't come up with a way to add concrete typing to those functions without enumerating every templated type, like is done in babel-traverse. Do you have a better way to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple NodePath (AKA NodePath<Node>) is okay in this case.

export { traverse, Visitor };
import { BabylonOptions } from "babylon";
export { BabylonOptions };
import { GeneratorOptions } from "babel-generator";
export { GeneratorOptions };

// A babel plugin is a simple function which must return an object matching
// the following interface. Babel will throw if it finds unknown properties.
Expand All @@ -38,14 +42,29 @@ export function transformFileSync(filename: string, opts?: TransformOptions): Ba
export function transformFromAst(ast: Node, code?: string, opts?: TransformOptions): BabelFileResult;

export interface TransformOptions {
/** Filename to use when reading from stdin - this will be used in source-maps, errors etc. Default: "unknown". */
filename?: string;
/** Include the AST in the returned object. Default: `true`. */
ast?: boolean;

/** Filename relative to `sourceRoot`. */
filenameRelative?: string;
/** Attach a comment after all non-user injected code. */
auxiliaryCommentAfter?: string;

/** A source map object that the output source map will be based on. */
inputSourceMap?: object;
/** Attach a comment before all non-user injected code. */
auxiliaryCommentBefore?: string;

/** Specify whether or not to use `.babelrc` and `.babelignore` files. Default: `true`. */
babelrc?: boolean;

/** Enable code generation. Default: `true`. */
code?: boolean;

/** write comments to generated output. Default: `true`. */
comments?: boolean;

/**
* Do not include superfluous whitespace characters and line terminators. When set to `"auto"`, `compact` is set to
* `true` on input sizes of >100KB.
*/
compact?: boolean | "auto";

/**
* This is an object of keys that represent different environments. For example, you may have:
Expand All @@ -55,50 +74,77 @@ export interface TransformOptions {
*/
env?: object;

/** Retain line numbers - will result in really ugly code. Default: `false` */
retainLines?: boolean;
/** A path to an .babelrc file to extend. */
extends?: string;

/** Enable/disable ANSI syntax highlighting of code frames. Default: `true`. */
highlightCode?: boolean;
/** Filename to use when reading from stdin - this will be used in source-maps, errors etc. Default: "unknown". */
filename?: string;

/** List of presets (a set of plugins) to load and use. */
presets?: any[];
/** Filename relative to `sourceRoot`. */
filenameRelative?: string;

/** List of plugins to load and use. */
plugins?: any[];
/** An object containing the options to be passed down to the babel code generator, babel-generator. Default: `{}` */
generatorOpts?: GeneratorOptions;

/**
* Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`.
* If falsy value is returned then the generated module id is used.
*/
getModuleId?(moduleName: string): string;

/** Enable/disable ANSI syntax highlighting of code frames. Default: `true`. */
highlightCode?: boolean;

/** list of glob paths to **not** compile. Opposite to the `only` option. */
ignore?: string[];

/** A source map object that the output source map will be based on. */
inputSourceMap?: object;

/** Should the output be minified. Default: `false` */
minified?: boolean;

/** Specify a custom name for module ids. */
moduleId?: string;

/**
* If truthy, insert an explicit id for modules. By default, all modules are anonymous.
* (Not available for `common` modules).
*/
moduleIds?: boolean;

/** Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions. */
moduleRoot?: string;

/**
* A glob, regex, or mixed array of both, matching paths to only compile. Can also be an array of arrays containing
* paths to explicitly match. When attempting to compile a non-matching file it's returned verbatim.
*/
only?: string | RegExp | Array<string | RegExp>;

/** Enable code generation. Default: `true`. */
code?: boolean;
/** Babylon parser options. */
parserOpts?: BabylonOptions;

/** Include the AST in the returned object. Default: `true`. */
ast?: boolean;
/** List of plugins to load and use. */
plugins?: any[];

/** A path to an .babelrc file to extend. */
extends?: string;
/** List of presets (a set of plugins) to load and use. */
presets?: any[];

/** write comments to generated output. Default: `true`. */
comments?: boolean;
/** Retain line numbers - will result in really ugly code. Default: `false` */
retainLines?: boolean;

/** Resolve a module source ie. import "SOURCE"; to a custom value. */
resolveModuleSource?(source: string, filename: string): string;

/**
* An optional callback that controls whether a comment should be output or not. Called as
* `shouldPrintComment(commentContents)`. **NOTE**: This overrides the `comments` option when used.
*/
shouldPrintComment?(comment: string): boolean;

/**
* Do not include superfluous whitespace characters and line terminators. When set to `"auto"`, `compact` is set to
* `true` on input sizes of >100KB.
*/
compact?: boolean | "auto";
/** Set `sources[0]` on returned source map. */
sourceFileName?: string;

/**
* If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a `sourceMappingURL`
Expand All @@ -110,38 +156,16 @@ export interface TransformOptions {
/** Set `file` on returned source map. */
sourceMapTarget?: string;

/** Set `sources[0]` on returned source map. */
sourceFileName?: string;

/** The root from which all sources are relative. */
sourceRoot?: string;

/** Specify whether or not to use `.babelrc` and `.babelignore` files. Default: `true`. */
babelrc?: boolean;

/** Attach a comment before all non-user injected code. */
auxiliaryCommentBefore?: string;

/** Attach a comment after all non-user injected code. */
auxiliaryCommentAfter?: string;

/**
* Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`.
* If falsy value is returned then the generated module id is used.
*/
getModuleId?(moduleName: string): string;

/** Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions. */
moduleRoot?: string;
/** Indicate the mode the code should be parsed in. Can be either “script” or “module”. Default: "module" */
sourceType?: "script" | "module";

/**
* If truthy, insert an explicit id for modules. By default, all modules are anonymous.
* (Not available for `common` modules).
/** An optional callback that can be used to wrap visitor methods.
* NOTE: This is useful for things like introspection, and not really needed for implementing anything.
*/
moduleIds?: boolean;

/** Specify a custom name for module ids. */
moduleId?: string;
wrapPluginVisitorMethod?(pluginAlias: string, visitorType: 'enter' | 'exit', callback: (path: NodePath, state: any) => void): (path: NodePath, state: any) => void ;
}

export interface BabelFileResult {
Expand Down