webcomponents / webcomponents/custom-elements-manifest
Add support for symbol-named class members
- Dominant language
- TypeScript
- Stars
- 502
- Forks
- 27
- PR merge metrics
- No merged PRs in 30d
Description
The manifest cannot currently describe class members whose name is defined using a symbol, which is valid JS and [not uncommonly](https://component.kitchen/elix/mixins#string-names-vs-symbol-keys) used:
```js
const foo = Symbol('foo');
class MyElement extends HTMLElement {
[foo]() {
console.log('foo called');
}
}
```
This could be represented in the manifest by expanding the model for a class field's `name` to either be a `string` or `Reference` to a symbol's declaration. However, currently the `name` field for class members (currently defined on `PropertyLike`) is typed as a `string` and required, so a change to this type would represent a breaking change.
A (mostly?) backward compatible way to represent such class members could be to add an optional `nameReference?: Reference` field to `ClassField` and `ClassMethod`, which would be interpreted as a reference to a symbol's `VariableDeclaration` when present. Because `name` would still be required, it could be filled with a "display string" used for e.g. documentation viewers, e.g.:
```json
{
"name": "Symbol('foo')"
"nameReference": {
"package": "my-package",
"module": "foo.js",
"name": "foo"
}
}
```
"Mostly" because tools could possibly be using `name` for purposes other than display, in which case it's still wrong, and might be better to just make a breaking change to support it.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.