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 {
|
import {
|
||||||
isParenthesizedExpression,
|
isParenthesizedExpression,
|
||||||
isTSAsExpression,
|
isTSAsExpression,
|
||||||
@ -7,14 +5,25 @@ import {
|
|||||||
isTSTypeAssertion,
|
isTSTypeAssertion,
|
||||||
isTypeCastExpression,
|
isTypeCastExpression,
|
||||||
} from "@babel/types";
|
} from "@babel/types";
|
||||||
|
|
||||||
|
import type * as t from "@babel/types";
|
||||||
import type { NodePath } from "@babel/traverse";
|
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
|
// 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
|
// 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
|
// includes expressions used for types, and extra parenthesis. For example, in
|
||||||
// (a as any)(), this helper can be used to skip the TSAsExpression when
|
// (a as any)(), this helper can be used to skip the TSAsExpression when
|
||||||
// determining the callee.
|
// determining the callee.
|
||||||
export function isTransparentExprWrapper(node: Node) {
|
export function isTransparentExprWrapper(
|
||||||
|
node: t.Node,
|
||||||
|
): node is TransparentExprWrapper {
|
||||||
return (
|
return (
|
||||||
isTSAsExpression(node) ||
|
isTSAsExpression(node) ||
|
||||||
isTSTypeAssertion(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)) {
|
while (isTransparentExprWrapper(path.node)) {
|
||||||
path = path.get("expression");
|
path = path.get("expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ function matchAffectedArguments(argumentNodes) {
|
|||||||
export function shouldTransform(
|
export function shouldTransform(
|
||||||
path: NodePath<t.OptionalMemberExpression | t.OptionalCallExpression>,
|
path: NodePath<t.OptionalMemberExpression | t.OptionalCallExpression>,
|
||||||
): boolean {
|
): boolean {
|
||||||
let optionalPath = path;
|
let optionalPath: NodePath<t.Expression> = path;
|
||||||
const chains = [];
|
const chains = [];
|
||||||
while (
|
while (
|
||||||
optionalPath.isOptionalMemberExpression() ||
|
optionalPath.isOptionalMemberExpression() ||
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
"./packages/babel-helper-optimise-call-expression/src/**/*.ts",
|
"./packages/babel-helper-optimise-call-expression/src/**/*.ts",
|
||||||
"./packages/babel-helper-replace-supers/src/**/*.ts",
|
"./packages/babel-helper-replace-supers/src/**/*.ts",
|
||||||
"./packages/babel-helper-simple-access/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-split-export-declaration/src/**/*.ts",
|
||||||
"./packages/babel-helper-transform-fixture-test-runner/src/**/*.ts",
|
"./packages/babel-helper-transform-fixture-test-runner/src/**/*.ts",
|
||||||
"./packages/babel-helper-validator-identifier/src/**/*.ts",
|
"./packages/babel-helper-validator-identifier/src/**/*.ts",
|
||||||
@ -96,6 +97,9 @@
|
|||||||
"@babel/helper-simple-access": [
|
"@babel/helper-simple-access": [
|
||||||
"./packages/babel-helper-simple-access/src"
|
"./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": [
|
"@babel/helper-split-export-declaration": [
|
||||||
"./packages/babel-helper-split-export-declaration/src"
|
"./packages/babel-helper-split-export-declaration/src"
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user