-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
fixes #35: adds module import and export grammar #43
Conversation
jsx: false, | ||
|
||
// enable parsing of import/export declarations | ||
module: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this? I was thinking just scriptType
would be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, we could use extra.scriptType==="module"
everywhere. The way I'm thinking here is to have the scriptType
to alter some of the feature flags based on its value, but keeping the code clean by verifying the actual feature flags. Although, I will be ok with using scriptType directly for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to add an isModule
flag so you don't need to keep comparing scriptType
. It's just having an ecmaFeature
of module
doesn't make much sense since it can't be independently controlled outside of scriptType
'.
Overall looks great! Just a couple of notes. And some bookkeeping stuff:
Thanks! |
Forgot to mention, you're right about the tests. I was trying first to get away from having giant files and planned on going back to clean up testing when I got some time. Subdirectories sounds like a great idea. |
throwError({}, Messages.IllegalImportDeclaration, "ILLEGAL"); | ||
} | ||
return parseImportDeclaration(); | ||
case "import": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two case "import":
s? That seems wrong.
doing cartwheels about this 🎠 |
@@ -4467,6 +4733,11 @@ function parse(code, options) { | |||
extra.trailingComments = []; | |||
extra.leadingComments = []; | |||
} | |||
if (options.sourceType === "module") { | |||
extra.ecmaFeatures.blockBindings = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should enable all ES6 features, not just block bindings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, that makes more sense!
Guys, I will probably get another chance to work on this on friday when flying back to miami after reactconf, be patient. |
Sure thing, thanks for the update. |
👍 |
After a discussion with @jeffmo at TC39 meeting last week, we decided to make one small adjustment (a non-backward compatible change) in esprima to align better with the module grammar, more details here: I will incorporate that requirement into this PR. |
@caridy also note the fix we made in esprima to ensure the correct token lists: jquery/esprima#310 |
@caridy, would you mind submitting the same patch upstream to the harmony branch? |
// covers: | ||
// export default ... | ||
lex(); | ||
if (matchKeyword("function") || matchKeyword("class")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to comment out the class
match here as well, I suppose?
thanks @mikesherov, I wasn't proud of the |
For what it's worth, the following should be illegal {
import "import/export outside of the top level";
} Not sure if this was intentional or not given that I'm not sure if espree is supposed to be "loose" or not given that it's for a linter. |
There aren't many tolerant errors, so I'm pretty agnostic as to the severity. |
For the sake of compatibility with Esprima (see jquery/esprima@b1dd29e), I would request the use of |
Fine by me. |
@caridy do you have a corresponding commit to pull through sourceType into eslint or some example code? So far had no other troubles with using this code 👍 |
@jonathanKingston we haven't yet decided how this would be exposed in ESLint. One step at a time. :) @caridy any ETA for finishing this up? |
@nzakas, there's still an ongoing discussion to resolve interop between Esprima and acorn and SpiderMonkey on this too. If you guys do land this now, please be prepared for possibly having to adjust should the data structure change and you guys want to not diverge. |
@nzakas I had assumed so, just thought it was worth checking. I had mostly got an Ember-cli app linted this morning using this code; I don't think there are any other hurdles in getting ESLint as a plugin there. |
@nzakas I'm confident that I can get it ready next week, since we made good progress on estree/estree#11 already, once we get the thumbs up there, I will get this one done. |
I get a chance to work on this PR this morning, here is the update:
|
Thanks @caridy |
@nzakas I will be on the road next week again, and I doubt that I will get a chance to work on this. We can either merge what we have (or a PR on my branch will be welcome if someone is up for helping with the two remaining small details from the list above). As for the refactor on the AST, that will take a little bit more time, until we settle on the discussions around that topic (hopefully after next wed meetings with jquery folks). |
That's okay. I'd rather hold off and get it right than need to break things later. |
Anyway I can help? |
@caridy Looks like both blocking issues are resolved: Looks like little is blocking this from going live, is there anything else needs looking over or help with? @nzakas is there an issue for ESLint how this will be implemented ticket yet? |
Ok, we finally agree on the work on espree for Import/Export definition, and I just propagated the changes to espree, enjoy :) UPDATE: I will resolve the conflicts for all the new stuff @xjamundx and @jonathanKingston, if you guys have some time, we have 3 remaining things that we can do in other PRs, feel free to contribute:
|
Hey @caridy, not to hijack here, but care to implement same PR to Esprima? Would be a shame to not have this upstreamed. |
@nzakas solved the conflicts, ready to roll. |
Thanks! |
@caridy I'll take ImportDeclaration and ExportDeclaration cannot be used inside functions (missing tests and implementation) for now and send the PR to caridy#1 - ImportDeclaration and ExportDeclaration in functions |
var expected = require(path.resolve(__dirname, "../../", MODULES_IMPORT_DIR, filename) + ".result.js"); | ||
var result; | ||
|
||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall there is a lot of similar/duplicate code with what's in ecma-features.js
already. Is there anyway we can combine them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably outside of the scope of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't it a new file that was created in this PR :-p
Either way that's fine. I just got confused trying to add some debugging into ecma-feature.js when really it was needed in modules.js :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, that's probably the merge after conflicts since this PR has been around for a while. These is the actual work: caridy@055f201
Rather than forcing more work on Caridy for this, I'd like to merge into Espree as-is and work on making additional changes as enhancements. Any objections? |
😌 |
@nzakas yes please! Happy to repoint the few extra test PRs back here once this merges |
fixes #35: adds module import and export grammar
@caridy any problems with me re-porting this back to upstream Esprima? |
@caridy , hello :) Can i do bulk named exports?
It works, but eslint showing errors. |
@koutsenko this feature is still in a stage 1, so far you can use only |
This is the bulk of the module grammar from TC39, the exact same supported by esprima today in the harmony branch. This PR includes:
import
grammarexport
grammarsourceType=module
to enablestrict mode
,import
,export
and any other module's feature.Export Syntax
Import Syntax
Other notes
espree
does not support classes as today, we need to revisitexport
once that lands (I added few TODO lines fro that)