From d4916b921d3c8f1419045fdf6d4ef2ceaac8b225 Mon Sep 17 00:00:00 2001 From: Jake Runzer Date: Thu, 9 Jan 2020 19:41:01 +0000 Subject: [PATCH] babel-plugin-macros: Export all types and fix References type (#41422) * update babel-plugin-macros types to match docs * babel-plugin-macros update version and ts version * babel-plugin-macros update createMacro and MacroError types * babel-plugin-macros: revert typescript version to 2.9 --- .../babel-plugin-macros-tests.ts | 4 +-- types/babel-plugin-macros/index.d.ts | 31 +++++++------------ 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/types/babel-plugin-macros/babel-plugin-macros-tests.ts b/types/babel-plugin-macros/babel-plugin-macros-tests.ts index aa7a3858b9..b0d993cb11 100644 --- a/types/babel-plugin-macros/babel-plugin-macros-tests.ts +++ b/types/babel-plugin-macros/babel-plugin-macros-tests.ts @@ -1,8 +1,8 @@ -import { createMacro, MacroError } from 'babel-plugin-macros'; +import { createMacro, MacroError, References, Options, MacroParams, MacroHandler } from 'babel-plugin-macros'; const macro = createMacro( ({ references, state, babel }) => { - references.forEach(() => {}); + Object.keys(references).forEach(() => {}); references.default.forEach(() => {}); state.abc = 123; babel.parse("console.log('Hello world!')"); diff --git a/types/babel-plugin-macros/index.d.ts b/types/babel-plugin-macros/index.d.ts index ef48280994..2db0ea45b8 100644 --- a/types/babel-plugin-macros/index.d.ts +++ b/types/babel-plugin-macros/index.d.ts @@ -1,36 +1,27 @@ -// Type definitions for babel-plugin-macros 2.6 +// Type definitions for babel-plugin-macros 2.8 // Project: https://github.com/kentcdodds/babel-plugin-macros // Definitions by: Billy Kwok +// Jake Runzer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.9 import * as Babel from '@babel/core'; -type References = Babel.NodePath[]; +export interface References { + [key: string]: Babel.NodePath[]; +} -interface Options { +export interface Options { configName?: string; } -interface MacroParams { - references: { default: References } & References; +export interface MacroParams { + references: { default: Babel.NodePath[] } & References; state: any; babel: typeof Babel; } -type MacroHandler = (params: MacroParams) => void; +export type MacroHandler = (params: MacroParams) => void; -declare function babel_plugin_macros( - babel: typeof Babel, - ref: { - require: (path: string) => any; - resolvePath: (src: string, baseDir: string) => any; - }, -): Babel.PluginObj; +export class MacroError extends Error {} -declare namespace babel_plugin_macros { - class MacroError extends Error {} - - function createMacro(handler: MacroHandler, options?: Options): any; -} - -export = babel_plugin_macros; +export function createMacro(handler: MacroHandler, options?: Options): any;