|
| 1 | +declare module 'jsx-ast-utils-x' { |
| 2 | + import * as ESTree from 'estree'; |
| 3 | + import * as ESTreeJSX from 'estree-jsx'; |
| 4 | + |
| 5 | + export interface GetPropOptions { |
| 6 | + /** |
| 7 | + * Ignores casing differences in the prop name. Enabled by default. |
| 8 | + * @default true |
| 9 | + */ |
| 10 | + ignoreCase: boolean; |
| 11 | + } |
| 12 | + |
| 13 | + export interface HasPropOptions extends GetPropOptions { |
| 14 | + /** |
| 15 | + * Assumes target property is not in a spread expression applied |
| 16 | + * to the element. For example `<div {...props} />` looking for |
| 17 | + * specific prop here will return false if `spreadStrict` is true. |
| 18 | + * Enabled by default. |
| 19 | + * @default true |
| 20 | + */ |
| 21 | + spreadStrict: boolean; |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Returns the tag name associated with a JSXOpeningElement. |
| 26 | + * @param node The visited JSXOpeningElement node object. |
| 27 | + * @returns The element's tag name. |
| 28 | + */ |
| 29 | + export function elementType( |
| 30 | + node: ESTreeJSX.JSXOpeningElement | ESTreeJSX.JSXOpeningFragment, |
| 31 | + ): string; |
| 32 | + |
| 33 | + /** |
| 34 | + * Returns the value of a given attribute. Different types of attributes have |
| 35 | + * their associated values in different properties on the object. This function |
| 36 | + * should return a value only if we can extract a literal value from its |
| 37 | + * attribute (i.e. values that have generic types in JavaScript including |
| 38 | + * strings, numbers, booleans, etc.) |
| 39 | + * @param prop The JSXAttribute collected by AST parser. |
| 40 | + * @returns The value of the prop. |
| 41 | + */ |
| 42 | + export function getLiteralPropValue(prop: ESTreeJSX.JSXAttribute): ESTree.Literal['value']; |
| 43 | + |
| 44 | + /** |
| 45 | + * Returns the JSXAttribute itself or `undefined`, indicating the prop is not |
| 46 | + * present on the JSXOpeningElement. |
| 47 | + * @param props The attributes on the visited node (Usually node.attributes). |
| 48 | + * @param prop A string representation of the prop you want to retrieve. |
| 49 | + * @param options An object representing options for existence checking. |
| 50 | + * @returns The JSXAttribute if found, otherwise `undefined`. |
| 51 | + */ |
| 52 | + export function getProp( |
| 53 | + props: ESTreeJSX.JSXOpeningElement['attributes'], |
| 54 | + prop: string, |
| 55 | + options?: GetPropOptions, |
| 56 | + ): ESTreeJSX.JSXAttribute | undefined; |
| 57 | + |
| 58 | + /** |
| 59 | + * Returns the value of a given attribute. Different types of attributes have |
| 60 | + * their associated values in different properties on the object. This function |
| 61 | + * should return the most closely associated value with the intention of the JSX. |
| 62 | + * @param prop The JSXAttribute collected by AST parser. |
| 63 | + * @returns The value of the prop. |
| 64 | + */ |
| 65 | + export function getPropValue(prop: ESTreeJSX.JSXAttribute): unknown; |
| 66 | + |
| 67 | + /** |
| 68 | + * Returns a boolean indicating if ANY of props in prop argument exist on the node. |
| 69 | + * @param props The attributes on the visited node (Usually node.attributes). |
| 70 | + * @param prop An array of strings representing the props you want to check for existence. |
| 71 | + * @param options An object representing options for existence checking. |
| 72 | + * @returns A boolean asserting the existence of some of the props. |
| 73 | + */ |
| 74 | + export function hasAnyProp( |
| 75 | + props: ESTreeJSX.JSXOpeningElement['attributes'], |
| 76 | + prop: string[], |
| 77 | + options?: HasPropOptions, |
| 78 | + ): boolean; |
| 79 | + |
| 80 | + /** |
| 81 | + * Returns a boolean indicating if ALL of props in prop argument exist on the node. |
| 82 | + * @param props The attributes on the visited node (Usually node.attributes). |
| 83 | + * @param prop An array of strings representing the props you want to check for existence. |
| 84 | + * @param options An object representing options for existence checking. |
| 85 | + * @returns A boolean asserting the existence of all of the props. |
| 86 | + */ |
| 87 | + export function hasEveryProp( |
| 88 | + props: ESTreeJSX.JSXOpeningElement['attributes'], |
| 89 | + prop: string[], |
| 90 | + options?: HasPropOptions, |
| 91 | + ): boolean; |
| 92 | + |
| 93 | + /** |
| 94 | + * Returns boolean indicating whether an prop exists as an attribute on a JSX element node. |
| 95 | + * @param props The attributes on the visited node (Usually node.attributes). |
| 96 | + * @param prop A string representation of the prop you want to check for existence. |
| 97 | + * @param options An object representing options for existence checking. |
| 98 | + * @returns A boolean asserting the existence of the prop. |
| 99 | + */ |
| 100 | + export function hasProp( |
| 101 | + props: ESTreeJSX.JSXOpeningElement['attributes'], |
| 102 | + prop: string, |
| 103 | + options?: HasPropOptions, |
| 104 | + ): boolean; |
| 105 | + |
| 106 | + /** |
| 107 | + * Returns the name associated with a JSXAttribute. For example, given `<div foo="bar" />` |
| 108 | + * and the JSXAttribute for foo, this will return the string "foo". |
| 109 | + * @param prop The JSXAttribute collected by AST parser. |
| 110 | + * @returns The name of the attribute. |
| 111 | + */ |
| 112 | + export function propName(prop: ESTreeJSX.JSXAttribute): string; |
| 113 | +} |
0 commit comments