Skip to content

Commit

Permalink
Fix @babel/transform-typescript compatibility with Next.js (#14610)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 29, 2022
1 parent e8c4b78 commit 6d59ed7
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 6d59ed7

Please sign in to comment.