@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,965 @@
|
|
|
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
|
+
asPrimary,
|
|
8
|
+
bindsAt,
|
|
9
|
+
bracketKey,
|
|
10
|
+
coreImportOf,
|
|
11
|
+
coreReExports,
|
|
12
|
+
coreSpecifiers,
|
|
13
|
+
isCoreExport,
|
|
14
|
+
isCoreNamespace,
|
|
15
|
+
isOptionalCall,
|
|
16
|
+
isPlainValue,
|
|
17
|
+
isRepeatable,
|
|
18
|
+
methodCall,
|
|
19
|
+
objectEntries,
|
|
20
|
+
referencesOf,
|
|
21
|
+
replaceStatement,
|
|
22
|
+
site,
|
|
23
|
+
stableBinding,
|
|
24
|
+
statementOfCall,
|
|
25
|
+
statementsBefore,
|
|
26
|
+
unwrap,
|
|
27
|
+
viewportEvidence,
|
|
28
|
+
} from './lib.ts';
|
|
29
|
+
import type { Node } from './lib.ts';
|
|
30
|
+
|
|
31
|
+
/** Sites that the reader changes. */
|
|
32
|
+
const manual = useMetricAtom('cornerstone3d-6-manual');
|
|
33
|
+
|
|
34
|
+
/** The data members of the legacy viewports that the transform reports. */
|
|
35
|
+
const REPORTED_MEMBERS = new Set([
|
|
36
|
+
'addVolumes',
|
|
37
|
+
'setWSI',
|
|
38
|
+
'setDataIds',
|
|
39
|
+
'setDataList',
|
|
40
|
+
'removeVolumeActors',
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
/** The data functions of the core that the transform reports. */
|
|
44
|
+
const REPORTED_FUNCTIONS = new Set([
|
|
45
|
+
'addVolumesToViewports',
|
|
46
|
+
'convertStackToVolumeViewport',
|
|
47
|
+
'convertVolumeToStackViewport',
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The nodes between a call and its statement through which the call runs
|
|
52
|
+
* whenever the statement runs.
|
|
53
|
+
*/
|
|
54
|
+
const UNCONDITIONAL_KINDS = new Set([
|
|
55
|
+
'expression_statement',
|
|
56
|
+
'lexical_declaration',
|
|
57
|
+
'variable_declaration',
|
|
58
|
+
'variable_declarator',
|
|
59
|
+
'await_expression',
|
|
60
|
+
'parenthesized_expression',
|
|
61
|
+
'as_expression',
|
|
62
|
+
'non_null_expression',
|
|
63
|
+
'arguments',
|
|
64
|
+
'array',
|
|
65
|
+
'call_expression',
|
|
66
|
+
'member_expression',
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The statements that run every part of their expression whenever they run:
|
|
71
|
+
* an expression statement and a declaration, never a loop, an `if` or a
|
|
72
|
+
* `return`.
|
|
73
|
+
*/
|
|
74
|
+
const PLAIN_STATEMENTS = new Set([
|
|
75
|
+
'expression_statement',
|
|
76
|
+
'lexical_declaration',
|
|
77
|
+
'variable_declaration',
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
/** The members whose presence a legacy check tests with `in`. */
|
|
81
|
+
const PRESENCE_CHECKS = new Set([
|
|
82
|
+
'setStack',
|
|
83
|
+
'setVolumes',
|
|
84
|
+
'setVideo',
|
|
85
|
+
'setWSI',
|
|
86
|
+
'setEcg',
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The state of one run of the transform on a file.
|
|
91
|
+
*/
|
|
92
|
+
interface Run {
|
|
93
|
+
root: SgRoot<TSX>;
|
|
94
|
+
rootNode: Node;
|
|
95
|
+
imports: CoreImports;
|
|
96
|
+
edits: EditSet;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns the arguments of a call, without comments.
|
|
101
|
+
*/
|
|
102
|
+
function argumentsOf(call: Node): Node[] {
|
|
103
|
+
return call
|
|
104
|
+
.field('arguments')
|
|
105
|
+
.children()
|
|
106
|
+
.filter((child) => child.isNamed() && child.kind() !== 'comment');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Returns what identifies the value of a volume id at a node: the text of a
|
|
111
|
+
* string, or the declaration of a name whose binding holds one value. Two
|
|
112
|
+
* volume ids with one key have one value. Returns undefined for any other
|
|
113
|
+
* expression.
|
|
114
|
+
*/
|
|
115
|
+
function volumeIdKey(node: Node): string | undefined {
|
|
116
|
+
if (node.kind() === 'string') {
|
|
117
|
+
return `string:${node.text().slice(1, -1)}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const binding =
|
|
121
|
+
node.kind() === 'identifier' ||
|
|
122
|
+
node.kind() === 'shorthand_property_identifier'
|
|
123
|
+
? stableBinding(node)
|
|
124
|
+
: undefined;
|
|
125
|
+
|
|
126
|
+
return binding ? `binding:${binding.range().start.index}` : undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Returns the volume id of a volume input list `[{ volumeId }]` with exactly
|
|
131
|
+
* one input that holds only its volume id, or the reason why not.
|
|
132
|
+
*/
|
|
133
|
+
function singleVolumeId(list: Node | undefined): {
|
|
134
|
+
volumeId?: Node;
|
|
135
|
+
reason?: string;
|
|
136
|
+
} {
|
|
137
|
+
if (list?.kind() !== 'array') {
|
|
138
|
+
return { reason: 'the inputs are not an array literal' };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const inputs = list
|
|
142
|
+
.children()
|
|
143
|
+
.filter((child) => child.isNamed() && child.kind() !== 'comment');
|
|
144
|
+
|
|
145
|
+
if (inputs.length !== 1 || inputs[0].kind() !== 'object') {
|
|
146
|
+
return { reason: 'more than one input' };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const { pairs, shorthand, hasSpread, keys } = objectEntries(inputs[0]);
|
|
150
|
+
|
|
151
|
+
if (hasSpread || keys.length !== 1 || !keys.includes('volumeId')) {
|
|
152
|
+
const other = keys.find((key) => key !== 'volumeId') ?? 'a spread';
|
|
153
|
+
|
|
154
|
+
return { reason: `the input has ${other}` };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const volumeId = shorthand.has('volumeId')
|
|
158
|
+
? inputs[0]
|
|
159
|
+
.children()
|
|
160
|
+
.find((child) => child.kind() === 'shorthand_property_identifier')
|
|
161
|
+
: pairs.get('volumeId').field('value');
|
|
162
|
+
|
|
163
|
+
return volumeIdKey(volumeId)
|
|
164
|
+
? { volumeId }
|
|
165
|
+
: { reason: 'the volume id is not a const name or a string' };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Tells whether a call of `createAndCacheVolume` comes from the core.
|
|
170
|
+
*/
|
|
171
|
+
function isCoreVolumeCreation(call: Node): boolean {
|
|
172
|
+
const callee = call.field('function');
|
|
173
|
+
|
|
174
|
+
if (callee?.kind() === 'identifier') {
|
|
175
|
+
return coreImportOf(callee)?.name === 'createAndCacheVolume';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return Boolean(
|
|
179
|
+
callee?.kind() === 'member_expression' &&
|
|
180
|
+
callee.field('property')?.text() === 'createAndCacheVolume' &&
|
|
181
|
+
isCoreExport(callee.field('object'), 'volumeLoader')
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Tells whether an object literal has a key computed in brackets, such as
|
|
187
|
+
* `['imageIds']` or `[key]`: it can name a key that another entry names, and
|
|
188
|
+
* the later entry wins.
|
|
189
|
+
*/
|
|
190
|
+
function hasComputedKey(objectNode: Node): boolean {
|
|
191
|
+
return objectNode
|
|
192
|
+
.children()
|
|
193
|
+
.some(
|
|
194
|
+
(child) =>
|
|
195
|
+
child.kind() === 'pair' &&
|
|
196
|
+
child.field('key')?.kind() === 'computed_property_name'
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Returns the image ids expression of the volume that the function of the
|
|
202
|
+
* target creates with `createAndCacheVolume(volumeId, { imageIds })` on
|
|
203
|
+
* every path to the target, or undefined. The volume id of the creation has
|
|
204
|
+
* the value of the volume id at the target (one string, or one binding that
|
|
205
|
+
* holds one value), and the image ids are a name whose binding holds one
|
|
206
|
+
* value and is seen at the target. Options with a computed key, or with
|
|
207
|
+
* `imageIds` twice, give no image ids: the loader takes the last entry.
|
|
208
|
+
*/
|
|
209
|
+
function imageIdsOfVolume(
|
|
210
|
+
run: Run,
|
|
211
|
+
volumeId: Node,
|
|
212
|
+
target: Node
|
|
213
|
+
): string | undefined {
|
|
214
|
+
const key = volumeIdKey(volumeId);
|
|
215
|
+
const found = new Set<string>();
|
|
216
|
+
const creations = statementsBefore(target).flatMap((statement) =>
|
|
217
|
+
statement
|
|
218
|
+
.findAll({ rule: { kind: 'call_expression' } })
|
|
219
|
+
.filter((call) => isCoreVolumeCreation(call) && runsWith(call, statement))
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
for (const call of creations) {
|
|
223
|
+
const [id, options] = argumentsOf(call);
|
|
224
|
+
|
|
225
|
+
if (!id || volumeIdKey(id) !== key) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (options?.kind() !== 'object') {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const { pairs, shorthand, hasSpread, keys } = objectEntries(options);
|
|
234
|
+
|
|
235
|
+
if (
|
|
236
|
+
hasSpread ||
|
|
237
|
+
hasComputedKey(options) ||
|
|
238
|
+
keys.filter((name) => name === 'imageIds').length > 1
|
|
239
|
+
) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const imageIds = shorthand.has('imageIds')
|
|
244
|
+
? options
|
|
245
|
+
.children()
|
|
246
|
+
.find(
|
|
247
|
+
(child) =>
|
|
248
|
+
child.kind() === 'shorthand_property_identifier' &&
|
|
249
|
+
child.text() === 'imageIds'
|
|
250
|
+
)
|
|
251
|
+
: pairs.get('imageIds')?.field('value');
|
|
252
|
+
const binding =
|
|
253
|
+
imageIds?.kind() === 'identifier' ||
|
|
254
|
+
imageIds?.kind() === 'shorthand_property_identifier'
|
|
255
|
+
? stableBinding(imageIds)
|
|
256
|
+
: undefined;
|
|
257
|
+
|
|
258
|
+
if (!binding || !bindsAt(run.rootNode, binding, target)) {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
found.add(imageIds.text());
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return found.size === 1 ? [...found][0] : undefined;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Tells whether a call runs whenever its statement runs: the statement is an
|
|
270
|
+
* expression statement or a declaration, and the nodes between them are
|
|
271
|
+
* declarations, `await`, parentheses, casts, arrays, arguments and the calls
|
|
272
|
+
* and member reads that hold them, never a condition, a loop or a function.
|
|
273
|
+
* A call in a part of a loop or of an `if`, such as the increment of a `for`
|
|
274
|
+
* that its body leaves with `break`, proves nothing.
|
|
275
|
+
*/
|
|
276
|
+
function runsWith(call: Node, statement: Node): boolean {
|
|
277
|
+
for (const ancestor of call.ancestors()) {
|
|
278
|
+
if (ancestor.id() === statement.id()) {
|
|
279
|
+
return PLAIN_STATEMENTS.has(statement.kind());
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (
|
|
283
|
+
!UNCONDITIONAL_KINDS.has(ancestor.kind()) ||
|
|
284
|
+
ancestor.children().some((child) => child.kind() === 'optional_chain')
|
|
285
|
+
) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Tells whether the code waits for a call where it makes it, or hands its
|
|
295
|
+
* promise on: the call, in parentheses or not, is under `await`, is the value
|
|
296
|
+
* of a `return` or is the body of an arrow function. Code after any other
|
|
297
|
+
* call runs before the mount ends.
|
|
298
|
+
*/
|
|
299
|
+
function isWaitedFor(call: Node): boolean {
|
|
300
|
+
let node = call;
|
|
301
|
+
let parent = call.parent();
|
|
302
|
+
|
|
303
|
+
while (parent?.kind() === 'parenthesized_expression') {
|
|
304
|
+
node = parent;
|
|
305
|
+
parent = parent.parent();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (
|
|
309
|
+
parent?.kind() === 'await_expression' ||
|
|
310
|
+
parent?.kind() === 'return_statement'
|
|
311
|
+
) {
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
parent?.kind() === 'arrow_function' &&
|
|
317
|
+
parent.field('body')?.id() === node.id()
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Formats the registration of a planar display set.
|
|
323
|
+
*/
|
|
324
|
+
function registration(
|
|
325
|
+
utilities: string,
|
|
326
|
+
idText: string,
|
|
327
|
+
entries: Array<[string, string]>,
|
|
328
|
+
indent: string
|
|
329
|
+
): string {
|
|
330
|
+
const lines = entries.map(
|
|
331
|
+
([key, value]) => `${indent} ${key === value ? key : `${key}: ${value}`},`
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
return `${utilities}.genericViewportDisplaySetMetadataProvider.add(${idText}, {\n${indent} kind: 'planar',\n${lines.join('\n')}\n${indent}});`;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Formats the awaited call that mounts a display set by the expression of its
|
|
339
|
+
* id.
|
|
340
|
+
*/
|
|
341
|
+
function mountCall(viewport: string, id: string): string {
|
|
342
|
+
const key = id === 'displaySetId' ? id : `displaySetId: ${id}`;
|
|
343
|
+
|
|
344
|
+
return `await ${viewport}.setDisplaySets({ ${key} });`;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Returns why a data call cannot become statements, or undefined: an
|
|
349
|
+
* optional call would mount on a missing viewport, and a call inside an
|
|
350
|
+
* expression has no statement to expand.
|
|
351
|
+
*/
|
|
352
|
+
function statementReason(call: Node): string | undefined {
|
|
353
|
+
if (isOptionalCall(call)) {
|
|
354
|
+
return 'an optional call';
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return statementOfCall(call) ? undefined : 'not a statement';
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Returns `base`, or `base2`, `base3` and so on: the first that is none of
|
|
362
|
+
* the names.
|
|
363
|
+
*/
|
|
364
|
+
function freshAmong(base: string, taken: Set<string>): string {
|
|
365
|
+
for (let index = 1; ; index += 1) {
|
|
366
|
+
const name = index === 1 ? base : `${base}${index}`;
|
|
367
|
+
|
|
368
|
+
if (!taken.has(name)) {
|
|
369
|
+
return name;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Returns `viewportId`, or `viewportId2` and so on: the first that is none
|
|
376
|
+
* of the names.
|
|
377
|
+
*/
|
|
378
|
+
function callbackParameter(taken: Set<string>): string {
|
|
379
|
+
return freshAmong('viewportId', taken);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Returns an expression without the parentheses around it.
|
|
384
|
+
*/
|
|
385
|
+
function withoutParentheses(node: Node): Node {
|
|
386
|
+
let current = node;
|
|
387
|
+
|
|
388
|
+
while (current.kind() === 'parenthesized_expression') {
|
|
389
|
+
const inner = current
|
|
390
|
+
.children()
|
|
391
|
+
.find((child) => child.isNamed() && child.kind() !== 'comment');
|
|
392
|
+
|
|
393
|
+
if (!inner) {
|
|
394
|
+
return current;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
current = inner;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return current;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Rewrites `viewport.setStack(imageIds, index)` in a statement to the
|
|
405
|
+
* registration of a display set and its mount. The display set id is the
|
|
406
|
+
* JSON of the rendering engine id, the viewport id and the first image id,
|
|
407
|
+
* so another series gets another id, two engines never share one, and no
|
|
408
|
+
* two of these tuples give one text. A viewport that is a property read,
|
|
409
|
+
* such as a getter, is read once into a `const` before the image list, and
|
|
410
|
+
* so is a name that a write can change (a `let`, a `var`, a written
|
|
411
|
+
* parameter) when an argument can run code, such as a getter that assigns
|
|
412
|
+
* it; an image list that is not a plain value is read once into a `const`,
|
|
413
|
+
* as the old call read each once and in that order. A call that is not
|
|
414
|
+
* awaited is reported: 5.x set the image ids and the index before its
|
|
415
|
+
* promise, so the code after it saw them, where a 6.0 viewport shows nothing
|
|
416
|
+
* before its mount ends, and only the reader knows which of the two the code
|
|
417
|
+
* needs.
|
|
418
|
+
*/
|
|
419
|
+
function rewriteSetStack(
|
|
420
|
+
run: Run,
|
|
421
|
+
call: Node,
|
|
422
|
+
object: Node,
|
|
423
|
+
args: Node[]
|
|
424
|
+
): void {
|
|
425
|
+
const statementInfo = statementOfCall(call);
|
|
426
|
+
const reason =
|
|
427
|
+
statementReason(call) ??
|
|
428
|
+
(!isRepeatable(object)
|
|
429
|
+
? 'the viewport is not a name'
|
|
430
|
+
: args.some((arg) => arg.kind() === 'spread_element')
|
|
431
|
+
? 'a spread argument'
|
|
432
|
+
: args.length < 1 || args.length > 2
|
|
433
|
+
? 'the arguments'
|
|
434
|
+
: !statementInfo?.awaited
|
|
435
|
+
? 'not awaited'
|
|
436
|
+
: undefined);
|
|
437
|
+
const utilities = reason
|
|
438
|
+
? undefined
|
|
439
|
+
: run.imports.ensure('utilities', { at: call });
|
|
440
|
+
|
|
441
|
+
if (reason || !utilities) {
|
|
442
|
+
manual.increment(
|
|
443
|
+
site(
|
|
444
|
+
run.root,
|
|
445
|
+
`setStack: ${reason ?? 'utilities cannot be imported'}`,
|
|
446
|
+
call
|
|
447
|
+
)
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const { statement } = statementInfo;
|
|
454
|
+
const target = unwrap(object);
|
|
455
|
+
const viewportLocal =
|
|
456
|
+
target.kind() === 'this' ||
|
|
457
|
+
(target.kind() === 'identifier' &&
|
|
458
|
+
(stableBinding(target) || args.every((arg) => isPlainValue(arg))))
|
|
459
|
+
? undefined
|
|
460
|
+
: run.imports.fresh('viewport');
|
|
461
|
+
const receiver = viewportLocal ?? target.text();
|
|
462
|
+
const [list, indexArg] = args;
|
|
463
|
+
const listLocal = isPlainValue(list)
|
|
464
|
+
? undefined
|
|
465
|
+
: run.imports.fresh('imageIds');
|
|
466
|
+
const firstElement =
|
|
467
|
+
list.kind() === 'array'
|
|
468
|
+
? list
|
|
469
|
+
.children()
|
|
470
|
+
.find((child) => child.isNamed() && child.kind() !== 'comment')
|
|
471
|
+
: undefined;
|
|
472
|
+
const first =
|
|
473
|
+
!listLocal && firstElement
|
|
474
|
+
? firstElement.text()
|
|
475
|
+
: `${listLocal ?? asPrimary(list)}[0]`;
|
|
476
|
+
const idLocal = run.imports.fresh('displaySetId');
|
|
477
|
+
const index = indexArg?.text() ?? '0';
|
|
478
|
+
const edit = replaceStatement(run.rootNode, statement, (indent) => [
|
|
479
|
+
...(viewportLocal
|
|
480
|
+
? [`const ${viewportLocal} = ${withoutParentheses(object).text()};`]
|
|
481
|
+
: []),
|
|
482
|
+
...(listLocal ? [`const ${listLocal} = ${list.text()};`] : []),
|
|
483
|
+
`const ${idLocal} = JSON.stringify([${receiver}.renderingEngineId, ${receiver}.id, ${first}]);`,
|
|
484
|
+
registration(
|
|
485
|
+
utilities,
|
|
486
|
+
idLocal,
|
|
487
|
+
[
|
|
488
|
+
['imageIds', listLocal ?? list.text()],
|
|
489
|
+
['initialImageIdIndex', index],
|
|
490
|
+
],
|
|
491
|
+
indent
|
|
492
|
+
),
|
|
493
|
+
mountCall(viewportLocal ?? object.text(), idLocal),
|
|
494
|
+
]);
|
|
495
|
+
|
|
496
|
+
if (!run.edits.add(edit)) {
|
|
497
|
+
manual.increment(site(run.root, 'setStack', call));
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Rewrites `viewport.setVolumes([{ volumeId }])` in a statement to the
|
|
503
|
+
* registration of a display set under the volume id and its mount. A call
|
|
504
|
+
* that is not awaited is reported: the code after it saw the camera of a 5.x
|
|
505
|
+
* volume viewport, where a 6.0 viewport has no view before its mount ends.
|
|
506
|
+
*/
|
|
507
|
+
function rewriteSetVolumes(
|
|
508
|
+
run: Run,
|
|
509
|
+
call: Node,
|
|
510
|
+
object: Node,
|
|
511
|
+
args: Node[]
|
|
512
|
+
): void {
|
|
513
|
+
const statementInfo = statementOfCall(call);
|
|
514
|
+
const { volumeId, reason: inputReason } = singleVolumeId(args[0]);
|
|
515
|
+
const imageIds = volumeId ? imageIdsOfVolume(run, volumeId, call) : undefined;
|
|
516
|
+
const reason =
|
|
517
|
+
statementReason(call) ??
|
|
518
|
+
(args.length !== 1
|
|
519
|
+
? 'more arguments'
|
|
520
|
+
: (inputReason ??
|
|
521
|
+
(!imageIds
|
|
522
|
+
? 'the image ids of the volume are not known'
|
|
523
|
+
: !statementInfo?.awaited
|
|
524
|
+
? 'not awaited'
|
|
525
|
+
: undefined)));
|
|
526
|
+
const utilities = reason
|
|
527
|
+
? undefined
|
|
528
|
+
: run.imports.ensure('utilities', { at: call });
|
|
529
|
+
|
|
530
|
+
if (reason || !utilities) {
|
|
531
|
+
manual.increment(
|
|
532
|
+
site(
|
|
533
|
+
run.root,
|
|
534
|
+
`setVolumes: ${reason ?? 'utilities cannot be imported'}`,
|
|
535
|
+
call
|
|
536
|
+
)
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const { statement } = statementInfo;
|
|
543
|
+
const id = volumeId.text();
|
|
544
|
+
const edit = replaceStatement(run.rootNode, statement, (indent) => [
|
|
545
|
+
registration(
|
|
546
|
+
utilities,
|
|
547
|
+
id,
|
|
548
|
+
[
|
|
549
|
+
['imageIds', imageIds],
|
|
550
|
+
['volumeId', id],
|
|
551
|
+
],
|
|
552
|
+
indent
|
|
553
|
+
),
|
|
554
|
+
mountCall(object.text(), id),
|
|
555
|
+
]);
|
|
556
|
+
|
|
557
|
+
if (!run.edits.add(edit)) {
|
|
558
|
+
manual.increment(site(run.root, 'setVolumes', call));
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Rewrites `setVolumesForViewports(engine, [{ volumeId }], viewportIds)` in a
|
|
564
|
+
* statement to the registration and a mount on each viewport. As in 5.x,
|
|
565
|
+
* every viewport is looked up and checked before any mount starts: a
|
|
566
|
+
* missing one, or one that is not planar or 3D (5.x took only viewports with
|
|
567
|
+
* `setVolumes`), throws before the registration. An engine that is not a
|
|
568
|
+
* name is read once into a local first, as the call read it once. A call
|
|
569
|
+
* that is not awaited is reported: 5.x gave a promise that the code did not
|
|
570
|
+
* wait for, where the new statements wait for every mount or throw.
|
|
571
|
+
*/
|
|
572
|
+
function rewriteSetVolumesForViewports(run: Run, call: Node): boolean {
|
|
573
|
+
const args = argumentsOf(call);
|
|
574
|
+
const statementInfo = statementOfCall(call);
|
|
575
|
+
const { volumeId, reason: inputReason } = singleVolumeId(args[1]);
|
|
576
|
+
const imageIds = volumeId ? imageIdsOfVolume(run, volumeId, call) : undefined;
|
|
577
|
+
const awaits = statementInfo?.awaited;
|
|
578
|
+
const reason =
|
|
579
|
+
statementReason(call) ??
|
|
580
|
+
(args.some((arg) => arg.kind() === 'spread_element')
|
|
581
|
+
? 'a spread argument'
|
|
582
|
+
: args.length !== 3
|
|
583
|
+
? 'the arguments'
|
|
584
|
+
: (inputReason ??
|
|
585
|
+
(!imageIds
|
|
586
|
+
? 'the image ids of the volume are not known'
|
|
587
|
+
: !awaits
|
|
588
|
+
? 'not awaited'
|
|
589
|
+
: undefined)));
|
|
590
|
+
const utilities = reason
|
|
591
|
+
? undefined
|
|
592
|
+
: run.imports.ensure('utilities', { at: call });
|
|
593
|
+
const enums = utilities
|
|
594
|
+
? run.imports.ensure('Enums', { at: call })
|
|
595
|
+
: undefined;
|
|
596
|
+
|
|
597
|
+
if (reason || !utilities || !enums) {
|
|
598
|
+
const missing = utilities ? 'Enums' : 'utilities';
|
|
599
|
+
|
|
600
|
+
manual.increment(
|
|
601
|
+
site(
|
|
602
|
+
run.root,
|
|
603
|
+
`setVolumesForViewports: ${reason ?? `${missing} cannot be imported`}`,
|
|
604
|
+
call
|
|
605
|
+
)
|
|
606
|
+
);
|
|
607
|
+
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const { statement } = statementInfo;
|
|
612
|
+
const [engine, , list] = args;
|
|
613
|
+
const id = volumeId.text();
|
|
614
|
+
const engineLocal =
|
|
615
|
+
engine.kind() === 'identifier'
|
|
616
|
+
? undefined
|
|
617
|
+
: run.imports.fresh('renderingEngine');
|
|
618
|
+
const engineText = engineLocal ?? engine.text();
|
|
619
|
+
const taken = new Set(
|
|
620
|
+
[engine, volumeId]
|
|
621
|
+
.flatMap((node) => [
|
|
622
|
+
node,
|
|
623
|
+
...node.findAll({ rule: { kind: 'identifier' } }),
|
|
624
|
+
])
|
|
625
|
+
.map((node) => node.text())
|
|
626
|
+
);
|
|
627
|
+
const parameter = callbackParameter(taken);
|
|
628
|
+
const element = freshAmong(
|
|
629
|
+
'viewport',
|
|
630
|
+
new Set([...taken, parameter, engineText])
|
|
631
|
+
);
|
|
632
|
+
const viewports = run.imports.fresh('viewports');
|
|
633
|
+
const edit = replaceStatement(run.rootNode, statement, (indent) => [
|
|
634
|
+
...(engineLocal ? [`const ${engineLocal} = ${engine.text()};`] : []),
|
|
635
|
+
[
|
|
636
|
+
`const ${viewports} = ${asPrimary(list)}.map((${parameter}) => {`,
|
|
637
|
+
`${indent} const ${element} = ${engineText}.getViewport(${parameter});`,
|
|
638
|
+
'',
|
|
639
|
+
`${indent} if (!${element}) {`,
|
|
640
|
+
`${indent} throw new Error(\`Viewport with Id \${${parameter}} does not exist\`);`,
|
|
641
|
+
`${indent} }`,
|
|
642
|
+
'',
|
|
643
|
+
`${indent} if (`,
|
|
644
|
+
`${indent} ${element}.type !== ${enums}.ViewportType.PLANAR &&`,
|
|
645
|
+
`${indent} ${element}.type !== ${enums}.ViewportType.VOLUME_3D`,
|
|
646
|
+
`${indent} ) {`,
|
|
647
|
+
`${indent} throw new Error(`,
|
|
648
|
+
`${indent} 'setVolumesForViewports only supports viewports that implement setVolumes'`,
|
|
649
|
+
`${indent} );`,
|
|
650
|
+
`${indent} }`,
|
|
651
|
+
'',
|
|
652
|
+
`${indent} return ${element};`,
|
|
653
|
+
`${indent}});`,
|
|
654
|
+
].join('\n'),
|
|
655
|
+
'',
|
|
656
|
+
registration(
|
|
657
|
+
utilities,
|
|
658
|
+
id,
|
|
659
|
+
[
|
|
660
|
+
['imageIds', imageIds],
|
|
661
|
+
['volumeId', id],
|
|
662
|
+
],
|
|
663
|
+
indent
|
|
664
|
+
),
|
|
665
|
+
'',
|
|
666
|
+
[
|
|
667
|
+
'await Promise.all(',
|
|
668
|
+
`${indent} ${viewports}.map((${element}) => ${element}.setDisplaySets({ displaySetId: ${id} }))`,
|
|
669
|
+
`${indent});`,
|
|
670
|
+
].join('\n'),
|
|
671
|
+
]);
|
|
672
|
+
|
|
673
|
+
if (run.edits.add(edit)) {
|
|
674
|
+
return true;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
manual.increment(site(run.root, 'setVolumesForViewports', call));
|
|
678
|
+
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Rewrites `setVideo(imageId, frameNumber)` and `setEcg(imageId)` to
|
|
684
|
+
* `setDisplaySets`, the image id as the display set id. A call that the code
|
|
685
|
+
* does not wait for or hand on is reported: 5.x set the image id (a video
|
|
686
|
+
* also its frame count and its source) before its promise, so the code after
|
|
687
|
+
* it saw them, where a 6.0 viewport shows nothing before its mount ends.
|
|
688
|
+
*/
|
|
689
|
+
function rewriteSingleSource(
|
|
690
|
+
run: Run,
|
|
691
|
+
call: Node,
|
|
692
|
+
property: Node,
|
|
693
|
+
args: Node[],
|
|
694
|
+
method: string
|
|
695
|
+
): void {
|
|
696
|
+
const maxArgs = method === 'setVideo' ? 2 : 1;
|
|
697
|
+
|
|
698
|
+
if (
|
|
699
|
+
args.length < 1 ||
|
|
700
|
+
args.length > maxArgs ||
|
|
701
|
+
args.some((arg) => arg.kind() === 'spread_element')
|
|
702
|
+
) {
|
|
703
|
+
manual.increment(site(run.root, `${method}: the arguments`, call));
|
|
704
|
+
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
if (!isWaitedFor(call)) {
|
|
709
|
+
manual.increment(site(run.root, `${method}: not awaited`, call));
|
|
710
|
+
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const options = args[1]
|
|
715
|
+
? `, options: { frameNumber: ${args[1].text()} }`
|
|
716
|
+
: '';
|
|
717
|
+
|
|
718
|
+
run.edits.add(
|
|
719
|
+
property.replace('setDisplaySets'),
|
|
720
|
+
call
|
|
721
|
+
.field('arguments')
|
|
722
|
+
.replace(`({ displaySetId: ${args[0].text()}${options} })`)
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Rewrites and reports the data calls on the viewports.
|
|
728
|
+
*/
|
|
729
|
+
function rewriteMembers(run: Run): void {
|
|
730
|
+
const names = [
|
|
731
|
+
'setStack',
|
|
732
|
+
'setVolumes',
|
|
733
|
+
'setVideo',
|
|
734
|
+
'setEcg',
|
|
735
|
+
...REPORTED_MEMBERS,
|
|
736
|
+
].join('|');
|
|
737
|
+
const calls = run.rootNode.findAll({
|
|
738
|
+
rule: {
|
|
739
|
+
kind: 'call_expression',
|
|
740
|
+
has: {
|
|
741
|
+
field: 'function',
|
|
742
|
+
kind: 'member_expression',
|
|
743
|
+
has: { field: 'property', regex: `^(${names})$` },
|
|
744
|
+
},
|
|
745
|
+
},
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
for (const call of calls) {
|
|
749
|
+
const { object, property, method, args } = methodCall(call);
|
|
750
|
+
|
|
751
|
+
if (REPORTED_MEMBERS.has(method) || viewportEvidence(object) !== 'core') {
|
|
752
|
+
manual.increment(site(run.root, method, call));
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (method === 'setStack') {
|
|
757
|
+
rewriteSetStack(run, call, object, args);
|
|
758
|
+
} else if (method === 'setVolumes') {
|
|
759
|
+
rewriteSetVolumes(run, call, object, args);
|
|
760
|
+
} else {
|
|
761
|
+
rewriteSingleSource(run, call, property, args, method);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Returns the core data function that a callee names, through its import,
|
|
768
|
+
* the core namespace or the core `utilities`.
|
|
769
|
+
*/
|
|
770
|
+
function coreDataFunction(callee: Node): string | undefined {
|
|
771
|
+
const names = ['setVolumesForViewports', ...REPORTED_FUNCTIONS];
|
|
772
|
+
|
|
773
|
+
if (callee.kind() === 'identifier') {
|
|
774
|
+
const name = coreImportOf(callee)?.name;
|
|
775
|
+
|
|
776
|
+
return name && names.includes(name) ? name : undefined;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
if (callee.kind() !== 'member_expression') {
|
|
780
|
+
return undefined;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const name = callee.field('property')?.text() ?? '';
|
|
784
|
+
const object = callee.field('object');
|
|
785
|
+
|
|
786
|
+
if (!names.includes(name)) {
|
|
787
|
+
return undefined;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
return isCoreExport(object, 'utilities') ||
|
|
791
|
+
(object?.kind() === 'identifier' && isCoreNamespace(object))
|
|
792
|
+
? name
|
|
793
|
+
: undefined;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Rewrites and reports the data functions of the core. Each other reference
|
|
798
|
+
* to an import of `setVolumesForViewports`, such as a shorthand property or
|
|
799
|
+
* an alias read as a value, is reported; the import goes when every
|
|
800
|
+
* reference was a call that the transform rewrote.
|
|
801
|
+
*/
|
|
802
|
+
function rewriteFunctions(run: Run): void {
|
|
803
|
+
const rewritten = new Set<number>();
|
|
804
|
+
const reported = new Set<number>();
|
|
805
|
+
|
|
806
|
+
for (const call of run.rootNode.findAll({
|
|
807
|
+
rule: { kind: 'call_expression' },
|
|
808
|
+
})) {
|
|
809
|
+
const callee = call.field('function');
|
|
810
|
+
const name = callee ? coreDataFunction(callee) : undefined;
|
|
811
|
+
|
|
812
|
+
if (!name) {
|
|
813
|
+
continue;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const changed =
|
|
817
|
+
name === 'setVolumesForViewports' &&
|
|
818
|
+
rewriteSetVolumesForViewports(run, call);
|
|
819
|
+
|
|
820
|
+
if (name !== 'setVolumesForViewports') {
|
|
821
|
+
manual.increment(site(run.root, name, call));
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
(changed ? rewritten : reported).add(callee.range().start.index);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
for (const { name, local } of coreSpecifiers(run.rootNode)) {
|
|
828
|
+
if (name !== 'setVolumesForViewports') {
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
let left = 0;
|
|
833
|
+
|
|
834
|
+
for (const reference of referencesOf(local)) {
|
|
835
|
+
const start = reference.range().start.index;
|
|
836
|
+
|
|
837
|
+
if (!rewritten.has(start) && !reported.has(start)) {
|
|
838
|
+
manual.increment(site(run.root, name, reference));
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
left += rewritten.has(start) ? 0 : 1;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
if (!left && rewritten.size) {
|
|
845
|
+
run.imports.remove(name, local.text());
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
for (const { specifier, name } of coreReExports(run.rootNode)) {
|
|
850
|
+
if (name === 'setVolumesForViewports' || REPORTED_FUNCTIONS.has(name)) {
|
|
851
|
+
manual.increment(site(run.root, name, specifier));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Reports a bracket access with a string key to a data member, such as
|
|
858
|
+
* `viewport['setStack'](imageIds)`: it names the member that
|
|
859
|
+
* `viewport.setStack` names.
|
|
860
|
+
*/
|
|
861
|
+
function reportBracketMembers(run: Run): void {
|
|
862
|
+
const names = new Set([
|
|
863
|
+
'setStack',
|
|
864
|
+
'setVolumes',
|
|
865
|
+
'setVideo',
|
|
866
|
+
'setEcg',
|
|
867
|
+
...REPORTED_MEMBERS,
|
|
868
|
+
...PRESENCE_CHECKS,
|
|
869
|
+
]);
|
|
870
|
+
|
|
871
|
+
for (const node of run.rootNode.findAll({
|
|
872
|
+
rule: { kind: 'subscript_expression' },
|
|
873
|
+
})) {
|
|
874
|
+
const name = bracketKey(node);
|
|
875
|
+
const parent = node.parent();
|
|
876
|
+
|
|
877
|
+
if (!name || !names.has(name)) {
|
|
878
|
+
continue;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
const isCall =
|
|
882
|
+
parent?.kind() === 'call_expression' &&
|
|
883
|
+
parent.field('function')?.id() === node.id();
|
|
884
|
+
|
|
885
|
+
manual.increment(site(run.root, isCall ? name : `${name} read`, node));
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Reports `'setStack' in viewport`, a read of `viewport.setStack` that is not
|
|
891
|
+
* a call (`typeof viewport.setStack === 'function'`) and their kin: false for
|
|
892
|
+
* every 6.0 viewport.
|
|
893
|
+
*/
|
|
894
|
+
function reportPresenceChecks(run: Run): void {
|
|
895
|
+
for (const binary of run.rootNode.findAll({
|
|
896
|
+
rule: {
|
|
897
|
+
kind: 'binary_expression',
|
|
898
|
+
has: { field: 'operator', regex: '^in$' },
|
|
899
|
+
},
|
|
900
|
+
})) {
|
|
901
|
+
const left = binary.field('left');
|
|
902
|
+
|
|
903
|
+
if (
|
|
904
|
+
left?.kind() === 'string' &&
|
|
905
|
+
PRESENCE_CHECKS.has(left.text().slice(1, -1))
|
|
906
|
+
) {
|
|
907
|
+
manual.increment(site(run.root, `${left.text()} in`, binary));
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
const members = run.rootNode.findAll({
|
|
912
|
+
rule: {
|
|
913
|
+
kind: 'member_expression',
|
|
914
|
+
has: {
|
|
915
|
+
field: 'property',
|
|
916
|
+
regex: `^(${[...PRESENCE_CHECKS].join('|')})$`,
|
|
917
|
+
},
|
|
918
|
+
},
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
for (const member of members) {
|
|
922
|
+
const parent = member.parent();
|
|
923
|
+
|
|
924
|
+
if (
|
|
925
|
+
parent?.kind() !== 'call_expression' ||
|
|
926
|
+
parent.field('function')?.id() !== member.id()
|
|
927
|
+
) {
|
|
928
|
+
manual.increment(
|
|
929
|
+
site(run.root, `${member.field('property').text()} read`, member)
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* Rewrites the data calls of the legacy viewports: `setStack`, `setVolumes`
|
|
937
|
+
* and `setVolumesForViewports` in their common shapes become a registered
|
|
938
|
+
* display set and `setDisplaySets`, `setVideo` and `setEcg` become
|
|
939
|
+
* `setDisplaySets`, each only where the code waits for its promise or hands
|
|
940
|
+
* it on. Every other shape and the other data calls are reported.
|
|
941
|
+
*/
|
|
942
|
+
const codemod: Codemod<TSX> = (root) => {
|
|
943
|
+
const rootNode = root.root();
|
|
944
|
+
const run: Run = {
|
|
945
|
+
root,
|
|
946
|
+
rootNode,
|
|
947
|
+
imports: new CoreImports(rootNode),
|
|
948
|
+
edits: new EditSet(),
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
rewriteMembers(run);
|
|
952
|
+
rewriteFunctions(run);
|
|
953
|
+
reportPresenceChecks(run);
|
|
954
|
+
reportBracketMembers(run);
|
|
955
|
+
|
|
956
|
+
const importEdits = run.imports.edits();
|
|
957
|
+
|
|
958
|
+
if (!run.edits.all().length && !importEdits.length) {
|
|
959
|
+
return null;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
return rootNode.commitEdits([...run.edits.all(), ...importEdits]);
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
export default codemod;
|