@typescript-eslint/type-utils 5.56.1-alpha.9 → 6.0.0-alpha.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_ts4.2/dist/TypeOrValueSpecifier.d.ts +112 -0
- package/_ts4.2/dist/containsAllTypesByName.d.ts +10 -0
- package/_ts4.2/dist/getConstrainedTypeAtLocation.d.ts +7 -0
- package/_ts4.2/dist/getContextualType.d.ts +8 -0
- package/_ts4.2/dist/getDeclaration.d.ts +7 -0
- package/_ts4.2/dist/getSourceFileOfNode.d.ts +6 -0
- package/_ts4.2/dist/getTokenAtPosition.d.ts +3 -0
- package/_ts4.2/dist/getTypeArguments.d.ts +3 -0
- package/_ts4.2/dist/getTypeName.d.ts +8 -0
- package/_ts4.2/dist/index.d.ts +17 -0
- package/_ts4.2/dist/isTypeReadonly.d.ts +118 -0
- package/_ts4.2/dist/isUnsafeAssignment.d.ts +17 -0
- package/_ts4.2/dist/predicates.d.ts +52 -0
- package/_ts4.2/dist/propertyTypes.d.ts +4 -0
- package/_ts4.2/dist/requiresQuoting.d.ts +4 -0
- package/_ts4.2/dist/typeFlagUtils.d.ts +11 -0
- package/dist/TypeOrValueSpecifier.d.ts +112 -0
- package/dist/TypeOrValueSpecifier.d.ts.map +1 -0
- package/dist/TypeOrValueSpecifier.js +141 -0
- package/dist/TypeOrValueSpecifier.js.map +1 -0
- package/dist/containsAllTypesByName.js +3 -3
- package/dist/containsAllTypesByName.js.map +1 -1
- package/dist/getConstrainedTypeAtLocation.d.ts +2 -1
- package/dist/getConstrainedTypeAtLocation.d.ts.map +1 -1
- package/dist/getConstrainedTypeAtLocation.js +6 -4
- package/dist/getConstrainedTypeAtLocation.js.map +1 -1
- package/dist/getContextualType.d.ts.map +1 -1
- package/dist/getContextualType.js +7 -8
- package/dist/getContextualType.js.map +1 -1
- package/dist/getDeclaration.d.ts +2 -1
- package/dist/getDeclaration.d.ts.map +1 -1
- package/dist/getDeclaration.js +3 -4
- package/dist/getDeclaration.js.map +1 -1
- package/dist/getTypeArguments.js +1 -2
- package/dist/getTypeArguments.js.map +1 -1
- package/dist/getTypeName.js +2 -2
- package/dist/getTypeName.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/isTypeReadonly.d.ts +99 -1
- package/dist/isTypeReadonly.d.ts.map +1 -1
- package/dist/isTypeReadonly.js +38 -25
- package/dist/isTypeReadonly.js.map +1 -1
- package/dist/isUnsafeAssignment.js +29 -7
- package/dist/isUnsafeAssignment.js.map +1 -1
- package/dist/predicates.js +2 -2
- package/dist/predicates.js.map +1 -1
- package/dist/typeFlagUtils.js +2 -2
- package/dist/typeFlagUtils.js.map +1 -1
- package/package.json +29 -22
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.containsAllTypesByName = void 0;
|
|
27
|
-
const
|
|
27
|
+
const tsutils = __importStar(require("ts-api-utils"));
|
|
28
28
|
const ts = __importStar(require("typescript"));
|
|
29
29
|
const typeFlagUtils_1 = require("./typeFlagUtils");
|
|
30
30
|
/**
|
|
@@ -38,7 +38,7 @@ function containsAllTypesByName(type, allowAny, allowedNames, matchAnyInstead =
|
|
|
38
38
|
if ((0, typeFlagUtils_1.isTypeFlagSet)(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
|
|
39
39
|
return !allowAny;
|
|
40
40
|
}
|
|
41
|
-
if (
|
|
41
|
+
if (tsutils.isTypeReference(type)) {
|
|
42
42
|
type = type.target;
|
|
43
43
|
}
|
|
44
44
|
const symbol = type.getSymbol();
|
|
@@ -46,7 +46,7 @@ function containsAllTypesByName(type, allowAny, allowedNames, matchAnyInstead =
|
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
48
|
const predicate = (t) => containsAllTypesByName(t, allowAny, allowedNames, matchAnyInstead);
|
|
49
|
-
if (
|
|
49
|
+
if (tsutils.isUnionOrIntersectionType(type)) {
|
|
50
50
|
return matchAnyInstead
|
|
51
51
|
? type.types.some(predicate)
|
|
52
52
|
: type.types.every(predicate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"containsAllTypesByName.js","sourceRoot":"","sources":["../src/containsAllTypesByName.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"containsAllTypesByName.js","sourceRoot":"","sources":["../src/containsAllTypesByName.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwC;AACxC,+CAAiC;AAEjC,mDAAgD;AAEhD;;;;;;GAMG;AACH,SAAgB,sBAAsB,CACpC,IAAa,EACb,QAAiB,EACjB,YAAyB,EACzB,eAAe,GAAG,KAAK;IAEvB,IAAI,IAAA,6BAAa,EAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;QAChE,OAAO,CAAC,QAAQ,CAAC;KAClB;IAED,IAAI,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QACjC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;KACpB;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,IAAI,MAAM,IAAI,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QAC3C,OAAO,IAAI,CAAC;KACb;IAED,MAAM,SAAS,GAAG,CAAC,CAAU,EAAW,EAAE,CACxC,sBAAsB,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC;IAErE,IAAI,OAAO,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE;QAC3C,OAAO,eAAe;YACpB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;YAC5B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;KACjC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IAElC,OAAO,CACL,KAAK,KAAK,SAAS;QACnB,CAAC,eAAe;YACd,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;YACvB,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAChD,CAAC;AACJ,CAAC;AApCD,wDAoCC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { ParserServicesWithTypeInformation, TSESTree } from '@typescript-eslint/typescript-estree';
|
|
1
2
|
import type * as ts from 'typescript';
|
|
2
3
|
/**
|
|
3
4
|
* Resolves the given node's type. Will resolve to the type's generic constraint, if it has one.
|
|
4
5
|
*/
|
|
5
|
-
export declare function getConstrainedTypeAtLocation(
|
|
6
|
+
export declare function getConstrainedTypeAtLocation(services: ParserServicesWithTypeInformation, node: TSESTree.Node): ts.Type;
|
|
6
7
|
//# sourceMappingURL=getConstrainedTypeAtLocation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getConstrainedTypeAtLocation.d.ts","sourceRoot":"","sources":["../src/getConstrainedTypeAtLocation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,
|
|
1
|
+
{"version":3,"file":"getConstrainedTypeAtLocation.d.ts","sourceRoot":"","sources":["../src/getConstrainedTypeAtLocation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iCAAiC,EACjC,QAAQ,EACT,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,iCAAiC,EAC3C,IAAI,EAAE,QAAQ,CAAC,IAAI,GAClB,EAAE,CAAC,IAAI,CAOT"}
|
|
@@ -4,10 +4,12 @@ exports.getConstrainedTypeAtLocation = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the given node's type. Will resolve to the type's generic constraint, if it has one.
|
|
6
6
|
*/
|
|
7
|
-
function getConstrainedTypeAtLocation(
|
|
8
|
-
const nodeType =
|
|
9
|
-
const constrained =
|
|
10
|
-
|
|
7
|
+
function getConstrainedTypeAtLocation(services, node) {
|
|
8
|
+
const nodeType = services.getTypeAtLocation(node);
|
|
9
|
+
const constrained = services.program
|
|
10
|
+
.getTypeChecker()
|
|
11
|
+
.getBaseConstraintOfType(nodeType);
|
|
12
|
+
return constrained ?? nodeType;
|
|
11
13
|
}
|
|
12
14
|
exports.getConstrainedTypeAtLocation = getConstrainedTypeAtLocation;
|
|
13
15
|
//# sourceMappingURL=getConstrainedTypeAtLocation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getConstrainedTypeAtLocation.js","sourceRoot":"","sources":["../src/getConstrainedTypeAtLocation.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getConstrainedTypeAtLocation.js","sourceRoot":"","sources":["../src/getConstrainedTypeAtLocation.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACH,SAAgB,4BAA4B,CAC1C,QAA2C,EAC3C,IAAmB;IAEnB,MAAM,QAAQ,GAAG,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO;SACjC,cAAc,EAAE;SAChB,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAErC,OAAO,WAAW,IAAI,QAAQ,CAAC;AACjC,CAAC;AAVD,oEAUC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContextualType.d.ts","sourceRoot":"","sources":["../src/getContextualType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getContextualType.d.ts","sourceRoot":"","sources":["../src/getContextualType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,EAAE,EAAE,CAAC,UAAU,GAClB,EAAE,CAAC,IAAI,GAAG,SAAS,CAuCrB"}
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getContextualType = void 0;
|
|
27
|
-
const tsutils_1 = require("tsutils");
|
|
28
27
|
const ts = __importStar(require("typescript"));
|
|
29
28
|
/**
|
|
30
29
|
* Returns the contextual type of a given node.
|
|
@@ -36,24 +35,24 @@ function getContextualType(checker, node) {
|
|
|
36
35
|
if (!parent) {
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
|
-
if (
|
|
38
|
+
if (ts.isCallExpression(parent) || ts.isNewExpression(parent)) {
|
|
40
39
|
if (node === parent.expression) {
|
|
41
40
|
// is the callee, so has no contextual type
|
|
42
41
|
return;
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
else if (
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
else if (ts.isVariableDeclaration(parent) ||
|
|
45
|
+
ts.isPropertyDeclaration(parent) ||
|
|
46
|
+
ts.isParameter(parent)) {
|
|
48
47
|
return parent.type ? checker.getTypeFromTypeNode(parent.type) : undefined;
|
|
49
48
|
}
|
|
50
|
-
else if (
|
|
49
|
+
else if (ts.isJsxExpression(parent)) {
|
|
51
50
|
return checker.getContextualType(parent);
|
|
52
51
|
}
|
|
53
|
-
else if (
|
|
52
|
+
else if (ts.isPropertyAssignment(parent) && ts.isIdentifier(node)) {
|
|
54
53
|
return checker.getContextualType(node);
|
|
55
54
|
}
|
|
56
|
-
else if (
|
|
55
|
+
else if (ts.isBinaryExpression(parent) &&
|
|
57
56
|
parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
58
57
|
parent.right === node) {
|
|
59
58
|
// is RHS of assignment
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContextualType.js","sourceRoot":"","sources":["../src/getContextualType.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"getContextualType.js","sourceRoot":"","sources":["../src/getContextualType.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,OAAuB,EACvB,IAAmB;IAEnB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,IAAI,CAAC,MAAM,EAAE;QACX,OAAO;KACR;IAED,IAAI,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE;QAC7D,IAAI,IAAI,KAAK,MAAM,CAAC,UAAU,EAAE;YAC9B,2CAA2C;YAC3C,OAAO;SACR;KACF;SAAM,IACL,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAChC,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAChC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EACtB;QACA,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;KAC3E;SAAM,IAAI,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE;QACrC,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;KAC1C;SAAM,IAAI,EAAE,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;QACnE,OAAO,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;KACxC;SAAM,IACL,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC;QAC7B,MAAM,CAAC,aAAa,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW;QACvD,MAAM,CAAC,KAAK,KAAK,IAAI,EACrB;QACA,uBAAuB;QACvB,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KAC/C;SAAM,IACL,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,QAAQ,CACjE,MAAM,CAAC,IAAI,CACZ,EACD;QACA,oEAAoE;QACpE,OAAO;KACR;IACD,2CAA2C;IAE3C,OAAO,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC;AA1CD,8CA0CC"}
|
package/dist/getDeclaration.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { ParserServicesWithTypeInformation, TSESTree } from '@typescript-eslint/typescript-estree';
|
|
1
2
|
import type * as ts from 'typescript';
|
|
2
3
|
/**
|
|
3
4
|
* Gets the declaration for the given variable
|
|
4
5
|
*/
|
|
5
|
-
export declare function getDeclaration(
|
|
6
|
+
export declare function getDeclaration(services: ParserServicesWithTypeInformation, node: TSESTree.Node): ts.Declaration | null;
|
|
6
7
|
//# sourceMappingURL=getDeclaration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDeclaration.d.ts","sourceRoot":"","sources":["../src/getDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,wBAAgB,cAAc,CAC5B,
|
|
1
|
+
{"version":3,"file":"getDeclaration.d.ts","sourceRoot":"","sources":["../src/getDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iCAAiC,EACjC,QAAQ,EACT,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,iCAAiC,EAC3C,IAAI,EAAE,QAAQ,CAAC,IAAI,GAClB,EAAE,CAAC,WAAW,GAAG,IAAI,CAOvB"}
|
package/dist/getDeclaration.js
CHANGED
|
@@ -4,14 +4,13 @@ exports.getDeclaration = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* Gets the declaration for the given variable
|
|
6
6
|
*/
|
|
7
|
-
function getDeclaration(
|
|
8
|
-
|
|
9
|
-
const symbol = checker.getSymbolAtLocation(node);
|
|
7
|
+
function getDeclaration(services, node) {
|
|
8
|
+
const symbol = services.getSymbolAtLocation(node);
|
|
10
9
|
if (!symbol) {
|
|
11
10
|
return null;
|
|
12
11
|
}
|
|
13
12
|
const declarations = symbol.getDeclarations();
|
|
14
|
-
return
|
|
13
|
+
return declarations?.[0] ?? null;
|
|
15
14
|
}
|
|
16
15
|
exports.getDeclaration = getDeclaration;
|
|
17
16
|
//# sourceMappingURL=getDeclaration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDeclaration.js","sourceRoot":"","sources":["../src/getDeclaration.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getDeclaration.js","sourceRoot":"","sources":["../src/getDeclaration.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACH,SAAgB,cAAc,CAC5B,QAA2C,EAC3C,IAAmB;IAEnB,MAAM,MAAM,GAAG,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,IAAI,CAAC;KACb;IACD,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC9C,OAAO,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC;AAVD,wCAUC"}
|
package/dist/getTypeArguments.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTypeArguments = void 0;
|
|
4
4
|
function getTypeArguments(type, checker) {
|
|
5
|
-
var _a;
|
|
6
5
|
// getTypeArguments was only added in TS3.7
|
|
7
6
|
if (checker.getTypeArguments) {
|
|
8
7
|
return checker.getTypeArguments(type);
|
|
9
8
|
}
|
|
10
|
-
return
|
|
9
|
+
return type.typeArguments ?? [];
|
|
11
10
|
}
|
|
12
11
|
exports.getTypeArguments = getTypeArguments;
|
|
13
12
|
//# sourceMappingURL=getTypeArguments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTypeArguments.js","sourceRoot":"","sources":["../src/getTypeArguments.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAC9B,IAAsB,EACtB,OAAuB
|
|
1
|
+
{"version":3,"file":"getTypeArguments.js","sourceRoot":"","sources":["../src/getTypeArguments.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAC9B,IAAsB,EACtB,OAAuB;IAEvB,2CAA2C;IAC3C,IAAI,OAAO,CAAC,gBAAgB,EAAE;QAC5B,OAAO,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACvC;IAED,OAAO,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC;AAClC,CAAC;AAVD,4CAUC"}
|
package/dist/getTypeName.js
CHANGED
|
@@ -43,8 +43,8 @@ function getTypeName(typeChecker, type) {
|
|
|
43
43
|
// the type parameter for some reason. So this gets the constraint type
|
|
44
44
|
// via AST.
|
|
45
45
|
const symbol = type.getSymbol();
|
|
46
|
-
const decls = symbol
|
|
47
|
-
const typeParamDecl = decls
|
|
46
|
+
const decls = symbol?.getDeclarations();
|
|
47
|
+
const typeParamDecl = decls?.[0];
|
|
48
48
|
if (ts.isTypeParameterDeclaration(typeParamDecl) &&
|
|
49
49
|
typeParamDecl.constraint != null) {
|
|
50
50
|
return getTypeName(typeChecker, typeChecker.getTypeFromTypeNode(typeParamDecl.constraint));
|
package/dist/getTypeName.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTypeName.js","sourceRoot":"","sources":["../src/getTypeName.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC;;;;GAIG;AACH,SAAgB,WAAW,CACzB,WAA2B,EAC3B,IAAa;IAEb,0DAA0D;IAC1D,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QAChD,OAAO,QAAQ,CAAC;KACjB;IAED,wEAAwE;IACxE,sEAAsE;IACtE,8BAA8B;IAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE;QACnD,sEAAsE;QACtE,uEAAuE;QACvE,WAAW;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"getTypeName.js","sourceRoot":"","sources":["../src/getTypeName.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC;;;;GAIG;AACH,SAAgB,WAAW,CACzB,WAA2B,EAC3B,IAAa;IAEb,0DAA0D;IAC1D,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QAChD,OAAO,QAAQ,CAAC;KACjB;IAED,wEAAwE;IACxE,sEAAsE;IACtE,8BAA8B;IAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE;QACnD,sEAAsE;QACtE,uEAAuE;QACvE,WAAW;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,MAAM,EAAE,eAAe,EAAE,CAAC;QACxC,MAAM,aAAa,GAAG,KAAK,EAAE,CAAC,CAAC,CAAgC,CAAC;QAChE,IACE,EAAE,CAAC,0BAA0B,CAAC,aAAa,CAAC;YAC5C,aAAa,CAAC,UAAU,IAAI,IAAI,EAChC;YACA,OAAO,WAAW,CAChB,WAAW,EACX,WAAW,CAAC,mBAAmB,CAAC,aAAa,CAAC,UAAU,CAAC,CAC1D,CAAC;SACH;KACF;IAED,qEAAqE;IACrE,gCAAgC;IAChC,2BAA2B;IAC3B,uCAAuC;IACvC,IACE,IAAI,CAAC,OAAO,EAAE;QACd,IAAI,CAAC,KAAK;aACP,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;aAC7C,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,EAC7B;QACA,OAAO,QAAQ,CAAC;KACjB;IAED,0EAA0E;IAC1E,uEAAuE;IACvE,IACE,IAAI,CAAC,cAAc,EAAE;QACrB,IAAI,CAAC,KAAK;aACP,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;aAC7C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,EAC5B;QACA,OAAO,QAAQ,CAAC;KACjB;IAED,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAvDD,kCAuDC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './isUnsafeAssignment';
|
|
|
11
11
|
export * from './predicates';
|
|
12
12
|
export * from './propertyTypes';
|
|
13
13
|
export * from './requiresQuoting';
|
|
14
|
+
export * from './TypeOrValueSpecifier';
|
|
14
15
|
export * from './typeFlagUtils';
|
|
15
16
|
export { getDecorators, getModifiers, typescriptVersionIsAtLeast, } from '@typescript-eslint/typescript-estree';
|
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,0BAA0B,GAC3B,MAAM,sCAAsC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,0BAA0B,GAC3B,MAAM,sCAAsC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ __exportStar(require("./isUnsafeAssignment"), exports);
|
|
|
28
28
|
__exportStar(require("./predicates"), exports);
|
|
29
29
|
__exportStar(require("./propertyTypes"), exports);
|
|
30
30
|
__exportStar(require("./requiresQuoting"), exports);
|
|
31
|
+
__exportStar(require("./TypeOrValueSpecifier"), exports);
|
|
31
32
|
__exportStar(require("./typeFlagUtils"), exports);
|
|
32
33
|
var typescript_estree_1 = require("@typescript-eslint/typescript-estree");
|
|
33
34
|
Object.defineProperty(exports, "getDecorators", { enumerable: true, get: function () { return typescript_estree_1.getDecorators; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,iEAA+C;AAC/C,sDAAoC;AACpC,mDAAiC;AACjC,wDAAsC;AACtC,uDAAqC;AACrC,qDAAmC;AACnC,gDAA8B;AAC9B,mDAAiC;AACjC,uDAAqC;AACrC,+CAA6B;AAC7B,kDAAgC;AAChC,oDAAkC;AAClC,kDAAgC;AAChC,0EAI8C;AAH5C,kHAAA,aAAa,OAAA;AACb,iHAAA,YAAY,OAAA;AACZ,+HAAA,0BAA0B,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,iEAA+C;AAC/C,sDAAoC;AACpC,mDAAiC;AACjC,wDAAsC;AACtC,uDAAqC;AACrC,qDAAmC;AACnC,gDAA8B;AAC9B,mDAAiC;AACjC,uDAAqC;AACrC,+CAA6B;AAC7B,kDAAgC;AAChC,oDAAkC;AAClC,yDAAuC;AACvC,kDAAgC;AAChC,0EAI8C;AAH5C,kHAAA,aAAa,OAAA;AACb,iHAAA,YAAY,OAAA;AACZ,+HAAA,0BAA0B,OAAA"}
|
package/dist/isTypeReadonly.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
+
import type { TypeOrValueSpecifier } from './TypeOrValueSpecifier';
|
|
2
3
|
export interface ReadonlynessOptions {
|
|
3
4
|
readonly treatMethodsAsReadonly?: boolean;
|
|
5
|
+
readonly allow?: TypeOrValueSpecifier[];
|
|
4
6
|
}
|
|
5
7
|
export declare const readonlynessOptionsSchema: {
|
|
6
8
|
type: string;
|
|
@@ -9,12 +11,108 @@ export declare const readonlynessOptionsSchema: {
|
|
|
9
11
|
treatMethodsAsReadonly: {
|
|
10
12
|
type: string;
|
|
11
13
|
};
|
|
14
|
+
allow: {
|
|
15
|
+
type: string;
|
|
16
|
+
items: {
|
|
17
|
+
oneOf: ({
|
|
18
|
+
type: string;
|
|
19
|
+
additionalProperties?: undefined;
|
|
20
|
+
properties?: undefined;
|
|
21
|
+
required?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
type: string;
|
|
24
|
+
additionalProperties: boolean;
|
|
25
|
+
properties: {
|
|
26
|
+
from: {
|
|
27
|
+
type: string;
|
|
28
|
+
const: string;
|
|
29
|
+
};
|
|
30
|
+
name: {
|
|
31
|
+
oneOf: ({
|
|
32
|
+
type: string;
|
|
33
|
+
minItems?: undefined;
|
|
34
|
+
uniqueItems?: undefined;
|
|
35
|
+
items?: undefined;
|
|
36
|
+
} | {
|
|
37
|
+
type: string;
|
|
38
|
+
minItems: number;
|
|
39
|
+
uniqueItems: boolean;
|
|
40
|
+
items: {
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
43
|
+
})[];
|
|
44
|
+
};
|
|
45
|
+
path: {
|
|
46
|
+
type: string;
|
|
47
|
+
};
|
|
48
|
+
package?: undefined;
|
|
49
|
+
};
|
|
50
|
+
required: string[];
|
|
51
|
+
} | {
|
|
52
|
+
type: string;
|
|
53
|
+
additionalProperties: boolean;
|
|
54
|
+
properties: {
|
|
55
|
+
from: {
|
|
56
|
+
type: string;
|
|
57
|
+
const: string;
|
|
58
|
+
};
|
|
59
|
+
name: {
|
|
60
|
+
oneOf: ({
|
|
61
|
+
type: string;
|
|
62
|
+
minItems?: undefined;
|
|
63
|
+
uniqueItems?: undefined;
|
|
64
|
+
items?: undefined;
|
|
65
|
+
} | {
|
|
66
|
+
type: string;
|
|
67
|
+
minItems: number;
|
|
68
|
+
uniqueItems: boolean;
|
|
69
|
+
items: {
|
|
70
|
+
type: string;
|
|
71
|
+
};
|
|
72
|
+
})[];
|
|
73
|
+
};
|
|
74
|
+
path?: undefined;
|
|
75
|
+
package?: undefined;
|
|
76
|
+
};
|
|
77
|
+
required: string[];
|
|
78
|
+
} | {
|
|
79
|
+
type: string;
|
|
80
|
+
additionalProperties: boolean;
|
|
81
|
+
properties: {
|
|
82
|
+
from: {
|
|
83
|
+
type: string;
|
|
84
|
+
const: string;
|
|
85
|
+
};
|
|
86
|
+
name: {
|
|
87
|
+
oneOf: ({
|
|
88
|
+
type: string;
|
|
89
|
+
minItems?: undefined;
|
|
90
|
+
uniqueItems?: undefined;
|
|
91
|
+
items?: undefined;
|
|
92
|
+
} | {
|
|
93
|
+
type: string;
|
|
94
|
+
minItems: number;
|
|
95
|
+
uniqueItems: boolean;
|
|
96
|
+
items: {
|
|
97
|
+
type: string;
|
|
98
|
+
};
|
|
99
|
+
})[];
|
|
100
|
+
};
|
|
101
|
+
package: {
|
|
102
|
+
type: string;
|
|
103
|
+
};
|
|
104
|
+
path?: undefined;
|
|
105
|
+
};
|
|
106
|
+
required: string[];
|
|
107
|
+
})[];
|
|
108
|
+
};
|
|
109
|
+
};
|
|
12
110
|
};
|
|
13
111
|
};
|
|
14
112
|
export declare const readonlynessOptionsDefaults: ReadonlynessOptions;
|
|
15
113
|
/**
|
|
16
114
|
* Checks if the given type is readonly
|
|
17
115
|
*/
|
|
18
|
-
declare function isTypeReadonly(
|
|
116
|
+
declare function isTypeReadonly(program: ts.Program, type: ts.Type, options?: ReadonlynessOptions): boolean;
|
|
19
117
|
export { isTypeReadonly };
|
|
20
118
|
//# sourceMappingURL=isTypeReadonly.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTypeReadonly.d.ts","sourceRoot":"","sources":["../src/isTypeReadonly.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isTypeReadonly.d.ts","sourceRoot":"","sources":["../src/isTypeReadonly.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAenE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,oBAAoB,EAAE,CAAC;CACzC;AAED,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAYrC,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,mBAGzC,CAAC;AAuSF;;GAEG;AACH,iBAAS,cAAc,CACrB,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,GAAE,mBAAiD,GACzD,OAAO,CAKT;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/isTypeReadonly.js
CHANGED
|
@@ -25,9 +25,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.isTypeReadonly = exports.readonlynessOptionsDefaults = exports.readonlynessOptionsSchema = void 0;
|
|
27
27
|
const utils_1 = require("@typescript-eslint/utils");
|
|
28
|
-
const
|
|
28
|
+
const tsutils = __importStar(require("ts-api-utils"));
|
|
29
29
|
const ts = __importStar(require("typescript"));
|
|
30
30
|
const propertyTypes_1 = require("./propertyTypes");
|
|
31
|
+
const TypeOrValueSpecifier_1 = require("./TypeOrValueSpecifier");
|
|
31
32
|
exports.readonlynessOptionsSchema = {
|
|
32
33
|
type: 'object',
|
|
33
34
|
additionalProperties: false,
|
|
@@ -35,22 +36,27 @@ exports.readonlynessOptionsSchema = {
|
|
|
35
36
|
treatMethodsAsReadonly: {
|
|
36
37
|
type: 'boolean',
|
|
37
38
|
},
|
|
39
|
+
allow: {
|
|
40
|
+
type: 'array',
|
|
41
|
+
items: TypeOrValueSpecifier_1.typeOrValueSpecifierSchema,
|
|
42
|
+
},
|
|
38
43
|
},
|
|
39
44
|
};
|
|
40
45
|
exports.readonlynessOptionsDefaults = {
|
|
41
46
|
treatMethodsAsReadonly: false,
|
|
47
|
+
allow: [],
|
|
42
48
|
};
|
|
43
49
|
function hasSymbol(node) {
|
|
44
50
|
return Object.prototype.hasOwnProperty.call(node, 'symbol');
|
|
45
51
|
}
|
|
46
|
-
function isTypeReadonlyArrayOrTuple(
|
|
52
|
+
function isTypeReadonlyArrayOrTuple(program, type, options, seenTypes) {
|
|
53
|
+
const checker = program.getTypeChecker();
|
|
47
54
|
function checkTypeArguments(arrayType) {
|
|
48
|
-
var _a;
|
|
49
55
|
const typeArguments =
|
|
50
56
|
// getTypeArguments was only added in TS3.7
|
|
51
57
|
checker.getTypeArguments
|
|
52
58
|
? checker.getTypeArguments(arrayType)
|
|
53
|
-
:
|
|
59
|
+
: arrayType.typeArguments ?? [];
|
|
54
60
|
// this shouldn't happen in reality as:
|
|
55
61
|
// - tuples require at least 1 type argument
|
|
56
62
|
// - ReadonlyArray requires at least 1 type argument
|
|
@@ -58,7 +64,7 @@ function isTypeReadonlyArrayOrTuple(checker, type, options, seenTypes) {
|
|
|
58
64
|
return 3 /* Readonlyness.Readonly */;
|
|
59
65
|
}
|
|
60
66
|
// validate the element types are also readonly
|
|
61
|
-
if (typeArguments.some(typeArg => isTypeReadonlyRecurser(
|
|
67
|
+
if (typeArguments.some(typeArg => isTypeReadonlyRecurser(program, typeArg, options, seenTypes) ===
|
|
62
68
|
2 /* Readonlyness.Mutable */)) {
|
|
63
69
|
return 2 /* Readonlyness.Mutable */;
|
|
64
70
|
}
|
|
@@ -80,7 +86,8 @@ function isTypeReadonlyArrayOrTuple(checker, type, options, seenTypes) {
|
|
|
80
86
|
}
|
|
81
87
|
return 1 /* Readonlyness.UnknownType */;
|
|
82
88
|
}
|
|
83
|
-
function isTypeReadonlyObject(
|
|
89
|
+
function isTypeReadonlyObject(program, type, options, seenTypes) {
|
|
90
|
+
const checker = program.getTypeChecker();
|
|
84
91
|
function checkIndexSignature(kind) {
|
|
85
92
|
const indexInfo = checker.getIndexInfoOfType(type, kind);
|
|
86
93
|
if (indexInfo) {
|
|
@@ -90,7 +97,7 @@ function isTypeReadonlyObject(checker, type, options, seenTypes) {
|
|
|
90
97
|
if (indexInfo.type === type || seenTypes.has(indexInfo.type)) {
|
|
91
98
|
return 3 /* Readonlyness.Readonly */;
|
|
92
99
|
}
|
|
93
|
-
return isTypeReadonlyRecurser(
|
|
100
|
+
return isTypeReadonlyRecurser(program, indexInfo.type, options, seenTypes);
|
|
94
101
|
}
|
|
95
102
|
return 1 /* Readonlyness.UnknownType */;
|
|
96
103
|
}
|
|
@@ -101,7 +108,7 @@ function isTypeReadonlyObject(checker, type, options, seenTypes) {
|
|
|
101
108
|
if (options.treatMethodsAsReadonly) {
|
|
102
109
|
if (property.valueDeclaration !== undefined &&
|
|
103
110
|
hasSymbol(property.valueDeclaration) &&
|
|
104
|
-
|
|
111
|
+
tsutils.isSymbolFlagSet(property.valueDeclaration.symbol, ts.SymbolFlags.Method)) {
|
|
105
112
|
continue;
|
|
106
113
|
}
|
|
107
114
|
const declarations = property.getDeclarations();
|
|
@@ -110,11 +117,11 @@ function isTypeReadonlyObject(checker, type, options, seenTypes) {
|
|
|
110
117
|
: undefined;
|
|
111
118
|
if (lastDeclaration !== undefined &&
|
|
112
119
|
hasSymbol(lastDeclaration) &&
|
|
113
|
-
|
|
120
|
+
tsutils.isSymbolFlagSet(lastDeclaration.symbol, ts.SymbolFlags.Method)) {
|
|
114
121
|
continue;
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
|
-
if (
|
|
124
|
+
if (tsutils.isPropertyReadonlyInType(type, property.getEscapedName(), checker)) {
|
|
118
125
|
continue;
|
|
119
126
|
}
|
|
120
127
|
const name = ts.getNameOfDeclaration(property.valueDeclaration);
|
|
@@ -135,7 +142,7 @@ function isTypeReadonlyObject(checker, type, options, seenTypes) {
|
|
|
135
142
|
if (seenTypes.has(propertyType)) {
|
|
136
143
|
continue;
|
|
137
144
|
}
|
|
138
|
-
if (isTypeReadonlyRecurser(
|
|
145
|
+
if (isTypeReadonlyRecurser(program, propertyType, options, seenTypes) ===
|
|
139
146
|
2 /* Readonlyness.Mutable */) {
|
|
140
147
|
return 2 /* Readonlyness.Mutable */;
|
|
141
148
|
}
|
|
@@ -152,42 +159,48 @@ function isTypeReadonlyObject(checker, type, options, seenTypes) {
|
|
|
152
159
|
return 3 /* Readonlyness.Readonly */;
|
|
153
160
|
}
|
|
154
161
|
// a helper function to ensure the seenTypes map is always passed down, except by the external caller
|
|
155
|
-
function isTypeReadonlyRecurser(
|
|
162
|
+
function isTypeReadonlyRecurser(program, type, options, seenTypes) {
|
|
163
|
+
const checker = program.getTypeChecker();
|
|
156
164
|
seenTypes.add(type);
|
|
157
|
-
if ((0,
|
|
165
|
+
if (options.allow?.some(specifier => (0, TypeOrValueSpecifier_1.typeMatchesSpecifier)(type, specifier, program))) {
|
|
166
|
+
return 3 /* Readonlyness.Readonly */;
|
|
167
|
+
}
|
|
168
|
+
if (tsutils.isUnionType(type)) {
|
|
158
169
|
// all types in the union must be readonly
|
|
159
|
-
const result =
|
|
160
|
-
|
|
170
|
+
const result = tsutils
|
|
171
|
+
.unionTypeParts(type)
|
|
172
|
+
.every(t => seenTypes.has(t) ||
|
|
173
|
+
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
|
161
174
|
3 /* Readonlyness.Readonly */);
|
|
162
175
|
const readonlyness = result ? 3 /* Readonlyness.Readonly */ : 2 /* Readonlyness.Mutable */;
|
|
163
176
|
return readonlyness;
|
|
164
177
|
}
|
|
165
|
-
if (
|
|
178
|
+
if (tsutils.isIntersectionType(type)) {
|
|
166
179
|
// Special case for handling arrays/tuples (as readonly arrays/tuples always have mutable methods).
|
|
167
180
|
if (type.types.some(t => checker.isArrayType(t) || checker.isTupleType(t))) {
|
|
168
181
|
const allReadonlyParts = type.types.every(t => seenTypes.has(t) ||
|
|
169
|
-
isTypeReadonlyRecurser(
|
|
182
|
+
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
|
170
183
|
3 /* Readonlyness.Readonly */);
|
|
171
184
|
return allReadonlyParts ? 3 /* Readonlyness.Readonly */ : 2 /* Readonlyness.Mutable */;
|
|
172
185
|
}
|
|
173
186
|
// Normal case.
|
|
174
|
-
const isReadonlyObject = isTypeReadonlyObject(
|
|
187
|
+
const isReadonlyObject = isTypeReadonlyObject(program, type, options, seenTypes);
|
|
175
188
|
if (isReadonlyObject !== 1 /* Readonlyness.UnknownType */) {
|
|
176
189
|
return isReadonlyObject;
|
|
177
190
|
}
|
|
178
191
|
}
|
|
179
|
-
if (
|
|
192
|
+
if (tsutils.isConditionalType(type)) {
|
|
180
193
|
const result = [type.root.node.trueType, type.root.node.falseType]
|
|
181
194
|
.map(checker.getTypeFromTypeNode)
|
|
182
195
|
.every(t => seenTypes.has(t) ||
|
|
183
|
-
isTypeReadonlyRecurser(
|
|
196
|
+
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
|
184
197
|
3 /* Readonlyness.Readonly */);
|
|
185
198
|
const readonlyness = result ? 3 /* Readonlyness.Readonly */ : 2 /* Readonlyness.Mutable */;
|
|
186
199
|
return readonlyness;
|
|
187
200
|
}
|
|
188
201
|
// all non-object, non-intersection types are readonly.
|
|
189
202
|
// this should only be primitive types
|
|
190
|
-
if (!
|
|
203
|
+
if (!tsutils.isObjectType(type)) {
|
|
191
204
|
return 3 /* Readonlyness.Readonly */;
|
|
192
205
|
}
|
|
193
206
|
// pure function types are readonly
|
|
@@ -195,11 +208,11 @@ function isTypeReadonlyRecurser(checker, type, options, seenTypes) {
|
|
|
195
208
|
type.getProperties().length === 0) {
|
|
196
209
|
return 3 /* Readonlyness.Readonly */;
|
|
197
210
|
}
|
|
198
|
-
const isReadonlyArray = isTypeReadonlyArrayOrTuple(
|
|
211
|
+
const isReadonlyArray = isTypeReadonlyArrayOrTuple(program, type, options, seenTypes);
|
|
199
212
|
if (isReadonlyArray !== 1 /* Readonlyness.UnknownType */) {
|
|
200
213
|
return isReadonlyArray;
|
|
201
214
|
}
|
|
202
|
-
const isReadonlyObject = isTypeReadonlyObject(
|
|
215
|
+
const isReadonlyObject = isTypeReadonlyObject(program, type, options, seenTypes);
|
|
203
216
|
/* istanbul ignore else */ if (isReadonlyObject !== 1 /* Readonlyness.UnknownType */) {
|
|
204
217
|
return isReadonlyObject;
|
|
205
218
|
}
|
|
@@ -208,8 +221,8 @@ function isTypeReadonlyRecurser(checker, type, options, seenTypes) {
|
|
|
208
221
|
/**
|
|
209
222
|
* Checks if the given type is readonly
|
|
210
223
|
*/
|
|
211
|
-
function isTypeReadonly(
|
|
212
|
-
return (isTypeReadonlyRecurser(
|
|
224
|
+
function isTypeReadonly(program, type, options = exports.readonlynessOptionsDefaults) {
|
|
225
|
+
return (isTypeReadonlyRecurser(program, type, options, new Set()) ===
|
|
213
226
|
3 /* Readonlyness.Readonly */);
|
|
214
227
|
}
|
|
215
228
|
exports.isTypeReadonly = isTypeReadonly;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTypeReadonly.js","sourceRoot":"","sources":["../src/isTypeReadonly.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuD;AACvD,
|
|
1
|
+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