Class decorator with object argument - `SyntaxError: Invalid regular expression`
Opened this issue · 3 comments
Using
"dependencies": {
"esdoc": "^1.0.3",
"esdoc-ecmascript-proposal-plugin": "^1.0.0",
"esdoc-jsx-plugin": "^1.0.0",
"esdoc-standard-plugin": "^1.0.0"
}
When using a class decorator with an object as argument, I run into this error:
SyntaxError: Invalid regular expression: /[~]Logger
level: 'debug'
})$/: Unmatched ')'
at RegExp (<anonymous>)
at ClassDocBuilder._findByName (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc-publish-html-plugin\out\src\Builder\DocBuilder.js:116:20)
at ClassDocBuilder._buildDocLinkHTML (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc-publish-html-plugin\out\src\Builder\DocBuilder.js:768:22)
at ClassDocBuilder._buildDecoratorHTML (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc-publish-html-plugin\out\src\Builder\DocBuilder.js:1012:25)
at ClassDocBuilder._buildClassDoc (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc-publish-html-plugin\out\src\Builder\ClassDocBuilder.js:87:32)
at ClassDocBuilder.exec (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc-publish-html-plugin\out\src\Builder\ClassDocBuilder.js:31:32)
at Plugin._exec (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc-publish-html-plugin\out\src\Plugin.js:93:63)
at Plugin.onPublish (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc-publish-html-plugin\out\src\Plugin.js:71:10)
at Plugin._execHandler (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc\out\src\Plugin\Plugin.js:55:26)
at Plugin.onPublish (D:\Projects\xai-jbm\jovi-r3r-experiments\docs\esdoc\node_modules\esdoc\out\src\Plugin\Plugin.js:154:10)
The stack trace is from this source code:
@Logger('Raycasting', { level: 0 })
export default class Raycasting { ... }
In general:
function Decorator() {}
// works:
@Decorator()
export default class MyClass { }
// works:
@Logger('foo')
export default class MyClass { }
// works:
const options = { level: 'debug' };
@Logger('foo', options )
export default class MyClass { }
// does not work:
@Logger({ level: 'debug' })
export default class MyClass { }
// does not work:
@Logger('foo', { level: 'debug' })
export default class MyClass { }
Important:
The error only happens using esdoc@1.0.3
- it does not happen using @1.0.2
or @1.01
I have traced this error to:
https://github.com/esdoc/esdoc-plugins/blob/master/esdoc-publish-html-plugin/src/Builder/DocBuilder.js
Line:
It's one of the Regular Expressions parsing the decorators. Here is a link at which Match 1 and 3 are as intended. Match 2 shows why the error exists.
http://rubular.com/r/6UdWsNAQS1
Who solves the RegEx, solves the bug. I'd prefer decorates would allow Simple Types, JSON Types and even functions in classic or Arrow (ES6) way.
An additional problem I found with regards to parsing Decorators originates from the core of ESDOC. See issue:
esdoc/esdoc#471