escope
escope copied to clipboard
Add ES6 Support
Supporting ES6 block scopes and some special scopes (such as arraw function and method)
Are you still going to do this? ESLint has a bug related to let
scoping that could use this: https://github.com/eslint/eslint/issues/917
Oh, OK. I'll work on it on weekend :)
semantics in ES6 spec may be mature enough :)
They are. I've documented it in my book: https://github.com/nzakas/understandinges6/blob/master/manuscript/01-The-Basics.md#block-bindings
This would be awesome to have!
Just checking in - any chance you're working on this? :)
Hi @nzakas, Sorry for my further late reply.
I'm now gradually supporting ES6 in the tools, now escodegen supports ES6 Syntax completely. So, next, I'm planning to support ES6 in estraverse since it is used in the escope. Then, support scoping in escope.
Since there's significant difference between ES5 scopes and ES6 scopes, maybe I'll introduce ecmaVersion
option.
That sounds awesome!
@Constellation what's the status on this? Is there anything we can do to help out? I'm working on trying to get an ES6-supported version of ESlint using the harmony branch of esprima, so my next step is to approach ES6 support in escope and estraverse. :)
OK, so, let's start to support ES6. I'll start it with estraverse.
Support ES6 traversing in estraverse. https://github.com/Constellation/estraverse/commit/19f7a5c5dbb7bcaca3226d3cd608e59dbea1a275
This would really help for getting eslint running on jsx
Any update on this? Definently keen to use this for 6to5. Reference 6to5/6to5#175
Currently, we're investigating the ES6 spec and Esprima AST nodes. And We're now updating escodegen and estraverse. Does anyone knows the issue about them? I think estraverse now completely support ES6 syntax. If it's correct, my mental model of ES6 AST may be stable.
Main issues you'll run into is implementing temporal dead zones. Default parameters have their own scope and you can't access let/const variables before they're initialised.
Main issues you'll run into is implementing temporal dead zones. Default parameters have their own scope and you can't access let/const variables before they're initialised.
Nice, it's very useful information. And we need to consider destructuring assigned variables.
var { a, b, c } = obj; // it materialize a, b, c variables.
And we need to ensure,
for (let i = 0; i < 10; ++i) { console.log(i); }
scope behavior.
We're now implementing scopes for ES6. But be careful, it's experimental and the behavior might be changed
@sebmck:
Do you know the actual section in the ES6 draft (rev28)? I'm now investigating it.
@Constellation For what specifically?
@sebmck I think sticking to the formal spec is very important ;) It provides a clear reason to "why it is so implemented". And makes the tool stable.
@Constellation Yeah I understand that. I was referring to what section specifically that you were looking for.
@sebmck Ah, I've misunderstood.
Default parameters have their own scope.
I'm looking for it. Now seeing 9.2.13, http://people.mozilla.org/~jorendorff/es6-draft.html#sec-functiondeclarationinstantiation
Added class declaration / expression scope support.
Remaining TODO is,
- Destructuring assignments
- [x] VariableDeclaration
- [x] Assignment
- [x] Parameters
- Initializers
- [ ] Default parameters
- [ ] Initializers in Destructuring Assignments
- [x] MethodDefinition's strictness
- [x] import declaration
- [x] export declaration
- [x] For/ForIn/ForOf special block scope
- [x] Class
- [x] TemplateLiteral
Please feel free to modify this list. Now, 4:00 JST, so I'll sleep today...
There's also the import
statement.
@nzakas Nice. I've added it to TODO list.
Destructuring assignments support is partially done. Initializers / Default parameters are not supported yet. Maybe need to change Esprima's AST architecture.
Seeing the ClassDefinitionEvaluation
1, we attempt to create class body scope only when the className
is provided. However, in this case, computed property names are evaluated in the upper scope, so sometimes it is not strict scope.
But spec says, ClassBody
is strict code. I think it may be a spec bug. In this time, I always create the scope for strictness of scope. And I'll open the issue to TC39 bugzilla.
edit: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-strict-mode-code I'll investigate more.
@ariya @michaelficarra Found Esprima's bug,
esprima.parse('try{}catch({a,b,c}){}').body[0].handlers[0].param
Should return ObjectPattern
, but returns ObjectExpression
.