HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/node_modules/vue-codemod/dist/transformations/vuex-v4.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parser = exports.transformAST = void 0;
const wrap_ast_transformation_1 = __importDefault(require("../src/wrap-ast-transformation"));
const add_import_1 = require("./add-import");
const remove_extraneous_import_1 = require("./remove-extraneous-import");
// new Store() -> createStore()
exports.transformAST = (context) => {
    const { j, root } = context;
    const vuexImportDecls = root.find(j.ImportDeclaration, {
        source: {
            value: 'vuex',
        },
    });
    const importedVuex = vuexImportDecls.find(j.ImportDefaultSpecifier);
    const importedStore = vuexImportDecls.find(j.ImportSpecifier, {
        imported: {
            name: 'Store',
        },
    });
    if (importedVuex.length) {
        const localVuex = importedVuex.get(0).node.local.name;
        const newVuexDotStore = root.find(j.NewExpression, {
            callee: {
                type: 'MemberExpression',
                object: {
                    type: 'Identifier',
                    name: localVuex,
                },
                property: {
                    name: 'Store',
                },
            },
        });
        newVuexDotStore.replaceWith(({ node }) => {
            return j.callExpression(j.memberExpression(j.identifier(localVuex), j.identifier('createStore')), node.arguments);
        });
    }
    if (importedStore.length) {
        const localStore = importedStore.get(0).node.local.name;
        const newStore = root.find(j.NewExpression, {
            callee: {
                type: 'Identifier',
                name: localStore,
            },
        });
        add_import_1.transformAST(context, {
            specifier: {
                type: 'named',
                imported: 'createStore',
            },
            source: 'vuex',
        });
        newStore.replaceWith(({ node }) => {
            return j.callExpression(j.identifier('createStore'), node.arguments);
        });
        remove_extraneous_import_1.transformAST(context, { localBinding: localStore });
    }
};
exports.default = wrap_ast_transformation_1.default(exports.transformAST);
exports.parser = 'babylon';