convert @babel/helper-skip-transparent-expression-wrappers to typescript (#13686)
This commit is contained in:
parent
51a0caa8a2
commit
e0c3969a24
@ -1,5 +1,3 @@
|
||||
// @flow
|
||||
|
||||
import {
|
||||
isParenthesizedExpression,
|
||||
isTSAsExpression,
|
||||
@ -7,14 +5,25 @@ import {
|
||||
isTSTypeAssertion,
|
||||
isTypeCastExpression,
|
||||
} from "@babel/types";
|
||||
|
||||
import type * as t from "@babel/types";
|
||||
import type { NodePath } from "@babel/traverse";
|
||||
|
||||
export type TransparentExprWrapper =
|
||||
| t.TSAsExpression
|
||||
| t.TSTypeAssertion
|
||||
| t.TSNonNullExpression
|
||||
| t.TypeCastExpression
|
||||
| t.ParenthesizedExpression;
|
||||
|
||||
// A transparent expression wrapper is an AST node that most plugins will wish
|
||||
// to skip, as its presence does not affect the behaviour of the code. This
|
||||
// includes expressions used for types, and extra parenthesis. For example, in
|
||||
// (a as any)(), this helper can be used to skip the TSAsExpression when
|
||||
// determining the callee.
|
||||
export function isTransparentExprWrapper(node: Node) {
|
||||
export function isTransparentExprWrapper(
|
||||
node: t.Node,
|
||||
): node is TransparentExprWrapper {
|
||||
return (
|
||||
isTSAsExpression(node) ||
|
||||
isTSTypeAssertion(node) ||
|
||||
@ -24,10 +33,11 @@ export function isTransparentExprWrapper(node: Node) {
|
||||
);
|
||||
}
|
||||
|
||||
export function skipTransparentExprWrappers(path: NodePath): NodePath {
|
||||
export function skipTransparentExprWrappers(
|
||||
path: NodePath<t.Expression>,
|
||||
): NodePath<t.Expression> {
|
||||
while (isTransparentExprWrapper(path.node)) {
|
||||
path = path.get("expression");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
@ -22,7 +22,7 @@ function matchAffectedArguments(argumentNodes) {
|
||||
export function shouldTransform(
|
||||
path: NodePath<t.OptionalMemberExpression | t.OptionalCallExpression>,
|
||||
): boolean {
|
||||
let optionalPath = path;
|
||||
let optionalPath: NodePath<t.Expression> = path;
|
||||
const chains = [];
|
||||
while (
|
||||
optionalPath.isOptionalMemberExpression() ||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
"./packages/babel-helper-optimise-call-expression/src/**/*.ts",
|
||||
"./packages/babel-helper-replace-supers/src/**/*.ts",
|
||||
"./packages/babel-helper-simple-access/src/**/*.ts",
|
||||
"./packages/babel-helper-skip-transparent-expression-wrappers/src/**/*.ts",
|
||||
"./packages/babel-helper-split-export-declaration/src/**/*.ts",
|
||||
"./packages/babel-helper-transform-fixture-test-runner/src/**/*.ts",
|
||||
"./packages/babel-helper-validator-identifier/src/**/*.ts",
|
||||
@ -96,6 +97,9 @@
|
||||
"@babel/helper-simple-access": [
|
||||
"./packages/babel-helper-simple-access/src"
|
||||
],
|
||||
"@babel/helper-skip-transparent-expression-wrappers": [
|
||||
"./packages/babel-helper-skip-transparent-expression-wrappers/src"
|
||||
],
|
||||
"@babel/helper-split-export-declaration": [
|
||||
"./packages/babel-helper-split-export-declaration/src"
|
||||
],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user