docdown
docdown copied to clipboard
Constructor entries break the parser
Attempting conversion on a source file that contains a class constructor or function marked w/ @constructor
breaks the parser.
Cause
The issue starts here
https://github.com/jdalton/docdown/blob/297e61f2ef179b4cebca9656cb4eac2dbdd18669/lib/generator.js#L100
Further down it attempts to dynamically assign the key organized.constructor
https://github.com/jdalton/docdown/blob/297e61f2ef179b4cebca9656cb4eac2dbdd18669/lib/generator.js#L130
This results in a tocGroup
receiving a TypeError as a value which throws when tocGroup.push
is called here
https://github.com/jdalton/docdown/blob/297e61f2ef179b4cebca9656cb4eac2dbdd18669/lib/generator.js#L147
Resolution
The issue is due to trying to use an object that inherits from Object
as a key/value store. The name of organized (ie an array) tries and fails to overwrite the existing constructor function.
To fix this, organized
can be initialized with an object literal that doesn't inherit any properties/methods from Object
with.
organized = Object.create(null),
It's possible this may also resolve #45