Anonymous class #13

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

Comments

Projects
None yet
2 participants
@azu

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

This comment has been minimized.

Show comment
Hide comment
@h13i32maru

h13i32maru Jun 21, 2015

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?

Member

h13i32maru commented Jun 21, 2015

@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

This comment has been minimized.

Show comment
Hide comment
@azu

azu Jun 21, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@h13i32maru

h13i32maru Jun 30, 2015

Member

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

Member

h13i32maru commented Jun 30, 2015

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