@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.
- package/README.md +23 -0
- package/package.json +2 -2
- package/registry/cornerstone3d/6/README.md +87 -0
- package/registry/cornerstone3d/6/classes-and-types/README.md +113 -0
- package/registry/cornerstone3d/6/classes-and-types/codemod.yaml +20 -0
- package/registry/cornerstone3d/6/classes-and-types/scripts/classes-and-types.ts +1461 -0
- package/registry/cornerstone3d/6/classes-and-types/scripts/lib.ts +2386 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/tsx/edge-namespace-and-reported/expected.tsx +27 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/tsx/edge-namespace-and-reported/input.tsx +27 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/tsx/edge-namespace-and-reported/metrics.json +36 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/edge-already-6/expected.ts +15 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/edge-already-6/input.ts +15 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/negative-other-packages/expected.ts +11 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/negative-other-packages/input.ts +11 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-3d-family-of-predicate-or-cast-object/expected.ts +55 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-3d-family-of-predicate-or-cast-object/input.ts +51 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-3d-family-of-predicate-or-cast-object/metrics.json +36 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-types-from-the-types-subpath/expected.ts +26 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-types-from-the-types-subpath/input.ts +26 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/ohif-types-from-the-types-subpath/metrics.json +52 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-3d-evidence/expected.ts +34 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-3d-evidence/input.ts +30 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-3d-evidence/metrics.json +12 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-classes/expected.ts +35 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-classes/input.ts +35 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-classes/metrics.json +28 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-types-and-casts/expected.ts +46 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/positive-types-and-casts/input.ts +42 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-class-import-cleanup-orphans-shorthand/expected.ts +4 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-class-import-cleanup-orphans-shorthand/input.ts +4 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-class-import-cleanup-orphans-shorthand/metrics.json +12 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-check-can-prevent-the-first-mount/expected.ts +24 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-check-can-prevent-the-first-mount/input.ts +25 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-check-can-prevent-the-first-mount/metrics.json +38 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-replacement-inverts-comparison/expected.ts +11 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-replacement-inverts-comparison/input.ts +11 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-instanceof-replacement-inverts-comparison/metrics.json +20 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-negative-3d-test-taken-as-3d-viewport/expected.ts +29 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-negative-3d-test-taken-as-3d-viewport/input.ts +29 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-negative-3d-test-taken-as-3d-viewport/metrics.json +20 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-re-exports-of-removed-classes/expected.ts +6 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-re-exports-of-removed-classes/input.ts +6 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-re-exports-of-removed-classes/metrics.json +20 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-type-only-namespace-used-as-value/expected.ts +8 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-type-only-namespace-used-as-value/input.ts +8 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review-type-only-namespace-used-as-value/metrics.json +12 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-instanceof-mount-proof-crosses-shadowed-binding/expected.ts +19 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-instanceof-mount-proof-crosses-shadowed-binding/input.ts +19 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-instanceof-mount-proof-crosses-shadowed-binding/metrics.json +22 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-unrelated-discriminator-taken-as-3d-proof/expected.ts +40 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-unrelated-discriminator-taken-as-3d-proof/input.ts +40 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review2-unrelated-discriminator-taken-as-3d-proof/metrics.json +28 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review3-conditional-viewport-type-taken-as-3d/expected.ts +39 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review3-conditional-viewport-type-taken-as-3d/input.ts +38 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review3-conditional-viewport-type-taken-as-3d/metrics.json +20 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-spread-or-computed-key-overrides-viewport-type/expected.ts +76 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-spread-or-computed-key-overrides-viewport-type/input.ts +75 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-spread-or-computed-key-overrides-viewport-type/metrics.json +36 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-viewport-family-proved-on-another-engine/expected.ts +92 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-viewport-family-proved-on-another-engine/input.ts +91 -0
- package/registry/cornerstone3d/6/classes-and-types/tests/typescript/review4-viewport-family-proved-on-another-engine/metrics.json +20 -0
- package/registry/cornerstone3d/6/classes-and-types/workflow.yaml +29 -0
- package/registry/cornerstone3d/6/codemod.yaml +19 -0
- package/registry/cornerstone3d/6/display-sets/README.md +173 -0
- package/registry/cornerstone3d/6/display-sets/codemod.yaml +20 -0
- package/registry/cornerstone3d/6/display-sets/scripts/display-sets.ts +965 -0
- package/registry/cornerstone3d/6/display-sets/scripts/lib.ts +2386 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes/expected.tsx +32 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes/input.tsx +32 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes/metrics.json +84 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes-on-a-typed-engine/expected.tsx +33 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes-on-a-typed-engine/input.tsx +33 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/edge-reported-shapes-on-a-typed-engine/metrics.json +84 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/positive-javascript/expected.js +23 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/positive-javascript/input.js +17 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/review-commonjs-module-gets-es-import/expected.js +10 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/review-commonjs-module-gets-es-import/input.js +10 -0
- package/registry/cornerstone3d/6/display-sets/tests/tsx/review-commonjs-module-gets-es-import/metrics.json +12 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/negative-already-6/expected.ts +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/negative-already-6/input.ts +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-set-volumes-for-viewports/expected.ts +27 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-set-volumes-for-viewports/input.ts +27 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-set-volumes-for-viewports/metrics.json +12 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-stack-and-volume/expected.ts +37 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-stack-and-volume/input.ts +31 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-stack-and-volume/metrics.json +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-video-and-ecg/expected.ts +15 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/positive-video-and-ecg/input.ts +15 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-mount-breaks-control-flow/expected.ts +26 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-mount-breaks-control-flow/input.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-mount-breaks-control-flow/metrics.json +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-viewport-lists-and-callback-capture/expected.ts +46 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-conditional-viewport-lists-and-callback-capture/input.ts +21 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-generated-references-resolve-to-shadowing-parameter/expected.ts +23 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-generated-references-resolve-to-shadowing-parameter/input.ts +13 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-optional-mounts-become-unconditional/expected.ts +11 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-optional-mounts-become-unconditional/input.ts +11 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-optional-mounts-become-unconditional/metrics.json +28 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-regenerated-import-drops-comments/expected.ts +22 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-regenerated-import-drops-comments/input.ts +15 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-stack-display-set-id-reused-across-series/expected.ts +41 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-stack-display-set-id-reused-across-series/input.ts +16 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/expected.ts +11 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/input.ts +11 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/metrics.json +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-helper-binding-still-used/expected.ts +46 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-helper-binding-still-used/input.ts +17 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-helper-binding-still-used/metrics.json +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-registration-references-image-list-outside-block/expected.ts +16 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-registration-references-image-list-outside-block/input.ts +16 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review-volume-registration-references-image-list-outside-block/metrics.json +12 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-bracketed-and-re-exported-data-names/expected.ts +19 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-bracketed-and-re-exported-data-names/input.ts +19 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-bracketed-and-re-exported-data-names/metrics.json +44 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-generic-container-taken-as-viewport/expected.ts +22 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-generic-container-taken-as-viewport/input.ts +22 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-generic-container-taken-as-viewport/metrics.json +36 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-image-list-getter-read-twice/expected.ts +62 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-image-list-getter-read-twice/input.ts +28 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-missing-target-partly-updates-layout/expected.ts +50 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-missing-target-partly-updates-layout/input.ts +25 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-missing-target-partly-updates-layout/metrics.json +12 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-reassigned-receiver-keeps-initializer-evidence/expected.ts +45 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-reassigned-receiver-keeps-initializer-evidence/input.ts +39 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-reassigned-receiver-keeps-initializer-evidence/metrics.json +36 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-stack-ids-collide-across-engines/expected.ts +24 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-stack-ids-collide-across-engines/input.ts +12 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-volume-registration-attaches-another-series/expected.ts +47 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-volume-registration-attaches-another-series/input.ts +42 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review2-volume-registration-attaches-another-series/metrics.json +28 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-computed-option-key-overrides-image-ids/expected.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-computed-option-key-overrides-image-ids/input.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-computed-option-key-overrides-image-ids/metrics.json +12 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-loop-increment-taken-as-volume-creation/expected.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-loop-increment-taken-as-volume-creation/input.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-loop-increment-taken-as-volume-creation/metrics.json +12 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-mixed-family-targets-partly-update-layout/expected.ts +42 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-mixed-family-targets-partly-update-layout/input.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-ecg-mount-empty-after-the-call/expected.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-ecg-mount-empty-after-the-call/input.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-ecg-mount-empty-after-the-call/metrics.json +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-helper-blocks-async-function/expected.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-helper-blocks-async-function/input.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-helper-blocks-async-function/metrics.json +12 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-stack-mount-blocks-async-function/expected.ts +19 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-stack-mount-blocks-async-function/input.ts +19 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-stack-mount-blocks-async-function/metrics.json +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-video-mount-empty-after-the-call/expected.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-video-mount-empty-after-the-call/input.ts +18 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-video-mount-empty-after-the-call/metrics.json +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-volume-mount-blocks-async-function/expected.ts +23 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-volume-mount-blocks-async-function/input.ts +23 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-unawaited-volume-mount-blocks-async-function/metrics.json +20 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-viewport-getter-read-three-times/expected.ts +34 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review3-viewport-getter-read-three-times/input.ts +19 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review4-argument-getter-redirects-stack-mount/expected.ts +80 -0
- package/registry/cornerstone3d/6/display-sets/tests/typescript/review4-argument-getter-redirects-stack-mount/input.ts +50 -0
- package/registry/cornerstone3d/6/display-sets/workflow.yaml +29 -0
- package/registry/cornerstone3d/6/events/README.md +65 -0
- package/registry/cornerstone3d/6/events/codemod.yaml +20 -0
- package/registry/cornerstone3d/6/events/scripts/events.ts +442 -0
- package/registry/cornerstone3d/6/events/scripts/lib.ts +2386 -0
- package/registry/cornerstone3d/6/events/tests/tsx/edge-reported-and-conflicts/expected.tsx +18 -0
- package/registry/cornerstone3d/6/events/tests/tsx/edge-reported-and-conflicts/input.tsx +18 -0
- package/registry/cornerstone3d/6/events/tests/tsx/edge-reported-and-conflicts/metrics.json +46 -0
- package/registry/cornerstone3d/6/events/tests/typescript/negative-other-events/expected.ts +10 -0
- package/registry/cornerstone3d/6/events/tests/typescript/negative-other-events/input.ts +10 -0
- package/registry/cornerstone3d/6/events/tests/typescript/ohif-core-events-export/expected.ts +22 -0
- package/registry/cornerstone3d/6/events/tests/typescript/ohif-core-events-export/input.ts +22 -0
- package/registry/cornerstone3d/6/events/tests/typescript/ohif-core-events-export/metrics.json +54 -0
- package/registry/cornerstone3d/6/events/tests/typescript/positive-destructured/expected.ts +20 -0
- package/registry/cornerstone3d/6/events/tests/typescript/positive-destructured/input.ts +20 -0
- package/registry/cornerstone3d/6/events/tests/typescript/positive-destructured/metrics.json +12 -0
- package/registry/cornerstone3d/6/events/tests/typescript/positive-members/expected.ts +16 -0
- package/registry/cornerstone3d/6/events/tests/typescript/positive-members/input.ts +16 -0
- package/registry/cornerstone3d/6/events/tests/typescript/positive-members/metrics.json +52 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-aliased-event-destructuring-left-silently/expected.ts +5 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-aliased-event-destructuring-left-silently/input.ts +5 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-aliased-event-destructuring-left-silently/metrics.json +12 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-event-destructuring-introduces-undeclared-name/expected.ts +9 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-event-destructuring-introduces-undeclared-name/input.ts +10 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-event-destructuring-introduces-undeclared-name/metrics.json +20 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-removed-event-strings-not-reported/expected.ts +11 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-removed-event-strings-not-reported/input.ts +11 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review-removed-event-strings-not-reported/metrics.json +28 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review2-quoted-defaulted-and-bracketed-event-keys/expected.ts +15 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review2-quoted-defaulted-and-bracketed-event-keys/input.ts +15 -0
- package/registry/cornerstone3d/6/events/tests/typescript/review2-quoted-defaulted-and-bracketed-event-keys/metrics.json +62 -0
- package/registry/cornerstone3d/6/events/workflow.yaml +29 -0
- package/registry/cornerstone3d/6/settings/README.md +69 -0
- package/registry/cornerstone3d/6/settings/codemod.yaml +20 -0
- package/registry/cornerstone3d/6/settings/scripts/lib.ts +2386 -0
- package/registry/cornerstone3d/6/settings/scripts/settings.ts +647 -0
- package/registry/cornerstone3d/6/settings/tests/tsx/edge-namespace-and-reported/expected.tsx +18 -0
- package/registry/cornerstone3d/6/settings/tests/tsx/edge-namespace-and-reported/input.tsx +18 -0
- package/registry/cornerstone3d/6/settings/tests/tsx/edge-namespace-and-reported/metrics.json +46 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/negative-other-names/expected.ts +18 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/negative-other-names/input.ts +18 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/positive-configuration/expected.ts +27 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/positive-configuration/input.ts +28 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/positive-configuration/metrics.json +46 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/positive-functions/expected.ts +32 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/positive-functions/input.ts +33 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/positive-functions/metrics.json +36 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-aliased-setting-imports-removed-while-used/expected.ts +10 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-aliased-setting-imports-removed-while-used/input.ts +9 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-aliased-setting-imports-removed-while-used/metrics.json +22 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-generated-references-resolve-to-shadowing-locals/expected.ts +12 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-generated-references-resolve-to-shadowing-locals/input.ts +12 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-import-name-collision-calls-undefined/expected.ts +9 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-import-name-collision-calls-undefined/input.ts +9 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-import-name-collision-calls-undefined/metrics.json +12 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-settings-deletes-unrelated-configuration/expected.ts +12 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-settings-deletes-unrelated-configuration/input.ts +12 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review-settings-deletes-unrelated-configuration/metrics.json +28 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-adjacent-obsolete-settings/expected.ts +24 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-adjacent-obsolete-settings/input.ts +29 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-adjacent-obsolete-settings/metrics.json +12 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-nested-cpu-getter-in-rewritten-setting/expected.ts +3 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-nested-cpu-getter-in-rewritten-setting/input.ts +3 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-nested-cpu-getter-in-rewritten-setting/metrics.json +12 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-re-exported-setting-names/expected.ts +1 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-re-exported-setting-names/input.ts +1 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-re-exported-setting-names/metrics.json +20 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-spread-boolean-tuple/expected.ts +6 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-spread-boolean-tuple/input.ts +6 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review2-spread-boolean-tuple/metrics.json +22 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review3-shorthand-cpu-setting/expected.ts +13 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review3-shorthand-cpu-setting/input.ts +13 -0
- package/registry/cornerstone3d/6/settings/tests/typescript/review3-shorthand-cpu-setting/metrics.json +12 -0
- package/registry/cornerstone3d/6/settings/workflow.yaml +29 -0
- package/registry/cornerstone3d/6/tools/README.md +59 -0
- package/registry/cornerstone3d/6/tools/codemod.yaml +20 -0
- package/registry/cornerstone3d/6/tools/scripts/lib.ts +2386 -0
- package/registry/cornerstone3d/6/tools/scripts/tools.ts +517 -0
- package/registry/cornerstone3d/6/tools/tests/tsx/edge-removed-names/expected.tsx +36 -0
- package/registry/cornerstone3d/6/tools/tests/tsx/edge-removed-names/input.tsx +36 -0
- package/registry/cornerstone3d/6/tools/tests/tsx/edge-removed-names/metrics.json +60 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/negative-other-modules/expected.ts +13 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/negative-other-modules/input.ts +13 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/positive-moved-modules/expected.ts +11 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/positive-moved-modules/input.ts +11 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/positive-viewport-capabilities-to-core/expected.ts +13 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/positive-viewport-capabilities-to-core/input.ts +13 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review-moved-import-collides-with-local/expected.ts +7 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review-moved-import-collides-with-local/input.ts +7 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review-viewport-capabilities-not-plain/expected.ts +26 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review-viewport-capabilities-not-plain/input.ts +26 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review-viewport-capabilities-not-plain/metrics.json +60 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review2-barrel-re-export-of-moved-module/expected.ts +6 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review2-barrel-re-export-of-moved-module/input.ts +6 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review2-barrel-re-export-of-moved-module/metrics.json +28 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review3-side-effect-and-empty-imports-of-deleted-module/expected.ts +12 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review3-side-effect-and-empty-imports-of-deleted-module/input.ts +12 -0
- package/registry/cornerstone3d/6/tools/tests/typescript/review3-side-effect-and-empty-imports-of-deleted-module/metrics.json +36 -0
- package/registry/cornerstone3d/6/tools/workflow.yaml +29 -0
- package/registry/cornerstone3d/6/viewport-members/README.md +101 -0
- package/registry/cornerstone3d/6/viewport-members/codemod.yaml +20 -0
- package/registry/cornerstone3d/6/viewport-members/scripts/lib.ts +2386 -0
- package/registry/cornerstone3d/6/viewport-members/scripts/viewport-members.ts +815 -0
- package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members/expected.tsx +31 -0
- package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members/input.tsx +31 -0
- package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members/metrics.json +100 -0
- package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members-on-a-typed-viewport/expected.tsx +31 -0
- package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members-on-a-typed-viewport/input.tsx +31 -0
- package/registry/cornerstone3d/6/viewport-members/tests/tsx/edge-reported-members-on-a-typed-viewport/metrics.json +100 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/negative-other-receivers/expected.ts +24 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/negative-other-receivers/input.ts +24 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-3d-presentation/expected.ts +11 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-3d-presentation/input.ts +11 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-3d-presentation/metrics.json +28 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-engine-render-frame-of-reference/expected.ts +16 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-engine-render-frame-of-reference/input.ts +16 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-engine-render-frame-of-reference/metrics.json +28 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-presentation-and-view/expected.ts +31 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-presentation-and-view/input.ts +31 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-questions-and-actors/expected.ts +31 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-questions-and-actors/input.ts +26 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-questions-and-actors/metrics.json +22 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-video-and-ecg/expected.ts +15 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-video-and-ecg/input.ts +15 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/positive-video-and-ecg/metrics.json +28 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-generated-imports-invalidate-file-directives/expected.ts +5 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-generated-imports-invalidate-file-directives/input.ts +5 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-generated-imports-invalidate-file-directives/metrics.json +12 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-quoted-presentation-key-loses-effect/expected.ts +12 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-quoted-presentation-key-loses-effect/input.ts +12 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-quoted-presentation-key-loses-effect/metrics.json +12 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-slice-index-rewrite-mishandles-references/expected.ts +12 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-slice-index-rewrite-mishandles-references/input.ts +12 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-slice-index-rewrite-mishandles-references/metrics.json +20 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/expected.ts +9 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/input.ts +9 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/metrics.json +20 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-bracket-access-hides-removed-methods/expected.ts +11 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-bracket-access-hides-removed-methods/input.ts +11 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-bracket-access-hides-removed-methods/metrics.json +36 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-re-exported-core-helpers/expected.ts +5 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-re-exported-core-helpers/input.ts +5 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review2-re-exported-core-helpers/metrics.json +20 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review3-conditional-mount-drops-presentation/expected.ts +58 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review3-conditional-mount-drops-presentation/input.ts +58 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review3-conditional-mount-drops-presentation/metrics.json +20 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review4-strict-bounds-and-actor-volume-ids/expected.ts +16 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review4-strict-bounds-and-actor-volume-ids/input.ts +16 -0
- package/registry/cornerstone3d/6/viewport-members/tests/typescript/review4-strict-bounds-and-actor-volume-ids/metrics.json +12 -0
- package/registry/cornerstone3d/6/viewport-members/workflow.yaml +29 -0
- package/registry/cornerstone3d/6/viewport-types/README.md +73 -0
- package/registry/cornerstone3d/6/viewport-types/codemod.yaml +20 -0
- package/registry/cornerstone3d/6/viewport-types/scripts/lib.ts +2386 -0
- package/registry/cornerstone3d/6/viewport-types/scripts/viewport-types.ts +714 -0
- package/registry/cornerstone3d/6/viewport-types/tests/tsx/edge-reported-sites/expected.tsx +57 -0
- package/registry/cornerstone3d/6/viewport-types/tests/tsx/edge-reported-sites/input.tsx +57 -0
- package/registry/cornerstone3d/6/viewport-types/tests/tsx/edge-reported-sites/metrics.json +70 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/edge-already-6/expected.ts +25 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/edge-already-6/input.ts +25 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/negative-other-names/expected.ts +22 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/negative-other-names/input.ts +22 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-destructured-viewport-type/expected.ts +68 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-destructured-viewport-type/input.ts +65 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-destructured-viewport-type/metrics.json +46 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-namespaced-and-aliased/expected.ts +20 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-namespaced-and-aliased/input.ts +19 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-namespaced-and-aliased/metrics.json +12 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-strings/expected.ts +25 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-strings/input.ts +24 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/positive-strings/metrics.json +22 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-destructured-viewport-type-members/expected.ts +19 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-destructured-viewport-type-members/input.ts +19 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-destructured-viewport-type-members/metrics.json +12 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-type-check-can-prevent-the-first-mount/expected.ts +27 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-type-check-can-prevent-the-first-mount/input.ts +27 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-type-check-can-prevent-the-first-mount/metrics.json +28 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/expected.ts +9 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/input.ts +9 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-like-name-rewrites-unrelated-objects/metrics.json +20 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-type-pass-changes-unrelated-discriminators/expected.ts +18 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-type-pass-changes-unrelated-discriminators/input.ts +18 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review-viewport-type-pass-changes-unrelated-discriminators/metrics.json +30 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-mount-proof-crosses-shadowed-binding/expected.ts +42 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-mount-proof-crosses-shadowed-binding/input.ts +42 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-mount-proof-crosses-shadowed-binding/metrics.json +36 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-quoted-defaulted-and-bracketed-viewport-type-keys/expected.ts +10 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-quoted-defaulted-and-bracketed-viewport-type-keys/input.ts +10 -0
- package/registry/cornerstone3d/6/viewport-types/tests/typescript/review2-quoted-defaulted-and-bracketed-viewport-type-keys/metrics.json +36 -0
- package/registry/cornerstone3d/6/viewport-types/workflow.yaml +29 -0
- package/registry/cornerstone3d/6/workflow.yaml +26 -0
- package/scripts/test-registry-packages.mjs +86 -0
- package/scripts/validate-registry-packages.mjs +43 -2
|
@@ -0,0 +1,714 @@
|
|
|
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
|
+
CoreImports,
|
|
6
|
+
EditSet,
|
|
7
|
+
bracketKey,
|
|
8
|
+
declarationNodeOf,
|
|
9
|
+
indentOf,
|
|
10
|
+
isCoreEnum,
|
|
11
|
+
isMountedBefore,
|
|
12
|
+
isRenderingEngine,
|
|
13
|
+
methodCall,
|
|
14
|
+
objectEntries,
|
|
15
|
+
referencesOf,
|
|
16
|
+
site,
|
|
17
|
+
staticKeyName,
|
|
18
|
+
unwrap,
|
|
19
|
+
viewportEvidence,
|
|
20
|
+
} from './lib.ts';
|
|
21
|
+
import type { Node, ViewportEvidence } from './lib.ts';
|
|
22
|
+
|
|
23
|
+
/** Sites that the reader changes. */
|
|
24
|
+
const manual = useMetricAtom('cornerstone3d-6-manual');
|
|
25
|
+
|
|
26
|
+
/** Rewrites at a decision of the migration guide. */
|
|
27
|
+
const review = useMetricAtom('cornerstone3d-6-review');
|
|
28
|
+
|
|
29
|
+
/** The deprecated `_NEXT` members and their plain names. */
|
|
30
|
+
const NEXT_MEMBERS: Record<string, string> = {
|
|
31
|
+
PLANAR_NEXT: 'PLANAR',
|
|
32
|
+
VOLUME_3D_NEXT: 'VOLUME_3D',
|
|
33
|
+
VIDEO_NEXT: 'VIDEO',
|
|
34
|
+
WHOLE_SLIDE_NEXT: 'WHOLE_SLIDE',
|
|
35
|
+
ECG_NEXT: 'ECG',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** The content mode that a comparison with a removed type asks for. */
|
|
39
|
+
const MODE_OF_LEGACY: Record<string, string> = {
|
|
40
|
+
STACK: 'stack',
|
|
41
|
+
ORTHOGRAPHIC: 'volume',
|
|
42
|
+
stack: 'stack',
|
|
43
|
+
orthographic: 'volume',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The deprecated `*Next` strings and their plain strings. */
|
|
47
|
+
const NEXT_STRINGS: Record<string, string> = {
|
|
48
|
+
planarNext: 'planar',
|
|
49
|
+
volume3dNext: 'volume3d',
|
|
50
|
+
videoNext: 'video',
|
|
51
|
+
wholeSlideNext: 'wholeSlide',
|
|
52
|
+
ecgNext: 'ecg',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** The removed strings of a viewport input. */
|
|
56
|
+
const LEGACY_STRINGS = new Set(['stack', 'orthographic', 'perspective']);
|
|
57
|
+
|
|
58
|
+
/** The operators of an equality test. */
|
|
59
|
+
const EQUALITY = new Set(['===', '!==', '==', '!=']);
|
|
60
|
+
|
|
61
|
+
/** The keys that make an object literal a viewport input. */
|
|
62
|
+
const INPUT_KEYS = ['viewportId', 'element'];
|
|
63
|
+
|
|
64
|
+
/** The methods of a rendering engine that take viewport inputs. */
|
|
65
|
+
const INPUT_METHODS = new Set(['enableElement', 'setViewports']);
|
|
66
|
+
|
|
67
|
+
/** The parents through which a viewport input keeps flowing to a call. */
|
|
68
|
+
const FLOW_KINDS = new Set([
|
|
69
|
+
'parenthesized_expression',
|
|
70
|
+
'as_expression',
|
|
71
|
+
'satisfies_expression',
|
|
72
|
+
'array',
|
|
73
|
+
'spread_element',
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns the pair `type: value` whose value holds the node, through
|
|
78
|
+
* parentheses and the branches of a conditional, or undefined.
|
|
79
|
+
*/
|
|
80
|
+
function typePairOf(node: Node): { pair: Node; direct: boolean } | undefined {
|
|
81
|
+
let current = node;
|
|
82
|
+
let direct = true;
|
|
83
|
+
|
|
84
|
+
for (;;) {
|
|
85
|
+
const parent = current.parent();
|
|
86
|
+
|
|
87
|
+
if (!parent) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (parent.kind() === 'parenthesized_expression') {
|
|
92
|
+
current = parent;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (
|
|
97
|
+
parent.kind() === 'ternary_expression' &&
|
|
98
|
+
parent.field('condition')?.id() !== current.id()
|
|
99
|
+
) {
|
|
100
|
+
direct = false;
|
|
101
|
+
current = parent;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (
|
|
106
|
+
parent.kind() === 'pair' &&
|
|
107
|
+
parent.field('value')?.id() === current.id()
|
|
108
|
+
) {
|
|
109
|
+
const key = parent.field('key');
|
|
110
|
+
const name =
|
|
111
|
+
key?.kind() === 'string' ? key.text().slice(1, -1) : key?.text();
|
|
112
|
+
|
|
113
|
+
return name === 'type' ? { pair: parent, direct } : undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Tells whether an object literal has the keys of a viewport input.
|
|
122
|
+
*/
|
|
123
|
+
function isViewportInput(objectNode: Node): boolean {
|
|
124
|
+
const { keys } = objectEntries(objectNode);
|
|
125
|
+
|
|
126
|
+
return INPUT_KEYS.some((key) => keys.includes(key));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Tells whether a variable reaches `enableElement` or `setViewports` of a
|
|
131
|
+
* core rendering engine through one of its references.
|
|
132
|
+
*/
|
|
133
|
+
function variableReaches(name: Node, depth: number): boolean {
|
|
134
|
+
return referencesOf(name).some(
|
|
135
|
+
(reference) =>
|
|
136
|
+
reference.kind() === 'identifier' &&
|
|
137
|
+
reachesViewportCall(reference, depth + 1)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Tells whether a value reaches `enableElement` or `setViewports` of a core
|
|
143
|
+
* rendering engine in the file: as an argument, as an entry of an array
|
|
144
|
+
* argument, pushed onto such an array, or through a variable that holds it.
|
|
145
|
+
*/
|
|
146
|
+
function reachesViewportCall(node: Node, depth = 0): boolean {
|
|
147
|
+
if (depth > 3) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let current = node;
|
|
152
|
+
|
|
153
|
+
while (FLOW_KINDS.has(current.parent()?.kind() ?? '')) {
|
|
154
|
+
current = current.parent();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const parent = current.parent();
|
|
158
|
+
|
|
159
|
+
if (parent?.kind() === 'arguments') {
|
|
160
|
+
const call = methodCall(parent.parent());
|
|
161
|
+
|
|
162
|
+
if (call && INPUT_METHODS.has(call.method)) {
|
|
163
|
+
return isRenderingEngine(call.object);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const array =
|
|
167
|
+
call?.method === 'push' && call.object.kind() === 'identifier'
|
|
168
|
+
? declarationNodeOf(call.object)
|
|
169
|
+
: undefined;
|
|
170
|
+
|
|
171
|
+
return Boolean(array && variableReaches(array, depth));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const name =
|
|
175
|
+
parent?.kind() === 'variable_declarator' &&
|
|
176
|
+
parent.field('value')?.id() === current.id()
|
|
177
|
+
? parent.field('name')
|
|
178
|
+
: undefined;
|
|
179
|
+
|
|
180
|
+
return Boolean(name?.kind() === 'identifier' && variableReaches(name, depth));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Returns the other operand of an equality test when it is `<viewport>.type`,
|
|
185
|
+
* with what shows that its object is a viewport.
|
|
186
|
+
*/
|
|
187
|
+
function comparedViewport(node: Node):
|
|
188
|
+
| {
|
|
189
|
+
binary: Node;
|
|
190
|
+
viewport: Node;
|
|
191
|
+
operator: string;
|
|
192
|
+
evidence: ViewportEvidence;
|
|
193
|
+
optional: boolean;
|
|
194
|
+
}
|
|
195
|
+
| undefined {
|
|
196
|
+
let current = node;
|
|
197
|
+
|
|
198
|
+
while (current.parent()?.kind() === 'parenthesized_expression') {
|
|
199
|
+
current = current.parent();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const binary = current.parent();
|
|
203
|
+
|
|
204
|
+
if (binary?.kind() !== 'binary_expression') {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const operator = binary.field('operator')?.text() ?? '';
|
|
209
|
+
|
|
210
|
+
if (!EQUALITY.has(operator)) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const left = binary.field('left');
|
|
215
|
+
const right = binary.field('right');
|
|
216
|
+
const other = unwrap(left?.id() === current.id() ? right : left);
|
|
217
|
+
const evidence =
|
|
218
|
+
other?.kind() === 'member_expression' &&
|
|
219
|
+
other.field('property')?.text() === 'type'
|
|
220
|
+
? viewportEvidence(other.field('object'))
|
|
221
|
+
: undefined;
|
|
222
|
+
|
|
223
|
+
if (!evidence) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
binary,
|
|
229
|
+
viewport: other.field('object'),
|
|
230
|
+
operator,
|
|
231
|
+
evidence,
|
|
232
|
+
optional: other
|
|
233
|
+
.children()
|
|
234
|
+
.some((child) => child.kind() === 'optional_chain'),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Rewrites a comparison of the type of a viewport with a removed type to a
|
|
240
|
+
* test of its content mode, when an awaited mount of the same binding of the
|
|
241
|
+
* viewport runs before it in its function: the type of a viewport is known
|
|
242
|
+
* from its creation, its mode only from its first mount. Reports the
|
|
243
|
+
* comparison otherwise. `?.type` keeps its `?.`.
|
|
244
|
+
*/
|
|
245
|
+
function rewriteModeTest(
|
|
246
|
+
run: Run,
|
|
247
|
+
comparison: ReturnType<typeof comparedViewport>,
|
|
248
|
+
mode: string,
|
|
249
|
+
rule: string,
|
|
250
|
+
node: Node
|
|
251
|
+
): void {
|
|
252
|
+
if (!isMountedBefore(comparison.binary, comparison.viewport)) {
|
|
253
|
+
manual.increment(
|
|
254
|
+
site(run.root, `${rule}: the viewport may not show its data yet`, node)
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const operator = comparison.operator.startsWith('!') ? '!==' : '===';
|
|
261
|
+
const access = comparison.optional ? '?.' : '.';
|
|
262
|
+
|
|
263
|
+
run.edits.add(
|
|
264
|
+
comparison.binary.replace(
|
|
265
|
+
`${comparison.viewport.text()}${access}getCurrentMode() ${operator} '${mode}'`
|
|
266
|
+
)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Tells whether a node is a value that names a viewport type to make: the
|
|
272
|
+
* value of a variable, a return value, the body of an arrow function or the
|
|
273
|
+
* right side of an assignment to `.type`.
|
|
274
|
+
*/
|
|
275
|
+
function isTypeValuePosition(node: Node): boolean {
|
|
276
|
+
const parent = node.parent();
|
|
277
|
+
const kind = parent?.kind();
|
|
278
|
+
|
|
279
|
+
if (
|
|
280
|
+
kind === 'variable_declarator' &&
|
|
281
|
+
parent.field('value')?.id() === node.id()
|
|
282
|
+
) {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (kind === 'return_statement') {
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (kind === 'arrow_function' && parent.field('body')?.id() === node.id()) {
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (
|
|
295
|
+
kind === 'assignment_expression' &&
|
|
296
|
+
parent.field('right')?.id() === node.id()
|
|
297
|
+
) {
|
|
298
|
+
return parent.field('left')?.text().endsWith('.type') ?? false;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The state of one run of the transform on a file.
|
|
306
|
+
*/
|
|
307
|
+
interface Run {
|
|
308
|
+
root: SgRoot<TSX>;
|
|
309
|
+
rootNode: Node;
|
|
310
|
+
imports: CoreImports;
|
|
311
|
+
edits: EditSet;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Writes the 5.x default orientation of an orthographic viewport into a
|
|
316
|
+
* viewport input that has none, and reports the site for review. Reports the
|
|
317
|
+
* site as manual when the options cannot be read.
|
|
318
|
+
*/
|
|
319
|
+
function addDefaultOrientation(run: Run, typePair: Node, rule: string): void {
|
|
320
|
+
const objectNode = typePair.parent();
|
|
321
|
+
const { pairs, shorthand, hasSpread } = objectEntries(objectNode);
|
|
322
|
+
|
|
323
|
+
if (shorthand.has('defaultOptions') || hasSpread) {
|
|
324
|
+
manual.increment(site(run.root, `${rule}: orientation`, typePair));
|
|
325
|
+
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const optionsPair = pairs.get('defaultOptions');
|
|
330
|
+
|
|
331
|
+
if (optionsPair) {
|
|
332
|
+
const options = optionsPair.field('value');
|
|
333
|
+
|
|
334
|
+
if (options?.kind() !== 'object') {
|
|
335
|
+
manual.increment(site(run.root, `${rule}: orientation`, typePair));
|
|
336
|
+
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const optionEntries = objectEntries(options);
|
|
341
|
+
|
|
342
|
+
if (optionEntries.keys.includes('orientation')) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (optionEntries.hasSpread) {
|
|
347
|
+
manual.increment(site(run.root, `${rule}: orientation`, typePair));
|
|
348
|
+
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const enums = run.imports.ensure('Enums', { at: typePair });
|
|
354
|
+
|
|
355
|
+
if (!enums) {
|
|
356
|
+
manual.increment(site(run.root, `${rule}: orientation`, typePair));
|
|
357
|
+
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const axial = `${enums}.OrientationAxis.AXIAL`;
|
|
362
|
+
const multiline = objectNode.text().includes('\n');
|
|
363
|
+
|
|
364
|
+
if (optionsPair) {
|
|
365
|
+
const options = optionsPair.field('value');
|
|
366
|
+
const first = options
|
|
367
|
+
.children()
|
|
368
|
+
.find((child) => child.isNamed() && child.kind() !== 'comment');
|
|
369
|
+
const comment = options
|
|
370
|
+
.children()
|
|
371
|
+
.find((child) => child.kind() === 'comment');
|
|
372
|
+
|
|
373
|
+
if (!first && comment) {
|
|
374
|
+
const brace = options.children()[0].range().end.index;
|
|
375
|
+
|
|
376
|
+
run.edits.add({
|
|
377
|
+
startPos: brace,
|
|
378
|
+
endPos: brace,
|
|
379
|
+
insertedText: `\n${indentOf(run.rootNode, comment)}orientation: ${axial},`,
|
|
380
|
+
});
|
|
381
|
+
} else if (!first) {
|
|
382
|
+
run.edits.add(options.replace(`{ orientation: ${axial} }`));
|
|
383
|
+
} else {
|
|
384
|
+
const separator = options.text().includes('\n')
|
|
385
|
+
? `\n${indentOf(run.rootNode, first)}`
|
|
386
|
+
: ' ';
|
|
387
|
+
const start = first.range().start.index;
|
|
388
|
+
|
|
389
|
+
run.edits.add({
|
|
390
|
+
startPos: start,
|
|
391
|
+
endPos: start,
|
|
392
|
+
insertedText: `orientation: ${axial},${separator}`,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
} else {
|
|
396
|
+
const separator = multiline ? `\n${indentOf(run.rootNode, typePair)}` : ' ';
|
|
397
|
+
const end = typePair.range().end.index;
|
|
398
|
+
|
|
399
|
+
run.edits.add({
|
|
400
|
+
startPos: end,
|
|
401
|
+
endPos: end,
|
|
402
|
+
insertedText: `,${separator}defaultOptions: { orientation: ${axial} }`,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
review.increment(
|
|
407
|
+
site(run.root, `${rule}: default orientation AXIAL`, typePair)
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Rewrites one use of a removed or deprecated `ViewportType` member.
|
|
413
|
+
*/
|
|
414
|
+
function rewriteMember(run: Run, node: Node, member: string): void {
|
|
415
|
+
const property = node.field('property');
|
|
416
|
+
|
|
417
|
+
if (NEXT_MEMBERS[member]) {
|
|
418
|
+
run.edits.add(property.replace(NEXT_MEMBERS[member]));
|
|
419
|
+
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const rule = `ViewportType.${member}`;
|
|
424
|
+
|
|
425
|
+
if (member === 'PERSPECTIVE') {
|
|
426
|
+
manual.increment(site(run.root, rule, node));
|
|
427
|
+
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const comparison = comparedViewport(node);
|
|
432
|
+
|
|
433
|
+
if (comparison?.evidence === 'name') {
|
|
434
|
+
manual.increment(site(run.root, rule, node));
|
|
435
|
+
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (comparison) {
|
|
440
|
+
rewriteModeTest(run, comparison, MODE_OF_LEGACY[member], rule, node);
|
|
441
|
+
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const typePair = typePairOf(node);
|
|
446
|
+
|
|
447
|
+
if (typePair || isTypeValuePosition(node)) {
|
|
448
|
+
run.edits.add(property.replace('PLANAR'));
|
|
449
|
+
|
|
450
|
+
if (member !== 'ORTHOGRAPHIC') {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (typePair?.direct && isViewportInput(typePair.pair.parent())) {
|
|
455
|
+
addDefaultOrientation(run, typePair.pair, rule);
|
|
456
|
+
} else {
|
|
457
|
+
review.increment(site(run.root, `${rule}: orientation`, node));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
manual.increment(site(run.root, rule, node));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Rewrites one string that names a removed or deprecated viewport type: in
|
|
468
|
+
* a comparison with the type of a viewport of the core, or as the `type` of
|
|
469
|
+
* a viewport input that reaches `enableElement` or `setViewports`. An object
|
|
470
|
+
* with the keys of a viewport input that does not is reported.
|
|
471
|
+
*/
|
|
472
|
+
function rewriteString(run: Run, node: Node, value: string): void {
|
|
473
|
+
const quote = node.text()[0];
|
|
474
|
+
const comparison = comparedViewport(node);
|
|
475
|
+
|
|
476
|
+
if (comparison?.evidence === 'name') {
|
|
477
|
+
manual.increment(site(run.root, `'${value}'`, node));
|
|
478
|
+
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (comparison) {
|
|
483
|
+
if (NEXT_STRINGS[value]) {
|
|
484
|
+
run.edits.add(node.replace(`${quote}${NEXT_STRINGS[value]}${quote}`));
|
|
485
|
+
} else if (MODE_OF_LEGACY[value]) {
|
|
486
|
+
rewriteModeTest(
|
|
487
|
+
run,
|
|
488
|
+
comparison,
|
|
489
|
+
MODE_OF_LEGACY[value],
|
|
490
|
+
`'${value}'`,
|
|
491
|
+
node
|
|
492
|
+
);
|
|
493
|
+
} else {
|
|
494
|
+
manual.increment(site(run.root, `'${value}'`, node));
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const typePair = typePairOf(node);
|
|
501
|
+
const objectNode = typePair?.pair.parent();
|
|
502
|
+
const looksLikeInput = Boolean(objectNode && isViewportInput(objectNode));
|
|
503
|
+
|
|
504
|
+
if (looksLikeInput && value === 'perspective') {
|
|
505
|
+
manual.increment(site(run.root, `'${value}'`, node));
|
|
506
|
+
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (looksLikeInput && !reachesViewportCall(objectNode)) {
|
|
511
|
+
manual.increment(
|
|
512
|
+
site(run.root, `'${value}': not shown to be a viewport input`, node)
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (!looksLikeInput) {
|
|
519
|
+
if (NEXT_STRINGS[value]) {
|
|
520
|
+
manual.increment(site(run.root, `'${value}'`, node));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (NEXT_STRINGS[value]) {
|
|
527
|
+
run.edits.add(node.replace(`${quote}${NEXT_STRINGS[value]}${quote}`));
|
|
528
|
+
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
run.edits.add(node.replace(`${quote}planar${quote}`));
|
|
533
|
+
|
|
534
|
+
if (value === 'orthographic') {
|
|
535
|
+
if (typePair.direct) {
|
|
536
|
+
addDefaultOrientation(run, typePair.pair, `'${value}'`);
|
|
537
|
+
} else {
|
|
538
|
+
review.increment(site(run.root, `'${value}': orientation`, node));
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Reports the viewport options that a planar viewport does not apply by
|
|
545
|
+
* itself.
|
|
546
|
+
*/
|
|
547
|
+
function reportInputOptions(run: Run, typePair: Node): void {
|
|
548
|
+
const objectNode = typePair.parent();
|
|
549
|
+
|
|
550
|
+
if (!isViewportInput(objectNode)) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const options = objectEntries(objectNode)
|
|
555
|
+
.pairs.get('defaultOptions')
|
|
556
|
+
?.field('value');
|
|
557
|
+
|
|
558
|
+
if (options?.kind() !== 'object') {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const { pairs, shorthand } = objectEntries(options);
|
|
563
|
+
|
|
564
|
+
for (const key of ['displayArea', 'aspectRatio']) {
|
|
565
|
+
const entry = pairs.get(key) ?? (shorthand.has(key) ? options : undefined);
|
|
566
|
+
|
|
567
|
+
if (entry) {
|
|
568
|
+
manual.increment(site(run.root, `defaultOptions.${key}`, entry));
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Rewrites the keys that a pattern takes out of the core
|
|
575
|
+
* `Enums.ViewportType`: a `_NEXT` key gets its plain name and keeps its local
|
|
576
|
+
* name (a quoted key keeps its quotes, a shorthand with a default value
|
|
577
|
+
* keeps its local name and its default), and a removed key is reported. A
|
|
578
|
+
* key computed from code and a rest element can take any member, so they
|
|
579
|
+
* are reported.
|
|
580
|
+
*/
|
|
581
|
+
function rewriteDestructured(run: Run): void {
|
|
582
|
+
for (const pattern of run.rootNode.findAll({
|
|
583
|
+
rule: { kind: 'object_pattern' },
|
|
584
|
+
})) {
|
|
585
|
+
const declarator = pattern.parent();
|
|
586
|
+
const value =
|
|
587
|
+
declarator?.kind() === 'variable_declarator' &&
|
|
588
|
+
declarator.field('name')?.id() === pattern.id()
|
|
589
|
+
? declarator.field('value')
|
|
590
|
+
: undefined;
|
|
591
|
+
|
|
592
|
+
if (!value || !isCoreEnum(value, 'ViewportType')) {
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
for (const entry of pattern.children()) {
|
|
597
|
+
const kind = entry.kind();
|
|
598
|
+
const keyNode =
|
|
599
|
+
kind === 'shorthand_property_identifier_pattern'
|
|
600
|
+
? entry
|
|
601
|
+
: kind === 'object_assignment_pattern'
|
|
602
|
+
? entry.field('left')
|
|
603
|
+
: kind === 'pair_pattern'
|
|
604
|
+
? entry.field('key')
|
|
605
|
+
: undefined;
|
|
606
|
+
const member = staticKeyName(keyNode);
|
|
607
|
+
|
|
608
|
+
if (kind === 'rest_pattern' || (keyNode && !member)) {
|
|
609
|
+
manual.increment(
|
|
610
|
+
site(run.root, 'ViewportType: a rest or computed key', entry)
|
|
611
|
+
);
|
|
612
|
+
} else if (NEXT_MEMBERS[member] && kind === 'pair_pattern') {
|
|
613
|
+
const string =
|
|
614
|
+
keyNode.kind() === 'string'
|
|
615
|
+
? keyNode
|
|
616
|
+
: keyNode.find({ rule: { kind: 'string' } });
|
|
617
|
+
const quote = string ? string.text()[0] : '';
|
|
618
|
+
|
|
619
|
+
run.edits.add(
|
|
620
|
+
(string ?? keyNode).replace(`${quote}${NEXT_MEMBERS[member]}${quote}`)
|
|
621
|
+
);
|
|
622
|
+
} else if (NEXT_MEMBERS[member]) {
|
|
623
|
+
run.edits.add(keyNode.replace(`${NEXT_MEMBERS[member]}: ${member}`));
|
|
624
|
+
} else if (/^(STACK|ORTHOGRAPHIC|PERSPECTIVE)$/.test(member ?? '')) {
|
|
625
|
+
manual.increment(site(run.root, `ViewportType.${member}`, entry));
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Reports a bracket access with a string key to a removed or deprecated
|
|
633
|
+
* member of the core `Enums.ViewportType`, such as
|
|
634
|
+
* `Enums.ViewportType['STACK']`.
|
|
635
|
+
*/
|
|
636
|
+
function reportBracketMembers(run: Run): void {
|
|
637
|
+
for (const node of run.rootNode.findAll({
|
|
638
|
+
rule: { kind: 'subscript_expression' },
|
|
639
|
+
})) {
|
|
640
|
+
const member = bracketKey(node);
|
|
641
|
+
const isMember =
|
|
642
|
+
Boolean(member && NEXT_MEMBERS[member]) ||
|
|
643
|
+
/^(STACK|ORTHOGRAPHIC|PERSPECTIVE)$/.test(member ?? '');
|
|
644
|
+
|
|
645
|
+
if (isMember && isCoreEnum(node.field('object'), 'ViewportType')) {
|
|
646
|
+
manual.increment(site(run.root, `ViewportType.${member}`, node));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Rewrites the removed and deprecated viewport types of Cornerstone3D 5.x:
|
|
653
|
+
* `STACK` and `ORTHOGRAPHIC` in a viewport input become `PLANAR`, a comparison
|
|
654
|
+
* with `viewport.type` asks for the content mode, the `_NEXT` members and
|
|
655
|
+
* the `*Next` strings get their plain names. `PERSPECTIVE` and every other
|
|
656
|
+
* site are reported.
|
|
657
|
+
*/
|
|
658
|
+
const codemod: Codemod<TSX> = (root) => {
|
|
659
|
+
const rootNode = root.root();
|
|
660
|
+
const run: Run = {
|
|
661
|
+
root,
|
|
662
|
+
rootNode,
|
|
663
|
+
imports: new CoreImports(rootNode),
|
|
664
|
+
edits: new EditSet(),
|
|
665
|
+
};
|
|
666
|
+
const members = rootNode.findAll({
|
|
667
|
+
rule: {
|
|
668
|
+
kind: 'member_expression',
|
|
669
|
+
has: {
|
|
670
|
+
field: 'property',
|
|
671
|
+
regex:
|
|
672
|
+
'^(STACK|ORTHOGRAPHIC|PERSPECTIVE|PLANAR_NEXT|VOLUME_3D_NEXT|VIDEO_NEXT|WHOLE_SLIDE_NEXT|ECG_NEXT)$',
|
|
673
|
+
},
|
|
674
|
+
},
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
for (const node of members) {
|
|
678
|
+
const member = node.field('property').text();
|
|
679
|
+
|
|
680
|
+
if (isCoreEnum(node.field('object'), 'ViewportType')) {
|
|
681
|
+
rewriteMember(run, node, member);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const strings = rootNode.findAll({
|
|
686
|
+
rule: {
|
|
687
|
+
kind: 'string',
|
|
688
|
+
regex: `^['"](${[...LEGACY_STRINGS, ...Object.keys(NEXT_STRINGS)].join('|')})['"]$`,
|
|
689
|
+
},
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
for (const node of strings) {
|
|
693
|
+
rewriteString(run, node, node.text().slice(1, -1));
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const typePairs = rootNode.findAll({
|
|
697
|
+
rule: { kind: 'pair', has: { field: 'key', regex: '^type$' } },
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
for (const pair of typePairs) {
|
|
701
|
+
reportInputOptions(run, pair);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
rewriteDestructured(run);
|
|
705
|
+
reportBracketMembers(run);
|
|
706
|
+
|
|
707
|
+
if (!run.edits.all().length) {
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return rootNode.commitEdits([...run.edits.all(), ...run.imports.edits()]);
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
export default codemod;
|