-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add support for @@iterator #7058
Conversation
rajasekarm
commented
Dec 19, 2017
Q | A |
---|---|
Fixed Issues? | Fixes #7053 |
Patch: Bug Fix? | |
Major: Breaking Change? | |
Minor: New Feature? | Yes |
Tests Added + Pass? | Yes |
Documentation PR | |
Any Dependency Changes? | |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6584/ |
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.
- There is also
@@asyncIterator
: https://github.com/facebook/flow/blob/4eb62a5597d59174531d44e532c65daa25d8331b/src/parser/lexer.ml#L805-L807 - Should the
@@iterator
identifier be allowed everywhere? e.g.let @@iterator = 2;
@@ -1231,6 +1231,9 @@ export default class Tokenizer extends LocationParser { | |||
const ch = this.fullCharCodeAtPos(); | |||
if (isIdentifierChar(ch)) { | |||
this.state.pos += ch <= 0xffff ? 1 : 2; | |||
} else if (this.state.isIterator) { | |||
this.state.pos += 2; | |||
delete this.state.isIterator; |
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.
Can you use this.state.isIterator
here?
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 meant this.state.isIterator = false
lol
@nicolo-ribaudo it's a flow syntax not related to JS, it would error with |
We should ask to the flow team if they plan to remove |
Should ping the flow team on all the flow prs anyway 😛 @babel/flow |
Also we should not allow any other identifier |
I checked and flow paeses that syntax sometimes (e.g. it accepts |
I have thought about this a little, and I think that we should allow function @@iterator() {}
@@iterator(); but I think that we shouldn't parse it since it will generate invalid JavaScript output. So, instead of throwing if |
@nicolo-ribaudo agreed |
@danez Would you like to look this over since you're familiar with the parser? It seems fine to me, but I'm also not an expert on it. |
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 looks good to me, but there are some remaining issues and untested things.
-
Flow-strip-types probably needs to remove the
@@iterator
and@@asyncIterator
, as the resulting code is otherwise invalid? -
Does babel-generator know how to reprint the examples which are added in the babylon tests? Can we add a simple test for this? (We should really have shared testcases for babylon and generator at some point, as everything that is parsable should be printable I guess)
Currently Flow only removes them from types. |
Looks good to me. As mentioned by @danez, It could probably also impact TypeScript? @hzoo could we ping them? I don't think that could break anything but maybe require a transformations (I'm not a TS expert). |
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.
actual/expected -> input/output in tests 😛
@nicolo-ribaudo updated the test cases. |
Yes, since someone might use Babel for a codemod and thus not remove Flow types. |
@nicolo-ribaudo @danez added test case for generator and Flow-strip-types plugin |
@@ -0,0 +1,15 @@ | |||
declare class A { |
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.
It looks like the output for this file is missing?
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.
That's expected (i.e. there is no output), similar to https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-declare-statements
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.
@existentialism Thanks!!
@rajzshkr thanks! |