-
-
Notifications
You must be signed in to change notification settings - Fork 28
Workaround for Import/Export Declarations can break chained transformers #77
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
@dko-slapdash Thanks for the report. There were several issues due to that. It was an attempt to workaround an existing bug in TS. The latest version has an updated method which creates a mutable clone of the existing node.
Please try out the latest version and let me know if you have any issues. If the issue is related to no parent, the latest should work for you. PS. I appreciate the detail in your issue! Thanks for the added diligence. |
Thanks! I've just tried the version from master, got another error:
Same steps to reproduce as above. |
@dko-slapdash Thanks. I'll look into this tomorrow.
This is part of a sort of ongoing battle to find a workaround for an issue in the TS compiler: microsoft/TypeScript#40603 The short version is, I can't replace either an I have some ideas, so I'll have a look tomorrow and see if I can get it working for these edge cases. |
Interesting. What about watch mode BTW? We sometime notice that tsc stops responding to some particular (random) *.ts files changes in watch mode, and also that for such files, typescript-transform-paths v1 also stops outputting the right paths. Not possible to reproduce unfortunately. Is it somehow related to what you mentioned about watch mode? |
Watch mode can be tricky. We've seen quite a few issues related to watch mode in issues for ttypescript / ts-patch. It's been awhile since I've been in that part of the TS codebase, and I haven't dug too deep in, so I can't speak with total authority, however, if memory serves, watch mode minimizes redundancy as much as possible. I believe it rebuilds the If you're doing everything by the book, ie. using the prescribed factory functions to transform and create nodes during transform, things usually are able to track nicely. It can begin to break with any colouring outside the lines. Historically, doing so has been necessary to compensate for limitations with the compiler functions, or in other cases it's done simply because the TS compiler API is obscure and transformer authors understandably don't know the best practices. In our case, we are having to go outside of that for the time being. I believe there's a path to doing what we need with the mutable clone route. When TS fixes the bug upstream, we'll convert over to the proper method. I do notice that these errors seem to crop up around diagnostics being attached to a node which was improperly replaced. I don't think v1 of this library did anything like that, but I don't completely recall, as I wasn't involved at that point. It's also possible some things break down over time with continual rebuilding from some issue happening within TS where the AST / type info gets corrupted. I noticed that happening with the If you do encounter anything like that in the new version once we've got this issue sorted, please let me know. Most of the issues that get filed related to watch mode for ttypescript / tspatch don't have any repro, so I can't do anything. If there is an issue in TS, it'd be good to track that out. |
Ok. I'm looking over this now. Couple things:
|
b.ts is arbitrary - it can just be export const b = 42; P.S. |
Ok, here's my update on this.
The diagnostic looks like this: After some exploration, it looks like although it's functionally viable to replace the That unfortunately takes us back to our original problem, which is that if we set an To sum it up, I was hoping I could find a reasonable way around it to replicate the internal behaviour, but I'm at a point where I don't think it would be prudent to investigate trying to circumvent the setup any further, as it'd be too hacky. I think the best bet is to wait on TS for this. I will leave this issue open, and will notify when we have it sorted. |
Just a heads up - this is fixed in v2.1.0. We implemented proper type elision. No more workarounds. If interested, more detail can be found in #81 |
Hi.
The library uses
createLiteral()
(which is deprecated in the last TS BTW) which creates a token with parent=undefined. And other transformers (like typescript-is) may not like this: they expectparent
to always be defined.Steps to repro:
a.ts:
package.json:
tsconfig.json:
It crashes TS with the following error:
I printed what's in the original
node.moduleSpecifier
and what's inp
here: https://github.com/LeDDGroup/typescript-transform-paths/blob/master/src/index.ts#L228 - and here is the result:If I manually set
p.parent = node.moduleSpecifier.parent
prior to calling Object.assign(), the crash disappears (but only for some cases).Potential solution
I think that createLiteral() creates a "too raw" literal; the screenshot above shows that the properties of the "original" moduleSpecifier is very different from the new one (e.g.
parent
,pos
,flags
etc.). I tried to usefactory.cloneNode()
, but it's not for these purposes and didn't work, there must be something else to replace string literals in the code inplace.P.S.
I think this topic is related to typescript-transform-paths and not to e.g. typescript-is, because it's typescript-transform-paths who generates a "slightly non native" AST. Thus, other transformers which reasonably expect to receive a "native" AST will break.
The text was updated successfully, but these errors were encountered: