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

Test: missing tests for modules & classes (refs #72) #75

Merged
merged 1 commit into from
Mar 7, 2015

Conversation

xjamundx
Copy link
Contributor

@xjamundx xjamundx commented Mar 6, 2015

Added tests for the following:

  • export default class extends bar {};
  • export default class {};
  • export default class foo extends bar {};
  • export default class foo {};
  • export class foo extends bar {};
  • export class foo {};

Fixed the following:

  • Provided a fix for export default class foo extends bar {}; such that it would not throw

Need to check the following:

  • AST for export default class {}; in class-default-anonymous.result.js
  • AST for export default class foo extends bar {}; in class-default-anonymous-extends.result.js

The ASTs are tricky and need to be verified as accurate, because they were generated by espree.

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 6, 2015

This will clash with 731d54f a bit

@caridy
Copy link
Contributor

caridy commented Mar 6, 2015

yes, that has to be fixed in espree and esprima. For anonymous classes and functions for export default we are using expressions, but really they are not expressions, they are nameless declarations. We got to consensus on that few days ago to avoid introducing HoistableDeclaration. This all means we need to fix part of the pieces I put together in the previous PR.

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 6, 2015

Thanks so much for your work on this @caridy Really amazing work! Do you want me to look into this last class issue?

@nzakas
Copy link
Member

nzakas commented Mar 6, 2015

Can you both yeah take a look at #73 for my changes? I'd like to use that as a bad before making further changes.

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 6, 2015

Okay will look at fixing that last test tomorrow!

@xjamundx xjamundx changed the title Fix: missing class support for modules (refs #72) Test: missing tests for classes (refs #72) Mar 6, 2015
@xjamundx xjamundx changed the title Test: missing tests for classes (refs #72) Test: missing tests for modules & classes (refs #72) Mar 6, 2015
@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 6, 2015

Looking quickly at export default class extends bar {}; to see if there's an easy fix.

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 6, 2015

Initially appears to be related to parseClassDeclaration() vs parseClassExpression(). Only in the case of modules we do this with parseSourceElement:

case "class":
    if (allowClasses) {
        return parseClassDeclaration();
    }
    break;

Inside of parseClassDeclaration we assume a name with this bit of code (which i think chokes up on finding extends instead):

expectKeyword("class");
id = parseVariableIdentifier();
if (matchKeyword("extends")) {
   lex();
   superClass = parseLeftHandSideExpressionAllowCall();
}

@nzakas
Copy link
Member

nzakas commented Mar 6, 2015

What's your definition of "not working"? I'm not clear on the bug you're trying to fix.

@caridy
Copy link
Contributor

caridy commented Mar 6, 2015

Here is a related issue:

https://github.com/eslint/espree/blob/master/tests/fixtures/ecma-features/modules/export-default-function.result.js#L7

when doing export default function () {} that's not an expression as we have it today (my bad), it should be a function declaration with no name. Probably we should fix the function declaration parser first, to support that case (which is spec'd as HoistDeclaration), and then we can do the same for classes, where we can have a class that has no name but it is still a class declaration exported as default.

@caridy
Copy link
Contributor

caridy commented Mar 6, 2015

/cc @jeffmo

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 6, 2015

@nzakas the issue is that export default class extends foo {} would throw (and I originally just included a test that validated the error)
@caridy yeah you know way more about the internal of how classes should work. the latest commit includes a workaround by parsing it as an expression. we could also make it a ClassDeclaration with a null name. I have a hunch it's not the only class AST that isn't 100% perfect :)

Let me know what to change!

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 6, 2015

Updated the PR description with clearer info and asks.

@nzakas
Copy link
Member

nzakas commented Mar 6, 2015

Ah, I see, so this is the unnamed function declaration discussion. Got it. (Ref: estree/estree#38)

So the change here is to allow a null ID for both function and class declarations.

@caridy
Copy link
Contributor

caridy commented Mar 6, 2015

@nzakas correct.

"body": [
{
"type": "ExportDefaultDeclaration",
"declaration": null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like this is missing a declaration :|

Copy link
Contributor

Choose a reason for hiding this comment

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

ha, that's a bug. related to what I mentioned before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

awesome i'll try to take a stab at this tonight :)

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 7, 2015

Okay took care of the ClassDeclaration stuff. I'm less familiar with the FunctionDeclaration stuff! I think the ASTs make sense now :)

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 7, 2015

Ahh the name/id stuff....fixing

@xjamundx
Copy link
Contributor Author

xjamundx commented Mar 7, 2015

Ok, should be good to go. Let me know if you need anything else on this (like FunctionDecl stuff)...

@nzakas
Copy link
Member

nzakas commented Mar 7, 2015

Cool, I'm hanging out in #eslint on Freenode as I try to get all of this merged and into ESLint

@@ -5114,7 +5113,9 @@ function parseClassDeclaration() {

expectKeyword("class");

id = parseVariableIdentifier();
if (lookahead.type === Token.Identifier) {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't quite right because parseClassDeclaration() normally must have an identifier. So you really need to pass in a flag specifying whether the ID is optional or required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if you have a specific class declaration that breaks, at the moment I think this code-path may only be called in export statements, so maybe it works by accident? maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to be out for most of the day taking kids to the zoo, but may be able to help later!

Copy link
Member

Choose a reason for hiding this comment

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

That's okay, I'll just merge and fix it. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Just FYI, the problem case is:

class {}

This should throw an error because class declarations require names, but this change parsed it okay.

nzakas added a commit that referenced this pull request Mar 7, 2015
Test: missing tests for modules & classes (refs #72)
@nzakas nzakas merged commit a7f0b2f into eslint:master Mar 7, 2015
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

Successfully merging this pull request may close these issues.

3 participants