plugin-proposal-decorators and TypeScript index signatures
- Dominant language
- TypeScript
- Stars
- 44k
- Forks
- 6k
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 23
Description
## Bug Report
**Current Behavior**
Classes using decorators _and_ TypeScript index signatures result in a crash.
```
TypeError: Cannot read property 'value' of undefined
at getKey (/Users/janbuschtoens/clark/application/node_modules/@babel/plugin-proposal-decorators/lib/transformer.js:89:56)
at getSingleElementDefinition (/Users/janbuschtoens/clark/application/node_modules/@babel/plugin-proposal-decorators/lib/transformer.js:113:219)
at getElementsDefinitions (/Users/janbuschtoens/clark/application/node_modules/@babel/plugin-proposal-decorators/lib/transformer.js:124:21)
at transformClass (/Users/janbuschtoens/clark/application/node_modules/@babel/plugin-proposal-decorators/lib/transformer.js:187:23)
at PluginPass.Class (/Users/janbuschtoens/clark/application/node_modules/@babel/plugin-proposal-decorators/lib/transformer.js:229:24)
at newFn (/Users/janbuschtoens/clark/application/node_modules/@babel/traverse/lib/visitors.js:193:21)
at NodePath._call (/Users/janbuschtoens/clark/application/node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/Users/janbuschtoens/clark/application/node_modules/@babel/traverse/lib/path/context.js:40:17)
at NodePath.visit (/Users/janbuschtoens/clark/application/node_modules/@babel/traverse/lib/path/context.js:88:12)
at TraversalContext.visitQueue (/Users/janbuschtoens/clark/application/node_modules/@babel/traverse/lib/context.js:118:16)
```
https://github.com/babel/babel/blob/35815832b56bcc85aeeb461bdddb3ff7c4e859dc/packages/babel-plugin-proposal-decorators/src/transformer.js#L42-L50
Error is in L48. `node` is a `TSIndexSignature`, which does not have a `key` property.
**Input Code**
```ts
class Foo {
[key: string]: any;
@deco
method() {}
}
```
**Expected behavior/code**
No crash. The decorator should be transformed as expected and the index signature should be stripped.
**Babel Configuration (.babelrc, package.json, cli command)**
```js
{
plugins: [
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-transform-typescript'
]
}
```
**Environment**
- Babel version(s): v7.2.1
- How you are using Babel: ember-cli-babel
**Possible Solution**
Check with `t.isXXXXX`, that this is actually a class field or method. Otherwise skip.
/cc @chriskrycho @ef4 @boris-petrov
Contributor guide
Assessment
This issue has not been assessed yet.