@typescript-eslint/type-utils 6.0.0-alpha.94 → 6.0.0-alpha.95
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/index.d.ts +1 -0
- package/_ts4.2/dist/isTypeReadonly.d.ts +99 -1
- 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/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 +26 -14
- package/dist/isTypeReadonly.js.map +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
interface FileSpecifier {
|
|
3
|
+
from: 'file';
|
|
4
|
+
name: string | string[];
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
interface LibSpecifier {
|
|
8
|
+
from: 'lib';
|
|
9
|
+
name: string | string[];
|
|
10
|
+
}
|
|
11
|
+
interface PackageSpecifier {
|
|
12
|
+
from: 'package';
|
|
13
|
+
name: string | string[];
|
|
14
|
+
package: string;
|
|
15
|
+
}
|
|
16
|
+
export type TypeOrValueSpecifier = string | FileSpecifier | LibSpecifier | PackageSpecifier;
|
|
17
|
+
export declare const typeOrValueSpecifierSchema: {
|
|
18
|
+
oneOf: ({
|
|
19
|
+
type: string;
|
|
20
|
+
additionalProperties?: undefined;
|
|
21
|
+
properties?: undefined;
|
|
22
|
+
required?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
type: string;
|
|
25
|
+
additionalProperties: boolean;
|
|
26
|
+
properties: {
|
|
27
|
+
from: {
|
|
28
|
+
type: string;
|
|
29
|
+
const: string;
|
|
30
|
+
};
|
|
31
|
+
name: {
|
|
32
|
+
oneOf: ({
|
|
33
|
+
type: string;
|
|
34
|
+
minItems?: undefined;
|
|
35
|
+
uniqueItems?: undefined;
|
|
36
|
+
items?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
type: string;
|
|
39
|
+
minItems: number;
|
|
40
|
+
uniqueItems: boolean;
|
|
41
|
+
items: {
|
|
42
|
+
type: string;
|
|
43
|
+
};
|
|
44
|
+
})[];
|
|
45
|
+
};
|
|
46
|
+
path: {
|
|
47
|
+
type: string;
|
|
48
|
+
};
|
|
49
|
+
package?: undefined;
|
|
50
|
+
};
|
|
51
|
+
required: string[];
|
|
52
|
+
} | {
|
|
53
|
+
type: string;
|
|
54
|
+
additionalProperties: boolean;
|
|
55
|
+
properties: {
|
|
56
|
+
from: {
|
|
57
|
+
type: string;
|
|
58
|
+
const: string;
|
|
59
|
+
};
|
|
60
|
+
name: {
|
|
61
|
+
oneOf: ({
|
|
62
|
+
type: string;
|
|
63
|
+
minItems?: undefined;
|
|
64
|
+
uniqueItems?: undefined;
|
|
65
|
+
items?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
type: string;
|
|
68
|
+
minItems: number;
|
|
69
|
+
uniqueItems: boolean;
|
|
70
|
+
items: {
|
|
71
|
+
type: string;
|
|
72
|
+
};
|
|
73
|
+
})[];
|
|
74
|
+
};
|
|
75
|
+
path?: undefined;
|
|
76
|
+
package?: undefined;
|
|
77
|
+
};
|
|
78
|
+
required: string[];
|
|
79
|
+
} | {
|
|
80
|
+
type: string;
|
|
81
|
+
additionalProperties: boolean;
|
|
82
|
+
properties: {
|
|
83
|
+
from: {
|
|
84
|
+
type: string;
|
|
85
|
+
const: string;
|
|
86
|
+
};
|
|
87
|
+
name: {
|
|
88
|
+
oneOf: ({
|
|
89
|
+
type: string;
|
|
90
|
+
minItems?: undefined;
|
|
91
|
+
uniqueItems?: undefined;
|
|
92
|
+
items?: undefined;
|
|
93
|
+
} | {
|
|
94
|
+
type: string;
|
|
95
|
+
minItems: number;
|
|
96
|
+
uniqueItems: boolean;
|
|
97
|
+
items: {
|
|
98
|
+
type: string;
|
|
99
|
+
};
|
|
100
|
+
})[];
|
|
101
|
+
};
|
|
102
|
+
package: {
|
|
103
|
+
type: string;
|
|
104
|
+
};
|
|
105
|
+
path?: undefined;
|
|
106
|
+
};
|
|
107
|
+
required: string[];
|
|
108
|
+
})[];
|
|
109
|
+
};
|
|
110
|
+
export declare function typeMatchesSpecifier(type: ts.Type, specifier: TypeOrValueSpecifier, program: ts.Program): boolean;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=TypeOrValueSpecifier.d.ts.map
|
package/_ts4.2/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
|
|
@@ -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
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
interface FileSpecifier {
|
|
3
|
+
from: 'file';
|
|
4
|
+
name: string | string[];
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
interface LibSpecifier {
|
|
8
|
+
from: 'lib';
|
|
9
|
+
name: string | string[];
|
|
10
|
+
}
|
|
11
|
+
interface PackageSpecifier {
|
|
12
|
+
from: 'package';
|
|
13
|
+
name: string | string[];
|
|
14
|
+
package: string;
|
|
15
|
+
}
|
|
16
|
+
export type TypeOrValueSpecifier = string | FileSpecifier | LibSpecifier | PackageSpecifier;
|
|
17
|
+
export declare const typeOrValueSpecifierSchema: {
|
|
18
|
+
oneOf: ({
|
|
19
|
+
type: string;
|
|
20
|
+
additionalProperties?: undefined;
|
|
21
|
+
properties?: undefined;
|
|
22
|
+
required?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
type: string;
|
|
25
|
+
additionalProperties: boolean;
|
|
26
|
+
properties: {
|
|
27
|
+
from: {
|
|
28
|
+
type: string;
|
|
29
|
+
const: string;
|
|
30
|
+
};
|
|
31
|
+
name: {
|
|
32
|
+
oneOf: ({
|
|
33
|
+
type: string;
|
|
34
|
+
minItems?: undefined;
|
|
35
|
+
uniqueItems?: undefined;
|
|
36
|
+
items?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
type: string;
|
|
39
|
+
minItems: number;
|
|
40
|
+
uniqueItems: boolean;
|
|
41
|
+
items: {
|
|
42
|
+
type: string;
|
|
43
|
+
};
|
|
44
|
+
})[];
|
|
45
|
+
};
|
|
46
|
+
path: {
|
|
47
|
+
type: string;
|
|
48
|
+
};
|
|
49
|
+
package?: undefined;
|
|
50
|
+
};
|
|
51
|
+
required: string[];
|
|
52
|
+
} | {
|
|
53
|
+
type: string;
|
|
54
|
+
additionalProperties: boolean;
|
|
55
|
+
properties: {
|
|
56
|
+
from: {
|
|
57
|
+
type: string;
|
|
58
|
+
const: string;
|
|
59
|
+
};
|
|
60
|
+
name: {
|
|
61
|
+
oneOf: ({
|
|
62
|
+
type: string;
|
|
63
|
+
minItems?: undefined;
|
|
64
|
+
uniqueItems?: undefined;
|
|
65
|
+
items?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
type: string;
|
|
68
|
+
minItems: number;
|
|
69
|
+
uniqueItems: boolean;
|
|
70
|
+
items: {
|
|
71
|
+
type: string;
|
|
72
|
+
};
|
|
73
|
+
})[];
|
|
74
|
+
};
|
|
75
|
+
path?: undefined;
|
|
76
|
+
package?: undefined;
|
|
77
|
+
};
|
|
78
|
+
required: string[];
|
|
79
|
+
} | {
|
|
80
|
+
type: string;
|
|
81
|
+
additionalProperties: boolean;
|
|
82
|
+
properties: {
|
|
83
|
+
from: {
|
|
84
|
+
type: string;
|
|
85
|
+
const: string;
|
|
86
|
+
};
|
|
87
|
+
name: {
|
|
88
|
+
oneOf: ({
|
|
89
|
+
type: string;
|
|
90
|
+
minItems?: undefined;
|
|
91
|
+
uniqueItems?: undefined;
|
|
92
|
+
items?: undefined;
|
|
93
|
+
} | {
|
|
94
|
+
type: string;
|
|
95
|
+
minItems: number;
|
|
96
|
+
uniqueItems: boolean;
|
|
97
|
+
items: {
|
|
98
|
+
type: string;
|
|
99
|
+
};
|
|
100
|
+
})[];
|
|
101
|
+
};
|
|
102
|
+
package: {
|
|
103
|
+
type: string;
|
|
104
|
+
};
|
|
105
|
+
path?: undefined;
|
|
106
|
+
};
|
|
107
|
+
required: string[];
|
|
108
|
+
})[];
|
|
109
|
+
};
|
|
110
|
+
export declare function typeMatchesSpecifier(type: ts.Type, specifier: TypeOrValueSpecifier, program: ts.Program): boolean;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=TypeOrValueSpecifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeOrValueSpecifier.d.ts","sourceRoot":"","sources":["../src/TypeOrValueSpecifier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,oBAAoB,GAC5B,MAAM,GACN,aAAa,GACb,YAAY,GACZ,gBAAgB,CAAC;AAErB,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0FtC,CAAC;AAgCF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,EAAE,CAAC,OAAO,GAClB,OAAO,CA4BT"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.typeMatchesSpecifier = exports.typeOrValueSpecifierSchema = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
exports.typeOrValueSpecifierSchema = {
|
|
9
|
+
oneOf: [
|
|
10
|
+
{
|
|
11
|
+
type: 'string',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
type: 'object',
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
properties: {
|
|
17
|
+
from: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
const: 'file',
|
|
20
|
+
},
|
|
21
|
+
name: {
|
|
22
|
+
oneOf: [
|
|
23
|
+
{
|
|
24
|
+
type: 'string',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: 'array',
|
|
28
|
+
minItems: 1,
|
|
29
|
+
uniqueItems: true,
|
|
30
|
+
items: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
path: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
required: ['from', 'name'],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: 'object',
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
properties: {
|
|
46
|
+
from: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
const: 'lib',
|
|
49
|
+
},
|
|
50
|
+
name: {
|
|
51
|
+
oneOf: [
|
|
52
|
+
{
|
|
53
|
+
type: 'string',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'array',
|
|
57
|
+
minItems: 1,
|
|
58
|
+
uniqueItems: true,
|
|
59
|
+
items: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
required: ['from', 'name'],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'object',
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
properties: {
|
|
72
|
+
from: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
const: 'package',
|
|
75
|
+
},
|
|
76
|
+
name: {
|
|
77
|
+
oneOf: [
|
|
78
|
+
{
|
|
79
|
+
type: 'string',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'array',
|
|
83
|
+
minItems: 1,
|
|
84
|
+
uniqueItems: true,
|
|
85
|
+
items: {
|
|
86
|
+
type: 'string',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
package: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
required: ['from', 'name', 'package'],
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
function specifierNameMatches(type, name) {
|
|
100
|
+
if (typeof name === 'string') {
|
|
101
|
+
name = [name];
|
|
102
|
+
}
|
|
103
|
+
const symbol = type.getSymbol();
|
|
104
|
+
if (symbol === undefined) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return name.some(item => item === symbol.escapedName);
|
|
108
|
+
}
|
|
109
|
+
function typeDeclaredInFile(relativePath, declarationFiles, program) {
|
|
110
|
+
if (relativePath === undefined) {
|
|
111
|
+
const cwd = program.getCurrentDirectory().toLowerCase();
|
|
112
|
+
return declarationFiles.some(declaration => declaration.fileName.toLowerCase().startsWith(cwd));
|
|
113
|
+
}
|
|
114
|
+
const absolutePath = path_1.default
|
|
115
|
+
.join(program.getCurrentDirectory(), relativePath)
|
|
116
|
+
.toLowerCase();
|
|
117
|
+
return declarationFiles.some(declaration => declaration.fileName.toLowerCase() === absolutePath);
|
|
118
|
+
}
|
|
119
|
+
function typeMatchesSpecifier(type, specifier, program) {
|
|
120
|
+
if (typeof specifier === 'string') {
|
|
121
|
+
return specifierNameMatches(type, specifier);
|
|
122
|
+
}
|
|
123
|
+
if (!specifierNameMatches(type, specifier.name)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const declarationFiles = type
|
|
127
|
+
.getSymbol()
|
|
128
|
+
?.getDeclarations()
|
|
129
|
+
?.map(declaration => declaration.getSourceFile()) ?? [];
|
|
130
|
+
switch (specifier.from) {
|
|
131
|
+
case 'file':
|
|
132
|
+
return typeDeclaredInFile(specifier.path, declarationFiles, program);
|
|
133
|
+
case 'lib':
|
|
134
|
+
return declarationFiles.some(declaration => program.isSourceFileDefaultLibrary(declaration));
|
|
135
|
+
case 'package':
|
|
136
|
+
return declarationFiles.some(declaration => declaration.fileName.includes(`node_modules/${specifier.package}/`) ||
|
|
137
|
+
declaration.fileName.includes(`node_modules/@types/${specifier.package}/`));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.typeMatchesSpecifier = typeMatchesSpecifier;
|
|
141
|
+
//# sourceMappingURL=TypeOrValueSpecifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeOrValueSpecifier.js","sourceRoot":"","sources":["../src/TypeOrVal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ACnE,CAAC;AACJ,CAAC;AAED,SAAgB,oBAAoB,CAClC,IAAa,EACb,SAA+B,EAC/B,OAAmB;IAEnB,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,OAAO,oBAAoB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;KAC9C;IACD,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE;QAC/C,OAAO,KAAK,CAAC;KACd;IACD,MAAM,gBAAgB,GACpB,IAAI;SACD,SAAS,EAAE;QACZ,EAAE,eAAe,EAAE;QACnB,EAAE,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,CAAC;IAC5D,QAAQ,SAAS,CAAC,IAAI,EAAE;QACtB,KAAK,MAAM;YACT,OAAO,kBAAkB,CAAC,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QACvE,KAAK,KAAK;YACR,OAAO,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CACzC,OAAO,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAChD,CAAC;QACJ,KAAK,SAAS;YACZ,OAAO,gBAAgB,CAAC,IAAI,CAC1B,WAAW,CAAC,EAAE,CACZ,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,SAAS,CAAC,OAAO,GAAG,CAAC;gBACnE,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAC3B,uBAAuB,SAAS,CAAC,OAAO,GAAG,CAC5C,CACJ,CAAC;KACL;AACH,CAAC;AAhCD,oDAgCC"}
|
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":"AAEA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
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
|
@@ -28,6 +28,7 @@ const utils_1 = require("@typescript-eslint/utils");
|
|
|
28
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,15 +36,21 @@ 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
55
|
const typeArguments =
|
|
49
56
|
// getTypeArguments was only added in TS3.7
|
|
@@ -57,7 +64,7 @@ function isTypeReadonlyArrayOrTuple(checker, type, options, seenTypes) {
|
|
|
57
64
|
return 3 /* Readonlyness.Readonly */;
|
|
58
65
|
}
|
|
59
66
|
// validate the element types are also readonly
|
|
60
|
-
if (typeArguments.some(typeArg => isTypeReadonlyRecurser(
|
|
67
|
+
if (typeArguments.some(typeArg => isTypeReadonlyRecurser(program, typeArg, options, seenTypes) ===
|
|
61
68
|
2 /* Readonlyness.Mutable */)) {
|
|
62
69
|
return 2 /* Readonlyness.Mutable */;
|
|
63
70
|
}
|
|
@@ -79,7 +86,8 @@ function isTypeReadonlyArrayOrTuple(checker, type, options, seenTypes) {
|
|
|
79
86
|
}
|
|
80
87
|
return 1 /* Readonlyness.UnknownType */;
|
|
81
88
|
}
|
|
82
|
-
function isTypeReadonlyObject(
|
|
89
|
+
function isTypeReadonlyObject(program, type, options, seenTypes) {
|
|
90
|
+
const checker = program.getTypeChecker();
|
|
83
91
|
function checkIndexSignature(kind) {
|
|
84
92
|
const indexInfo = checker.getIndexInfoOfType(type, kind);
|
|
85
93
|
if (indexInfo) {
|
|
@@ -89,7 +97,7 @@ function isTypeReadonlyObject(checker, type, options, seenTypes) {
|
|
|
89
97
|
if (indexInfo.type === type || seenTypes.has(indexInfo.type)) {
|
|
90
98
|
return 3 /* Readonlyness.Readonly */;
|
|
91
99
|
}
|
|
92
|
-
return isTypeReadonlyRecurser(
|
|
100
|
+
return isTypeReadonlyRecurser(program, indexInfo.type, options, seenTypes);
|
|
93
101
|
}
|
|
94
102
|
return 1 /* Readonlyness.UnknownType */;
|
|
95
103
|
}
|
|
@@ -134,7 +142,7 @@ function isTypeReadonlyObject(checker, type, options, seenTypes) {
|
|
|
134
142
|
if (seenTypes.has(propertyType)) {
|
|
135
143
|
continue;
|
|
136
144
|
}
|
|
137
|
-
if (isTypeReadonlyRecurser(
|
|
145
|
+
if (isTypeReadonlyRecurser(program, propertyType, options, seenTypes) ===
|
|
138
146
|
2 /* Readonlyness.Mutable */) {
|
|
139
147
|
return 2 /* Readonlyness.Mutable */;
|
|
140
148
|
}
|
|
@@ -151,14 +159,18 @@ function isTypeReadonlyObject(checker, type, options, seenTypes) {
|
|
|
151
159
|
return 3 /* Readonlyness.Readonly */;
|
|
152
160
|
}
|
|
153
161
|
// a helper function to ensure the seenTypes map is always passed down, except by the external caller
|
|
154
|
-
function isTypeReadonlyRecurser(
|
|
162
|
+
function isTypeReadonlyRecurser(program, type, options, seenTypes) {
|
|
163
|
+
const checker = program.getTypeChecker();
|
|
155
164
|
seenTypes.add(type);
|
|
165
|
+
if (options.allow?.some(specifier => (0, TypeOrValueSpecifier_1.typeMatchesSpecifier)(type, specifier, program))) {
|
|
166
|
+
return 3 /* Readonlyness.Readonly */;
|
|
167
|
+
}
|
|
156
168
|
if (tsutils.isUnionType(type)) {
|
|
157
169
|
// all types in the union must be readonly
|
|
158
170
|
const result = tsutils
|
|
159
171
|
.unionTypeParts(type)
|
|
160
172
|
.every(t => seenTypes.has(t) ||
|
|
161
|
-
isTypeReadonlyRecurser(
|
|
173
|
+
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
|
162
174
|
3 /* Readonlyness.Readonly */);
|
|
163
175
|
const readonlyness = result ? 3 /* Readonlyness.Readonly */ : 2 /* Readonlyness.Mutable */;
|
|
164
176
|
return readonlyness;
|
|
@@ -167,12 +179,12 @@ function isTypeReadonlyRecurser(checker, type, options, seenTypes) {
|
|
|
167
179
|
// Special case for handling arrays/tuples (as readonly arrays/tuples always have mutable methods).
|
|
168
180
|
if (type.types.some(t => checker.isArrayType(t) || checker.isTupleType(t))) {
|
|
169
181
|
const allReadonlyParts = type.types.every(t => seenTypes.has(t) ||
|
|
170
|
-
isTypeReadonlyRecurser(
|
|
182
|
+
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
|
171
183
|
3 /* Readonlyness.Readonly */);
|
|
172
184
|
return allReadonlyParts ? 3 /* Readonlyness.Readonly */ : 2 /* Readonlyness.Mutable */;
|
|
173
185
|
}
|
|
174
186
|
// Normal case.
|
|
175
|
-
const isReadonlyObject = isTypeReadonlyObject(
|
|
187
|
+
const isReadonlyObject = isTypeReadonlyObject(program, type, options, seenTypes);
|
|
176
188
|
if (isReadonlyObject !== 1 /* Readonlyness.UnknownType */) {
|
|
177
189
|
return isReadonlyObject;
|
|
178
190
|
}
|
|
@@ -181,7 +193,7 @@ function isTypeReadonlyRecurser(checker, type, options, seenTypes) {
|
|
|
181
193
|
const result = [type.root.node.trueType, type.root.node.falseType]
|
|
182
194
|
.map(checker.getTypeFromTypeNode)
|
|
183
195
|
.every(t => seenTypes.has(t) ||
|
|
184
|
-
isTypeReadonlyRecurser(
|
|
196
|
+
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
|
185
197
|
3 /* Readonlyness.Readonly */);
|
|
186
198
|
const readonlyness = result ? 3 /* Readonlyness.Readonly */ : 2 /* Readonlyness.Mutable */;
|
|
187
199
|
return readonlyness;
|
|
@@ -196,11 +208,11 @@ function isTypeReadonlyRecurser(checker, type, options, seenTypes) {
|
|
|
196
208
|
type.getProperties().length === 0) {
|
|
197
209
|
return 3 /* Readonlyness.Readonly */;
|
|
198
210
|
}
|
|
199
|
-
const isReadonlyArray = isTypeReadonlyArrayOrTuple(
|
|
211
|
+
const isReadonlyArray = isTypeReadonlyArrayOrTuple(program, type, options, seenTypes);
|
|
200
212
|
if (isReadonlyArray !== 1 /* Readonlyness.UnknownType */) {
|
|
201
213
|
return isReadonlyArray;
|
|
202
214
|
}
|
|
203
|
-
const isReadonlyObject = isTypeReadonlyObject(
|
|
215
|
+
const isReadonlyObject = isTypeReadonlyObject(program, type, options, seenTypes);
|
|
204
216
|
/* istanbul ignore else */ if (isReadonlyObject !== 1 /* Readonlyness.UnknownType */) {
|
|
205
217
|
return isReadonlyObject;
|
|
206
218
|
}
|
|
@@ -209,8 +221,8 @@ function isTypeReadonlyRecurser(checker, type, options, seenTypes) {
|
|
|
209
221
|
/**
|
|
210
222
|
* Checks if the given type is readonly
|
|
211
223
|
*/
|
|
212
|
-
function isTypeReadonly(
|
|
213
|
-
return (isTypeReadonlyRecurser(
|
|
224
|
+
function isTypeReadonly(program, type, options = exports.readonlynessOptionsDefaults) {
|
|
225
|
+
return (isTypeReadonlyRecurser(program, type, options, new Set()) ===
|
|
214
226
|
3 /* Readonlyness.Readonly */);
|
|
215
227
|
}
|
|
216
228
|
exports.isTypeReadonly = isTypeReadonly;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTypeReadonly.js","sourceRoot":"","sources":["../src/isTypeReadonly.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuD;AACvD,sDAAwC;AACxC,+CAAiC;AAEjC,mDAA0D;
|
|
1
|
+
{"version":3,"file":"isTypeReadonly.js","sourceRoot":"","sources":["../src/isTypeReadonly.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;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AAE,SAAS,CAAC;6CAC/B,CAC1B,CAAC;QAEJ,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,+BAAuB,CAAC,6BAAqB,CAAC;QAC3E,OAAO,YAAY,CAAC;KACrB;IAED,uDAAuD;IACvD,sCAAsC;IACtC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;QAC/B,qCAA6B;KAC9B;IAED,mCAAmC;IACnC,IACE,IAAI,CAAC,iBAAiB,EAAE,CAAC,MAAM,GAAG,CAAC;QACnC,IAAI,CAAC,aAAa,EAAE,CAAC,MAAM,KAAK,CAAC,EACjC;QACA,qCAA6B;KAC9B;IAED,MAAM,eAAe,GAAG,0BAA0B,CAChD,OAAO,EACP,IAAI,EACJ,OAAO,EACP,SAAS,CACV,CAAC;IACF,IAAI,eAAe,qCAA6B,EAAE;QAChD,OAAO,eAAe,CAAC;KACxB;IAED,MAAM,gBAAgB,GAAG,oBAAoB,CAC3C,OAAO,EACP,IAAI,EACJ,OAAO,EACP,SAAS,CACV,CAAC;IACF,0BAA0B,CAAC,IACzB,gBAAgB,qCAA6B,EAC7C;QACA,OAAO,gBAAgB,CAAC;KACzB;IAED,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CACrB,OAAmB,EACnB,IAAa,EACb,UAA+B,mCAA2B;IAE1D,OAAO,CACL,sBAAsB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC;qCACpC,CACtB,CAAC;AACJ,CAAC;AAEQ,wCAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/type-utils",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.95+c9427b78b",
|
|
4
4
|
"description": "Type utilities for working with TypeScript + ESLint together",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -45,13 +45,14 @@
|
|
|
45
45
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@typescript-eslint/typescript-estree": "6.0.0-alpha.
|
|
49
|
-
"@typescript-eslint/utils": "6.0.0-alpha.
|
|
48
|
+
"@typescript-eslint/typescript-estree": "6.0.0-alpha.95+c9427b78b",
|
|
49
|
+
"@typescript-eslint/utils": "6.0.0-alpha.95+c9427b78b",
|
|
50
50
|
"debug": "^4.3.4",
|
|
51
51
|
"ts-api-utils": "^0.0.44"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@typescript-eslint/parser": "6.0.0-alpha.
|
|
54
|
+
"@typescript-eslint/parser": "6.0.0-alpha.95+c9427b78b",
|
|
55
|
+
"ajv": "^8.12.0",
|
|
55
56
|
"typescript": "*"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
@@ -73,5 +74,5 @@
|
|
|
73
74
|
]
|
|
74
75
|
}
|
|
75
76
|
},
|
|
76
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "c9427b78b69f1a6a2453ef2df2be5bf96b7b00bc"
|
|
77
78
|
}
|