diff --git a/types/babel-plugin-macros/babel-plugin-macros-tests.ts b/types/babel-plugin-macros/babel-plugin-macros-tests.ts new file mode 100644 index 0000000000..aa7a3858b9 --- /dev/null +++ b/types/babel-plugin-macros/babel-plugin-macros-tests.ts @@ -0,0 +1,14 @@ +import { createMacro, MacroError } from 'babel-plugin-macros'; + +const macro = createMacro( + ({ references, state, babel }) => { + references.forEach(() => {}); + references.default.forEach(() => {}); + state.abc = 123; + babel.parse("console.log('Hello world!')"); + throw new MacroError('testing'); + }, + { configName: 'test' }, +); + +macro() === 'Hello world!'; diff --git a/types/babel-plugin-macros/index.d.ts b/types/babel-plugin-macros/index.d.ts new file mode 100644 index 0000000000..ef48280994 --- /dev/null +++ b/types/babel-plugin-macros/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for babel-plugin-macros 2.6 +// Project: https://github.com/kentcdodds/babel-plugin-macros +// Definitions by: Billy Kwok +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.9 +import * as Babel from '@babel/core'; + +type References = Babel.NodePath[]; + +interface Options { + configName?: string; +} + +interface MacroParams { + references: { default: References } & References; + state: any; + babel: typeof Babel; +} + +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; + +declare namespace babel_plugin_macros { + class MacroError extends Error {} + + function createMacro(handler: MacroHandler, options?: Options): any; +} + +export = babel_plugin_macros; diff --git a/types/babel-plugin-macros/tsconfig.json b/types/babel-plugin-macros/tsconfig.json new file mode 100644 index 0000000000..10c6998332 --- /dev/null +++ b/types/babel-plugin-macros/tsconfig.json @@ -0,0 +1,37 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "@babel/core": [ + "babel__core" + ], + "@babel/generator": [ + "babel__generator" + ], + "@babel/template": [ + "babel__template" + ], + "@babel/traverse": [ + "babel__traverse" + ] + } + }, + "files": [ + "index.d.ts", + "babel-plugin-macros-tests.ts" + ] +} diff --git a/types/babel-plugin-macros/tslint.json b/types/babel-plugin-macros/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/babel-plugin-macros/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }