mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
Add react helpers to babel-types
This commit is contained in:
@@ -29,3 +29,30 @@ t.assertBinaryExpression(ast);
|
||||
t.assertBinaryExpression(ast, { operator: "*" });
|
||||
|
||||
var exp: t.Expression = t.nullLiteral();
|
||||
|
||||
// React examples:
|
||||
|
||||
// https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-plugin-transform-react-inline-elements/src/index.js#L61
|
||||
traverse(ast, {
|
||||
JSXElement(path, file) {
|
||||
const { node } = path;
|
||||
const open = node.openingElement;
|
||||
|
||||
// init
|
||||
const type = open.name;
|
||||
|
||||
let newType: t.StringLiteral;
|
||||
if (t.isJSXIdentifier(type) && t.react.isCompatTag(type.name)) {
|
||||
newType = t.stringLiteral(type.name);
|
||||
}
|
||||
|
||||
const args: any[] = [];
|
||||
if (node.children.length) {
|
||||
const children = t.react.buildChildren(node);
|
||||
args.push(
|
||||
t.unaryExpression("void", t.numericLiteral(0), true),
|
||||
...children,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Vendored
+11
-2
@@ -1,6 +1,8 @@
|
||||
// Type definitions for babel-types v6.7
|
||||
// Type definitions for babel-types v6.25
|
||||
// Project: https://github.com/babel/babel/tree/master/packages/babel-types
|
||||
// Definitions by: Troy Gerwien <https://github.com/yortus>, Sam Baxter <https://github.com/baxtersa>
|
||||
// Definitions by: Troy Gerwien <https://github.com/yortus>
|
||||
// Sam Baxter <https://github.com/baxtersa>
|
||||
// Marvin Hagemeister <https://github.com/marvinhagemeister>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface Comment {
|
||||
@@ -1226,6 +1228,13 @@ export function isUser(node: Object, opts?: Object): boolean;
|
||||
export function isGenerated(node: Object, opts?: Object): boolean;
|
||||
export function isPure(node: Object, opts?: Object): boolean;
|
||||
|
||||
// React specific
|
||||
interface ReactHelpers {
|
||||
isCompatTag(tagName?: string): boolean;
|
||||
buildChildren(node: Object): Object[];
|
||||
}
|
||||
export const react: ReactHelpers;
|
||||
|
||||
export function assertArrayExpression(node: Object, opts?: Object): void;
|
||||
export function assertAssignmentExpression(node: Object, opts?: Object): void;
|
||||
export function assertBinaryExpression(node: Object, opts?: Object): void;
|
||||
|
||||
Reference in New Issue
Block a user