From 09aeb8b139ff4a0bd815e32b1cd99a7c854ceaab Mon Sep 17 00:00:00 2001 From: BIPPAN Date: Mon, 6 May 2024 19:30:57 +0530 Subject: [PATCH] fix mapGetters, mapState and mapActions --- src/codemod.js | 4 ++-- src/vueProperties/getVuexActionNames/index.js | 4 ++-- src/vueProperties/getVuexActionNames/index.test.js | 5 +++++ src/vueProperties/getVuexActionNames/test.vue | 3 ++- src/vueProperties/getVuexGetterNames/index.js | 4 ++-- src/vueProperties/getVuexGetterNames/test.vue | 4 ++-- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/codemod.js b/src/codemod.js index 9b12c78..3c7d1db 100644 --- a/src/codemod.js +++ b/src/codemod.js @@ -335,8 +335,7 @@ class Codemod { addSyntaxInOrder = () => { let order = [ - "imports", - "head", + "imports", "layout", "emits", "props", @@ -347,6 +346,7 @@ class Codemod { "methods", "lifecycleHooks", "provide", + "head", "codeToMigrateManually", ]; let newUpdatedSyntax = "\n"; diff --git a/src/vueProperties/getVuexActionNames/index.js b/src/vueProperties/getVuexActionNames/index.js index 41785f7..83509bb 100644 --- a/src/vueProperties/getVuexActionNames/index.js +++ b/src/vueProperties/getVuexActionNames/index.js @@ -53,7 +53,7 @@ const transform = ({ root, j }) => { if (getterNameIndex !== -1) { names.forEach((data) => { const currentName = data.value.value; - let asName = data.key.name; + let asName = data.key.name ?? data?.key?.value; if (asName === currentName) { asName = undefined; } @@ -66,7 +66,7 @@ const transform = ({ root, j }) => { names.forEach((data) => { let [storeName, currentActionName] = data.value.value.split("/"); let options = { isMapped: true }; - options.as = data.key.name; + options.as = data.key.name ?? data?.key?.value; if (options.as === currentActionName) { options.as = undefined; } diff --git a/src/vueProperties/getVuexActionNames/index.test.js b/src/vueProperties/getVuexActionNames/index.test.js index d20e7bc..5929018 100644 --- a/src/vueProperties/getVuexActionNames/index.test.js +++ b/src/vueProperties/getVuexActionNames/index.test.js @@ -20,6 +20,11 @@ test("get all vuex actions in vue file", () => { document: [{ name: "newDocument", isMapped: true, as: "document" }], guest: [ { name: "isInterested", isMapped: true, as: "isGuest" }, + { + name: "isNotInterested", + as: "userNotInterested", + isMapped: true, + }, { name: "username" }, { name: "name", params: "'jerry'" }, { name: "age", params: "10" }, diff --git a/src/vueProperties/getVuexActionNames/test.vue b/src/vueProperties/getVuexActionNames/test.vue index 04113b8..c56976e 100644 --- a/src/vueProperties/getVuexActionNames/test.vue +++ b/src/vueProperties/getVuexActionNames/test.vue @@ -8,11 +8,12 @@ export default { ...mapActions('documents', ['requiredDocuments']), ...mapActions('documents', ['requiredDocuments', 'oldDocument']), ...mapActions({ - user: "user/isPremium", + 'user': "user/isPremium", document: "document/newDocument", }), ...mapActions('guest', { isGuest: "isInterested", + 'userNotInterested': "isNotInterested", }), click() { this.$store.commit('app/newApplication') diff --git a/src/vueProperties/getVuexGetterNames/index.js b/src/vueProperties/getVuexGetterNames/index.js index f07284c..bda4992 100644 --- a/src/vueProperties/getVuexGetterNames/index.js +++ b/src/vueProperties/getVuexGetterNames/index.js @@ -68,7 +68,7 @@ const transform = ({ root, j }) => { getterNames.forEach((getterName) => { const options = {}; let currentName = getterName.value.value; - let asName = getterName.key.name; + let asName = getterName?.key?.name ?? getterName?.key?.value; if (asName !== currentName) { options.as = asName; } @@ -94,7 +94,7 @@ const transform = ({ root, j }) => { const options = {}; let [storeName, currentGetterName] = getterName?.value?.value?.split("/") ?? []; - let asName = getterName?.key?.name; + let asName = getterName?.key?.name ?? getterName?.key?.value; if (asName !== currentGetterName) { options.as = asName; } diff --git a/src/vueProperties/getVuexGetterNames/test.vue b/src/vueProperties/getVuexGetterNames/test.vue index 38c0906..09dd203 100644 --- a/src/vueProperties/getVuexGetterNames/test.vue +++ b/src/vueProperties/getVuexGetterNames/test.vue @@ -8,12 +8,12 @@ export default { ...mapGetters('documents', ['requiredDocuments']), ...mapGetters('documents', ['requiredDocuments', 'oldDocument']), ...mapGetters({ - user: "user/isPremium", + 'user': "user/isPremium", document: "document/newDocument", app: "apps/app" }), ...mapGetters('guest', { - isGuest: "isInterested", + 'isGuest': "isInterested", newApplication: 'newApplication' }), },