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

Migrate some duplicate binding tests to traverse #9532

Merged
merged 5 commits into from
Feb 20, 2019
Merged

Migrate some duplicate binding tests to traverse #9532

merged 5 commits into from
Feb 20, 2019

Conversation

danez
Copy link
Member

@danez danez commented Feb 18, 2019

Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix? y
Major: Breaking Change? ?
Minor: New Feature? n
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The main goal here was to transfer all the tests which test duplicate bindings. They were in different transforms, although the code was in @babel/traverse and the transforms have no impact on that behavior, and imho also shouldn't.

While doing this I discovered, that on case wasn't throwing an error:

let foo;
function foo(){};

see inline comment.

@danez danez added area: tests PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: traverse (scope) labels Feb 18, 2019
@@ -349,9 +349,6 @@ export default class Scope {
// class expression
if (local.kind === "local") return;

// ignore hoisted functions if there's also a local let
if (kind === "hoisted" && local.kind === "let") return;

Copy link
Member Author

@danez danez Feb 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason we have this exception in the code for the case mentioned in the PR. I couldn't come up with a reason why we do this and the commit that introduced it doesn't help either 8a4296a
Simply removing it also doesn't break any of the tests.
Do you think it is safe to remove? Anyone has an idea why this code was there and which case it covers?

To avoid confusion: kind === "hoisted" are function declarations. Should be renamed I think, but that would be definitely breaking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it was this? It is an Annex B thing:

let a;
{ function a() {} }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right but even with removing these lines, this case still works. will add a test.

@danez danez changed the title Migrate som duplicate binding tests to traverse Migrate some duplicate binding tests to traverse Feb 18, 2019
@babel-bot
Copy link
Collaborator

babel-bot commented Feb 18, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10156/

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10154/

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Feb 18, 2019

Maybe it's worth using .toThrowErrorMatchingInlineSnapshot instead of toThrowErrorMatchingSnapshot, since the error messages are small?

@danez
Copy link
Member Author

danez commented Feb 18, 2019

Oh I have never seen this. makes sense.

@danez
Copy link
Member Author

danez commented Feb 18, 2019

Nevermind this does not work obviously with loops and generated testcases.

});

describe("global", () => {
["let", "const"].forEach(name => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test class/function and class/var (and maybe function/var to be sure that it doesn't throw)

Copy link
Member Author

@danez danez Feb 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I added a more generic way to define tests.
Turns out we have some problems, unless I made a mistake in the tests.

var foo = 1;
class foo {};

and

class foo {};
var foo = 1;

Class and var never throw.

also does not throw:

function foo() {}
const foo = 1;
var foo = 1;
const foo = 1;

Thats why I disabled the reverse matching in the test, because swapping the two statements does throw.

@danez
Copy link
Member Author

danez commented Feb 18, 2019

It seems the scope tracking in traverse has some flaws. I guess we should have a look separately from this. I can maybe work on this once done with the scope tracking in the parser.
I was also already thinking that maybe we can make a shared module that handles scopes correctly and share it between the parser and traverse. That would be nice, but not sure what requirements the scope tracking in traverse has.

@nicolo-ribaudo
Copy link
Member

Yeah let's just update the tests for now.

I was also already thinking that maybe we can make a shared module that handles scopes correctly and share it between the parser and traverse

traverse's scope tracker needs to be kept updated while parser's scope describes a static AST; I don't know how feasible it would be.

@danez
Copy link
Member Author

danez commented Feb 18, 2019

traverse's scope tracker needs to be kept updated while parser's scope describes a static AST; I don't know how feasible it would be.

But in the end both implementations (parser and traverse) work on nodes, have a stack of scopes, add/remove bindings and check for duplicates. But yes there might be more stuff going on in traverse which I'm not yet aware of.

@danez danez added this to In progress in Parser: Spec Compliance, Refactoring and Performance via automation Feb 19, 2019
Parser: Spec Compliance, Refactoring and Performance automation moved this from In progress to Reviewed Feb 19, 2019
@danez danez merged commit b32d271 into babel:master Feb 20, 2019
Parser: Spec Compliance, Refactoring and Performance automation moved this from Reviewed to Done Feb 20, 2019
@danez danez deleted the migrate-tests branch February 20, 2019 05:25
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: tests outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse (scope) PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants