Galooshi / import-js

A tool to simplify importing JS modules
MIT License
525 stars 55 forks source link

Importing default and destructuring unnecessarily creates two separate imports when using import declaration keyword #83

Closed lencioni closed 8 years ago

lencioni commented 8 years ago

Currently, with aliases configuration like the following:

"React": {
  "path": "react",
  "destructure": [
    "PropTypes"
  ]
}

importing both React and PropTypes will result in:

import React from 'react';
import { PropTypes } from 'react';

but it would be better if it instead resulted in:

import React, { PropTypes } from 'react';

I'm not sure if there is any equivalent syntax for CommonJS imports, but it would be really nice if ImportJS did this when using the import declaration keyword. I suppose if you were using CommonJS, it would be better to have one require and one assignment after the fact than two requires:

const React = require('react');
const { PropTypes } = React;
trotzig commented 8 years ago

This is probably not super urgent, but I think it makes sense. It does introduce a bit of complexity keeping the two import variants apart, and getting the const case right might be tricky. Right now there are no dependencies amongst import statements, and introducing such will likely lead to some tricky complexity. I could see a first version where we treat the import variant separate in these cases.

lencioni commented 8 years ago

Yeah, I think it would be just fine to start by adding support for the import case and punting on the const/let/var case for now.