@tamagui/static 2.7.7 → 3.0.0-beta.643.1

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.
Files changed (329) hide show
  1. package/dist/cjs/check-dep-versions.cjs +355 -0
  2. package/dist/cjs/checkDeps.cjs +302 -0
  3. package/dist/cjs/compiler.cjs +286 -0
  4. package/dist/cjs/compilerHost.cjs +1695 -0
  5. package/dist/cjs/constants.cjs +33 -0
  6. package/dist/cjs/domStructuralPass.cjs +112 -0
  7. package/dist/cjs/exports.cjs +42 -0
  8. package/dist/cjs/extractor/addLocalExports.cjs +64 -0
  9. package/dist/cjs/extractor/bundle.cjs +203 -0
  10. package/dist/cjs/extractor/bundleConfig.cjs +747 -0
  11. package/dist/cjs/extractor/concatClassName.cjs +117 -0
  12. package/dist/cjs/extractor/detectModuleFormat.cjs +54 -0
  13. package/dist/cjs/extractor/esbuildAliasPlugin.cjs +47 -0
  14. package/dist/cjs/extractor/esbuildTsconfigPaths.cjs +92 -0
  15. package/dist/cjs/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +38 -0
  16. package/dist/cjs/extractor/loadTamagui.cjs +344 -0
  17. package/dist/cjs/extractor/regenerateConfig.cjs +161 -0
  18. package/dist/cjs/extractor/watchTamaguiConfig.cjs +64 -0
  19. package/dist/cjs/getPragmaOptions.cjs +67 -0
  20. package/dist/cjs/helpers/memoize.cjs +42 -0
  21. package/dist/cjs/helpers/requireTamaguiCore.cjs +40 -0
  22. package/dist/cjs/index.cjs +34 -0
  23. package/dist/cjs/registerRequire.cjs +220 -0
  24. package/dist/cjs/server.cjs +66 -0
  25. package/dist/cjs/staticEvaluationIgnoredModules.cjs +86 -0
  26. package/dist/cjs/types.cjs +17 -0
  27. package/dist/cjs/zero/artifact.cjs +145 -0
  28. package/dist/cjs/zero/graph.cjs +209 -0
  29. package/dist/cjs/zero/identity.cjs +61 -0
  30. package/dist/cjs/zero/index.cjs +26 -0
  31. package/dist/cjs/zero/islands.cjs +232 -0
  32. package/dist/cjs/zero/options.cjs +163 -0
  33. package/dist/cjs/zero/ownership.cjs +79 -0
  34. package/dist/cjs/zero/theme.cjs +328 -0
  35. package/dist/cjs/zero/transform.cjs +203 -0
  36. package/dist/esm/check-dep-versions.mjs +329 -0
  37. package/dist/esm/check-dep-versions.mjs.map +1 -0
  38. package/dist/esm/checkDeps.mjs +279 -0
  39. package/dist/esm/checkDeps.mjs.map +1 -0
  40. package/dist/esm/compiler.mjs +255 -0
  41. package/dist/esm/compiler.mjs.map +1 -0
  42. package/dist/esm/compilerHost.mjs +1675 -0
  43. package/dist/esm/compilerHost.mjs.map +1 -0
  44. package/dist/esm/constants.mjs +7 -0
  45. package/dist/esm/constants.mjs.map +1 -0
  46. package/dist/esm/domStructuralPass.mjs +92 -0
  47. package/dist/esm/domStructuralPass.mjs.map +1 -0
  48. package/dist/esm/exports.mjs +26 -0
  49. package/dist/esm/extractor/addLocalExports.mjs +44 -0
  50. package/dist/esm/extractor/addLocalExports.mjs.map +1 -0
  51. package/dist/esm/extractor/bundle.mjs +173 -0
  52. package/dist/esm/extractor/bundle.mjs.map +1 -0
  53. package/dist/esm/extractor/bundleConfig.mjs +706 -0
  54. package/dist/esm/extractor/bundleConfig.mjs.map +1 -0
  55. package/dist/esm/extractor/concatClassName.mjs +96 -0
  56. package/dist/esm/extractor/concatClassName.mjs.map +1 -0
  57. package/dist/esm/extractor/detectModuleFormat.mjs +31 -0
  58. package/dist/esm/extractor/detectModuleFormat.mjs.map +1 -0
  59. package/dist/esm/extractor/esbuildAliasPlugin.mjs +26 -0
  60. package/dist/esm/extractor/esbuildAliasPlugin.mjs.map +1 -0
  61. package/dist/esm/extractor/esbuildTsconfigPaths.mjs +63 -0
  62. package/dist/esm/extractor/esbuildTsconfigPaths.mjs.map +1 -0
  63. package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs +18 -0
  64. package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs.map +1 -0
  65. package/dist/esm/extractor/loadTamagui.mjs +306 -0
  66. package/dist/esm/extractor/loadTamagui.mjs.map +1 -0
  67. package/dist/esm/extractor/regenerateConfig.mjs +131 -0
  68. package/dist/esm/extractor/regenerateConfig.mjs.map +1 -0
  69. package/dist/esm/extractor/watchTamaguiConfig.mjs +43 -0
  70. package/dist/esm/extractor/watchTamaguiConfig.mjs.map +1 -0
  71. package/dist/esm/getPragmaOptions.mjs +46 -0
  72. package/dist/esm/getPragmaOptions.mjs.map +1 -0
  73. package/dist/esm/helpers/memoize.mjs +21 -0
  74. package/dist/esm/helpers/memoize.mjs.map +1 -0
  75. package/dist/esm/helpers/requireTamaguiCore.mjs +19 -0
  76. package/dist/esm/helpers/requireTamaguiCore.mjs.map +1 -0
  77. package/dist/esm/index.mjs +8 -0
  78. package/dist/esm/index.mjs.map +1 -0
  79. package/dist/esm/registerRequire.mjs +195 -0
  80. package/dist/esm/registerRequire.mjs.map +1 -0
  81. package/dist/esm/server.mjs +40 -0
  82. package/dist/esm/server.mjs.map +1 -0
  83. package/dist/esm/setup.mjs +0 -0
  84. package/dist/esm/staticEvaluationIgnoredModules.mjs +61 -0
  85. package/dist/esm/staticEvaluationIgnoredModules.mjs.map +1 -0
  86. package/dist/esm/types.mjs +0 -0
  87. package/dist/esm/zero/artifact.mjs +119 -0
  88. package/dist/esm/zero/artifact.mjs.map +1 -0
  89. package/dist/esm/zero/graph.mjs +170 -0
  90. package/dist/esm/zero/graph.mjs.map +1 -0
  91. package/dist/esm/zero/identity.mjs +36 -0
  92. package/dist/esm/zero/identity.mjs.map +1 -0
  93. package/dist/esm/zero/index.mjs +15 -0
  94. package/dist/esm/zero/islands.mjs +197 -0
  95. package/dist/esm/zero/islands.mjs.map +1 -0
  96. package/dist/esm/zero/options.mjs +129 -0
  97. package/dist/esm/zero/options.mjs.map +1 -0
  98. package/dist/esm/zero/ownership.mjs +48 -0
  99. package/dist/esm/zero/ownership.mjs.map +1 -0
  100. package/dist/esm/zero/theme.mjs +303 -0
  101. package/dist/esm/zero/theme.mjs.map +1 -0
  102. package/dist/esm/zero/transform.mjs +177 -0
  103. package/dist/esm/zero/transform.mjs.map +1 -0
  104. package/package.json +33 -43
  105. package/src/check-dep-versions.ts +2 -2
  106. package/src/checkDeps.ts +3 -2
  107. package/src/compiler.ts +425 -0
  108. package/src/compilerHost.ts +3125 -0
  109. package/src/constants.ts +0 -5
  110. package/src/domStructuralPass.ts +170 -0
  111. package/src/exports.ts +3 -6
  112. package/src/extractor/addLocalExports.ts +49 -0
  113. package/src/extractor/bundle.ts +20 -35
  114. package/src/extractor/bundleConfig.ts +334 -187
  115. package/src/extractor/concatClassName.ts +13 -20
  116. package/src/extractor/getTamaguiConfigPathFromOptionsConfig.ts +5 -4
  117. package/src/extractor/loadTamagui.ts +196 -143
  118. package/src/extractor/regenerateConfig.ts +65 -13
  119. package/src/extractor/watchTamaguiConfig.ts +6 -1
  120. package/src/helpers/requireTamaguiCore.ts +6 -1
  121. package/src/registerRequire.ts +94 -132
  122. package/src/staticEvaluationIgnoredModules.ts +74 -0
  123. package/src/types.ts +2 -107
  124. package/src/zero/artifact.ts +142 -0
  125. package/src/zero/graph.ts +359 -0
  126. package/src/zero/identity.ts +73 -0
  127. package/src/zero/index.ts +8 -0
  128. package/src/zero/islands.ts +262 -0
  129. package/src/zero/options.ts +239 -0
  130. package/src/zero/ownership.ts +113 -0
  131. package/src/zero/theme.ts +478 -0
  132. package/src/zero/transform.ts +320 -0
  133. package/types/check-dep-versions.d.ts.map +1 -1
  134. package/types/checkDeps.d.ts.map +1 -1
  135. package/types/compiler.d.ts +117 -0
  136. package/types/compiler.d.ts.map +1 -0
  137. package/types/compilerHost.d.ts +25 -0
  138. package/types/compilerHost.d.ts.map +1 -0
  139. package/types/constants.d.ts +0 -1
  140. package/types/constants.d.ts.map +1 -1
  141. package/types/domStructuralPass.d.ts +3 -0
  142. package/types/domStructuralPass.d.ts.map +1 -0
  143. package/types/exports.d.ts +3 -6
  144. package/types/exports.d.ts.map +1 -1
  145. package/types/extractor/addLocalExports.d.ts +3 -0
  146. package/types/extractor/addLocalExports.d.ts.map +1 -0
  147. package/types/extractor/bundle.d.ts +66 -65
  148. package/types/extractor/bundle.d.ts.map +1 -1
  149. package/types/extractor/bundleConfig.d.ts +19 -4
  150. package/types/extractor/bundleConfig.d.ts.map +1 -1
  151. package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -1
  152. package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts +1 -1
  153. package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts.map +1 -1
  154. package/types/extractor/loadTamagui.d.ts +26 -3
  155. package/types/extractor/loadTamagui.d.ts.map +1 -1
  156. package/types/extractor/regenerateConfig.d.ts +1 -1
  157. package/types/extractor/regenerateConfig.d.ts.map +1 -1
  158. package/types/extractor/watchTamaguiConfig.d.ts.map +1 -1
  159. package/types/getPragmaOptions.d.ts +1 -1
  160. package/types/helpers/memoize.d.ts +1 -1
  161. package/types/helpers/memoize.d.ts.map +1 -1
  162. package/types/helpers/requireTamaguiCore.d.ts.map +1 -1
  163. package/types/index.d.ts.map +1 -1
  164. package/types/registerRequire.d.ts +2 -2
  165. package/types/registerRequire.d.ts.map +1 -1
  166. package/types/staticEvaluationIgnoredModules.d.ts +9 -0
  167. package/types/staticEvaluationIgnoredModules.d.ts.map +1 -0
  168. package/types/types.d.ts +2 -90
  169. package/types/types.d.ts.map +1 -1
  170. package/types/zero/artifact.d.ts +44 -0
  171. package/types/zero/artifact.d.ts.map +1 -0
  172. package/types/zero/graph.d.ts +139 -0
  173. package/types/zero/graph.d.ts.map +1 -0
  174. package/types/zero/identity.d.ts +33 -0
  175. package/types/zero/identity.d.ts.map +1 -0
  176. package/types/zero/index.d.ts +9 -0
  177. package/types/zero/index.d.ts.map +1 -0
  178. package/types/zero/islands.d.ts +56 -0
  179. package/types/zero/islands.d.ts.map +1 -0
  180. package/types/zero/options.d.ts +58 -0
  181. package/types/zero/options.d.ts.map +1 -0
  182. package/types/zero/ownership.d.ts +51 -0
  183. package/types/zero/ownership.d.ts.map +1 -0
  184. package/types/zero/theme.d.ts +83 -0
  185. package/types/zero/theme.d.ts.map +1 -0
  186. package/types/zero/transform.d.ts +53 -0
  187. package/types/zero/transform.d.ts.map +1 -0
  188. package/dist/check-dep-versions.cjs +0 -372
  189. package/dist/checkDeps.cjs +0 -271
  190. package/dist/constants.cjs +0 -51
  191. package/dist/exports.cjs +0 -48
  192. package/dist/extractor/accessSafe.cjs +0 -48
  193. package/dist/extractor/babelParse.cjs +0 -56
  194. package/dist/extractor/buildClassName.cjs +0 -86
  195. package/dist/extractor/bundle.cjs +0 -234
  196. package/dist/extractor/bundleConfig.cjs +0 -729
  197. package/dist/extractor/concatClassName.cjs +0 -129
  198. package/dist/extractor/createEvaluator.cjs +0 -88
  199. package/dist/extractor/createExtractor.cjs +0 -1968
  200. package/dist/extractor/createLogger.cjs +0 -50
  201. package/dist/extractor/detectModuleFormat.cjs +0 -55
  202. package/dist/extractor/ensureImportingConcat.cjs +0 -54
  203. package/dist/extractor/errors.cjs +0 -28
  204. package/dist/extractor/esbuildAliasPlugin.cjs +0 -56
  205. package/dist/extractor/esbuildTsconfigPaths.cjs +0 -108
  206. package/dist/extractor/evaluateAstNode.cjs +0 -128
  207. package/dist/extractor/extractHelpers.cjs +0 -182
  208. package/dist/extractor/extractMediaStyle.cjs +0 -169
  209. package/dist/extractor/extractToClassNames.cjs +0 -475
  210. package/dist/extractor/extractToNative.cjs +0 -369
  211. package/dist/extractor/findTopmostFunction.cjs +0 -43
  212. package/dist/extractor/generatedUid.cjs +0 -58
  213. package/dist/extractor/getPrefixLogs.cjs +0 -31
  214. package/dist/extractor/getPropValueFromAttributes.cjs +0 -85
  215. package/dist/extractor/getSourceModule.cjs +0 -100
  216. package/dist/extractor/getStaticBindingsForScope.cjs +0 -213
  217. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +0 -41
  218. package/dist/extractor/hasTopLevelAwait.cjs +0 -62
  219. package/dist/extractor/hoistClassNames.cjs +0 -76
  220. package/dist/extractor/literalToAst.cjs +0 -109
  221. package/dist/extractor/loadFile.cjs +0 -17
  222. package/dist/extractor/loadTamagui.cjs +0 -373
  223. package/dist/extractor/logLines.cjs +0 -43
  224. package/dist/extractor/normalizeTernaries.cjs +0 -100
  225. package/dist/extractor/propsToFontFamilyCache.cjs +0 -42
  226. package/dist/extractor/regenerateConfig.cjs +0 -178
  227. package/dist/extractor/removeUnusedHooks.cjs +0 -108
  228. package/dist/extractor/timer.cjs +0 -52
  229. package/dist/extractor/validHTMLAttributes.cjs +0 -79
  230. package/dist/extractor/watchTamaguiConfig.cjs +0 -70
  231. package/dist/getPragmaOptions.cjs +0 -73
  232. package/dist/helpers/memoize.cjs +0 -45
  233. package/dist/helpers/requireTamaguiCore.cjs +0 -40
  234. package/dist/index.cjs +0 -42
  235. package/dist/registerRequire.cjs +0 -209
  236. package/dist/server.cjs +0 -82
  237. package/dist/types.cjs +0 -18
  238. package/dist/worker.cjs +0 -111
  239. package/src/extractor/accessSafe.ts +0 -22
  240. package/src/extractor/babelParse.ts +0 -38
  241. package/src/extractor/buildClassName.ts +0 -76
  242. package/src/extractor/createEvaluator.ts +0 -82
  243. package/src/extractor/createExtractor.ts +0 -2970
  244. package/src/extractor/createLogger.ts +0 -41
  245. package/src/extractor/ensureImportingConcat.ts +0 -36
  246. package/src/extractor/errors.ts +0 -1
  247. package/src/extractor/evaluateAstNode.ts +0 -136
  248. package/src/extractor/extractHelpers.ts +0 -211
  249. package/src/extractor/extractMediaStyle.ts +0 -194
  250. package/src/extractor/extractToClassNames.ts +0 -733
  251. package/src/extractor/extractToNative.ts +0 -506
  252. package/src/extractor/findTopmostFunction.ts +0 -24
  253. package/src/extractor/generatedUid.ts +0 -41
  254. package/src/extractor/getPrefixLogs.ts +0 -9
  255. package/src/extractor/getPropValueFromAttributes.ts +0 -95
  256. package/src/extractor/getSourceModule.ts +0 -96
  257. package/src/extractor/getStaticBindingsForScope.ts +0 -237
  258. package/src/extractor/hasTopLevelAwait.ts +0 -28
  259. package/src/extractor/hoistClassNames.ts +0 -52
  260. package/src/extractor/literalToAst.ts +0 -85
  261. package/src/extractor/loadFile.ts +0 -17
  262. package/src/extractor/logLines.ts +0 -16
  263. package/src/extractor/normalizeTernaries.ts +0 -89
  264. package/src/extractor/propsToFontFamilyCache.ts +0 -18
  265. package/src/extractor/removeUnusedHooks.ts +0 -83
  266. package/src/extractor/timer.ts +0 -25
  267. package/src/extractor/validHTMLAttributes.ts +0 -52
  268. package/src/worker.ts +0 -142
  269. package/types/extractor/accessSafe.d.ts +0 -3
  270. package/types/extractor/accessSafe.d.ts.map +0 -1
  271. package/types/extractor/babelParse.d.ts +0 -5
  272. package/types/extractor/babelParse.d.ts.map +0 -1
  273. package/types/extractor/buildClassName.d.ts +0 -7
  274. package/types/extractor/buildClassName.d.ts.map +0 -1
  275. package/types/extractor/createEvaluator.d.ts +0 -12
  276. package/types/extractor/createEvaluator.d.ts.map +0 -1
  277. package/types/extractor/createExtractor.d.ts +0 -32
  278. package/types/extractor/createExtractor.d.ts.map +0 -1
  279. package/types/extractor/createLogger.d.ts +0 -3
  280. package/types/extractor/createLogger.d.ts.map +0 -1
  281. package/types/extractor/ensureImportingConcat.d.ts +0 -4
  282. package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
  283. package/types/extractor/errors.d.ts +0 -3
  284. package/types/extractor/errors.d.ts.map +0 -1
  285. package/types/extractor/evaluateAstNode.d.ts +0 -3
  286. package/types/extractor/evaluateAstNode.d.ts.map +0 -1
  287. package/types/extractor/extractHelpers.d.ts +0 -28
  288. package/types/extractor/extractHelpers.d.ts.map +0 -1
  289. package/types/extractor/extractMediaStyle.d.ts +0 -11
  290. package/types/extractor/extractMediaStyle.d.ts.map +0 -1
  291. package/types/extractor/extractToClassNames.d.ts +0 -25
  292. package/types/extractor/extractToClassNames.d.ts.map +0 -1
  293. package/types/extractor/extractToNative.d.ts +0 -13
  294. package/types/extractor/extractToNative.d.ts.map +0 -1
  295. package/types/extractor/findTopmostFunction.d.ts +0 -4
  296. package/types/extractor/findTopmostFunction.d.ts.map +0 -1
  297. package/types/extractor/generatedUid.d.ts +0 -5
  298. package/types/extractor/generatedUid.d.ts.map +0 -1
  299. package/types/extractor/getPrefixLogs.d.ts +0 -3
  300. package/types/extractor/getPrefixLogs.d.ts.map +0 -1
  301. package/types/extractor/getPropValueFromAttributes.d.ts +0 -19
  302. package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -1
  303. package/types/extractor/getSourceModule.d.ts +0 -16
  304. package/types/extractor/getSourceModule.d.ts.map +0 -1
  305. package/types/extractor/getStaticBindingsForScope.d.ts +0 -5
  306. package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -1
  307. package/types/extractor/hasTopLevelAwait.d.ts +0 -2
  308. package/types/extractor/hasTopLevelAwait.d.ts.map +0 -1
  309. package/types/extractor/hoistClassNames.d.ts +0 -6
  310. package/types/extractor/hoistClassNames.d.ts.map +0 -1
  311. package/types/extractor/literalToAst.d.ts +0 -4
  312. package/types/extractor/literalToAst.d.ts.map +0 -1
  313. package/types/extractor/loadFile.d.ts +0 -1
  314. package/types/extractor/loadFile.d.ts.map +0 -1
  315. package/types/extractor/logLines.d.ts +0 -2
  316. package/types/extractor/logLines.d.ts.map +0 -1
  317. package/types/extractor/normalizeTernaries.d.ts +0 -5
  318. package/types/extractor/normalizeTernaries.d.ts.map +0 -1
  319. package/types/extractor/propsToFontFamilyCache.d.ts +0 -4
  320. package/types/extractor/propsToFontFamilyCache.d.ts.map +0 -1
  321. package/types/extractor/removeUnusedHooks.d.ts +0 -3
  322. package/types/extractor/removeUnusedHooks.d.ts.map +0 -1
  323. package/types/extractor/timer.d.ts +0 -5
  324. package/types/extractor/timer.d.ts.map +0 -1
  325. package/types/extractor/validHTMLAttributes.d.ts +0 -52
  326. package/types/extractor/validHTMLAttributes.d.ts.map +0 -1
  327. package/types/worker.d.ts +0 -46
  328. package/types/worker.d.ts.map +0 -1
  329. /package/dist/{setup.cjs → cjs/setup.cjs} +0 -0
@@ -1,41 +0,0 @@
1
- import { basename } from 'node:path'
2
-
3
- import type { TamaguiOptions } from '../types'
4
- import { getPrefixLogs } from './getPrefixLogs'
5
-
6
- export function createLogger(sourcePath: string, options: TamaguiOptions) {
7
- const shouldLogTiming = options.logTimings ?? true
8
- const start = Date.now()
9
- const mem =
10
- process.env.TAMAGUI_SHOW_MEMORY_USAGE && shouldLogTiming
11
- ? process.memoryUsage()
12
- : null
13
-
14
- return (res) => {
15
- if (!shouldLogTiming) {
16
- return
17
- }
18
-
19
- const memUsed = mem
20
- ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) /
21
- 10
22
- : 0
23
- const path = basename(sourcePath || '')
24
- .replace(/\.[jt]sx?$/, '')
25
- .slice(0, 22)
26
- .trim()
27
- .padEnd(24)
28
-
29
- const numOptimized = `${res.optimized + res.styled}`.padStart(3)
30
- const numFound = `${res.found + res.styled}`.padStart(3)
31
- const numFlattened = `${res.flattened}`.padStart(3)
32
- const memory = memUsed ? ` ${memUsed}MB` : ''
33
- const timing = Date.now() - start
34
- const timingStr = `${timing}ms`.padStart(6)
35
- const pre = getPrefixLogs(options)
36
- const memStr = memory ? `(${memory})` : ''
37
- console.info(
38
- `${pre} ${path} · ${numFound} found · ${numOptimized} opt · ${numFlattened} flat ${timingStr} ${memStr}`
39
- )
40
- }
41
- }
@@ -1,36 +0,0 @@
1
- import type { NodePath } from '@babel/traverse'
2
- import * as t from '@babel/types'
3
-
4
- const importConcatPkg = '@tamagui/helpers'
5
-
6
- export function ensureImportingConcat(path: NodePath<t.Program>) {
7
- const bodyPath = path.get('body')
8
- const imported: NodePath<t.ImportDeclaration> | undefined = bodyPath.find(
9
- (x) => x.isImportDeclaration() && x.node.source.value === importConcatPkg
10
- ) as any
11
- const importSpecifier = t.importSpecifier(
12
- t.identifier('concatClassName'),
13
- t.identifier('concatClassName')
14
- )
15
-
16
- if (!imported) {
17
- path.node.body.push(
18
- t.importDeclaration([importSpecifier], t.stringLiteral(importConcatPkg))
19
- )
20
- return
21
- }
22
-
23
- const specifiers = imported.node.specifiers
24
- const alreadyImported = specifiers.some(
25
- (x) =>
26
- t.isImportSpecifier(x) &&
27
- t.isIdentifier(x.imported) &&
28
- x.imported.name === 'concatClassName'
29
- )
30
-
31
- if (!alreadyImported) {
32
- specifiers.push(
33
- t.importSpecifier(t.identifier('concatClassName'), t.identifier('concatClassName'))
34
- )
35
- }
36
- }
@@ -1 +0,0 @@
1
- export class BailOptimizationError extends Error {}
@@ -1,136 +0,0 @@
1
- import * as t from '@babel/types'
2
-
3
- export function evaluateAstNode(
4
- exprNode: t.Node | undefined | null,
5
- evalFn?: (node: t.Node) => any,
6
- shouldPrintDebug?: boolean | 'verbose'
7
- ): any {
8
- if (exprNode === undefined) {
9
- return undefined
10
- }
11
-
12
- // null === boolean true (at least in our use cases for jsx eval)
13
- if (exprNode === null) {
14
- return true
15
- }
16
-
17
- if (t.isJSXExpressionContainer(exprNode)) {
18
- return evaluateAstNode(exprNode.expression)
19
- }
20
-
21
- // loop through ObjectExpression keys
22
- if (t.isObjectExpression(exprNode)) {
23
- const ret: Record<string, any> = {}
24
- for (let idx = -1, len = exprNode.properties.length; ++idx < len; ) {
25
- const value = exprNode.properties[idx]
26
-
27
- if (!t.isObjectProperty(value)) {
28
- throw new Error('evaluateAstNode can only evaluate object properties')
29
- }
30
-
31
- let key: string | number | null | undefined | boolean
32
- if (value.computed) {
33
- if (typeof evalFn !== 'function') {
34
- throw new Error(
35
- 'evaluateAstNode does not support computed keys unless an eval function is provided'
36
- )
37
- }
38
- key = evaluateAstNode(value.key, evalFn)
39
- } else if (t.isIdentifier(value.key)) {
40
- key = value.key.name
41
- } else if (t.isStringLiteral(value.key) || t.isNumericLiteral(value.key)) {
42
- key = value.key.value
43
- } else {
44
- throw new Error('Unsupported key type: ' + value.key.type)
45
- }
46
-
47
- if (typeof key !== 'string' && typeof key !== 'number') {
48
- throw new Error('key must be either a string or a number')
49
- }
50
-
51
- ret[key] = evaluateAstNode(value.value, evalFn)
52
- }
53
- return ret
54
- }
55
-
56
- if (t.isArrayExpression(exprNode)) {
57
- return exprNode.elements.map((x) => {
58
- return evaluateAstNode(x as any, evalFn)
59
- })
60
- }
61
-
62
- if (t.isUnaryExpression(exprNode) && exprNode.operator === '-') {
63
- const ret = evaluateAstNode(exprNode.argument, evalFn)
64
- if (ret == null) {
65
- return null
66
- }
67
- return -ret
68
- }
69
-
70
- if (t.isTemplateLiteral(exprNode)) {
71
- if (typeof evalFn !== 'function') {
72
- throw new Error(
73
- 'evaluateAstNode does not support template literals unless an eval function is provided'
74
- )
75
- }
76
-
77
- let ret = ''
78
- for (let idx = -1, len = exprNode.quasis.length; ++idx < len; ) {
79
- const quasi = exprNode.quasis[idx]
80
- const expr = exprNode.expressions[idx]
81
- ret += quasi.value.raw
82
- if (expr) {
83
- ret += evaluateAstNode(expr, evalFn)
84
- }
85
- }
86
- return ret
87
- }
88
-
89
- // In the interest of representing the "evaluated" prop
90
- // as the user intended, we support negative null. Why not.
91
- if (t.isNullLiteral(exprNode)) {
92
- return null
93
- }
94
-
95
- if (
96
- t.isNumericLiteral(exprNode) ||
97
- t.isStringLiteral(exprNode) ||
98
- t.isBooleanLiteral(exprNode)
99
- ) {
100
- // In the interest of representing the "evaluated" prop
101
- // as the user intended, we support negative null. Why not.
102
- return exprNode.value
103
- }
104
-
105
- if (t.isBinaryExpression(exprNode)) {
106
- if (exprNode.operator === '+') {
107
- return (
108
- evaluateAstNode(exprNode.left, evalFn) + evaluateAstNode(exprNode.right, evalFn)
109
- )
110
- }
111
- if (exprNode.operator === '-') {
112
- return (
113
- evaluateAstNode(exprNode.left, evalFn) - evaluateAstNode(exprNode.right, evalFn)
114
- )
115
- }
116
- if (exprNode.operator === '*') {
117
- return (
118
- evaluateAstNode(exprNode.left, evalFn) * evaluateAstNode(exprNode.right, evalFn)
119
- )
120
- }
121
- if (exprNode.operator === '/') {
122
- return (
123
- evaluateAstNode(exprNode.left, evalFn) / evaluateAstNode(exprNode.right, evalFn)
124
- )
125
- }
126
- }
127
-
128
- // if we've made it this far, the value has to be evaluated
129
- if (typeof evalFn !== 'function') {
130
- throw new Error(
131
- 'evaluateAstNode does not support non-literal values unless an eval function is provided'
132
- )
133
- }
134
-
135
- return evalFn(exprNode)
136
- }
@@ -1,211 +0,0 @@
1
- import { basename } from 'node:path'
2
-
3
- import generate from '@babel/generator'
4
- import type { NodePath } from '@babel/traverse'
5
- import * as t from '@babel/types'
6
- import findRoot from 'find-root'
7
-
8
- import { memoize } from '../helpers/memoize'
9
- import type { ExtractedAttr, TamaguiOptionsWithFileInfo, Ternary } from '../types'
10
-
11
- // import { astToLiteral } from './literalToAst'
12
-
13
- export function isPresent<T extends object>(
14
- input: null | void | undefined | T
15
- ): input is T {
16
- return input != null
17
- }
18
-
19
- export function isSimpleSpread(node: t.JSXSpreadAttribute) {
20
- return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument)
21
- }
22
-
23
- export const attrStr = (attr?: ExtractedAttr) => {
24
- return !attr
25
- ? ''
26
- : attr.type === 'attr'
27
- ? getNameAttr(attr.value)
28
- : attr.type === 'ternary'
29
- ? `...${ternaryStr(attr.value)}`
30
- : `${attr.type}(${objToStr(attr.value)})`
31
- }
32
-
33
- export const objToStr = (obj: any, spacer = ', ') => {
34
- if (!obj) {
35
- return `${obj}`
36
- }
37
- return `{${Object.entries(obj)
38
- .map(
39
- ([k, v]) =>
40
- `${k}:${
41
- Array.isArray(v)
42
- ? `[...]`
43
- : v && typeof v === 'object'
44
- ? `${objToStr(v, ',')}`
45
- : JSON.stringify(v)
46
- }`
47
- )
48
- .join(spacer)}}`
49
- }
50
-
51
- const getNameAttr = (attr: t.JSXAttribute | t.JSXSpreadAttribute) => {
52
- if (t.isJSXSpreadAttribute(attr)) {
53
- return `...${attr.argument['name']}`
54
- }
55
- return 'name' in attr ? attr.name.name : `unknown-${attr['type']}`
56
- }
57
-
58
- export const ternaryStr = (x: Ternary) => {
59
- const conditional = t.isIdentifier(x.test)
60
- ? x.test.name
61
- : t.isMemberExpression(x.test)
62
- ? [x.test.object['name'], x.test.property['name']]
63
- : // @ts-ignore
64
- generate(x.test as any).code
65
- return [
66
- 'ternary(',
67
- conditional,
68
- isFilledObj(x.consequent) ? ` ? ${objToStr(x.consequent)}` : ' ? 🚫',
69
- isFilledObj(x.alternate) ? ` : ${objToStr(x.alternate)}` : ' : 🚫',
70
- ')',
71
- ]
72
- .flat()
73
- .join('')
74
- }
75
-
76
- const isFilledObj = (obj: any) => obj && Object.keys(obj).length
77
-
78
- export function findComponentName(scope) {
79
- const componentName = ''
80
- let cur = scope.path
81
- while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
82
- cur = cur.parentPath
83
- }
84
- let node = cur.parent
85
- if (t.isExportNamedDeclaration(node)) {
86
- node = node.declaration
87
- }
88
- if (t.isVariableDeclaration(node)) {
89
- const [dec] = node.declarations
90
- if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {
91
- return dec.id.name
92
- }
93
- }
94
- if (t.isFunctionDeclaration(node)) {
95
- return node.id?.name
96
- }
97
- return componentName
98
- }
99
-
100
- export function isValidThemeHook(
101
- props: TamaguiOptionsWithFileInfo,
102
- jsxPath: NodePath<t.JSXElement>,
103
- n: t.MemberExpression,
104
- sourcePath?: string
105
- ) {
106
- if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return false
107
- const bindings = jsxPath.scope.getAllBindings()
108
- const binding = bindings[n.object.name]
109
- if (!binding?.path) return false
110
- if (!binding.path.isVariableDeclarator()) return false
111
- const init = binding.path.node.init
112
- if (!init || !t.isCallExpression(init)) return false
113
- if (!t.isIdentifier(init.callee)) return false
114
- // TODO could support renaming useTheme by looking up import first
115
- if (init.callee.name !== 'useTheme') return false
116
- const importNode = binding.scope.getBinding('useTheme')?.path.parent
117
- if (!t.isImportDeclaration(importNode)) return false
118
- if (sourcePath && !isValidImport(props, sourcePath)) {
119
- return false
120
- }
121
- return true
122
- }
123
-
124
- export const isInsideComponentPackage = (
125
- props: TamaguiOptionsWithFileInfo,
126
- moduleName: string
127
- ) => {
128
- return getValidComponentsPaths(props).some((path) => {
129
- return moduleName.startsWith(path)
130
- })
131
- }
132
-
133
- export const isComponentPackage = (
134
- props: TamaguiOptionsWithFileInfo,
135
- srcName: string
136
- ) => {
137
- return getValidComponentsPaths(props).some((path) => {
138
- return srcName.startsWith(path)
139
- })
140
- }
141
-
142
- export function getValidComponent(
143
- props: TamaguiOptionsWithFileInfo,
144
- moduleName: string,
145
- componentName: string
146
- ) {
147
- // must be uppercase of course
148
- if (componentName[0].toUpperCase() !== componentName[0]) {
149
- return false
150
- }
151
-
152
- for (const loaded of props.allLoadedComponents) {
153
- if (!loaded) continue
154
- const isInModule = moduleName === '*' || moduleName.startsWith(loaded.moduleName)
155
- const foundComponent = loaded.nameToInfo[componentName]
156
- if (isInModule && foundComponent) {
157
- return foundComponent
158
- }
159
- }
160
-
161
- return null
162
- }
163
-
164
- export const isValidModule = (props: TamaguiOptionsWithFileInfo, moduleName: string) => {
165
- if (typeof moduleName !== 'string') {
166
- throw new Error(`No module name`)
167
- }
168
- const isLocal = moduleName.startsWith('.')
169
- return {
170
- isLocal,
171
- isValid: isLocal
172
- ? isInsideComponentPackage(props, moduleName)
173
- : isComponentPackage(props, moduleName),
174
- }
175
- }
176
-
177
- export const getValidImport = (
178
- props: TamaguiOptionsWithFileInfo,
179
- moduleName: string,
180
- componentName?: string
181
- ) => {
182
- const { isValid, isLocal } = isValidModule(props, moduleName)
183
- if (!isValid || !componentName) {
184
- return null
185
- }
186
- return getValidComponent(props, isLocal ? '*' : moduleName, componentName) || null
187
- }
188
-
189
- export const isValidImport = (
190
- props: TamaguiOptionsWithFileInfo,
191
- moduleName: string,
192
- componentName?: string
193
- ) => {
194
- if (!componentName) {
195
- return isValidModule(props, moduleName).isValid
196
- }
197
- return Boolean(getValidImport(props, moduleName, componentName))
198
- }
199
-
200
- const getValidComponentPackages = memoize((props: TamaguiOptionsWithFileInfo) => {
201
- // just always look for `tamagui` and `@tamagui/core`
202
- return [...new Set(['@tamagui/core', 'tamagui', ...(props.components || [])])]
203
- })
204
-
205
- export const getValidComponentsPaths = memoize((props: TamaguiOptionsWithFileInfo) => {
206
- return getValidComponentPackages(props).flatMap((pkg) => {
207
- const root = findRoot(pkg)
208
- const based = basename(root)
209
- return [based, pkg].filter(Boolean)
210
- })
211
- })
@@ -1,194 +0,0 @@
1
- import type { NodePath } from '@babel/traverse'
2
- import * as t from '@babel/types'
3
- import type { TamaguiInternalConfig } from '@tamagui/core'
4
- import * as core from '@tamagui/core'
5
- import type { ViewStyle } from 'react-native'
6
-
7
- import { requireTamaguiCore } from '../helpers/requireTamaguiCore'
8
- import type { StyleObject, TamaguiOptionsWithFileInfo, Ternary } from '../types'
9
- import { isPresent, isValidImport } from './extractHelpers'
10
-
11
- export function extractMediaStyle(
12
- props: TamaguiOptionsWithFileInfo,
13
- ternary: Ternary,
14
- jsxPath: NodePath<t.JSXElement>,
15
- tamaguiConfig: TamaguiInternalConfig,
16
- sourcePath: string,
17
- importance = 0,
18
- shouldPrintDebug: boolean | 'verbose' = false
19
- ) {
20
- const { getCSSStylesAtomic } = requireTamaguiCore('web')
21
- const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)
22
- if (!mt) {
23
- return null
24
- }
25
- const { key } = mt
26
- const mq = tamaguiConfig.media[key]
27
- if (!mq) {
28
- console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`)
29
- return null
30
- }
31
- const getStyleObj = (styleObj: ViewStyle | null, negate = false) => {
32
- return styleObj ? { styleObj, negate } : null
33
- }
34
- const styleOpts = [
35
- getStyleObj(ternary.consequent, false),
36
- getStyleObj(ternary.alternate, true),
37
- ].filter(isPresent)
38
- if (shouldPrintDebug && !styleOpts.length) {
39
- console.info(' media query, no styles?')
40
- return null
41
- }
42
- // for now order first strongest
43
- const mediaKeys = Object.keys(tamaguiConfig.media)
44
- const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
45
- acc[cur] = new Array(importance + 1).fill(':root').join('')
46
- return acc
47
- }, {})
48
- let mediaStyles: StyleObject[] = []
49
-
50
- // TODO this should NOT be here
51
- // this should be done using the same logic as createMediaStyle
52
-
53
- for (const { styleObj, negate } of styleOpts) {
54
- const styles = getCSSStylesAtomic(styleObj as any)
55
-
56
- const singleMediaStyles = styles.map((style) => {
57
- const mediaStyle = core.createMediaStyle(
58
- style,
59
- key,
60
- tamaguiConfig.media,
61
- true,
62
- negate
63
- )
64
- const className = `.${mediaStyle[core.StyleObjectIdentifier]}`
65
- return {
66
- ...mediaStyle,
67
- className,
68
- }
69
- })
70
-
71
- if (shouldPrintDebug === 'verbose') {
72
- console.info(
73
- ' media styles:',
74
- importance,
75
- styleObj,
76
- singleMediaStyles.map((x) => x[core.StyleObjectIdentifier]).join(', ')
77
- )
78
- }
79
- // add to output
80
- mediaStyles = [...mediaStyles, ...singleMediaStyles]
81
- }
82
- // filter out
83
- ternary.remove()
84
- return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia }
85
- }
86
-
87
- function getMediaQueryTernary(
88
- props: TamaguiOptionsWithFileInfo,
89
- ternary: Ternary,
90
- jsxPath: NodePath<t.JSXElement>,
91
- sourcePath: string
92
- ): null | {
93
- key: string
94
- bindingName: string
95
- ternaryWithoutMedia: Ternary | null
96
- } {
97
- // this handles unwrapping logical && media query ternarys
98
- // first, unwrap if it has media logicalExpression
99
- if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {
100
- // *should* be normalized to always be on left side
101
- const mediaLeft = getMediaInfoFromExpression(
102
- props,
103
- ternary.test.left,
104
- jsxPath,
105
- sourcePath,
106
- ternary.inlineMediaQuery
107
- )
108
- if (mediaLeft) {
109
- return {
110
- ...mediaLeft,
111
- ternaryWithoutMedia: {
112
- ...ternary,
113
- test: ternary.test.right,
114
- },
115
- }
116
- }
117
- }
118
- // const media = useMedia()
119
- // ... media.sm
120
- const result = getMediaInfoFromExpression(
121
- props,
122
- ternary.test,
123
- jsxPath,
124
- sourcePath,
125
- ternary.inlineMediaQuery
126
- )
127
- if (result) {
128
- return {
129
- ...result,
130
- ternaryWithoutMedia: null,
131
- }
132
- }
133
- return null
134
- }
135
-
136
- function getMediaInfoFromExpression(
137
- props: TamaguiOptionsWithFileInfo,
138
- test: t.Expression,
139
- jsxPath: NodePath<t.JSXElement>,
140
- sourcePath: string,
141
- inlineMediaQuery?: string
142
- ) {
143
- if (inlineMediaQuery) {
144
- return {
145
- key: inlineMediaQuery,
146
- bindingName: inlineMediaQuery,
147
- }
148
- }
149
- if (
150
- t.isMemberExpression(test) &&
151
- t.isIdentifier(test.object) &&
152
- t.isIdentifier(test.property)
153
- ) {
154
- const name = test.object['name']
155
- const key = test.property['name']
156
- const bindings = jsxPath.scope.getAllBindings()
157
- const binding = bindings[name]
158
- if (!binding) return false
159
- const bindingNode = binding.path?.node
160
- if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false
161
- if (!isValidMediaCall(props, jsxPath, bindingNode.init, sourcePath)) return false
162
- return { key, bindingName: name }
163
- }
164
- if (t.isIdentifier(test)) {
165
- const key = test.name
166
- const node = jsxPath.scope.getBinding(test.name)?.path?.node
167
- if (!t.isVariableDeclarator(node)) return false
168
- if (!node.init || !isValidMediaCall(props, jsxPath, node.init, sourcePath))
169
- return false
170
- return { key, bindingName: key }
171
- }
172
- return null
173
- }
174
-
175
- export function isValidMediaCall(
176
- props: TamaguiOptionsWithFileInfo,
177
- jsxPath: NodePath<t.JSXElement>,
178
- init: t.Expression,
179
- sourcePath: string
180
- ) {
181
- if (!init || !t.isCallExpression(init)) return false
182
- if (!t.isIdentifier(init.callee)) return false
183
- // TODO could support renaming useMedia by looking up import first
184
- if (init.callee.name !== 'useMedia') return false
185
- const bindings = jsxPath.scope.getAllBindings()
186
- const mediaBinding = bindings['useMedia']
187
- if (!mediaBinding) return false
188
- const useMediaImport = mediaBinding.path.parent
189
- if (!t.isImportDeclaration(useMediaImport)) return false
190
- if (!isValidImport(props, sourcePath)) {
191
- return false
192
- }
193
- return true
194
- }