Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why "un-transform babelify transformed source"? #357

Closed
wenbing opened this issue Feb 17, 2016 · 2 comments
Closed

why "un-transform babelify transformed source"? #357

wenbing opened this issue Feb 17, 2016 · 2 comments
Labels

Comments

@wenbing
Copy link

wenbing commented Feb 17, 2016

in lib/input/dependency.js

      // un-transform babelify transformed source
      input.source = fs.readFileSync(input.file, 'utf8');

why?

@tmcw tmcw added the question label Feb 17, 2016
@tmcw
Copy link
Member

tmcw commented Feb 17, 2016

Good question!

Two reasons:

  1. documentation.js uses Babel to get an abstract syntax tree, which is what it uses to run inference - we look at the AST structure and derive parameters and so on. Babel transforms-away a lot of the things we'd want to document - destructuring parameters, for instance, are transformed into a single parameter and then destructuring within the function. For inference to work, we need to have a look at the original source, not a transformed version.
  2. When we link to github, run lint, or output an error, we rely on correct line numbers - line numbers that match the original source code, so that you can find the error. Babel's transformation changes the code and the line numbers.

We're using babelify as kind of a hack: we use module-deps to find dependencies, and to find dependencies in es6 code, it needs to invoke babelify - otherwise, module-deps would choke on es6 syntax and import statements and so on. So we aren't actually using babelify for its usual purpose of transforming code for output - we're only transforming code to figure out where dependencies are.

We parse code with babylon in lib/parsers/javascript, which gives us the AST, and that's the source of truth for inference.

@wenbing
Copy link
Author

wenbing commented Feb 18, 2016

Thank you very much.

I think using module-deps is ok.

@wenbing wenbing closed this as completed Feb 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants