Skip to content

Commit

Permalink
Add to transform plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 16, 2022
1 parent ac6d138 commit 110b104
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Expand Up @@ -2,6 +2,7 @@ import {
isParenthesizedExpression,
isTSAsExpression,
isTSNonNullExpression,
isTSSatisfiesExpression,
isTSTypeAssertion,
isTypeCastExpression,
} from "@babel/types";
Expand All @@ -11,6 +12,7 @@ import type { NodePath } from "@babel/traverse";

export type TransparentExprWrapper =
| t.TSAsExpression
| t.TSSatisfiesExpression
| t.TSTypeAssertion
| t.TSNonNullExpression
| t.TypeCastExpression
Expand All @@ -26,6 +28,7 @@ export function isTransparentExprWrapper(
): node is TransparentExprWrapper {
return (
isTSAsExpression(node) ||
isTSSatisfiesExpression(node) ||
isTSTypeAssertion(node) ||
isTSNonNullExpression(node) ||
isTypeCastExpression(node) ||
Expand Down
7 changes: 5 additions & 2 deletions packages/babel-plugin-transform-typescript/src/index.ts
Expand Up @@ -593,11 +593,14 @@ export default declare((api, opts: Options) => {
path.replaceWith(path.node.expression);
},

TSAsExpression(path) {
[`TSAsExpression${
// Added in Babel 7.17.0
t.tsSatisfiesExpression ? "|TSSatisfiesExpression" : ""
}`](path: NodePath<t.TSAsExpression | t.TSSatisfiesExpression>) {
let { node }: { node: t.Expression } = path;
do {
node = node.expression;
} while (t.isTSAsExpression(node));
} while (t.isTSAsExpression(node) || t.isTSSatisfiesExpression?.(node));
path.replaceWith(node);
},

Expand Down

0 comments on commit 110b104

Please sign in to comment.