react-native-unistyles 3.0.0-nightly-20250210 → 3.0.0-nightly-20250214
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.
- package/README.md +3 -0
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +16 -1
- package/cxx/core/HostUnistyle.cpp +15 -5
- package/cxx/core/HostUnistyle.h +1 -0
- package/cxx/core/UnistylesCommitHook.cpp +20 -17
- package/cxx/core/UnistylesRegistry.cpp +8 -6
- package/cxx/shadowTree/ShadowTrafficController.h +10 -4
- package/cxx/shadowTree/ShadowTreeManager.cpp +38 -35
- package/lib/commonjs/components/native/Pressable.native.js +7 -0
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +3 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +7 -0
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +4 -2
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +2 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/package.json +19 -9
- package/plugin/index.d.ts +51 -18
- package/plugin/index.js +785 -178
- package/src/components/native/Pressable.native.tsx +8 -0
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +2 -2
- package/src/core/withUnistyles/withUnistyles.native.tsx +5 -3
- package/src/types/stylesheet.ts +1 -1
- package/plugin/consts.js +0 -63
- package/plugin/exotic.js +0 -54
- package/plugin/import.js +0 -51
- package/plugin/ref.js +0 -11
- package/plugin/stylesheet.js +0 -565
- package/plugin/variants.js +0 -66
package/plugin/index.js
CHANGED
@@ -1,192 +1,799 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
7
29
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS
|
16
|
-
.concat(state.opts.autoProcessPaths ?? [])
|
17
|
-
.some(path => state.filename.includes(path))
|
18
|
-
|
19
|
-
state.file.hasAnyUnistyle = false
|
20
|
-
state.file.hasUnistylesImport = false
|
21
|
-
state.file.hasVariants = false
|
22
|
-
state.file.styleSheetLocalName = ''
|
23
|
-
state.file.tagNumber = 0
|
24
|
-
state.reactNativeImports = {}
|
25
|
-
state.file.forceProcessing = state.opts.autoProcessRoot
|
26
|
-
? state.filename.includes(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)
|
27
|
-
: false
|
28
|
-
},
|
29
|
-
exit(path, state) {
|
30
|
-
if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
|
31
|
-
return
|
32
|
-
}
|
33
|
-
|
34
|
-
if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
|
35
|
-
addUnistylesImport(t, path, state)
|
36
|
-
}
|
37
|
-
}
|
38
|
-
},
|
39
|
-
FunctionDeclaration(path, state) {
|
40
|
-
if (isInsideNodeModules(state)) {
|
41
|
-
return
|
42
|
-
}
|
43
|
-
|
44
|
-
const componentName = path.node.id
|
45
|
-
? path.node.id.name
|
46
|
-
: null
|
47
|
-
|
48
|
-
if (componentName) {
|
49
|
-
state.file.hasVariants = false
|
50
|
-
}
|
51
|
-
},
|
52
|
-
ClassDeclaration(path, state) {
|
53
|
-
if (isInsideNodeModules(state)) {
|
54
|
-
return
|
55
|
-
}
|
56
|
-
|
57
|
-
const componentName = path.node.id
|
58
|
-
? path.node.id.name
|
59
|
-
: null
|
60
|
-
|
61
|
-
if (componentName) {
|
62
|
-
state.file.hasVariants = false
|
63
|
-
}
|
64
|
-
},
|
65
|
-
VariableDeclaration(path, state) {
|
66
|
-
if (isInsideNodeModules(state)) {
|
67
|
-
return
|
68
|
-
}
|
69
|
-
|
70
|
-
path.node.declarations.forEach((declaration) => {
|
71
|
-
if (t.isArrowFunctionExpression(declaration.init) || t.isFunctionExpression(declaration.init)) {
|
72
|
-
const componentName = declaration.id
|
73
|
-
? declaration.id.name
|
74
|
-
: null
|
75
|
-
|
76
|
-
if (componentName) {
|
77
|
-
state.file.hasVariants = false
|
78
|
-
}
|
79
|
-
}
|
80
|
-
})
|
81
|
-
},
|
82
|
-
/** @param {import('./index').UnistylesPluginPass} state */
|
83
|
-
ImportDeclaration(path, state) {
|
84
|
-
const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
|
85
|
-
.concat(state.opts.autoRemapImports ?? [])
|
86
|
-
.find(exotic => state.filename.includes(exotic.path))
|
87
|
-
|
88
|
-
if (exoticImport) {
|
89
|
-
return handleExoticImport(t, path, state, exoticImport)
|
90
|
-
}
|
30
|
+
// plugin/src/index.ts
|
31
|
+
var index_exports = {};
|
32
|
+
__export(index_exports, {
|
33
|
+
default: () => index_default
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
36
|
+
var t6 = __toESM(require("@babel/types"));
|
91
37
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
if (isInsideNodeModules(state)) {
|
135
|
-
return
|
136
|
-
}
|
137
|
-
|
138
|
-
extractVariants(t, path, state)
|
139
|
-
},
|
140
|
-
CallExpression(path, state) {
|
141
|
-
if (isInsideNodeModules(state)) {
|
142
|
-
return
|
143
|
-
}
|
38
|
+
// plugin/src/consts.ts
|
39
|
+
var REACT_NATIVE_COMPONENT_NAMES = [
|
40
|
+
"ActivityIndicator",
|
41
|
+
"View",
|
42
|
+
"Text",
|
43
|
+
"Image",
|
44
|
+
"ImageBackground",
|
45
|
+
"KeyboardAvoidingView",
|
46
|
+
"Pressable",
|
47
|
+
"ScrollView",
|
48
|
+
"FlatList",
|
49
|
+
"SectionList",
|
50
|
+
"Switch",
|
51
|
+
"TextInput",
|
52
|
+
"RefreshControl",
|
53
|
+
"TouchableHighlight",
|
54
|
+
"TouchableOpacity",
|
55
|
+
"VirtualizedList",
|
56
|
+
"Animated"
|
57
|
+
// Modal - there is no exposed native handle
|
58
|
+
// TouchableWithoutFeedback - can't accept a ref
|
59
|
+
];
|
60
|
+
var REPLACE_WITH_UNISTYLES_PATHS = [
|
61
|
+
"react-native-reanimated/src/component",
|
62
|
+
"react-native-gesture-handler/src/components"
|
63
|
+
];
|
64
|
+
var REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = [];
|
65
|
+
var NATIVE_COMPONENTS_PATHS = {
|
66
|
+
imports: [
|
67
|
+
{
|
68
|
+
name: "NativeText",
|
69
|
+
isDefault: false,
|
70
|
+
path: "react-native/Libraries/Text/TextNativeComponent",
|
71
|
+
mapTo: "NativeText"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
isDefault: true,
|
75
|
+
path: "react-native/Libraries/Components/View/ViewNativeComponent",
|
76
|
+
mapTo: "NativeView"
|
77
|
+
}
|
78
|
+
]
|
79
|
+
};
|
144
80
|
|
145
|
-
|
146
|
-
|
147
|
-
|
81
|
+
// plugin/src/exotic.ts
|
82
|
+
var t = __toESM(require("@babel/types"));
|
83
|
+
function handleExoticImport(path, state, exoticImport) {
|
84
|
+
const specifiers = path.node.specifiers;
|
85
|
+
const source = path.node.source;
|
86
|
+
if (path.node.importKind !== "value") {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
specifiers.forEach((specifier) => {
|
90
|
+
for (const rule of exoticImport.imports) {
|
91
|
+
const hasMatchingImportType = !rule.isDefault && t.isImportSpecifier(specifier) || rule.isDefault && t.isImportDefaultSpecifier(specifier);
|
92
|
+
const hasMatchingImportName = rule.isDefault || !rule.isDefault && rule.name === specifier.local.name;
|
93
|
+
const hasMatchingPath = rule.path === source.value;
|
94
|
+
if (!hasMatchingImportType || !hasMatchingImportName || !hasMatchingPath) {
|
95
|
+
continue;
|
96
|
+
}
|
97
|
+
if (t.isImportDefaultSpecifier(specifier)) {
|
98
|
+
const newImport = t.importDeclaration(
|
99
|
+
[t.importDefaultSpecifier(t.identifier(specifier.local.name))],
|
100
|
+
t.stringLiteral(
|
101
|
+
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
|
102
|
+
)
|
103
|
+
);
|
104
|
+
path.replaceWith(newImport);
|
105
|
+
} else {
|
106
|
+
const newImport = t.importDeclaration(
|
107
|
+
[t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
|
108
|
+
t.stringLiteral(
|
109
|
+
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
|
110
|
+
)
|
111
|
+
);
|
112
|
+
path.node.specifiers = specifiers.filter((s) => s !== specifier);
|
113
|
+
if (path.node.specifiers.length === 0) {
|
114
|
+
path.replaceWith(newImport);
|
115
|
+
} else {
|
116
|
+
path.insertBefore(newImport);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
});
|
122
|
+
}
|
148
123
|
|
149
|
-
|
124
|
+
// plugin/src/import.ts
|
125
|
+
var t2 = __toESM(require("@babel/types"));
|
126
|
+
function addUnistylesImport(path, state) {
|
127
|
+
const localNames = Object.keys(state.reactNativeImports);
|
128
|
+
const names = Object.values(state.reactNativeImports);
|
129
|
+
const pairs = Object.entries(state.reactNativeImports);
|
130
|
+
const nodesToRemove = [];
|
131
|
+
path.node.body.forEach((node) => {
|
132
|
+
if (t2.isImportDeclaration(node) && node.source.value === "react-native") {
|
133
|
+
node.specifiers = node.specifiers.filter((specifier) => !localNames.some((name) => name === specifier.local.name));
|
134
|
+
if (node.specifiers.length === 0) {
|
135
|
+
nodesToRemove.push(node);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
});
|
139
|
+
names.forEach((name) => {
|
140
|
+
const rnWebImport = path.node.body.find((node) => t2.isImportDeclaration(node) && node.source.value === `react-native-web/dist/exports/${name}`);
|
141
|
+
if (rnWebImport) {
|
142
|
+
rnWebImport.specifiers = [];
|
143
|
+
}
|
144
|
+
});
|
145
|
+
pairs.forEach(([localName, name]) => {
|
146
|
+
const newImport = t2.importDeclaration(
|
147
|
+
[t2.importSpecifier(t2.identifier(localName), t2.identifier(name))],
|
148
|
+
t2.stringLiteral(
|
149
|
+
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/src/components/native/${name}`) ?? "" : `react-native-unistyles/components/native/${name}`
|
150
|
+
)
|
151
|
+
);
|
152
|
+
path.node.body.unshift(newImport);
|
153
|
+
});
|
154
|
+
nodesToRemove.forEach((node) => path.node.body.splice(path.node.body.indexOf(node), 1));
|
155
|
+
}
|
156
|
+
function isInsideNodeModules(state) {
|
157
|
+
return state.file.opts.filename?.includes("node_modules");
|
158
|
+
}
|
150
159
|
|
151
|
-
|
160
|
+
// plugin/src/ref.ts
|
161
|
+
var t3 = __toESM(require("@babel/types"));
|
162
|
+
function hasStringRef(path) {
|
163
|
+
return path.node.openingElement.attributes.find(
|
164
|
+
(attr) => t3.isJSXAttribute(attr) && t3.isJSXIdentifier(attr.name, { name: "ref" }) && t3.isStringLiteral(attr.value)
|
165
|
+
);
|
166
|
+
}
|
152
167
|
|
153
|
-
|
168
|
+
// plugin/src/stylesheet.ts
|
169
|
+
var t4 = __toESM(require("@babel/types"));
|
170
|
+
var UnistyleDependency = {
|
171
|
+
Theme: 0,
|
172
|
+
ThemeName: 1,
|
173
|
+
AdaptiveThemes: 2,
|
174
|
+
Breakpoints: 3,
|
175
|
+
Variants: 4,
|
176
|
+
ColorScheme: 5,
|
177
|
+
Dimensions: 6,
|
178
|
+
Orientation: 7,
|
179
|
+
ContentSizeCategory: 8,
|
180
|
+
Insets: 9,
|
181
|
+
PixelRatio: 10,
|
182
|
+
FontScale: 11,
|
183
|
+
StatusBar: 12,
|
184
|
+
NavigationBar: 13,
|
185
|
+
Ime: 14
|
186
|
+
};
|
187
|
+
function getProperty(property) {
|
188
|
+
if (!property) {
|
189
|
+
return void 0;
|
190
|
+
}
|
191
|
+
if (t4.isIdentifier(property)) {
|
192
|
+
const prop = property;
|
193
|
+
return {
|
194
|
+
properties: [prop.name]
|
195
|
+
};
|
196
|
+
}
|
197
|
+
if (t4.isObjectPattern(property)) {
|
198
|
+
const prop = property;
|
199
|
+
const matchingProperties = prop.properties.flatMap((p) => getProperty(p));
|
200
|
+
return {
|
201
|
+
properties: matchingProperties.flatMap((properties) => properties?.properties).filter((prop2) => prop2 !== void 0)
|
202
|
+
};
|
203
|
+
}
|
204
|
+
if (t4.isObjectProperty(property) && t4.isIdentifier(property.value)) {
|
205
|
+
const prop = property.key;
|
206
|
+
return {
|
207
|
+
properties: [prop.name]
|
208
|
+
};
|
209
|
+
}
|
210
|
+
if (t4.isObjectProperty(property) && t4.isObjectPattern(property.value)) {
|
211
|
+
const matchingProperties = property.value.properties.flatMap((p) => getProperty(p));
|
212
|
+
const prop = property.key;
|
213
|
+
return {
|
214
|
+
parent: prop.name,
|
215
|
+
properties: matchingProperties.flatMap((properties) => properties?.properties).filter((prop2) => prop2 !== void 0)
|
216
|
+
};
|
217
|
+
}
|
218
|
+
return void 0;
|
219
|
+
}
|
220
|
+
function toUnistylesDependency(dependency) {
|
221
|
+
switch (dependency) {
|
222
|
+
case "theme": {
|
223
|
+
return UnistyleDependency.Theme;
|
224
|
+
}
|
225
|
+
case "themeName": {
|
226
|
+
return UnistyleDependency.ThemeName;
|
227
|
+
}
|
228
|
+
case "adaptiveThemes": {
|
229
|
+
return UnistyleDependency.AdaptiveThemes;
|
230
|
+
}
|
231
|
+
case "breakpoint": {
|
232
|
+
return UnistyleDependency.Breakpoints;
|
233
|
+
}
|
234
|
+
case "colorScheme": {
|
235
|
+
return UnistyleDependency.ColorScheme;
|
236
|
+
}
|
237
|
+
case "screen": {
|
238
|
+
return UnistyleDependency.Dimensions;
|
239
|
+
}
|
240
|
+
case "isPortrait":
|
241
|
+
case "isLandscape": {
|
242
|
+
return UnistyleDependency.Orientation;
|
243
|
+
}
|
244
|
+
case "contentSizeCategory": {
|
245
|
+
return UnistyleDependency.ContentSizeCategory;
|
246
|
+
}
|
247
|
+
case "ime": {
|
248
|
+
return UnistyleDependency.Ime;
|
249
|
+
}
|
250
|
+
case "insets": {
|
251
|
+
return UnistyleDependency.Insets;
|
252
|
+
}
|
253
|
+
case "pixelRatio": {
|
254
|
+
return UnistyleDependency.PixelRatio;
|
255
|
+
}
|
256
|
+
case "fontScale": {
|
257
|
+
return UnistyleDependency.FontScale;
|
258
|
+
}
|
259
|
+
case "statusBar": {
|
260
|
+
return UnistyleDependency.StatusBar;
|
261
|
+
}
|
262
|
+
case "navigationBar": {
|
263
|
+
return UnistyleDependency.NavigationBar;
|
264
|
+
}
|
265
|
+
case "variants": {
|
266
|
+
return UnistyleDependency.Variants;
|
267
|
+
}
|
268
|
+
default:
|
269
|
+
return null;
|
270
|
+
}
|
271
|
+
}
|
272
|
+
function getReturnStatementsFromBody(node, results = []) {
|
273
|
+
if (t4.isReturnStatement(node)) {
|
274
|
+
results.push(node);
|
275
|
+
}
|
276
|
+
if (t4.isBlockStatement(node)) {
|
277
|
+
node.body.forEach((child) => getReturnStatementsFromBody(child, results));
|
278
|
+
}
|
279
|
+
if (t4.isIfStatement(node)) {
|
280
|
+
getReturnStatementsFromBody(node.consequent, results);
|
281
|
+
if (node.alternate) {
|
282
|
+
getReturnStatementsFromBody(node.alternate, results);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
return results;
|
286
|
+
}
|
287
|
+
function stringToUniqueId(str) {
|
288
|
+
let hash = 0;
|
289
|
+
for (let i = 0; i < str.length; i++) {
|
290
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
291
|
+
hash |= 0;
|
292
|
+
}
|
293
|
+
const absHash = Math.abs(hash);
|
294
|
+
return absHash % 1e9;
|
295
|
+
}
|
296
|
+
function isUnistylesStyleSheet(path, state) {
|
297
|
+
const { callee } = path.node;
|
298
|
+
if (t4.isMemberExpression(callee) && t4.isIdentifier(callee.property)) {
|
299
|
+
return callee.property.name === "create" && t4.isIdentifier(callee.object) && callee.object.name === state.file.styleSheetLocalName;
|
300
|
+
}
|
301
|
+
return false;
|
302
|
+
}
|
303
|
+
function isKindOfStyleSheet(path, state) {
|
304
|
+
if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
|
305
|
+
return false;
|
306
|
+
}
|
307
|
+
const { callee } = path.node;
|
308
|
+
return t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && t4.isIdentifier(callee.object);
|
309
|
+
}
|
310
|
+
function addStyleSheetTag(path, state) {
|
311
|
+
const str = state.filename?.replace(state.cwd, "") ?? "";
|
312
|
+
const uniqueId = stringToUniqueId(str) + ++state.file.tagNumber;
|
313
|
+
path.node.arguments.push(t4.numericLiteral(uniqueId));
|
314
|
+
}
|
315
|
+
function getStylesDependenciesFromObject(path) {
|
316
|
+
const detectedStylesWithVariants = /* @__PURE__ */ new Set();
|
317
|
+
const stylesheet = path.node.arguments[0];
|
318
|
+
if (t4.isObjectExpression(stylesheet)) {
|
319
|
+
stylesheet?.properties.forEach((property) => {
|
320
|
+
if (!t4.isObjectProperty(property) || !t4.isIdentifier(property.key)) {
|
321
|
+
return;
|
322
|
+
}
|
323
|
+
if (t4.isObjectProperty(property)) {
|
324
|
+
if (t4.isObjectExpression(property.value)) {
|
325
|
+
property.value.properties.forEach((innerProp) => {
|
326
|
+
if (t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && t4.isIdentifier(property.key) && innerProp.key.name === "variants") {
|
327
|
+
detectedStylesWithVariants.add({
|
328
|
+
label: "variants",
|
329
|
+
key: property.key.name
|
330
|
+
});
|
331
|
+
}
|
332
|
+
});
|
333
|
+
}
|
334
|
+
}
|
335
|
+
if (t4.isArrowFunctionExpression(property.value)) {
|
336
|
+
if (t4.isObjectExpression(property.value.body)) {
|
337
|
+
property.value.body.properties.forEach((innerProp) => {
|
338
|
+
if (t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && t4.isIdentifier(property.key) && innerProp.key.name === "variants") {
|
339
|
+
detectedStylesWithVariants.add({
|
340
|
+
label: "variants",
|
341
|
+
key: property.key.name
|
342
|
+
});
|
343
|
+
}
|
344
|
+
});
|
345
|
+
}
|
346
|
+
}
|
347
|
+
});
|
348
|
+
}
|
349
|
+
const variants = Array.from(detectedStylesWithVariants);
|
350
|
+
return variants.reduce((acc, { key, label }) => {
|
351
|
+
if (acc[key]) {
|
352
|
+
acc[key] = [
|
353
|
+
...acc[key],
|
354
|
+
label
|
355
|
+
];
|
356
|
+
return acc;
|
357
|
+
}
|
358
|
+
acc[key] = [label];
|
359
|
+
return acc;
|
360
|
+
}, {});
|
361
|
+
}
|
362
|
+
function getStylesDependenciesFromFunction(path) {
|
363
|
+
const funcPath = path.get("arguments.0");
|
364
|
+
if (!funcPath) {
|
365
|
+
return;
|
366
|
+
}
|
367
|
+
if (Array.isArray(funcPath)) {
|
368
|
+
return;
|
369
|
+
}
|
370
|
+
if (!t4.isFunctionExpression(funcPath.node) && !t4.isArrowFunctionExpression(funcPath.node)) {
|
371
|
+
return;
|
372
|
+
}
|
373
|
+
const params = funcPath.node.params;
|
374
|
+
const [themeParam, rtParam] = params;
|
375
|
+
const themeNames = [];
|
376
|
+
if (t4.isObjectPattern(themeParam)) {
|
377
|
+
for (const prop of themeParam.properties) {
|
378
|
+
const property = getProperty(prop);
|
379
|
+
if (property) {
|
380
|
+
themeNames.push(property);
|
381
|
+
}
|
382
|
+
}
|
383
|
+
}
|
384
|
+
if (t4.isIdentifier(themeParam)) {
|
385
|
+
themeNames.push({
|
386
|
+
properties: [themeParam.name]
|
387
|
+
});
|
388
|
+
}
|
389
|
+
const rtNames = [];
|
390
|
+
if (t4.isObjectPattern(rtParam)) {
|
391
|
+
for (const prop of rtParam.properties) {
|
392
|
+
const property = getProperty(prop);
|
393
|
+
if (property) {
|
394
|
+
rtNames.push(property);
|
395
|
+
}
|
396
|
+
}
|
397
|
+
}
|
398
|
+
if (t4.isIdentifier(rtParam)) {
|
399
|
+
rtNames.push({
|
400
|
+
properties: [rtParam.name]
|
401
|
+
});
|
402
|
+
}
|
403
|
+
let returnedObjectPath = null;
|
404
|
+
if (t4.isObjectExpression(funcPath.node.body)) {
|
405
|
+
returnedObjectPath = funcPath.get("body");
|
406
|
+
} else {
|
407
|
+
funcPath.traverse({
|
408
|
+
ReturnStatement(retPath) {
|
409
|
+
if (!returnedObjectPath && retPath.get("argument").isObjectExpression()) {
|
410
|
+
const argumentPath = retPath.get("argument");
|
411
|
+
if (argumentPath.isObjectExpression()) {
|
412
|
+
returnedObjectPath = argumentPath;
|
413
|
+
}
|
414
|
+
}
|
415
|
+
}
|
416
|
+
});
|
417
|
+
}
|
418
|
+
if (!returnedObjectPath) {
|
419
|
+
return;
|
420
|
+
}
|
421
|
+
const detectedStylesWithVariants = /* @__PURE__ */ new Set();
|
422
|
+
const properties = returnedObjectPath.get("properties");
|
423
|
+
properties.forEach((propPath) => {
|
424
|
+
const stylePath = propPath.get("key");
|
425
|
+
if (Array.isArray(stylePath)) {
|
426
|
+
return;
|
427
|
+
}
|
428
|
+
if (!stylePath.isIdentifier()) {
|
429
|
+
return;
|
430
|
+
}
|
431
|
+
const styleKey = stylePath.node.name;
|
432
|
+
const valuePath = propPath.get("value");
|
433
|
+
if (Array.isArray(valuePath)) {
|
434
|
+
return;
|
435
|
+
}
|
436
|
+
if (valuePath.isObjectExpression()) {
|
437
|
+
const hasVariants = valuePath.get("properties").some((innerProp) => {
|
438
|
+
const innerKey = innerProp.get("key");
|
439
|
+
if (Array.isArray(innerKey)) {
|
440
|
+
return;
|
441
|
+
}
|
442
|
+
return innerKey.isIdentifier() && innerKey.node.name === "variants";
|
443
|
+
});
|
444
|
+
if (hasVariants) {
|
445
|
+
detectedStylesWithVariants.add({
|
446
|
+
label: "variants",
|
447
|
+
key: styleKey
|
448
|
+
});
|
449
|
+
}
|
450
|
+
}
|
451
|
+
if (valuePath.isArrowFunctionExpression()) {
|
452
|
+
if (t4.isObjectExpression(valuePath.node.body)) {
|
453
|
+
const hasVariants = valuePath.node.body.properties.some((innerProp) => {
|
454
|
+
return t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && innerProp.key.name === "variants";
|
455
|
+
});
|
456
|
+
if (hasVariants) {
|
457
|
+
detectedStylesWithVariants.add({
|
458
|
+
label: "variants",
|
459
|
+
key: styleKey
|
460
|
+
});
|
461
|
+
}
|
462
|
+
}
|
463
|
+
}
|
464
|
+
});
|
465
|
+
const detectedStylesWithTheme = /* @__PURE__ */ new Set();
|
466
|
+
themeNames.forEach(({ properties: properties2 }) => {
|
467
|
+
properties2.forEach((property) => {
|
468
|
+
const binding = funcPath.scope.getBinding(property);
|
469
|
+
if (!binding) {
|
470
|
+
return;
|
471
|
+
}
|
472
|
+
binding.referencePaths.forEach((refPath) => {
|
473
|
+
const containerProp = refPath.findParent((parent) => parent.isObjectProperty() && parent.parentPath === returnedObjectPath);
|
474
|
+
if (!containerProp) {
|
475
|
+
return;
|
476
|
+
}
|
477
|
+
const keyNode = containerProp.get("key");
|
478
|
+
if (Array.isArray(keyNode)) {
|
479
|
+
return;
|
480
|
+
}
|
481
|
+
const keyValue = keyNode.isLiteral() ? keyNode.isStringLiteral() || keyNode.isNumericLiteral() || keyNode.isBooleanLiteral() ? String(keyNode.node.value) : null : null;
|
482
|
+
const styleKey = keyNode.isIdentifier() ? keyNode.node.name : keyValue;
|
483
|
+
if (styleKey) {
|
484
|
+
detectedStylesWithTheme.add({
|
485
|
+
label: "theme",
|
486
|
+
key: styleKey
|
487
|
+
});
|
488
|
+
}
|
489
|
+
});
|
490
|
+
});
|
491
|
+
});
|
492
|
+
const detectedStylesWithRt = /* @__PURE__ */ new Set();
|
493
|
+
const localRtName = t4.isIdentifier(rtParam) ? rtParam.name : void 0;
|
494
|
+
rtNames.forEach(({ properties: properties2, parent }) => {
|
495
|
+
properties2.forEach((property) => {
|
496
|
+
const rtBinding = funcPath.scope.getBinding(property);
|
497
|
+
if (!rtBinding) {
|
498
|
+
return;
|
499
|
+
}
|
500
|
+
const isValidDependency = Boolean(toUnistylesDependency(property));
|
501
|
+
let validRtName = property;
|
502
|
+
if (!isValidDependency && (!localRtName || localRtName && localRtName !== property)) {
|
503
|
+
if (!parent) {
|
504
|
+
return;
|
505
|
+
}
|
506
|
+
if (!toUnistylesDependency(parent)) {
|
507
|
+
return;
|
508
|
+
}
|
509
|
+
validRtName = parent;
|
510
|
+
}
|
511
|
+
rtBinding.referencePaths.forEach((refPath) => {
|
512
|
+
let usedLabel = validRtName;
|
513
|
+
if (refPath.parentPath?.isMemberExpression() && refPath.parentPath.get("object") === refPath) {
|
514
|
+
const memberExpr = refPath.parentPath;
|
515
|
+
const propPath = memberExpr.get("property");
|
516
|
+
if (propPath.isIdentifier()) {
|
517
|
+
if (localRtName) {
|
518
|
+
usedLabel = propPath.node.name;
|
519
|
+
}
|
520
|
+
if (usedLabel === "insets" && memberExpr.parentPath.isMemberExpression() && memberExpr.parentPath.get("object") === memberExpr) {
|
521
|
+
const secondPropPath = memberExpr.parentPath.get("property");
|
522
|
+
if (secondPropPath.isIdentifier() && secondPropPath.node.name === "ime") {
|
523
|
+
usedLabel = "ime";
|
524
|
+
}
|
525
|
+
}
|
526
|
+
}
|
527
|
+
}
|
528
|
+
const containerProp = refPath.findParent((parent2) => parent2.isObjectProperty() && parent2.parentPath === returnedObjectPath);
|
529
|
+
if (!containerProp) {
|
530
|
+
return;
|
531
|
+
}
|
532
|
+
const keyNode = containerProp.get("key");
|
533
|
+
if (Array.isArray(keyNode)) {
|
534
|
+
return;
|
535
|
+
}
|
536
|
+
const keyValue = keyNode.isLiteral() ? keyNode.isStringLiteral() || keyNode.isNumericLiteral() || keyNode.isBooleanLiteral() ? String(keyNode.node.value) : null : null;
|
537
|
+
const styleKey = keyNode.isIdentifier() ? keyNode.node.name : keyValue;
|
538
|
+
if (styleKey) {
|
539
|
+
detectedStylesWithRt.add({
|
540
|
+
label: usedLabel,
|
541
|
+
key: styleKey
|
542
|
+
});
|
543
|
+
}
|
544
|
+
});
|
545
|
+
});
|
546
|
+
});
|
547
|
+
const variants = Array.from(detectedStylesWithVariants);
|
548
|
+
const theme = Array.from(detectedStylesWithTheme);
|
549
|
+
const rt = Array.from(detectedStylesWithRt);
|
550
|
+
return theme.concat(rt).concat(variants).reduce((acc, { key, label }) => {
|
551
|
+
if (acc[key]) {
|
552
|
+
acc[key] = [
|
553
|
+
...acc[key],
|
554
|
+
label
|
555
|
+
];
|
556
|
+
return acc;
|
557
|
+
}
|
558
|
+
acc[key] = [label];
|
559
|
+
return acc;
|
560
|
+
}, {});
|
561
|
+
}
|
562
|
+
function addDependencies(state, styleName, unistyle, detectedDependencies) {
|
563
|
+
const debugMessage = (deps) => {
|
564
|
+
if (state.opts.debug) {
|
565
|
+
const mappedDeps = deps.map((dep) => Object.keys(UnistyleDependency).find((key) => UnistyleDependency[key] === dep)).join(", ");
|
566
|
+
console.log(`${state.filename?.replace(`${state.file.opts.root}/`, "")}: styles.${styleName}: [${mappedDeps}]`);
|
567
|
+
}
|
568
|
+
};
|
569
|
+
const styleDependencies = detectedDependencies.map(toUnistylesDependency);
|
570
|
+
if (styleDependencies.length > 0) {
|
571
|
+
const uniqueDependencies = Array.from(new Set(styleDependencies));
|
572
|
+
debugMessage(uniqueDependencies);
|
573
|
+
let targets = [];
|
574
|
+
if (t4.isArrowFunctionExpression(unistyle.value) || t4.isFunctionExpression(unistyle.value)) {
|
575
|
+
if (t4.isObjectExpression(unistyle.value.body)) {
|
576
|
+
targets.push(unistyle.value.body);
|
577
|
+
}
|
578
|
+
if (t4.isBlockStatement(unistyle.value.body)) {
|
579
|
+
targets = getReturnStatementsFromBody(unistyle.value.body).map((node) => {
|
580
|
+
if (t4.isIdentifier(node.argument)) {
|
581
|
+
node.argument = t4.objectExpression([
|
582
|
+
t4.spreadElement(node.argument)
|
583
|
+
]);
|
584
|
+
}
|
585
|
+
return node.argument;
|
586
|
+
}).filter((node) => t4.isObjectExpression(node));
|
587
|
+
}
|
588
|
+
}
|
589
|
+
if (t4.isObjectExpression(unistyle.value)) {
|
590
|
+
targets.push(unistyle.value);
|
591
|
+
}
|
592
|
+
if (t4.isMemberExpression(unistyle.value)) {
|
593
|
+
unistyle.value = t4.objectExpression([t4.spreadElement(unistyle.value)]);
|
594
|
+
targets.push(unistyle.value);
|
595
|
+
}
|
596
|
+
if (targets.length > 0) {
|
597
|
+
targets.forEach((target) => {
|
598
|
+
target.properties.push(
|
599
|
+
t4.objectProperty(
|
600
|
+
t4.identifier("uni__dependencies"),
|
601
|
+
t4.arrayExpression(uniqueDependencies.filter((dep) => dep !== void 0).map((dep) => t4.numericLiteral(dep)))
|
602
|
+
)
|
603
|
+
);
|
604
|
+
});
|
605
|
+
}
|
606
|
+
}
|
607
|
+
}
|
154
608
|
|
155
|
-
|
156
|
-
|
157
|
-
|
609
|
+
// plugin/src/variants.ts
|
610
|
+
var t5 = __toESM(require("@babel/types"));
|
611
|
+
function extractVariants(path, state) {
|
612
|
+
const maybeVariants = path.node.body.filter((node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee));
|
613
|
+
if (maybeVariants.length === 0) {
|
614
|
+
return;
|
615
|
+
}
|
616
|
+
const targetVariant = maybeVariants.find((variant) => {
|
617
|
+
if (!t5.isExpressionStatement(variant) || !t5.isCallExpression(variant.expression) || !t5.isMemberExpression(variant.expression.callee) || !t5.isIdentifier(variant.expression.callee.object)) {
|
618
|
+
return false;
|
619
|
+
}
|
620
|
+
const calleeName2 = variant.expression.callee.object.name;
|
621
|
+
return t5.isIdentifier(variant.expression.callee.object, { name: calleeName2 }) && t5.isIdentifier(variant.expression.callee.property, { name: "useVariants" }) && variant.expression.arguments.length === 1;
|
622
|
+
});
|
623
|
+
if (!targetVariant) {
|
624
|
+
return;
|
625
|
+
}
|
626
|
+
const node = targetVariant.expression;
|
627
|
+
if (!t5.isCallExpression(node)) {
|
628
|
+
return;
|
629
|
+
}
|
630
|
+
const callee = node.callee;
|
631
|
+
if (!t5.isMemberExpression(callee) || !t5.isIdentifier(callee.object)) {
|
632
|
+
return;
|
633
|
+
}
|
634
|
+
const calleeName = callee.object.name;
|
635
|
+
const newUniqueName = path.scope.generateUidIdentifier(calleeName);
|
636
|
+
const shadowDeclaration = t5.variableDeclaration("const", [
|
637
|
+
t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
|
638
|
+
]);
|
639
|
+
const newCallExpression = t5.callExpression(
|
640
|
+
t5.memberExpression(t5.identifier(newUniqueName.name), t5.identifier("useVariants")),
|
641
|
+
node.arguments
|
642
|
+
);
|
643
|
+
const finalDeclaration = t5.variableDeclaration("const", [
|
644
|
+
t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
|
645
|
+
]);
|
646
|
+
const pathIndex = path.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
|
647
|
+
const rest = path.node.body.slice(pathIndex + 1);
|
648
|
+
const statement = t5.blockStatement([
|
649
|
+
finalDeclaration,
|
650
|
+
...rest
|
651
|
+
]);
|
652
|
+
path.node.body = [
|
653
|
+
...path.node.body.slice(0, pathIndex),
|
654
|
+
shadowDeclaration,
|
655
|
+
statement
|
656
|
+
];
|
657
|
+
state.file.hasVariants = true;
|
658
|
+
}
|
158
659
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
660
|
+
// plugin/src/index.ts
|
661
|
+
function index_default() {
|
662
|
+
return {
|
663
|
+
name: "babel-react-native-unistyles",
|
664
|
+
visitor: {
|
665
|
+
Program: {
|
666
|
+
enter(_, state) {
|
667
|
+
state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.concat(state.opts.autoProcessPaths ?? []).some((path) => state.filename?.includes(path));
|
668
|
+
state.file.hasAnyUnistyle = false;
|
669
|
+
state.file.hasUnistylesImport = false;
|
670
|
+
state.file.hasVariants = false;
|
671
|
+
state.file.styleSheetLocalName = "";
|
672
|
+
state.file.tagNumber = 0;
|
673
|
+
state.reactNativeImports = {};
|
674
|
+
state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`) : false;
|
675
|
+
},
|
676
|
+
exit(path, state) {
|
677
|
+
if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
|
678
|
+
return;
|
679
|
+
}
|
680
|
+
if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
|
681
|
+
addUnistylesImport(path, state);
|
682
|
+
}
|
683
|
+
}
|
684
|
+
},
|
685
|
+
FunctionDeclaration(path, state) {
|
686
|
+
if (isInsideNodeModules(state)) {
|
687
|
+
return;
|
688
|
+
}
|
689
|
+
const componentName = path.node.id ? path.node.id.name : null;
|
690
|
+
if (componentName) {
|
691
|
+
state.file.hasVariants = false;
|
692
|
+
}
|
693
|
+
},
|
694
|
+
ClassDeclaration(path, state) {
|
695
|
+
if (isInsideNodeModules(state)) {
|
696
|
+
return;
|
697
|
+
}
|
698
|
+
const componentName = path.node.id ? path.node.id.name : null;
|
699
|
+
if (componentName) {
|
700
|
+
state.file.hasVariants = false;
|
701
|
+
}
|
702
|
+
},
|
703
|
+
VariableDeclaration(path, state) {
|
704
|
+
if (isInsideNodeModules(state)) {
|
705
|
+
return;
|
706
|
+
}
|
707
|
+
path.node.declarations.forEach((declaration) => {
|
708
|
+
if (t6.isArrowFunctionExpression(declaration.init) || t6.isFunctionExpression(declaration.init)) {
|
709
|
+
const componentName = declaration.id && t6.isIdentifier(declaration.id) ? declaration.id.name : null;
|
710
|
+
if (componentName) {
|
711
|
+
state.file.hasVariants = false;
|
712
|
+
}
|
713
|
+
}
|
714
|
+
});
|
715
|
+
},
|
716
|
+
ImportDeclaration(path, state) {
|
717
|
+
const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find((exotic) => state.filename?.includes(exotic.path));
|
718
|
+
if (exoticImport) {
|
719
|
+
return handleExoticImport(path, state, exoticImport);
|
720
|
+
}
|
721
|
+
if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
|
722
|
+
return;
|
723
|
+
}
|
724
|
+
const importSource = path.node.source.value;
|
725
|
+
if (importSource.includes("react-native-unistyles")) {
|
726
|
+
state.file.hasUnistylesImport = true;
|
727
|
+
path.node.specifiers.forEach((specifier) => {
|
728
|
+
if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && specifier.imported.name === "StyleSheet") {
|
729
|
+
state.file.styleSheetLocalName = specifier.local.name;
|
730
|
+
}
|
731
|
+
});
|
732
|
+
}
|
733
|
+
if (importSource === "react-native") {
|
734
|
+
path.node.specifiers.forEach((specifier) => {
|
735
|
+
if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
|
736
|
+
state.reactNativeImports[specifier.local.name] = specifier.imported.name;
|
737
|
+
}
|
738
|
+
});
|
739
|
+
}
|
740
|
+
if (importSource.includes("react-native/Libraries")) {
|
741
|
+
handleExoticImport(path, state, NATIVE_COMPONENTS_PATHS);
|
742
|
+
}
|
743
|
+
if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
|
744
|
+
state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource);
|
745
|
+
}
|
746
|
+
},
|
747
|
+
JSXElement(path, state) {
|
748
|
+
if (isInsideNodeModules(state)) {
|
749
|
+
return;
|
750
|
+
}
|
751
|
+
if (hasStringRef(path)) {
|
752
|
+
throw new Error("Detected string based ref which is not supported by Unistyles.");
|
753
|
+
}
|
754
|
+
},
|
755
|
+
BlockStatement(path, state) {
|
756
|
+
if (isInsideNodeModules(state)) {
|
757
|
+
return;
|
758
|
+
}
|
759
|
+
extractVariants(path, state);
|
760
|
+
},
|
761
|
+
CallExpression(path, state) {
|
762
|
+
if (isInsideNodeModules(state)) {
|
763
|
+
return;
|
764
|
+
}
|
765
|
+
if (!isUnistylesStyleSheet(path, state) && !isKindOfStyleSheet(path, state)) {
|
766
|
+
return;
|
767
|
+
}
|
768
|
+
state.file.hasAnyUnistyle = true;
|
769
|
+
addStyleSheetTag(path, state);
|
770
|
+
const arg = path.node.arguments[0];
|
771
|
+
if (t6.isObjectExpression(arg)) {
|
772
|
+
const detectedDependencies = getStylesDependenciesFromObject(path);
|
773
|
+
if (detectedDependencies) {
|
774
|
+
if (t6.isObjectExpression(arg)) {
|
775
|
+
arg.properties.forEach((property) => {
|
776
|
+
if (t6.isObjectProperty(property) && t6.isIdentifier(property.key) && Object.prototype.hasOwnProperty.call(detectedDependencies, property.key.name)) {
|
777
|
+
addDependencies(state, property.key.name, property, detectedDependencies[property.key.name] ?? []);
|
168
778
|
}
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
body.properties.forEach(property => {
|
182
|
-
if (detectedDependencies.hasOwnProperty(property.key.name)) {
|
183
|
-
addDependencies(t, state, property.key.name, property, detectedDependencies[property.key.name])
|
184
|
-
}
|
185
|
-
})
|
186
|
-
}
|
187
|
-
}
|
779
|
+
});
|
780
|
+
}
|
781
|
+
}
|
782
|
+
}
|
783
|
+
if (t6.isArrowFunctionExpression(arg) || t6.isFunctionExpression(arg)) {
|
784
|
+
const detectedDependencies = getStylesDependenciesFromFunction(path);
|
785
|
+
if (detectedDependencies) {
|
786
|
+
const body = t6.isBlockStatement(arg.body) ? arg.body.body.find((statement) => t6.isReturnStatement(statement))?.argument : arg.body;
|
787
|
+
if (t6.isObjectExpression(body)) {
|
788
|
+
body.properties.forEach((property) => {
|
789
|
+
if (t6.isObjectProperty(property) && t6.isIdentifier(property.key) && Object.prototype.hasOwnProperty.call(detectedDependencies, property.key.name)) {
|
790
|
+
addDependencies(state, property.key.name, property, detectedDependencies[property.key.name] ?? []);
|
188
791
|
}
|
792
|
+
});
|
189
793
|
}
|
794
|
+
}
|
190
795
|
}
|
796
|
+
}
|
191
797
|
}
|
798
|
+
};
|
192
799
|
}
|