@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,506 +0,0 @@
1
- import { type BabelFileResult, transformFromAstSync } from '@babel/core'
2
- import generator from '@babel/generator'
3
- import { declare } from '@babel/helper-plugin-utils'
4
- import { parse } from '@babel/parser'
5
- import template from '@babel/template'
6
- import * as t from '@babel/types'
7
- import { basename } from 'node:path'
8
- import { getPragmaOptions } from '../getPragmaOptions'
9
- import type { TamaguiOptions } from '../types'
10
- import { createExtractor } from './createExtractor'
11
- import { createLogger } from './createLogger'
12
- import { isSimpleSpread } from './extractHelpers'
13
- import { literalToAst } from './literalToAst'
14
- import { loadTamaguiBuildConfigSync } from './loadTamagui'
15
-
16
- const importNativeView = template(`
17
- const __ReactNativeView = require('react-native').View;
18
- const __ReactNativeText = require('react-native').Text;
19
- `)
20
-
21
- const importStyleSheet = template(`
22
- const __ReactNativeStyleSheet = require('react-native').StyleSheet;
23
- `)
24
-
25
- const importWithStyle = template.ast(`import { _withStableStyle } from '@tamagui/core';`)
26
-
27
- const extractor = createExtractor({ platform: 'native' })
28
-
29
- let tamaguiBuildOptionsLoaded: TamaguiOptions | null
30
-
31
- export function extractToNative(
32
- sourceFileName: string,
33
- sourceCode: string,
34
- options: TamaguiOptions
35
- ): BabelFileResult {
36
- const ast = parse(sourceCode, {
37
- sourceType: 'module',
38
- plugins: ['jsx', 'typescript'],
39
- })
40
-
41
- const babelPlugin = getBabelPlugin()
42
-
43
- const out = transformFromAstSync(ast, sourceCode, {
44
- plugins: [[babelPlugin, options]],
45
- configFile: false,
46
- sourceFileName,
47
- filename: sourceFileName,
48
- })
49
-
50
- if (!out) {
51
- throw new Error(`No output returned`)
52
- }
53
-
54
- return out
55
- }
56
-
57
- export function getBabelPlugin() {
58
- return declare((api, options: TamaguiOptions) => {
59
- api.assertVersion(7)
60
- return getBabelParseDefinition(options)
61
- })
62
- }
63
-
64
- export function getBabelParseDefinition(options: TamaguiOptions) {
65
- return {
66
- name: 'tamagui',
67
-
68
- visitor: {
69
- Program: {
70
- enter(this: any, root) {
71
- let sourcePath = this.file.opts.filename
72
- if (sourcePath?.includes('node_modules')) {
73
- return
74
- }
75
- // by default only pick up .jsx / .tsx
76
- if (!sourcePath?.endsWith('.jsx') && !sourcePath?.endsWith('.tsx')) {
77
- return
78
- }
79
-
80
- // this filename comes back incorrect in react-native, it adds /ios/ for some reason
81
- // adding a fix here, but it's a bit tentative...
82
- if (process.env.SOURCE_ROOT?.endsWith('ios')) {
83
- sourcePath = sourcePath.replace('/ios', '')
84
- }
85
-
86
- let hasImportedView = false
87
- let hasImportedViewWrapper = false
88
- let wrapperCount = 0
89
- const sheetStyles = {}
90
- const sheetIdentifier = root.scope.generateUidIdentifier('sheet')
91
-
92
- // babel doesnt append the `//` so we need to
93
- const firstCommentContents = // join because you can join together multiple pragmas
94
- root.node.body[0]?.leadingComments
95
- ?.map((comment) => comment?.value || ' ')
96
- .join(' ') ?? ''
97
- const firstComment = firstCommentContents ? `//${firstCommentContents}` : ''
98
-
99
- const { shouldPrintDebug, shouldDisable } = getPragmaOptions({
100
- source: firstComment,
101
- path: sourcePath,
102
- })
103
-
104
- if (shouldDisable) {
105
- return
106
- }
107
-
108
- if (!options.config && !options.components) {
109
- // if no config/components given try and load from the tamagui.build.ts file
110
- tamaguiBuildOptionsLoaded ||= loadTamaguiBuildConfigSync({})
111
- }
112
-
113
- const finalOptions = {
114
- // @ts-ignore just in case they leave it out
115
- platform: 'native',
116
- ...tamaguiBuildOptionsLoaded,
117
- ...options,
118
- } satisfies TamaguiOptions
119
-
120
- const printLog = createLogger(sourcePath, finalOptions)
121
-
122
- function addSheetStyle(style: any, node: t.JSXOpeningElement) {
123
- const styleIndex = `${Object.keys(sheetStyles).length}`
124
- let key = `${styleIndex}`
125
- if (process.env.NODE_ENV === 'development') {
126
- const lineNumbers = node.loc
127
- ? node.loc.start.line +
128
- (node.loc.start.line !== node.loc.end.line
129
- ? `-${node.loc.end.line}`
130
- : '')
131
- : ''
132
- key += `:${basename(sourcePath)}:${lineNumbers}`
133
- }
134
- sheetStyles[key] = style
135
- return readStyleExpr(key)
136
- }
137
-
138
- function readStyleExpr(key: string) {
139
- return template(`SHEET['KEY']`)({
140
- SHEET: sheetIdentifier.name,
141
- KEY: key,
142
- })['expression'] as t.MemberExpression
143
- }
144
-
145
- let res
146
-
147
- try {
148
- res = extractor.parseSync(root, {
149
- importsWhitelist: ['constants.js', 'colors.js'],
150
- excludeProps: new Set([
151
- 'className',
152
- 'userSelect',
153
- 'whiteSpace',
154
- 'textOverflow',
155
- 'cursor',
156
- 'contain',
157
- ]),
158
- // native props that should pass through without preventing extraction
159
- inlineProps: new Set([
160
- 'testID',
161
- 'nativeID',
162
- 'accessibilityLabel',
163
- 'accessibilityHint',
164
- 'accessibilityRole',
165
- 'accessibilityState',
166
- 'accessibilityValue',
167
- 'accessibilityActions',
168
- 'accessibilityLabelledBy',
169
- 'accessibilityLiveRegion',
170
- 'accessibilityElementsHidden',
171
- 'accessibilityViewIsModal',
172
- 'importantForAccessibility',
173
- 'onAccessibilityAction',
174
- 'onAccessibilityEscape',
175
- 'onAccessibilityTap',
176
- 'onMagicTap',
177
- 'collapsable',
178
- 'needsOffscreenAlphaCompositing',
179
- 'removeClippedSubviews',
180
- 'renderToHardwareTextureAndroid',
181
- 'shouldRasterizeIOS',
182
- 'hitSlop',
183
- 'pointerEvents',
184
- ]),
185
- shouldPrintDebug,
186
- ...finalOptions,
187
- // disable extracting variables as no native concept of them (only theme values)
188
- disableExtractVariables: false,
189
- sourcePath,
190
-
191
- // disabling flattening for now
192
- // it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
193
- // thinking it's not really worth the effort to do much compilation on native
194
- // for now just disable flatten as it can only run in narrow places on native
195
- // disableFlattening: 'styled',
196
-
197
- getFlattenedNode({ isTextView }) {
198
- if (!hasImportedView) {
199
- hasImportedView = true
200
- root.unshiftContainer('body', importNativeView())
201
- }
202
- return isTextView ? '__ReactNativeText' : '__ReactNativeView'
203
- },
204
-
205
- onExtractTag(props) {
206
- assertValidTag(props.node)
207
- const stylesExpr = t.arrayExpression([])
208
- const hocStylesExpr = t.arrayExpression([])
209
- const expressions: t.Expression[] = []
210
- const mediaExpressionIndexes = new Set<number>()
211
- const finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []
212
- const themeKeysUsed = new Set<string>()
213
-
214
- function getStyleExpression(style: object | null, forTernary = false) {
215
- if (!style) return
216
-
217
- // split theme properties and leave them as props since RN has no concept of theme
218
- const { plain, themed } = splitThemeStyles(style)
219
-
220
- // TODO: themed is not a good name, because it's not just theme it also includes tokens
221
- let themeExpr: t.ObjectExpression | null = null
222
- if (themed) {
223
- for (const key in themed) {
224
- themeKeysUsed.add(themed[key].split('$')[1])
225
- }
226
-
227
- // make a sub-array
228
- themeExpr = getThemedStyleExpression(themed)
229
- }
230
- const hasPlainKeys = Object.keys(plain).length > 0
231
- const ident = hasPlainKeys ? addSheetStyle(plain, props.node) : null
232
- if (themeExpr) {
233
- if (forTernary) {
234
- // for ternary branches, return combined expression
235
- // without adding plain styles unconditionally
236
- if (ident) {
237
- return t.arrayExpression([ident, themeExpr])
238
- }
239
- return themeExpr
240
- }
241
- // for base styles, add unconditionally
242
- if (ident) {
243
- addStyleExpression(ident)
244
- addStyleExpression(ident, true)
245
- }
246
- return themeExpr
247
- }
248
- return ident
249
- }
250
-
251
- function addStyleExpression(expr: any, HOC = false) {
252
- if (Array.isArray(expr)) {
253
- ;(HOC ? hocStylesExpr : stylesExpr).elements.push(...expr)
254
- } else {
255
- ;(HOC ? hocStylesExpr : stylesExpr).elements.push(expr)
256
- }
257
- }
258
-
259
- function getThemedStyleExpression(styles: object) {
260
- const themedStylesAst = literalToAst(styles) as t.ObjectExpression
261
- themedStylesAst.properties.forEach((_) => {
262
- const prop = _ as t.ObjectProperty
263
- if (prop.value.type === 'StringLiteral') {
264
- const propVal = prop.value.value.slice(1)
265
- const isComputed = !t.isValidIdentifier(propVal)
266
- prop.value = t.callExpression(
267
- t.memberExpression(
268
- t.memberExpression(
269
- t.identifier('theme'),
270
- isComputed ? t.stringLiteral(propVal) : t.identifier(propVal),
271
- isComputed
272
- ),
273
- t.identifier('get')
274
- ),
275
- []
276
- )
277
- }
278
- })
279
- return themedStylesAst
280
- }
281
-
282
- let hasDynamicStyle = false
283
- let hasMediaKeys = false
284
-
285
- for (const attr of props.attrs) {
286
- switch (attr.type) {
287
- case 'style': {
288
- let styleExpr = getStyleExpression(attr.value)
289
- addStyleExpression(styleExpr)
290
- addStyleExpression(styleExpr, true)
291
- break
292
- }
293
-
294
- case 'ternary': {
295
- const { consequent, alternate } = attr.value
296
- const consExpr = getStyleExpression(consequent, true)
297
- const altExpr = getStyleExpression(alternate, true)
298
-
299
- if (attr.value.inlineMediaQuery) {
300
- hasMediaKeys = true
301
- }
302
-
303
- let expression = attr.value.test
304
- if (
305
- attr.value.inlineMediaQuery &&
306
- t.isLogicalExpression(attr.value.test, { operator: '&&' }) &&
307
- t.isStringLiteral(attr.value.test.left)
308
- ) {
309
- expression = t.arrayExpression([
310
- t.stringLiteral(attr.value.inlineMediaQuery),
311
- t.unaryExpression(
312
- '!',
313
- t.unaryExpression('!', attr.value.test.right)
314
- ),
315
- ])
316
- mediaExpressionIndexes.add(expressions.length)
317
- }
318
- expressions.push(expression)
319
- addStyleExpression(
320
- t.conditionalExpression(
321
- t.identifier(`_expressions[${expressions.length - 1}]`),
322
- consExpr || t.nullLiteral(),
323
- altExpr || t.nullLiteral()
324
- ),
325
- true
326
- )
327
-
328
- const styleExpr = t.conditionalExpression(
329
- attr.value.test,
330
- consExpr || t.nullLiteral(),
331
- altExpr || t.nullLiteral()
332
- )
333
- addStyleExpression(styleExpr)
334
- break
335
- }
336
-
337
- case 'attr': {
338
- if (t.isJSXSpreadAttribute(attr.value)) {
339
- if (isSimpleSpread(attr.value)) {
340
- stylesExpr.elements.push(
341
- t.memberExpression(attr.value.argument, t.identifier('style'))
342
- )
343
- hocStylesExpr.elements.push(
344
- t.memberExpression(attr.value.argument, t.identifier('style'))
345
- )
346
- }
347
- }
348
- finalAttrs.push(attr.value)
349
- break
350
- }
351
- }
352
- }
353
-
354
- props.node.attributes = finalAttrs
355
-
356
- if (
357
- themeKeysUsed.size ||
358
- hocStylesExpr.elements.length > 1 ||
359
- hasDynamicStyle ||
360
- hasMediaKeys
361
- ) {
362
- if (!hasImportedViewWrapper) {
363
- root.unshiftContainer('body', importWithStyle)
364
- hasImportedViewWrapper = true
365
- }
366
-
367
- const name = props.flatNodeName || props.node.name['name']
368
- // Use a unique name that won't conflict with the base component
369
- const wrapperName = `_${name.replace(/^_+/, '')}Styled${wrapperCount++}`
370
- // Use regular identifier for variable declarations, JSX identifier for JSX elements
371
- const WrapperIdentifier = t.identifier(wrapperName)
372
- const WrapperJSXIdentifier = t.jsxIdentifier(wrapperName)
373
-
374
- const hasThemeKeysFlag = themeKeysUsed.size > 0
375
- root.pushContainer(
376
- 'body',
377
- t.variableDeclaration('const', [
378
- t.variableDeclarator(
379
- WrapperIdentifier,
380
- t.callExpression(t.identifier('_withStableStyle'), [
381
- t.identifier(name),
382
- t.arrowFunctionExpression(
383
- [t.identifier('theme'), t.identifier('_expressions')],
384
- // return styles directly - no useMemo, theme changes must trigger style recalc
385
- t.arrayExpression([...hocStylesExpr.elements])
386
- ),
387
- t.booleanLiteral(hasThemeKeysFlag),
388
- t.booleanLiteral(hasMediaKeys),
389
- ])
390
- ),
391
- ])
392
- )
393
-
394
- // @ts-ignore - use JSX identifier for JSX elements
395
- props.node.name = WrapperJSXIdentifier
396
- // Also set the opening element directly via the path
397
- props.jsxPath.node.openingElement.name = WrapperJSXIdentifier
398
- if (props.jsxPath.node.closingElement) {
399
- // @ts-ignore
400
- props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName)
401
- }
402
-
403
- if (expressions.length) {
404
- // coerce runtime expressions to boolean so they can't be
405
- // confused with string media keys at runtime
406
- const safeExpressions = expressions.map((expr, index) =>
407
- t.isStringLiteral(expr) || mediaExpressionIndexes.has(index)
408
- ? expr
409
- : t.unaryExpression('!', t.unaryExpression('!', expr))
410
- )
411
- props.node.attributes.push(
412
- t.jsxAttribute(
413
- t.jsxIdentifier('_expressions'),
414
- t.jsxExpressionContainer(t.arrayExpression(safeExpressions))
415
- )
416
- )
417
- }
418
- } else {
419
- props.node.attributes.push(
420
- t.jsxAttribute(
421
- t.jsxIdentifier('style'),
422
- t.jsxExpressionContainer(
423
- stylesExpr.elements.length === 1
424
- ? (stylesExpr.elements[0] as any)
425
- : stylesExpr
426
- )
427
- )
428
- )
429
- }
430
- },
431
- })
432
- } catch (err) {
433
- if (err instanceof Error) {
434
- // metro doesn't show stack so we can
435
- let message = `${shouldPrintDebug === 'verbose' ? err : err.message}`
436
- if (message.includes('Unexpected return value from visitor method')) {
437
- message = 'Unexpected return value from visitor method'
438
- }
439
- console.warn('Error in Tamagui parse, skipping', message, err.stack)
440
- return
441
- }
442
- }
443
-
444
- if (!Object.keys(sheetStyles).length) {
445
- if (shouldPrintDebug) {
446
- console.info('END no styles')
447
- }
448
- if (res) printLog(res)
449
- return
450
- }
451
-
452
- const sheetObject = literalToAst(sheetStyles)
453
- const sheetOuter = template(
454
- 'const SHEET = __ReactNativeStyleSheet.create(null)'
455
- )({
456
- SHEET: sheetIdentifier.name,
457
- }) as any
458
-
459
- // replace the null with our object
460
- sheetOuter.declarations[0].init.arguments[0] = sheetObject
461
- root.unshiftContainer('body', sheetOuter)
462
- // add import
463
- root.unshiftContainer('body', importStyleSheet())
464
-
465
- if (shouldPrintDebug) {
466
- console.info('\n -------- output code ------- \n')
467
- console.info(
468
- generator(root.parent)
469
- .code.split('\n')
470
- .filter((x) => !x.startsWith('//'))
471
- .join('\n')
472
- )
473
- }
474
-
475
- if (res) printLog(res)
476
- },
477
- },
478
- },
479
- }
480
- }
481
-
482
- function assertValidTag(node: t.JSXOpeningElement) {
483
- if (node.attributes.find((x) => x.type === 'JSXAttribute' && x.name.name === 'style')) {
484
- // we can just deopt here instead and log warning
485
- // need to make onExtractTag have a special catch error or similar
486
- if (process.env.DEBUG?.startsWith('tamagui')) {
487
- console.warn('⚠️ Cannot pass style attribute to extracted style')
488
- }
489
- }
490
- }
491
-
492
- function splitThemeStyles(style: object) {
493
- const themed: object = {}
494
- const plain: object = {}
495
- let noTheme = true
496
- for (const key in style) {
497
- const val = style[key]
498
- if (val && val[0] === '$') {
499
- themed[key] = val
500
- noTheme = false
501
- } else {
502
- plain[key] = val
503
- }
504
- }
505
- return { themed: noTheme ? null : themed, plain }
506
- }
@@ -1,24 +0,0 @@
1
- import type { NodePath } from '@babel/traverse'
2
- import type * as t from '@babel/types'
3
-
4
- export function findTopmostFunction(jsxPath: NodePath<t.JSXElement>) {
5
- // get topmost fn
6
- const isFunction = (path: NodePath<any>) =>
7
- path.isArrowFunctionExpression() ||
8
- path.isFunctionDeclaration() ||
9
- path.isFunctionExpression()
10
- let compFn: NodePath<any> | null = jsxPath.findParent(isFunction)
11
- while (compFn) {
12
- const parent = compFn.findParent(isFunction)
13
- if (parent) {
14
- compFn = parent
15
- } else {
16
- break
17
- }
18
- }
19
- if (!compFn) {
20
- // console.error(`Couldn't find a topmost function for media query extraction`)
21
- return null
22
- }
23
- return compFn
24
- }
@@ -1,41 +0,0 @@
1
- import * as t from '@babel/types'
2
-
3
- // TODO: open a PR upstream
4
- declare module '@babel/types' {
5
- export function toIdentifier(input: string): string
6
- }
7
-
8
- // A clone of path.scope.generateUid that doesn't prepend underscores
9
- export function generateUid(scope: any, name: string): string {
10
- if (!(typeof scope === 'object'))
11
- throw 'generateUid expects a scope object as its first parameter'
12
- if (!(typeof name === 'string' && name !== ''))
13
- throw 'generateUid expects a valid name as its second parameter'
14
-
15
- name = t
16
- .toIdentifier(name)
17
- .replace(/^_+/, '')
18
- .replace(/[0-9]+$/g, '')
19
-
20
- let uid
21
- let i = 0
22
- do {
23
- if (i > 1) {
24
- uid = name + i
25
- } else {
26
- uid = name
27
- }
28
- i++
29
- } while (
30
- scope.hasLabel(uid) ||
31
- scope.hasBinding(uid) ||
32
- scope.hasGlobal(uid) ||
33
- scope.hasReference(uid)
34
- )
35
-
36
- const program = scope.getProgramParent()
37
- program.references[uid] = true
38
- program.uids[uid] = true
39
-
40
- return uid
41
- }
@@ -1,9 +0,0 @@
1
- import { Color, colorString } from '@tamagui/cli-color'
2
- import type { TamaguiOptions } from '../types'
3
-
4
- export function getPrefixLogs(options?: TamaguiOptions) {
5
- return (
6
- options?.prefixLogs ??
7
- ` 🐥 [tamagui] ${colorString(Color.FgYellow, options?.platform || 'web')}`
8
- )
9
- }
@@ -1,95 +0,0 @@
1
- import generate from '@babel/generator'
2
- import * as t from '@babel/types'
3
-
4
- import { accessSafe } from './accessSafe'
5
-
6
- /**
7
- * getPropValueFromAttributes gets a prop by name from a list of attributes and accounts for potential spread operators.
8
- * Here's an example. Given this component:
9
- * ```
10
- * <Block coolProp="wow" {...spread1} neatProp="ok" {...spread2} />```
11
- * getPropValueFromAttributes will return the following:
12
- * - for propName `coolProp`:
13
- * ```
14
- * accessSafe(spread1, 'coolProp') || accessSafe(spread2, 'coolProp') || 'wow'```
15
- * - for propName `neatProp`:
16
- * ```
17
- * accessSafe(spread2, 'neatProp') || 'ok'```
18
- * - for propName `notPresent`: `null`
19
- *
20
- * The returned value should (obviously) be placed after spread operators.
21
- */
22
- export function getPropValueFromAttributes(
23
- propName: string,
24
- attrs: (t.JSXAttribute | t.JSXSpreadAttribute)[]
25
- ): t.Expression | null {
26
- let propIndex = -1
27
- let jsxAttr: t.JSXAttribute | null = null
28
- for (let idx = -1, len = attrs.length; ++idx < len; ) {
29
- const attr = attrs[idx]
30
- if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {
31
- propIndex = idx
32
- jsxAttr = attr
33
- break
34
- }
35
- }
36
-
37
- if (!jsxAttr || jsxAttr.value == null) {
38
- return null
39
- }
40
-
41
- let propValue:
42
- | t.JSXElement
43
- | t.JSXFragment
44
- | t.StringLiteral
45
- | t.JSXExpressionContainer
46
- | t.JSXEmptyExpression
47
- | t.Expression = jsxAttr.value
48
-
49
- if (t.isJSXExpressionContainer(propValue)) {
50
- propValue = propValue.expression
51
- }
52
-
53
- // TODO how to handle this??
54
- if (t.isJSXEmptyExpression(propValue)) {
55
- console.error('encountered JSXEmptyExpression')
56
- return null
57
- }
58
-
59
- // filter out spread props that occur before propValue
60
- const applicableSpreads = attrs
61
- .filter(
62
- // 1. idx is greater than propValue prop index
63
- // 2. attr is a spread operator
64
- (attr, idx): attr is t.JSXSpreadAttribute => {
65
- if (t.isJSXSpreadAttribute(attr)) {
66
- if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) {
67
- return idx > propIndex
68
- }
69
- if (t.isLogicalExpression(attr.argument)) {
70
- return false
71
- }
72
- throw new Error(
73
- `unsupported spread of type "${attr.argument.type}": ${
74
- // @ts-ignore
75
- generate(attr as any).code
76
- }`
77
- )
78
- }
79
- return false
80
- }
81
- )
82
- .map((attr) => attr.argument)
83
-
84
- // if spread operators occur after propValue, create a binary expression for each operator
85
- // i.e. before1.propValue || before2.propValue || propValue
86
- // TODO: figure out how to do this without all the extra parens
87
- if (applicableSpreads.length > 0) {
88
- propValue = applicableSpreads.reduce<t.Expression>(
89
- (acc, val) => t.logicalExpression('||', accessSafe(val, propName), acc),
90
- propValue
91
- )
92
- }
93
-
94
- return propValue
95
- }