Add ECMAScript 6 features
nzakas opened this issue ยท 47 comments
This is a rollup that will let us keep track of ES6 progress.
-
let
declarations -
const
declarations - Regular expression
u
flag - Regular expression
y
flag - Binary literals
- New octal literals
- Arrow functions
- Default parameters
- Rest parameters
- Spread operator
-
super
references - Classes
-
for-of
loops - Generators
- Object literal property shorthand
- Object literal method shorthand
- Object literal computed properties
- Template strings
- Destructuring
- Unicode code point escapes
- Allow duplicate object literal properties (except
__proto__
) - Modules
The let
and const
changes are in. Next up: regular expression flags.
In order to make the regular expression flags work, I needed to add a regex
property to both AST nodes and literal nodes to coincide with Esprima Harmony. I've got this working, but need to update the AST tests for the various third-party libraries that Esprima uses to validate AST output.
@nzakas which of these would you reccomend to get started on?
I think allowing duplicate properties in strict mode is the easiest to get started with. I'd call that objectLiteralDuplicateProperties
.
After that, Unicode code point escapes (see https://leanpub.com/understandinges6/read#leanpub-auto-better-unicode-support)
I'm currently working on generators.
I'm starting work on Unicode code point escapes
Generators and code point escapes have been merged in.
Next priority is template literals. @FredKSchott interested in taking that?
definitely, I'll tackle that next (away for the long weekend but I'll take a look next week)
They're supported in V8 now, right? Makes sense to do them next
Yup! And also in io.js now.
I'm planning on attacking arrow functions when I have some energy.
Interested in taking a shot in default params, though I'm not sure how much work it will be/take I'll have...
Template strings are done! I'd be interested in taking on destructuring or rest parameters next. @nzakas thoughts?
+1 for destructuring.
@xjamundx whoops, just saw your post above on taking rest params. Are you still planning on working on that? nvm, I forgot that Rest params != Default params
Rest params are much easier. Destructuring is tricky. You can decide the level of challenge you want. :)
๐
๐ for modules and classes!
+1 classes
Quick update: I've been completely swamped this week, and haven't been able to work on this at all this week. I probably won't be free again for another week or two. Anyone who wants to grab rest params or destructuring should feel free.
๐
Thanks for the update, Fred.
Tackling super
references now.
๐ to destructuring and arrow functions
I have like 45 minutes to takea stab at either. I'll try arrow functions.
I'd be super impressed if you could do arrow functions in 45 minutes, it's a bit complicated because you don't know that an expression is the beginning of an arrow function until the =>
is encountered.
If you want a nice simple one, rest parameters would probably work.
Yeah def won't be done in 45, but I think in a few hours I could get this to work. Will open PR shortly... it's coming along. A lot of the core stuff was already ported over for other ES6 stuff...
Will take a stab at destructuring. Hoping to have a PR with just some broken tests today, but imagine it will take a few weeks to track down every last piece.
๐
Hey people this is pretty great. 4 things left!
<3
โ for rest next
facebook/esprima supports classes.
Esprima classes support: jquery/esprima#1061
Well that makes things easier :)
Working on classes now.
๐
you guys are killing it ๐ ๐ ๐
Ran into a bit of trouble with classes. The Harmony branch is different that Esprima's master now (master being the most correct). Will probably take me a bit to work through it unless someone else wants to give it a shot.
I'm still trying to grok the destructuring defaults spec. Once I'm done with that I'll try to throw my hat into either classes or modules. Whatever's left....
Fast work on getting these es6 features implemented!
I noticed an issue with rest parameters though, they don't seem to get added to the scope's variable list. I noticed this when trying to use eslint to validate a function with rest parameters.
var func = function (first, ...rest) {
return rest;
};
I am getting a 'rest' is not defined (no-undef) error. The underlying cause seems to be that when the rule's function looks at context.getScope().variables, a variable named 'rest' is not in the list.
see eslint/eslint#1870 to fully replicate
Cool just saw eslint/eslint#1870.
As I mentioned there, this is an issue with escope, not espree.
Don't look now, modules is the last feature!
should we file a separate bug just for the modules support?
In this related bug I posted an example of how espree differs from esprima when used with escope eslint/eslint#1978 (comment)
Modules are already properly supported.