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

Support ES6 modules #112

Closed
benderTheCrime opened this issue Jun 30, 2015 · 28 comments
Closed

Support ES6 modules #112

benderTheCrime opened this issue Jun 30, 2015 · 28 comments
Labels
Milestone

Comments

@benderTheCrime
Copy link

events.js:141
      throw er; // Unhandled 'error' event
            ^
Error: Parsing file *: 'import' and 'export' may appear only with 'sourceType: module' (4:0)

I see in the README that ES6 code is supported, but I do no see any documentation supporting this. How would one use the documentation package to build documentation for an ES6 project?

@benderTheCrime
Copy link
Author

This also does not appear to be specific to gulp-documentation or documentation, but this is still a relevant issue because I have not experienced it in any other package.

@anandthakker
Copy link
Contributor

@benderTheCrime - Thanks for the report. Could you include the source file that causes the error above?

@benderTheCrime
Copy link
Author

Sure can, it's throwing this error in the very first file I load using ES6 module imports:
https://github.com/benderTheCrime/angie/blob/master/src/Angular.js. The gulpfile I'm using is the one associated with that same project and is already registering ES6 files:
https://github.com/benderTheCrime/angie/blob/master/gulpfile.babel.js the documentation task is currently commented out). However, the command also fails with the very simplest variation of the tool from the command line: documentation src/Angular.js

@anandthakker
Copy link
Contributor

Okay, I looked into this, and there are a couple of (deepish) issues:

  1. The error above is thrown during dependency walking (module-deps, via node-detective) isn't handling ES6 modules correctly. Passing {ecmaVersion: 6, sourceType: 'module'} as options to acorn would solve this, but that'll require: (a) a patch to module-deps to allow those options, and (b) a patch to node-detective to pass the sourceType option through to acorn (it already passes ecmaVersion through).
  2. ast-types doesn't have a definition for ExportNamedDeclaration (although it does have one for ExportDeclaration), so even after the module-deps issue is fixed, ES6 modules will blow up the parse() stream.

@benderTheCrime For now, one non-ideal workaround might be to use the polyglot: true option.

1 similar comment
@anandthakker
Copy link
Contributor

Okay, I looked into this, and there are a couple of (deepish) issues:

  1. The error above is thrown during dependency walking (module-deps, via node-detective) isn't handling ES6 modules correctly. Passing {ecmaVersion: 6, sourceType: 'module'} as options to acorn would solve this, but that'll require: (a) a patch to module-deps to allow those options, and (b) a patch to node-detective to pass the sourceType option through to acorn (it already passes ecmaVersion through).
  2. ast-types doesn't have a definition for ExportNamedDeclaration (although it does have one for ExportDeclaration), so even after the module-deps issue is fixed, ES6 modules will blow up the parse() stream.

@benderTheCrime For now, one non-ideal workaround might be to use the polyglot: true option.

@benderTheCrime
Copy link
Author

Let me first try the polyglot: true option and see what my output looks like.

@benderTheCrime
Copy link
Author

I don'y see any difference in the output with polyglot: true in my gulp task option arguments:

gulp.task('documentation', function() {
    gulp.src(src)
        .pipe(documentation({
            format: 'html',
            polyglot: true
        }))
        .pipe(gulp.dest('md-documentation'));
});

and I do not see documentation on passing the polyglot option to the CLI anywhere other than on the homepage: http://documentation.js.org/

Is there another way to do this?

@benderTheCrime
Copy link
Author

Ah, it's --polyglot could you please add that to the documentation? Also, could the website be updated to reflect that the ES6 support is actually only available as a byproduct of using the language agnostic option? I've been vetting documentation tools and I spent a good deal of time on this tool (because it appears to have the best output) on what could have been avoided by some clarity. Otherwise, I think this is an awesome tool.

I'm also going to add an issue to the gulp project to make sure that the polyglot option is available.

@tmcw
Copy link
Member

tmcw commented Jun 30, 2015

--polyglot is intended for non-JavaScript code: ES6 is supported but it looks like espree / ast-types are choking on the import/export declarations.

@anandthakker
Copy link
Contributor

@tmcw @benderTheCrime Yeah, I should have been clearer: the polyglot idea was really just meant as a temporary workaround to force documentation not to do any parsing.

@tmcw
Copy link
Member

tmcw commented Jun 30, 2015

The error above is thrown during dependency walking (module-deps, via node-detective) isn't handling ES6 modules correctly. Passing {ecmaVersion: 6, sourceType: 'module'} as options to acorn would solve this, but that'll require: (a) a patch to module-deps to allow those options, and (b) a patch to node-detective to pass the sourceType option through to acorn (it already passes ecmaVersion through).

@benderTheCrime do you have a package.json file with transforms defined? If you've got, for instance, babelify in your project to transpile ES6 to ES5, then documentation's module-deps instance will automatically use this transform. We shouldn't need to pass any options to acorn as above - module-deps transforms abstract away from any other language like ES6 or CoffeeScript and transform before resolving dependencies.

Given that not all projects that use documentation will use browserify or its "browserify" package key, this might be an area where we'll need to define transforms as passed-in options...

@benderTheCrime
Copy link
Author

I'm using a gulpfile.babel.js. This immediately loads require('babel/register'); which transpiles all included ES6 modules when they are imported. This is a node/iojs project.

@tmcw
Copy link
Member

tmcw commented Jun 30, 2015

On second thought, @anandthakker was totally right: we shouldn't need to babelify at that point, module-deps should permit passing options to acorn.

@anandthakker
Copy link
Contributor

@tmcw I think passing that option would still be a superficial fix, because (I'm guessing) module-deps won't resolve ES6 module deps.

@benderTheCrime
Copy link
Author

So what is the verdict here? Should I use polyglot until the espree / ast-types packages are upped?

@anandthakker
Copy link
Contributor

@benderTheCrime Yep, I think that's the best bet in the short term. Not 100% sure on all the limitations you'll face, but one of them is that documentation won't automatically walk the dependency tree. (Since you're using gulp you could probably use that to rig up a way to run documentation on each individual file.)

@anandthakker anandthakker changed the title How does one use espree and the ES6 functionality? Support ES6 modules Jul 1, 2015
@anandthakker
Copy link
Contributor

Upstream: browserify/module-deps#93

Re: ast-types - looks like the newest version might have support, but haven't checked yet.

@fundon
Copy link

fundon commented Sep 21, 2015

Is it fixed?

@tmcw
Copy link
Member

tmcw commented Sep 21, 2015

As a general rule of thumb, if the issue is open, people are still working on the problem and it is not fixed yet.

@tmcw
Copy link
Member

tmcw commented Oct 5, 2015

This is fixed in #163 which uses babel to transform code and generate an AST, and is covered by tests in cbff1d3 .

@tmcw tmcw closed this as completed Oct 5, 2015
@thealjey
Copy link

thealjey commented Oct 6, 2015

@tmcw Is there any way I could already use this? Doesn't seem to work in 2.1.0-alpha2

@anandthakker
Copy link
Contributor

@thealjey You could try installing straight off the github repo with npm install -g documentationjs/documentation#b173cf14a55dbed1ef6b214789c5218e1ab032a2

@thealjey
Copy link

thealjey commented Oct 6, 2015

@tmcw unfortunately this isn't really an option for me, but thanks anyway 😄
any plans on when this might land on npm?
sorry for bothering

@tmcw
Copy link
Member

tmcw commented Oct 6, 2015

As soon as the 3.0.0 milestone is complete. We're moving fast, so it may be done by the end of the week.

@developit
Copy link

I am super pumped for this. What's left that is blocking 3.0.0?

@matthiasg
Copy link

this was confusing .. i have the same issue. Saw this as closed, but it isnt really published yet. thanks for the work though. BTW the --version command line parameter isnt really working.

@tmcw
Copy link
Member

tmcw commented Oct 30, 2015

@matthiasg there isn't a --version flag. Opened #206 to add it.

the 3.0.0 milestone is everything that needs to be complete before it's released.

@tmcw
Copy link
Member

tmcw commented Oct 30, 2015

Ah - going to rename the existing --version flag to --project-version for clarity.

rhendric pushed a commit to rhendric/documentation that referenced this issue Sep 15, 2022
)

This should help people who reach the end of the Getting Started guide
and are not clear about what they should do next. I think ought to be
particularly useful for people who are new to typed FP.
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

7 participants