Skip to content

Bug: error when exporting indirect class #166

@typhonrt

Description

@typhonrt

ESDoc does not support export of indirect class instances. The following gives a simple test case.

'use strict';

class Test2 {}

class Test
{
   constructor()
   {
      this.Test2 = Test2;
   }
}
const test = new Test();

export default new test.Test2();

This will work, but is an undesirable workaround:

'use strict';

class Test2 {}

class Test
{
   constructor()
   {
      this.Test2 = Test2;
   }
}
const test = new Test();

const test2 = new test.Test2();

export default test2;

In my day to day usage of ESDoc this pops up when I try to export a Backbone.Events instance. Like the test example above Backbone is a composed class at runtime. IE this fails like the test case above:

'use strict';

import Backbone   from 'backbone';

export default new Backbone.Events();

Here is the stack trace. Note that I am using typhonjs-core-gulptasks which uses gulp-esdoc which embeds esdoc. I shortened the paths so ignore <FILEPATH>. The ESDoc version being used is 0.4.3.

<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/ESDoc.js:409
            throw _iteratorError5;
                  ^
TypeError: Cannot read property 'replace' of undefined
    at DocFactory._inspectExportDefaultDeclaration (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/Factory/DocFactory.js:170:51)
    at new DocFactory (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/Factory/DocFactory.js:101:10)
    at Function._traverse (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/ESDoc.js:439:21)
    at <FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/ESDoc.js:187:26
    at Function._walk (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/ESDoc.js:394:13)
    at Function._walk (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/ESDoc.js:396:18)
    at Function._walk (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/ESDoc.js:396:18)
    at Function.generate (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/esdoc/out/src/ESDoc.js:127:12)
    at DestroyableTransform.flush [as _flush] (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/index.js:31:11)
    at DestroyableTransform.<anonymous> (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:123:12)
    at DestroyableTransform.g (events.js:199:16)
    at DestroyableTransform.emit (events.js:104:17)
    at prefinish (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:499:12)
    at finishMaybe (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:507:7)
    at endWritable (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:519:3)
    at DestroyableTransform.Writable.end (<FILEPATH>/node_modules/typhonjs-core-gulptasks/node_modules/gulp-esdoc/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:484:5)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions