peachsim 0.1.1660 → 0.1.1673

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 (515) hide show
  1. package/README.md +8 -1
  2. package/cli/bridge-flow-runner.ts +6 -3
  3. package/cli/commands/box.ts +2 -0
  4. package/cli/commands/control.ts +56 -17
  5. package/cli/commands/coverage-swift.ts +291 -0
  6. package/cli/commands/coverage.ts +168 -24
  7. package/cli/commands/debug.ts +100 -9
  8. package/cli/commands/diagnose.ts +1 -19
  9. package/cli/commands/flow.ts +2 -2
  10. package/cli/commands/inspect/settle.ts +4 -2
  11. package/cli/commands/inspect/settling.ts +17 -14
  12. package/cli/commands/platform.ts +3 -0
  13. package/cli/commands/react.ts +3 -18
  14. package/cli/commands/screenshot.ts +1 -1
  15. package/cli/commands/screenshots-capture.ts +1 -1
  16. package/cli/current-sim.ts +21 -1
  17. package/cli/dev-build-freshness.ts +36 -2
  18. package/cli/drivers/playwright-provisioning.ts +1 -4
  19. package/cli/drivers/playwright.ts +15 -1
  20. package/cli/maestro-compare.ts +44 -14
  21. package/cli/main.ts +3 -0
  22. package/cli/material-symbol-fonts.ts +3 -100
  23. package/cli/output-redaction.ts +21 -6
  24. package/cli/parent-pid.ts +2 -2
  25. package/cli/scene-video.ts +1 -1
  26. package/cli/ui.ts +20 -0
  27. package/cli/ws-bridge.ts +26 -37
  28. package/detox/frame-identity.cjs +21 -0
  29. package/detox/frame-identity.d.cts +6 -0
  30. package/detox/index.ts +39 -33
  31. package/detox/jest-environment.cjs +4 -1
  32. package/detox/jest-setup-after-env.cjs +0 -4
  33. package/detox/navigation-lifecycle.ts +2 -2
  34. package/detox/proof-observer.ts +126 -0
  35. package/dist-lib/agent-daemon-client.cjs +29 -1
  36. package/dist-lib/agent-events.cjs +1 -1
  37. package/dist-lib/attached-projects.cjs +10 -1
  38. package/dist-lib/auth/shared-session.cjs +1 -1
  39. package/dist-lib/backend-origin.cjs +1 -1
  40. package/dist-lib/beta.cjs +1 -1
  41. package/dist-lib/beta.mjs +1 -1
  42. package/dist-lib/bridge-constants.cjs +1 -1
  43. package/dist-lib/bridge-contract-input.cjs +1 -1
  44. package/dist-lib/bridge-contract-input.mjs +1 -1
  45. package/dist-lib/bridge-contract.cjs +1 -1
  46. package/dist-lib/bridge-contract.mjs +1 -1
  47. package/dist-lib/bundle-channel.cjs +2581 -27346
  48. package/dist-lib/capture-contract.cjs +1 -1
  49. package/dist-lib/capture-contract.mjs +1 -1
  50. package/dist-lib/cloud-contract.cjs +1 -1
  51. package/dist-lib/cloud-contract.mjs +1 -1
  52. package/dist-lib/cloud-test-args.cjs +1 -1
  53. package/dist-lib/cloud-test-args.mjs +1 -1
  54. package/dist-lib/cloud.cjs +1 -1
  55. package/dist-lib/cloud.mjs +1 -1
  56. package/dist-lib/config.cjs +1 -1
  57. package/dist-lib/config.mjs +1 -1
  58. package/dist-lib/detox/index.cjs +2752 -4982
  59. package/dist-lib/detox/jest-environment.cjs +4 -1
  60. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  61. package/dist-lib/expo-swift-bundle.cjs +2272 -27004
  62. package/dist-lib/expo-swift-metadata.cjs +1 -1
  63. package/dist-lib/expo-swift-metadata.mjs +1 -1
  64. package/dist-lib/home-paths.cjs +1 -1
  65. package/dist-lib/host/bridge-host.cjs +2801 -27484
  66. package/dist-lib/host/fetch-proxy-handler.cjs +7 -7
  67. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  68. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  69. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  70. package/dist-lib/host/websocket-proxy.cjs +1 -1
  71. package/dist-lib/index.cjs +394 -49
  72. package/dist-lib/jump-to-source-babel.cjs +1 -1
  73. package/dist-lib/jump-to-source-native.cjs +1 -1
  74. package/dist-lib/kotlin-host.cjs +1 -1
  75. package/dist-lib/menu.cjs +1 -1
  76. package/dist-lib/menu.mjs +1 -1
  77. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  78. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  79. package/dist-lib/metro-production-bundle.cjs +10 -1
  80. package/dist-lib/metro-production-bundle.mjs +12 -1
  81. package/dist-lib/metro.cjs +235 -13
  82. package/dist-lib/native-app-identity-project.cjs +123 -13
  83. package/dist-lib/native-app-identity-project.mjs +123 -13
  84. package/dist-lib/native-app-identity.cjs +1 -1
  85. package/dist-lib/native-app-identity.mjs +1 -1
  86. package/dist-lib/native-firebase-metadata.cjs +1 -1
  87. package/dist-lib/native-firebase-metadata.mjs +1 -1
  88. package/dist-lib/plist.cjs +1 -1
  89. package/dist-lib/plist.mjs +1 -1
  90. package/dist-lib/profiles.cjs +21 -1
  91. package/dist-lib/public-brand.cjs +1 -1
  92. package/dist-lib/public-origins-lib-esm.json +76 -28
  93. package/dist-lib/public-origins-lib-static.json +1 -1
  94. package/dist-lib/public-origins-lib.json +590 -184
  95. package/dist-lib/react-native-host-modules.cjs +1 -1
  96. package/dist-lib/react-native-host-modules.mjs +1 -1
  97. package/dist-lib/reap-browser.cjs +964 -0
  98. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  99. package/dist-lib/sdk.cjs +18 -15
  100. package/dist-lib/sdk.mjs +18 -15
  101. package/dist-lib/skills.cjs +3900 -28409
  102. package/dist-lib/swift-compile.cjs +1227 -26292
  103. package/dist-lib/swift-compile.mjs +1156 -26221
  104. package/dist-lib/swift-package.cjs +34 -4
  105. package/dist-lib/swift-package.mjs +33 -4
  106. package/dist-lib/swift-submit.cjs +2 -2
  107. package/dist-lib/swift-submit.mjs +2 -2
  108. package/dist-lib/swift-toolchain.cjs +52 -44
  109. package/dist-lib/swift.cjs +1 -1
  110. package/dist-lib/vite-swift.cjs +2317 -26955
  111. package/dist-lib/vite.cjs +132 -21
  112. package/dist-lib/worklet-executable.cjs +1 -1
  113. package/dist-lib/worklet-executable.mjs +1 -1
  114. package/dist-types/packages/peach-engine/src/demo/demo-bundle-platform.d.ts +29 -0
  115. package/dist-types/packages/peach-engine/src/engine/app-font-registry.d.ts +13 -1
  116. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +24 -0
  117. package/dist-types/packages/peach-engine/src/engine/fontDataContract.d.ts +73 -0
  118. package/dist-types/packages/peach-engine/src/engine/glass-material.d.ts +2 -3
  119. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +21 -3
  120. package/dist-types/packages/peach-engine/src/engine/inspect-outline.d.ts +2 -1
  121. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +1 -4
  122. package/dist-types/packages/peach-engine/src/engine/node.d.ts +0 -1
  123. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +3 -1
  124. package/dist-types/packages/peach-engine/src/ios/aux-shell-animated-sources.d.ts +6 -0
  125. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +68 -0
  126. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +11 -0
  127. package/dist-types/packages/peach-engine/src/render-worker/nativeSyncReplyContract.d.ts +1 -0
  128. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +8 -1
  129. package/dist-types/packages/peach-engine/src/render-worker/shell-scene-schema.d.ts +10 -2
  130. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime-kind.d.ts +24 -0
  131. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +7 -2
  132. package/dist-types/packages/peach-engine/src/settings/devices.d.ts +1 -0
  133. package/dist-types/packages/peach-globals/src/accessibilityBridgeContract.d.ts +11 -0
  134. package/dist-types/packages/peach-globals/src/androidDateTimePickerBridgeContract.d.ts +41 -0
  135. package/dist-types/packages/peach-globals/src/appLifecycleBridgeContract.d.ts +22 -0
  136. package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +33 -0
  137. package/dist-types/packages/peach-globals/src/bridgeContract.d.ts +1 -0
  138. package/dist-types/packages/peach-globals/src/cameraBridgeContract.d.ts +94 -0
  139. package/dist-types/packages/peach-globals/src/captureBridgeContract.d.ts +36 -0
  140. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +45 -0
  141. package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +31 -0
  142. package/dist-types/packages/peach-globals/src/debugBridgeContract.d.ts +27 -0
  143. package/dist-types/packages/peach-globals/src/electronBridgeContract.d.ts +29 -0
  144. package/dist-types/packages/peach-globals/src/eventBridgeContract.d.ts +200 -0
  145. package/dist-types/packages/peach-globals/src/globalsContract.d.ts +462 -0
  146. package/dist-types/packages/peach-globals/src/hostStorageBridgeContract.d.ts +3 -0
  147. package/dist-types/packages/peach-globals/src/imagePickerBridgeContract.d.ts +47 -0
  148. package/dist-types/packages/peach-globals/src/index.d.ts +47 -3343
  149. package/dist-types/packages/peach-globals/src/interactionBridgeContract.d.ts +21 -0
  150. package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +44 -0
  151. package/dist-types/packages/peach-globals/src/lockstepCaptureBridgeContract.d.ts +77 -0
  152. package/dist-types/packages/peach-globals/src/nativeViewContract.d.ts +28 -0
  153. package/dist-types/packages/peach-globals/src/navigationBridgeContract.d.ts +11 -0
  154. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +665 -0
  155. package/dist-types/packages/peach-globals/src/performanceBridgeContract.d.ts +100 -0
  156. package/dist-types/packages/peach-globals/src/permissionsBridgeContract.d.ts +152 -0
  157. package/dist-types/packages/peach-globals/src/photoLibraryBridgeContract.d.ts +36 -0
  158. package/dist-types/packages/peach-globals/src/portalBridgeContract.d.ts +9 -0
  159. package/dist-types/packages/peach-globals/src/recordingBridgeContract.d.ts +131 -0
  160. package/dist-types/packages/peach-globals/src/replayBridgeContract.d.ts +125 -0
  161. package/dist-types/packages/peach-globals/src/sceneStreamBridgeContract.d.ts +37 -0
  162. package/dist-types/packages/peach-globals/src/settingsBridgeContract.d.ts +7 -0
  163. package/dist-types/packages/peach-globals/src/shareSheetBridgeContract.d.ts +14 -0
  164. package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +82 -0
  165. package/dist-types/packages/peach-globals/src/shellHostBridgeContract.d.ts +28 -0
  166. package/dist-types/packages/peach-globals/src/speechSynthesisBridgeContract.d.ts +25 -0
  167. package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +278 -0
  168. package/dist-types/packages/peach-globals/src/timelineBridgeContract.d.ts +58 -0
  169. package/dist-types/packages/peach-globals/src/videoBridgeContract.d.ts +80 -0
  170. package/dist-types/packages/peach-globals/src/webViewBridgeContract.d.ts +331 -0
  171. package/dist-types/packages/peach-globals/src/windowBridgeContract.d.ts +5 -0
  172. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  173. package/dist-types/packages/peach-kit/src/ui/popover-placement.d.ts +3 -5
  174. package/package.json +2 -1
  175. package/runtime-companion.json +1 -1
  176. package/sdk/ios/System/Library/Frameworks/AVFoundation.framework/Headers/AVAsset.h +20 -0
  177. package/sdk/ios/System/Library/Frameworks/AVFoundation.framework/Headers/AVAsynchronousKeyValueLoading.h +15 -0
  178. package/sdk/ios/System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h +5 -0
  179. package/sdk/ios/System/Library/Frameworks/AVFoundation.framework/Headers/AVMetadataFormat.h +13 -0
  180. package/sdk/ios/System/Library/Frameworks/AVFoundation.framework/Headers/AVMetadataItem.h +16 -0
  181. package/sdk/ios/System/Library/Frameworks/AVFoundation.framework/Headers/AVTimedMetadataGroup.h +13 -0
  182. package/sdk/ios/System/Library/Frameworks/AVFoundation.framework/Modules/module.modulemap +4 -0
  183. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Conversion.h +19 -0
  184. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Convolution.h +11 -0
  185. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Geometry.h +17 -0
  186. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage.h +13 -0
  187. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_Types.h +307 -0
  188. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_Utilities.h +174 -0
  189. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h +7 -0
  190. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/CoreData.h +5 -0
  191. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSFetchRequest.h +21 -0
  192. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSFetchedResultsController.h +39 -0
  193. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSManagedObject.h +10 -0
  194. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSManagedObjectContext.h +9 -0
  195. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSManagedObjectID.h +7 -0
  196. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSManagedObjectModel.h +5 -0
  197. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSPersistentStoreCoordinator.h +5 -0
  198. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSPersistentStoreRequest.h +5 -0
  199. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Modules/module.modulemap +5 -0
  200. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +2 -0
  201. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +221 -0
  202. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBase.h +2 -0
  203. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +316 -0
  204. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Modules/module.modulemap +4 -0
  205. package/sdk/ios/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.h +46 -0
  206. package/sdk/ios/System/Library/Frameworks/CoreImage.framework/Modules/module.modulemap +4 -0
  207. package/sdk/ios/System/Library/Frameworks/CoreMedia.framework/Headers/CMTime.h +31 -0
  208. package/sdk/ios/System/Library/Frameworks/CoreMedia.framework/Headers/CMTimeRange.h +8 -0
  209. package/sdk/ios/System/Library/Frameworks/CoreMedia.framework/Headers/CoreMedia.h +3 -0
  210. package/sdk/ios/System/Library/Frameworks/CoreMedia.framework/Modules/module.modulemap +4 -0
  211. package/sdk/ios/System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h +12 -0
  212. package/sdk/ios/System/Library/Frameworks/CoreServices.framework/Headers/UTCoreTypes.h +1276 -0
  213. package/sdk/ios/System/Library/Frameworks/CoreServices.framework/Headers/UTType.h +644 -0
  214. package/sdk/ios/System/Library/Frameworks/CoreText.framework/Headers/CTFontManager.h +20 -0
  215. package/sdk/ios/System/Library/Frameworks/CoreText.framework/Headers/CoreText.h +2 -0
  216. package/sdk/ios/System/Library/Frameworks/CoreText.framework/Modules/module.modulemap +4 -0
  217. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +1441 -0
  218. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Modules/module.modulemap +4 -0
  219. package/sdk/ios/System/Library/Frameworks/ImageIO.framework/Headers/CGImageAnimation.h +106 -0
  220. package/sdk/ios/System/Library/Frameworks/ImageIO.framework/Headers/CGImageDestination.h +429 -0
  221. package/sdk/ios/System/Library/Frameworks/ImageIO.framework/Headers/CGImageMetadata.h +665 -0
  222. package/sdk/ios/System/Library/Frameworks/ImageIO.framework/Headers/CGImageProperties.h +2504 -0
  223. package/sdk/ios/System/Library/Frameworks/ImageIO.framework/Headers/CGImageSource.h +634 -0
  224. package/sdk/ios/System/Library/Frameworks/ImageIO.framework/Headers/ImageIO.h +22 -0
  225. package/sdk/ios/System/Library/Frameworks/ImageIO.framework/Headers/ImageIOBase.h +18 -0
  226. package/sdk/ios/System/Library/Frameworks/ImageIO.framework/Modules/module.modulemap +4 -0
  227. package/sdk/ios/System/Library/Frameworks/MobileCoreServices.framework/Headers/MobileCoreServices.h +9 -0
  228. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.h +40 -0
  229. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Modules/module.modulemap +4 -0
  230. package/sdk/ios/System/Library/Frameworks/SafariServices.framework/Headers/SFSafariViewController.h +14 -0
  231. package/sdk/ios/System/Library/Frameworks/SafariServices.framework/Headers/SFSafariViewControllerConfiguration.h +9 -0
  232. package/sdk/ios/System/Library/Frameworks/SafariServices.framework/Headers/SafariServices.h +2 -0
  233. package/sdk/ios/System/Library/Frameworks/SafariServices.framework/Modules/module.modulemap +5 -0
  234. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecBase.h +3 -0
  235. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecItem.h +30 -0
  236. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/Security.h +3 -0
  237. package/sdk/ios/System/Library/Frameworks/Security.framework/Modules/module.modulemap +5 -0
  238. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStore.h +439 -0
  239. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h +216 -0
  240. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreKey.h +267 -0
  241. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetwork.h +204 -0
  242. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h +1393 -0
  243. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConnection.h +568 -0
  244. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkReachability.h +369 -0
  245. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferences.h +473 -0
  246. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesPath.h +179 -0
  247. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesSetSpecific.h +95 -0
  248. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h +2395 -0
  249. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SystemConfiguration.h +184 -0
  250. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAppearance.h +5 -0
  251. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIColor.h +2 -0
  252. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +817 -0
  253. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Modules/module.modulemap +4 -0
  254. package/sdk/ios/usr/include/Availability.h +630 -0
  255. package/sdk/ios/usr/include/AvailabilityInternal.h +556 -0
  256. package/sdk/ios/usr/include/AvailabilityInternalLegacy.h +4346 -0
  257. package/sdk/ios/usr/include/AvailabilityVersions.h +547 -0
  258. package/sdk/ios/usr/include/CommonCrypto/CommonDigest.h +130 -0
  259. package/sdk/ios/usr/include/MacTypes.h +3 -0
  260. package/sdk/ios/usr/include/TargetConditionals.h +14 -0
  261. package/sdk/ios/usr/include/__xlocale.h +41 -0
  262. package/sdk/ios/usr/include/_bounds.h +67 -0
  263. package/sdk/ios/usr/include/_ctermid.h +42 -0
  264. package/sdk/ios/usr/include/_mb_cur_max.h +39 -0
  265. package/sdk/ios/usr/include/_printf.h +38 -0
  266. package/sdk/ios/usr/include/_stdio.h +510 -0
  267. package/sdk/ios/usr/include/_types/_intmax_t.h +40 -0
  268. package/sdk/ios/usr/include/_types/_locale_t.h +38 -0
  269. package/sdk/ios/usr/include/_types/_uint16_t.h +32 -0
  270. package/sdk/ios/usr/include/_types/_uint32_t.h +32 -0
  271. package/sdk/ios/usr/include/_types/_uint64_t.h +32 -0
  272. package/sdk/ios/usr/include/_types/_uint8_t.h +32 -0
  273. package/sdk/ios/usr/include/_types/_uintmax_t.h +40 -0
  274. package/sdk/ios/usr/include/_types.h +72 -0
  275. package/sdk/ios/usr/include/arm/_endian.h +105 -0
  276. package/sdk/ios/usr/include/arm/_mcontext.h +95 -0
  277. package/sdk/ios/usr/include/arm/_param.h +25 -0
  278. package/sdk/ios/usr/include/arm/_types.h +125 -0
  279. package/sdk/ios/usr/include/arm/endian.h +65 -0
  280. package/sdk/ios/usr/include/arm/signal.h +22 -0
  281. package/sdk/ios/usr/include/arm/types.h +110 -0
  282. package/sdk/ios/usr/include/asl.h +160 -0
  283. package/sdk/ios/usr/include/assert.h +14 -0
  284. package/sdk/ios/usr/include/dirent.h +224 -0
  285. package/sdk/ios/usr/include/dispatch/dispatch.h +114 -0
  286. package/sdk/ios/usr/include/dlfcn.h +16 -0
  287. package/sdk/ios/usr/include/errno.h +24 -0
  288. package/sdk/ios/usr/include/execinfo.h +11 -0
  289. package/sdk/ios/usr/include/fcntl.h +23 -0
  290. package/sdk/ios/usr/include/i386/_endian.h +105 -0
  291. package/sdk/ios/usr/include/i386/_mcontext.h +216 -0
  292. package/sdk/ios/usr/include/i386/_param.h +49 -0
  293. package/sdk/ios/usr/include/i386/_types.h +149 -0
  294. package/sdk/ios/usr/include/i386/endian.h +89 -0
  295. package/sdk/ios/usr/include/i386/signal.h +47 -0
  296. package/sdk/ios/usr/include/libkern/OSAtomic.h +51 -0
  297. package/sdk/ios/usr/include/libkern/OSAtomicDeprecated.h +1267 -0
  298. package/sdk/ios/usr/include/libkern/OSAtomicQueue.h +115 -0
  299. package/sdk/ios/usr/include/libkern/OSByteOrder.h +315 -0
  300. package/sdk/ios/usr/include/libkern/OSSpinLockDeprecated.h +212 -0
  301. package/sdk/ios/usr/include/libkern/_OSByteOrder.h +125 -0
  302. package/sdk/ios/usr/include/libkern/arm/_OSByteOrder.h +99 -0
  303. package/sdk/ios/usr/include/libkern/i386/_OSByteOrder.h +110 -0
  304. package/sdk/ios/usr/include/libkern/machine/OSByteOrder.h +147 -0
  305. package/sdk/ios/usr/include/limits.h +4 -0
  306. package/sdk/ios/usr/include/mach/arm/_structs.h +741 -0
  307. package/sdk/ios/usr/include/mach/boolean.h +4 -0
  308. package/sdk/ios/usr/include/mach/exception_types.h +40 -0
  309. package/sdk/ios/usr/include/mach/host_info.h +200 -0
  310. package/sdk/ios/usr/include/mach/i386/_structs.h +1316 -0
  311. package/sdk/ios/usr/include/mach/kern_return.h +61 -0
  312. package/sdk/ios/usr/include/mach/mach.h +16 -0
  313. package/sdk/ios/usr/include/mach/mach_error.h +10 -0
  314. package/sdk/ios/usr/include/mach/mach_host.h +18 -0
  315. package/sdk/ios/usr/include/mach/mach_init.h +15 -0
  316. package/sdk/ios/usr/include/mach/mach_port.h +11 -0
  317. package/sdk/ios/usr/include/mach/mach_time.h +14 -0
  318. package/sdk/ios/usr/include/mach/mach_types.h +20 -0
  319. package/sdk/ios/usr/include/mach/machine/_structs.h +40 -0
  320. package/sdk/ios/usr/include/mach/machine.h +144 -0
  321. package/sdk/ios/usr/include/mach/task.h +14 -0
  322. package/sdk/ios/usr/include/mach/task_info.h +23 -0
  323. package/sdk/ios/usr/include/mach/task_policy.h +29 -0
  324. package/sdk/ios/usr/include/mach/thread_act.h +12 -0
  325. package/sdk/ios/usr/include/mach/thread_info.h +32 -0
  326. package/sdk/ios/usr/include/mach/time_value.h +4 -0
  327. package/sdk/ios/usr/include/mach/vm_prot.h +8 -0
  328. package/sdk/ios/usr/include/mach/vm_region.h +43 -0
  329. package/sdk/ios/usr/include/mach/vm_statistics.h +491 -0
  330. package/sdk/ios/usr/include/mach/vm_types.h +8 -0
  331. package/sdk/ios/usr/include/mach-o/arch.h +21 -0
  332. package/sdk/ios/usr/include/mach-o/dyld.h +16 -0
  333. package/sdk/ios/usr/include/mach-o/dyld_images.h +71 -0
  334. package/sdk/ios/usr/include/mach-o/getsect.h +17 -0
  335. package/sdk/ios/usr/include/mach-o/loader.h +158 -0
  336. package/sdk/ios/usr/include/mach-o/nlist.h +38 -0
  337. package/sdk/ios/usr/include/mach-o/stab.h +33 -0
  338. package/sdk/ios/usr/include/mach-o/utils.h +10 -0
  339. package/sdk/ios/usr/include/machine/_endian.h +42 -0
  340. package/sdk/ios/usr/include/machine/_mcontext.h +39 -0
  341. package/sdk/ios/usr/include/machine/_param.h +39 -0
  342. package/sdk/ios/usr/include/machine/_types.h +39 -0
  343. package/sdk/ios/usr/include/machine/endian.h +42 -0
  344. package/sdk/ios/usr/include/machine/signal.h +39 -0
  345. package/sdk/ios/usr/include/machine/types.h +42 -0
  346. package/sdk/ios/usr/include/math.h +5 -0
  347. package/sdk/ios/usr/include/module.modulemap +4 -0
  348. package/sdk/ios/usr/include/net/if.h +20 -0
  349. package/sdk/ios/usr/include/net/if_dl.h +10 -0
  350. package/sdk/ios/usr/include/net/if_var.h +15 -0
  351. package/sdk/ios/usr/include/net/net_kev.h +100 -0
  352. package/sdk/ios/usr/include/netdb.h +5 -0
  353. package/sdk/ios/usr/include/netinet/in.h +670 -0
  354. package/sdk/ios/usr/include/netinet6/in6.h +676 -0
  355. package/sdk/ios/usr/include/notify.h +45 -0
  356. package/sdk/ios/usr/include/notify_keys.h +17 -0
  357. package/sdk/ios/usr/include/objc/NSObject.h +79 -0
  358. package/sdk/ios/usr/include/os/availability.h +140 -0
  359. package/sdk/ios/usr/include/os/lock.h +24 -0
  360. package/sdk/ios/usr/include/os/log.h +77 -0
  361. package/sdk/ios/usr/include/os/object.h +13 -0
  362. package/sdk/ios/usr/include/peach/darwin.h +6 -0
  363. package/sdk/ios/usr/include/peach/netdb.h +316 -0
  364. package/sdk/ios/usr/include/peach/pthread.h +19 -0
  365. package/sdk/ios/usr/include/pthread.h +4 -0
  366. package/sdk/ios/usr/include/secure/_common.h +45 -0
  367. package/sdk/ios/usr/include/secure/_stdio.h +130 -0
  368. package/sdk/ios/usr/include/signal.h +132 -0
  369. package/sdk/ios/usr/include/stdint.h +205 -0
  370. package/sdk/ios/usr/include/stdio.h +65 -0
  371. package/sdk/ios/usr/include/stdlib.h +17 -0
  372. package/sdk/ios/usr/include/string.h +8 -0
  373. package/sdk/ios/usr/include/sys/__endian.h +108 -0
  374. package/sdk/ios/usr/include/sys/_endian.h +152 -0
  375. package/sdk/ios/usr/include/sys/_posix_availability.h +73 -0
  376. package/sdk/ios/usr/include/sys/_pthread/_pthread_attr_t.h +32 -0
  377. package/sdk/ios/usr/include/sys/_pthread/_pthread_t.h +32 -0
  378. package/sdk/ios/usr/include/sys/_pthread/_pthread_types.h +120 -0
  379. package/sdk/ios/usr/include/sys/_symbol_aliasing.h +1093 -0
  380. package/sdk/ios/usr/include/sys/_types/_errno_t.h +31 -0
  381. package/sdk/ios/usr/include/sys/_types/_filesec_t.h +32 -0
  382. package/sdk/ios/usr/include/sys/_types/_gid_t.h +32 -0
  383. package/sdk/ios/usr/include/sys/_types/_in_addr_t.h +32 -0
  384. package/sdk/ios/usr/include/sys/_types/_in_port_t.h +32 -0
  385. package/sdk/ios/usr/include/sys/_types/_ino_t.h +32 -0
  386. package/sdk/ios/usr/include/sys/_types/_int16_t.h +31 -0
  387. package/sdk/ios/usr/include/sys/_types/_int32_t.h +31 -0
  388. package/sdk/ios/usr/include/sys/_types/_int64_t.h +31 -0
  389. package/sdk/ios/usr/include/sys/_types/_int8_t.h +31 -0
  390. package/sdk/ios/usr/include/sys/_types/_intptr_t.h +33 -0
  391. package/sdk/ios/usr/include/sys/_types/_iovec_t.h +35 -0
  392. package/sdk/ios/usr/include/sys/_types/_mode_t.h +32 -0
  393. package/sdk/ios/usr/include/sys/_types/_null.h +54 -0
  394. package/sdk/ios/usr/include/sys/_types/_o_dsync.h +30 -0
  395. package/sdk/ios/usr/include/sys/_types/_o_sync.h +30 -0
  396. package/sdk/ios/usr/include/sys/_types/_off_t.h +32 -0
  397. package/sdk/ios/usr/include/sys/_types/_pid_t.h +32 -0
  398. package/sdk/ios/usr/include/sys/_types/_ptrdiff_t.h +56 -0
  399. package/sdk/ios/usr/include/sys/_types/_s_ifmt.h +74 -0
  400. package/sdk/ios/usr/include/sys/_types/_sa_family_t.h +32 -0
  401. package/sdk/ios/usr/include/sys/_types/_seek_set.h +51 -0
  402. package/sdk/ios/usr/include/sys/_types/_sigaltstack.h +50 -0
  403. package/sdk/ios/usr/include/sys/_types/_sigset_t.h +32 -0
  404. package/sdk/ios/usr/include/sys/_types/_size_t.h +56 -0
  405. package/sdk/ios/usr/include/sys/_types/_socklen_t.h +32 -0
  406. package/sdk/ios/usr/include/sys/_types/_ssize_t.h +32 -0
  407. package/sdk/ios/usr/include/sys/_types/_timespec.h +38 -0
  408. package/sdk/ios/usr/include/sys/_types/_timeval32.h +3 -0
  409. package/sdk/ios/usr/include/sys/_types/_u_int16_t.h +31 -0
  410. package/sdk/ios/usr/include/sys/_types/_u_int32_t.h +31 -0
  411. package/sdk/ios/usr/include/sys/_types/_u_int64_t.h +31 -0
  412. package/sdk/ios/usr/include/sys/_types/_u_int8_t.h +31 -0
  413. package/sdk/ios/usr/include/sys/_types/_ucontext.h +59 -0
  414. package/sdk/ios/usr/include/sys/_types/_uid_t.h +32 -0
  415. package/sdk/ios/usr/include/sys/_types/_uintptr_t.h +37 -0
  416. package/sdk/ios/usr/include/sys/_types/_va_list.h +49 -0
  417. package/sdk/ios/usr/include/sys/_types/_wchar_t.h +59 -0
  418. package/sdk/ios/usr/include/sys/_types.h +103 -0
  419. package/sdk/ios/usr/include/sys/appleapiopts.h +61 -0
  420. package/sdk/ios/usr/include/sys/cdefs.h +341 -0
  421. package/sdk/ios/usr/include/sys/constrained_ctypes.h +622 -0
  422. package/sdk/ios/usr/include/sys/dirent.h +141 -0
  423. package/sdk/ios/usr/include/sys/errno.h +271 -0
  424. package/sdk/ios/usr/include/sys/fcntl.h +649 -0
  425. package/sdk/ios/usr/include/sys/mman.h +273 -0
  426. package/sdk/ios/usr/include/sys/proc.h +65 -0
  427. package/sdk/ios/usr/include/sys/qos.h +61 -0
  428. package/sdk/ios/usr/include/sys/signal.h +394 -0
  429. package/sdk/ios/usr/include/sys/socket.h +752 -0
  430. package/sdk/ios/usr/include/sys/stdio.h +61 -0
  431. package/sdk/ios/usr/include/sys/sysctl.h +74 -0
  432. package/sdk/ios/usr/include/sys/syslimits.h +11 -0
  433. package/sdk/ios/usr/include/sys/time.h +5 -0
  434. package/sdk/ios/usr/include/sys/types.h +21 -0
  435. package/sdk/ios/usr/include/sys/ucontext.h +41 -0
  436. package/sdk/ios/usr/include/sys/xattr.h +50 -0
  437. package/sdk/ios/usr/include/time.h +2 -0
  438. package/sdk/ios/usr/include/unistd.h +3 -0
  439. package/sdk/ios/usr/include/uuid/uuid.h +19 -0
  440. package/sdk/ios/usr/include/xlocale/_stdio.h +85 -0
  441. package/sdk/ios/usr/lib/swift/CoreGraphics.swiftmodule/arm64-apple-ios-simulator.swiftinterface +8 -0
  442. package/sdk/ios/usr/lib/swift/Foundation.swiftmodule/arm64-apple-ios-simulator.swiftinterface +51 -0
  443. package/sdk/ios/usr/lib/swift/ObjectiveC.swiftmodule/arm64-apple-ios-simulator.swiftinterface +20 -0
  444. package/sdk/ios/wasm/include/dlfcn.h +3 -0
  445. package/sdk/ios/wasm/include/netdb.h +4 -0
  446. package/sdk/ios/wasm/include/pthread.h +3 -0
  447. package/sdk/ios/wasm/include/stdlib.h +3 -0
  448. package/sdk/ios/wasm/include/string.h +3 -0
  449. package/sdk/ios/wasm/include/sys/socket.h +7 -0
  450. package/sdk/ios/wasm/include/sys/types.h +4 -0
  451. package/sdk/ios/wasm/include/sys/ucontext.h +38 -0
  452. package/src/bridge-contract.ts +42 -0
  453. package/src/chromium-admission.ts +196 -0
  454. package/src/cli-runtime.ts +5 -5
  455. package/src/conformance-comparison-contract.ts +146 -0
  456. package/src/conformance-pixel-comparison.ts +327 -0
  457. package/src/device-catalog.ts +12 -3
  458. package/src/host/bridge-host.ts +6 -43
  459. package/src/launch-deadline.ts +74 -0
  460. package/src/material-symbol-fonts.ts +107 -0
  461. package/src/nitro-adapter.lock.json +3 -3
  462. package/src/profiles.ts +21 -0
  463. package/src/react-native-coverage/capability-reference-resolution.ts +402 -0
  464. package/src/react-native-coverage/capability-source-references.ts +1296 -0
  465. package/src/react-native-coverage/native-typescript-parser.ts +74 -0
  466. package/src/react-native-coverage/project-aliases.ts +207 -0
  467. package/src/react-native-coverage/verified-reach.ts +47 -0
  468. package/src/reap-browser.ts +1019 -0
  469. package/src/skills/builtin/a11y-review.ts +1 -1
  470. package/src/skills/builtin/perf-profile.ts +1 -1
  471. package/src/skills/builtin/screenshot-all.ts +1 -1
  472. package/src/skills/builtin/visual-diff.ts +1 -1
  473. package/src/swift-compile.ts +584 -226
  474. package/src/swift-compiler-digest.ts +6 -2
  475. package/src/swift-coverage/indexdump.ts +80 -0
  476. package/src/swift-coverage/indexing.ts +147 -0
  477. package/src/swift-coverage/package.ts +230 -0
  478. package/src/swift-coverage/provenance.ts +47 -0
  479. package/src/swift-coverage/reader.ts +81 -0
  480. package/src/swift-coverage/source.ts +252 -0
  481. package/src/swift-coverage/types.ts +58 -0
  482. package/src/swift-coverage/xcode-assets.ts +175 -0
  483. package/src/swift-coverage/xcode-bridging.ts +160 -0
  484. package/src/swift-coverage/xcode-packages.ts +251 -0
  485. package/src/swift-coverage/xcode-strings.ts +78 -0
  486. package/src/swift-coverage/xcode.ts +656 -0
  487. package/src/swift-distribution.lock.json +8 -8
  488. package/src/swift-distribution.ts +2 -1
  489. package/src/swift-host.ts +47 -4
  490. package/src/swift-objc-compile.ts +72 -97
  491. package/src/swift-objc-import.ts +238 -38
  492. package/src/swift-objc-metadata.ts +54 -7
  493. package/src/swift-objc-sdk-tree.ts +17 -0
  494. package/src/swift-objc-sdk.ts +27 -25677
  495. package/src/swift-objc-standin.ts +4 -2
  496. package/src/swift-package-manifest.ts +134 -13
  497. package/src/swift-package.ts +46 -4
  498. package/src/swift-standins.ts +2 -2
  499. package/src/swift-submit.ts +2 -1
  500. package/src/swift-toolchain.ts +72 -61
  501. package/src/swift-vite-lifetime.ts +42 -0
  502. package/src/swiftContract.ts +54 -0
  503. package/src/vite-plugin-one.ts +36 -15
  504. package/src/vite-plugin-swift.ts +21 -2
  505. package/src/worker-system-chunks.ts +3 -10
  506. package/src/xcode-header-search.ts +114 -0
  507. package/src/xcode-project.ts +108 -14
  508. package/detox/attempt-events.cjs +0 -884
  509. package/detox/attempt-events.d.cts +0 -113
  510. package/detox/motion-change.cjs +0 -524
  511. package/detox/motion-change.d.cts +0 -140
  512. package/detox/motion-leg-starts.cjs +0 -20
  513. package/detox/motion-leg-starts.d.cts +0 -8
  514. package/detox/proof-frame.cjs +0 -190
  515. package/detox/record-block-execution.cjs +0 -78
@@ -0,0 +1,1296 @@
1
+ import { createHash } from 'node:crypto'
2
+ import * as ts from 'typescript/ast'
3
+ import type { TypeScriptSourceParser } from './native-typescript-parser'
4
+ import type { Symbol as NativeSymbol } from 'typescript/async'
5
+
6
+ export type CapabilityReferenceKind =
7
+ | 'export'
8
+ | 'member'
9
+ | 'prop'
10
+ | 'style'
11
+ | 'spread'
12
+ | 'side-effect'
13
+
14
+ export type StaticValue = string | number | boolean
15
+
16
+ export type CapabilityReferenceCandidate = {
17
+ id: string
18
+ corpus: string
19
+ path: string
20
+ start: number
21
+ end: number
22
+ originStart: number | null
23
+ packageName: string
24
+ module: string
25
+ kind: CapabilityReferenceKind
26
+ exportName: string
27
+ memberName: string | null
28
+ /** the literal a prop or style entry is set to; null when absent or computed */
29
+ value?: StaticValue | null
30
+ exclusion: string | null
31
+ importForm:
32
+ | 'named'
33
+ | 'default'
34
+ | 'namespace'
35
+ | 'require'
36
+ | 'side-effect'
37
+ | 're-export'
38
+ | null
39
+ }
40
+
41
+ export type CapabilityReferenceResolution = CapabilityReferenceCandidate &
42
+ (
43
+ | { state: 'attributed'; capabilityId: string }
44
+ | { state: 'unmatched'; reason: string }
45
+ | { state: 'excluded'; reason: string }
46
+ )
47
+
48
+ type SourceBinding = {
49
+ packageName: string
50
+ module: string
51
+ exportName: string
52
+ typeOnly: boolean
53
+ memberPath?: readonly string[]
54
+ }
55
+
56
+ // collect package-bound occurrences before looking at the capability inventory.
57
+ // a nested root is a public export whose static member chain is one reference
58
+ // (`One.iOS.List` is member `iOS.List` of `One`); other exports keep one level.
59
+ export async function collectCapabilityReferences(
60
+ parse: TypeScriptSourceParser,
61
+ content: string,
62
+ path: string,
63
+ packageNames: ReadonlySet<string> | null,
64
+ corpus = 'fixture',
65
+ nestedRoots: readonly { exportName: string | null; module: string }[] = [],
66
+ ): Promise<CapabilityReferenceCandidate[]> {
67
+ // an escaped module name needs decoding. otherwise a package-bound literal
68
+ // must contain its package name before opening a native compiler program.
69
+ if (
70
+ packageNames &&
71
+ !content.includes('\\') &&
72
+ ![...packageNames].some((name) => content.includes(name))
73
+ ) {
74
+ return []
75
+ }
76
+ return parse(new Map([[path, content]]), async (sources, projects) => {
77
+ const source = sources.get(path)
78
+ const project = projects.get(path)
79
+ if (!source || !project)
80
+ throw new Error(`native TypeScript parser did not return ${path}`)
81
+ const identifiers: ts.Identifier[] = []
82
+ const collectIdentifiers = (node: ts.Node): void => {
83
+ if (ts.isIdentifier(node)) identifiers.push(node)
84
+ node.forEachChild(collectIdentifiers)
85
+ }
86
+ collectIdentifiers(source)
87
+ const resolvedSymbols = await project.checker.getSymbolAtLocation(identifiers)
88
+ const symbols = new Map<ts.Node, NativeSymbol | undefined>(
89
+ identifiers.map((identifier, index) => [identifier, resolvedSymbols[index]]),
90
+ )
91
+ // export specifiers and object shorthands have their own symbols; safety
92
+ // checks need the lexical value they expose, without inferring its type.
93
+ await Promise.all(
94
+ identifiers.map(async (identifier) => {
95
+ const parent = identifier.parent
96
+ if (ts.isShorthandPropertyAssignment(parent) && parent.name === identifier)
97
+ symbols.set(
98
+ identifier,
99
+ await project.checker.getShorthandAssignmentValueSymbol(parent),
100
+ )
101
+ else if (
102
+ ts.isExportSpecifier(parent) &&
103
+ (parent.propertyName ?? parent.name) === identifier &&
104
+ ts.isExportDeclaration(parent.parent.parent) &&
105
+ !parent.parent.parent.moduleSpecifier
106
+ )
107
+ symbols.set(
108
+ identifier,
109
+ await project.checker.getExportSpecifierLocalTargetSymbol(parent),
110
+ )
111
+ }),
112
+ )
113
+ const valueDeclarations = new Map<number, ts.Node>()
114
+ await Promise.all(
115
+ [
116
+ ...new Map(
117
+ resolvedSymbols.flatMap((symbol) => (symbol ? [[symbol.id, symbol]] : [])),
118
+ ).values(),
119
+ ].map(async (symbol) => {
120
+ const declaration = await symbol.valueDeclaration?.resolve(project)
121
+ if (declaration) valueDeclarations.set(symbol.id, declaration)
122
+ }),
123
+ )
124
+ const bindings = new Map<number, SourceBinding>()
125
+ const bindingNames = new Map<number, ts.Identifier>()
126
+ const symbolUses = new Map<number, ts.Identifier[]>()
127
+ for (const identifier of identifiers) {
128
+ const symbol = symbols.get(identifier)
129
+ if (!symbol) continue
130
+ const uses = symbolUses.get(symbol.id) ?? []
131
+ uses.push(identifier)
132
+ symbolUses.set(symbol.id, uses)
133
+ }
134
+ const reactFactories = new Map<number, 'container' | 'factory'>()
135
+ const reactRefCreators = new Map<number, 'container' | 'creator'>()
136
+ const candidates = new Map<string, CapabilityReferenceCandidate>()
137
+ const packageFor = (module: string) => {
138
+ if (module.startsWith('.') || module.startsWith('/') || module.includes(':'))
139
+ return undefined
140
+ const parts = module.split('/')
141
+ const packageName = module.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]
142
+ return packageName && (!packageNames || packageNames.has(packageName))
143
+ ? packageName
144
+ : undefined
145
+ }
146
+ function emit(
147
+ node: ts.Node,
148
+ binding: SourceBinding,
149
+ kind: CapabilityReferenceKind,
150
+ memberName: string | null = null,
151
+ exclusion: string | null = null,
152
+ importForm: CapabilityReferenceCandidate['importForm'] = null,
153
+ originStart: number | null = null,
154
+ value: StaticValue | null = null,
155
+ ): void {
156
+ const start = node.getStart(source)
157
+ const end = node.end
158
+ const id = createHash('sha256')
159
+ .update(
160
+ JSON.stringify([
161
+ corpus,
162
+ path,
163
+ start,
164
+ end,
165
+ binding.packageName,
166
+ binding.module,
167
+ kind,
168
+ binding.exportName,
169
+ memberName,
170
+ originStart,
171
+ ]),
172
+ )
173
+ .digest('hex')
174
+ const candidate = {
175
+ id,
176
+ corpus,
177
+ path,
178
+ start,
179
+ end,
180
+ originStart,
181
+ packageName: binding.packageName,
182
+ module: binding.module,
183
+ kind,
184
+ exportName: binding.exportName,
185
+ memberName,
186
+ value,
187
+ exclusion: binding.typeOnly
188
+ ? 'type-only import'
189
+ : (exclusion ??
190
+ (kind === 'export' &&
191
+ nestedRoots.some(
192
+ (root) =>
193
+ root.module === binding.module && root.exportName === binding.exportName,
194
+ )
195
+ ? 'nested root container; member chains counted at use sites'
196
+ : null)),
197
+ importForm,
198
+ }
199
+ if (candidates.has(id))
200
+ throw new Error(`duplicate candidate visitation: ${path}:${start}:${kind}`)
201
+ candidates.set(id, candidate)
202
+ }
203
+ function bind(name: ts.Identifier, binding: SourceBinding): void {
204
+ const symbol = symbols.get(name)
205
+ if (!symbol)
206
+ throw new Error(`unresolved lexical declaration at ${path}:${name.pos}`)
207
+ bindings.set(symbol.id, binding)
208
+ bindingNames.set(symbol.id, name)
209
+ }
210
+ function bindingFor(node: ts.Node, nestedMembers = false): SourceBinding | undefined {
211
+ if (ts.isIdentifier(node)) {
212
+ const symbol = symbols.get(node)
213
+ return symbol ? bindings.get(symbol.id) : undefined
214
+ }
215
+ if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
216
+ const owner = bindingFor(node.expression, nestedMembers)
217
+ if (!owner || owner.typeOnly) return undefined
218
+ const member = ts.isPropertyAccessExpression(node)
219
+ ? node.name.text
220
+ : node.argumentExpression && ts.isStringLiteralLikeNode(node.argumentExpression)
221
+ ? node.argumentExpression.text
222
+ : null
223
+ if (
224
+ member &&
225
+ (owner.exportName === '*' ||
226
+ (owner.exportName === 'default' && owner.packageName === 'react-native'))
227
+ ) {
228
+ return { ...owner, exportName: member }
229
+ }
230
+ if (
231
+ nestedMembers &&
232
+ member &&
233
+ nestedRoots.some(
234
+ (root) =>
235
+ root.module === owner.module && root.exportName === owner.exportName,
236
+ )
237
+ )
238
+ return { ...owner, memberPath: [...(owner.memberPath ?? []), member] }
239
+ }
240
+ return undefined
241
+ }
242
+ function memberKey(node: ts.Node): string | null {
243
+ if (ts.isPropertyAccessExpression(node)) return node.name.text
244
+ return ts.isElementAccessExpression(node) &&
245
+ node.argumentExpression &&
246
+ ts.isStringLiteralLikeNode(node.argumentExpression)
247
+ ? node.argumentExpression.text
248
+ : null
249
+ }
250
+ // a static chain of member names below a nested root binding
251
+ function nestedChain(
252
+ node: ts.Node,
253
+ ): { binding: SourceBinding; names: string[] } | undefined {
254
+ if (!ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node))
255
+ return undefined
256
+ const name = memberKey(node)
257
+ if (name === null) return undefined
258
+ const binding = bindingFor(node.expression, true)
259
+ return binding &&
260
+ !binding.typeOnly &&
261
+ nestedRoots.some(
262
+ (root) =>
263
+ root.module === binding.module && root.exportName === binding.exportName,
264
+ )
265
+ ? { binding, names: [...(binding.memberPath ?? []), name] }
266
+ : undefined
267
+ }
268
+ function imports(node: ts.Node): void {
269
+ if (
270
+ ts.isImportDeclaration(node) &&
271
+ ts.isStringLiteralLikeNode(node.moduleSpecifier)
272
+ ) {
273
+ const module = node.moduleSpecifier.text
274
+ const clause = node.importClause
275
+ if (
276
+ ['react', 'react/jsx-runtime', 'react/jsx-dev-runtime'].includes(module) &&
277
+ clause &&
278
+ clause.phaseModifier !== ts.SyntaxKind.TypeKeyword
279
+ ) {
280
+ if (clause.name) {
281
+ const symbol = symbols.get(clause.name)
282
+ if (symbol) reactFactories.set(symbol.id, 'container')
283
+ if (symbol && module === 'react') reactRefCreators.set(symbol.id, 'container')
284
+ }
285
+ if (clause.namedBindings && ts.isNamespaceImport(clause.namedBindings)) {
286
+ const symbol = symbols.get(clause.namedBindings.name)
287
+ if (symbol) reactFactories.set(symbol.id, 'container')
288
+ if (symbol && module === 'react') reactRefCreators.set(symbol.id, 'container')
289
+ } else if (clause.namedBindings) {
290
+ for (const specifier of clause.namedBindings.elements) {
291
+ const imported = specifier.propertyName?.text ?? specifier.name.text
292
+ if (
293
+ module === 'react' &&
294
+ !specifier.isTypeOnly &&
295
+ (imported === 'useRef' || imported === 'createRef')
296
+ ) {
297
+ const symbol = symbols.get(specifier.name)
298
+ if (symbol) reactRefCreators.set(symbol.id, 'creator')
299
+ }
300
+ if (
301
+ !specifier.isTypeOnly &&
302
+ ['createElement', 'jsx', 'jsxs', 'jsxDEV'].includes(imported)
303
+ ) {
304
+ const symbol = symbols.get(specifier.name)
305
+ if (symbol) reactFactories.set(symbol.id, 'factory')
306
+ }
307
+ }
308
+ }
309
+ }
310
+ const packageName = packageFor(module)
311
+ if (packageName) {
312
+ const clause = node.importClause
313
+ if (!clause)
314
+ emit(
315
+ node,
316
+ { packageName, module, exportName: 'side-effect', typeOnly: false },
317
+ 'side-effect',
318
+ null,
319
+ null,
320
+ 'side-effect',
321
+ )
322
+ else {
323
+ const typeOnly = clause.phaseModifier === ts.SyntaxKind.TypeKeyword
324
+ if (clause.name) {
325
+ const binding = { packageName, module, exportName: 'default', typeOnly }
326
+ bind(clause.name, binding)
327
+ emit(
328
+ clause.name,
329
+ binding,
330
+ 'export',
331
+ null,
332
+ packageName === 'react-native'
333
+ ? 'namespace container; members counted at use sites'
334
+ : null,
335
+ 'default',
336
+ )
337
+ }
338
+ if (clause.namedBindings && ts.isNamespaceImport(clause.namedBindings)) {
339
+ const binding = { packageName, module, exportName: '*', typeOnly }
340
+ bind(clause.namedBindings.name, binding)
341
+ emit(
342
+ clause.namedBindings,
343
+ binding,
344
+ 'export',
345
+ null,
346
+ 'namespace container; members counted at use sites',
347
+ 'namespace',
348
+ )
349
+ } else if (clause.namedBindings) {
350
+ for (const specifier of clause.namedBindings.elements) {
351
+ const binding = {
352
+ packageName,
353
+ module,
354
+ exportName: specifier.propertyName?.text ?? specifier.name.text,
355
+ typeOnly: typeOnly || specifier.isTypeOnly,
356
+ }
357
+ bind(specifier.name, binding)
358
+ emit(specifier, binding, 'export', null, null, 'named')
359
+ }
360
+ }
361
+ }
362
+ }
363
+ }
364
+ if (
365
+ ts.isExportDeclaration(node) &&
366
+ node.moduleSpecifier &&
367
+ ts.isStringLiteralLikeNode(node.moduleSpecifier)
368
+ ) {
369
+ const module = node.moduleSpecifier.text
370
+ const packageName = packageFor(module)
371
+ if (
372
+ packageName &&
373
+ (!node.exportClause || ts.isNamespaceExport(node.exportClause))
374
+ ) {
375
+ emit(
376
+ node,
377
+ { packageName, module, exportName: '*', typeOnly: node.isTypeOnly },
378
+ 'export',
379
+ null,
380
+ null,
381
+ 're-export',
382
+ )
383
+ }
384
+ if (packageName && node.exportClause && ts.isNamedExports(node.exportClause)) {
385
+ for (const specifier of node.exportClause.elements) {
386
+ emit(
387
+ specifier,
388
+ {
389
+ packageName,
390
+ module,
391
+ exportName: specifier.propertyName?.text ?? specifier.name.text,
392
+ typeOnly: node.isTypeOnly || specifier.isTypeOnly,
393
+ },
394
+ 'export',
395
+ null,
396
+ null,
397
+ 're-export',
398
+ )
399
+ }
400
+ }
401
+ }
402
+ if (
403
+ ts.isVariableDeclaration(node) &&
404
+ node.initializer &&
405
+ ts.isCallExpression(node.initializer)
406
+ ) {
407
+ const call = node.initializer
408
+ if (
409
+ ts.isIdentifier(call.expression) &&
410
+ call.expression.text === 'require' &&
411
+ !symbols.get(call.expression) &&
412
+ call.arguments[0] &&
413
+ ts.isStringLiteralLikeNode(call.arguments[0])
414
+ ) {
415
+ const module = call.arguments[0].text
416
+ const packageName = packageFor(module)
417
+ if (packageName) {
418
+ if (node.name && ts.isIdentifier(node.name)) {
419
+ const binding = { packageName, module, exportName: '*', typeOnly: false }
420
+ bind(node.name, binding)
421
+ emit(
422
+ node.name,
423
+ binding,
424
+ 'export',
425
+ null,
426
+ 'namespace container; members counted at use sites',
427
+ 'require',
428
+ )
429
+ } else if (node.name && ts.isObjectBindingPattern(node.name)) {
430
+ for (const element of node.name.elements) {
431
+ if (!element.name) continue
432
+ if (!ts.isIdentifier(element.name)) continue
433
+ const exportName =
434
+ element.propertyName &&
435
+ (ts.isIdentifier(element.propertyName) ||
436
+ ts.isStringLiteralLikeNode(element.propertyName))
437
+ ? element.propertyName.text
438
+ : element.name.text
439
+ const binding = {
440
+ packageName,
441
+ module,
442
+ exportName: element.dotDotDotToken ? '*' : exportName,
443
+ typeOnly: false,
444
+ }
445
+ bind(element.name, binding)
446
+ emit(
447
+ element,
448
+ binding,
449
+ 'export',
450
+ null,
451
+ element.dotDotDotToken ? 'namespace rest container' : null,
452
+ 'require',
453
+ )
454
+ }
455
+ }
456
+ }
457
+ }
458
+ }
459
+ if (
460
+ ts.isCallExpression(node) &&
461
+ ts.isExpressionStatement(node.parent) &&
462
+ ts.isIdentifier(node.expression) &&
463
+ node.expression.text === 'require' &&
464
+ !symbols.get(node.expression) &&
465
+ node.arguments[0] &&
466
+ ts.isStringLiteralLikeNode(node.arguments[0])
467
+ ) {
468
+ const module = node.arguments[0].text
469
+ const packageName = packageFor(module)
470
+ if (packageName)
471
+ emit(
472
+ node,
473
+ { packageName, module, exportName: 'side-effect', typeOnly: false },
474
+ 'side-effect',
475
+ null,
476
+ null,
477
+ 'side-effect',
478
+ )
479
+ }
480
+ node.forEachChild(imports)
481
+ }
482
+ imports(source)
483
+ const namespaceModuleBindings = new Map<string, ts.Identifier[]>()
484
+ for (const [id, binding] of bindings) {
485
+ const name = bindingNames.get(id)
486
+ if (
487
+ name &&
488
+ !binding.typeOnly &&
489
+ nestedRoots.some(
490
+ (root) =>
491
+ root.module === binding.module &&
492
+ (binding.exportName === '*' || root.exportName === binding.exportName),
493
+ )
494
+ ) {
495
+ const names = namespaceModuleBindings.get(binding.module) ?? []
496
+ names.push(name)
497
+ namespaceModuleBindings.set(binding.module, names)
498
+ }
499
+ }
500
+ // namespace aliases must keep every use visible. following const aliases
501
+ // here also rejects a mutation or escape through a second local name.
502
+ function isConstDeclaration(node: ts.VariableDeclarationList): boolean {
503
+ // await using shares the const bit, so compare the full declaration kind.
504
+ return ((node.flags & ts.NodeFlags.BlockScoped) ^ ts.NodeFlags.Const) === 0
505
+ }
506
+ const safeNamespaceBindings = new Map<number, boolean>()
507
+ function safeNamespaceBinding(name: ts.Identifier): boolean {
508
+ const symbol = symbols.get(name)
509
+ if (!symbol) return false
510
+ const cached = safeNamespaceBindings.get(symbol.id)
511
+ if (cached !== undefined) return cached
512
+ safeNamespaceBindings.set(symbol.id, false)
513
+ const bindingName = bindingNames.get(symbol.id) ?? name
514
+ const declaration = valueDeclarations.get(symbol.id) ?? bindingName.parent
515
+ const local = ts.isVariableDeclaration(declaration)
516
+ if (local) {
517
+ if (
518
+ declaration.name !== bindingName ||
519
+ !ts.isVariableDeclarationList(declaration.parent) ||
520
+ !isConstDeclaration(declaration.parent) ||
521
+ (ts.isVariableStatement(declaration.parent.parent) &&
522
+ declaration.parent.parent.modifiers?.some(
523
+ (modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword,
524
+ ))
525
+ )
526
+ return false
527
+ } else if (
528
+ !(
529
+ (ts.isImportSpecifier(declaration) ||
530
+ ts.isNamespaceImport(declaration) ||
531
+ ts.isImportClause(declaration)) &&
532
+ declaration.name === bindingName
533
+ )
534
+ )
535
+ return false
536
+ for (const use of symbolUses.get(symbol.id) ?? []) {
537
+ if (use === bindingName) continue
538
+ let context = use.parent
539
+ while (ts.isQualifiedName(context)) context = context.parent
540
+ if (ts.isTypeNode(context)) continue
541
+ if (local && use.getStart(source) < declaration.end) return false
542
+ let access: ts.Node = use
543
+ while (
544
+ (ts.isPropertyAccessExpression(access.parent) ||
545
+ ts.isElementAccessExpression(access.parent)) &&
546
+ access.parent.expression === access
547
+ ) {
548
+ if (memberKey(access.parent) === null || access.parent.questionDotToken)
549
+ return false
550
+ access = access.parent
551
+ }
552
+ const parent = access.parent
553
+ if (ts.isVariableDeclaration(parent) && parent.initializer === access) {
554
+ if (!ts.isIdentifier(parent.name) || !safeNamespaceBinding(parent.name))
555
+ return false
556
+ continue
557
+ }
558
+ if (
559
+ ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) &&
560
+ parent.tagName === access) ||
561
+ (ts.isCallExpression(parent) &&
562
+ parent.expression === access &&
563
+ !parent.questionDotToken) ||
564
+ (access !== use && ts.isExpressionStatement(parent))
565
+ )
566
+ continue
567
+ return false
568
+ }
569
+ safeNamespaceBindings.set(symbol.id, true)
570
+ return true
571
+ }
572
+ const safeNamespaceModules = new Map(
573
+ [...namespaceModuleBindings].map(([module, names]) => [
574
+ module,
575
+ names.every(safeNamespaceBinding),
576
+ ]),
577
+ )
578
+ function aliases(node: ts.Node): void {
579
+ if (
580
+ ts.isVariableDeclaration(node) &&
581
+ node.initializer &&
582
+ ts.isVariableDeclarationList(node.parent) &&
583
+ isConstDeclaration(node.parent)
584
+ ) {
585
+ const owner = bindingFor(node.initializer, true)
586
+ let root: ts.Node = node.initializer
587
+ while (ts.isPropertyAccessExpression(root) || ts.isElementAccessExpression(root))
588
+ root = root.expression
589
+ if (
590
+ owner &&
591
+ node.name &&
592
+ ts.isObjectBindingPattern(node.name) &&
593
+ owner.exportName === '*'
594
+ ) {
595
+ for (const element of node.name.elements) {
596
+ if (!element.name) continue
597
+ if (!ts.isIdentifier(element.name)) continue
598
+ const exportName =
599
+ element.propertyName &&
600
+ (ts.isIdentifier(element.propertyName) ||
601
+ ts.isStringLiteralLikeNode(element.propertyName))
602
+ ? element.propertyName.text
603
+ : element.name.text
604
+ const binding = {
605
+ ...owner,
606
+ exportName: element.dotDotDotToken ? '*' : exportName,
607
+ }
608
+ bind(element.name, binding)
609
+ emit(
610
+ element,
611
+ binding,
612
+ 'export',
613
+ null,
614
+ element.dotDotDotToken ? 'namespace rest container' : null,
615
+ 'namespace',
616
+ )
617
+ }
618
+ } else if (
619
+ owner &&
620
+ node.name &&
621
+ ts.isIdentifier(node.name) &&
622
+ (!nestedRoots.some(
623
+ (root) =>
624
+ root.module === owner.module && root.exportName === owner.exportName,
625
+ ) ||
626
+ (safeNamespaceBinding(node.name) &&
627
+ ts.isIdentifier(root) &&
628
+ safeNamespaceBinding(root) &&
629
+ safeNamespaceModules.get(owner.module)))
630
+ ) {
631
+ bind(node.name, owner)
632
+ emit(
633
+ node.name,
634
+ owner,
635
+ 'export',
636
+ null,
637
+ 'local alias container; imported API counted at its declaration',
638
+ null,
639
+ )
640
+ }
641
+ }
642
+ node.forEachChild(aliases)
643
+ }
644
+ aliases(source)
645
+ // a const React ref whose every use is lexically visible binds its
646
+ // `.current` method calls to the one package component it is passed to as
647
+ // `ref={name}`. any other use (another target, an unbound or wrapper tag, a
648
+ // write, a computed access, an alias, a call argument) leaves it unknown.
649
+ function refMethods(): void {
650
+ const creates = (init: ts.Expression): boolean => {
651
+ const callee = ts.isCallExpression(init) ? init.expression : undefined
652
+ if (!callee) return false
653
+ if (ts.isIdentifier(callee)) {
654
+ const symbol = symbols.get(callee)
655
+ return symbol !== undefined && reactRefCreators.get(symbol.id) === 'creator'
656
+ }
657
+ if (
658
+ ts.isPropertyAccessExpression(callee) &&
659
+ ts.isIdentifier(callee.expression) &&
660
+ (callee.name.text === 'useRef' || callee.name.text === 'createRef')
661
+ ) {
662
+ const symbol = symbols.get(callee.expression)
663
+ return symbol !== undefined && reactRefCreators.get(symbol.id) === 'container'
664
+ }
665
+ return false
666
+ }
667
+ type RefUse = {
668
+ binding?: SourceBinding
669
+ invalid: boolean
670
+ sites: ts.Node[]
671
+ }
672
+ const refs = new Map<number, RefUse>()
673
+ for (const identifier of identifiers) {
674
+ const declaration = identifier.parent
675
+ if (
676
+ ts.isVariableDeclaration(declaration) &&
677
+ declaration.name === identifier &&
678
+ declaration.initializer &&
679
+ ts.isVariableDeclarationList(declaration.parent) &&
680
+ isConstDeclaration(declaration.parent) &&
681
+ creates(declaration.initializer)
682
+ ) {
683
+ const symbol = symbols.get(identifier)
684
+ if (symbol) refs.set(symbol.id, { invalid: false, sites: [] })
685
+ }
686
+ }
687
+ if (refs.size === 0) return
688
+ const effectiveRefs = new Map<ts.JsxAttributes, ts.JsxAttribute | null>()
689
+ for (const identifier of identifiers) {
690
+ const symbol = symbols.get(identifier)
691
+ const use = symbol ? refs.get(symbol.id) : undefined
692
+ if (!use || use.invalid) continue
693
+ const parent = identifier.parent
694
+ if (ts.isVariableDeclaration(parent) && parent.name === identifier) continue
695
+ if (
696
+ ts.isJsxExpression(parent) &&
697
+ parent.expression === identifier &&
698
+ ts.isJsxAttribute(parent.parent) &&
699
+ ts.isIdentifier(parent.parent.name) &&
700
+ parent.parent.name.text === 'ref' &&
701
+ ts.isJsxAttributes(parent.parent.parent) &&
702
+ ts.isJsxOpeningLikeElement(parent.parent.parent.parent)
703
+ ) {
704
+ const attributes = parent.parent.parent
705
+ let effective = effectiveRefs.get(attributes)
706
+ if (effective === undefined) {
707
+ effective = null
708
+ for (const attribute of attributes.properties) {
709
+ if (ts.isJsxSpreadAttribute(attribute)) {
710
+ // a later spread can replace ref. only a literal whose own
711
+ // keys are all known and exclude ref is transparent here.
712
+ if (
713
+ !ts.isObjectLiteralExpression(attribute.expression) ||
714
+ !attribute.expression.properties.every((property) => {
715
+ if (ts.isSpreadAssignment(property)) return false
716
+ const name = key(property.name)
717
+ return name !== null && name !== 'ref'
718
+ })
719
+ )
720
+ effective = null
721
+ } else if (ts.isIdentifier(attribute.name) && attribute.name.text === 'ref')
722
+ effective = attribute
723
+ }
724
+ effectiveRefs.set(attributes, effective)
725
+ }
726
+ const binding = bindingFor(parent.parent.parent.parent.tagName)
727
+ if (
728
+ effective !== parent.parent ||
729
+ !binding ||
730
+ binding.typeOnly ||
731
+ (use.binding &&
732
+ (use.binding.module !== binding.module ||
733
+ use.binding.exportName !== binding.exportName))
734
+ )
735
+ use.invalid = true
736
+ else use.binding = binding
737
+ continue
738
+ }
739
+ // the only other accepted use is a static method call on `.current`
740
+ if (
741
+ ts.isPropertyAccessExpression(parent) &&
742
+ parent.expression === identifier &&
743
+ parent.name.text === 'current'
744
+ ) {
745
+ const method = parent.parent
746
+ if (
747
+ (ts.isPropertyAccessExpression(method) ||
748
+ ts.isElementAccessExpression(method)) &&
749
+ method.expression === parent &&
750
+ memberKey(method) !== null &&
751
+ ts.isCallExpression(method.parent) &&
752
+ method.parent.expression === method
753
+ ) {
754
+ use.sites.push(method)
755
+ continue
756
+ }
757
+ }
758
+ use.invalid = true
759
+ }
760
+ for (const use of refs.values()) {
761
+ if (use.invalid || !use.binding) continue
762
+ for (const site of use.sites) {
763
+ const member = memberKey(site)
764
+ if (member !== null) emit(site, use.binding, 'member', member)
765
+ }
766
+ }
767
+ }
768
+ refMethods()
769
+ function key(name: ts.PropertyName): string | null {
770
+ return ts.isIdentifier(name) ||
771
+ ts.isStringLiteralLikeNode(name) ||
772
+ ts.isNumericLiteral(name)
773
+ ? name.text
774
+ : null
775
+ }
776
+ function factoryBinding(node: ts.CallExpression): SourceBinding | undefined {
777
+ if (
778
+ !node.arguments[0] ||
779
+ !node.arguments[1] ||
780
+ !ts.isObjectLiteralExpression(node.arguments[1])
781
+ )
782
+ return undefined
783
+ const callee = ts.isPropertyAccessExpression(node.expression)
784
+ ? node.expression.expression
785
+ : node.expression
786
+ const symbol = ts.isIdentifier(callee) ? symbols.get(callee) : undefined
787
+ const factoryKind = symbol ? reactFactories.get(symbol.id) : undefined
788
+ if (
789
+ factoryKind !== 'factory' &&
790
+ !(
791
+ factoryKind === 'container' &&
792
+ ts.isPropertyAccessExpression(node.expression) &&
793
+ ['createElement', 'jsx', 'jsxs', 'jsxDEV'].includes(node.expression.name.text)
794
+ )
795
+ )
796
+ return undefined
797
+ const binding = bindingFor(node.arguments[0])
798
+ return binding && !binding.typeOnly ? binding : undefined
799
+ }
800
+ // const does not freeze an object. every alias, containing array and
801
+ // spread copy must keep all its uses inside visible package inputs.
802
+ function transparentStyleSyntax(node: ts.Node) {
803
+ return (
804
+ ts.isParenthesizedExpression(node) ||
805
+ ts.isAsExpression(node) ||
806
+ ts.isTypeAssertion(node) ||
807
+ ts.isNonNullExpression(node) ||
808
+ ts.isSatisfiesExpression(node)
809
+ )
810
+ }
811
+ const safeStyleBindings = new Map<number, boolean>()
812
+ function safeStyleBinding(name: ts.Identifier): boolean {
813
+ const symbol = symbols.get(name)
814
+ if (!symbol) return false
815
+ const cached = safeStyleBindings.get(symbol.id)
816
+ if (cached !== undefined) return cached
817
+ safeStyleBindings.set(symbol.id, false)
818
+ const declaration = valueDeclarations.get(symbol.id)
819
+ if (
820
+ !declaration ||
821
+ !ts.isVariableDeclaration(declaration) ||
822
+ !ts.isIdentifier(declaration.name) ||
823
+ !declaration.initializer ||
824
+ !ts.isVariableDeclarationList(declaration.parent) ||
825
+ !isConstDeclaration(declaration.parent) ||
826
+ (ts.isVariableStatement(declaration.parent.parent) &&
827
+ declaration.parent.parent.modifiers?.some(
828
+ (modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword,
829
+ ))
830
+ )
831
+ return false
832
+ for (const use of symbolUses.get(symbol.id) ?? []) {
833
+ if (use === declaration.name) continue
834
+ let context = use.parent
835
+ while (ts.isQualifiedName(context)) context = context.parent
836
+ if (ts.isTypeNode(context)) continue
837
+ if (use.getStart(source) < declaration.end || !safeStyleUse(use)) return false
838
+ }
839
+ safeStyleBindings.set(symbol.id, true)
840
+ return true
841
+ }
842
+ function safeStyleUse(use: ts.Expression): boolean {
843
+ let value = use
844
+ while (true) {
845
+ const parent = value.parent
846
+ if (transparentStyleSyntax(parent) || ts.isArrayLiteralExpression(parent))
847
+ value = parent
848
+ else if (
849
+ ts.isSpreadAssignment(parent) &&
850
+ parent.expression === value &&
851
+ ts.isObjectLiteralExpression(parent.parent)
852
+ )
853
+ value = parent.parent
854
+ else if (
855
+ (ts.isPropertyAccessExpression(parent) ||
856
+ ts.isElementAccessExpression(parent)) &&
857
+ parent.expression === value &&
858
+ !parent.questionDotToken &&
859
+ memberKey(parent) !== null
860
+ )
861
+ value = parent
862
+ else break
863
+ }
864
+ const parent = value.parent
865
+ if (ts.isVariableDeclaration(parent) && parent.initializer === value)
866
+ return ts.isIdentifier(parent.name) && safeStyleBinding(parent.name)
867
+ if (
868
+ ts.isJsxSpreadAttribute(parent) &&
869
+ parent.expression === value &&
870
+ ts.isJsxAttributes(parent.parent) &&
871
+ ts.isJsxOpeningLikeElement(parent.parent.parent)
872
+ ) {
873
+ const binding = bindingFor(parent.parent.parent.tagName)
874
+ return binding !== undefined && !binding.typeOnly
875
+ }
876
+ if (
877
+ ts.isObjectLiteralExpression(value) &&
878
+ ts.isCallExpression(parent) &&
879
+ parent.arguments[1] === value
880
+ )
881
+ return factoryBinding(parent) !== undefined
882
+ if (
883
+ ts.isJsxExpression(parent) &&
884
+ parent.expression === value &&
885
+ ts.isJsxAttribute(parent.parent) &&
886
+ ts.isIdentifier(parent.parent.name) &&
887
+ parent.parent.name.text === 'style' &&
888
+ ts.isJsxAttributes(parent.parent.parent) &&
889
+ ts.isJsxOpeningLikeElement(parent.parent.parent.parent)
890
+ ) {
891
+ const binding = bindingFor(parent.parent.parent.parent.tagName)
892
+ return binding !== undefined && !binding.typeOnly
893
+ }
894
+ if (
895
+ ((ts.isPropertyAssignment(parent) && parent.initializer === value) ||
896
+ (ts.isShorthandPropertyAssignment(parent) && parent.name === value)) &&
897
+ key(parent.name) === 'style' &&
898
+ ts.isObjectLiteralExpression(parent.parent) &&
899
+ ts.isCallExpression(parent.parent.parent) &&
900
+ parent.parent.parent.arguments[1] === parent.parent
901
+ )
902
+ return factoryBinding(parent.parent.parent) !== undefined
903
+ return false
904
+ }
905
+ const styleBindingObjects = new Map<
906
+ number,
907
+ Map<string, ts.ObjectLiteralExpression[]>
908
+ >()
909
+ const styleObjectProperties = new Map<
910
+ ts.ObjectLiteralExpression,
911
+ Map<string, ts.Expression> | null
912
+ >()
913
+ function styleObjects(
914
+ node: ts.Expression,
915
+ site?: ts.Expression,
916
+ members: readonly string[] = [],
917
+ allowArrays = true,
918
+ ): { node: ts.ObjectLiteralExpression; site?: ts.Expression }[] {
919
+ if (transparentStyleSyntax(node))
920
+ return styleObjects(node.expression, site, members, allowArrays)
921
+ if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
922
+ const member = memberKey(node)
923
+ return member !== null && !node.questionDotToken
924
+ ? styleObjects(node.expression, site ?? node, [member, ...members], allowArrays)
925
+ : []
926
+ }
927
+ if (ts.isObjectLiteralExpression(node)) {
928
+ // accessors, spreads and computed names can hide effects or identity.
929
+ // direct literals retain their existing candidate path.
930
+ if (site || members.length > 0) {
931
+ let properties = styleObjectProperties.get(node)
932
+ if (properties === undefined) {
933
+ properties = new Map<string, ts.Expression>()
934
+ for (const property of node.properties) {
935
+ if (
936
+ !(
937
+ ts.isPropertyAssignment(property) ||
938
+ ts.isShorthandPropertyAssignment(property)
939
+ )
940
+ ) {
941
+ properties = null
942
+ break
943
+ }
944
+ const name = key(property.name)
945
+ const expression = propertyExpression(property)
946
+ if (name === null || expression === null) {
947
+ properties = null
948
+ break
949
+ }
950
+ properties.set(name, expression)
951
+ }
952
+ styleObjectProperties.set(node, properties)
953
+ }
954
+ if (!properties) return []
955
+ if (members.length > 0) {
956
+ // __proto__ in an object initializer changes its prototype; it is
957
+ // not an own data property whose value we can follow.
958
+ const value =
959
+ members[0] === '__proto__' ? undefined : properties.get(members[0])
960
+ return value ? styleObjects(value, site, members.slice(1), allowArrays) : []
961
+ }
962
+ }
963
+ return [{ node, site }]
964
+ }
965
+ if (ts.isArrayLiteralExpression(node)) {
966
+ if (!allowArrays || members.length > 0) return []
967
+ const objects = node.elements.flatMap((element) => styleObjects(element, site))
968
+ const seen = new Map<ts.Node | undefined, Set<ts.Node>>()
969
+ return objects.filter((object) => {
970
+ const nodes = seen.get(object.site) ?? new Set<ts.Node>()
971
+ if (nodes.has(object.node)) return false
972
+ nodes.add(object.node)
973
+ seen.set(object.site, nodes)
974
+ return true
975
+ })
976
+ }
977
+ if (ts.isIdentifier(node) && safeStyleBinding(node)) {
978
+ const symbol = symbols.get(node)
979
+ const declaration = symbol ? valueDeclarations.get(symbol.id) : undefined
980
+ if (
981
+ symbol &&
982
+ declaration &&
983
+ ts.isVariableDeclaration(declaration) &&
984
+ declaration.initializer
985
+ ) {
986
+ let paths = styleBindingObjects.get(symbol.id)
987
+ if (!paths) {
988
+ paths = new Map()
989
+ styleBindingObjects.set(symbol.id, paths)
990
+ }
991
+ const path = JSON.stringify([allowArrays, members])
992
+ let objects = paths.get(path)
993
+ if (!objects) {
994
+ paths.set(path, [])
995
+ objects = styleObjects(
996
+ declaration.initializer,
997
+ node,
998
+ members,
999
+ allowArrays,
1000
+ ).map((value) => value.node)
1001
+ paths.set(path, objects)
1002
+ }
1003
+ return objects.map((value) => ({ node: value, site: site ?? node }))
1004
+ }
1005
+ }
1006
+ return []
1007
+ }
1008
+ function staticValue(expression: ts.Expression): StaticValue | null {
1009
+ if (
1010
+ ts.isParenthesizedExpression(expression) ||
1011
+ ts.isAsExpression(expression) ||
1012
+ ts.isSatisfiesExpression(expression) ||
1013
+ ts.isNonNullExpression(expression)
1014
+ )
1015
+ return staticValue(expression.expression)
1016
+ if (ts.isStringLiteralLikeNode(expression)) return expression.text
1017
+ if (ts.isNumericLiteral(expression)) return Number(expression.text)
1018
+ if (expression.kind === ts.SyntaxKind.TrueKeyword) return true
1019
+ if (expression.kind === ts.SyntaxKind.FalseKeyword) return false
1020
+ if (
1021
+ ts.isPrefixUnaryExpression(expression) &&
1022
+ expression.operator === ts.SyntaxKind.MinusToken &&
1023
+ ts.isNumericLiteral(expression.operand)
1024
+ )
1025
+ return -Number(expression.operand.text)
1026
+ return null
1027
+ }
1028
+ function propertyExpression(
1029
+ property: ts.ObjectLiteralElementLike,
1030
+ ): ts.Expression | null {
1031
+ if (ts.isPropertyAssignment(property)) return property.initializer
1032
+ return ts.isShorthandPropertyAssignment(property) && ts.isIdentifier(property.name)
1033
+ ? property.name
1034
+ : null
1035
+ }
1036
+ function propertyValue(property: ts.ObjectLiteralElementLike): StaticValue | null {
1037
+ return ts.isPropertyAssignment(property) ? staticValue(property.initializer) : null
1038
+ }
1039
+ function attributeValue(attribute: ts.JsxAttribute): StaticValue | null {
1040
+ const initializer = attribute.initializer
1041
+ if (!initializer) return true
1042
+ if (ts.isStringLiteralLikeNode(initializer)) return initializer.text
1043
+ return ts.isJsxExpression(initializer) && initializer.expression
1044
+ ? staticValue(initializer.expression)
1045
+ : null
1046
+ }
1047
+ function spread(
1048
+ expression: ts.Expression,
1049
+ site: ts.Node,
1050
+ binding: SourceBinding,
1051
+ kind: 'prop' | 'style' = 'prop',
1052
+ ): void {
1053
+ const value = ts.isObjectLiteralExpression(expression)
1054
+ ? expression
1055
+ : (styleObjects(expression, expression, [], false)[0]?.node ?? null)
1056
+ emit(
1057
+ site,
1058
+ binding,
1059
+ 'spread',
1060
+ null,
1061
+ value ? 'static spread container; properties counted separately' : null,
1062
+ )
1063
+ if (value)
1064
+ for (const property of value.properties) {
1065
+ emit(
1066
+ site,
1067
+ binding,
1068
+ ts.isSpreadAssignment(property) ? 'spread' : kind,
1069
+ ts.isSpreadAssignment(property) ? null : key(property.name),
1070
+ null,
1071
+ null,
1072
+ property.getStart(source),
1073
+ ts.isSpreadAssignment(property) ? null : propertyValue(property),
1074
+ )
1075
+ }
1076
+ }
1077
+ function object(
1078
+ node: ts.ObjectLiteralExpression,
1079
+ binding: SourceBinding,
1080
+ kind: 'prop' | 'style',
1081
+ site?: ts.Expression,
1082
+ ): void {
1083
+ for (const property of node.properties) {
1084
+ if (ts.isSpreadAssignment(property))
1085
+ spread(property.expression, property, binding, kind)
1086
+ else {
1087
+ const name = key(property.name)
1088
+ emit(
1089
+ site ?? property,
1090
+ binding,
1091
+ kind,
1092
+ name,
1093
+ null,
1094
+ null,
1095
+ site ? property.getStart(source) : null,
1096
+ propertyValue(property),
1097
+ )
1098
+ const value =
1099
+ kind === 'prop' && name === 'style' ? propertyExpression(property) : null
1100
+ if (value) {
1101
+ for (const style of styleObjects(value))
1102
+ object(
1103
+ style.node,
1104
+ {
1105
+ ...binding,
1106
+ exportName:
1107
+ binding.packageName === 'react-native'
1108
+ ? 'StyleSheet'
1109
+ : binding.exportName,
1110
+ },
1111
+ 'style',
1112
+ style.site,
1113
+ )
1114
+ }
1115
+ }
1116
+ }
1117
+ }
1118
+ function visit(node: ts.Node): void {
1119
+ const chain = nestedChain(node)
1120
+ if (chain) {
1121
+ const parent = node.parent
1122
+ // only the longest static chain is a reference; its prefixes are not
1123
+ if (
1124
+ !(
1125
+ (ts.isPropertyAccessExpression(parent) ||
1126
+ ts.isElementAccessExpression(parent)) &&
1127
+ parent.expression === node &&
1128
+ memberKey(parent) !== null
1129
+ )
1130
+ )
1131
+ emit(node, chain.binding, 'member', chain.names.join('.'))
1132
+ } else if (
1133
+ ts.isPropertyAccessExpression(node) ||
1134
+ ts.isElementAccessExpression(node)
1135
+ ) {
1136
+ const owner = bindingFor(node.expression)
1137
+ if (owner && !owner.typeOnly) {
1138
+ const member = ts.isPropertyAccessExpression(node)
1139
+ ? node.name.text
1140
+ : node.argumentExpression &&
1141
+ ts.isStringLiteralLikeNode(node.argumentExpression)
1142
+ ? node.argumentExpression.text
1143
+ : null
1144
+ const namespace =
1145
+ owner.exportName === '*' ||
1146
+ (owner.exportName === 'default' && owner.packageName === 'react-native')
1147
+ emit(
1148
+ node,
1149
+ namespace && member ? { ...owner, exportName: member } : owner,
1150
+ namespace && member ? 'export' : 'member',
1151
+ namespace && member ? null : member,
1152
+ )
1153
+ }
1154
+ }
1155
+ if (ts.isJsxOpeningLikeElement(node)) {
1156
+ const binding = bindingFor(node.tagName)
1157
+ if (binding && !binding.typeOnly) {
1158
+ for (const attribute of node.attributes.properties) {
1159
+ if (ts.isJsxSpreadAttribute(attribute))
1160
+ spread(attribute.expression, attribute, binding)
1161
+ else {
1162
+ const name = ts.isIdentifier(attribute.name) ? attribute.name.text : null
1163
+ emit(
1164
+ attribute,
1165
+ binding,
1166
+ 'prop',
1167
+ name,
1168
+ null,
1169
+ null,
1170
+ null,
1171
+ attributeValue(attribute),
1172
+ )
1173
+ if (
1174
+ name === 'style' &&
1175
+ attribute.initializer &&
1176
+ ts.isJsxExpression(attribute.initializer) &&
1177
+ attribute.initializer.expression
1178
+ ) {
1179
+ for (const style of styleObjects(attribute.initializer.expression))
1180
+ object(
1181
+ style.node,
1182
+ {
1183
+ ...binding,
1184
+ exportName:
1185
+ binding.packageName === 'react-native'
1186
+ ? 'StyleSheet'
1187
+ : binding.exportName,
1188
+ },
1189
+ 'style',
1190
+ style.site,
1191
+ )
1192
+ }
1193
+ }
1194
+ }
1195
+ }
1196
+ }
1197
+ if (
1198
+ ts.isCallExpression(node) &&
1199
+ node.arguments[0] &&
1200
+ node.arguments[1] &&
1201
+ ts.isObjectLiteralExpression(node.arguments[1])
1202
+ ) {
1203
+ const binding = factoryBinding(node)
1204
+ if (binding) object(node.arguments[1], binding, 'prop')
1205
+ }
1206
+ if (
1207
+ ts.isCallExpression(node) &&
1208
+ ts.isPropertyAccessExpression(node.expression) &&
1209
+ node.expression.name.text === 'create' &&
1210
+ bindingFor(node.expression.expression)?.exportName === 'StyleSheet' &&
1211
+ bindingFor(node.expression.expression)?.packageName === 'react-native' &&
1212
+ node.arguments[0] &&
1213
+ ts.isObjectLiteralExpression(node.arguments[0])
1214
+ ) {
1215
+ const binding = bindingFor(node.expression.expression)
1216
+ if (binding)
1217
+ for (const rule of node.arguments[0].properties) {
1218
+ if (
1219
+ ts.isPropertyAssignment(rule) &&
1220
+ ts.isObjectLiteralExpression(rule.initializer)
1221
+ )
1222
+ object(rule.initializer, binding, 'style')
1223
+ }
1224
+ }
1225
+ node.forEachChild(visit)
1226
+ }
1227
+ visit(source)
1228
+ return [...candidates.values()].sort(
1229
+ (a, b) => a.start - b.start || a.id.localeCompare(b.id),
1230
+ )
1231
+ })
1232
+ }
1233
+
1234
+ export const EXCLUDED_SOURCE_DIRECTORIES = new Set([
1235
+ '.git',
1236
+ '.expo',
1237
+ '.next',
1238
+ '.storybook',
1239
+ 'carthage',
1240
+ 'pods',
1241
+ 'android',
1242
+ 'ios',
1243
+ 'artifacts',
1244
+ 'build',
1245
+ 'coverage',
1246
+ 'dist',
1247
+ 'node_modules',
1248
+ 'vendor',
1249
+ '__tests__',
1250
+ '__e2e__',
1251
+ '__mocks__',
1252
+ 'fixtures',
1253
+ '__fixtures__',
1254
+ 'test',
1255
+ 'testing',
1256
+ 'tests',
1257
+ 'e2e',
1258
+ 'stories',
1259
+ 'storybook',
1260
+ 'doc',
1261
+ 'docs',
1262
+ 'example',
1263
+ 'examples',
1264
+ 'samples',
1265
+ 'website',
1266
+ 'scripts',
1267
+ 'tools',
1268
+ '__generated__',
1269
+ ])
1270
+
1271
+ export function capabilitySourceExclusion(
1272
+ path: string,
1273
+ sourceRoots: readonly string[],
1274
+ mode = '100644',
1275
+ ): string | null {
1276
+ if (mode === '120000') return 'symbolic link'
1277
+ const sourceRoot = sourceRoots.find(
1278
+ (root) => root === '.' || path === root || path.startsWith(`${root}/`),
1279
+ )
1280
+ if (!sourceRoot) return 'outside application source roots'
1281
+ const relativePath = sourceRoot === '.' ? path : path.slice(sourceRoot.length + 1)
1282
+ if (
1283
+ relativePath
1284
+ .split('/')
1285
+ .slice(0, -1)
1286
+ .some((part) => EXCLUDED_SOURCE_DIRECTORIES.has(part.toLowerCase()))
1287
+ )
1288
+ return 'dependency, generated output, test, documentation, tool, or bundled sample directory'
1289
+ if (/\.d\.[cm]?ts$/.test(path)) return 'declaration-only source'
1290
+ if (
1291
+ /(?:^|[./_-])(?:test|spec|stories|story|fixture|mock)(?:[./_-]|$)/i.test(relativePath)
1292
+ )
1293
+ return 'test, fixture, mock, or story source'
1294
+ if (/(?:^|\/)(?:jest[.-]|.*\.config\.)/.test(relativePath)) return 'tool configuration'
1295
+ return null
1296
+ }