Skip to content

Fix various issues with TS workaround #76

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

Merged
merged 3 commits into from
Nov 17, 2020
Merged

Fix various issues with TS workaround #76

merged 3 commits into from
Nov 17, 2020

Conversation

nonara
Copy link
Collaborator

@nonara nonara commented Nov 17, 2020

Fixes #72

Background

TypeScript type elision breaks when we transform an ImportDeclaration, ExportDeclaration, or the child property moduleSpecifier 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 created StringLiteral.

Fix Detail

We are now using the new updateNode method of the transformer factory API (which replaces the former getMutableClone) 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stopped working after upgrade to 2.0.0
1 participant