@cornerstonejs/codemods 5.19.3 → 6.0.0-beta.0

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 (349) hide show
  1. package/README.md +23 -0
  2. package/package.json +2 -2
  3. package/registry/cornerstone3d/6/README.md +87 -0
  4. package/registry/cornerstone3d/6/classes-and-types/README.md +113 -0
  5. package/registry/cornerstone3d/6/classes-and-types/codemod.yaml +20 -0
  6. package/registry/cornerstone3d/6/classes-and-types/scripts/classes-and-types.ts +1461 -0
  7. package/registry/cornerstone3d/6/classes-and-types/scripts/lib.ts +2386 -0
  8. package/registry/cornerstone3d/6/classes-and-types/tests/tsx/edge-namespace-and-reported/expected.tsx +27 -0
  9. package/registry/cornerstone3d/6/classes-and-types/tests/tsx/edge-namespace-and-reported/input.tsx +27 -0
  10. package/registry/cornerstone3d/6/classes-and-types/tests/tsx/edge-namespace-and-reported/metrics.json +36 -0
  11. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/edge-already-6/expected.ts +15 -0
  12. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/edge-already-6/input.ts +15 -0
  13. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/negative-other-packages/expected.ts +11 -0
  14. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/negative-other-packages/input.ts +11 -0
  15. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-3d-family-of-predicate-or-cast-object/expected.ts +55 -0
  16. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-3d-family-of-predicate-or-cast-object/input.ts +51 -0
  17. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-3d-family-of-predicate-or-cast-object/metrics.json +36 -0
  18. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-types-from-the-types-subpath/expected.ts +26 -0
  19. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-types-from-the-types-subpath/input.ts +26 -0
  20. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-types-from-the-types-subpath/metrics.json +52 -0
  21. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-3d-evidence/expected.ts +34 -0
  22. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-3d-evidence/input.ts +30 -0
  23. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-3d-evidence/metrics.json +12 -0
  24. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-classes/expected.ts +35 -0
  25. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-classes/input.ts +35 -0
  26. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-classes/metrics.json +28 -0
  27. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-types-and-casts/expected.ts +46 -0
  28. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-types-and-casts/input.ts +42 -0
  29. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-class-import-cleanup-orphans-shorthand/expected.ts +4 -0
  30. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-class-import-cleanup-orphans-shorthand/input.ts +4 -0
  31. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-class-import-cleanup-orphans-shorthand/metrics.json +12 -0
  32. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-check-can-prevent-the-first-mount/expected.ts +24 -0
  33. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-check-can-prevent-the-first-mount/input.ts +25 -0
  34. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-check-can-prevent-the-first-mount/metrics.json +38 -0
  35. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-replacement-inverts-comparison/expected.ts +11 -0
  36. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-replacement-inverts-comparison/input.ts +11 -0
  37. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-replacement-inverts-comparison/metrics.json +20 -0
  38. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-negative-3d-test-taken-as-3d-viewport/expected.ts +29 -0
  39. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-negative-3d-test-taken-as-3d-viewport/input.ts +29 -0
  40. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-negative-3d-test-taken-as-3d-viewport/metrics.json +20 -0
  41. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-re-exports-of-removed-classes/expected.ts +6 -0
  42. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-re-exports-of-removed-classes/input.ts +6 -0
  43. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-re-exports-of-removed-classes/metrics.json +20 -0
  44. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-type-only-namespace-used-as-value/expected.ts +8 -0
  45. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-type-only-namespace-used-as-value/input.ts +8 -0
  46. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-type-only-namespace-used-as-value/metrics.json +12 -0
  47. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-instanceof-mount-proof-crosses-shadowed-binding/expected.ts +19 -0
  48. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-instanceof-mount-proof-crosses-shadowed-binding/input.ts +19 -0
  49. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-instanceof-mount-proof-crosses-shadowed-binding/metrics.json +22 -0
  50. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-unrelated-discriminator-taken-as-3d-proof/expected.ts +40 -0
  51. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-unrelated-discriminator-taken-as-3d-proof/input.ts +40 -0
  52. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-unrelated-discriminator-taken-as-3d-proof/metrics.json +28 -0
  53. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review3-conditional-viewport-type-taken-as-3d/expected.ts +39 -0
  54. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review3-conditional-viewport-type-taken-as-3d/input.ts +38 -0
  55. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review3-conditional-viewport-type-taken-as-3d/metrics.json +20 -0
  56. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-spread-or-computed-key-overrides-viewport-type/expected.ts +76 -0
  57. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-spread-or-computed-key-overrides-viewport-type/input.ts +75 -0
  58. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-spread-or-computed-key-overrides-viewport-type/metrics.json +36 -0
  59. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-viewport-family-proved-on-another-engine/expected.ts +92 -0
  60. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-viewport-family-proved-on-another-engine/input.ts +91 -0
  61. package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-viewport-family-proved-on-another-engine/metrics.json +20 -0
  62. package/registry/cornerstone3d/6/classes-and-types/workflow.yaml +29 -0
  63. package/registry/cornerstone3d/6/codemod.yaml +19 -0
  64. package/registry/cornerstone3d/6/display-sets/README.md +173 -0
  65. package/registry/cornerstone3d/6/display-sets/codemod.yaml +20 -0
  66. package/registry/cornerstone3d/6/display-sets/scripts/display-sets.ts +965 -0
  67. package/registry/cornerstone3d/6/display-sets/scripts/lib.ts +2386 -0
  68. package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes/expected.tsx +32 -0
  69. package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes/input.tsx +32 -0
  70. package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes/metrics.json +84 -0
  71. package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes-on-a-typed-engine/expected.tsx +33 -0
  72. package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes-on-a-typed-engine/input.tsx +33 -0
  73. package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes-on-a-typed-engine/metrics.json +84 -0
  74. package/registry/cornerstone3d/6/display-sets/tests/tsx/positive-javascript/expected.js +23 -0
  75. package/registry/cornerstone3d/6/display-sets/tests/tsx/positive-javascript/input.js +17 -0
  76. package/registry/cornerstone3d/6/display-sets/tests/tsx/review-commonjs-module-gets-es-import/expected.js +10 -0
  77. package/registry/cornerstone3d/6/display-sets/tests/tsx/review-commonjs-module-gets-es-import/input.js +10 -0
  78. package/registry/cornerstone3d/6/display-sets/tests/tsx/review-commonjs-module-gets-es-import/metrics.json +12 -0
  79. package/registry/cornerstone3d/6/display-sets/tests/typescript/negative-already-6/expected.ts +20 -0
  80. package/registry/cornerstone3d/6/display-sets/tests/typescript/negative-already-6/input.ts +20 -0
  81. package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-set-volumes-for-viewports/expected.ts +27 -0
  82. package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-set-volumes-for-viewports/input.ts +27 -0
  83. package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-set-volumes-for-viewports/metrics.json +12 -0
  84. package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-stack-and-volume/expected.ts +37 -0
  85. package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-stack-and-volume/input.ts +31 -0
  86. package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-stack-and-volume/metrics.json +20 -0
  87. package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-video-and-ecg/expected.ts +15 -0
  88. package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-video-and-ecg/input.ts +15 -0
  89. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-mount-breaks-control-flow/expected.ts +26 -0
  90. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-mount-breaks-control-flow/input.ts +18 -0
  91. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-mount-breaks-control-flow/metrics.json +20 -0
  92. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-viewport-lists-and-callback-capture/expected.ts +46 -0
  93. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-viewport-lists-and-callback-capture/input.ts +21 -0
  94. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-generated-references-resolve-to-shadowing-parameter/expected.ts +23 -0
  95. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-generated-references-resolve-to-shadowing-parameter/input.ts +13 -0
  96. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-optional-mounts-become-unconditional/expected.ts +11 -0
  97. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-optional-mounts-become-unconditional/input.ts +11 -0
  98. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-optional-mounts-become-unconditional/metrics.json +28 -0
  99. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-regenerated-import-drops-comments/expected.ts +22 -0
  100. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-regenerated-import-drops-comments/input.ts +15 -0
  101. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-stack-display-set-id-reused-across-series/expected.ts +41 -0
  102. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-stack-display-set-id-reused-across-series/input.ts +16 -0
  103. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/expected.ts +11 -0
  104. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/input.ts +11 -0
  105. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/metrics.json +20 -0
  106. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-helper-binding-still-used/expected.ts +46 -0
  107. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-helper-binding-still-used/input.ts +17 -0
  108. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-helper-binding-still-used/metrics.json +20 -0
  109. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-registration-references-image-list-outside-block/expected.ts +16 -0
  110. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-registration-references-image-list-outside-block/input.ts +16 -0
  111. package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-registration-references-image-list-outside-block/metrics.json +12 -0
  112. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-bracketed-and-re-exported-data-names/expected.ts +19 -0
  113. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-bracketed-and-re-exported-data-names/input.ts +19 -0
  114. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-bracketed-and-re-exported-data-names/metrics.json +44 -0
  115. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-generic-container-taken-as-viewport/expected.ts +22 -0
  116. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-generic-container-taken-as-viewport/input.ts +22 -0
  117. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-generic-container-taken-as-viewport/metrics.json +36 -0
  118. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-image-list-getter-read-twice/expected.ts +62 -0
  119. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-image-list-getter-read-twice/input.ts +28 -0
  120. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-missing-target-partly-updates-layout/expected.ts +50 -0
  121. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-missing-target-partly-updates-layout/input.ts +25 -0
  122. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-missing-target-partly-updates-layout/metrics.json +12 -0
  123. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-reassigned-receiver-keeps-initializer-evidence/expected.ts +45 -0
  124. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-reassigned-receiver-keeps-initializer-evidence/input.ts +39 -0
  125. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-reassigned-receiver-keeps-initializer-evidence/metrics.json +36 -0
  126. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-stack-ids-collide-across-engines/expected.ts +24 -0
  127. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-stack-ids-collide-across-engines/input.ts +12 -0
  128. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-volume-registration-attaches-another-series/expected.ts +47 -0
  129. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-volume-registration-attaches-another-series/input.ts +42 -0
  130. package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-volume-registration-attaches-another-series/metrics.json +28 -0
  131. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-computed-option-key-overrides-image-ids/expected.ts +18 -0
  132. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-computed-option-key-overrides-image-ids/input.ts +18 -0
  133. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-computed-option-key-overrides-image-ids/metrics.json +12 -0
  134. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-loop-increment-taken-as-volume-creation/expected.ts +18 -0
  135. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-loop-increment-taken-as-volume-creation/input.ts +18 -0
  136. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-loop-increment-taken-as-volume-creation/metrics.json +12 -0
  137. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-mixed-family-targets-partly-update-layout/expected.ts +42 -0
  138. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-mixed-family-targets-partly-update-layout/input.ts +18 -0
  139. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-ecg-mount-empty-after-the-call/expected.ts +18 -0
  140. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-ecg-mount-empty-after-the-call/input.ts +18 -0
  141. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-ecg-mount-empty-after-the-call/metrics.json +20 -0
  142. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-helper-blocks-async-function/expected.ts +18 -0
  143. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-helper-blocks-async-function/input.ts +18 -0
  144. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-helper-blocks-async-function/metrics.json +12 -0
  145. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-stack-mount-blocks-async-function/expected.ts +19 -0
  146. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-stack-mount-blocks-async-function/input.ts +19 -0
  147. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-stack-mount-blocks-async-function/metrics.json +20 -0
  148. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-video-mount-empty-after-the-call/expected.ts +18 -0
  149. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-video-mount-empty-after-the-call/input.ts +18 -0
  150. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-video-mount-empty-after-the-call/metrics.json +20 -0
  151. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-volume-mount-blocks-async-function/expected.ts +23 -0
  152. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-volume-mount-blocks-async-function/input.ts +23 -0
  153. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-volume-mount-blocks-async-function/metrics.json +20 -0
  154. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-viewport-getter-read-three-times/expected.ts +34 -0
  155. package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-viewport-getter-read-three-times/input.ts +19 -0
  156. package/registry/cornerstone3d/6/display-sets/tests/typescript/review4-argument-getter-redirects-stack-mount/expected.ts +80 -0
  157. package/registry/cornerstone3d/6/display-sets/tests/typescript/review4-argument-getter-redirects-stack-mount/input.ts +50 -0
  158. package/registry/cornerstone3d/6/display-sets/workflow.yaml +29 -0
  159. package/registry/cornerstone3d/6/events/README.md +65 -0
  160. package/registry/cornerstone3d/6/events/codemod.yaml +20 -0
  161. package/registry/cornerstone3d/6/events/scripts/events.ts +442 -0
  162. package/registry/cornerstone3d/6/events/scripts/lib.ts +2386 -0
  163. package/registry/cornerstone3d/6/events/tests/tsx/edge-reported-and-conflicts/expected.tsx +18 -0
  164. package/registry/cornerstone3d/6/events/tests/tsx/edge-reported-and-conflicts/input.tsx +18 -0
  165. package/registry/cornerstone3d/6/events/tests/tsx/edge-reported-and-conflicts/metrics.json +46 -0
  166. package/registry/cornerstone3d/6/events/tests/typescript/negative-other-events/expected.ts +10 -0
  167. package/registry/cornerstone3d/6/events/tests/typescript/negative-other-events/input.ts +10 -0
  168. package/registry/cornerstone3d/6/events/tests/typescript/ohif-core-events-export/expected.ts +22 -0
  169. package/registry/cornerstone3d/6/events/tests/typescript/ohif-core-events-export/input.ts +22 -0
  170. package/registry/cornerstone3d/6/events/tests/typescript/ohif-core-events-export/metrics.json +54 -0
  171. package/registry/cornerstone3d/6/events/tests/typescript/positive-destructured/expected.ts +20 -0
  172. package/registry/cornerstone3d/6/events/tests/typescript/positive-destructured/input.ts +20 -0
  173. package/registry/cornerstone3d/6/events/tests/typescript/positive-destructured/metrics.json +12 -0
  174. package/registry/cornerstone3d/6/events/tests/typescript/positive-members/expected.ts +16 -0
  175. package/registry/cornerstone3d/6/events/tests/typescript/positive-members/input.ts +16 -0
  176. package/registry/cornerstone3d/6/events/tests/typescript/positive-members/metrics.json +52 -0
  177. package/registry/cornerstone3d/6/events/tests/typescript/review-aliased-event-destructuring-left-silently/expected.ts +5 -0
  178. package/registry/cornerstone3d/6/events/tests/typescript/review-aliased-event-destructuring-left-silently/input.ts +5 -0
  179. package/registry/cornerstone3d/6/events/tests/typescript/review-aliased-event-destructuring-left-silently/metrics.json +12 -0
  180. package/registry/cornerstone3d/6/events/tests/typescript/review-event-destructuring-introduces-undeclared-name/expected.ts +9 -0
  181. package/registry/cornerstone3d/6/events/tests/typescript/review-event-destructuring-introduces-undeclared-name/input.ts +10 -0
  182. package/registry/cornerstone3d/6/events/tests/typescript/review-event-destructuring-introduces-undeclared-name/metrics.json +20 -0
  183. package/registry/cornerstone3d/6/events/tests/typescript/review-removed-event-strings-not-reported/expected.ts +11 -0
  184. package/registry/cornerstone3d/6/events/tests/typescript/review-removed-event-strings-not-reported/input.ts +11 -0
  185. package/registry/cornerstone3d/6/events/tests/typescript/review-removed-event-strings-not-reported/metrics.json +28 -0
  186. package/registry/cornerstone3d/6/events/tests/typescript/review2-quoted-defaulted-and-bracketed-event-keys/expected.ts +15 -0
  187. package/registry/cornerstone3d/6/events/tests/typescript/review2-quoted-defaulted-and-bracketed-event-keys/input.ts +15 -0
  188. package/registry/cornerstone3d/6/events/tests/typescript/review2-quoted-defaulted-and-bracketed-event-keys/metrics.json +62 -0
  189. package/registry/cornerstone3d/6/events/workflow.yaml +29 -0
  190. package/registry/cornerstone3d/6/settings/README.md +69 -0
  191. package/registry/cornerstone3d/6/settings/codemod.yaml +20 -0
  192. package/registry/cornerstone3d/6/settings/scripts/lib.ts +2386 -0
  193. package/registry/cornerstone3d/6/settings/scripts/settings.ts +647 -0
  194. package/registry/cornerstone3d/6/settings/tests/tsx/edge-namespace-and-reported/expected.tsx +18 -0
  195. package/registry/cornerstone3d/6/settings/tests/tsx/edge-namespace-and-reported/input.tsx +18 -0
  196. package/registry/cornerstone3d/6/settings/tests/tsx/edge-namespace-and-reported/metrics.json +46 -0
  197. package/registry/cornerstone3d/6/settings/tests/typescript/negative-other-names/expected.ts +18 -0
  198. package/registry/cornerstone3d/6/settings/tests/typescript/negative-other-names/input.ts +18 -0
  199. package/registry/cornerstone3d/6/settings/tests/typescript/positive-configuration/expected.ts +27 -0
  200. package/registry/cornerstone3d/6/settings/tests/typescript/positive-configuration/input.ts +28 -0
  201. package/registry/cornerstone3d/6/settings/tests/typescript/positive-configuration/metrics.json +46 -0
  202. package/registry/cornerstone3d/6/settings/tests/typescript/positive-functions/expected.ts +32 -0
  203. package/registry/cornerstone3d/6/settings/tests/typescript/positive-functions/input.ts +33 -0
  204. package/registry/cornerstone3d/6/settings/tests/typescript/positive-functions/metrics.json +36 -0
  205. package/registry/cornerstone3d/6/settings/tests/typescript/review-aliased-setting-imports-removed-while-used/expected.ts +10 -0
  206. package/registry/cornerstone3d/6/settings/tests/typescript/review-aliased-setting-imports-removed-while-used/input.ts +9 -0
  207. package/registry/cornerstone3d/6/settings/tests/typescript/review-aliased-setting-imports-removed-while-used/metrics.json +22 -0
  208. package/registry/cornerstone3d/6/settings/tests/typescript/review-generated-references-resolve-to-shadowing-locals/expected.ts +12 -0
  209. package/registry/cornerstone3d/6/settings/tests/typescript/review-generated-references-resolve-to-shadowing-locals/input.ts +12 -0
  210. package/registry/cornerstone3d/6/settings/tests/typescript/review-import-name-collision-calls-undefined/expected.ts +9 -0
  211. package/registry/cornerstone3d/6/settings/tests/typescript/review-import-name-collision-calls-undefined/input.ts +9 -0
  212. package/registry/cornerstone3d/6/settings/tests/typescript/review-import-name-collision-calls-undefined/metrics.json +12 -0
  213. package/registry/cornerstone3d/6/settings/tests/typescript/review-settings-deletes-unrelated-configuration/expected.ts +12 -0
  214. package/registry/cornerstone3d/6/settings/tests/typescript/review-settings-deletes-unrelated-configuration/input.ts +12 -0
  215. package/registry/cornerstone3d/6/settings/tests/typescript/review-settings-deletes-unrelated-configuration/metrics.json +28 -0
  216. package/registry/cornerstone3d/6/settings/tests/typescript/review2-adjacent-obsolete-settings/expected.ts +24 -0
  217. package/registry/cornerstone3d/6/settings/tests/typescript/review2-adjacent-obsolete-settings/input.ts +29 -0
  218. package/registry/cornerstone3d/6/settings/tests/typescript/review2-adjacent-obsolete-settings/metrics.json +12 -0
  219. package/registry/cornerstone3d/6/settings/tests/typescript/review2-nested-cpu-getter-in-rewritten-setting/expected.ts +3 -0
  220. package/registry/cornerstone3d/6/settings/tests/typescript/review2-nested-cpu-getter-in-rewritten-setting/input.ts +3 -0
  221. package/registry/cornerstone3d/6/settings/tests/typescript/review2-nested-cpu-getter-in-rewritten-setting/metrics.json +12 -0
  222. package/registry/cornerstone3d/6/settings/tests/typescript/review2-re-exported-setting-names/expected.ts +1 -0
  223. package/registry/cornerstone3d/6/settings/tests/typescript/review2-re-exported-setting-names/input.ts +1 -0
  224. package/registry/cornerstone3d/6/settings/tests/typescript/review2-re-exported-setting-names/metrics.json +20 -0
  225. package/registry/cornerstone3d/6/settings/tests/typescript/review2-spread-boolean-tuple/expected.ts +6 -0
  226. package/registry/cornerstone3d/6/settings/tests/typescript/review2-spread-boolean-tuple/input.ts +6 -0
  227. package/registry/cornerstone3d/6/settings/tests/typescript/review2-spread-boolean-tuple/metrics.json +22 -0
  228. package/registry/cornerstone3d/6/settings/tests/typescript/review3-shorthand-cpu-setting/expected.ts +13 -0
  229. package/registry/cornerstone3d/6/settings/tests/typescript/review3-shorthand-cpu-setting/input.ts +13 -0
  230. package/registry/cornerstone3d/6/settings/tests/typescript/review3-shorthand-cpu-setting/metrics.json +12 -0
  231. package/registry/cornerstone3d/6/settings/workflow.yaml +29 -0
  232. package/registry/cornerstone3d/6/tools/README.md +59 -0
  233. package/registry/cornerstone3d/6/tools/codemod.yaml +20 -0
  234. package/registry/cornerstone3d/6/tools/scripts/lib.ts +2386 -0
  235. package/registry/cornerstone3d/6/tools/scripts/tools.ts +517 -0
  236. package/registry/cornerstone3d/6/tools/tests/tsx/edge-removed-names/expected.tsx +36 -0
  237. package/registry/cornerstone3d/6/tools/tests/tsx/edge-removed-names/input.tsx +36 -0
  238. package/registry/cornerstone3d/6/tools/tests/tsx/edge-removed-names/metrics.json +60 -0
  239. package/registry/cornerstone3d/6/tools/tests/typescript/negative-other-modules/expected.ts +13 -0
  240. package/registry/cornerstone3d/6/tools/tests/typescript/negative-other-modules/input.ts +13 -0
  241. package/registry/cornerstone3d/6/tools/tests/typescript/positive-moved-modules/expected.ts +11 -0
  242. package/registry/cornerstone3d/6/tools/tests/typescript/positive-moved-modules/input.ts +11 -0
  243. package/registry/cornerstone3d/6/tools/tests/typescript/positive-viewport-capabilities-to-core/expected.ts +13 -0
  244. package/registry/cornerstone3d/6/tools/tests/typescript/positive-viewport-capabilities-to-core/input.ts +13 -0
  245. package/registry/cornerstone3d/6/tools/tests/typescript/review-moved-import-collides-with-local/expected.ts +7 -0
  246. package/registry/cornerstone3d/6/tools/tests/typescript/review-moved-import-collides-with-local/input.ts +7 -0
  247. package/registry/cornerstone3d/6/tools/tests/typescript/review-viewport-capabilities-not-plain/expected.ts +26 -0
  248. package/registry/cornerstone3d/6/tools/tests/typescript/review-viewport-capabilities-not-plain/input.ts +26 -0
  249. package/registry/cornerstone3d/6/tools/tests/typescript/review-viewport-capabilities-not-plain/metrics.json +60 -0
  250. package/registry/cornerstone3d/6/tools/tests/typescript/review2-barrel-re-export-of-moved-module/expected.ts +6 -0
  251. package/registry/cornerstone3d/6/tools/tests/typescript/review2-barrel-re-export-of-moved-module/input.ts +6 -0
  252. package/registry/cornerstone3d/6/tools/tests/typescript/review2-barrel-re-export-of-moved-module/metrics.json +28 -0
  253. package/registry/cornerstone3d/6/tools/tests/typescript/review3-side-effect-and-empty-imports-of-deleted-module/expected.ts +12 -0
  254. package/registry/cornerstone3d/6/tools/tests/typescript/review3-side-effect-and-empty-imports-of-deleted-module/input.ts +12 -0
  255. package/registry/cornerstone3d/6/tools/tests/typescript/review3-side-effect-and-empty-imports-of-deleted-module/metrics.json +36 -0
  256. package/registry/cornerstone3d/6/tools/workflow.yaml +29 -0
  257. package/registry/cornerstone3d/6/viewport-members/README.md +101 -0
  258. package/registry/cornerstone3d/6/viewport-members/codemod.yaml +20 -0
  259. package/registry/cornerstone3d/6/viewport-members/scripts/lib.ts +2386 -0
  260. package/registry/cornerstone3d/6/viewport-members/scripts/viewport-members.ts +815 -0
  261. package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members/expected.tsx +31 -0
  262. package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members/input.tsx +31 -0
  263. package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members/metrics.json +100 -0
  264. package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members-on-a-typed-viewport/expected.tsx +31 -0
  265. package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members-on-a-typed-viewport/input.tsx +31 -0
  266. package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members-on-a-typed-viewport/metrics.json +100 -0
  267. package/registry/cornerstone3d/6/viewport-members/tests/typescript/negative-other-receivers/expected.ts +24 -0
  268. package/registry/cornerstone3d/6/viewport-members/tests/typescript/negative-other-receivers/input.ts +24 -0
  269. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-3d-presentation/expected.ts +11 -0
  270. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-3d-presentation/input.ts +11 -0
  271. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-3d-presentation/metrics.json +28 -0
  272. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-engine-render-frame-of-reference/expected.ts +16 -0
  273. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-engine-render-frame-of-reference/input.ts +16 -0
  274. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-engine-render-frame-of-reference/metrics.json +28 -0
  275. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-presentation-and-view/expected.ts +31 -0
  276. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-presentation-and-view/input.ts +31 -0
  277. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-questions-and-actors/expected.ts +31 -0
  278. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-questions-and-actors/input.ts +26 -0
  279. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-questions-and-actors/metrics.json +22 -0
  280. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-video-and-ecg/expected.ts +15 -0
  281. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-video-and-ecg/input.ts +15 -0
  282. package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-video-and-ecg/metrics.json +28 -0
  283. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-generated-imports-invalidate-file-directives/expected.ts +5 -0
  284. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-generated-imports-invalidate-file-directives/input.ts +5 -0
  285. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-generated-imports-invalidate-file-directives/metrics.json +12 -0
  286. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-quoted-presentation-key-loses-effect/expected.ts +12 -0
  287. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-quoted-presentation-key-loses-effect/input.ts +12 -0
  288. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-quoted-presentation-key-loses-effect/metrics.json +12 -0
  289. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-slice-index-rewrite-mishandles-references/expected.ts +12 -0
  290. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-slice-index-rewrite-mishandles-references/input.ts +12 -0
  291. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-slice-index-rewrite-mishandles-references/metrics.json +20 -0
  292. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/expected.ts +9 -0
  293. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/input.ts +9 -0
  294. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/metrics.json +20 -0
  295. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-bracket-access-hides-removed-methods/expected.ts +11 -0
  296. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-bracket-access-hides-removed-methods/input.ts +11 -0
  297. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-bracket-access-hides-removed-methods/metrics.json +36 -0
  298. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-re-exported-core-helpers/expected.ts +5 -0
  299. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-re-exported-core-helpers/input.ts +5 -0
  300. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-re-exported-core-helpers/metrics.json +20 -0
  301. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review3-conditional-mount-drops-presentation/expected.ts +58 -0
  302. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review3-conditional-mount-drops-presentation/input.ts +58 -0
  303. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review3-conditional-mount-drops-presentation/metrics.json +20 -0
  304. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review4-strict-bounds-and-actor-volume-ids/expected.ts +16 -0
  305. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review4-strict-bounds-and-actor-volume-ids/input.ts +16 -0
  306. package/registry/cornerstone3d/6/viewport-members/tests/typescript/review4-strict-bounds-and-actor-volume-ids/metrics.json +12 -0
  307. package/registry/cornerstone3d/6/viewport-members/workflow.yaml +29 -0
  308. package/registry/cornerstone3d/6/viewport-types/README.md +73 -0
  309. package/registry/cornerstone3d/6/viewport-types/codemod.yaml +20 -0
  310. package/registry/cornerstone3d/6/viewport-types/scripts/lib.ts +2386 -0
  311. package/registry/cornerstone3d/6/viewport-types/scripts/viewport-types.ts +714 -0
  312. package/registry/cornerstone3d/6/viewport-types/tests/tsx/edge-reported-sites/expected.tsx +57 -0
  313. package/registry/cornerstone3d/6/viewport-types/tests/tsx/edge-reported-sites/input.tsx +57 -0
  314. package/registry/cornerstone3d/6/viewport-types/tests/tsx/edge-reported-sites/metrics.json +70 -0
  315. package/registry/cornerstone3d/6/viewport-types/tests/typescript/edge-already-6/expected.ts +25 -0
  316. package/registry/cornerstone3d/6/viewport-types/tests/typescript/edge-already-6/input.ts +25 -0
  317. package/registry/cornerstone3d/6/viewport-types/tests/typescript/negative-other-names/expected.ts +22 -0
  318. package/registry/cornerstone3d/6/viewport-types/tests/typescript/negative-other-names/input.ts +22 -0
  319. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-destructured-viewport-type/expected.ts +68 -0
  320. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-destructured-viewport-type/input.ts +65 -0
  321. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-destructured-viewport-type/metrics.json +46 -0
  322. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-namespaced-and-aliased/expected.ts +20 -0
  323. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-namespaced-and-aliased/input.ts +19 -0
  324. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-namespaced-and-aliased/metrics.json +12 -0
  325. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-strings/expected.ts +25 -0
  326. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-strings/input.ts +24 -0
  327. package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-strings/metrics.json +22 -0
  328. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-destructured-viewport-type-members/expected.ts +19 -0
  329. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-destructured-viewport-type-members/input.ts +19 -0
  330. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-destructured-viewport-type-members/metrics.json +12 -0
  331. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-type-check-can-prevent-the-first-mount/expected.ts +27 -0
  332. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-type-check-can-prevent-the-first-mount/input.ts +27 -0
  333. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-type-check-can-prevent-the-first-mount/metrics.json +28 -0
  334. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/expected.ts +9 -0
  335. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/input.ts +9 -0
  336. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/metrics.json +20 -0
  337. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-type-pass-changes-unrelated-discriminators/expected.ts +18 -0
  338. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-type-pass-changes-unrelated-discriminators/input.ts +18 -0
  339. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-type-pass-changes-unrelated-discriminators/metrics.json +30 -0
  340. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-mount-proof-crosses-shadowed-binding/expected.ts +42 -0
  341. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-mount-proof-crosses-shadowed-binding/input.ts +42 -0
  342. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-mount-proof-crosses-shadowed-binding/metrics.json +36 -0
  343. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-quoted-defaulted-and-bracketed-viewport-type-keys/expected.ts +10 -0
  344. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-quoted-defaulted-and-bracketed-viewport-type-keys/input.ts +10 -0
  345. package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-quoted-defaulted-and-bracketed-viewport-type-keys/metrics.json +36 -0
  346. package/registry/cornerstone3d/6/viewport-types/workflow.yaml +29 -0
  347. package/registry/cornerstone3d/6/workflow.yaml +26 -0
  348. package/scripts/test-registry-packages.mjs +86 -0
  349. package/scripts/validate-registry-packages.mjs +43 -2
@@ -0,0 +1,1461 @@
1
+ import type { Codemod, SgRoot } from 'codemod:ast-grep';
2
+ import type TSX from 'codemod:ast-grep/langs/tsx';
3
+ import { useMetricAtom } from 'codemod:metrics';
4
+ import {
5
+ CORE_PACKAGE,
6
+ CoreImports,
7
+ EditSet,
8
+ bracketKey,
9
+ comparisonAt,
10
+ coreImportOf,
11
+ declarationNodeOf,
12
+ enclosingFunction,
13
+ importSource,
14
+ isCoreEnum,
15
+ isCoreExport,
16
+ isCoreNamespace,
17
+ isMountedBefore,
18
+ isStableBinding,
19
+ methodCall,
20
+ referencesOf as declarationReferences,
21
+ site,
22
+ stableBinding,
23
+ staticKeyName,
24
+ unwrap,
25
+ } from './lib.ts';
26
+ import type { Node } from './lib.ts';
27
+
28
+ /** Sites that the reader changes. */
29
+ const manual = useMetricAtom('cornerstone3d-6-manual');
30
+
31
+ /** Rewrites at a decision of the migration guide. */
32
+ const review = useMetricAtom('cornerstone3d-6-review');
33
+
34
+ /** The legacy classes and the class that types the same viewport in 6.0. */
35
+ const LEGACY_CLASS_TYPE: Record<string, string> = {
36
+ StackViewport: 'PlanarViewport',
37
+ VolumeViewport: 'PlanarViewport',
38
+ BaseVolumeViewport: 'PlanarViewport',
39
+ Viewport: 'GenericViewport',
40
+ };
41
+
42
+ /** The class names that 6.0 renames, deprecated aliases and the legacy 3D name. */
43
+ const RENAMED_CLASS: Record<string, string> = {
44
+ LegacyVolumeViewport3D: 'VolumeViewport3D',
45
+ GenericVolumeViewport3D: 'VolumeViewport3D',
46
+ VideoGenericViewport: 'VideoViewport',
47
+ WSIGenericViewport: 'WSIViewport',
48
+ ECGGenericViewport: 'ECGViewport',
49
+ };
50
+
51
+ /** The removed `Types` interfaces and the class that replaces each. */
52
+ const TYPES_TO_CLASS: Record<string, string> = {
53
+ IStackViewport: 'PlanarViewport',
54
+ IVolumeViewport: 'PlanarViewport',
55
+ IBaseVolumeViewport: 'PlanarViewport',
56
+ IVideoViewport: 'VideoViewport',
57
+ IWSIViewport: 'WSIViewport',
58
+ IECGViewport: 'ECGViewport',
59
+ };
60
+
61
+ /** The `Types` names that keep the namespace and change their name. */
62
+ const TYPES_RENAMED: Record<string, string> = {
63
+ IGenericViewport: 'IViewport',
64
+ };
65
+
66
+ /** The removed `Types` names that need the application. */
67
+ const TYPES_REPORTED = new Set([
68
+ 'ViewportProperties',
69
+ 'StackViewportProperties',
70
+ 'VolumeViewportProperties',
71
+ 'VideoViewportProperties',
72
+ 'WSIViewportProperties',
73
+ 'ECGViewportProperties',
74
+ 'IVolumeInput',
75
+ 'VolumeInputCallback',
76
+ 'SetAspectRatioOptions',
77
+ 'ImageSetOptions',
78
+ ]);
79
+
80
+ /** The test of the content mode that replaces an `instanceof` check. */
81
+ const INSTANCEOF_TEST: Record<
82
+ string,
83
+ (utilities: string, value: string) => string
84
+ > = {
85
+ StackViewport: (utilities, value) =>
86
+ `${utilities}.viewportIsInStackMode(${value})`,
87
+ VolumeViewport: (utilities, value) =>
88
+ `${utilities}.getViewportContentMode(${value}) === 'volume'`,
89
+ BaseVolumeViewport: (utilities, value) =>
90
+ `${utilities}.viewportIsInVolumeMode(${value})`,
91
+ };
92
+
93
+ /**
94
+ * The names that typed a 3D viewport in 5.x as well as a volume viewport:
95
+ * `IBaseVolumeViewport` and `BaseVolumeViewport` by their class, and
96
+ * `IVolumeViewport` by a cast that applications wrote for a 3D viewport.
97
+ */
98
+ const VOLUME_OR_3D = new Set([
99
+ 'IVolumeViewport',
100
+ 'IBaseVolumeViewport',
101
+ 'BaseVolumeViewport',
102
+ ]);
103
+
104
+ /** A viewport type of 3D, as code names it. */
105
+ const THREE_D_TYPE = /\bVOLUME_3D(_NEXT)?\b|['"]volume3d(Next)?['"]/;
106
+
107
+ /** A planar viewport type, as code names it after the viewport types step. */
108
+ const PLANAR_TYPE =
109
+ /\b(PLANAR(_NEXT)?|STACK|ORTHOGRAPHIC)\b|['"](planar(Next)?|stack|orthographic)['"]/;
110
+
111
+ /** The calls that give a typed rendering engine. */
112
+ const ENGINE_FACTORIES = new Set(['getRenderingEngine', 'RenderingEngine']);
113
+
114
+ /** The operators of an equality test. */
115
+ const EQUALITY = new Set(['===', '==', '!==', '!=']);
116
+
117
+ /** The statements that end a `case` without falling through. */
118
+ const CASE_ENDS = new Set([
119
+ 'break_statement',
120
+ 'return_statement',
121
+ 'throw_statement',
122
+ 'continue_statement',
123
+ ]);
124
+
125
+ /**
126
+ * The engine method that takes a viewport input object, and the one that
127
+ * takes an array literal of them.
128
+ */
129
+ const INPUT_METHOD: Record<string, string> = {
130
+ object: 'enableElement',
131
+ array: 'setViewports',
132
+ };
133
+
134
+ /**
135
+ * The expressions around a value that keep it: parentheses, casts and
136
+ * non-null assertions.
137
+ */
138
+ const KEEPING_KINDS = new Set([
139
+ 'parenthesized_expression',
140
+ 'as_expression',
141
+ 'satisfies_expression',
142
+ 'non_null_expression',
143
+ 'type_assertion',
144
+ ]);
145
+
146
+ /**
147
+ * The parents of a name that write it in another way than `name = value`:
148
+ * an operator assignment, `++` or `--`, a `for in` or `for of`, or a
149
+ * destructuring target.
150
+ */
151
+ const OTHER_WRITES = new Set([
152
+ 'augmented_assignment_expression',
153
+ 'update_expression',
154
+ 'for_in_statement',
155
+ 'object_pattern',
156
+ 'array_pattern',
157
+ 'pair_pattern',
158
+ 'assignment_pattern',
159
+ 'object_assignment_pattern',
160
+ 'rest_pattern',
161
+ ]);
162
+
163
+ /**
164
+ * What a test of the viewport type tells about the family of a node;
165
+ * `mixed` when the viewport inputs of its id give a 3D type with another, or
166
+ * a type that only the running code resolves; `unlinked` when they give a 3D
167
+ * type and none of them is shown on the engine of the `getViewport` call.
168
+ */
169
+ type Decision =
170
+ | '3d'
171
+ | 'planar'
172
+ | 'ambiguous'
173
+ | 'mixed'
174
+ | 'unlinked'
175
+ | undefined;
176
+
177
+ /**
178
+ * The state of one run of the transform on a file.
179
+ */
180
+ interface Run {
181
+ root: SgRoot<TSX>;
182
+ rootNode: Node;
183
+ imports: CoreImports;
184
+ edits: EditSet;
185
+ }
186
+
187
+ /**
188
+ * Tells whether a node lies inside an import statement.
189
+ */
190
+ function inImport(node: Node): boolean {
191
+ return node
192
+ .ancestors()
193
+ .some((ancestor) => ancestor.kind() === 'import_statement');
194
+ }
195
+
196
+ /**
197
+ * Tells whether an expression is a rendering engine with a type, so that a
198
+ * call of `getViewport` on it takes a type argument.
199
+ */
200
+ function isTypedEngine(node: Node): boolean {
201
+ const inner = unwrap(node);
202
+
203
+ if (inner.kind() === 'call_expression' || inner.kind() === 'new_expression') {
204
+ const callee = inner.field(
205
+ inner.kind() === 'call_expression' ? 'function' : 'constructor'
206
+ );
207
+
208
+ return Boolean(
209
+ callee && ENGINE_FACTORIES.has(callee.text().split('.').pop() ?? '')
210
+ );
211
+ }
212
+
213
+ if (inner.kind() !== 'identifier') {
214
+ return false;
215
+ }
216
+
217
+ const definition = inner.definition();
218
+ const target = definition?.node;
219
+
220
+ if (!target || definition.kind !== 'local') {
221
+ return false;
222
+ }
223
+
224
+ const holder = target.kind() === 'identifier' ? target.parent() : target;
225
+ const annotation = holder
226
+ ?.children()
227
+ .find((child) => child.kind() === 'type_annotation');
228
+
229
+ if (annotation) {
230
+ return /RenderingEngine\b/.test(annotation.text());
231
+ }
232
+
233
+ if (holder?.kind() === 'variable_declarator') {
234
+ const value = holder.field('value');
235
+
236
+ return Boolean(value && isTypedEngine(value));
237
+ }
238
+
239
+ return false;
240
+ }
241
+
242
+ /**
243
+ * Returns the key of the binding that a name refers to, when that binding
244
+ * holds one value for its whole scope, or undefined.
245
+ */
246
+ function bindingKey(node: Node | null | undefined): string | undefined {
247
+ const inner = node ? unwrap(node) : undefined;
248
+ const kind = inner?.kind() ?? '';
249
+ const binding =
250
+ kind === 'identifier' || kind === 'shorthand_property_identifier'
251
+ ? stableBinding(inner)
252
+ : undefined;
253
+
254
+ return binding ? `binding:${binding.range().start.index}` : undefined;
255
+ }
256
+
257
+ /**
258
+ * Returns what identifies the value of a viewport id: the text of a string,
259
+ * or the binding of a name that holds one value; undefined otherwise.
260
+ */
261
+ function viewportIdKey(node: Node): string | undefined {
262
+ const inner = unwrap(node);
263
+
264
+ return inner.kind() === 'string'
265
+ ? `string:${inner.text().slice(1, -1)}`
266
+ : bindingKey(inner);
267
+ }
268
+
269
+ /**
270
+ * Returns the bindings of the viewport that a type node types: the name that
271
+ * its cast casts, or the name that an annotated declaration starts with.
272
+ * Each binding holds one value for its whole scope.
273
+ */
274
+ function receiversOf(typeNode: Node): Set<string> {
275
+ const receivers = new Set<string>();
276
+ const holder = typeNode
277
+ .ancestors()
278
+ .find((ancestor) =>
279
+ ['as_expression', 'type_assertion', 'variable_declarator'].includes(
280
+ ancestor.kind()
281
+ )
282
+ );
283
+ const named = holder?.children().filter((child) => child.isNamed()) ?? [];
284
+ const expression =
285
+ holder?.kind() === 'as_expression'
286
+ ? named[0]
287
+ : holder?.kind() === 'type_assertion'
288
+ ? named[named.length - 1]
289
+ : holder?.field('value');
290
+ const key = bindingKey(expression);
291
+
292
+ if (key) {
293
+ receivers.add(key);
294
+ }
295
+
296
+ return receivers;
297
+ }
298
+
299
+ /**
300
+ * Returns the expression whose `type` a `const` holds: `<viewport>` for
301
+ * `const type = viewport.type`, `const { type } = viewport` or
302
+ * `const { type: viewportType } = viewport`, or undefined.
303
+ */
304
+ function typeSourceOf(identifier: Node): Node | undefined {
305
+ const declaration = stableBinding(identifier);
306
+ const parent = declaration?.parent();
307
+
308
+ if (
309
+ parent?.kind() === 'variable_declarator' &&
310
+ parent.field('name')?.id() === declaration.id()
311
+ ) {
312
+ const value = parent.field('value');
313
+ const inner = value ? unwrap(value) : undefined;
314
+
315
+ return inner?.kind() === 'member_expression' &&
316
+ inner.field('property')?.text() === 'type'
317
+ ? inner.field('object')
318
+ : undefined;
319
+ }
320
+
321
+ const key =
322
+ declaration?.kind() === 'shorthand_property_identifier_pattern'
323
+ ? declaration.text()
324
+ : parent?.kind() === 'pair_pattern' &&
325
+ parent.field('value')?.id() === declaration.id()
326
+ ? staticKeyName(parent.field('key'))
327
+ : undefined;
328
+ const pattern =
329
+ declaration?.kind() === 'shorthand_property_identifier_pattern'
330
+ ? parent
331
+ : parent?.parent();
332
+ const declarator = pattern?.parent();
333
+
334
+ return key === 'type' &&
335
+ pattern?.kind() === 'object_pattern' &&
336
+ declarator?.kind() === 'variable_declarator' &&
337
+ declarator.field('name')?.id() === pattern.id()
338
+ ? (declarator.field('value') ?? undefined)
339
+ : undefined;
340
+ }
341
+
342
+ /**
343
+ * Tells whether a tested value is the type of the viewport that a type node
344
+ * types: `<receiver>.type`, or a `const` that holds it, where the receiver
345
+ * is the binding of the viewport. Any other value, such as a parameter
346
+ * `type` or the type of another object, tells nothing about the viewport.
347
+ */
348
+ function isTiedValue(value: Node, receivers: Set<string>): boolean {
349
+ const inner = unwrap(value);
350
+ const source =
351
+ inner.kind() === 'member_expression' &&
352
+ inner.field('property')?.text() === 'type'
353
+ ? inner.field('object')
354
+ : inner.kind() === 'identifier'
355
+ ? typeSourceOf(inner)
356
+ : undefined;
357
+ const key = bindingKey(source);
358
+
359
+ return Boolean(key && receivers.has(key));
360
+ }
361
+
362
+ /**
363
+ * Returns the family that a viewport type names, by its text.
364
+ */
365
+ function familyOfTypeText(text: string): '3d' | 'planar' | undefined {
366
+ if (THREE_D_TYPE.test(text)) {
367
+ return '3d';
368
+ }
369
+
370
+ return PLANAR_TYPE.test(text) ? 'planar' : undefined;
371
+ }
372
+
373
+ /**
374
+ * Returns what a condition tells about the family of a node that runs when
375
+ * the condition is `positive`: a 3D or a planar family when the node runs
376
+ * only when the tested type equals it, planar when it runs only when the
377
+ * type is not 3D. A condition that names a 3D type and decides nothing (a
378
+ * negation, `||`, a value other than the type of the viewport) is
379
+ * `ambiguous`; one that names planar types only adds nothing to the default,
380
+ * planar, and is undefined like one that names no type.
381
+ */
382
+ function decidedFamily(
383
+ condition: Node,
384
+ positive: boolean,
385
+ receivers: Set<string>
386
+ ): Decision {
387
+ if (!familyOfTypeText(condition.text())) {
388
+ return undefined;
389
+ }
390
+
391
+ const undecided: Decision = THREE_D_TYPE.test(condition.text())
392
+ ? 'ambiguous'
393
+ : undefined;
394
+ const inner = unwrap(condition);
395
+ const operator = inner.field('operator')?.text() ?? '';
396
+
397
+ if (inner.kind() !== 'binary_expression') {
398
+ return undecided;
399
+ }
400
+
401
+ if (operator === '&&' && positive) {
402
+ const decisions = new Set(
403
+ [inner.field('left'), inner.field('right')]
404
+ .map((side) => decidedFamily(side, true, receivers))
405
+ .filter(Boolean)
406
+ );
407
+
408
+ return decisions.size === 1 ? [...decisions][0] : undecided;
409
+ }
410
+
411
+ if (!EQUALITY.has(operator)) {
412
+ return undecided;
413
+ }
414
+
415
+ const left = inner.field('left');
416
+ const right = inner.field('right');
417
+ const leftFamily = familyOfTypeText(left.text());
418
+ const typeSide = leftFamily ? left : right;
419
+ const value = leftFamily ? right : left;
420
+ const family = familyOfTypeText(typeSide.text());
421
+
422
+ if (
423
+ !family ||
424
+ familyOfTypeText(value.text()) ||
425
+ !isTiedValue(value, receivers)
426
+ ) {
427
+ return undecided;
428
+ }
429
+
430
+ if (operator.startsWith('!') !== positive) {
431
+ return family;
432
+ }
433
+
434
+ return family === '3d' ? 'planar' : undecided;
435
+ }
436
+
437
+ /**
438
+ * Returns what a `case` tells about the family of the nodes in its body. A
439
+ * case that the case before it falls into decides nothing, and is ambiguous
440
+ * when it names a 3D type.
441
+ */
442
+ function caseFamily(caseNode: Node, receivers: Set<string>): Decision {
443
+ const value = caseNode.field('value');
444
+ const family = value ? familyOfTypeText(value.text()) : undefined;
445
+
446
+ if (!family) {
447
+ return undefined;
448
+ }
449
+
450
+ const previous = caseNode.prev();
451
+ const previousLast = previous
452
+ ?.children()
453
+ .filter((child) => child.isNamed() && child.kind() !== 'comment')
454
+ .pop();
455
+ const discriminant = caseNode.parent()?.parent()?.field('value');
456
+ const fallsIn =
457
+ previous?.kind() === 'switch_case' &&
458
+ !CASE_ENDS.has(previousLast?.kind() ?? '');
459
+
460
+ if (fallsIn || !discriminant || !isTiedValue(discriminant, receivers)) {
461
+ return family === '3d' ? 'ambiguous' : undefined;
462
+ }
463
+
464
+ return family;
465
+ }
466
+
467
+ /**
468
+ * Returns what a type node shows by itself about the family of the viewport
469
+ * that it types. The type of a type predicate (`viewport is
470
+ * Types.IVolumeViewport`) holds when the body of its function says so, so a
471
+ * body that names a 3D type leaves it 'ambiguous'. A cast of an object
472
+ * literal (`{ ...base, type } as Types.IVolumeViewport`) has the family of
473
+ * the last `type` entry of the object when nothing after it can replace it
474
+ * and its value is resolved without running code; an object that names a 3D
475
+ * type otherwise is 'ambiguous'. Undefined for any other node.
476
+ */
477
+ function ownFamily(typeNode: Node): Decision {
478
+ const predicate = typeNode
479
+ .ancestors()
480
+ .find((ancestor) => ancestor.kind() === 'type_predicate');
481
+
482
+ if (predicate) {
483
+ const body = enclosingFunction(predicate)?.field('body');
484
+ const inSignature =
485
+ body &&
486
+ !predicate.ancestors().some((ancestor) => ancestor.id() === body.id());
487
+
488
+ return inSignature && THREE_D_TYPE.test(body.text())
489
+ ? 'ambiguous'
490
+ : undefined;
491
+ }
492
+
493
+ const parent = typeNode.parent();
494
+ const cast =
495
+ parent?.kind() === 'type_arguments' &&
496
+ parent.parent()?.kind() === 'type_assertion'
497
+ ? parent.parent()
498
+ : parent;
499
+
500
+ if (cast?.kind() !== 'as_expression' && cast?.kind() !== 'type_assertion') {
501
+ return undefined;
502
+ }
503
+
504
+ const named = cast.children().filter((child) => child.isNamed());
505
+ const expression =
506
+ cast.kind() === 'as_expression' ? named[0] : named[named.length - 1];
507
+ const value = expression ? unwrap(expression) : undefined;
508
+
509
+ if (value?.kind() !== 'object') {
510
+ return undefined;
511
+ }
512
+
513
+ const entries = inputEntries(value);
514
+ const family =
515
+ entries.type && entries.typeFinal
516
+ ? staticTypeFamily(entries.type)
517
+ : undefined;
518
+
519
+ if (family === '3d' || family === 'planar') {
520
+ return family;
521
+ }
522
+
523
+ return THREE_D_TYPE.test(value.text()) ? 'ambiguous' : undefined;
524
+ }
525
+
526
+ /**
527
+ * Returns the family that the file shows for a type node: the family that
528
+ * the node shows by itself (`ownFamily`), or '3d' or 'planar' when an
529
+ * enclosing `if`, `else` or `case` of the same function runs only for that
530
+ * family of the viewport it types, or when the viewport inputs of the file
531
+ * with the id of the `getViewport` call that the type casts all have one
532
+ * family; 'mixed' or 'unlinked' when those inputs do not show it
533
+ * (`inputFamily`); 'ambiguous' when the node itself or an enclosing test
534
+ * names a 3D type and decides nothing, or when the test decides outside the
535
+ * function of the node, where the viewport can be another by the time the
536
+ * function runs; undefined otherwise.
537
+ */
538
+ function familyEvidence(run: Run, typeNode: Node): Decision {
539
+ const own = ownFamily(typeNode);
540
+
541
+ if (own === '3d' || own === 'planar') {
542
+ return own;
543
+ }
544
+
545
+ const receivers = receiversOf(typeNode);
546
+ const fn = enclosingFunction(typeNode);
547
+ let child = typeNode;
548
+ let ambiguous = false;
549
+ let outside = false;
550
+
551
+ for (const ancestor of typeNode.ancestors()) {
552
+ const inConsequence =
553
+ ancestor.kind() === 'if_statement' &&
554
+ ancestor.field('consequence')?.id() === child.id();
555
+ const inAlternative =
556
+ ancestor.kind() === 'if_statement' &&
557
+ ancestor.field('alternative')?.id() === child.id();
558
+ const condition =
559
+ inConsequence || inAlternative
560
+ ? ancestor.field('condition')
561
+ : ancestor.kind() === 'switch_case'
562
+ ? ancestor.field('value')
563
+ : undefined;
564
+ const decision =
565
+ inConsequence || inAlternative
566
+ ? decidedFamily(condition, inConsequence, receivers)
567
+ : ancestor.kind() === 'switch_case'
568
+ ? caseFamily(ancestor, receivers)
569
+ : undefined;
570
+
571
+ if (!outside && (decision === '3d' || decision === 'planar')) {
572
+ return decision;
573
+ }
574
+
575
+ ambiguous ||=
576
+ decision === 'ambiguous' ||
577
+ Boolean(decision && condition && THREE_D_TYPE.test(condition.text()));
578
+ outside ||= ancestor.id() === fn?.id();
579
+ child = ancestor;
580
+ }
581
+
582
+ return (
583
+ inputFamily(run, typeNode) ??
584
+ (ambiguous || own === 'ambiguous' ? 'ambiguous' : undefined)
585
+ );
586
+ }
587
+
588
+ /**
589
+ * Returns the family that a viewport type value names when it is resolved
590
+ * without running code: a member of the core `Enums.ViewportType`, or a
591
+ * string. Returns 'other' for another resolved type, and undefined for any
592
+ * other expression, such as a condition, a name or a call.
593
+ */
594
+ function staticTypeFamily(value: Node): '3d' | 'planar' | 'other' | undefined {
595
+ const inner = unwrap(value);
596
+
597
+ if (inner.kind() === 'string') {
598
+ return familyOfTypeText(inner.text()) ?? 'other';
599
+ }
600
+
601
+ const object =
602
+ inner.kind() === 'member_expression' ? inner.field('object') : undefined;
603
+
604
+ if (!object || !isCoreEnum(object, 'ViewportType')) {
605
+ return undefined;
606
+ }
607
+
608
+ return familyOfTypeText(inner.field('property')?.text() ?? '') ?? 'other';
609
+ }
610
+
611
+ /**
612
+ * Returns the last `viewportId` and `type` entries of an object literal (the
613
+ * value of a pair, a shorthand name, or a method of that name), and whether
614
+ * each holds the final value: a spread, a key computed from code or a
615
+ * method of a computed name after it can replace it. A missing type is not
616
+ * final when such an entry exists, as it can give the type.
617
+ */
618
+ function inputEntries(objectNode: Node): {
619
+ id?: Node;
620
+ type?: Node;
621
+ idFinal: boolean;
622
+ typeFinal: boolean;
623
+ open: boolean;
624
+ } {
625
+ const entries = objectNode
626
+ .children()
627
+ .filter((child) => child.isNamed() && child.kind() !== 'comment');
628
+ let id: Node | undefined;
629
+ let type: Node | undefined;
630
+ let idIndex = -1;
631
+ let typeIndex = -1;
632
+ let openIndex = -1;
633
+
634
+ entries.forEach((entry, index) => {
635
+ const kind = entry.kind();
636
+ const name =
637
+ kind === 'pair'
638
+ ? staticKeyName(entry.field('key'))
639
+ : kind === 'shorthand_property_identifier'
640
+ ? entry.text()
641
+ : kind === 'method_definition'
642
+ ? staticKeyName(entry.field('name'))
643
+ : undefined;
644
+ const value = kind === 'pair' ? (entry.field('value') ?? entry) : entry;
645
+
646
+ if (name === undefined) {
647
+ openIndex = index;
648
+ } else if (name === 'viewportId') {
649
+ id = value;
650
+ idIndex = index;
651
+ } else if (name === 'type') {
652
+ type = value;
653
+ typeIndex = index;
654
+ }
655
+ });
656
+
657
+ return {
658
+ id,
659
+ type,
660
+ idFinal: idIndex > openIndex,
661
+ typeFinal: typeIndex > openIndex,
662
+ open: openIndex >= 0,
663
+ };
664
+ }
665
+
666
+ /**
667
+ * Returns the outermost expression that keeps the value of a node through
668
+ * parentheses, casts and non-null assertions.
669
+ */
670
+ function keptValue(node: Node): Node {
671
+ let current = node;
672
+ let parent = node.parent();
673
+
674
+ while (parent && KEEPING_KINDS.has(parent.kind())) {
675
+ current = parent;
676
+ parent = parent.parent();
677
+ }
678
+
679
+ return current;
680
+ }
681
+
682
+ /**
683
+ * Returns the values that a declared name gets: the value of its declaration
684
+ * and the value of each `name = value`. Undefined when the file writes the
685
+ * name in another way, such as `+=` or a destructuring.
686
+ */
687
+ function writtenValues(declaration: Node): Node[] | undefined {
688
+ const holder = declaration.parent();
689
+ const initial =
690
+ holder?.kind() === 'variable_declarator' &&
691
+ holder.field('name')?.id() === declaration.id()
692
+ ? holder.field('value')
693
+ : undefined;
694
+ const values = initial ? [initial] : [];
695
+
696
+ for (const reference of declarationReferences(declaration)) {
697
+ let child = reference;
698
+ let parent = reference.parent();
699
+
700
+ while (parent?.kind() === 'parenthesized_expression') {
701
+ child = parent;
702
+ parent = parent.parent();
703
+ }
704
+
705
+ const kind = parent?.kind() ?? '';
706
+ const right =
707
+ kind === 'assignment_expression' &&
708
+ parent.field('left')?.id() === child.id()
709
+ ? parent.field('right')
710
+ : undefined;
711
+
712
+ if (right) {
713
+ values.push(right);
714
+ } else if (OTHER_WRITES.has(kind)) {
715
+ return undefined;
716
+ }
717
+ }
718
+
719
+ return values;
720
+ }
721
+
722
+ /**
723
+ * Returns what identifies the rendering engine that an expression gives:
724
+ * `engine:` with the id of `new RenderingEngine(id)` or
725
+ * `getRenderingEngine(id)` of the core, when the id is a string or a name
726
+ * that holds one value, also through a name whose every value is such an
727
+ * engine; `binding:` with the declaration of another name that holds one
728
+ * value for its whole scope. Undefined when the engine is not known.
729
+ */
730
+ function engineKey(
731
+ node: Node | null | undefined,
732
+ depth = 0
733
+ ): string | undefined {
734
+ const inner = node ? unwrap(node) : undefined;
735
+ const kind = inner?.kind() ?? '';
736
+
737
+ if (!inner || depth > 4) {
738
+ return undefined;
739
+ }
740
+
741
+ if (kind === 'new_expression' || kind === 'call_expression') {
742
+ const callee = inner.field(
743
+ kind === 'new_expression' ? 'constructor' : 'function'
744
+ );
745
+ const factory =
746
+ kind === 'new_expression' ? 'RenderingEngine' : 'getRenderingEngine';
747
+ const [engineId] =
748
+ inner
749
+ .field('arguments')
750
+ ?.children()
751
+ .filter((child) => child.isNamed() && child.kind() !== 'comment') ?? [];
752
+ const key =
753
+ callee && engineId && isCoreExport(callee, factory)
754
+ ? viewportIdKey(engineId)
755
+ : undefined;
756
+
757
+ return key ? `engine:${key}` : undefined;
758
+ }
759
+
760
+ const declaration =
761
+ kind === 'identifier' ? declarationNodeOf(inner) : undefined;
762
+ const values = declaration ? writtenValues(declaration) : undefined;
763
+
764
+ if (!values) {
765
+ return undefined;
766
+ }
767
+
768
+ if (isStableBinding(declaration)) {
769
+ return (
770
+ (values[0] && engineKey(values[0], depth + 1)) ??
771
+ `binding:${declaration.range().start.index}`
772
+ );
773
+ }
774
+
775
+ const keys = new Set(values.map((value) => engineKey(value, depth + 1)));
776
+
777
+ return keys.size === 1 ? [...keys][0] : undefined;
778
+ }
779
+
780
+ /**
781
+ * Tells whether two engine keys name two engines: both are engines of a
782
+ * string id, and the ids differ.
783
+ */
784
+ function isOtherEngine(key: string | undefined, other: string): boolean {
785
+ return Boolean(
786
+ key?.startsWith('engine:string:') &&
787
+ other.startsWith('engine:string:') &&
788
+ key !== other
789
+ );
790
+ }
791
+
792
+ /**
793
+ * Returns the engines, by `engineKey`, that a viewport input object is given
794
+ * to, and whether every use of it is known: the object is the argument of
795
+ * `enableElement` on an engine, or an entry of an array literal that is the
796
+ * argument of `setViewports`, directly or through a `const` that holds it.
797
+ */
798
+ function inputEngines(objectNode: Node): {
799
+ engines: Set<string | undefined>;
800
+ complete: boolean;
801
+ } {
802
+ const outer = keptValue(objectNode);
803
+ const holder = outer.parent()?.kind() === 'array' ? outer.parent() : outer;
804
+ const method = INPUT_METHOD[holder.kind()] ?? INPUT_METHOD.object;
805
+ const value = keptValue(holder);
806
+ const declarator = value.parent();
807
+ const name =
808
+ declarator?.kind() === 'variable_declarator' &&
809
+ declarator.field('value')?.id() === value.id()
810
+ ? declarator.field('name')
811
+ : undefined;
812
+ const engines = new Set<string | undefined>();
813
+
814
+ if (name && (name.kind() !== 'identifier' || !isStableBinding(name))) {
815
+ return { engines, complete: false };
816
+ }
817
+
818
+ const uses = name
819
+ ? declarationReferences(name).map((reference) => keptValue(reference))
820
+ : [value];
821
+ let complete = true;
822
+
823
+ for (const use of uses) {
824
+ const args = use.parent();
825
+ const callNode = args?.kind() === 'arguments' ? args.parent() : undefined;
826
+ const call = callNode ? methodCall(callNode) : undefined;
827
+
828
+ if (call?.method === method && call.args[0]?.id() === use.id()) {
829
+ engines.add(engineKey(call.object));
830
+ } else {
831
+ complete = false;
832
+ }
833
+ }
834
+
835
+ return { engines, complete };
836
+ }
837
+
838
+ /**
839
+ * Returns the family of the viewport inputs of the file with the id of the
840
+ * `getViewport` call that a type node casts, when they all give one type
841
+ * that is resolved without running code. An input given to an engine of
842
+ * another string id than the engine of the call does not count. Returns
843
+ * `mixed` when one gives a 3D type and another gives another type, or when
844
+ * one gives a type that only the running code resolves: such as
845
+ * `flag ? VOLUME_3D : PLANAR`, a type that a spread, a computed key or a
846
+ * method after it can replace, or the type of an input whose id they can
847
+ * replace. Returns `unlinked` when they give a 3D type and none of them is
848
+ * given to the engine of the call: the same id can name a planar viewport
849
+ * there.
850
+ */
851
+ function inputFamily(run: Run, typeNode: Node): Decision {
852
+ const holder = typeNode
853
+ .ancestors()
854
+ .find((ancestor) =>
855
+ ['as_expression', 'type_assertion', 'variable_declarator'].includes(
856
+ ancestor.kind()
857
+ )
858
+ );
859
+ const expression =
860
+ holder?.kind() === 'variable_declarator'
861
+ ? holder.field('value')
862
+ : holder
863
+ ?.children()
864
+ .filter((node) => node.isNamed())
865
+ .find((node) => node.kind() === 'call_expression');
866
+ const call = expression ? methodCall(unwrap(expression)) : undefined;
867
+
868
+ if (!call || call.method !== 'getViewport' || call.args.length !== 1) {
869
+ return undefined;
870
+ }
871
+
872
+ const id = viewportIdKey(call.args[0]);
873
+ const engine = engineKey(call.object);
874
+ const families = new Set<string>();
875
+ let shownOnEngine = false;
876
+
877
+ if (!id) {
878
+ return undefined;
879
+ }
880
+
881
+ for (const objectNode of run.rootNode.findAll({ rule: { kind: 'object' } })) {
882
+ const entries = inputEntries(objectNode);
883
+
884
+ if (
885
+ !entries.id ||
886
+ viewportIdKey(entries.id) !== id ||
887
+ (!entries.type && !entries.open)
888
+ ) {
889
+ continue;
890
+ }
891
+
892
+ const { engines, complete } = inputEngines(objectNode);
893
+ const linked = Boolean(engine && engines.has(engine));
894
+
895
+ if (
896
+ engine &&
897
+ !linked &&
898
+ complete &&
899
+ engines.size > 0 &&
900
+ [...engines].every((key) => isOtherEngine(key, engine))
901
+ ) {
902
+ continue;
903
+ }
904
+
905
+ const family =
906
+ entries.idFinal && entries.typeFinal
907
+ ? (staticTypeFamily(entries.type) ?? 'dynamic')
908
+ : 'dynamic';
909
+
910
+ families.add(family);
911
+ shownOnEngine ||= family === '3d' && linked;
912
+ }
913
+
914
+ if (families.has('dynamic') || (families.has('3d') && families.size > 1)) {
915
+ return 'mixed';
916
+ }
917
+
918
+ if (families.has('3d')) {
919
+ return shownOnEngine ? '3d' : 'unlinked';
920
+ }
921
+
922
+ return families.size === 1 && families.has('planar') ? 'planar' : undefined;
923
+ }
924
+
925
+ /**
926
+ * Returns the 6.0 class of a legacy type name at a type node: the 3D class
927
+ * for a name that also typed a 3D viewport when the file shows a 3D viewport,
928
+ * the planar class otherwise. Returns undefined, and reports the site, when
929
+ * a test of a 3D type around the node does not show the family: the type
930
+ * stays for the reader.
931
+ */
932
+ function classFor(
933
+ run: Run,
934
+ typeNode: Node,
935
+ name: string,
936
+ planarClass: string,
937
+ label: string
938
+ ): string | undefined {
939
+ if (!VOLUME_OR_3D.has(name)) {
940
+ return planarClass;
941
+ }
942
+
943
+ const family = familyEvidence(run, typeNode);
944
+
945
+ if (family === 'ambiguous' || family === 'mixed' || family === 'unlinked') {
946
+ const reason =
947
+ family === 'mixed'
948
+ ? 'the inputs of this viewport id do not give one static type'
949
+ : family === 'unlinked'
950
+ ? 'the 3D input of this viewport id is not tied to the engine of this call'
951
+ : 'a test of a 3D type here does not show the family';
952
+
953
+ manual.increment(site(run.root, `${label}: ${reason}`, typeNode));
954
+
955
+ return undefined;
956
+ }
957
+
958
+ return family === '3d' ? 'VolumeViewport3D' : planarClass;
959
+ }
960
+
961
+ /**
962
+ * Replaces a type node with a class name. When the type is the cast of a
963
+ * `getViewport` call on a typed engine, the cast becomes the type argument
964
+ * of the call.
965
+ */
966
+ function replaceType(run: Run, typeNode: Node, className: string): boolean {
967
+ const parent = typeNode.parent();
968
+ const cast =
969
+ parent?.kind() === 'type_arguments' &&
970
+ parent.parent()?.kind() === 'type_assertion'
971
+ ? parent.parent()
972
+ : parent;
973
+
974
+ if (
975
+ cast &&
976
+ (cast.kind() === 'as_expression' || cast.kind() === 'type_assertion')
977
+ ) {
978
+ const named = cast.children().filter((child) => child.isNamed());
979
+ const expression =
980
+ cast.kind() === 'as_expression' ? named[0] : named[named.length - 1];
981
+ const callNode = expression ? unwrap(expression) : undefined;
982
+ const call = callNode ? methodCall(callNode) : undefined;
983
+
984
+ if (
985
+ call &&
986
+ call.method === 'getViewport' &&
987
+ !callNode.field('type_arguments') &&
988
+ isTypedEngine(call.object)
989
+ ) {
990
+ return run.edits.add(
991
+ cast.replace(
992
+ `${call.object.text()}.getViewport<${className}>${call.argsNode.text()}`
993
+ )
994
+ );
995
+ }
996
+ }
997
+
998
+ return run.edits.add(typeNode.replace(className));
999
+ }
1000
+
1001
+ /**
1002
+ * Returns the identifiers, type identifiers and shorthand properties of the
1003
+ * file that refer to an import specifier.
1004
+ */
1005
+ function referencesOf(run: Run, specifier: Node, local: string): Node[] {
1006
+ return run.rootNode
1007
+ .findAll({
1008
+ rule: {
1009
+ any: [
1010
+ { kind: 'identifier' },
1011
+ { kind: 'type_identifier' },
1012
+ { kind: 'shorthand_property_identifier' },
1013
+ ],
1014
+ regex: `^${local}$`,
1015
+ },
1016
+ })
1017
+ .filter(
1018
+ (node) =>
1019
+ !inImport(node) && coreImportOf(node)?.specifier.id() === specifier.id()
1020
+ );
1021
+ }
1022
+
1023
+ /**
1024
+ * Tells whether a reference is the right side of `instanceof`.
1025
+ */
1026
+ function instanceofOf(node: Node): Node | undefined {
1027
+ const parent = node.parent();
1028
+
1029
+ if (
1030
+ parent?.kind() === 'binary_expression' &&
1031
+ parent.field('operator')?.text() === 'instanceof' &&
1032
+ parent.field('right')?.id() === node.id()
1033
+ ) {
1034
+ return parent;
1035
+ }
1036
+
1037
+ return undefined;
1038
+ }
1039
+
1040
+ /**
1041
+ * Rewrites `value instanceof LegacyClass` to the test of the content mode,
1042
+ * when an awaited mount of the value comes before it: a 5.x class is known
1043
+ * from the creation of the viewport, a 6.0 mode only from its first mount.
1044
+ * Reports the test otherwise.
1045
+ */
1046
+ function rewriteInstanceof(run: Run, binary: Node, name: string): boolean {
1047
+ const test = INSTANCEOF_TEST[name];
1048
+ const left = binary.field('left');
1049
+
1050
+ if (test && !isMountedBefore(binary, left)) {
1051
+ manual.increment(
1052
+ site(
1053
+ run.root,
1054
+ `instanceof ${name}: the viewport may not show its data yet`,
1055
+ binary
1056
+ )
1057
+ );
1058
+
1059
+ return false;
1060
+ }
1061
+
1062
+ const utilities = test
1063
+ ? run.imports.ensure('utilities', { at: binary })
1064
+ : undefined;
1065
+
1066
+ if (!test || !utilities) {
1067
+ manual.increment(site(run.root, `instanceof ${name}`, binary));
1068
+
1069
+ return false;
1070
+ }
1071
+
1072
+ const text = test(utilities, left.text());
1073
+ const added = run.edits.add(
1074
+ binary.replace(text.includes(' === ') ? comparisonAt(binary, text) : text)
1075
+ );
1076
+
1077
+ if (added) {
1078
+ review.increment(site(run.root, `instanceof ${name}`, binary));
1079
+ }
1080
+
1081
+ return added;
1082
+ }
1083
+
1084
+ /**
1085
+ * Rewrites the references of a named import of a legacy class: a type
1086
+ * becomes the 6.0 class, `instanceof` the test of the mode. The import goes
1087
+ * when no reference is left.
1088
+ */
1089
+ function rewriteLegacyClass(
1090
+ run: Run,
1091
+ specifier: Node,
1092
+ name: string,
1093
+ local: string
1094
+ ): void {
1095
+ const references = referencesOf(run, specifier, local);
1096
+ let left = 0;
1097
+
1098
+ for (const reference of references) {
1099
+ const binary = instanceofOf(reference);
1100
+
1101
+ if (binary) {
1102
+ left += rewriteInstanceof(run, binary, name) ? 0 : 1;
1103
+ continue;
1104
+ }
1105
+
1106
+ if (reference.kind() === 'type_identifier') {
1107
+ const chosen = classFor(
1108
+ run,
1109
+ reference,
1110
+ name,
1111
+ LEGACY_CLASS_TYPE[name],
1112
+ name
1113
+ );
1114
+ const className = chosen
1115
+ ? run.imports.ensure(chosen, { type: true })
1116
+ : undefined;
1117
+
1118
+ left += className && replaceType(run, reference, className) ? 0 : 1;
1119
+ continue;
1120
+ }
1121
+
1122
+ manual.increment(site(run.root, name, reference));
1123
+ left += 1;
1124
+ }
1125
+
1126
+ if (!left) {
1127
+ run.imports.remove(name);
1128
+ }
1129
+ }
1130
+
1131
+ /**
1132
+ * Renames a class that 6.0 names differently, in the import and in every
1133
+ * reference. A shorthand property and an export keep their public key.
1134
+ */
1135
+ function renameClass(
1136
+ run: Run,
1137
+ specifier: Node,
1138
+ name: string,
1139
+ local: string
1140
+ ): void {
1141
+ const references = referencesOf(run, specifier, local);
1142
+ const newLocal = run.imports.rename(name, RENAMED_CLASS[name]);
1143
+
1144
+ if (!newLocal || newLocal === local) {
1145
+ return;
1146
+ }
1147
+
1148
+ for (const reference of references) {
1149
+ const parent = reference.parent();
1150
+
1151
+ if (reference.kind() === 'shorthand_property_identifier') {
1152
+ run.edits.add(reference.replace(`${local}: ${newLocal}`));
1153
+ } else if (
1154
+ parent?.kind() === 'export_specifier' &&
1155
+ !parent.field('alias')
1156
+ ) {
1157
+ run.edits.add(parent.replace(`${newLocal} as ${local}`));
1158
+ } else {
1159
+ run.edits.add(reference.replace(newLocal));
1160
+ }
1161
+ }
1162
+ }
1163
+
1164
+ /**
1165
+ * Rewrites the re-exports of the core: a renamed class keeps its public name
1166
+ * through `as`, and a removed class is reported, as 6.0 has no export of
1167
+ * that name.
1168
+ */
1169
+ function rewriteReExports(run: Run): void {
1170
+ const statements = run.rootNode
1171
+ .children()
1172
+ .filter(
1173
+ (child) =>
1174
+ child.kind() === 'export_statement' &&
1175
+ importSource(child) === CORE_PACKAGE
1176
+ );
1177
+
1178
+ for (const statement of statements) {
1179
+ for (const specifier of statement.findAll({
1180
+ rule: { kind: 'export_specifier' },
1181
+ })) {
1182
+ const nameNode = specifier.field('name');
1183
+ const name = nameNode?.text() ?? '';
1184
+
1185
+ if (LEGACY_CLASS_TYPE[name]) {
1186
+ manual.increment(site(run.root, name, specifier));
1187
+ } else if (RENAMED_CLASS[name]) {
1188
+ run.edits.add(
1189
+ specifier.field('alias')
1190
+ ? nameNode.replace(RENAMED_CLASS[name])
1191
+ : specifier.replace(`${RENAMED_CLASS[name]} as ${name}`)
1192
+ );
1193
+ }
1194
+ }
1195
+ }
1196
+ }
1197
+
1198
+ /**
1199
+ * Returns the parts of a nested type such as `Types.IStackViewport` or
1200
+ * `cs.Types.IStackViewport` when its namespace is the core `Types`, or the
1201
+ * core namespace itself.
1202
+ */
1203
+ function coreNestedType(
1204
+ node: Node
1205
+ ): { namespace: 'Types' | 'core'; name: string; nameNode: Node } | undefined {
1206
+ const named = node.children().filter((child) => child.isNamed());
1207
+ const module = named[0];
1208
+ const nameNode = named[named.length - 1];
1209
+
1210
+ if (!module || !nameNode || nameNode.kind() !== 'type_identifier') {
1211
+ return undefined;
1212
+ }
1213
+
1214
+ if (module.kind() === 'identifier') {
1215
+ if (coreImportOf(module)?.name === 'Types') {
1216
+ return { namespace: 'Types', name: nameNode.text(), nameNode };
1217
+ }
1218
+
1219
+ if (isCoreNamespace(module)) {
1220
+ return { namespace: 'core', name: nameNode.text(), nameNode };
1221
+ }
1222
+
1223
+ return undefined;
1224
+ }
1225
+
1226
+ if (module.kind() === 'nested_identifier') {
1227
+ const parts = module.children().filter((child) => child.isNamed());
1228
+
1229
+ if (
1230
+ parts.length === 2 &&
1231
+ parts[0].kind() === 'identifier' &&
1232
+ parts[1].text() === 'Types' &&
1233
+ isCoreNamespace(parts[0])
1234
+ ) {
1235
+ return { namespace: 'Types', name: nameNode.text(), nameNode };
1236
+ }
1237
+ }
1238
+
1239
+ return undefined;
1240
+ }
1241
+
1242
+ /**
1243
+ * Rewrites the nested types of the core: the removed `Types` interfaces, the
1244
+ * renamed ones, and the classes read through the core namespace.
1245
+ */
1246
+ function rewriteNestedTypes(run: Run): void {
1247
+ for (const node of run.rootNode.findAll({
1248
+ rule: { kind: 'nested_type_identifier' },
1249
+ })) {
1250
+ const nested = coreNestedType(node);
1251
+
1252
+ if (!nested) {
1253
+ continue;
1254
+ }
1255
+
1256
+ const { namespace, name, nameNode } = nested;
1257
+
1258
+ if (namespace === 'Types' && TYPES_TO_CLASS[name]) {
1259
+ const chosen = classFor(
1260
+ run,
1261
+ node,
1262
+ name,
1263
+ TYPES_TO_CLASS[name],
1264
+ `Types.${name}`
1265
+ );
1266
+ const className = chosen
1267
+ ? run.imports.ensure(chosen, { type: true })
1268
+ : undefined;
1269
+
1270
+ if (chosen && (!className || !replaceType(run, node, className))) {
1271
+ manual.increment(site(run.root, `Types.${name}`, node));
1272
+ }
1273
+ } else if (namespace === 'Types' && TYPES_RENAMED[name]) {
1274
+ run.edits.add(nameNode.replace(TYPES_RENAMED[name]));
1275
+ } else if (namespace === 'Types' && TYPES_REPORTED.has(name)) {
1276
+ manual.increment(site(run.root, `Types.${name}`, node));
1277
+ } else if (namespace === 'core' && LEGACY_CLASS_TYPE[name]) {
1278
+ const chosen = classFor(run, node, name, LEGACY_CLASS_TYPE[name], name);
1279
+ const module = node
1280
+ .children()
1281
+ .find((child) => child.isNamed())
1282
+ .text();
1283
+
1284
+ if (chosen) {
1285
+ replaceType(run, node, `${module}.${chosen}`);
1286
+ }
1287
+ } else if (namespace === 'core' && RENAMED_CLASS[name]) {
1288
+ run.edits.add(nameNode.replace(RENAMED_CLASS[name]));
1289
+ }
1290
+ }
1291
+ }
1292
+
1293
+ /**
1294
+ * Rewrites the classes read as values through the core namespace:
1295
+ * `value instanceof cs.StackViewport` and `cs.GenericVolumeViewport3D`.
1296
+ */
1297
+ function rewriteNamespaceValues(run: Run): void {
1298
+ if (!run.imports.namespace) {
1299
+ return;
1300
+ }
1301
+
1302
+ for (const node of run.rootNode.findAll({
1303
+ rule: { kind: 'member_expression' },
1304
+ })) {
1305
+ const name = node.field('property')?.text() ?? '';
1306
+ const object = node.field('object');
1307
+
1308
+ if (
1309
+ (!LEGACY_CLASS_TYPE[name] && !RENAMED_CLASS[name]) ||
1310
+ object?.kind() !== 'identifier' ||
1311
+ !isCoreNamespace(object)
1312
+ ) {
1313
+ continue;
1314
+ }
1315
+
1316
+ if (RENAMED_CLASS[name]) {
1317
+ run.edits.add(node.field('property').replace(RENAMED_CLASS[name]));
1318
+ continue;
1319
+ }
1320
+
1321
+ const binary = instanceofOf(node);
1322
+
1323
+ if (binary) {
1324
+ rewriteInstanceof(run, binary, name);
1325
+ } else {
1326
+ manual.increment(site(run.root, name, node));
1327
+ }
1328
+ }
1329
+ }
1330
+
1331
+ /**
1332
+ * Reports a bracket access with a string key to a removed or renamed class
1333
+ * on the core namespace, such as `cs['StackViewport']`.
1334
+ */
1335
+ function reportBracketClasses(run: Run): void {
1336
+ for (const node of run.rootNode.findAll({
1337
+ rule: { kind: 'subscript_expression' },
1338
+ })) {
1339
+ const name = bracketKey(node) ?? '';
1340
+ const object = node.field('object');
1341
+
1342
+ if (
1343
+ (LEGACY_CLASS_TYPE[name] || RENAMED_CLASS[name]) &&
1344
+ object?.kind() === 'identifier' &&
1345
+ isCoreNamespace(object)
1346
+ ) {
1347
+ manual.increment(site(run.root, name, node));
1348
+ }
1349
+ }
1350
+ }
1351
+
1352
+ /**
1353
+ * Reports `utilities.isGenericViewport(viewport)`: deprecated, true for every
1354
+ * viewport, so its check goes and its true branch stays.
1355
+ */
1356
+ function reportIsGenericViewport(run: Run): void {
1357
+ for (const call of run.rootNode.findAll({
1358
+ rule: { pattern: '$UTILS.isGenericViewport($$$ARGS)' },
1359
+ })) {
1360
+ const callee = call.field('function');
1361
+
1362
+ if (callee && isCoreExport(callee.field('object'), 'utilities')) {
1363
+ manual.increment(site(run.root, 'isGenericViewport', call));
1364
+ }
1365
+ }
1366
+ }
1367
+
1368
+ /**
1369
+ * Reports the removed and renamed `Types` names that a file imports or
1370
+ * re-exports from the subpath `@cornerstonejs/core/types`
1371
+ * (`import { IStackViewport } from '@cornerstonejs/core/types'`). The
1372
+ * rewrites read `Types.X` of the core only, so each name is left to the
1373
+ * reader, by its `Types` name.
1374
+ */
1375
+ function reportTypesSubpath(run: Run): void {
1376
+ const typesPath = `${CORE_PACKAGE}/types`;
1377
+
1378
+ for (const statement of run.rootNode.findAll({
1379
+ rule: { any: [{ kind: 'import_statement' }, { kind: 'export_statement' }] },
1380
+ })) {
1381
+ const source = importSource(statement);
1382
+
1383
+ if (source !== typesPath && !source?.startsWith(`${typesPath}/`)) {
1384
+ continue;
1385
+ }
1386
+
1387
+ for (const specifier of statement.findAll({
1388
+ rule: {
1389
+ any: [{ kind: 'import_specifier' }, { kind: 'export_specifier' }],
1390
+ },
1391
+ })) {
1392
+ const name = specifier.field('name')?.text() ?? '';
1393
+
1394
+ if (
1395
+ TYPES_TO_CLASS[name] ||
1396
+ TYPES_RENAMED[name] ||
1397
+ TYPES_REPORTED.has(name)
1398
+ ) {
1399
+ manual.increment(site(run.root, `Types.${name}`, specifier));
1400
+ }
1401
+ }
1402
+ }
1403
+ }
1404
+
1405
+ /**
1406
+ * Rewrites the classes and the TypeScript types that Cornerstone3D 6.0
1407
+ * removes or renames: the legacy viewport classes become `PlanarViewport` in
1408
+ * a type and a test of the content mode after `instanceof`, the deprecated
1409
+ * class aliases get their plain names, `Types.IStackViewport` and its kin
1410
+ * become the class of their family, and a cast of `getViewport` becomes its
1411
+ * type argument.
1412
+ */
1413
+ const codemod: Codemod<TSX> = (root) => {
1414
+ const rootNode = root.root();
1415
+ const run: Run = {
1416
+ root,
1417
+ rootNode,
1418
+ imports: new CoreImports(rootNode),
1419
+ edits: new EditSet(),
1420
+ };
1421
+ const specifiers = rootNode
1422
+ .findAll({ rule: { kind: 'import_specifier' } })
1423
+ .filter((specifier) => {
1424
+ const statement = specifier
1425
+ .ancestors()
1426
+ .find((ancestor) => ancestor.kind() === 'import_statement');
1427
+
1428
+ return (
1429
+ statement?.field('source')?.text().slice(1, -1) ===
1430
+ '@cornerstonejs/core'
1431
+ );
1432
+ });
1433
+
1434
+ for (const specifier of specifiers) {
1435
+ const name = specifier.field('name')?.text() ?? '';
1436
+ const local = specifier.field('alias')?.text() ?? name;
1437
+
1438
+ if (LEGACY_CLASS_TYPE[name]) {
1439
+ rewriteLegacyClass(run, specifier, name, local);
1440
+ } else if (RENAMED_CLASS[name]) {
1441
+ renameClass(run, specifier, name, local);
1442
+ }
1443
+ }
1444
+
1445
+ rewriteNestedTypes(run);
1446
+ rewriteNamespaceValues(run);
1447
+ rewriteReExports(run);
1448
+ reportBracketClasses(run);
1449
+ reportIsGenericViewport(run);
1450
+ reportTypesSubpath(run);
1451
+
1452
+ const importEdits = run.imports.edits();
1453
+
1454
+ if (!run.edits.all().length && !importEdits.length) {
1455
+ return null;
1456
+ }
1457
+
1458
+ return rootNode.commitEdits([...run.edits.all(), ...importEdits]);
1459
+ };
1460
+
1461
+ export default codemod;