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.
- package/Unistyles.podspec +33 -0
- package/cxx/common/Constants.h +1 -0
- package/cxx/common/Helpers.h +92 -0
- package/cxx/core/HostStyle.cpp +18 -12
- package/cxx/core/HostStyle.h +3 -0
- package/cxx/core/StyleSheet.h +0 -1
- package/cxx/core/StyleSheetRegistry.cpp +10 -13
- package/cxx/core/StyleSheetRegistry.h +4 -4
- package/cxx/core/Unistyle.h +7 -10
- package/cxx/core/UnistyleData.h +23 -0
- package/cxx/core/UnistyleWrapper.h +25 -7
- package/cxx/core/UnistylesCommitHook.cpp +8 -7
- package/cxx/core/UnistylesCommitHook.h +6 -1
- package/cxx/core/UnistylesCommitShadowNode.h +13 -0
- package/cxx/core/UnistylesMountHook.cpp +40 -0
- package/cxx/core/UnistylesMountHook.h +30 -0
- package/cxx/core/UnistylesRegistry.cpp +44 -75
- package/cxx/core/UnistylesRegistry.h +10 -11
- package/cxx/core/UnistylesState.cpp +4 -4
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +13 -6
- package/cxx/hybridObjects/HybridStyleSheet.cpp +35 -39
- package/cxx/hybridObjects/HybridStyleSheet.h +9 -6
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +34 -15
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +87 -165
- package/cxx/parser/Parser.h +8 -14
- package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
- package/cxx/shadowTree/ShadowTreeManager.cpp +3 -8
- package/ios/UnistylesModuleOnLoad.h +2 -0
- package/ios/UnistylesModuleOnLoad.mm +8 -1
- package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +3 -3
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +77 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/breakpoint.js +25 -0
- package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +76 -0
- package/lib/commonjs/web/convert/index.js.map +1 -0
- package/lib/commonjs/web/convert/module.d.js +2 -0
- package/lib/commonjs/web/convert/module.d.js.map +1 -0
- package/lib/commonjs/web/convert/shadow.js +68 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +89 -0
- package/lib/commonjs/web/convert/style.js.map +1 -0
- package/lib/commonjs/web/convert/textShadow.js +73 -0
- package/lib/commonjs/web/convert/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/transform.js +72 -0
- package/lib/commonjs/web/convert/transform.js.map +1 -0
- package/lib/commonjs/web/convert/types.js +9 -0
- package/lib/commonjs/web/convert/types.js.map +1 -0
- package/lib/commonjs/web/convert/utils.js +55 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +89 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/index.js +51 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener/index.js +13 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +36 -0
- package/lib/commonjs/web/listener/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +37 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/mq.js +23 -0
- package/lib/commonjs/web/mq.js.map +1 -0
- package/lib/commonjs/web/pseudo.js +11 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +37 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +164 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/state.js +121 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +78 -0
- package/lib/commonjs/web/utils.js.map +1 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +1 -0
- package/lib/commonjs/web/variants/index.js +28 -0
- package/lib/commonjs/web/variants/index.js.map +1 -0
- package/lib/commonjs/web/variants/useVariants.js +75 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- package/lib/module/specs/NavigtionBar/index.js +1 -1
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +3 -3
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/specs/index.web.js +1 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/breakpoint.js +20 -0
- package/lib/module/web/convert/breakpoint.js.map +1 -0
- package/lib/module/web/convert/index.js +71 -0
- package/lib/module/web/convert/index.js.map +1 -0
- package/lib/module/web/convert/module.d.js +2 -0
- package/lib/module/web/convert/module.d.js.map +1 -0
- package/lib/module/web/convert/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +84 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +68 -0
- package/lib/module/web/convert/textShadow.js.map +1 -0
- package/lib/module/web/convert/transform.js +67 -0
- package/lib/module/web/convert/transform.js.map +1 -0
- package/lib/module/web/convert/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +43 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +84 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/index.js +24 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener/index.js +4 -0
- package/lib/module/web/listener/index.js.map +1 -0
- package/lib/module/web/listener/listener.js +31 -0
- package/lib/module/web/listener/listener.js.map +1 -0
- package/lib/module/web/mock.js +33 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/mq.js +17 -0
- package/lib/module/web/mq.js.map +1 -0
- package/lib/module/web/pseudo.js +6 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +33 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +160 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/state.js +117 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +65 -0
- package/lib/module/web/utils.js.map +1 -0
- package/lib/module/web/variants/getVariants.js +34 -0
- package/lib/module/web/variants/getVariants.js.map +1 -0
- package/lib/module/web/variants/index.js +5 -0
- package/lib/module/web/variants/index.js.map +1 -0
- package/lib/module/web/variants/useVariants.js +70 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/example/App.d.ts.map +1 -1
- package/lib/typescript/example/Typography.d.ts +12 -0
- package/lib/typescript/example/Typography.d.ts.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +1 -1
- package/lib/typescript/src/specs/index.web.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/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/create.d.ts +11 -11
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/{web → src/web}/index.d.ts +12 -12
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
- package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
- package/lib/typescript/src/web/mock.d.ts.map +1 -0
- package/lib/typescript/src/web/mq.d.ts.map +1 -0
- package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/state.d.ts +4 -4
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
- package/lib/typescript/src/web/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/index.d.ts +3 -0
- package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
- package/package.json +2 -2
- package/plugin/__tests__/dependencies.spec.js +195 -107
- package/plugin/__tests__/ref.spec.js +537 -179
- package/plugin/__tests__/stylesheet.spec.js +174 -63
- package/plugin/index.js +68 -23
- package/plugin/ref.js +74 -12
- package/plugin/style.js +57 -24
- package/plugin/stylesheet.js +44 -1
- package/plugin/variants.js +33 -0
- package/src/specs/NavigtionBar/index.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +5 -5
- package/src/specs/StatusBar/index.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -1
- package/src/specs/UnistylesRuntime/index.ts +1 -1
- package/src/specs/index.web.ts +1 -1
- package/src/types/stylesheet.ts +1 -1
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +1 -1
- package/{web → src/web}/convert/types.ts +1 -1
- package/{web → src/web}/create.ts +36 -33
- package/{web → src/web}/listener/listener.ts +1 -1
- package/{web → src/web}/mock.ts +2 -2
- package/{web → src/web}/registry.ts +1 -1
- package/{web → src/web}/runtime.ts +4 -4
- package/{web → src/web}/state.ts +5 -5
- package/{web → src/web}/utils.ts +5 -5
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/{web → src/web/variants}/useVariants.ts +24 -44
- package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- package/lib/typescript/web/convert/index.d.ts.map +0 -1
- package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/style.d.ts.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/transform.d.ts.map +0 -1
- package/lib/typescript/web/convert/types.d.ts.map +0 -1
- package/lib/typescript/web/convert/utils.d.ts.map +0 -1
- package/lib/typescript/web/listener/index.d.ts.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- package/lib/typescript/web/mock.d.ts.map +0 -1
- package/lib/typescript/web/mq.d.ts.map +0 -1
- package/lib/typescript/web/pseudo.d.ts.map +0 -1
- package/lib/typescript/web/registry.d.ts.map +0 -1
- package/lib/typescript/web/runtime.d.ts.map +0 -1
- package/lib/typescript/web/state.d.ts.map +0 -1
- package/lib/typescript/web/useVariants.d.ts +0 -3
- package/lib/typescript/web/useVariants.d.ts.map +0 -1
- package/lib/typescript/web/utils.d.ts.map +0 -1
- /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
- /package/{web → src/web}/convert/boxShadow.ts +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
- /package/{web → src/web}/convert/shadow.ts +0 -0
- /package/{web → src/web}/convert/style.ts +0 -0
- /package/{web → src/web}/convert/textShadow.ts +0 -0
- /package/{web → src/web}/convert/transform.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
- /package/{web → src/web}/index.ts +0 -0
- /package/{web → src/web}/listener/index.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
- /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
|
-
|
55
|
-
|
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(
|
98
|
-
|
99
|
-
|
100
|
-
|
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(
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
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(
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
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(
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
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 {
|
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.
|
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
|
-
|
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
|
82
|
+
const metadata = getStyleMetadata(t, styleAttr.value.expression)
|
49
83
|
|
50
|
-
// style prop is
|
51
|
-
if (
|
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
|
-
|
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
|
-
|
65
|
-
|
97
|
+
if (!refProp && hasStringRef(t, path)) {
|
98
|
+
throw new Error("Detected string based ref which is not supported by Unistyles.")
|
99
|
+
}
|
66
100
|
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
83
|
-
|
84
|
-
|
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
|
111
|
-
|
112
|
-
|
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
|
}
|