DEV Community

loading...

Codemod with jscodeshift help needed

Vimalraj Selvam
Full stack developer and have a history of QA role
・1 min read

I'm trying to write a small codemod to refactor some of the code. Consider I've somethihng like this:

import { mod1, mod2, mod3 } from 'package1'
import localMod from 'package2'
Enter fullscreen mode Exit fullscreen mode

and I wanted to change this to:

import { mod1, mod3 } from 'package1'
import * as mod2 from 'new-package'
import localMod from 'package2'
Enter fullscreen mode Exit fullscreen mode

As a first step, I'm trying to remove mod2 from the 1st line of import which I did successfully, but I'm not able to remove the comma after mod1.

My code snippet so far look like this:

Please help.

Discussion (1)

Collapse
rajasegar profile image
Rajasegar Chandran • Edited

Vimal, you are removing just the Identifiers from the Specifiers, you need to remove the actual import specifiers