react-native-boost 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,120 +0,0 @@
1
- import { NodePath, types as t } from '@babel/core';
2
-
3
- /**
4
- * Checks if any ancestor element is of the specified component type or contains that component type.
5
- * This function handles both direct ancestors and custom components that may contain the specified component.
6
- *
7
- * @param path - The path to the JSXOpeningElement.
8
- * @param componentName - The name of the component to check for in ancestors.
9
- * @param skipComponents - Optional array of component names to skip when checking ancestors.
10
- * @returns true if any ancestor is or contains the specified component.
11
- */
12
- export function hasComponentAncestor(
13
- path: NodePath<t.JSXOpeningElement>,
14
- componentName: string,
15
- skipComponents: string[] = ['Fragment']
16
- ): boolean {
17
- // Check for direct ancestors of the specified component type
18
- const directAncestor = path.findParent((parentPath) => {
19
- return (
20
- t.isJSXElement(parentPath.node) && t.isJSXIdentifier(parentPath.node.openingElement.name, { name: componentName })
21
- );
22
- });
23
-
24
- if (directAncestor) return true;
25
-
26
- // Check for indirect ancestors (custom components that contain the specified component)
27
- return !!path.findParent((parentPath) => {
28
- // Only check JSX elements
29
- if (!t.isJSXElement(parentPath.node)) return false;
30
-
31
- // Get the component name
32
- const openingElement = parentPath.node.openingElement;
33
- if (!t.isJSXIdentifier(openingElement.name)) return false;
34
-
35
- const ancestorComponentName = openingElement.name.name;
36
-
37
- // Skip the component we're looking for
38
- if (ancestorComponentName === componentName) {
39
- return false;
40
- }
41
-
42
- // Skip components in the skipComponents list
43
- if (skipComponents.includes(ancestorComponentName)) {
44
- return false;
45
- }
46
-
47
- // Skip lowercase components (built-in HTML elements)
48
- if (ancestorComponentName[0] === ancestorComponentName[0].toLowerCase()) {
49
- return false;
50
- }
51
-
52
- // Try to find the component definition through variable binding
53
- const binding = parentPath.scope.getBinding(ancestorComponentName);
54
- if (!binding) return false;
55
-
56
- // Now check the component definition for the specified component
57
- if (t.isVariableDeclarator(binding.path.node)) {
58
- const init = binding.path.node.init;
59
-
60
- // Handle arrow functions or function expressions
61
- if (t.isArrowFunctionExpression(init) || t.isFunctionExpression(init)) {
62
- // Check the function body for the specified component
63
- return t.isBlockStatement(init.body)
64
- ? hasComponentInReturnStatement(init.body, componentName)
65
- : hasComponentInExpression(init.body, componentName);
66
- }
67
- } else if (t.isFunctionDeclaration(binding.path.node)) {
68
- // Handle function declarations
69
- return hasComponentInReturnStatement(binding.path.node.body, componentName);
70
- }
71
-
72
- return false;
73
- });
74
- }
75
-
76
- /**
77
- * Check if a block statement contains a return statement with the specified component
78
- *
79
- * @param blockStatement - The block statement to check
80
- * @param componentName - The name of the component to look for
81
- * @returns true if the block statement contains a return with the specified component
82
- */
83
- function hasComponentInReturnStatement(blockStatement: t.BlockStatement, componentName: string): boolean {
84
- for (const statement of blockStatement.body) {
85
- if (
86
- t.isReturnStatement(statement) &&
87
- statement.argument &&
88
- hasComponentInExpression(statement.argument, componentName)
89
- ) {
90
- return true;
91
- }
92
- }
93
- return false;
94
- }
95
-
96
- /**
97
- * Check if an expression contains the specified component
98
- *
99
- * @param expression - The expression to check
100
- * @param componentName - The name of the component to look for
101
- * @returns true if the expression contains the specified component
102
- */
103
- function hasComponentInExpression(expression: t.Expression, componentName: string): boolean {
104
- // If directly returning a JSX element
105
- if (t.isJSXElement(expression)) {
106
- // Check if it's the specified component
107
- if (t.isJSXIdentifier(expression.openingElement.name, { name: componentName })) {
108
- return true;
109
- }
110
-
111
- // Check if any children are the specified component
112
- for (const child of expression.children) {
113
- if (t.isJSXElement(child) && t.isJSXIdentifier(child.openingElement.name, { name: componentName })) {
114
- return true;
115
- }
116
- }
117
- }
118
-
119
- return false;
120
- }
@@ -1,22 +0,0 @@
1
- import { NodePath, types as t } from '@babel/core';
2
-
3
- /**
4
- * Checks if a node represents a string value.
5
- */
6
- export const isStringNode = (path: NodePath<t.JSXOpeningElement>, child: t.Node): boolean => {
7
- if (t.isJSXText(child) || t.isStringLiteral(child)) return true;
8
-
9
- // Check for JSX expressions
10
- if (t.isJSXExpressionContainer(child)) {
11
- const expression = child.expression;
12
- if (t.isIdentifier(expression)) {
13
- const binding = path.scope.getBinding(expression.name);
14
- if (binding && binding.path.node && t.isVariableDeclarator(binding.path.node)) {
15
- return !!binding.path.node.init && t.isStringLiteral(binding.path.node.init);
16
- }
17
- return false;
18
- }
19
- if (t.isStringLiteral(expression)) return true;
20
- }
21
- return false;
22
- };