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

Anonymous class #13

Closed
azu opened this issue Jun 20, 2015 · 3 comments
Closed

Anonymous class #13

azu opened this issue Jun 20, 2015 · 3 comments

Comments

@azu
Copy link

azu commented Jun 20, 2015

ES6 Classes allow to anonymous.

ClassDeclaration[Yield, Default] :
    class BindingIdentifier[?Yield] ClassTail[?Yield]
    [+Default] class ClassTail[?Yield] // <= export default class { }

ClassTail[Yield] :
    ClassHeritage[?Yield]opt { ClassBody[?Yield]opt }

esdoc fail to parse anonymous class and throw error.

I'v create example repository : azu/esdoc-no-class-name-issue

// anonymous class
export default class {
    constructor(){
        this.description = "this is example class";
    }
}

parse error:

$ npm run doc

> esdoc-no-class-name-issue@1.0.0 doc /Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue
> esdoc -c esdoc.json

/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/ESDoc.js:378
            throw _iteratorError5;
                  ^
TypeError: Cannot read property 'name' of null
    at ClassDoc.name (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Doc/ClassDoc.js:70:39)
    at ClassDoc._apply (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Doc/AbstractDoc.js:68:20)
    at ClassDoc._apply (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Doc/ClassDoc.js:48:71)
    at ClassDoc.AbstractDoc (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Doc/AbstractDoc.js:54:10)
    at new ClassDoc (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Doc/ClassDoc.js:34:20)
    at DocFactory._createDoc (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Factory/DocFactory.js:388:14)
    at DocFactory._traverseComments (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Factory/DocFactory.js:318:24)
    at DocFactory.push (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Factory/DocFactory.js:206:26)
    at Controller.<anonymous> (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/ESDoc.js:411:17)
    at Controller.enter (/Users/azu/.ghq/github.com/azu/esdoc-no-class-name-issue/node_modules/esdoc/out/src/Util/ASTUtil.js:42:20)

I suggest that esdoc throw warning instead of error.

@h13i32maru
Copy link
Member

@azu Thank you for reporting this issue! Sorry, I did not know the specifications...

  • idea 1: ESDoc throws warning and not output document of an anonymous class.
  • idea 2: ESDoc treats all anonymous classes as export default class Anonymous {}.
  • idea 3: ESDoc guesses a name of an anonymous class from the file name.
    • e.g. with your repository, the anonymous class as export default class ExampleClass {}

I think that idea 3 is good. What do you think about ideas?

@azu
Copy link
Author

azu commented Jun 21, 2015

I vote for idea 3 👍
If you implement idea 3, need to validate the file name as valid JavaScript variable names.

@h13i32maru
Copy link
Member

I fixed this issue. I will release it in next version.

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

No branches or pull requests

2 participants