@lark-apaas/fullstack-presets 1.1.3-beta.4 → 1.1.3-beta.5
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.
|
@@ -48,6 +48,15 @@ const rule = {
|
|
|
48
48
|
if (!hasJsxAttribute) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
+
// Check if this is a "jsx global" style tag - these are allowed to coexist with regular jsx styles
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
const hasGlobalAttribute = openingElement.attributes.some((attr) => attr.type === 'JSXAttribute' &&
|
|
54
|
+
attr.name?.type === 'JSXIdentifier' &&
|
|
55
|
+
attr.name?.name === 'global');
|
|
56
|
+
// Skip checking for "jsx global" tags - they don't conflict with regular jsx styles
|
|
57
|
+
if (hasGlobalAttribute) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
51
60
|
// Count JSXElement ancestors and find the outer styled-jsx tag
|
|
52
61
|
// styled-jsx uses ignoreClosing counter that increments on JSXOpeningElement enter
|
|
53
62
|
// and checks if ignoreClosing > 1 on style tag exit
|
|
@@ -56,32 +65,61 @@ const rule = {
|
|
|
56
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
66
|
let outerStyledJsxNode = null;
|
|
58
67
|
let current = node.parent;
|
|
68
|
+
// Helper function to recursively find styled-jsx tags in a node tree (excluding "jsx global")
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
const findStyledJsxInTree = (astNode, excludeNode) => {
|
|
71
|
+
if (!astNode)
|
|
72
|
+
return null;
|
|
73
|
+
// Check if this node itself is a styled-jsx tag
|
|
74
|
+
if (astNode.type === 'JSXElement' && astNode !== excludeNode) {
|
|
75
|
+
const openingEl = astNode.openingElement;
|
|
76
|
+
if (openingEl) {
|
|
77
|
+
const elName = openingEl.name;
|
|
78
|
+
if (elName?.type === 'JSXIdentifier' && elName?.name === 'style') {
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
const hasJsxAttr = openingEl.attributes?.some((attr) => attr.type === 'JSXAttribute' &&
|
|
81
|
+
attr.name?.type === 'JSXIdentifier' &&
|
|
82
|
+
attr.name?.name === 'jsx');
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
+
const hasGlobalAttr = openingEl.attributes?.some((attr) => attr.type === 'JSXAttribute' &&
|
|
85
|
+
attr.name?.type === 'JSXIdentifier' &&
|
|
86
|
+
attr.name?.name === 'global');
|
|
87
|
+
// Only return if it's a regular jsx style (not global)
|
|
88
|
+
if (hasJsxAttr && !hasGlobalAttr) {
|
|
89
|
+
return astNode;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Check children
|
|
95
|
+
const children = astNode.children;
|
|
96
|
+
if (children && Array.isArray(children)) {
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
for (const child of children) {
|
|
99
|
+
const result = findStyledJsxInTree(child, excludeNode);
|
|
100
|
+
if (result)
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
};
|
|
59
106
|
while (current) {
|
|
60
107
|
if (current.type === 'JSXElement') {
|
|
61
108
|
jsxElementCount++;
|
|
62
|
-
//
|
|
109
|
+
// Try to find any styled-jsx tag in the ancestor tree
|
|
63
110
|
if (!outerStyledJsxNode && current.parent) {
|
|
64
111
|
const parentNode = current.parent;
|
|
65
|
-
//
|
|
112
|
+
// Search in parent's children (siblings of current)
|
|
66
113
|
const children = parentNode.children || (parentNode.type === 'JSXElement' ? parentNode.children : null);
|
|
67
114
|
if (children && Array.isArray(children)) {
|
|
68
115
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
116
|
for (const child of children) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
-
const hasChildJsxAttr = childOpeningElement.attributes?.some((attr) => attr.type === 'JSXAttribute' &&
|
|
78
|
-
attr.name?.type === 'JSXIdentifier' &&
|
|
79
|
-
attr.name?.name === 'jsx');
|
|
80
|
-
if (hasChildJsxAttr) {
|
|
81
|
-
outerStyledJsxNode = child;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
117
|
+
// Don't search in the current branch that contains our node
|
|
118
|
+
if (child !== current) {
|
|
119
|
+
const result = findStyledJsxInTree(child, node);
|
|
120
|
+
if (result) {
|
|
121
|
+
outerStyledJsxNode = result;
|
|
122
|
+
break;
|
|
85
123
|
}
|
|
86
124
|
}
|
|
87
125
|
}
|