Fix createImportSpecifier with typescript 4.5+#7426
Merged
devongovett merged 1 commit intoparcel-bundler:v2from Dec 13, 2021
Merged
Fix createImportSpecifier with typescript 4.5+#7426devongovett merged 1 commit intoparcel-bundler:v2from
devongovett merged 1 commit intoparcel-bundler:v2from
Conversation
|
devongovett
reviewed
Dec 13, 2021
| .split('.') | ||
| .map(num => parseInt(num, 10)); | ||
| // The signature of createImportSpecifier had a breaking change in Typescript 4.5. | ||
| // see: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#type-modifiers-on-import-names |
Member
There was a problem hiding this comment.
Wowwwwww... TS doesn't follow semver?? Maybe we should pin our dependency on it?
devongovett
approved these changes
Dec 13, 2021
Member
|
Though that would break if Typescript implemented |
Closed
bhovhannes
pushed a commit
to bhovhannes/parcel
that referenced
this pull request
Dec 23, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

↪️ Pull Request
This fixes #7325 and possibly also #7400. The issue, as @benpigchu pointed out here, was that Typescript 4.5 added support for type modifiers on specific import names. For example, it is now valid to write:
Unfortunately, the way that the compiler API was changed to support this is not backward compatible :-(
Here's what the pre-4.5 API looked like:
And here's the new API (see PR):
Since there's no way that I know of to check a function's arity at runtime, I had to resort to a version check.
There were several other backward-incompatible changes in that PR (to
updateImportSpecifier,createExportSpecifierandupdateExportSpecifier), and I verified that we don't use these APIs in parcel.💻 Examples
Without this change, when you have typescript 4.5+,
@parcel/transformer-typescript-typeswill generate output like:instead of
This change ensures that we do the right thing.
🚨 Test instructions
Several of the existing unit tests will break if you upgrade to typescript 4.5+ and don't apply this change, so it didn't seem necessary to add new ones.
I manually verified that with this change, and typescript 4.2.4 (the old version in the repo), all the unit tests still pass. You can test it yourself by modifying
yarn.lockto revert back to4.2.4, runningyarn install, thenyarn test:integration.✔️ PR Todo