summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path
diff options
context:
space:
mode:
authorNode.js GitHub Bot <github-bot@iojs.org>2022-07-17 20:59:22 +0200
committerGitHub <noreply@github.com>2022-07-17 19:59:22 +0100
commit3e0965780bf63d3c7bd51700cfc1e11c4c180396 (patch)
tree20704fdfb472e4b93e3668fbc95a45ab63966628 /tools/node_modules/eslint/node_modules/@babel/traverse/lib/path
parent820b7104c528c7a0d6613750cf219fdb9920dec1 (diff)
downloadnode-new-3e0965780bf63d3c7bd51700cfc1e11c4c180396.tar.gz
tools: update eslint to 8.20.0
PR-URL: https://github.com/nodejs/node/pull/43873 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/node_modules/@babel/traverse/lib/path')
-rw-r--r--tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/index.js20
-rw-r--r--tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js32
-rw-r--r--tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js77
-rw-r--r--tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/util.js32
4 files changed, 87 insertions, 74 deletions
diff --git a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/index.js b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/index.js
index 0f9ba34a4b..4d0b3b9bbe 100644
--- a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/index.js
+++ b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/index.js
@@ -17,6 +17,7 @@ var _t = require("@babel/types");
const {
anyTypeAnnotation,
isAnyTypeAnnotation,
+ isArrayTypeAnnotation,
isBooleanTypeAnnotation,
isEmptyTypeAnnotation,
isFlowBaseAnnotation,
@@ -25,6 +26,10 @@ const {
isMixedTypeAnnotation,
isNumberTypeAnnotation,
isStringTypeAnnotation,
+ isTSArrayType,
+ isTSTypeAnnotation,
+ isTSTypeReference,
+ isTupleTypeAnnotation,
isTypeAnnotation,
isUnionTypeAnnotation,
isVoidTypeAnnotation,
@@ -40,7 +45,11 @@ function getTypeAnnotation() {
}
type = this._getTypeAnnotation() || anyTypeAnnotation();
- if (isTypeAnnotation(type)) type = type.typeAnnotation;
+
+ if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {
+ type = type.typeAnnotation;
+ }
+
this.setData("typeAnnotation", type);
return type;
}
@@ -156,7 +165,16 @@ function baseTypeStrictlyMatches(rightArg) {
function isGenericType(genericName) {
const type = this.getTypeAnnotation();
+
+ if (genericName === "Array") {
+ if (isTSArrayType(type) || isArrayTypeAnnotation(type) || isTupleTypeAnnotation(type)) {
+ return true;
+ }
+ }
+
return isGenericTypeAnnotation(type) && isIdentifier(type.id, {
name: genericName
+ }) || isTSTypeReference(type) && isIdentifier(type.typeName, {
+ name: genericName
});
} \ No newline at end of file
diff --git a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
index 0273106f03..4591fe75e0 100644
--- a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
+++ b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
@@ -7,13 +7,11 @@ exports.default = _default;
var _t = require("@babel/types");
+var _util = require("./util");
+
const {
BOOLEAN_NUMBER_BINARY_OPERATORS,
- createFlowUnionType,
- createTSUnionType,
createTypeAnnotationBasedOnTypeof,
- createUnionTypeAnnotation,
- isTSTypeAnnotation,
numberTypeAnnotation,
voidTypeAnnotation
} = _t;
@@ -61,15 +59,7 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
return;
}
- if (isTSTypeAnnotation(types[0]) && createTSUnionType) {
- return createTSUnionType(types);
- }
-
- if (createFlowUnionType) {
- return createFlowUnionType(types);
- }
-
- return createUnionTypeAnnotation(types);
+ return (0, _util.createUnionType)(types);
}
function getConstantViolationsBefore(binding, path, functions) {
@@ -182,22 +172,8 @@ function getConditionalAnnotation(binding, path, name) {
}
if (types.length) {
- if (isTSTypeAnnotation(types[0]) && createTSUnionType) {
- return {
- typeAnnotation: createTSUnionType(types),
- ifStatement
- };
- }
-
- if (createFlowUnionType) {
- return {
- typeAnnotation: createFlowUnionType(types),
- ifStatement
- };
- }
-
return {
- typeAnnotation: createUnionTypeAnnotation(types),
+ typeAnnotation: (0, _util.createUnionType)(types),
ifStatement
};
}
diff --git a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js
index be0a3e512c..e3727a4a71 100644
--- a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js
+++ b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js
@@ -26,6 +26,8 @@ exports.RegExpLiteral = RegExpLiteral;
exports.RestElement = RestElement;
exports.SequenceExpression = SequenceExpression;
exports.StringLiteral = StringLiteral;
+exports.TSAsExpression = TSAsExpression;
+exports.TSNonNullExpression = TSNonNullExpression;
exports.TaggedTemplateExpression = TaggedTemplateExpression;
exports.TemplateLiteral = TemplateLiteral;
exports.TypeCastExpression = TypeCastExpression;
@@ -37,6 +39,8 @@ var _t = require("@babel/types");
var _infererReference = require("./inferer-reference");
+var _util = require("./util");
+
const {
BOOLEAN_BINARY_OPERATORS,
BOOLEAN_UNARY_OPERATORS,
@@ -47,37 +51,20 @@ const {
arrayTypeAnnotation,
booleanTypeAnnotation,
buildMatchMemberExpression,
- createFlowUnionType,
- createTSUnionType,
- createUnionTypeAnnotation,
genericTypeAnnotation,
identifier,
- isTSTypeAnnotation,
nullLiteralTypeAnnotation,
numberTypeAnnotation,
stringTypeAnnotation,
tupleTypeAnnotation,
unionTypeAnnotation,
- voidTypeAnnotation
+ voidTypeAnnotation,
+ isIdentifier
} = _t;
function VariableDeclarator() {
- var _type;
-
- const id = this.get("id");
- if (!id.isIdentifier()) return;
- const init = this.get("init");
- let type = init.getTypeAnnotation();
-
- if (((_type = type) == null ? void 0 : _type.type) === "AnyTypeAnnotation") {
- if (init.isCallExpression() && init.get("callee").isIdentifier({
- name: "Array"
- }) && !init.scope.hasBinding("Array", true)) {
- type = ArrayExpression();
- }
- }
-
- return type;
+ if (!this.get("id").isIdentifier()) return;
+ return this.get("init").getTypeAnnotation();
}
function TypeCastExpression(node) {
@@ -86,6 +73,16 @@ function TypeCastExpression(node) {
TypeCastExpression.validParent = true;
+function TSAsExpression(node) {
+ return node.typeAnnotation;
+}
+
+TSAsExpression.validParent = true;
+
+function TSNonNullExpression() {
+ return this.get("expression").getTypeAnnotation();
+}
+
function NewExpression(node) {
if (node.callee.type === "Identifier") {
return genericTypeAnnotation(node.callee);
@@ -133,30 +130,12 @@ function BinaryExpression(node) {
function LogicalExpression() {
const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
-
- if (isTSTypeAnnotation(argumentTypes[0]) && createTSUnionType) {
- return createTSUnionType(argumentTypes);
- }
-
- if (createFlowUnionType) {
- return createFlowUnionType(argumentTypes);
- }
-
- return createUnionTypeAnnotation(argumentTypes);
+ return (0, _util.createUnionType)(argumentTypes);
}
function ConditionalExpression() {
const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
-
- if (isTSTypeAnnotation(argumentTypes[0]) && createTSUnionType) {
- return createTSUnionType(argumentTypes);
- }
-
- if (createFlowUnionType) {
- return createFlowUnionType(argumentTypes);
- }
-
- return createUnionTypeAnnotation(argumentTypes);
+ return (0, _util.createUnionType)(argumentTypes);
}
function SequenceExpression() {
@@ -229,7 +208,9 @@ function CallExpression() {
if (isObjectKeys(callee)) {
return arrayTypeAnnotation(stringTypeAnnotation());
- } else if (isArrayFrom(callee) || isObjectValues(callee)) {
+ } else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier(callee, {
+ name: "Array"
+ })) {
return arrayTypeAnnotation(anyTypeAnnotation());
} else if (isObjectEntries(callee)) {
return arrayTypeAnnotation(tupleTypeAnnotation([stringTypeAnnotation(), anyTypeAnnotation()]));
@@ -246,14 +227,20 @@ function resolveCall(callee) {
callee = callee.resolve();
if (callee.isFunction()) {
- if (callee.is("async")) {
- if (callee.is("generator")) {
+ const {
+ node
+ } = callee;
+
+ if (node.async) {
+ if (node.generator) {
return genericTypeAnnotation(identifier("AsyncIterator"));
} else {
return genericTypeAnnotation(identifier("Promise"));
}
} else {
- if (callee.node.returnType) {
+ if (node.generator) {
+ return genericTypeAnnotation(identifier("Iterator"));
+ } else if (callee.node.returnType) {
return callee.node.returnType;
} else {}
}
diff --git a/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/util.js b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/util.js
new file mode 100644
index 0000000000..c38267088a
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/@babel/traverse/lib/path/inference/util.js
@@ -0,0 +1,32 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.createUnionType = createUnionType;
+
+var _t = require("@babel/types");
+
+const {
+ createFlowUnionType,
+ createTSUnionType,
+ createUnionTypeAnnotation,
+ isFlowType,
+ isTSType
+} = _t;
+
+function createUnionType(types) {
+ {
+ if (isFlowType(types[0])) {
+ if (createFlowUnionType) {
+ return createFlowUnionType(types);
+ }
+
+ return createUnionTypeAnnotation(types);
+ } else {
+ if (createTSUnionType) {
+ return createTSUnionType(types);
+ }
+ }
+ }
+} \ No newline at end of file