Closed
Description
Description of the bug:
When using any before transform on a file containing a class with both:
- a decorator
- a constructor parameter with a class type
An error will be thrown (TypeError: Cannot read property 'exports' of undefined at resolveNameHelper
).
This error goes away if:
- the transform is removed
- the transform is moved from
before
toafter
- the decorator is removed
- the constructor type is changed from a class to a basic type (
boolean
,number
, etc).
TypeScript Version: 2.4.2
Code
function classDecorator<T extends { new(...args: any[]): {} }>(constructor: T) {
return class extends constructor { }
}
class SomeClass {}
@classDecorator
export class AppComponent {
constructor(test: SomeClass) { }
}
'change me';
Reproduction of this bug requires using the transforms API.
I have prepared a repository with a simple reproduction that runs this file: https://github.com/filipesilva/ts-transform-decorator-bug/blob/master/test.ts
git clone https://github.com/filipesilva/ts-transform-decorator-bug
cd ts-transform-decorator-bug
npm install
npm test
Expected behavior:
File is emitted without errors.
Actual behavior:
An error is thrown:
D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:27546
var moduleExports = getSymbolOfNode(location).exports;
^
TypeError: Cannot read property 'exports' of undefined
at resolveNameHelper (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:27546:70)
at resolveName (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:27491:20)
at resolveEntityName (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:28152:26)
at Object.getTypeReferenceSerializationKind (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:47726:31)
at serializeTypeReferenceNode (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:52219:30)
at serializeTypeNode (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:52167:28)
at serializeTypeOfNode (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:52039:28)
at serializeParameterTypesOfNode (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:52074:42)
at addOldTypeMetadata (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:51962:98)
at addTypeMetadata (D:\sandbox\ts-transform-decorator-bug\node_modules\typescript\lib\typescript.js:51953:17)
/cc @rbuckton