Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created April 21, 2016 10:36
Show Gist options
  • Save sibelius/bd775b266d464e9618de46df00eed73b to your computer and use it in GitHub Desktop.
Save sibelius/bd775b266d464e9618de46df00eed73b to your computer and use it in GitHub Desktop.
Convert import React, { Component } from 'react-native' to import React, { Component } from 'react'
// find and update all import React, { Component } from 'react-native'
root
.find(j.ImportDeclaration, {
source: {
value: 'react-native'
}
})
.filter(({node}) => {
// check React or { Component } from 'react-native'
const nodes = node.specifiers.filter(imports => {
return imports.type === 'ImportDefaultSpecifier' && imports.local.name === 'React' ||
imports.type === 'ImportSpecifier' && imports.local.name === 'Component';
});
return nodes.length > 0;
})
.forEach(updateImport);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment