Skip to content
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

Fix @babel/transform-typescript compatibility with Next.js #14610

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/babel-plugin-transform-typescript/src/index.ts
Expand Up @@ -575,8 +575,16 @@ export default declare((api, opts: Options) => {

[process.env.BABEL_8_BREAKING
? "TSNonNullExpression|TSInstantiationExpression"
: // This has been introduced in Babel 7.18.0
t.tsInstantiationExpression
: /* This has been introduced in Babel 7.18.0
We use api.types.* and not t.* for feature detection,
because the Babel version that is running this plugin
(where we check if the visitor is valid) might be different
from the Babel version that we resolve with `import "@babel/core"`.
This happens, for example, with Next.js that bundled `@babel/core`
but allows loading unbundled plugin (which cannot obviously import
the bundled `@babel/core` version).
*/
api.types.tsInstantiationExpression
? "TSNonNullExpression|TSInstantiationExpression"
: "TSNonNullExpression"](
path: NodePath<t.TSNonNullExpression | t.TSExpressionWithTypeArguments>,
Expand Down