AsaAyers / code-links

MIT License
16 stars 8 forks source link

ES6 module support #11

Closed lejafo closed 9 years ago

lejafo commented 9 years ago

I use babel in my project and es6 modules as well. So, in my code I use things like this:

import Router from '../../common/router';
import Radio from 'backbone.radio';

import IndexRoute from './index/route';
...

But your plugin doesn't work for links like this. It would be great if you include this functionality in your package.

Thanks!

AsaAyers commented 9 years ago

yup, this is just something I haven't got to yet because I don't use modules. I am requesting module support in the call to espree. PRs are always welcome if you're up for it :)

lejafo commented 9 years ago

I think I did it. Just adding this code to javascript-processor.js process method:

const modules = ast.body.filter((el) => {
    return el.type === 'ImportDeclaration';
});

modules.map((mod) => {
    let { start, end } = mod.source.loc;
    let { value } = mod.source;

    results.push({
      moduleName: value,
      range: [
          // espree uses 1-indexed lines where
          // atom uses 0-indexed
          [start.line - 1, start.column],
          [end.line - 1, end.column]
      ]
    });
});

Maybe I did it in a wrong way, i don't know, but if you correct me I would be very grateful.

PS I could not PR this - says i haven't permission to repository. PPS Sorry for my english - I'm from Russia

AsaAyers commented 9 years ago

Thanks. I'll verify this and get it in.

For future reference I looked up a guide from github on contributing to open source. Everyone on github can fork a repository (get your own copy), then make changes there, then issue a pull request.

lejafo commented 9 years ago

@AsaAyers Thanks!

lejafo commented 9 years ago

@AsaAyers By the way, I made PR.