Fix various issues with TS workaround #76
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #72
Background
TypeScript type elision breaks when we transform an
ImportDeclaration
,ExportDeclaration
, or the child propertymoduleSpecifier
on either of the former. (see: microsoft/TypeScript#40603). This resulted in type exports being output in resulting js output instead of the normal elision behaviour.To work around this, we used
ts.updateNode
in TS <4. In version 4+, however, this method was removed.Our first attempt at a new workaround was successful at restoring elision, however, it would break in instances where specific node-based information such as diagnostics were still referenced elsewhere. This is because we circumvented the API to directly replace the
moduleSpecifier
property with a newly createdStringLiteral
.Fix Detail
We are now using the new
updateNode
method of the transformer factory API (which replaces the formergetMutableClone
) in order to perform a somewhat lower-level replacement which does not cause elision functionality to break.In the future, if microsoft/TypeScript#40603 is resolved, we can switch to regular factory functions associated with updating the node types in question.
For now, however, this seems to work.
I've also added several specific tests for type elision functionality to ensure that this is checked in our build pipeline