react-native-unistyles 3.0.0-nightly-20250203 → 3.0.0-nightly-20250206

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.
@@ -183,6 +183,7 @@ inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, std::shared_ptr<Hyb
183
183
 
184
184
  hostFn.setNativeState(rt, std::move(wrappedUnistyle));
185
185
  hostFn.setProperty(rt, unistyleID, jsi::Object(rt));
186
+ hostFn.setProperty(rt, helpers::STYLESHEET_VARIANTS.c_str(), helpers::variantsToValue(rt, variants));
186
187
 
187
188
  return std::move(hostFn);
188
189
  }
@@ -51,7 +51,7 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
51
51
  return (0, _core.passForwardedRef)(props, ref, forwardedRef);
52
52
  },
53
53
  style: state => {
54
- const unistyles = typeof style === 'function' ? style(state) : getStyles(style);
54
+ const unistyles = typeof style === 'function' ? style.call(style, state) : getStyles(style);
55
55
  if (!storedRef.current) {
56
56
  return unistyles;
57
57
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_core","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","getStyles","styleProps","unistyleKey","keys","find","key","startsWith","uni__getStyles","Pressable","exports","forwardRef","variants","style","props","forwardedRef","storedRef","useRef","useLayoutEffect","current","UnistylesShadowRegistry","remove","jsx","ref","unistyles","pressed","add","passForwardedRef","state"],"sourceRoot":"../../../../src","sources":["components/native/Pressable.native.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAA6C,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAA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AC,GACZ3B,SAAS,CAACY,KAAuC,CAAC;MAExD,IAAI,CAACG,SAAS,CAACG,OAAO,EAAE;QACpB,OAAOK,SAAS;MACpB;;MAEA;MACAJ,8BAAuB,CAACC,MAAM,CAACL,SAAS,CAACG,OAAO,CAAC;MACjD;MACAC,8BAAuB,CAACM,GAAG,CAACV,SAAS,CAACG,OAAO,EAAEK,SAAS,CAAC;MAEzD,OAAOA,SAAS;IACpB;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_core","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","getStyles","styleProps","unistyleKey","keys","find","key","startsWith","uni__getStyles","Pressable","exports","forwardRef","variants","style","props","forwardedRef","storedRef","useRef","useLayoutEffect","current","UnistylesShadowRegistry","remove","jsx","ref","unistyles","pressed","add","passForwardedRef","state"],"sourceRoot":"../../../../src","sources":["components/native/Pressable.native.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAA6C,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,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7 +45,7 @@ export const Pressable = /*#__PURE__*/forwardRef(({
45
45
  return passForwardedRef(props, ref, forwardedRef);
46
46
  },
47
47
  style: state => {
48
- const unistyles = typeof style === 'function' ? style(state) : getStyles(style);
48
+ const unistyles = typeof style === 'function' ? style.call(style, state) : getStyles(style);
49
49
  if (!storedRef.current) {
50
50
  return unistyles;
51
51
  }
@@ -1 +1 @@
1
- {"version":3,"names":["React","forwardRef","useLayoutEffect","useRef","Pressable","NativePressableReactNative","UnistylesShadowRegistry","passForwardedRef","jsx","_jsx","getStyles","styleProps","unistyleKey","Object","keys","find","key","startsWith","uni__getStyles","variants","style","props","forwardedRef","storedRef","current","remove","ref","unistyles","pressed","add","state"],"sourceRoot":"../../../../src","sources":["components/native/Pressable.native.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,eAAe,EAAEC,MAAM,QAAQ,OAAO;AAClE,SAASC,SAAS,IAAIC,0BAA0B,QAAQ,cAAc;AAEtE,SAASC,uBAAuB,QAAQ,aAAa;AACrD,SAASC,gBAAgB,QAAQ,YAAY;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAM7C,MAAMC,SAAS,GAAGA,CAACC,UAA+B,GAAG,CAAC,CAAC,KAAK;EACxD,MAAMC,WAAW,GAAGC,MAAM,CACrBC,IAAI,CAACH,UAAU,CAAC,CAChBI,IAAI,CAACC,GAAG,IAAIA,GAAG,CAACC,UAAU,CAAC,YAAY,CAAC,CAAC;EAE9C,IAAI,CAACL,WAAW,EAAE;IACd,OAAOD,UAAU;EACrB;EAEA,OAAO;IACH;IACA,GAAGA,UAAU,CAACC,WAAW,CAAC,CAACM,cAAc,CAAC,CAAC;IAC3C,CAACN,WAAW,GAAGD,UAAU,CAACC,WAAW,CAAC,CAACM,cAAc,CAAC;EAC1D,CAAC;AACL,CAAC;AAED,OAAO,MAAMd,SAAS,gBAAGH,UAAU,CAAuB,CAAC;EAAEkB,QAAQ;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EAAEC,YAAY,KAAK;EACvG,MAAMC,SAAS,GAAGpB,MAAM,CAAc,CAAC;EAEvCD,eAAe,CAAC,MAAM;IAClB,OAAO,MAAM;MACT,IAAIqB,SAAS,CAACC,OAAO,EAAE;QACnB;QACAlB,uBAAuB,CAACmB,MAAM,CAACF,SAAS,CAACC,OAAO,CAAC;MACrD;IACJ,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,oBACIf,IAAA,CAACJ,0BAA0B;IAAA,GACnBgB,KAAK;IACTK,GAAG,EAAEA,GAAG,IAAI;MACR,MAAMC,SAAS,GAAG,OAAOP,KAAK,KAAK,UAAU,GACvCA,KAAK,CAAC;QAAEQ,OAAO,EAAE;MAAM,CAAC,CAAC,GACzBR,KAAK;;MAEX;MACAd,uBAAuB,CAACuB,GAAG,CAACH,GAAG,EAAEC,SAAS,CAAC;MAE3C,IAAID,GAAG,EAAE;QACLH,SAAS,CAACC,OAAO,GAAGE,GAAG;MAC3B;MAEA,OAAOnB,gBAAgB,CAACc,KAAK,EAAEK,GAAG,EAAEJ,YAAY,CAAC;IACrD,CAAE;IACFF,KAAK,EAAEU,KAAK,IAAI;MACZ,MAAMH,SAAS,GAAG,OAAOP,KAAK,KAAK,UAAU,GACvCA,KAAK,CAACU,KAAK,CAAC,GACZpB,SAAS,CAACU,KAAuC,CAAC;MAExD,IAAI,CAACG,SAAS,CAACC,OAAO,EAAE;QACpB,OAAOG,SAAS;MACpB;;MAEA;MACArB,uBAAuB,CAACmB,MAAM,CAACF,SAAS,CAACC,OAAO,CAAC;MACjD;MACAlB,uBAAuB,CAACuB,GAAG,CAACN,SAAS,CAACC,OAAO,EAAEG,SAAS,CAAC;MAEzD,OAAOA,SAAS;IACpB;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","forwardRef","useLayoutEffect","useRef","Pressable","NativePressableReactNative","UnistylesShadowRegistry","passForwardedRef","jsx","_jsx","getStyles","styleProps","unistyleKey","Object","keys","find","key","startsWith","uni__getStyles","variants","style","props","forwardedRef","storedRef","current","remove","ref","unistyles","pressed","add","state","call"],"sourceRoot":"../../../../src","sources":["components/native/Pressable.native.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,eAAe,EAAEC,MAAM,QAAQ,OAAO;AAClE,SAASC,SAAS,IAAIC,0BAA0B,QAAQ,cAAc;AAEtE,SAASC,uBAAuB,QAAQ,aAAa;AACrD,SAASC,gBAAgB,QAAQ,YAAY;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAM7C,MAAMC,SAAS,GAAGA,CAACC,UAA+B,GAAG,CAAC,CAAC,KAAK;EACxD,MAAMC,WAAW,GAAGC,MAAM,CACrBC,IAAI,CAACH,UAAU,CAAC,CAChBI,IAAI,CAACC,GAAG,IAAIA,GAAG,CAACC,UAAU,CAAC,YAAY,CAAC,CAAC;EAE9C,IAAI,CAACL,WAAW,EAAE;IACd,OAAOD,UAAU;EACrB;EAEA,OAAO;IACH;IACA,GAAGA,UAAU,CAACC,WAAW,CAAC,CAACM,cAAc,CAAC,CAAC;IAC3C,CAACN,WAAW,GAAGD,UAAU,CAACC,WAAW,CAAC,CAACM,cAAc,CAAC;EAC1D,CAAC;AACL,CAAC;AAED,OAAO,MAAMd,SAAS,gBAAGH,UAAU,CAAuB,CAAC;EAAEkB,QAAQ;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EAAEC,YAAY,KAAK;EACvG,MAAMC,SAAS,GAAGpB,MAAM,CAAc,CAAC;EAEvCD,eAAe,CAAC,MAAM;IAClB,OAAO,MAAM;MACT,IAAIqB,SAAS,CAACC,OAAO,EAAE;QACnB;QACAlB,uBAAuB,CAACmB,MAAM,CAACF,SAAS,CAACC,OAAO,CAAC;MACrD;IACJ,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,oBACIf,IAAA,CAACJ,0BAA0B;IAAA,GACnBgB,KAAK;IACTK,GAAG,EAAEA,GAAG,IAAI;MACR,MAAMC,SAAS,GAAG,OAAOP,KAAK,KAAK,UAAU,GACvCA,KAAK,CAAC;QAAEQ,OAAO,EAAE;MAAM,CAAC,CAAC,GACzBR,KAAK;;MAEX;MACAd,uBAAuB,CAACuB,GAAG,CAACH,GAAG,EAAEC,SAAS,CAAC;MAE3C,IAAID,GAAG,EAAE;QACLH,SAAS,CAACC,OAAO,GAAGE,GAAG;MAC3B;MAEA,OAAOnB,gBAAgB,CAACc,KAAK,EAAEK,GAAG,EAAEJ,YAAY,CAAC;IACrD,CAAE;IACFF,KAAK,EAAEU,KAAK,IAAI;MACZ,MAAMH,SAAS,GAAG,OAAOP,KAAK,KAAK,UAAU,GACvCA,KAAK,CAACW,IAAI,CAACX,KAAK,EAAEU,KAAK,CAAC,GACxBpB,SAAS,CAACU,KAAuC,CAAC;MAExD,IAAI,CAACG,SAAS,CAACC,OAAO,EAAE;QACpB,OAAOG,SAAS;MACpB;;MAEA;MACArB,uBAAuB,CAACmB,MAAM,CAACF,SAAS,CAACC,OAAO,CAAC;MACjD;MACAlB,uBAAuB,CAACuB,GAAG,CAACN,SAAS,CAACC,OAAO,EAAEG,SAAS,CAAC;MAEzD,OAAOA,SAAS;IACpB;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-nightly-20250203",
3
+ "version": "3.0.0-nightly-20250206",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
package/plugin/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const { addUnistylesImport, isInsideNodeModules } = require('./import')
2
2
  const { hasStringRef } = require('./ref')
3
- const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyles, isKindOfStyleSheet, maybeAddThemeDependencyToMemberExpression, addThemeDependencyToMemberExpression, getStyleSheetLocalNames } = require('./stylesheet')
3
+ const { isUnistylesStyleSheet, addStyleSheetTag, isKindOfStyleSheet, getStylesDependenciesFromFunction, addDependencies, getStylesDependenciesFromObject } = require('./stylesheet')
4
4
  const { extractVariants } = require('./variants')
5
5
  const { REACT_NATIVE_COMPONENT_NAMES, REPLACE_WITH_UNISTYLES_PATHS, REPLACE_WITH_UNISTYLES_EXOTIC_PATHS, NATIVE_COMPONENTS_PATHS } = require('./consts')
6
6
  const { handleExoticImport } = require('./exotic')
@@ -149,43 +149,38 @@ module.exports = function ({ types: t }) {
149
149
 
150
150
  const arg = path.node.arguments[0]
151
151
 
152
- // Object passed to StyleSheet.create
152
+ // Object passed to StyleSheet.create (may contain variants)
153
153
  if (t.isObjectExpression(arg)) {
154
- arg.properties.forEach(property => {
155
- if (t.isObjectProperty(property)) {
156
- const propertyValues = getUnistyles(t, property)
154
+ const detectedDependencies = getStylesDependenciesFromObject(t, path)
157
155
 
158
- propertyValues.forEach(propertyValue => {
159
- analyzeDependencies(t, state, property.key.name, propertyValue, [], [])
156
+ if (detectedDependencies) {
157
+ if (t.isObjectExpression(arg)) {
158
+ arg.properties.forEach(property => {
159
+ if (detectedDependencies[property.key.name]) {
160
+ addDependencies(t, state, property.key.name, property, detectedDependencies[property.key.name])
161
+ }
160
162
  })
161
163
  }
162
- })
164
+ }
163
165
  }
164
166
 
165
167
  // Function passed to StyleSheet.create (e.g., theme => ({ container: {} }))
166
168
  if (t.isArrowFunctionExpression(arg) || t.isFunctionExpression(arg)) {
167
- const localNames = getStyleSheetLocalNames(t, arg)
168
- const body = t.isBlockStatement(arg.body)
169
- ? arg.body.body.find(statement => t.isReturnStatement(statement)).argument
170
- : arg.body
171
-
172
- // Ensure the function body returns an object
173
- if (t.isObjectExpression(body)) {
174
- body.properties.forEach(property => {
175
- if (t.isObjectProperty(property)) {
176
- const propertyValues = getUnistyles(t, property)
177
-
178
- // special case for non object/function properties
179
- // maybe user used inlined theme? ({ container: theme.components.container })
180
- if (propertyValues.length === 0 && maybeAddThemeDependencyToMemberExpression(t, property, localNames.theme)) {
181
- addThemeDependencyToMemberExpression(t, property)
169
+ const detectedDependencies = getStylesDependenciesFromFunction(t, path)
170
+
171
+ if (detectedDependencies) {
172
+ const body = t.isBlockStatement(arg.body)
173
+ ? arg.body.body.find(statement => t.isReturnStatement(statement)).argument
174
+ : arg.body
175
+
176
+ // Ensure the function body returns an object
177
+ if (t.isObjectExpression(body)) {
178
+ body.properties.forEach(property => {
179
+ if (detectedDependencies[property.key.name]) {
180
+ addDependencies(t, state, property.key.name, property, detectedDependencies[property.key.name])
182
181
  }
183
-
184
- propertyValues.forEach(propertyValue => {
185
- analyzeDependencies(t, state, property.key.name, propertyValue, localNames.theme, localNames.miniRuntime)
186
- })
187
- }
188
- })
182
+ })
183
+ }
189
184
  }
190
185
  }
191
186
  }
@@ -1,5 +1,3 @@
1
- const { getIdentifierNameFromExpression, getSecondPropertyName } = require('./common')
2
-
3
1
  const UnistyleDependency = {
4
2
  Theme: 0,
5
3
  ThemeName: 1,
@@ -19,7 +17,7 @@ const UnistyleDependency = {
19
17
  }
20
18
 
21
19
  function stringToUniqueId(str) {
22
- let hash = 0;
20
+ let hash = 0
23
21
 
24
22
  for (let i = 0; i < str.length; i++) {
25
23
  hash = (hash << 5) - hash + str.charCodeAt(i)
@@ -63,268 +61,505 @@ function addStyleSheetTag(t, path, state) {
63
61
  callee.container.arguments.push(t.numericLiteral(uniqueId))
64
62
  }
65
63
 
66
- function getStyleSheetLocalNames(t, functionArg) {
67
- const params = functionArg.params
68
- const hasTheme = params.length >= 1
69
- const hasMiniRuntime = params.length === 2
70
- const getProperty = (property, allowNested) => {
71
- if (t.isIdentifier(property.value)) {
72
- return property.value.name
64
+ const getProperty = (t, property) => {
65
+ if (!property) {
66
+ return undefined
67
+ }
68
+
69
+ if (t.isIdentifier(property)) {
70
+ return {
71
+ properties: [property.name]
73
72
  }
73
+ }
74
+
75
+ if (t.isObjectPattern(property)) {
76
+ const matchingProperties = property.properties.flatMap(p => getProperty(t, p))
74
77
 
75
- if (!t.isObjectPattern(property.value)) {
76
- return undefined
78
+ return {
79
+ properties: matchingProperties.flatMap(properties => properties.properties)
77
80
  }
81
+ }
78
82
 
79
- if (allowNested) {
80
- return property.value.properties.flatMap(getProperty)
83
+ if (t.isObjectProperty(property) && t.isIdentifier(property.value)) {
84
+ return {
85
+ properties: [property.key.name]
81
86
  }
87
+ }
82
88
 
83
- // we can force allow nested only for insets
84
- const hasIme = property.value.properties.find(property => property.key.name === 'ime')
85
- const lastKeyValue = property.value.properties.flatMap(getProperty)
89
+ if (t.isObjectProperty(property) && t.isObjectPattern(property.value)) {
90
+ const matchingProperties = property.value.properties.flatMap(p => getProperty(t, p))
86
91
 
87
- if (hasIme) {
88
- return lastKeyValue
92
+ return {
93
+ parent: property.key.name,
94
+ properties: matchingProperties.flatMap(properties => properties.properties)
89
95
  }
90
-
91
- return `${property.key.name}.${lastKeyValue}`
92
96
  }
93
- const getLocalNames = (param, allowNested) => {
94
- if (t.isObjectPattern(param)) {
95
- return param.properties
96
- .flatMap(property => getProperty(property, allowNested))
97
- .filter(Boolean)
97
+
98
+ return undefined
99
+ }
100
+
101
+ function getStylesDependenciesFromObject(t, path) {
102
+ const detectedStylesWithVariants = new Set()
103
+ const stylesheet = path.node.arguments[0]
104
+
105
+ stylesheet.properties.forEach(property => {
106
+ if (!t.isIdentifier(property.key)) {
107
+ return
98
108
  }
99
109
 
110
+ if (t.isObjectProperty(property)) {
111
+ if(t.isObjectExpression(property.value)) {
112
+ property.value.properties.forEach(innerProp => {
113
+ if (t.isIdentifier(innerProp.key) && innerProp.key.name === 'variants') {
114
+ detectedStylesWithVariants.add({
115
+ label: 'variants',
116
+ key: property.key.name
117
+ })
118
+ }
119
+ })
100
120
 
101
- if (t.isIdentifier(param)) {
102
- return [param.name]
121
+ }
103
122
  }
104
123
 
105
- return []
124
+ if (t.isArrowFunctionExpression(property.value)) {
125
+ if(t.isObjectExpression(property.value.body)) {
126
+ property.value.body.properties.forEach(innerProp => {
127
+ if (t.isIdentifier(innerProp.key) && innerProp.key.name === 'variants') {
128
+ detectedStylesWithVariants.add({
129
+ label: 'variants',
130
+ key: property.key.name
131
+ })
132
+ }
133
+ })
134
+
135
+ }
136
+ }
137
+ })
138
+
139
+ const variants = Array.from(detectedStylesWithVariants)
140
+
141
+ return variants.reduce((acc, { key, label }) => {
142
+ if (acc[key]) {
143
+ return {
144
+ ...acc,
145
+ [key]: [
146
+ ...acc[key],
147
+ label
148
+ ]
149
+ }
150
+ }
151
+
152
+ return {
153
+ ...acc,
154
+ [key]: [label]
155
+ }
156
+ }, [])
157
+ }
158
+
159
+ function getStylesDependenciesFromFunction(t, path) {
160
+ const funcPath = path.get('arguments.0')
161
+
162
+ if (!funcPath) {
163
+ return
106
164
  }
107
165
 
108
- return {
109
- theme: hasTheme ? getLocalNames(params[0], true) : [],
110
- miniRuntime: hasMiniRuntime ? getLocalNames(params[1], false) : []
166
+ const params = funcPath.node.params
167
+ const [themeParam, rtParam] = params
168
+
169
+ let themeNames = []
170
+
171
+ // destructured theme object
172
+ if (themeParam.type === 'ObjectPattern') {
173
+ // If destructured, collect all property names
174
+ for (const prop of themeParam.properties) {
175
+ themeNames.push(getProperty(t, prop))
176
+ }
111
177
  }
112
- }
113
178
 
114
- function maybeAddThemeDependencyToMemberExpression(t, property, themeLocalNames) {
115
- if (t.isIdentifier(property)) {
116
- return themeLocalNames.includes(property.name)
179
+ // user used 'theme' without destructuring
180
+ if (themeParam.type === 'Identifier') {
181
+ themeNames.push({
182
+ properties: [themeParam.name]
183
+ })
117
184
  }
118
185
 
119
- if (t.isObjectProperty(property)) {
120
- return maybeAddThemeDependencyToMemberExpression(t, property.value, themeLocalNames)
186
+ let rtNames = []
187
+
188
+ // destructured rt object
189
+ if (rtParam && rtParam.type === 'ObjectPattern') {
190
+ // If destructured, collect all property names
191
+ for (const prop of rtParam.properties) {
192
+ rtNames.push(getProperty(t, prop))
193
+ }
121
194
  }
122
195
 
123
- if (t.isMemberExpression(property)) {
124
- return maybeAddThemeDependencyToMemberExpression(t, property.object, themeLocalNames)
196
+ // user used 'rt' without destructuring
197
+ if (rtParam && rtParam.type === 'Identifier') {
198
+ rtNames.push({
199
+ properties: [rtParam.name]
200
+ })
125
201
  }
126
- }
127
202
 
203
+ // get returned object or return statement from StyleSheet.create function
204
+ let returnedObjectPath = null
128
205
 
129
- /** @param {import('./index').UnistylesPluginPass} state */
130
- function analyzeDependencies(t, state, name, unistyleObj, themeNames, rtNames) {
131
- const debugMessage = deps => {
132
- if (state.opts.debug) {
133
- const mappedDeps = deps
134
- .map(dep => Object.keys(UnistyleDependency).find(key => UnistyleDependency[key] === dep))
135
- .join(', ')
206
+ if (funcPath.get('body').isObjectExpression()) {
207
+ returnedObjectPath = funcPath.get('body')
208
+ } else {
209
+ funcPath.traverse({
210
+ ReturnStatement(retPath) {
211
+ if (!returnedObjectPath && retPath.get('argument').isObjectExpression()) {
212
+ returnedObjectPath = retPath.get('argument')
213
+ }
214
+ }
215
+ })
216
+ }
136
217
 
137
- console.log(`${state.filename.replace(`${state.file.opts.root}/`, '')}: styles.${name}: [${mappedDeps}]`)
138
- }
218
+ if (!returnedObjectPath) {
219
+ // there is no returned object
220
+ // abort
221
+
222
+ return
139
223
  }
140
- const unistyle = unistyleObj.properties
141
- const dependencies = []
142
224
 
143
- Object.values(unistyle).forEach(uni => {
144
- const identifiers = getIdentifierNameFromExpression(t, uni)
225
+ const detectedStylesWithVariants = new Set()
226
+
227
+ // detect variants via Scope
228
+ returnedObjectPath.get('properties').forEach(propPath => {
229
+ // get style name
230
+ const stylePath = propPath.get('key')
145
231
 
146
- if (themeNames.some(name => identifiers.some(id => id === name))) {
147
- dependencies.push(UnistyleDependency.Theme)
232
+ if (!stylePath.isIdentifier()) {
233
+ return
148
234
  }
149
235
 
150
- const matchingRtNames = rtNames.reduce((acc, name) => {
151
- if (name.includes('.')) {
152
- const key = name.split('.').at(0)
236
+ const styleKey = stylePath.node.name
153
237
 
154
- if (identifiers.some(id => name.includes(id))) {
155
- return [
156
- ...acc,
157
- key
158
- ]
159
- }
238
+ const valuePath = propPath.get('value')
239
+
240
+ if (valuePath.isObjectExpression()) {
241
+ const hasVariants = valuePath.get('properties').some(innerProp => {
242
+ const innerKey = innerProp.get('key')
243
+
244
+ return innerKey.isIdentifier() && innerKey.node.name === 'variants'
245
+ })
160
246
 
161
- return acc
247
+ if (hasVariants) {
248
+ detectedStylesWithVariants.add({
249
+ label: 'variants',
250
+ key: styleKey
251
+ })
162
252
  }
253
+ }
163
254
 
255
+ if (valuePath.isArrowFunctionExpression()) {
256
+ if(t.isObjectExpression(valuePath.node.body)) {
257
+ const hasVariants = valuePath.node.body.properties.some(innerProp => {
164
258
 
165
- if (identifiers.some(id => id === name)) {
166
- return [
167
- ...acc,
168
- name
169
- ]
259
+ return t.isIdentifier(innerProp.key) && innerProp.key.name === 'variants'
260
+ })
261
+
262
+ if (hasVariants) {
263
+ detectedStylesWithVariants.add({
264
+ label: 'variants',
265
+ key: styleKey
266
+ })
267
+ }
170
268
  }
269
+ }
270
+ })
171
271
 
172
- return acc
173
- }, [])
272
+ const detectedStylesWithTheme = new Set()
174
273
 
175
- if (matchingRtNames.length > 0) {
176
- const propertyNames = getSecondPropertyName(t, uni.value)
274
+ // detect theme dependencies via Scope
275
+ themeNames.forEach(({ properties }) => {
276
+ properties.forEach(property => {
277
+ const binding = funcPath.scope.getBinding(property)
177
278
 
178
- matchingRtNames
179
- .concat(propertyNames)
180
- .filter(Boolean)
181
- .forEach(propertyName => {
182
- switch (propertyName) {
183
- case 'themeName': {
184
- dependencies.push(UnistyleDependency.ThemeName)
279
+ if (!binding) {
280
+ return
281
+ }
185
282
 
186
- return
187
- }
188
- case 'adaptiveThemes': {
189
- dependencies.push(UnistyleDependency.AdaptiveThemes)
283
+ binding.referencePaths.forEach(refPath => {
284
+ // find key of the style that we are referring to
285
+ const containerProp = refPath
286
+ .findParent(parent => parent.isObjectProperty() && parent.parentPath === returnedObjectPath)
190
287
 
191
- return
192
- }
193
- case 'breakpoint': {
194
- dependencies.push(UnistyleDependency.Breakpoints)
288
+ if (!containerProp) {
289
+ return
290
+ }
195
291
 
196
- return
197
- }
198
- case 'colorScheme': {
199
- dependencies.push(UnistyleDependency.ColorScheme)
292
+ const keyNode = containerProp.get('key')
293
+ const styleKey = keyNode.isIdentifier()
294
+ ? keyNode.node.name
295
+ : keyNode.isLiteral()
296
+ ? keyNode.node.value
297
+ : null
298
+
299
+ if (styleKey) {
300
+ detectedStylesWithTheme.add({
301
+ label: 'theme',
302
+ key: styleKey
303
+ })
304
+ }
305
+ })
306
+ })
307
+ })
200
308
 
201
- return
202
- }
203
- case 'screen': {
204
- dependencies.push(UnistyleDependency.Dimensions)
309
+ const detectedStylesWithRt = new Set()
310
+ const localRtName = t.isIdentifier(rtParam)
311
+ ? rtParam.name
312
+ : undefined
205
313
 
206
- return
207
- }
208
- case 'isPortrait':
209
- case 'isLandscape': {
210
- dependencies.push(UnistyleDependency.Orientation)
314
+ // detect rt dependencies via Scope
315
+ rtNames.forEach(({ properties, parent }) => {
316
+ properties.forEach(property => {
317
+ const rtBinding = funcPath.scope.getBinding(property)
211
318
 
212
- return
213
- }
214
- case 'contentSizeCategory': {
215
- dependencies.push(UnistyleDependency.ContentSizeCategory)
319
+ if (!rtBinding) {
320
+ return
321
+ }
216
322
 
217
- return
218
- }
219
- case 'ime': {
220
- dependencies.push(UnistyleDependency.Ime)
323
+ const isValidDependency = Boolean(toUnistylesDependency(property))
221
324
 
222
- return
223
- }
224
- case 'insets': {
225
- dependencies.push(UnistyleDependency.Insets)
325
+ let validRtName = property
226
326
 
227
- return
228
- }
229
- case 'pixelRatio': {
230
- dependencies.push(UnistyleDependency.PixelRatio)
327
+ // user used nested destructing, find out parent key
328
+ if (!isValidDependency && (!localRtName || (localRtName && localRtName !== property))) {
329
+ if (!parent) {
330
+ return
331
+ }
231
332
 
232
- return
233
- }
234
- case 'fontScale': {
235
- dependencies.push(UnistyleDependency.FontScale)
333
+ if (!Boolean(toUnistylesDependency(parent))) {
334
+ return
335
+ }
236
336
 
237
- return
238
- }
239
- case 'statusBar': {
240
- dependencies.push(UnistyleDependency.StatusBar)
337
+ validRtName = parent
338
+ }
339
+
340
+ rtBinding.referencePaths.forEach(refPath => {
341
+ // to detect rt dependencies we need to get parameter not rt itself
342
+ // eg. rt.screen.width -> screen
343
+ // rt.insets.top -> insets
344
+ // special case: rt.insets.ime -> ime
345
+
346
+ let usedLabel = validRtName
241
347
 
242
- return
348
+ if (refPath.parentPath.isMemberExpression() && refPath.parentPath.get('object') === refPath) {
349
+ const memberExpr = refPath.parentPath
350
+ const propPath = memberExpr.get('property')
351
+
352
+ if (propPath.isIdentifier()) {
353
+ if (localRtName) {
354
+ usedLabel = propPath.node.name
243
355
  }
244
- case 'navigationBar': {
245
- dependencies.push(UnistyleDependency.NavigationBar)
246
356
 
247
- return
357
+ if (
358
+ usedLabel === 'insets' &&
359
+ memberExpr.parentPath.isMemberExpression() &&
360
+ memberExpr.parentPath.get('object') === memberExpr
361
+ ) {
362
+ const secondPropPath = memberExpr.parentPath.get('property')
363
+
364
+ if (secondPropPath.isIdentifier() && secondPropPath.node.name === 'ime') {
365
+ usedLabel = 'ime'
366
+ }
248
367
  }
249
368
  }
250
- })
251
- }
369
+ }
370
+
371
+ // find key of the style that we are referring to
372
+ const containerProp = refPath
373
+ .findParent(parent => parent.isObjectProperty() && parent.parentPath === returnedObjectPath)
374
+
375
+ if (!containerProp) {
376
+ return
377
+ }
252
378
 
253
- if (uni.key && uni.key.name === 'variants') {
254
- dependencies.push(UnistyleDependency.Variants)
379
+ const keyNode = containerProp.get('key')
380
+ const styleKey = keyNode.isIdentifier()
381
+ ? keyNode.node.name
382
+ : keyNode.isLiteral()
383
+ ? keyNode.node.value
384
+ : null
385
+
386
+ if (styleKey) {
387
+ detectedStylesWithRt.add({
388
+ label: usedLabel,
389
+ key: styleKey
390
+ })
391
+ }
392
+ })
393
+ })
394
+ })
395
+
396
+ const variants = Array.from(detectedStylesWithVariants)
397
+ const theme = Array.from(detectedStylesWithTheme)
398
+ const rt = Array.from(detectedStylesWithRt)
399
+
400
+ return theme
401
+ .concat(rt)
402
+ .concat(variants)
403
+ .reduce((acc, { key, label }) => {
404
+ if (acc[key]) {
405
+ return {
406
+ ...acc,
407
+ [key]: [
408
+ ...acc[key],
409
+ label
410
+ ]
411
+ }
412
+ }
413
+
414
+ return {
415
+ ...acc,
416
+ [key]: [label]
417
+ }
418
+ }, [])
419
+ }
420
+
421
+ function toUnistylesDependency(dependency) {
422
+ switch (dependency) {
423
+ case 'theme': {
424
+ return UnistyleDependency.Theme
425
+ }
426
+ case 'themeName': {
427
+ return UnistyleDependency.ThemeName
428
+ }
429
+ case 'adaptiveThemes': {
430
+ return UnistyleDependency.AdaptiveThemes
431
+ }
432
+ case 'breakpoint': {
433
+ return UnistyleDependency.Breakpoints
434
+ }
435
+ case 'colorScheme': {
436
+ return UnistyleDependency.ColorScheme
437
+ }
438
+ case 'screen': {
439
+ return UnistyleDependency.Dimensions
440
+ }
441
+ case 'isPortrait':
442
+ case 'isLandscape': {
443
+ return UnistyleDependency.Orientation
444
+ }
445
+ case 'contentSizeCategory': {
446
+ return UnistyleDependency.ContentSizeCategory
447
+ }
448
+ case 'ime': {
449
+ return UnistyleDependency.Ime
450
+ }
451
+ case 'insets': {
452
+ return UnistyleDependency.Insets
453
+ }
454
+ case 'pixelRatio': {
455
+ return UnistyleDependency.PixelRatio
456
+ }
457
+ case 'fontScale': {
458
+ return UnistyleDependency.FontScale
459
+ }
460
+ case 'statusBar': {
461
+ return UnistyleDependency.StatusBar
462
+ }
463
+ case 'navigationBar': {
464
+ return UnistyleDependency.NavigationBar
465
+ }
466
+ case 'variants': {
467
+ return UnistyleDependency.Variants
255
468
  }
256
469
 
257
470
  // breakpoints are too complex and are handled by C++
258
- })
471
+ }
472
+ }
259
473
 
260
- // add dependencies to the unistyle object if any found
261
- if (dependencies.length > 0) {
262
- const uniqueDependencies = Array.from(new Set(dependencies))
474
+ function getReturnStatementsFromBody(t, node, results = []) {
475
+ if (t.isReturnStatement(node)) {
476
+ results.push(node)
477
+ }
263
478
 
264
- debugMessage(uniqueDependencies)
479
+ if (t.isBlockStatement(node)) {
480
+ node.body.forEach(child => getReturnStatementsFromBody(t, child, results))
481
+ }
482
+
483
+ if (t.isIfStatement(node)) {
484
+ getReturnStatementsFromBody(t, node.consequent, results)
265
485
 
266
- unistyleObj.properties.push(
267
- t.objectProperty(
268
- t.identifier('uni__dependencies'),
269
- t.arrayExpression(uniqueDependencies.map(dep => t.numericLiteral(dep)))
270
- )
271
- )
486
+ if (node.alternate) {
487
+ getReturnStatementsFromBody(t, node.alternate, results)
488
+ }
272
489
  }
490
+
491
+ return results
273
492
  }
274
493
 
275
- function getUnistyles(t, property) {
276
- const propertyValue = t.isArrowFunctionExpression(property.value)
277
- ? property.value.body
278
- : property.value
494
+ function addDependencies(t, state, styleName, unistyle, detectedDependencies) {
495
+ const debugMessage = deps => {
496
+ if (state.opts.debug) {
497
+ const mappedDeps = deps
498
+ .map(dep => Object.keys(UnistyleDependency).find(key => UnistyleDependency[key] === dep))
499
+ .join(', ')
279
500
 
280
- if (t.isObjectExpression(propertyValue)) {
281
- return [propertyValue]
501
+ console.log(`${state.filename.replace(`${state.file.opts.root}/`, '')}: styles.${styleName}: [${mappedDeps}]`)
502
+ }
282
503
  }
283
504
 
284
- if (t.isBlockStatement(propertyValue)) {
285
- // here we might have single return statement
286
- // or if-else statements with return statements
287
- return propertyValue.body
288
- .flatMap(value => {
289
- if (t.isReturnStatement(value)) {
290
- return [value]
291
- }
505
+ const styleDependencies = detectedDependencies.map(toUnistylesDependency)
292
506
 
293
- if (!t.isIfStatement(value)) {
294
- return []
295
- }
507
+ // add metadata about dependencies
508
+ if (styleDependencies.length > 0) {
509
+ const uniqueDependencies = Array.from(new Set(styleDependencies))
510
+
511
+ debugMessage(uniqueDependencies)
512
+
513
+ let targets = []
296
514
 
297
- return [value.consequent, value.alternate]
298
- .filter(Boolean)
299
- .flatMap(value => {
300
- if (t.isBlockStatement(value)) {
301
- return value.body.filter(t.isReturnStatement)
515
+ if (t.isArrowFunctionExpression(unistyle.value) || t.isFunctionExpression(unistyle.value)) {
516
+ if (t.isObjectExpression(unistyle.value.body)) {
517
+ targets.push(unistyle.value.body)
518
+ }
519
+
520
+ if (t.isBlockStatement(unistyle.value.body)) {
521
+ targets = getReturnStatementsFromBody(t, unistyle.value.body)
522
+ .map(node => {
523
+ if (t.isIdentifier(node.argument)) {
524
+ node.argument = t.objectExpression([
525
+ t.spreadElement(node.argument)
526
+ ])
302
527
  }
528
+
529
+ return node.argument
303
530
  })
304
- })
305
- .map(value => value.argument)
306
- }
531
+ }
532
+ }
307
533
 
308
- return []
309
- }
534
+ if (t.isObjectExpression(unistyle.value)) {
535
+ targets.push(unistyle.value)
536
+ }
537
+
538
+ if (t.isMemberExpression(unistyle.value)) {
539
+ // convert to object
540
+ unistyle.value = t.objectExpression([t.spreadElement(unistyle.value)])
310
541
 
311
- function addThemeDependencyToMemberExpression(t, path) {
312
- path.value = t.objectExpression([
313
- t.spreadElement(path.value),
314
- t.objectProperty(
315
- t.identifier('uni__dependencies'),
316
- t.arrayExpression([t.numericLiteral(UnistyleDependency.Theme)])
317
- )
318
- ])
542
+ targets.push(unistyle.value)
543
+ }
544
+
545
+ if (targets.length > 0) {
546
+ targets.forEach(target => {
547
+ target.properties.push(
548
+ t.objectProperty(
549
+ t.identifier('uni__dependencies'),
550
+ t.arrayExpression(uniqueDependencies.map(dep => t.numericLiteral(dep)))
551
+ )
552
+ )
553
+ })
554
+ }
555
+ }
319
556
  }
320
557
 
321
558
  module.exports = {
322
559
  isUnistylesStyleSheet,
323
- analyzeDependencies,
560
+ addDependencies,
324
561
  addStyleSheetTag,
325
- getUnistyles,
326
- isKindOfStyleSheet,
327
- getStyleSheetLocalNames,
328
- maybeAddThemeDependencyToMemberExpression,
329
- addThemeDependencyToMemberExpression
562
+ getStylesDependenciesFromObject,
563
+ getStylesDependenciesFromFunction,
564
+ isKindOfStyleSheet
330
565
  }
@@ -55,7 +55,7 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
55
55
  }}
56
56
  style={state => {
57
57
  const unistyles = typeof style === 'function'
58
- ? style(state)
58
+ ? style.call(style, state)
59
59
  : getStyles(style as unknown as Record<string, any>)
60
60
 
61
61
  if (!storedRef.current) {
package/plugin/common.js DELETED
@@ -1,154 +0,0 @@
1
- function getIdentifierNameFromExpression(t, memberExpression) {
2
- if (t.isIdentifier(memberExpression)) {
3
- return [memberExpression.name]
4
- }
5
-
6
- if (t.isSpreadElement(memberExpression)) {
7
- return [getIdentifierNameFromExpression(t, memberExpression.argument)].flat()
8
- }
9
-
10
- if (t.isObjectProperty(memberExpression)) {
11
- return [getIdentifierNameFromExpression(t, memberExpression.value)].flat()
12
- }
13
-
14
- if (t.isMemberExpression(memberExpression)) {
15
- if (memberExpression.computed) {
16
- return [
17
- getIdentifierNameFromExpression(t, memberExpression.property),
18
- getIdentifierNameFromExpression(t, memberExpression.object)
19
- ].flat()
20
- }
21
-
22
- const object = memberExpression.object
23
-
24
- // If the object is an Identifier, return its name
25
- if (t.isIdentifier(object)) {
26
- return [object.name]
27
- }
28
-
29
- // If the object is another MemberExpression, recursively get the identifier
30
- if (t.isMemberExpression(object)) {
31
- return getIdentifierNameFromExpression(t, object).flat()
32
- }
33
- }
34
-
35
- if (t.isBinaryExpression(memberExpression)) {
36
- return [
37
- getIdentifierNameFromExpression(t, memberExpression.left),
38
- getIdentifierNameFromExpression(t, memberExpression.right)
39
- ].flat()
40
- }
41
-
42
- if (t.isCallExpression(memberExpression)) {
43
- return getIdentifierNameFromExpression(t, memberExpression.callee)
44
- }
45
-
46
- if (t.isConditionalExpression(memberExpression)) {
47
- return [
48
- getIdentifierNameFromExpression(t, memberExpression.test.left),
49
- getIdentifierNameFromExpression(t, memberExpression.test.right),
50
- getIdentifierNameFromExpression(t, memberExpression.alternate),
51
- getIdentifierNameFromExpression(t, memberExpression.consequent),
52
- getIdentifierNameFromExpression(t, memberExpression.test)
53
- ].flat()
54
- }
55
-
56
- if (t.isArrayExpression(memberExpression)) {
57
- return memberExpression.elements.map(expression => getIdentifierNameFromExpression(t, expression)).flat()
58
- }
59
-
60
- if (t.isArrowFunctionExpression(memberExpression)) {
61
- return memberExpression.body.properties.map(prop => getIdentifierNameFromExpression(t, prop.value)).flat()
62
- }
63
-
64
- if (t.isTemplateLiteral(memberExpression)) {
65
- return memberExpression.expressions.map(expression => getIdentifierNameFromExpression(t, expression)).flat()
66
- }
67
-
68
- if (t.isObjectExpression(memberExpression)) {
69
- return memberExpression.properties
70
- .filter(property => t.isObjectProperty(property))
71
- .flatMap(property => getIdentifierNameFromExpression(t, property.value))
72
- }
73
-
74
- if (t.isUnaryExpression(memberExpression)) {
75
- return getIdentifierNameFromExpression(t, memberExpression.argument.object)
76
- }
77
-
78
- return []
79
- }
80
-
81
- function getSecondPropertyName(t, memberExpression) {
82
- if (t.isUnaryExpression(memberExpression)) {
83
- return getSecondPropertyName(t, memberExpression.argument.object)
84
- }
85
-
86
- if (t.isConditionalExpression(memberExpression)) {
87
- return [
88
- getSecondPropertyName(t, memberExpression.test.left),
89
- getSecondPropertyName(t, memberExpression.test.right),
90
- getSecondPropertyName(t, memberExpression.alternate),
91
- getSecondPropertyName(t, memberExpression.consequent),
92
- getSecondPropertyName(t, memberExpression.test)
93
- ].flat()
94
- }
95
-
96
- if (t.isTemplateLiteral(memberExpression)) {
97
- return memberExpression.expressions.map(expression => getSecondPropertyName(t, expression)).flat()
98
- }
99
-
100
- if (t.isBinaryExpression(memberExpression)) {
101
- return [
102
- getSecondPropertyName(t, memberExpression.left),
103
- getSecondPropertyName(t, memberExpression.right)
104
- ].flat()
105
- }
106
-
107
- if (t.isObjectExpression(memberExpression)) {
108
- return memberExpression.properties
109
- .filter(property => t.isObjectProperty(property))
110
- .flatMap(property => getSecondPropertyName(t, property.value))
111
- }
112
-
113
- if (t.isArrayExpression(memberExpression)) {
114
- return memberExpression.elements.map(expression => getSecondPropertyName(t, expression)).flat()
115
- }
116
-
117
- if (!t.isMemberExpression(memberExpression)) {
118
- return []
119
- }
120
-
121
- let current = memberExpression.computed
122
- ? memberExpression.property
123
- : memberExpression
124
- let propertyName = null
125
-
126
- while (t.isMemberExpression(current)) {
127
- propertyName = current.property
128
- current = current.object
129
- }
130
-
131
- // special case for IME
132
- if (propertyName && t.isIdentifier(propertyName) && propertyName.name === 'insets') {
133
- if (t.isIdentifier(memberExpression.property) && memberExpression.property.name === "ime") {
134
- return [memberExpression.property.name]
135
- }
136
-
137
- return [propertyName.name]
138
- }
139
-
140
- if (propertyName && t.isIdentifier(propertyName)) {
141
- return [propertyName.name]
142
- }
143
-
144
- if (propertyName) {
145
- return [propertyName.value]
146
- }
147
-
148
- return []
149
- }
150
-
151
- module.exports = {
152
- getIdentifierNameFromExpression,
153
- getSecondPropertyName
154
- }