add types for babel-plugin-macros (#39151)

* add types for babel-plugin-macros

* rename babel-plugin-macros-test.ts to babel-plugin-macros-tests.ts

* add paths in tsconfig.json

* remove patch version from version string

* remove unnecessary generics

* fix import module name and minimum TypeScript version

* update minimum TypeScript version to 2.9
This commit is contained in:
Billy Kwok
2019-10-16 11:44:50 -07:00
committed by Andrew Branch
parent a70a4e352f
commit 5018a8e150
4 changed files with 88 additions and 0 deletions
@@ -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!';
+36
View File
@@ -0,0 +1,36 @@
// Type definitions for babel-plugin-macros 2.6
// Project: https://github.com/kentcdodds/babel-plugin-macros
// Definitions by: Billy Kwok <https://github.com/billykwok>
// 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;
+37
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }