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

Add ES6 Support #33

Open
Constellation opened this issue Feb 16, 2014 · 77 comments
Open

Add ES6 Support #33

Constellation opened this issue Feb 16, 2014 · 77 comments

Comments

@Constellation
Copy link
Member

Supporting ES6 block scopes and some special scopes (such as arraw function and method)

@nzakas
Copy link
Contributor

nzakas commented Jun 6, 2014

Are you still going to do this? ESLint has a bug related to let scoping that could use this: eslint/eslint#917

@Constellation
Copy link
Member Author

Oh, OK. I'll work on it on weekend :)

@Constellation
Copy link
Member Author

semantics in ES6 spec may be mature enough :)

@nzakas
Copy link
Contributor

nzakas commented Jun 6, 2014

@jlongster
Copy link

This would be awesome to have!

@nzakas
Copy link
Contributor

nzakas commented Sep 14, 2014

Just checking in - any chance you're working on this? :)

@Constellation
Copy link
Member Author

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.

@nzakas
Copy link
Contributor

nzakas commented Sep 15, 2014

That sounds awesome!

@elwayman02
Copy link

@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. :)

@Constellation
Copy link
Member Author

OK, so, let's start to support ES6.
I'll start it with estraverse.

@Constellation
Copy link
Member Author

Support ES6 traversing in estraverse. estools/estraverse@19f7a5c

@StoneCypher
Copy link

This would really help for getting eslint running on jsx

@sebmck
Copy link

sebmck commented Nov 16, 2014

Any update on this? Definently keen to use this for 6to5. Reference babel/babel#175

@Constellation
Copy link
Member Author

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.

@sebmck
Copy link

sebmck commented Nov 16, 2014

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.

@Constellation
Copy link
Member Author

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.

@Constellation
Copy link
Member Author

And we need to ensure,

for (let i = 0; i < 10; ++i) { console.log(i); }

scope behavior.

@Constellation
Copy link
Member Author

We're now implementing scopes for ES6. But be careful, it's experimental and the behavior might be changed

Constellation added a commit that referenced this issue Nov 16, 2014
@Constellation
Copy link
Member Author

@sebmck:

Do you know the actual section in the ES6 draft (rev28)?
I'm now investigating it.

@sebmck
Copy link

sebmck commented Nov 16, 2014

@Constellation For what specifically?

@Constellation
Copy link
Member Author

@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.

@sebmck
Copy link

sebmck commented Nov 16, 2014

@Constellation Yeah I understand that. I was referring to what section specifically that you were looking for.

@Constellation
Copy link
Member Author

@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

Constellation added a commit that referenced this issue Nov 16, 2014
In this commit, we fix the let/const declaration behavior.

var i = 20;  // (1)
{
    i;  // (1)
    let i = 20;  // (2)
    i;  // (2)
}

ref #33
@Constellation
Copy link
Member Author

@nzakas

OK, I've fixed the bug.
Which is the preferable for you?

  1. update the 2.0.1 code with this fix. (8794242)
  2. publish the current code as 3.0.0, currently TDZ is not updated yet. But other things are almost identical.

@nzakas
Copy link
Contributor

nzakas commented Jan 10, 2015

If you can update 2.0.1 with the fix, I can keep testing for other incompatibilities.

@Constellation
Copy link
Member Author

OK, so I've published it as 2.0.2, it shipps the above bug fix :)

@nzakas
Copy link
Contributor

nzakas commented Jan 10, 2015

Thanks!

@nzakas
Copy link
Contributor

nzakas commented Jan 17, 2015

I found one more issue. It looks like escope isn't marking increment/decrement as write operations. For example:

/*global b:false*/
b++;

The ref for this has ref.isWrite() return false, whereas in 1.x it returned true.

@Constellation
Copy link
Member Author

@nzakas
Cool! I'll fix it :)

@Constellation
Copy link
Member Author

@nzakas

I've fixed it and released it as 2.0.3 :)

@nzakas
Copy link
Contributor

nzakas commented Jan 18, 2015

Thanks!

@nzakas
Copy link
Contributor

nzakas commented Jan 31, 2015

@Constellation Found a couple more issues.

First, when using a label, references inside the label are not counted accurately:

var foo = 5;

label: while (true) {
  console.log(foo);
  break label;
}

In this example, the variable foo incorrectly reports zero references when there should be one.

Second, block scope references don't appear to work in loops:

for (let prop in box) {
    box[prop] = parseInt(box[prop]);
}

The variable prop also shows up with zero references instead of two.

@nzakas
Copy link
Contributor

nzakas commented Jan 31, 2015

Sorry, I should have said isRead() was the problem, not references.

@nzakas
Copy link
Contributor

nzakas commented Feb 1, 2015

Okay, nailed down the problem for the let in loops. Basically, the variable prop appears in the variables array for both the TDZ scope and the block scope. The reference to prop inside the block scope is then counted as a reference to prop in block, whereas the prop in TDZ is said to have zero references. This is what's confusing ESLint.

For the time being, I can avoid checking the TDZ for variables, but it seems like the TDZ logic is not quite correct.

@Constellation
Copy link
Member Author

@nzakas

Oh, thank you for your pointing.
These are raised when using ecmaVersion: 6?
I'll investigate this issues.

Constellation added a commit that referenced this issue Feb 1, 2015
Fix: Labeled statement ref counting (refs #33)
@nzakas
Copy link
Contributor

nzakas commented Feb 1, 2015

Yes, with ecmaVersion: 6.

@jrvidal
Copy link

jrvidal commented May 7, 2015

Just for reference, eslint/eslint#2405 is blocked by this issue, more concretely by "Initializers in Destructuring Assignments".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants