Merge pull request #26158 from ksoldau/babel-core-types

[babel-core] Add missing properties to BabelFileResult
This commit is contained in:
Benjamin Lichtman
2018-05-31 09:17:12 -07:00
committed by GitHub
2 changed files with 27 additions and 2 deletions

View File

@@ -1,13 +1,15 @@
import * as babel from "babel-core";
// Example from https://github.com/babel/babel/tree/master/packages/babel-core
// Slightly modified example from https://github.com/babel/babel/tree/master/packages/babel-core
const code = `class Example {}`;
const result = babel.transform(code, { /* options */ });
result.code; // Generated code
result.map; // Sourcemap
result.ast; // AST
result.ignored;
result.metadata;
// Examples from http://babeljs.io/docs/usage/api/
// Slightly modified examples from http://babeljs.io/docs/usage/api/
const options: babel.TransformOptions = {
plugins: [
"es2015-arrow-functions",
@@ -24,6 +26,8 @@ babel.transformFile("filename.js", options, (err, result) => {
result.code;
result.map;
result.ast;
result.ignored;
result.metadata;
});
babel.transformFileSync("filename.js", options).code;

View File

@@ -169,9 +169,30 @@ export interface TransformOptions {
wrapPluginVisitorMethod?(pluginAlias: string, visitorType: 'enter' | 'exit', callback: (path: NodePath, state: any) => void): (path: NodePath, state: any) => void ;
}
export interface BabelFileModulesMetadata {
imports: object[];
exports: {
exported: object[],
specifiers: object[]
};
}
export interface BabelFileMetadata {
usedHelpers: string[];
marked: Array<{
type: string;
message: string;
loc: object;
}>;
modules: BabelFileModulesMetadata;
}
export interface BabelFileResult {
ast?: Node;
code?: string;
ignored?: boolean;
map?: object;
metadata?: BabelFileMetadata;
}
export as namespace babel;