react-native-unistyles 3.0.0-alpha.1 → 3.0.0-alpha.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. package/Unistyles.podspec +33 -0
  2. package/cxx/common/Constants.h +1 -0
  3. package/cxx/common/Helpers.h +92 -0
  4. package/cxx/core/HostStyle.cpp +18 -12
  5. package/cxx/core/HostStyle.h +3 -0
  6. package/cxx/core/StyleSheet.h +0 -1
  7. package/cxx/core/StyleSheetRegistry.cpp +10 -13
  8. package/cxx/core/StyleSheetRegistry.h +4 -4
  9. package/cxx/core/Unistyle.h +7 -10
  10. package/cxx/core/UnistyleData.h +23 -0
  11. package/cxx/core/UnistyleWrapper.h +25 -7
  12. package/cxx/core/UnistylesCommitHook.cpp +8 -7
  13. package/cxx/core/UnistylesCommitHook.h +6 -1
  14. package/cxx/core/UnistylesCommitShadowNode.h +13 -0
  15. package/cxx/core/UnistylesMountHook.cpp +40 -0
  16. package/cxx/core/UnistylesMountHook.h +30 -0
  17. package/cxx/core/UnistylesRegistry.cpp +44 -75
  18. package/cxx/core/UnistylesRegistry.h +10 -11
  19. package/cxx/core/UnistylesState.cpp +4 -4
  20. package/cxx/hybridObjects/HybridShadowRegistry.cpp +13 -6
  21. package/cxx/hybridObjects/HybridStyleSheet.cpp +35 -39
  22. package/cxx/hybridObjects/HybridStyleSheet.h +9 -6
  23. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +34 -15
  24. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  25. package/cxx/parser/Parser.cpp +87 -165
  26. package/cxx/parser/Parser.h +8 -14
  27. package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
  28. package/cxx/shadowTree/ShadowTreeManager.cpp +3 -8
  29. package/ios/UnistylesModuleOnLoad.h +2 -0
  30. package/ios/UnistylesModuleOnLoad.mm +8 -1
  31. package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
  32. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
  33. package/lib/commonjs/specs/ShadowRegistry/index.js +3 -3
  34. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  35. package/lib/commonjs/specs/StatusBar/index.js +1 -1
  36. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  37. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  38. package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
  39. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  40. package/lib/commonjs/specs/index.web.js +1 -1
  41. package/lib/commonjs/web/convert/boxShadow.js +77 -0
  42. package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
  43. package/lib/commonjs/web/convert/breakpoint.js +25 -0
  44. package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
  45. package/lib/commonjs/web/convert/index.js +76 -0
  46. package/lib/commonjs/web/convert/index.js.map +1 -0
  47. package/lib/commonjs/web/convert/module.d.js +2 -0
  48. package/lib/commonjs/web/convert/module.d.js.map +1 -0
  49. package/lib/commonjs/web/convert/shadow.js +68 -0
  50. package/lib/commonjs/web/convert/shadow.js.map +1 -0
  51. package/lib/commonjs/web/convert/style.js +89 -0
  52. package/lib/commonjs/web/convert/style.js.map +1 -0
  53. package/lib/commonjs/web/convert/textShadow.js +73 -0
  54. package/lib/commonjs/web/convert/textShadow.js.map +1 -0
  55. package/lib/commonjs/web/convert/transform.js +72 -0
  56. package/lib/commonjs/web/convert/transform.js.map +1 -0
  57. package/lib/commonjs/web/convert/types.js +9 -0
  58. package/lib/commonjs/web/convert/types.js.map +1 -0
  59. package/lib/commonjs/web/convert/utils.js +55 -0
  60. package/lib/commonjs/web/convert/utils.js.map +1 -0
  61. package/lib/commonjs/web/create.js +89 -0
  62. package/lib/commonjs/web/create.js.map +1 -0
  63. package/lib/commonjs/web/index.js +51 -0
  64. package/lib/commonjs/web/index.js.map +1 -0
  65. package/lib/commonjs/web/listener/index.js +13 -0
  66. package/lib/commonjs/web/listener/index.js.map +1 -0
  67. package/lib/commonjs/web/listener/listener.js +36 -0
  68. package/lib/commonjs/web/listener/listener.js.map +1 -0
  69. package/lib/commonjs/web/mock.js +37 -0
  70. package/lib/commonjs/web/mock.js.map +1 -0
  71. package/lib/commonjs/web/mq.js +23 -0
  72. package/lib/commonjs/web/mq.js.map +1 -0
  73. package/lib/commonjs/web/pseudo.js +11 -0
  74. package/lib/commonjs/web/pseudo.js.map +1 -0
  75. package/lib/commonjs/web/registry.js +37 -0
  76. package/lib/commonjs/web/registry.js.map +1 -0
  77. package/lib/commonjs/web/runtime.js +164 -0
  78. package/lib/commonjs/web/runtime.js.map +1 -0
  79. package/lib/commonjs/web/state.js +121 -0
  80. package/lib/commonjs/web/state.js.map +1 -0
  81. package/lib/commonjs/web/utils.js +78 -0
  82. package/lib/commonjs/web/utils.js.map +1 -0
  83. package/lib/commonjs/web/variants/getVariants.js +39 -0
  84. package/lib/commonjs/web/variants/getVariants.js.map +1 -0
  85. package/lib/commonjs/web/variants/index.js +28 -0
  86. package/lib/commonjs/web/variants/index.js.map +1 -0
  87. package/lib/commonjs/web/variants/useVariants.js +75 -0
  88. package/lib/commonjs/web/variants/useVariants.js.map +1 -0
  89. package/lib/module/specs/NavigtionBar/index.js +1 -1
  90. package/lib/module/specs/NavigtionBar/index.js.map +1 -1
  91. package/lib/module/specs/ShadowRegistry/index.js +3 -3
  92. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  93. package/lib/module/specs/StatusBar/index.js +1 -1
  94. package/lib/module/specs/StatusBar/index.js.map +1 -1
  95. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  96. package/lib/module/specs/UnistylesRuntime/index.js +1 -1
  97. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  98. package/lib/module/specs/index.web.js +1 -1
  99. package/lib/module/specs/index.web.js.map +1 -1
  100. package/lib/module/web/convert/boxShadow.js +72 -0
  101. package/lib/module/web/convert/boxShadow.js.map +1 -0
  102. package/lib/module/web/convert/breakpoint.js +20 -0
  103. package/lib/module/web/convert/breakpoint.js.map +1 -0
  104. package/lib/module/web/convert/index.js +71 -0
  105. package/lib/module/web/convert/index.js.map +1 -0
  106. package/lib/module/web/convert/module.d.js +2 -0
  107. package/lib/module/web/convert/module.d.js.map +1 -0
  108. package/lib/module/web/convert/shadow.js +63 -0
  109. package/lib/module/web/convert/shadow.js.map +1 -0
  110. package/lib/module/web/convert/style.js +84 -0
  111. package/lib/module/web/convert/style.js.map +1 -0
  112. package/lib/module/web/convert/textShadow.js +68 -0
  113. package/lib/module/web/convert/textShadow.js.map +1 -0
  114. package/lib/module/web/convert/transform.js +67 -0
  115. package/lib/module/web/convert/transform.js.map +1 -0
  116. package/lib/module/web/convert/types.js +5 -0
  117. package/lib/module/web/convert/types.js.map +1 -0
  118. package/lib/module/web/convert/utils.js +43 -0
  119. package/lib/module/web/convert/utils.js.map +1 -0
  120. package/lib/module/web/create.js +84 -0
  121. package/lib/module/web/create.js.map +1 -0
  122. package/lib/module/web/index.js +24 -0
  123. package/lib/module/web/index.js.map +1 -0
  124. package/lib/module/web/listener/index.js +4 -0
  125. package/lib/module/web/listener/index.js.map +1 -0
  126. package/lib/module/web/listener/listener.js +31 -0
  127. package/lib/module/web/listener/listener.js.map +1 -0
  128. package/lib/module/web/mock.js +33 -0
  129. package/lib/module/web/mock.js.map +1 -0
  130. package/lib/module/web/mq.js +17 -0
  131. package/lib/module/web/mq.js.map +1 -0
  132. package/lib/module/web/pseudo.js +6 -0
  133. package/lib/module/web/pseudo.js.map +1 -0
  134. package/lib/module/web/registry.js +33 -0
  135. package/lib/module/web/registry.js.map +1 -0
  136. package/lib/module/web/runtime.js +160 -0
  137. package/lib/module/web/runtime.js.map +1 -0
  138. package/lib/module/web/state.js +117 -0
  139. package/lib/module/web/state.js.map +1 -0
  140. package/lib/module/web/utils.js +65 -0
  141. package/lib/module/web/utils.js.map +1 -0
  142. package/lib/module/web/variants/getVariants.js +34 -0
  143. package/lib/module/web/variants/getVariants.js.map +1 -0
  144. package/lib/module/web/variants/index.js +5 -0
  145. package/lib/module/web/variants/index.js.map +1 -0
  146. package/lib/module/web/variants/useVariants.js +70 -0
  147. package/lib/module/web/variants/useVariants.js.map +1 -0
  148. package/lib/typescript/example/App.d.ts.map +1 -1
  149. package/lib/typescript/example/Typography.d.ts +12 -0
  150. package/lib/typescript/example/Typography.d.ts.map +1 -0
  151. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
  152. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  153. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  154. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  155. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  156. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  157. package/lib/typescript/src/types/stylesheet.d.ts +1 -1
  158. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  159. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
  160. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
  161. package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
  162. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  163. package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
  164. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  165. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
  166. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
  167. package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
  168. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  169. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  170. package/lib/typescript/{web → src/web}/create.d.ts +11 -11
  171. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  172. package/lib/typescript/{web → src/web}/index.d.ts +12 -12
  173. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  174. package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
  175. package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
  176. package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
  177. package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
  178. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  179. package/lib/typescript/src/web/mq.d.ts.map +1 -0
  180. package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
  181. package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
  182. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  183. package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
  184. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  185. package/lib/typescript/{web → src/web}/state.d.ts +4 -4
  186. package/lib/typescript/src/web/state.d.ts.map +1 -0
  187. package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
  188. package/lib/typescript/src/web/utils.d.ts.map +1 -0
  189. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  190. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  191. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  192. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  193. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  194. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  195. package/package.json +2 -2
  196. package/plugin/__tests__/dependencies.spec.js +195 -107
  197. package/plugin/__tests__/ref.spec.js +537 -179
  198. package/plugin/__tests__/stylesheet.spec.js +174 -63
  199. package/plugin/index.js +68 -23
  200. package/plugin/ref.js +74 -12
  201. package/plugin/style.js +57 -24
  202. package/plugin/stylesheet.js +44 -1
  203. package/plugin/variants.js +33 -0
  204. package/src/specs/NavigtionBar/index.ts +1 -1
  205. package/src/specs/ShadowRegistry/index.ts +5 -5
  206. package/src/specs/StatusBar/index.ts +1 -1
  207. package/src/specs/StyleSheet/index.ts +3 -1
  208. package/src/specs/UnistylesRuntime/index.ts +1 -1
  209. package/src/specs/index.web.ts +1 -1
  210. package/src/types/stylesheet.ts +1 -1
  211. package/{web → src/web}/convert/breakpoint.ts +1 -1
  212. package/{web → src/web}/convert/index.ts +1 -1
  213. package/{web → src/web}/convert/types.ts +1 -1
  214. package/{web → src/web}/create.ts +36 -33
  215. package/{web → src/web}/listener/listener.ts +1 -1
  216. package/{web → src/web}/mock.ts +2 -2
  217. package/{web → src/web}/registry.ts +1 -1
  218. package/{web → src/web}/runtime.ts +4 -4
  219. package/{web → src/web}/state.ts +5 -5
  220. package/{web → src/web}/utils.ts +5 -5
  221. package/src/web/variants/getVariants.ts +42 -0
  222. package/src/web/variants/index.ts +2 -0
  223. package/{web → src/web/variants}/useVariants.ts +24 -44
  224. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  225. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  226. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  227. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  228. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  229. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  230. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  231. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  232. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  233. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  234. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  235. package/lib/typescript/web/mock.d.ts.map +0 -1
  236. package/lib/typescript/web/mq.d.ts.map +0 -1
  237. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  238. package/lib/typescript/web/registry.d.ts.map +0 -1
  239. package/lib/typescript/web/runtime.d.ts.map +0 -1
  240. package/lib/typescript/web/state.d.ts.map +0 -1
  241. package/lib/typescript/web/useVariants.d.ts +0 -3
  242. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  243. package/lib/typescript/web/utils.d.ts.map +0 -1
  244. /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
  245. /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
  246. /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
  247. /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
  248. /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
  249. /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
  250. /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
  251. /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
  252. /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
  253. /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
  254. /package/{web → src/web}/convert/boxShadow.ts +0 -0
  255. /package/{web → src/web}/convert/module.d.ts +0 -0
  256. /package/{web → src/web}/convert/shadow.ts +0 -0
  257. /package/{web → src/web}/convert/style.ts +0 -0
  258. /package/{web → src/web}/convert/textShadow.ts +0 -0
  259. /package/{web → src/web}/convert/transform.ts +0 -0
  260. /package/{web → src/web}/convert/utils.ts +0 -0
  261. /package/{web → src/web}/index.ts +0 -0
  262. /package/{web → src/web}/listener/index.ts +0 -0
  263. /package/{web → src/web}/mq.ts +0 -0
  264. /package/{web → src/web}/pseudo.ts +0 -0
@@ -16,6 +16,7 @@ pluginTester({
16
16
  {
17
17
  title: 'Should not add dependencies to StyleSheet if user is not using theme or miniRuntime',
18
18
  code: `
19
+ import { View, Text } from 'react-native'
19
20
  import { StyleSheet } from 'react-native-unistyles'
20
21
 
21
22
  export const Example = () => {
@@ -34,14 +35,15 @@ pluginTester({
34
35
  `,
35
36
  output: `
36
37
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
38
+ import { View, Text } from 'react-native'
37
39
  import { StyleSheet } from 'react-native-unistyles'
38
40
 
39
41
  export const Example = () => {
40
42
  return (
41
43
  <View
42
- style={styles.container}
44
+ style={[styles.container]}
43
45
  ref={ref => {
44
- UnistylesShadowRegistry.add(ref, styles.container)
46
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
45
47
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
46
48
  }}
47
49
  >
@@ -50,16 +52,20 @@ pluginTester({
50
52
  )
51
53
  }
52
54
 
53
- const styles = StyleSheet.create({
54
- container: {
55
- backgroundColor: 'red'
56
- }
57
- })
55
+ const styles = StyleSheet.create(
56
+ {
57
+ container: {
58
+ backgroundColor: 'red'
59
+ }
60
+ },
61
+ 793953373
62
+ )
58
63
  `
59
64
  },
60
65
  {
61
66
  title: 'Should add dependencies to StyleSheet if user is using theme',
62
67
  code: `
68
+ import { View, Text } from 'react-native'
63
69
  import { StyleSheet } from 'react-native-unistyles'
64
70
 
65
71
  export const Example = () => {
@@ -78,14 +84,15 @@ pluginTester({
78
84
  `,
79
85
  output: `
80
86
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
87
+ import { View, Text } from 'react-native'
81
88
  import { StyleSheet } from 'react-native-unistyles'
82
89
 
83
90
  export const Example = () => {
84
91
  return (
85
92
  <View
86
- style={styles.container}
93
+ style={[styles.container]}
87
94
  ref={ref => {
88
- UnistylesShadowRegistry.add(ref, styles.container)
95
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
89
96
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
90
97
  }}
91
98
  >
@@ -94,17 +101,21 @@ pluginTester({
94
101
  )
95
102
  }
96
103
 
97
- const styles = StyleSheet.create(theme => ({
98
- container: {
99
- backgroundColor: theme.colors.background,
100
- uni__dependencies: [0]
101
- }
102
- }))
104
+ const styles = StyleSheet.create(
105
+ theme => ({
106
+ container: {
107
+ backgroundColor: theme.colors.background,
108
+ uni__dependencies: [0]
109
+ }
110
+ }),
111
+ 793953373
112
+ )
103
113
  `
104
114
  },
105
115
  {
106
116
  title: 'Should add dependencies to StyleSheet even if user did rename import',
107
117
  code: `
118
+ import { View, Text } from 'react-native'
108
119
  import { StyleSheet as ST } from 'react-native-unistyles'
109
120
 
110
121
  export const Example = () => {
@@ -123,14 +134,15 @@ pluginTester({
123
134
  `,
124
135
  output: `
125
136
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
137
+ import { View, Text } from 'react-native'
126
138
  import { StyleSheet as ST } from 'react-native-unistyles'
127
139
 
128
140
  export const Example = () => {
129
141
  return (
130
142
  <View
131
- style={styles.container}
143
+ style={[styles.container]}
132
144
  ref={ref => {
133
- UnistylesShadowRegistry.add(ref, styles.container)
145
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
134
146
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
135
147
  }}
136
148
  >
@@ -139,17 +151,21 @@ pluginTester({
139
151
  )
140
152
  }
141
153
 
142
- const styles = ST.create(theme => ({
143
- container: {
144
- backgroundColor: theme.colors.background,
145
- uni__dependencies: [0]
146
- }
147
- }))
154
+ const styles = ST.create(
155
+ theme => ({
156
+ container: {
157
+ backgroundColor: theme.colors.background,
158
+ uni__dependencies: [0]
159
+ }
160
+ }),
161
+ 793953373
162
+ )
148
163
  `
149
164
  },
150
165
  {
151
166
  title: 'Should detect variants for object StyleSheet',
152
167
  code: `
168
+ import { View, Text } from 'react-native'
153
169
  import { StyleSheet } from 'react-native-unistyles'
154
170
 
155
171
  export const Example = () => {
@@ -169,14 +185,15 @@ pluginTester({
169
185
  `,
170
186
  output: `
171
187
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
188
+ import { View, Text } from 'react-native'
172
189
  import { StyleSheet } from 'react-native-unistyles'
173
190
 
174
191
  export const Example = () => {
175
192
  return (
176
193
  <View
177
- style={styles.container}
194
+ style={[styles.container]}
178
195
  ref={ref => {
179
- UnistylesShadowRegistry.add(ref, styles.container)
196
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
180
197
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
181
198
  }}
182
199
  >
@@ -185,18 +202,22 @@ pluginTester({
185
202
  )
186
203
  }
187
204
 
188
- const styles = StyleSheet.create({
189
- container: {
190
- backgroundColor: 'red',
191
- variants: {},
192
- uni__dependencies: [4]
193
- }
194
- })
205
+ const styles = StyleSheet.create(
206
+ {
207
+ container: {
208
+ backgroundColor: 'red',
209
+ variants: {},
210
+ uni__dependencies: [4]
211
+ }
212
+ },
213
+ 793953373
214
+ )
195
215
  `
196
216
  },
197
217
  {
198
218
  title: 'Should detect variants for object StyleSheet and dynamic function',
199
219
  code: `
220
+ import { View, Text } from 'react-native'
200
221
  import { StyleSheet } from 'react-native-unistyles'
201
222
 
202
223
  export const Example = () => {
@@ -216,14 +237,15 @@ pluginTester({
216
237
  `,
217
238
  output: `
218
239
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
240
+ import { View, Text } from 'react-native'
219
241
  import { StyleSheet } from 'react-native-unistyles'
220
242
 
221
243
  export const Example = () => {
222
244
  return (
223
245
  <View
224
- style={styles.container}
246
+ style={[styles.container]}
225
247
  ref={ref => {
226
- UnistylesShadowRegistry.add(ref, styles.container)
248
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
227
249
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
228
250
  }}
229
251
  >
@@ -232,18 +254,22 @@ pluginTester({
232
254
  )
233
255
  }
234
256
 
235
- const styles = StyleSheet.create({
236
- container: () => ({
237
- backgroundColor: 'red',
238
- variants: {},
239
- uni__dependencies: [4]
240
- })
241
- })
257
+ const styles = StyleSheet.create(
258
+ {
259
+ container: () => ({
260
+ backgroundColor: 'red',
261
+ variants: {},
262
+ uni__dependencies: [4]
263
+ })
264
+ },
265
+ 793953373
266
+ )
242
267
  `
243
268
  },
244
269
  {
245
270
  title: 'Should detect miniRuntime dependency',
246
271
  code: `
272
+ import { View, Text } from 'react-native'
247
273
  import { StyleSheet } from 'react-native-unistyles'
248
274
 
249
275
  export const Example = () => {
@@ -264,14 +290,15 @@ pluginTester({
264
290
  `,
265
291
  output: `
266
292
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
293
+ import { View, Text } from 'react-native'
267
294
  import { StyleSheet } from 'react-native-unistyles'
268
295
 
269
296
  export const Example = () => {
270
297
  return (
271
298
  <View
272
- style={styles.container}
299
+ style={[styles.container]}
273
300
  ref={ref => {
274
- UnistylesShadowRegistry.add(ref, styles.container)
301
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
275
302
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
276
303
  }}
277
304
  >
@@ -280,19 +307,23 @@ pluginTester({
280
307
  )
281
308
  }
282
309
 
283
- const styles = StyleSheet.create((_, rt) => ({
284
- container: () => ({
285
- backgroundColor: 'red',
286
- variants: {},
287
- paddingTop: rt.insets.top,
288
- uni__dependencies: [4, 9]
289
- })
290
- }))
310
+ const styles = StyleSheet.create(
311
+ (_, rt) => ({
312
+ container: () => ({
313
+ backgroundColor: 'red',
314
+ variants: {},
315
+ paddingTop: rt.insets.top,
316
+ uni__dependencies: [4, 9]
317
+ })
318
+ }),
319
+ 793953373
320
+ )
291
321
  `
292
322
  },
293
323
  {
294
324
  title: 'Should detect miniRuntime and theme dependencies even if user renamed it\'s names',
295
325
  code: `
326
+ import { View, Text } from 'react-native'
296
327
  import { StyleSheet } from 'react-native-unistyles'
297
328
 
298
329
  export const Example = () => {
@@ -313,14 +344,15 @@ pluginTester({
313
344
  `,
314
345
  output: `
315
346
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
347
+ import { View, Text } from 'react-native'
316
348
  import { StyleSheet } from 'react-native-unistyles'
317
349
 
318
350
  export const Example = () => {
319
351
  return (
320
352
  <View
321
- style={styles.container}
353
+ style={[styles.container]}
322
354
  ref={ref => {
323
- UnistylesShadowRegistry.add(ref, styles.container)
355
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
324
356
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
325
357
  }}
326
358
  >
@@ -329,19 +361,23 @@ pluginTester({
329
361
  )
330
362
  }
331
363
 
332
- const styles = StyleSheet.create((hhsa, dee) => ({
333
- container: () => ({
334
- backgroundColor: hhsa.colors.background,
335
- variants: {},
336
- paddingTop: dee.colorScheme === 'dark' ? 0 : 10,
337
- uni__dependencies: [0, 4, 5]
338
- })
339
- }))
364
+ const styles = StyleSheet.create(
365
+ (hhsa, dee) => ({
366
+ container: () => ({
367
+ backgroundColor: hhsa.colors.background,
368
+ variants: {},
369
+ paddingTop: dee.colorScheme === 'dark' ? 0 : 10,
370
+ uni__dependencies: [0, 4, 5]
371
+ })
372
+ }),
373
+ 793953373
374
+ )
340
375
  `
341
376
  },
342
377
  {
343
378
  title: 'Should detect dependencies in function',
344
379
  code: `
380
+ import { View, Text } from 'react-native'
345
381
  import { StyleSheet } from 'react-native-unistyles'
346
382
 
347
383
  export const Example = () => {
@@ -364,14 +400,15 @@ pluginTester({
364
400
  `,
365
401
  output: `
366
402
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
403
+ import { View, Text } from 'react-native'
367
404
  import { StyleSheet } from 'react-native-unistyles'
368
405
 
369
406
  export const Example = () => {
370
407
  return (
371
408
  <View
372
- style={styles.container}
409
+ style={[styles.container]}
373
410
  ref={ref => {
374
- UnistylesShadowRegistry.add(ref, styles.container)
411
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
375
412
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
376
413
  }}
377
414
  >
@@ -389,7 +426,81 @@ pluginTester({
389
426
  uni__dependencies: [0, 4, 9]
390
427
  })
391
428
  }
429
+ }, 793953373)
430
+ `
431
+ },
432
+ {
433
+ title: 'Should generates two different ids for 2 stylesheets in the same file',
434
+ code: `
435
+ import { View, Text } from 'react-native'
436
+ import { StyleSheet } from 'react-native-unistyles'
437
+
438
+ export const Example = () => {
439
+ return (
440
+ <View style={styles.container}>
441
+ <Text>Hello world</Text>
442
+ </View>
443
+ )
444
+ }
445
+
446
+ const styles = StyleSheet.create((theme, rt) => {
447
+ return {
448
+ container: () => ({
449
+ backgroundColor: theme.colors.background,
450
+ variants: {},
451
+ paddingTop: rt.insets.top
452
+ })
453
+ }
392
454
  })
455
+ const styles2 = StyleSheet.create((theme, rt) => {
456
+ return {
457
+ container: () => ({
458
+ backgroundColor: theme.colors.background,
459
+ variants: {},
460
+ paddingTop: rt.insets.top
461
+ })
462
+ }
463
+ })
464
+ `,
465
+ output: `
466
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
467
+ import { View, Text } from 'react-native'
468
+ import { StyleSheet } from 'react-native-unistyles'
469
+
470
+ export const Example = () => {
471
+ return (
472
+ <View
473
+ style={[styles.container]}
474
+ ref={ref => {
475
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
476
+ return () => UnistylesShadowRegistry.remove(ref, styles.container)
477
+ }}
478
+ >
479
+ <Text>Hello world</Text>
480
+ </View>
481
+ )
482
+ }
483
+
484
+ const styles = StyleSheet.create((theme, rt) => {
485
+ return {
486
+ container: () => ({
487
+ backgroundColor: theme.colors.background,
488
+ variants: {},
489
+ paddingTop: rt.insets.top,
490
+ uni__dependencies: [0, 4, 9]
491
+ })
492
+ }
493
+ }, 793953373)
494
+ const styles2 = StyleSheet.create((theme, rt) => {
495
+ return {
496
+ container: () => ({
497
+ backgroundColor: theme.colors.background,
498
+ variants: {},
499
+ paddingTop: rt.insets.top,
500
+ uni__dependencies: [0, 4, 9]
501
+ })
502
+ }
503
+ }, 793953374)
393
504
  `
394
505
  },
395
506
  ]
package/plugin/index.js CHANGED
@@ -1,7 +1,28 @@
1
1
  const addShadowRegistryImport = require('./import')
2
- const { getStyleObjectPath, getStyleAttribute } = require('./style')
2
+ const { getStyleMetadata, getStyleAttribute, styleAttributeToArray } = require('./style')
3
3
  const { getRefProp, addRef, overrideRef, hasStringRef } = require('./ref')
4
- const { isUnistylesStyleSheet, analyzeDependencies } = require('./stylesheet')
4
+ const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyle } = require('./stylesheet')
5
+ const { isUsingVariants, extractVariants } = require('./variants')
6
+
7
+ const reactNativeComponentNames = [
8
+ 'View',
9
+ 'Text',
10
+ 'Image',
11
+ 'ImageBackground',
12
+ 'KeyboardAvoidingView',
13
+ 'Modal',
14
+ 'Pressable',
15
+ 'ScrollView',
16
+ 'FlatList',
17
+ 'SectionList',
18
+ 'Switch',
19
+ 'Text',
20
+ 'TextInput',
21
+ 'TouchableHighlight',
22
+ 'TouchableOpacity',
23
+ 'TouchableWithoutFeedback',
24
+ 'VirtualizedList'
25
+ ]
5
26
 
6
27
  module.exports = function ({ types: t }) {
7
28
  return {
@@ -12,7 +33,8 @@ module.exports = function ({ types: t }) {
12
33
  state.file.hasAnyUnistyle = false
13
34
  state.file.hasUnistylesImport = false
14
35
  state.file.styleSheetLocalName = ''
15
- state.file.webDynamicFunctions = {}
36
+ state.file.tagNumber = 0
37
+ state.reactNativeImports = {}
16
38
  },
17
39
  exit(path, state) {
18
40
  if (state.file.hasAnyUnistyle) {
@@ -32,9 +54,21 @@ module.exports = function ({ types: t }) {
32
54
  }
33
55
  })
34
56
  }
57
+
58
+ if (importSource.includes('react-native')) {
59
+ path.node.specifiers.forEach(specifier => {
60
+ if (specifier.imported && reactNativeComponentNames.includes(specifier.imported.name)) {
61
+ state.reactNativeImports[specifier.local.name] = true
62
+ }
63
+ })
64
+ }
35
65
  },
36
66
  JSXElement(path, state) {
37
- if (!state.file.hasUnistylesImport) {
67
+ const openingElement = path.node.openingElement
68
+ const openingElementName = openingElement.name.name
69
+ const isReactNativeComponent = Boolean(state.reactNativeImports[openingElementName])
70
+
71
+ if (!isReactNativeComponent) {
38
72
  return
39
73
  }
40
74
 
@@ -45,43 +79,52 @@ module.exports = function ({ types: t }) {
45
79
  return
46
80
  }
47
81
 
48
- const stylePath = getStyleObjectPath(t, styleAttr.value.expression, state)
82
+ const metadata = getStyleMetadata(t, styleAttr.value.expression)
49
83
 
50
- // style prop is not using object expression
51
- if (stylePath.length !== 2) {
84
+ // style prop is using unexpected expression
85
+ if (metadata.length === 0) {
52
86
  return
53
87
  }
54
88
 
89
+ styleAttributeToArray(t, path)
90
+
55
91
  // to add import
56
92
  state.file.hasAnyUnistyle = true
57
93
 
58
- const refProp = getRefProp(t, path)
59
-
60
- if (!refProp && hasStringRef(t, path)) {
61
- throw new Error("Detected string based ref which is not supported by Unistyles.")
62
- }
94
+ metadata.forEach(meta => {
95
+ const refProp = getRefProp(t, path)
63
96
 
64
- const styleObj = stylePath[0]
65
- const styleProp = stylePath[1]
97
+ if (!refProp && hasStringRef(t, path)) {
98
+ throw new Error("Detected string based ref which is not supported by Unistyles.")
99
+ }
66
100
 
67
- refProp
68
- ? overrideRef(t, path, refProp, styleObj, styleProp)
69
- : addRef(t, path, styleObj, styleProp)
101
+ refProp
102
+ ? overrideRef(t, path, refProp, meta, state)
103
+ : addRef(t, path, meta, state)
104
+ })
70
105
  },
71
106
  CallExpression(path, state) {
107
+ if (isUsingVariants(t, path)) {
108
+ extractVariants(t, path, state)
109
+ }
110
+
72
111
  if (!isUnistylesStyleSheet(t, path, state)) {
73
112
  return
74
113
  }
75
114
 
115
+ addStyleSheetTag(t, path, state)
116
+
76
117
  const arg = path.node.arguments[0]
77
118
 
78
119
  // Object passed to StyleSheet.create
79
120
  if (t.isObjectExpression(arg)) {
80
121
  arg.properties.forEach(property => {
81
122
  if (t.isObjectProperty(property)) {
82
- const propertyValue = t.isArrowFunctionExpression(property.value)
83
- ? property.value.body
84
- : property.value
123
+ const propertyValue = getUnistyle(t, property)
124
+
125
+ if (!propertyValue) {
126
+ return
127
+ }
85
128
 
86
129
  analyzeDependencies(t, state, property.key.name, propertyValue)
87
130
  }
@@ -107,9 +150,11 @@ module.exports = function ({ types: t }) {
107
150
  if (t.isObjectExpression(body)) {
108
151
  body.properties.forEach(property => {
109
152
  if (t.isObjectProperty(property)) {
110
- const propertyValue = t.isArrowFunctionExpression(property.value)
111
- ? property.value.body
112
- : property.value
153
+ const propertyValue = getUnistyle(t, property)
154
+
155
+ if (!propertyValue) {
156
+ return
157
+ }
113
158
 
114
159
  analyzeDependencies(t, state, property.key.name, propertyValue, themeLocalName, miniRuntimeLocalName)
115
160
  }