@cornerstonejs/codemods 5.19.4 → 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,647 @@
1
+ import type { Codemod, Edit, SgRoot } from 'codemod:ast-grep';
2
+ import type TSX from 'codemod:ast-grep/langs/tsx';
3
+ import { useMetricAtom } from 'codemod:metrics';
4
+ import {
5
+ CoreImports,
6
+ EditSet,
7
+ bracketKey,
8
+ comparisonAt,
9
+ coreImportOf,
10
+ coreReExports,
11
+ coreSpecifiers,
12
+ isCoreExport,
13
+ isCoreNamespace,
14
+ isPure,
15
+ objectEntries,
16
+ referencesOf,
17
+ site,
18
+ } from './lib.ts';
19
+ import type { Node } from './lib.ts';
20
+
21
+ /** Sites that the reader changes. */
22
+ const manual = useMetricAtom('cornerstone3d-6-manual');
23
+
24
+ /** Rewrites at a decision of the migration guide. */
25
+ const review = useMetricAtom('cornerstone3d-6-review');
26
+
27
+ /** The removed functions of the CPU switch and of the generic switch. */
28
+ const SETTING_FUNCTIONS = new Set([
29
+ 'setUseCPURendering',
30
+ 'resetUseCPURendering',
31
+ 'getShouldUseCPURendering',
32
+ 'getUseGenericViewport',
33
+ ]);
34
+
35
+ /** The keys of the configuration that 6.0 removes, as a regular expression. */
36
+ const REMOVED_KEYS =
37
+ 'useGenericViewport|useCPURendering|useViewportSamplingForLinear';
38
+
39
+ /** The core functions that take the configuration. */
40
+ const CONFIGURATION_FUNCTIONS = ['init', 'setConfiguration'];
41
+
42
+ /** The expressions that need parentheses before `? :`. */
43
+ const LOW_PRECEDENCE = new Set([
44
+ 'ternary_expression',
45
+ 'assignment_expression',
46
+ 'augmented_assignment_expression',
47
+ 'sequence_expression',
48
+ 'arrow_function',
49
+ 'yield_expression',
50
+ ]);
51
+
52
+ /**
53
+ * The state of one run of the transform on a file.
54
+ */
55
+ interface Run {
56
+ root: SgRoot<TSX>;
57
+ rootNode: Node;
58
+ imports: CoreImports;
59
+ edits: EditSet;
60
+ }
61
+
62
+ /** A pair of the configuration to remove, with the pair that holds it. */
63
+ interface Removal {
64
+ pair: Node;
65
+ holder: Node;
66
+ rule: string;
67
+ }
68
+
69
+ /**
70
+ * The pairs to remove from one object literal; `outer` when they are pairs
71
+ * that hold objects which lose every key.
72
+ */
73
+ interface RemovalGroup {
74
+ objectNode: Node;
75
+ pairs: Node[];
76
+ outer: boolean;
77
+ }
78
+
79
+ /**
80
+ * Returns the key of a pair, without quotes.
81
+ */
82
+ function keyOf(pair: Node): string {
83
+ const key = pair.field('key');
84
+
85
+ return key?.kind() === 'string'
86
+ ? key.text().slice(1, -1)
87
+ : (key?.text() ?? '');
88
+ }
89
+
90
+ /**
91
+ * Returns the pair whose value is the object that holds a pair, when its key
92
+ * is `name`.
93
+ */
94
+ function holderPair(pair: Node, name: string): Node | undefined {
95
+ const objectNode = pair.parent();
96
+ const holder = objectNode?.parent();
97
+
98
+ return holder?.kind() === 'pair' && keyOf(holder) === name
99
+ ? holder
100
+ : undefined;
101
+ }
102
+
103
+ /**
104
+ * Returns the edits that remove entries of an object literal, each run of
105
+ * neighbouring entries in one edit with its commas, so that two removals
106
+ * never share a comma.
107
+ */
108
+ function removeEntries(objectNode: Node, removed: Node[]): Edit[] {
109
+ const ids = new Set(removed.map((entry) => entry.id()));
110
+ const entries = objectNode
111
+ .children()
112
+ .filter((child) => child.isNamed() && child.kind() !== 'comment');
113
+ const edits: Edit[] = [];
114
+ let index = 0;
115
+
116
+ while (index < entries.length) {
117
+ if (!ids.has(entries[index].id())) {
118
+ index += 1;
119
+ continue;
120
+ }
121
+
122
+ const first = index;
123
+
124
+ while (index < entries.length && ids.has(entries[index].id())) {
125
+ index += 1;
126
+ }
127
+
128
+ const last = entries[index - 1];
129
+ const next = entries[index];
130
+ const previous = entries[first - 1];
131
+
132
+ if (next) {
133
+ edits.push({
134
+ startPos: entries[first].range().start.index,
135
+ endPos: next.range().start.index,
136
+ insertedText: '',
137
+ });
138
+ } else if (previous) {
139
+ const comma = previous.next();
140
+
141
+ edits.push({
142
+ startPos:
143
+ comma?.kind() === ','
144
+ ? comma.range().start.index
145
+ : previous.range().end.index,
146
+ endPos: last.range().end.index,
147
+ insertedText: '',
148
+ });
149
+ } else {
150
+ edits.push({
151
+ startPos: entries[first].range().start.index,
152
+ endPos: last.range().end.index,
153
+ insertedText: '',
154
+ });
155
+ }
156
+ }
157
+
158
+ return edits;
159
+ }
160
+
161
+ /**
162
+ * Tells whether an object literal is the one argument of the core `init`.
163
+ */
164
+ function isInitArgument(objectNode: Node): boolean {
165
+ const args = objectNode.parent();
166
+ const call = args?.parent();
167
+ const namedArgs = args?.children().filter((child) => child.isNamed()) ?? [];
168
+ const callee =
169
+ call?.kind() === 'call_expression' ? call.field('function') : undefined;
170
+
171
+ return Boolean(
172
+ args?.kind() === 'arguments' &&
173
+ namedArgs.length === 1 &&
174
+ callee &&
175
+ (coreImportOf(callee)?.name === 'init' ||
176
+ (callee.kind() === 'member_expression' &&
177
+ callee.field('property')?.text() === 'init' &&
178
+ isCoreNamespace(callee.field('object'))))
179
+ );
180
+ }
181
+
182
+ /**
183
+ * Removes the obsolete pairs of the configuration, each object in one set
184
+ * of edits. An object that loses every key goes with the pair that holds
185
+ * it; an outer object that loses every key becomes `{}`, and `init({})`
186
+ * becomes `init()`. A removal that another edit overlaps is reported.
187
+ */
188
+ function removeSettings(run: Run, removals: Removal[]): void {
189
+ const groups = new Map<number, RemovalGroup>();
190
+ const addTo = (objectNode: Node, pair: Node, outer: boolean) => {
191
+ const group = groups.get(objectNode.id()) ?? {
192
+ objectNode,
193
+ pairs: [],
194
+ outer,
195
+ };
196
+
197
+ group.pairs.push(pair);
198
+ group.outer ||= outer;
199
+ groups.set(objectNode.id(), group);
200
+ };
201
+ const isEmptied = ({ objectNode, pairs }: RemovalGroup) => {
202
+ const { keys, hasSpread } = objectEntries(objectNode);
203
+
204
+ return !hasSpread && keys.length === pairs.length;
205
+ };
206
+
207
+ for (const { pair } of removals) {
208
+ addTo(pair.parent(), pair, false);
209
+ }
210
+
211
+ for (const group of [...groups.values()].filter(isEmptied)) {
212
+ const holder = removals.find(
213
+ ({ pair }) => pair.id() === group.pairs[0].id()
214
+ ).holder;
215
+
216
+ groups.delete(group.objectNode.id());
217
+ addTo(holder.parent(), holder, true);
218
+ }
219
+
220
+ const failed = new Set<number>();
221
+
222
+ for (const group of groups.values()) {
223
+ const { objectNode, pairs } = group;
224
+ const edits =
225
+ group.outer && isEmptied(group)
226
+ ? [
227
+ isInitArgument(objectNode)
228
+ ? objectNode.parent().replace('()')
229
+ : objectNode.replace('{}'),
230
+ ]
231
+ : removeEntries(objectNode, pairs);
232
+
233
+ if (!run.edits.add(...edits)) {
234
+ pairs.forEach((pair) => failed.add(pair.id()));
235
+ }
236
+ }
237
+
238
+ for (const { pair, holder, rule } of removals) {
239
+ if (failed.has(pair.id()) || failed.has(holder.id())) {
240
+ manual.increment(site(run.root, rule, pair));
241
+ }
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Tells whether an object literal, or a variable that holds it, is passed to
247
+ * the core `init` or `setConfiguration` in the file.
248
+ */
249
+ function reachesConfigurationCall(node: Node): boolean {
250
+ let current = node;
251
+
252
+ while (
253
+ [
254
+ 'parenthesized_expression',
255
+ 'as_expression',
256
+ 'satisfies_expression',
257
+ ].includes(current.parent()?.kind() ?? '')
258
+ ) {
259
+ current = current.parent();
260
+ }
261
+
262
+ const parent = current.parent();
263
+
264
+ if (parent?.kind() === 'arguments') {
265
+ const callee = parent.parent()?.field('function');
266
+
267
+ return Boolean(
268
+ callee &&
269
+ CONFIGURATION_FUNCTIONS.some((name) => isCoreExport(callee, name))
270
+ );
271
+ }
272
+
273
+ if (
274
+ parent?.kind() !== 'variable_declarator' ||
275
+ parent.field('value')?.id() !== current.id()
276
+ ) {
277
+ return false;
278
+ }
279
+
280
+ const name = parent.field('name');
281
+
282
+ return Boolean(
283
+ name?.kind() === 'identifier' &&
284
+ referencesOf(name).some(
285
+ (reference) =>
286
+ reference.kind() === 'identifier' &&
287
+ reachesConfigurationCall(reference)
288
+ )
289
+ );
290
+ }
291
+
292
+ /**
293
+ * Returns the outermost object literal that holds a pair through nested
294
+ * pairs.
295
+ */
296
+ function configurationOf(pair: Node): Node {
297
+ let objectNode = pair.parent();
298
+
299
+ while (
300
+ objectNode.parent()?.kind() === 'pair' &&
301
+ objectNode.parent().parent()?.kind() === 'object'
302
+ ) {
303
+ objectNode = objectNode.parent().parent();
304
+ }
305
+
306
+ return objectNode;
307
+ }
308
+
309
+ /**
310
+ * Rewrites the removed keys of the `rendering` configuration of an object
311
+ * that the file passes to `init` or `setConfiguration`. A key of another
312
+ * object, or a key whose value runs code, is reported. A shorthand entry,
313
+ * such as `{ useCPURendering }`, is a key whose value is the name it reads.
314
+ */
315
+ function rewriteConfiguration(run: Run): void {
316
+ const pairs = run.rootNode.findAll({
317
+ rule: {
318
+ any: [
319
+ {
320
+ kind: 'pair',
321
+ has: {
322
+ field: 'key',
323
+ regex: `^['"]?(${REMOVED_KEYS})['"]?$`,
324
+ },
325
+ },
326
+ {
327
+ kind: 'shorthand_property_identifier',
328
+ regex: `^(${REMOVED_KEYS})$`,
329
+ },
330
+ ],
331
+ },
332
+ });
333
+
334
+ const removals: Removal[] = [];
335
+
336
+ for (const pair of pairs) {
337
+ const isShorthand = pair.kind() === 'shorthand_property_identifier';
338
+ const key = isShorthand ? pair.text() : keyOf(pair);
339
+ const holderName =
340
+ key === 'useViewportSamplingForLinear' ? 'cpuVolume' : 'rendering';
341
+ const holder = holderPair(pair, holderName);
342
+ const rule = `${holderName}.${key}`;
343
+ const value = isShorthand ? pair : pair.field('value');
344
+
345
+ if (!holder) {
346
+ continue;
347
+ }
348
+
349
+ if (!reachesConfigurationCall(configurationOf(pair))) {
350
+ manual.increment(
351
+ site(run.root, `${rule}: not shown to reach init()`, pair)
352
+ );
353
+ continue;
354
+ }
355
+
356
+ if (value && callsSettingFunction(value)) {
357
+ manual.increment(
358
+ site(
359
+ run.root,
360
+ `${rule}: its value calls a removed setting function`,
361
+ pair
362
+ )
363
+ );
364
+ continue;
365
+ }
366
+
367
+ const removes = key !== 'useCPURendering' || value?.text() === 'false';
368
+
369
+ if (removes && (!value || !(isShorthand || isPure(value)))) {
370
+ manual.increment(site(run.root, `${rule}: its value has effects`, pair));
371
+ continue;
372
+ }
373
+
374
+ if (removes) {
375
+ removals.push({ pair, holder, rule });
376
+ continue;
377
+ }
378
+
379
+ const { keys } = objectEntries(pair.parent());
380
+
381
+ if (keys.includes('planar')) {
382
+ manual.increment(site(run.root, 'rendering.useCPURendering', pair));
383
+ continue;
384
+ }
385
+
386
+ const backend =
387
+ value?.text() === 'true'
388
+ ? "'cpu'"
389
+ : `${LOW_PRECEDENCE.has(value.kind()) ? `(${value.text()})` : value.text()} ? 'cpu' : 'auto'`;
390
+
391
+ if (run.edits.add(pair.replace(`planar: { renderBackend: ${backend} }`))) {
392
+ review.increment(
393
+ site(
394
+ run.root,
395
+ 'rendering.useCPURendering: a 3D viewport stays on the GPU',
396
+ pair
397
+ )
398
+ );
399
+ } else {
400
+ manual.increment(site(run.root, rule, pair));
401
+ }
402
+ }
403
+
404
+ removeSettings(run, removals);
405
+ }
406
+
407
+ /**
408
+ * Tells whether an expression refers to a removed setting function of the
409
+ * core, which the function pass rewrites: the pair that holds it is
410
+ * reported, so the two rewrites never replace the same text.
411
+ */
412
+ function callsSettingFunction(value: Node): boolean {
413
+ return [
414
+ value,
415
+ ...value.findAll({
416
+ rule: { any: [{ kind: 'identifier' }, { kind: 'member_expression' }] },
417
+ }),
418
+ ].some((node) => {
419
+ if (node.kind() === 'identifier') {
420
+ return SETTING_FUNCTIONS.has(coreImportOf(node)?.name ?? '');
421
+ }
422
+
423
+ const object = node.field('object');
424
+
425
+ return Boolean(
426
+ node.kind() === 'member_expression' &&
427
+ SETTING_FUNCTIONS.has(node.field('property')?.text() ?? '') &&
428
+ object?.kind() === 'identifier' &&
429
+ isCoreNamespace(object)
430
+ );
431
+ });
432
+ }
433
+
434
+ /**
435
+ * Returns the expression that names a core function at a call, the way the
436
+ * old call named its function.
437
+ */
438
+ function functionRef(
439
+ run: Run,
440
+ call: Node,
441
+ callee: Node,
442
+ name: string
443
+ ): string | undefined {
444
+ if (callee.kind() === 'member_expression') {
445
+ return `${callee.field('object').text()}.${name}`;
446
+ }
447
+
448
+ return run.imports.ensure(name, { at: call });
449
+ }
450
+
451
+ /**
452
+ * Rewrites one call of a removed setting function. Returns whether the call
453
+ * changed. A spread argument, and a call inside text that another rewrite
454
+ * replaces, are reported.
455
+ */
456
+ function rewriteCall(
457
+ run: Run,
458
+ call: Node,
459
+ callee: Node,
460
+ name: string
461
+ ): boolean {
462
+ const args = call
463
+ .field('arguments')
464
+ .children()
465
+ .filter((child) => child.isNamed() && child.kind() !== 'comment');
466
+
467
+ if (args.some((arg) => arg.kind() === 'spread_element')) {
468
+ manual.increment(site(run.root, `${name}: a spread argument`, call));
469
+
470
+ return false;
471
+ }
472
+
473
+ if (
474
+ name === 'getUseGenericViewport' ||
475
+ (name === 'setUseCPURendering' && args.length !== 1)
476
+ ) {
477
+ manual.increment(site(run.root, `${name}()`, call));
478
+
479
+ return false;
480
+ }
481
+
482
+ if (run.edits.covers(call)) {
483
+ manual.increment(site(run.root, name, call));
484
+
485
+ return false;
486
+ }
487
+
488
+ const newName =
489
+ name === 'getShouldUseCPURendering'
490
+ ? 'getEffectiveRenderBackend'
491
+ : 'setRenderBackend';
492
+ const ref = functionRef(run, call, callee, newName);
493
+
494
+ if (!ref) {
495
+ manual.increment(
496
+ site(run.root, `${name}: ${newName} cannot be imported`, call)
497
+ );
498
+
499
+ return false;
500
+ }
501
+
502
+ if (name === 'getShouldUseCPURendering') {
503
+ return run.edits.add(
504
+ call.replace(comparisonAt(call, `${ref}() === 'cpu'`))
505
+ );
506
+ }
507
+
508
+ if (name === 'resetUseCPURendering') {
509
+ return run.edits.add(call.replace(`${ref}('auto')`));
510
+ }
511
+
512
+ const [arg] = args;
513
+ const backend =
514
+ arg.text() === 'true'
515
+ ? "'cpu'"
516
+ : arg.text() === 'false'
517
+ ? "'auto'"
518
+ : `${LOW_PRECEDENCE.has(arg.kind()) ? `(${arg.text()})` : arg.text()} ? 'cpu' : 'auto'`;
519
+ const changed = run.edits.add(call.replace(`${ref}(${backend})`));
520
+
521
+ if (changed) {
522
+ review.increment(
523
+ site(
524
+ run.root,
525
+ 'setUseCPURendering: it marked the library initialized, call init() first',
526
+ call
527
+ )
528
+ );
529
+ }
530
+
531
+ return changed;
532
+ }
533
+
534
+ /**
535
+ * Rewrites a reference to a removed setting function when it is the callee
536
+ * of a call, and reports it otherwise. Returns whether it changed.
537
+ */
538
+ function rewriteReference(run: Run, callee: Node, name: string): boolean {
539
+ const call = callee.parent();
540
+ const isCall =
541
+ call?.kind() === 'call_expression' &&
542
+ call.field('function')?.id() === callee.id();
543
+
544
+ if (!isCall) {
545
+ manual.increment(site(run.root, name, callee));
546
+
547
+ return false;
548
+ }
549
+
550
+ return rewriteCall(run, call, callee, name);
551
+ }
552
+
553
+ /**
554
+ * Rewrites the calls of the removed setting functions, through each named
555
+ * import with its local name or through the core namespace. A named import
556
+ * goes when every reference to it changed.
557
+ */
558
+ function rewriteFunctions(run: Run): void {
559
+ for (const { name, local } of coreSpecifiers(run.rootNode)) {
560
+ if (!SETTING_FUNCTIONS.has(name)) {
561
+ continue;
562
+ }
563
+
564
+ let left = 0;
565
+
566
+ for (const reference of referencesOf(local)) {
567
+ const isIdentifier = reference.kind() === 'identifier';
568
+
569
+ if (!isIdentifier) {
570
+ manual.increment(site(run.root, name, reference));
571
+ }
572
+
573
+ left += isIdentifier && rewriteReference(run, reference, name) ? 0 : 1;
574
+ }
575
+
576
+ if (!left) {
577
+ run.imports.remove(name, local.text());
578
+ }
579
+ }
580
+
581
+ for (const member of run.rootNode.findAll({
582
+ rule: {
583
+ kind: 'member_expression',
584
+ has: {
585
+ field: 'property',
586
+ regex: `^(${[...SETTING_FUNCTIONS].join('|')})$`,
587
+ },
588
+ },
589
+ })) {
590
+ const object = member.field('object');
591
+
592
+ if (object?.kind() === 'identifier' && isCoreNamespace(object)) {
593
+ rewriteReference(run, member, member.field('property').text());
594
+ }
595
+ }
596
+
597
+ for (const { specifier, name } of coreReExports(run.rootNode)) {
598
+ if (SETTING_FUNCTIONS.has(name)) {
599
+ manual.increment(site(run.root, name, specifier));
600
+ }
601
+ }
602
+
603
+ for (const node of run.rootNode.findAll({
604
+ rule: { kind: 'subscript_expression' },
605
+ })) {
606
+ const name = bracketKey(node) ?? '';
607
+ const object = node.field('object');
608
+
609
+ if (
610
+ SETTING_FUNCTIONS.has(name) &&
611
+ object?.kind() === 'identifier' &&
612
+ isCoreNamespace(object)
613
+ ) {
614
+ manual.increment(site(run.root, name, node));
615
+ }
616
+ }
617
+ }
618
+
619
+ /**
620
+ * Rewrites the settings that Cornerstone3D 6.0 removes:
621
+ * `rendering.useGenericViewport` and `useViewportSamplingForLinear` go,
622
+ * `rendering.useCPURendering` becomes `rendering.planar.renderBackend`, and
623
+ * the CPU functions become `setRenderBackend` and `getEffectiveRenderBackend`.
624
+ * `getUseGenericViewport()` is reported.
625
+ */
626
+ const codemod: Codemod<TSX> = (root) => {
627
+ const rootNode = root.root();
628
+ const run: Run = {
629
+ root,
630
+ rootNode,
631
+ imports: new CoreImports(rootNode),
632
+ edits: new EditSet(),
633
+ };
634
+
635
+ rewriteConfiguration(run);
636
+ rewriteFunctions(run);
637
+
638
+ const importEdits = run.imports.edits();
639
+
640
+ if (!run.edits.all().length && !importEdits.length) {
641
+ return null;
642
+ }
643
+
644
+ return rootNode.commitEdits([...run.edits.all(), ...importEdits]);
645
+ };
646
+
647
+ export default codemod;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import * as cornerstone from '@cornerstonejs/core';
3
+ import { getUseGenericViewport, setUseCPURendering } from '@cornerstonejs/core';
4
+
5
+ cornerstone.setRenderBackend('cpu');
6
+ cornerstone.init({
7
+ rendering: { useCPURendering: true, planar: { sliceFirst: false } },
8
+ });
9
+
10
+ export function Toggle() {
11
+ const handlers = [setUseCPURendering];
12
+
13
+ return (
14
+ <button onClick={() => setUseCPURendering(true, false)}>
15
+ {String(getUseGenericViewport())} {handlers.length}
16
+ </button>
17
+ );
18
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import * as cornerstone from '@cornerstonejs/core';
3
+ import { getUseGenericViewport, setUseCPURendering } from '@cornerstonejs/core';
4
+
5
+ cornerstone.setUseCPURendering(true);
6
+ cornerstone.init({
7
+ rendering: { useCPURendering: true, planar: { sliceFirst: false } },
8
+ });
9
+
10
+ export function Toggle() {
11
+ const handlers = [setUseCPURendering];
12
+
13
+ return (
14
+ <button onClick={() => setUseCPURendering(true, false)}>
15
+ {String(getUseGenericViewport())} {handlers.length}
16
+ </button>
17
+ );
18
+ }