-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Error using before transforms on files with decorators and class constructor parameter #17551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm actually running into a very similar problem. I am currently attempting to decorate fields of a class while using transpilation. By default the code is breaking on the fact that the PropertyDeclarations do not have a parent property set generating new elements. Using the built in visitor, the parent relationship seems to be severed. Additionally, if I do add the parent relationship in manually, I am failing in the exact same way above, that the symbol information is not updated or created when using the visitor pattern. The createNode/updateNode flow leaves me with a SourceFile object and no symbol data. |
Attaching a gist that is able to reproduce both issues I mentioned above https://gist.github.com/arciisine/2ba754f561d3e28b138aeed686a800d3 |
Did some investigation into the issue and it seems that the underlying cause is surfaced (in this case) by enabling the emit decorator metadata compiler option. When the source file node is updated, the symbol is removed from the node. The TS transformer tries to use the symbol to generate the type information for the decorator metadata but the symbol is no longer accessible from the node. The call into the emit resolver that throws is https://github.com/Microsoft/TypeScript/blob/master/src/compiler/transformers/ts.ts#L1875 |
Also, haven't done any additional tests but similar issues may arise in other areas that assume a node has a symbol. |
This seems related to #17384. Maybe the workaround there also works here. |
An interim fix could be to get the original node within |
@tbosch thanks for the pointer. I integrated the tsickle transformers into my workflow, and it resolved the code errors I was seeing. Though it seems to have no impact on import eliding, as I'm losing the import my identifier is referencing. |
Awesome, thanks for the fix @rbuckton ! |
Description of the bug:
When using any before transform on a file containing a class with both:
An error will be thrown (
TypeError: Cannot read property 'exports' of undefined at resolveNameHelper
).This error goes away if:
before
toafter
boolean
,number
, etc).TypeScript Version: 2.4.2
Code
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
Expected behavior:
File is emitted without errors.
Actual behavior:
An error is thrown:
/cc @rbuckton
The text was updated successfully, but these errors were encountered: