@oxlint/plugins 1.50.0 → 1.52.0
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/index.cjs +50 -2
- package/index.d.ts +270 -249
- package/index.js +51 -2
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src-js/package/define.ts
|
|
3
|
+
/**
|
|
4
|
+
* Define a plugin.
|
|
5
|
+
*
|
|
6
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
7
|
+
*
|
|
8
|
+
* @param plugin - Plugin to define
|
|
9
|
+
* @returns Same plugin as passed in
|
|
10
|
+
*/
|
|
2
11
|
function definePlugin(plugin) {
|
|
3
12
|
return plugin;
|
|
4
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Define a rule.
|
|
16
|
+
*
|
|
17
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
18
|
+
*
|
|
19
|
+
* @param rule - Rule to define
|
|
20
|
+
* @returns Same rule as passed in
|
|
21
|
+
*/
|
|
5
22
|
function defineRule(rule) {
|
|
6
23
|
return rule;
|
|
7
24
|
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src-js/package/compat.ts
|
|
8
27
|
const EMPTY_VISITOR = {};
|
|
28
|
+
/**
|
|
29
|
+
* Convert a plugin which used Oxlint's `createOnce` API to also work with ESLint.
|
|
30
|
+
*
|
|
31
|
+
* If any of the plugin's rules use the Oxlint alternative `createOnce` API,
|
|
32
|
+
* add ESLint-compatible `create` methods to those rules, which delegate to `createOnce`.
|
|
33
|
+
* This makes the plugin compatible with ESLint.
|
|
34
|
+
*
|
|
35
|
+
* The `plugin` object passed in is mutated in-place.
|
|
36
|
+
*
|
|
37
|
+
* @param plugin - Plugin to convert
|
|
38
|
+
* @returns Plugin with all rules having `create` method
|
|
39
|
+
* @throws {Error} If `plugin` is not an object, or `plugin.rules` is not an object
|
|
40
|
+
*/
|
|
9
41
|
function eslintCompatPlugin(plugin) {
|
|
10
42
|
if (typeof plugin != "object" || !plugin) throw Error("Plugin must be an object");
|
|
11
43
|
let { rules } = plugin;
|
|
@@ -13,6 +45,14 @@ function eslintCompatPlugin(plugin) {
|
|
|
13
45
|
for (let ruleName in rules) Object.hasOwn(rules, ruleName) && convertRule(rules[ruleName]);
|
|
14
46
|
return plugin;
|
|
15
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Convert a rule.
|
|
50
|
+
*
|
|
51
|
+
* The `rule` object passed in is mutated in-place.
|
|
52
|
+
*
|
|
53
|
+
* @param rule - Rule to convert
|
|
54
|
+
* @throws {Error} If `rule` is not an object
|
|
55
|
+
*/
|
|
16
56
|
function convertRule(rule) {
|
|
17
57
|
if (typeof rule != "object" || !rule) throw Error("Rule must be an object");
|
|
18
58
|
if ("create" in rule) return;
|
|
@@ -64,13 +104,19 @@ const FILE_CONTEXT = Object.freeze({
|
|
|
64
104
|
throw Error("Cannot access `context.parserPath` in `createOnce`");
|
|
65
105
|
}
|
|
66
106
|
});
|
|
107
|
+
/**
|
|
108
|
+
* Call `createOnce` method of rule, and return `Context`, `Visitor`, and `beforeHook` (if any).
|
|
109
|
+
*
|
|
110
|
+
* @param rule - Rule with `createOnce` method
|
|
111
|
+
* @returns Object with `context`, `visitor`, and `beforeHook` properties
|
|
112
|
+
*/
|
|
67
113
|
function createContextAndVisitor(rule) {
|
|
68
114
|
let { createOnce } = rule;
|
|
69
115
|
if (createOnce == null) throw Error("Rules must define either a `create` or `createOnce` method");
|
|
70
116
|
if (typeof createOnce != "function") throw Error("Rule `createOnce` property must be a function");
|
|
71
117
|
let context = Object.create(FILE_CONTEXT, {
|
|
72
118
|
id: {
|
|
73
|
-
value:
|
|
119
|
+
value: null,
|
|
74
120
|
enumerable: !0,
|
|
75
121
|
configurable: !0
|
|
76
122
|
},
|
|
@@ -80,7 +126,9 @@ function createContextAndVisitor(rule) {
|
|
|
80
126
|
configurable: !0
|
|
81
127
|
},
|
|
82
128
|
report: {
|
|
83
|
-
value
|
|
129
|
+
value() {
|
|
130
|
+
throw Error("Cannot report errors in `createOnce`");
|
|
131
|
+
},
|
|
84
132
|
enumerable: !0,
|
|
85
133
|
configurable: !0
|
|
86
134
|
}
|
package/index.d.ts
CHANGED
|
@@ -1049,45 +1049,13 @@ Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] & // 3. Add the re
|
|
|
1049
1049
|
Except<ObjectType, KeysType>;
|
|
1050
1050
|
//#endregion
|
|
1051
1051
|
//#region src-js/plugins/tokens.d.ts
|
|
1052
|
-
/**
|
|
1053
|
-
* Options for various `SourceCode` methods e.g. `getFirstToken`.
|
|
1054
|
-
*/
|
|
1055
|
-
interface SkipOptions {
|
|
1056
|
-
/** Number of skipping tokens */
|
|
1057
|
-
skip?: number;
|
|
1058
|
-
/** `true` to include comment tokens in the result */
|
|
1059
|
-
includeComments?: boolean;
|
|
1060
|
-
/** Function to filter tokens */
|
|
1061
|
-
filter?: FilterFn | null;
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* Options for various `SourceCode` methods e.g. `getFirstTokens`.
|
|
1065
|
-
*/
|
|
1066
|
-
interface CountOptions {
|
|
1067
|
-
/** Maximum number of tokens to return */
|
|
1068
|
-
count?: number;
|
|
1069
|
-
/** `true` to include comment tokens in the result */
|
|
1070
|
-
includeComments?: boolean;
|
|
1071
|
-
/** Function to filter tokens */
|
|
1072
|
-
filter?: FilterFn | null;
|
|
1073
|
-
}
|
|
1074
|
-
/**
|
|
1075
|
-
* Options for `getTokenByRangeStart`.
|
|
1076
|
-
*/
|
|
1077
|
-
interface RangeOptions {
|
|
1078
|
-
/** `true` to include comment tokens in the result */
|
|
1079
|
-
includeComments?: boolean;
|
|
1080
|
-
}
|
|
1081
|
-
/**
|
|
1082
|
-
* Filter function, passed as `filter` property of `SkipOptions` and `CountOptions`.
|
|
1083
|
-
*/
|
|
1084
|
-
type FilterFn = (token: TokenOrComment) => boolean;
|
|
1085
1052
|
/**
|
|
1086
1053
|
* AST token type.
|
|
1087
1054
|
*/
|
|
1088
|
-
type
|
|
1055
|
+
type TokenType = BooleanToken | IdentifierToken | JSXIdentifierToken | JSXTextToken | KeywordToken | NullToken | NumericToken | PrivateIdentifierToken | PunctuatorToken | RegularExpressionToken | StringToken | TemplateToken;
|
|
1089
1056
|
interface BaseToken extends Span {
|
|
1090
1057
|
value: string;
|
|
1058
|
+
regex: undefined;
|
|
1091
1059
|
}
|
|
1092
1060
|
interface BooleanToken extends BaseToken {
|
|
1093
1061
|
type: "Boolean";
|
|
@@ -1116,11 +1084,12 @@ interface PrivateIdentifierToken extends BaseToken {
|
|
|
1116
1084
|
interface PunctuatorToken extends BaseToken {
|
|
1117
1085
|
type: "Punctuator";
|
|
1118
1086
|
}
|
|
1119
|
-
interface RegularExpressionToken extends
|
|
1087
|
+
interface RegularExpressionToken extends Span {
|
|
1120
1088
|
type: "RegularExpression";
|
|
1089
|
+
value: string;
|
|
1121
1090
|
regex: {
|
|
1122
|
-
flags: string;
|
|
1123
1091
|
pattern: string;
|
|
1092
|
+
flags: string;
|
|
1124
1093
|
};
|
|
1125
1094
|
}
|
|
1126
1095
|
interface StringToken extends BaseToken {
|
|
@@ -1129,213 +1098,9 @@ interface StringToken extends BaseToken {
|
|
|
1129
1098
|
interface TemplateToken extends BaseToken {
|
|
1130
1099
|
type: "Template";
|
|
1131
1100
|
}
|
|
1132
|
-
type TokenOrComment =
|
|
1133
|
-
/**
|
|
1134
|
-
* Get all tokens that are related to the given node.
|
|
1135
|
-
* @param node - The AST node.
|
|
1136
|
-
* @param countOptions? - Options object. If is a function, equivalent to `{ filter: fn }`.
|
|
1137
|
-
* @returns Array of `Token`s.
|
|
1138
|
-
*/
|
|
1139
|
-
/**
|
|
1140
|
-
* Get all tokens that are related to the given node.
|
|
1141
|
-
* @param node - The AST node.
|
|
1142
|
-
* @param beforeCount? - The number of tokens before the node to retrieve.
|
|
1143
|
-
* @param afterCount? - The number of tokens after the node to retrieve.
|
|
1144
|
-
* @returns Array of `Token`s.
|
|
1145
|
-
*/
|
|
1146
|
-
declare function getTokens(node: Node, countOptions?: CountOptions | number | FilterFn | null, afterCount?: number | null): TokenOrComment[];
|
|
1147
|
-
/**
|
|
1148
|
-
* Get the first token of the given node.
|
|
1149
|
-
* @param node - The AST node.
|
|
1150
|
-
* @param skipOptions? - Options object.
|
|
1151
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1152
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1153
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1154
|
-
*/
|
|
1155
|
-
declare function getFirstToken(node: Node, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1156
|
-
/**
|
|
1157
|
-
* Get the first tokens of the given node.
|
|
1158
|
-
* @param node - The AST node.
|
|
1159
|
-
* @param countOptions? - Options object.
|
|
1160
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1161
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1162
|
-
* @returns Array of `Token`s.
|
|
1163
|
-
*/
|
|
1164
|
-
declare function getFirstTokens(node: Node, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1165
|
-
/**
|
|
1166
|
-
* Get the last token of the given node.
|
|
1167
|
-
* @param node - The AST node.
|
|
1168
|
-
* @param skipOptions? - Options object.
|
|
1169
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1170
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1171
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1172
|
-
*/
|
|
1173
|
-
declare function getLastToken(node: Node, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1174
|
-
/**
|
|
1175
|
-
* Get the last tokens of the given node.
|
|
1176
|
-
* @param node - The AST node.
|
|
1177
|
-
* @param countOptions? - Options object.
|
|
1178
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1179
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1180
|
-
* @returns Array of `Token`s.
|
|
1181
|
-
*/
|
|
1182
|
-
declare function getLastTokens(node: Node, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1183
|
-
/**
|
|
1184
|
-
* Get the token that precedes a given node or token.
|
|
1185
|
-
* @param nodeOrToken - The AST node or token.
|
|
1186
|
-
* @param skipOptions? - Options object.
|
|
1187
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1188
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1189
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1190
|
-
*/
|
|
1191
|
-
declare function getTokenBefore(nodeOrToken: NodeOrToken, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1192
|
-
/**
|
|
1193
|
-
* Get the token that precedes a given node or token.
|
|
1194
|
-
*
|
|
1195
|
-
* @deprecated Use `sourceCode.getTokenBefore` with `includeComments: true` instead.
|
|
1196
|
-
*
|
|
1197
|
-
* @param nodeOrToken The AST node or token.
|
|
1198
|
-
* @param skip - Number of tokens to skip.
|
|
1199
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1200
|
-
*/
|
|
1201
|
-
declare function getTokenOrCommentBefore(nodeOrToken: NodeOrToken, skip?: number): TokenOrComment | null;
|
|
1202
|
-
/**
|
|
1203
|
-
* Get the tokens that precede a given node or token.
|
|
1204
|
-
* @param nodeOrToken - The AST node or token.
|
|
1205
|
-
* @param countOptions? - Options object.
|
|
1206
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1207
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1208
|
-
* @returns Array of `Token`s.
|
|
1209
|
-
*/
|
|
1210
|
-
declare function getTokensBefore(nodeOrToken: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1211
|
-
/**
|
|
1212
|
-
* Get the token that follows a given node or token.
|
|
1213
|
-
* @param nodeOrToken - The AST node or token.
|
|
1214
|
-
* @param skipOptions? - Options object.
|
|
1215
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1216
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1217
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1218
|
-
*/
|
|
1219
|
-
declare function getTokenAfter(nodeOrToken: NodeOrToken, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1220
|
-
/**
|
|
1221
|
-
* Get the token that follows a given node or token.
|
|
1222
|
-
*
|
|
1223
|
-
* @deprecated Use `sourceCode.getTokenAfter` with `includeComments: true` instead.
|
|
1224
|
-
*
|
|
1225
|
-
* @param nodeOrToken The AST node or token.
|
|
1226
|
-
* @param skip - Number of tokens to skip.
|
|
1227
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1228
|
-
*/
|
|
1229
|
-
declare function getTokenOrCommentAfter(nodeOrToken: NodeOrToken, skip?: number): TokenOrComment | null;
|
|
1230
|
-
/**
|
|
1231
|
-
* Get the tokens that follow a given node or token.
|
|
1232
|
-
* @param nodeOrToken - The AST node or token.
|
|
1233
|
-
* @param countOptions? - Options object.
|
|
1234
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1235
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1236
|
-
* @returns Array of `Token`s.
|
|
1237
|
-
*/
|
|
1238
|
-
declare function getTokensAfter(nodeOrToken: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1239
|
-
/**
|
|
1240
|
-
* Get all of the tokens between two non-overlapping nodes.
|
|
1241
|
-
* @param left - Node or token before the desired token range.
|
|
1242
|
-
* @param right - Node or token after the desired token range.
|
|
1243
|
-
* @param countOptions? - Options object. If is a function, equivalent to `{ filter: fn }`.
|
|
1244
|
-
* @returns Array of `Token`s between `left` and `right`.
|
|
1245
|
-
*/
|
|
1246
|
-
/**
|
|
1247
|
-
* Get all of the tokens between two non-overlapping nodes.
|
|
1248
|
-
* @param left - Node or token before the desired token range.
|
|
1249
|
-
* @param right - Node or token after the desired token range.
|
|
1250
|
-
* @param padding - Number of extra tokens on either side of center.
|
|
1251
|
-
* @returns Array of `Token`s between `left` and `right`.
|
|
1252
|
-
*/
|
|
1253
|
-
declare function getTokensBetween(left: NodeOrToken, right: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1254
|
-
/**
|
|
1255
|
-
* Get the first token between two non-overlapping nodes.
|
|
1256
|
-
* @param left - Node or token before the desired token range.
|
|
1257
|
-
* @param right - Node or token after the desired token range.
|
|
1258
|
-
* @param skipOptions? - Options object.
|
|
1259
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1260
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1261
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1262
|
-
*/
|
|
1263
|
-
declare function getFirstTokenBetween(left: NodeOrToken, right: NodeOrToken, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1264
|
-
/**
|
|
1265
|
-
* Get the first tokens between two non-overlapping nodes.
|
|
1266
|
-
* @param left - Node or token before the desired token range.
|
|
1267
|
-
* @param right - Node or token after the desired token range.
|
|
1268
|
-
* @param countOptions? - Options object.
|
|
1269
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1270
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1271
|
-
* @returns Array of `Token`s between `left` and `right`.
|
|
1272
|
-
*/
|
|
1273
|
-
declare function getFirstTokensBetween(left: NodeOrToken, right: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1274
|
-
/**
|
|
1275
|
-
* Get the last token between two non-overlapping nodes.
|
|
1276
|
-
* @param left - Node or token before the desired token range.
|
|
1277
|
-
* @param right - Node or token after the desired token range.
|
|
1278
|
-
* @param skipOptions? - Options object.
|
|
1279
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1280
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1281
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1282
|
-
*/
|
|
1283
|
-
declare function getLastTokenBetween(left: NodeOrToken, right: NodeOrToken, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1284
|
-
/**
|
|
1285
|
-
* Get the last tokens between two non-overlapping nodes.
|
|
1286
|
-
* @param left - Node or token before the desired token range.
|
|
1287
|
-
* @param right - Node or token after the desired token range.
|
|
1288
|
-
* @param countOptions? - Options object.
|
|
1289
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1290
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1291
|
-
* @returns Array of `Token`s between `left` and `right`.
|
|
1292
|
-
*/
|
|
1293
|
-
declare function getLastTokensBetween(left: NodeOrToken, right: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1294
|
-
/**
|
|
1295
|
-
* Get the token starting at the specified index.
|
|
1296
|
-
* @param index - Index of the start of the token's range.
|
|
1297
|
-
* @param rangeOptions - Options object.
|
|
1298
|
-
* @returns The token starting at index, or `null` if no such token.
|
|
1299
|
-
*/
|
|
1300
|
-
declare function getTokenByRangeStart(index: number, rangeOptions?: RangeOptions | null): TokenOrComment | null;
|
|
1301
|
-
/**
|
|
1302
|
-
* Determine if two nodes or tokens have at least one whitespace character between them.
|
|
1303
|
-
* Order does not matter.
|
|
1304
|
-
*
|
|
1305
|
-
* Returns `false` if the given nodes or tokens overlap.
|
|
1306
|
-
*
|
|
1307
|
-
* Checks for whitespace *between tokens*, not including whitespace *inside tokens*.
|
|
1308
|
-
* e.g. Returns `false` for `isSpaceBetween(x, y)` in `x+" "+y`.
|
|
1309
|
-
*
|
|
1310
|
-
* @param first - The first node or token to check between.
|
|
1311
|
-
* @param second - The second node or token to check between.
|
|
1312
|
-
* @returns `true` if there is a whitespace character between
|
|
1313
|
-
* any of the tokens found between the two given nodes or tokens.
|
|
1314
|
-
*/
|
|
1315
|
-
declare function isSpaceBetween(first: NodeOrToken, second: NodeOrToken): boolean;
|
|
1316
|
-
/**
|
|
1317
|
-
* Determine if two nodes or tokens have at least one whitespace character between them.
|
|
1318
|
-
* Order does not matter.
|
|
1319
|
-
*
|
|
1320
|
-
* Returns `false` if the given nodes or tokens overlap.
|
|
1321
|
-
*
|
|
1322
|
-
* Checks for whitespace *between tokens*, not including whitespace *inside tokens*.
|
|
1323
|
-
* e.g. Returns `false` for `isSpaceBetween(x, y)` in `x+" "+y`.
|
|
1324
|
-
*
|
|
1325
|
-
* Unlike `SourceCode#isSpaceBetween`, this function does return `true` if there is a `JSText` token between the two
|
|
1326
|
-
* input tokens, and it contains whitespace.
|
|
1327
|
-
* e.g. Returns `true` for `isSpaceBetweenTokens(x, slash)` in `<X>a b</X>`.
|
|
1328
|
-
*
|
|
1329
|
-
* @deprecated Use `sourceCode.isSpaceBetween` instead.
|
|
1330
|
-
*
|
|
1331
|
-
* @param first - The first node or token to check between.
|
|
1332
|
-
* @param second - The second node or token to check between.
|
|
1333
|
-
* @returns `true` if there is a whitespace character between
|
|
1334
|
-
* any of the tokens found between the two given nodes or tokens.
|
|
1335
|
-
*/
|
|
1336
|
-
declare function isSpaceBetweenTokens(first: NodeOrToken, second: NodeOrToken): boolean;
|
|
1101
|
+
type TokenOrComment = TokenType | Comment;
|
|
1337
1102
|
declare namespace types_d_exports {
|
|
1338
|
-
export { AccessorProperty, AccessorPropertyType, Argument, ArrayAssignmentTarget, ArrayExpression, ArrayExpressionElement, ArrayPattern, ArrowFunctionExpression, AssignmentExpression, AssignmentOperator, AssignmentPattern, AssignmentTarget, AssignmentTargetMaybeDefault, AssignmentTargetPattern, AssignmentTargetProperty, AssignmentTargetPropertyIdentifier, AssignmentTargetPropertyProperty, AssignmentTargetRest, AssignmentTargetWithDefault, AwaitExpression, BigIntLiteral, BinaryExpression, BinaryOperator, BindingIdentifier, BindingPattern, BindingProperty, BindingRestElement, BlockStatement, BooleanLiteral, BreakStatement, CallExpression, CatchClause, ChainElement, ChainExpression, Class, ClassBody, ClassElement, ClassType, Comment, ComputedMemberExpression, ConditionalExpression, ContinueStatement, DebuggerStatement, Declaration, Decorator, Directive, DoWhileStatement, EmptyStatement, ExportAllDeclaration, ExportDefaultDeclaration, ExportDefaultDeclarationKind, ExportNamedDeclaration, ExportSpecifier, Expression, ExpressionStatement, ForInStatement, ForOfStatement, ForStatement, ForStatementInit, ForStatementLeft, FormalParameter, FormalParameterRest, Function$1 as Function, FunctionBody, FunctionType, Hashbang, IdentifierName, IdentifierReference, IfStatement, ImportAttribute, ImportAttributeKey, ImportDeclaration, ImportDeclarationSpecifier, ImportDefaultSpecifier, ImportExpression, ImportNamespaceSpecifier, ImportOrExportKind, ImportPhase, ImportSpecifier, JSDocNonNullableType, JSDocNullableType, JSDocUnknownType, JSXAttribute, JSXAttributeItem, JSXAttributeName, JSXAttributeValue, JSXChild, JSXClosingElement, JSXClosingFragment, JSXElement, JSXElementName, JSXEmptyExpression, JSXExpression, JSXExpressionContainer, JSXFragment, JSXIdentifier, JSXMemberExpression, JSXMemberExpressionObject, JSXNamespacedName, JSXOpeningElement, JSXOpeningFragment, JSXSpreadAttribute, JSXSpreadChild, JSXText, LabelIdentifier, LabeledStatement, LogicalExpression, LogicalOperator, MemberExpression, MetaProperty, MethodDefinition, MethodDefinitionKind, MethodDefinitionType, ModuleDeclaration, ModuleExportName, ModuleKind, NewExpression, Node$1 as Node, NullLiteral, NumericLiteral, ObjectAssignmentTarget, ObjectExpression, ObjectPattern, ObjectProperty, ObjectPropertyKind, ParamPattern, ParenthesizedExpression, PrivateFieldExpression, PrivateIdentifier, PrivateInExpression, Program, PropertyDefinition, PropertyDefinitionType, PropertyKey$1 as PropertyKey, PropertyKind, RegExpLiteral, ReturnStatement, SequenceExpression, SimpleAssignmentTarget, Span, SpreadElement, Statement, StaticBlock, StaticMemberExpression, StringLiteral, Super, SwitchCase, SwitchStatement, TSAccessibility, TSAnyKeyword, TSArrayType, TSAsExpression, TSBigIntKeyword, TSBooleanKeyword, TSCallSignatureDeclaration, TSClassImplements, TSConditionalType, TSConstructSignatureDeclaration, TSConstructorType, TSEnumBody, TSEnumDeclaration, TSEnumMember, TSEnumMemberName, TSExportAssignment, TSExternalModuleReference, TSFunctionType, TSGlobalDeclaration, TSImportEqualsDeclaration, TSImportType, TSImportTypeQualifiedName, TSImportTypeQualifier, TSIndexSignature, TSIndexSignatureName, TSIndexedAccessType, TSInferType, TSInstantiationExpression, TSInterfaceBody, TSInterfaceDeclaration, TSInterfaceHeritage, TSIntersectionType, TSIntrinsicKeyword, TSLiteral, TSLiteralType, TSMappedType, TSMappedTypeModifierOperator, TSMethodSignature, TSMethodSignatureKind, TSModuleBlock, TSModuleDeclaration, TSModuleDeclarationKind, TSModuleReference, TSNamedTupleMember, TSNamespaceExportDeclaration, TSNeverKeyword, TSNonNullExpression, TSNullKeyword, TSNumberKeyword, TSObjectKeyword, TSOptionalType, TSParameterProperty, TSParenthesizedType, TSPropertySignature, TSQualifiedName, TSRestType, TSSatisfiesExpression, TSSignature, TSStringKeyword, TSSymbolKeyword, TSTemplateLiteralType, TSThisParameter, TSThisType, TSTupleElement, TSTupleType, TSType, TSTypeAliasDeclaration, TSTypeAnnotation, TSTypeAssertion, TSTypeLiteral, TSTypeName, TSTypeOperator, TSTypeOperatorOperator, TSTypeParameter, TSTypeParameterDeclaration, TSTypeParameterInstantiation, TSTypePredicate, TSTypePredicateName, TSTypeQuery, TSTypeQueryExprName, TSTypeReference, TSUndefinedKeyword, TSUnionType, TSUnknownKeyword, TSVoidKeyword, TaggedTemplateExpression, TemplateElement, TemplateElementValue, TemplateLiteral, ThisExpression, ThrowStatement, Token, TryStatement, UnaryExpression, UnaryOperator, UpdateExpression, UpdateOperator, V8IntrinsicExpression, VariableDeclaration, VariableDeclarationKind, VariableDeclarator, WhileStatement, WithStatement, YieldExpression };
|
|
1103
|
+
export { AccessorProperty, AccessorPropertyType, Argument, ArrayAssignmentTarget, ArrayExpression, ArrayExpressionElement, ArrayPattern, ArrowFunctionExpression, AssignmentExpression, AssignmentOperator, AssignmentPattern, AssignmentTarget, AssignmentTargetMaybeDefault, AssignmentTargetPattern, AssignmentTargetProperty, AssignmentTargetPropertyIdentifier, AssignmentTargetPropertyProperty, AssignmentTargetRest, AssignmentTargetWithDefault, AwaitExpression, BigIntLiteral, BinaryExpression, BinaryOperator, BindingIdentifier, BindingPattern, BindingProperty, BindingRestElement, BlockStatement, BooleanLiteral, BreakStatement, CallExpression, CatchClause, ChainElement, ChainExpression, Class, ClassBody, ClassElement, ClassType, Comment, ComputedMemberExpression, ConditionalExpression, ContinueStatement, DebuggerStatement, Declaration, Decorator, Directive, DoWhileStatement, EmptyStatement, ExportAllDeclaration, ExportDefaultDeclaration, ExportDefaultDeclarationKind, ExportNamedDeclaration, ExportSpecifier, Expression, ExpressionStatement, ForInStatement, ForOfStatement, ForStatement, ForStatementInit, ForStatementLeft, FormalParameter, FormalParameterRest, Function$1 as Function, FunctionBody, FunctionType, Hashbang, IdentifierName, IdentifierReference, IfStatement, ImportAttribute, ImportAttributeKey, ImportDeclaration, ImportDeclarationSpecifier, ImportDefaultSpecifier, ImportExpression, ImportNamespaceSpecifier, ImportOrExportKind, ImportPhase, ImportSpecifier, JSDocNonNullableType, JSDocNullableType, JSDocUnknownType, JSXAttribute, JSXAttributeItem, JSXAttributeName, JSXAttributeValue, JSXChild, JSXClosingElement, JSXClosingFragment, JSXElement, JSXElementName, JSXEmptyExpression, JSXExpression, JSXExpressionContainer, JSXFragment, JSXIdentifier, JSXMemberExpression, JSXMemberExpressionObject, JSXNamespacedName, JSXOpeningElement, JSXOpeningFragment, JSXSpreadAttribute, JSXSpreadChild, JSXText, LabelIdentifier, LabeledStatement, LogicalExpression, LogicalOperator, MemberExpression, MetaProperty, MethodDefinition, MethodDefinitionKind, MethodDefinitionType, ModuleDeclaration, ModuleExportName, ModuleKind, NewExpression, Node$1 as Node, NullLiteral, NumericLiteral, ObjectAssignmentTarget, ObjectExpression, ObjectPattern, ObjectProperty, ObjectPropertyKind, ParamPattern, ParenthesizedExpression, PrivateFieldExpression, PrivateIdentifier, PrivateInExpression, Program, PropertyDefinition, PropertyDefinitionType, PropertyKey$1 as PropertyKey, PropertyKind, RegExpLiteral, ReturnStatement, SequenceExpression, SimpleAssignmentTarget, Span, SpreadElement, Statement, StaticBlock, StaticMemberExpression, StringLiteral, Super, SwitchCase, SwitchStatement, TSAccessibility, TSAnyKeyword, TSArrayType, TSAsExpression, TSBigIntKeyword, TSBooleanKeyword, TSCallSignatureDeclaration, TSClassImplements, TSConditionalType, TSConstructSignatureDeclaration, TSConstructorType, TSEnumBody, TSEnumDeclaration, TSEnumMember, TSEnumMemberName, TSExportAssignment, TSExternalModuleReference, TSFunctionType, TSGlobalDeclaration, TSImportEqualsDeclaration, TSImportType, TSImportTypeQualifiedName, TSImportTypeQualifier, TSIndexSignature, TSIndexSignatureName, TSIndexedAccessType, TSInferType, TSInstantiationExpression, TSInterfaceBody, TSInterfaceDeclaration, TSInterfaceHeritage, TSIntersectionType, TSIntrinsicKeyword, TSLiteral, TSLiteralType, TSMappedType, TSMappedTypeModifierOperator, TSMethodSignature, TSMethodSignatureKind, TSModuleBlock, TSModuleDeclaration, TSModuleDeclarationKind, TSModuleReference, TSNamedTupleMember, TSNamespaceExportDeclaration, TSNeverKeyword, TSNonNullExpression, TSNullKeyword, TSNumberKeyword, TSObjectKeyword, TSOptionalType, TSParameterProperty, TSParenthesizedType, TSPropertySignature, TSQualifiedName, TSRestType, TSSatisfiesExpression, TSSignature, TSStringKeyword, TSSymbolKeyword, TSTemplateLiteralType, TSThisParameter, TSThisType, TSTupleElement, TSTupleType, TSType, TSTypeAliasDeclaration, TSTypeAnnotation, TSTypeAssertion, TSTypeLiteral, TSTypeName, TSTypeOperator, TSTypeOperatorOperator, TSTypeParameter, TSTypeParameterDeclaration, TSTypeParameterInstantiation, TSTypePredicate, TSTypePredicateName, TSTypeQuery, TSTypeQueryExprName, TSTypeReference, TSUndefinedKeyword, TSUnionType, TSUnknownKeyword, TSVoidKeyword, TaggedTemplateExpression, TemplateElement, TemplateElementValue, TemplateLiteral, ThisExpression, ThrowStatement, TokenType as Token, TryStatement, UnaryExpression, UnaryOperator, UpdateExpression, UpdateOperator, V8IntrinsicExpression, VariableDeclaration, VariableDeclarationKind, VariableDeclarator, WhileStatement, WithStatement, YieldExpression };
|
|
1339
1104
|
}
|
|
1340
1105
|
interface Program extends Span {
|
|
1341
1106
|
type: "Program";
|
|
@@ -1343,7 +1108,7 @@ interface Program extends Span {
|
|
|
1343
1108
|
sourceType: ModuleKind;
|
|
1344
1109
|
hashbang: Hashbang | null;
|
|
1345
1110
|
comments: Comment[];
|
|
1346
|
-
tokens:
|
|
1111
|
+
tokens: TokenType[];
|
|
1347
1112
|
parent: null;
|
|
1348
1113
|
}
|
|
1349
1114
|
type Expression = BooleanLiteral | NullLiteral | NumericLiteral | BigIntLiteral | RegExpLiteral | StringLiteral | TemplateLiteral | IdentifierReference | MetaProperty | Super | ArrayExpression | ArrowFunctionExpression | AssignmentExpression | AwaitExpression | BinaryExpression | CallExpression | ChainExpression | Class | ConditionalExpression | Function$1 | ImportExpression | LogicalExpression | NewExpression | ObjectExpression | ParenthesizedExpression | SequenceExpression | TaggedTemplateExpression | ThisExpression | UnaryExpression | UpdateExpression | YieldExpression | PrivateInExpression | JSXElement | JSXFragment | TSAsExpression | TSSatisfiesExpression | TSTypeAssertion | TSNonNullExpression | TSInstantiationExpression | V8IntrinsicExpression | MemberExpression;
|
|
@@ -2631,7 +2396,12 @@ type ModuleKind = "script" | "module" | "commonjs";
|
|
|
2631
2396
|
type Node$1 = Program | IdentifierName | IdentifierReference | BindingIdentifier | LabelIdentifier | ThisExpression | ArrayExpression | ObjectExpression | ObjectProperty | TemplateLiteral | TaggedTemplateExpression | TemplateElement | ComputedMemberExpression | StaticMemberExpression | PrivateFieldExpression | CallExpression | NewExpression | MetaProperty | SpreadElement | UpdateExpression | UnaryExpression | BinaryExpression | PrivateInExpression | LogicalExpression | ConditionalExpression | AssignmentExpression | ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetRest | AssignmentTargetWithDefault | AssignmentTargetPropertyIdentifier | AssignmentTargetPropertyProperty | SequenceExpression | Super | AwaitExpression | ChainExpression | ParenthesizedExpression | Directive | Hashbang | BlockStatement | VariableDeclaration | VariableDeclarator | EmptyStatement | ExpressionStatement | IfStatement | DoWhileStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | ContinueStatement | BreakStatement | ReturnStatement | WithStatement | SwitchStatement | SwitchCase | LabeledStatement | ThrowStatement | TryStatement | CatchClause | DebuggerStatement | AssignmentPattern | ObjectPattern | BindingProperty | ArrayPattern | BindingRestElement | Function$1 | FunctionBody | ArrowFunctionExpression | YieldExpression | Class | ClassBody | MethodDefinition | PropertyDefinition | PrivateIdentifier | StaticBlock | AccessorProperty | ImportExpression | ImportDeclaration | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ImportAttribute | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration | ExportSpecifier | V8IntrinsicExpression | BooleanLiteral | NullLiteral | NumericLiteral | StringLiteral | BigIntLiteral | RegExpLiteral | JSXElement | JSXOpeningElement | JSXClosingElement | JSXFragment | JSXOpeningFragment | JSXClosingFragment | JSXNamespacedName | JSXMemberExpression | JSXExpressionContainer | JSXEmptyExpression | JSXAttribute | JSXSpreadAttribute | JSXIdentifier | JSXSpreadChild | JSXText | TSThisParameter | TSEnumDeclaration | TSEnumBody | TSEnumMember | TSTypeAnnotation | TSLiteralType | TSConditionalType | TSUnionType | TSIntersectionType | TSParenthesizedType | TSTypeOperator | TSArrayType | TSIndexedAccessType | TSTupleType | TSNamedTupleMember | TSOptionalType | TSRestType | TSAnyKeyword | TSStringKeyword | TSBooleanKeyword | TSNumberKeyword | TSNeverKeyword | TSIntrinsicKeyword | TSUnknownKeyword | TSNullKeyword | TSUndefinedKeyword | TSVoidKeyword | TSSymbolKeyword | TSThisType | TSObjectKeyword | TSBigIntKeyword | TSTypeReference | TSQualifiedName | TSTypeParameterInstantiation | TSTypeParameter | TSTypeParameterDeclaration | TSTypeAliasDeclaration | TSClassImplements | TSInterfaceDeclaration | TSInterfaceBody | TSPropertySignature | TSIndexSignature | TSCallSignatureDeclaration | TSMethodSignature | TSConstructSignatureDeclaration | TSIndexSignatureName | TSInterfaceHeritage | TSTypePredicate | TSModuleDeclaration | TSGlobalDeclaration | TSModuleBlock | TSTypeLiteral | TSInferType | TSTypeQuery | TSImportType | TSImportTypeQualifiedName | TSFunctionType | TSConstructorType | TSMappedType | TSTemplateLiteralType | TSAsExpression | TSSatisfiesExpression | TSTypeAssertion | TSImportEqualsDeclaration | TSExternalModuleReference | TSNonNullExpression | Decorator | TSExportAssignment | TSNamespaceExportDeclaration | TSInstantiationExpression | JSDocNullableType | JSDocNonNullableType | JSDocUnknownType | ParamPattern;
|
|
2632
2397
|
//#endregion
|
|
2633
2398
|
//#region src-js/generated/visitor.d.ts
|
|
2634
|
-
|
|
2399
|
+
// To understand why we need the "Bivariance hack", see: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/20219
|
|
2400
|
+
// For downsides, see: https://github.com/oxc-project/oxc/issues/18154#issuecomment-4012955607
|
|
2401
|
+
type BivarianceHackHandler<Handler extends (...args: any) => any> = {
|
|
2402
|
+
bivarianceHack(...args: Parameters<Handler>): ReturnType<Handler>;
|
|
2403
|
+
}["bivarianceHack"];
|
|
2404
|
+
interface StrictVisitorObject {
|
|
2635
2405
|
DebuggerStatement?: (node: DebuggerStatement) => void;
|
|
2636
2406
|
"DebuggerStatement:exit"?: (node: DebuggerStatement) => void;
|
|
2637
2407
|
EmptyStatement?: (node: EmptyStatement) => void;
|
|
@@ -2962,8 +2732,8 @@ interface VisitorObject {
|
|
|
2962
2732
|
"TSTypeReference:exit"?: (node: TSTypeReference) => void;
|
|
2963
2733
|
TSUnionType?: (node: TSUnionType) => void;
|
|
2964
2734
|
"TSUnionType:exit"?: (node: TSUnionType) => void;
|
|
2965
|
-
[key: string]: (node: Node$1) => void;
|
|
2966
2735
|
}
|
|
2736
|
+
type VisitorObject = { [K in keyof StrictVisitorObject]?: BivarianceHackHandler<Exclude<StrictVisitorObject[K], undefined>> | undefined } & Record<string, BivarianceHackHandler<(node: Node$1) => void> | undefined>;
|
|
2967
2737
|
//#endregion
|
|
2968
2738
|
//#region src-js/plugins/types.d.ts
|
|
2969
2739
|
type BeforeHook = () => boolean | void;
|
|
@@ -2973,7 +2743,7 @@ type VisitorWithHooks = VisitorObject & {
|
|
|
2973
2743
|
after?: AfterHook;
|
|
2974
2744
|
};
|
|
2975
2745
|
interface Node extends Span {}
|
|
2976
|
-
type NodeOrToken = Node |
|
|
2746
|
+
type NodeOrToken = Node | TokenType | Comment;
|
|
2977
2747
|
interface Comment extends Span {
|
|
2978
2748
|
type: "Line" | "Block" | "Shebang";
|
|
2979
2749
|
value: string;
|
|
@@ -3296,6 +3066,257 @@ declare function getScope(node: Node$1): Scope;
|
|
|
3296
3066
|
*/
|
|
3297
3067
|
declare function markVariableAsUsed(name: string, refNode: Node$1): boolean;
|
|
3298
3068
|
//#endregion
|
|
3069
|
+
//#region src-js/plugins/tokens_methods.d.ts
|
|
3070
|
+
/**
|
|
3071
|
+
* Options for various `SourceCode` methods e.g. `getFirstToken`.
|
|
3072
|
+
*/
|
|
3073
|
+
interface SkipOptions {
|
|
3074
|
+
/** Number of skipping tokens */
|
|
3075
|
+
skip?: number;
|
|
3076
|
+
/** `true` to include comment tokens in the result */
|
|
3077
|
+
includeComments?: boolean;
|
|
3078
|
+
/** Function to filter tokens */
|
|
3079
|
+
filter?: FilterFn | null;
|
|
3080
|
+
}
|
|
3081
|
+
/**
|
|
3082
|
+
* Options for various `SourceCode` methods e.g. `getFirstTokens`.
|
|
3083
|
+
*/
|
|
3084
|
+
interface CountOptions {
|
|
3085
|
+
/** Maximum number of tokens to return */
|
|
3086
|
+
count?: number;
|
|
3087
|
+
/** `true` to include comment tokens in the result */
|
|
3088
|
+
includeComments?: boolean;
|
|
3089
|
+
/** Function to filter tokens */
|
|
3090
|
+
filter?: FilterFn | null;
|
|
3091
|
+
}
|
|
3092
|
+
/**
|
|
3093
|
+
* Options for `getTokenByRangeStart`.
|
|
3094
|
+
*/
|
|
3095
|
+
interface RangeOptions {
|
|
3096
|
+
/** `true` to include comment tokens in the result */
|
|
3097
|
+
includeComments?: boolean;
|
|
3098
|
+
}
|
|
3099
|
+
/**
|
|
3100
|
+
* Filter function, passed as `filter` property of `SkipOptions` and `CountOptions`.
|
|
3101
|
+
*/
|
|
3102
|
+
type FilterFn = (token: TokenOrComment) => boolean;
|
|
3103
|
+
/**
|
|
3104
|
+
* Whether `Options` may include comment tokens in the result.
|
|
3105
|
+
* Resolves to `true` if `Options` has an `includeComments` property whose type includes `true`
|
|
3106
|
+
* (i.e. it's `true`, `boolean`, or `boolean | undefined`), and `false` otherwise.
|
|
3107
|
+
*/
|
|
3108
|
+
type MayIncludeComments<Options> = Options extends {
|
|
3109
|
+
includeComments: false;
|
|
3110
|
+
} ? false : "includeComments" extends keyof Options ? true : false;
|
|
3111
|
+
/**
|
|
3112
|
+
* Resolves to `TokenOrComment` if `Options` may include comments, `Token` otherwise.
|
|
3113
|
+
*/
|
|
3114
|
+
type TokenResult<Options> = MayIncludeComments<Options> extends true ? TokenOrComment : TokenType;
|
|
3115
|
+
/**
|
|
3116
|
+
* Get all tokens that are related to the given node.
|
|
3117
|
+
* @param node - The AST node.
|
|
3118
|
+
* @param countOptions? - Options object. If is a function, equivalent to `{ filter: fn }`.
|
|
3119
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3120
|
+
*/
|
|
3121
|
+
/**
|
|
3122
|
+
* Get all tokens that are related to the given node.
|
|
3123
|
+
* @param node - The AST node.
|
|
3124
|
+
* @param beforeCount? - The number of tokens before the node to retrieve.
|
|
3125
|
+
* @param afterCount? - The number of tokens after the node to retrieve.
|
|
3126
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3127
|
+
*/
|
|
3128
|
+
declare function getTokens<Options extends CountOptions | number | FilterFn | null | undefined>(node: Node, countOptions?: Options, afterCount?: number | null): TokenResult<Options>[];
|
|
3129
|
+
/**
|
|
3130
|
+
* Get the first token of the given node.
|
|
3131
|
+
* @param node - The AST node.
|
|
3132
|
+
* @param skipOptions? - Options object.
|
|
3133
|
+
* If is a number, equivalent to `{ skip: n }`.
|
|
3134
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3135
|
+
* @returns `Token` (or `Token | Comment` if `includeComments` is `true`), or `null` if none found.
|
|
3136
|
+
*/
|
|
3137
|
+
declare function getFirstToken<Options extends SkipOptions | number | FilterFn | null | undefined>(node: Node, skipOptions?: Options): TokenResult<Options> | null;
|
|
3138
|
+
/**
|
|
3139
|
+
* Get the first tokens of the given node.
|
|
3140
|
+
* @param node - The AST node.
|
|
3141
|
+
* @param countOptions? - Options object.
|
|
3142
|
+
* If is a number, equivalent to `{ count: n }`.
|
|
3143
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3144
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3145
|
+
*/
|
|
3146
|
+
declare function getFirstTokens<Options extends CountOptions | number | FilterFn | null | undefined>(node: Node, countOptions?: Options): TokenResult<Options>[];
|
|
3147
|
+
/**
|
|
3148
|
+
* Get the last token of the given node.
|
|
3149
|
+
* @param node - The AST node.
|
|
3150
|
+
* @param skipOptions? - Options object.
|
|
3151
|
+
* If is a number, equivalent to `{ skip: n }`.
|
|
3152
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3153
|
+
* @returns `Token` (or `Token | Comment` if `includeComments` is `true`), or `null` if none found.
|
|
3154
|
+
*/
|
|
3155
|
+
declare function getLastToken<Options extends SkipOptions | number | FilterFn | null | undefined>(node: Node, skipOptions?: Options): TokenResult<Options> | null;
|
|
3156
|
+
/**
|
|
3157
|
+
* Get the last tokens of the given node.
|
|
3158
|
+
* @param node - The AST node.
|
|
3159
|
+
* @param countOptions? - Options object.
|
|
3160
|
+
* If is a number, equivalent to `{ count: n }`.
|
|
3161
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3162
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3163
|
+
*/
|
|
3164
|
+
declare function getLastTokens<Options extends CountOptions | number | FilterFn | null | undefined>(node: Node, countOptions?: Options): TokenResult<Options>[];
|
|
3165
|
+
/**
|
|
3166
|
+
* Get the token that precedes a given node or token.
|
|
3167
|
+
* @param nodeOrToken - The AST node or token.
|
|
3168
|
+
* @param skipOptions? - Options object.
|
|
3169
|
+
* If is a number, equivalent to `{ skip: n }`.
|
|
3170
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3171
|
+
* @returns `Token` (or `Token | Comment` if `includeComments` is `true`), or `null` if none found.
|
|
3172
|
+
*/
|
|
3173
|
+
declare function getTokenBefore<Options extends SkipOptions | number | FilterFn | null | undefined>(nodeOrToken: NodeOrToken, skipOptions?: Options): TokenResult<Options> | null;
|
|
3174
|
+
/**
|
|
3175
|
+
* Get the token that precedes a given node or token.
|
|
3176
|
+
*
|
|
3177
|
+
* @deprecated Use `sourceCode.getTokenBefore` with `includeComments: true` instead.
|
|
3178
|
+
*
|
|
3179
|
+
* @param nodeOrToken The AST node or token.
|
|
3180
|
+
* @param skip - Number of tokens to skip.
|
|
3181
|
+
* @returns `TokenOrComment | null`.
|
|
3182
|
+
*/
|
|
3183
|
+
declare function getTokenOrCommentBefore(nodeOrToken: NodeOrToken, skip?: number): TokenOrComment | null;
|
|
3184
|
+
/**
|
|
3185
|
+
* Get the tokens that precede a given node or token.
|
|
3186
|
+
* @param nodeOrToken - The AST node or token.
|
|
3187
|
+
* @param countOptions? - Options object.
|
|
3188
|
+
* If is a number, equivalent to `{ count: n }`.
|
|
3189
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3190
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3191
|
+
*/
|
|
3192
|
+
declare function getTokensBefore<Options extends CountOptions | number | FilterFn | null | undefined>(nodeOrToken: NodeOrToken, countOptions?: Options): TokenResult<Options>[];
|
|
3193
|
+
/**
|
|
3194
|
+
* Get the token that follows a given node or token.
|
|
3195
|
+
* @param nodeOrToken - The AST node or token.
|
|
3196
|
+
* @param skipOptions? - Options object.
|
|
3197
|
+
* If is a number, equivalent to `{ skip: n }`.
|
|
3198
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3199
|
+
* @returns `Token` (or `Token | Comment` if `includeComments` is `true`), or `null` if none found.
|
|
3200
|
+
*/
|
|
3201
|
+
declare function getTokenAfter<Options extends SkipOptions | number | FilterFn | null | undefined>(nodeOrToken: NodeOrToken, skipOptions?: Options): TokenResult<Options> | null;
|
|
3202
|
+
/**
|
|
3203
|
+
* Get the token that follows a given node or token.
|
|
3204
|
+
*
|
|
3205
|
+
* @deprecated Use `sourceCode.getTokenAfter` with `includeComments: true` instead.
|
|
3206
|
+
*
|
|
3207
|
+
* @param nodeOrToken The AST node or token.
|
|
3208
|
+
* @param skip - Number of tokens to skip.
|
|
3209
|
+
* @returns `TokenOrComment | null`.
|
|
3210
|
+
*/
|
|
3211
|
+
declare function getTokenOrCommentAfter(nodeOrToken: NodeOrToken, skip?: number): TokenOrComment | null;
|
|
3212
|
+
/**
|
|
3213
|
+
* Get the tokens that follow a given node or token.
|
|
3214
|
+
* @param nodeOrToken - The AST node or token.
|
|
3215
|
+
* @param countOptions? - Options object.
|
|
3216
|
+
* If is a number, equivalent to `{ count: n }`.
|
|
3217
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3218
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3219
|
+
*/
|
|
3220
|
+
declare function getTokensAfter<Options extends CountOptions | number | FilterFn | null | undefined>(nodeOrToken: NodeOrToken, countOptions?: Options): TokenResult<Options>[];
|
|
3221
|
+
/**
|
|
3222
|
+
* Get all of the tokens between two non-overlapping nodes.
|
|
3223
|
+
* @param left - Node or token before the desired token range.
|
|
3224
|
+
* @param right - Node or token after the desired token range.
|
|
3225
|
+
* @param countOptions? - Options object. If is a function, equivalent to `{ filter: fn }`.
|
|
3226
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3227
|
+
*/
|
|
3228
|
+
/**
|
|
3229
|
+
* Get all of the tokens between two non-overlapping nodes.
|
|
3230
|
+
* @param left - Node or token before the desired token range.
|
|
3231
|
+
* @param right - Node or token after the desired token range.
|
|
3232
|
+
* @param padding - Number of extra tokens on either side of center.
|
|
3233
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3234
|
+
*/
|
|
3235
|
+
declare function getTokensBetween<Options extends CountOptions | number | FilterFn | null | undefined>(left: NodeOrToken, right: NodeOrToken, countOptions?: Options): TokenResult<Options>[];
|
|
3236
|
+
/**
|
|
3237
|
+
* Get the first token between two non-overlapping nodes.
|
|
3238
|
+
* @param left - Node or token before the desired token range.
|
|
3239
|
+
* @param right - Node or token after the desired token range.
|
|
3240
|
+
* @param skipOptions? - Options object.
|
|
3241
|
+
* If is a number, equivalent to `{ skip: n }`.
|
|
3242
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3243
|
+
* @returns `Token` (or `Token | Comment` if `includeComments` is `true`), or `null` if none found.
|
|
3244
|
+
*/
|
|
3245
|
+
declare function getFirstTokenBetween<Options extends SkipOptions | number | FilterFn | null | undefined>(left: NodeOrToken, right: NodeOrToken, skipOptions?: Options): TokenResult<Options> | null;
|
|
3246
|
+
/**
|
|
3247
|
+
* Get the first tokens between two non-overlapping nodes.
|
|
3248
|
+
* @param left - Node or token before the desired token range.
|
|
3249
|
+
* @param right - Node or token after the desired token range.
|
|
3250
|
+
* @param countOptions? - Options object.
|
|
3251
|
+
* If is a number, equivalent to `{ count: n }`.
|
|
3252
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3253
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3254
|
+
*/
|
|
3255
|
+
declare function getFirstTokensBetween<Options extends CountOptions | number | FilterFn | null | undefined>(left: NodeOrToken, right: NodeOrToken, countOptions?: Options): TokenResult<Options>[];
|
|
3256
|
+
/**
|
|
3257
|
+
* Get the last token between two non-overlapping nodes.
|
|
3258
|
+
* @param left - Node or token before the desired token range.
|
|
3259
|
+
* @param right - Node or token after the desired token range.
|
|
3260
|
+
* @param skipOptions? - Options object.
|
|
3261
|
+
* If is a number, equivalent to `{ skip: n }`.
|
|
3262
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3263
|
+
* @returns `Token` (or `Token | Comment` if `includeComments` is `true`), or `null` if none found.
|
|
3264
|
+
*/
|
|
3265
|
+
declare function getLastTokenBetween<Options extends SkipOptions | number | FilterFn | null | undefined>(left: NodeOrToken, right: NodeOrToken, skipOptions?: Options): TokenResult<Options> | null;
|
|
3266
|
+
/**
|
|
3267
|
+
* Get the last tokens between two non-overlapping nodes.
|
|
3268
|
+
* @param left - Node or token before the desired token range.
|
|
3269
|
+
* @param right - Node or token after the desired token range.
|
|
3270
|
+
* @param countOptions? - Options object.
|
|
3271
|
+
* If is a number, equivalent to `{ count: n }`.
|
|
3272
|
+
* If is a function, equivalent to `{ filter: fn }`.
|
|
3273
|
+
* @returns Array of `Token`s, or array of `Token | Comment`s if `includeComments` is `true`.
|
|
3274
|
+
*/
|
|
3275
|
+
declare function getLastTokensBetween<Options extends CountOptions | number | FilterFn | null | undefined>(left: NodeOrToken, right: NodeOrToken, countOptions?: Options): TokenResult<Options>[];
|
|
3276
|
+
/**
|
|
3277
|
+
* Get the token starting at the specified index.
|
|
3278
|
+
* @param index - Index of the start of the token's range.
|
|
3279
|
+
* @param rangeOptions - Options object.
|
|
3280
|
+
* @returns `Token` (or `Token | Comment` if `includeComments` is `true`), or `null` if none found.
|
|
3281
|
+
*/
|
|
3282
|
+
declare function getTokenByRangeStart<Options extends RangeOptions | null | undefined>(index: number, rangeOptions?: Options): TokenResult<Options> | null;
|
|
3283
|
+
/**
|
|
3284
|
+
* Determine if two nodes or tokens have at least one whitespace character between them.
|
|
3285
|
+
* Order does not matter.
|
|
3286
|
+
*
|
|
3287
|
+
* Returns `false` if the given nodes or tokens overlap.
|
|
3288
|
+
*
|
|
3289
|
+
* Checks for whitespace *between tokens*, not including whitespace *inside tokens*.
|
|
3290
|
+
* e.g. Returns `false` for `isSpaceBetween(x, y)` in `x+" "+y`.
|
|
3291
|
+
*
|
|
3292
|
+
* @param first - The first node or token to check between.
|
|
3293
|
+
* @param second - The second node or token to check between.
|
|
3294
|
+
* @returns `true` if there is a whitespace character between
|
|
3295
|
+
* any of the tokens found between the two given nodes or tokens.
|
|
3296
|
+
*/
|
|
3297
|
+
declare function isSpaceBetween(first: NodeOrToken, second: NodeOrToken): boolean;
|
|
3298
|
+
/**
|
|
3299
|
+
* Determine if two nodes or tokens have at least one whitespace character between them.
|
|
3300
|
+
* Order does not matter.
|
|
3301
|
+
*
|
|
3302
|
+
* Returns `false` if the given nodes or tokens overlap.
|
|
3303
|
+
*
|
|
3304
|
+
* Checks for whitespace *between tokens*, not including whitespace *inside tokens*.
|
|
3305
|
+
* e.g. Returns `false` for `isSpaceBetween(x, y)` in `x+" "+y`.
|
|
3306
|
+
*
|
|
3307
|
+
* Unlike `SourceCode#isSpaceBetween`, this function does return `true` if there is a `JSText` token between the two
|
|
3308
|
+
* input tokens, and it contains whitespace.
|
|
3309
|
+
* e.g. Returns `true` for `isSpaceBetweenTokens(x, slash)` in `<X>a b</X>`.
|
|
3310
|
+
*
|
|
3311
|
+
* @deprecated Use `sourceCode.isSpaceBetween` instead.
|
|
3312
|
+
*
|
|
3313
|
+
* @param first - The first node or token to check between.
|
|
3314
|
+
* @param second - The second node or token to check between.
|
|
3315
|
+
* @returns `true` if there is a whitespace character between
|
|
3316
|
+
* any of the tokens found between the two given nodes or tokens.
|
|
3317
|
+
*/
|
|
3318
|
+
declare function isSpaceBetweenTokens(first: NodeOrToken, second: NodeOrToken): boolean;
|
|
3319
|
+
//#endregion
|
|
3299
3320
|
//#region src-js/plugins/source_code.d.ts
|
|
3300
3321
|
declare const SOURCE_CODE: Readonly<{
|
|
3301
3322
|
/**
|
|
@@ -3340,7 +3361,7 @@ declare const SOURCE_CODE: Readonly<{
|
|
|
3340
3361
|
/**
|
|
3341
3362
|
* Array of all tokens and comments in the file, in source order.
|
|
3342
3363
|
*/
|
|
3343
|
-
readonly tokensAndComments: (
|
|
3364
|
+
readonly tokensAndComments: (TokenType | Comment)[];
|
|
3344
3365
|
/**
|
|
3345
3366
|
* Get the source code for the given node.
|
|
3346
3367
|
* @param node? - The AST node to get the text for.
|
|
@@ -3770,7 +3791,7 @@ interface RuleMeta {
|
|
|
3770
3791
|
* Type of fixes that the rule provides.
|
|
3771
3792
|
* Must be `'code'` or `'whitespace'` if the rule provides fixes.
|
|
3772
3793
|
*/
|
|
3773
|
-
fixable?: "code" | "whitespace";
|
|
3794
|
+
fixable?: "code" | "whitespace" | null | undefined;
|
|
3774
3795
|
/**
|
|
3775
3796
|
* Specifies whether rule can return suggestions.
|
|
3776
3797
|
* Must be `true` if the rule provides suggestions.
|
|
@@ -3961,4 +3982,4 @@ declare function defineRule(rule: Rule): Rule;
|
|
|
3961
3982
|
*/
|
|
3962
3983
|
declare function eslintCompatPlugin(plugin: Plugin): Plugin;
|
|
3963
3984
|
//#endregion
|
|
3964
|
-
export { type AfterHook, type BeforeHook, type BooleanToken, type Comment, type Context, type CountOptions, type CreateOnceRule, type CreateRule, type Definition, type DefinitionType, type Diagnostic, type DiagnosticData, type types_d_exports as ESTree, type Envs, type FilterFn, type Fix, type FixFn, type Fixer, type Globals, type IdentifierToken, type JSXIdentifierToken, type JSXTextToken, type KeywordToken, type LanguageOptions, type LineColumn, type Location, type Node, type NullToken, type NumericToken, type Options, type Plugin, type PrivateIdentifierToken, type PunctuatorToken, type Range, type RangeOptions, type Ranged, type Reference, type RegularExpressionToken, type Rule, type RuleDeprecatedInfo, type RuleDocs, type RuleMeta, type RuleOptionsSchema, type RuleReplacedByExternalSpecifier, type RuleReplacedByInfo, type Scope, type ScopeManager, type ScopeType, type Settings, type SkipOptions, type SourceCode, type Span, type StringToken, type Suggestion, type TemplateToken, type Token, type Variable, type VisitorObject as Visitor, type VisitorWithHooks, definePlugin, defineRule, eslintCompatPlugin };
|
|
3985
|
+
export { type AfterHook, type BeforeHook, type BooleanToken, type Comment, type Context, type CountOptions, type CreateOnceRule, type CreateRule, type Definition, type DefinitionType, type Diagnostic, type DiagnosticData, type types_d_exports as ESTree, type Envs, type FilterFn, type Fix, type FixFn, type Fixer, type Globals, type IdentifierToken, type JSXIdentifierToken, type JSXTextToken, type KeywordToken, type LanguageOptions, type LineColumn, type Location, type Node, type NullToken, type NumericToken, type Options, type Plugin, type PrivateIdentifierToken, type PunctuatorToken, type Range, type RangeOptions, type Ranged, type Reference, type RegularExpressionToken, type Rule, type RuleDeprecatedInfo, type RuleDocs, type RuleMeta, type RuleOptionsSchema, type RuleReplacedByExternalSpecifier, type RuleReplacedByInfo, type Scope, type ScopeManager, type ScopeType, type Settings, type SkipOptions, type SourceCode, type Span, type StringToken, type Suggestion, type TemplateToken, type TokenType as Token, type Variable, type VisitorObject as Visitor, type VisitorWithHooks, definePlugin, defineRule, eslintCompatPlugin };
|
package/index.js
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
|
+
//#region src-js/package/define.ts
|
|
2
|
+
/**
|
|
3
|
+
* Define a plugin.
|
|
4
|
+
*
|
|
5
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param plugin - Plugin to define
|
|
8
|
+
* @returns Same plugin as passed in
|
|
9
|
+
*/
|
|
1
10
|
function definePlugin(plugin) {
|
|
2
11
|
return plugin;
|
|
3
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Define a rule.
|
|
15
|
+
*
|
|
16
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
17
|
+
*
|
|
18
|
+
* @param rule - Rule to define
|
|
19
|
+
* @returns Same rule as passed in
|
|
20
|
+
*/
|
|
4
21
|
function defineRule(rule) {
|
|
5
22
|
return rule;
|
|
6
23
|
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src-js/package/compat.ts
|
|
7
26
|
const EMPTY_VISITOR = {};
|
|
27
|
+
/**
|
|
28
|
+
* Convert a plugin which used Oxlint's `createOnce` API to also work with ESLint.
|
|
29
|
+
*
|
|
30
|
+
* If any of the plugin's rules use the Oxlint alternative `createOnce` API,
|
|
31
|
+
* add ESLint-compatible `create` methods to those rules, which delegate to `createOnce`.
|
|
32
|
+
* This makes the plugin compatible with ESLint.
|
|
33
|
+
*
|
|
34
|
+
* The `plugin` object passed in is mutated in-place.
|
|
35
|
+
*
|
|
36
|
+
* @param plugin - Plugin to convert
|
|
37
|
+
* @returns Plugin with all rules having `create` method
|
|
38
|
+
* @throws {Error} If `plugin` is not an object, or `plugin.rules` is not an object
|
|
39
|
+
*/
|
|
8
40
|
function eslintCompatPlugin(plugin) {
|
|
9
41
|
if (typeof plugin != "object" || !plugin) throw Error("Plugin must be an object");
|
|
10
42
|
let { rules } = plugin;
|
|
@@ -12,6 +44,14 @@ function eslintCompatPlugin(plugin) {
|
|
|
12
44
|
for (let ruleName in rules) Object.hasOwn(rules, ruleName) && convertRule(rules[ruleName]);
|
|
13
45
|
return plugin;
|
|
14
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Convert a rule.
|
|
49
|
+
*
|
|
50
|
+
* The `rule` object passed in is mutated in-place.
|
|
51
|
+
*
|
|
52
|
+
* @param rule - Rule to convert
|
|
53
|
+
* @throws {Error} If `rule` is not an object
|
|
54
|
+
*/
|
|
15
55
|
function convertRule(rule) {
|
|
16
56
|
if (typeof rule != "object" || !rule) throw Error("Rule must be an object");
|
|
17
57
|
if ("create" in rule) return;
|
|
@@ -63,13 +103,19 @@ const FILE_CONTEXT = Object.freeze({
|
|
|
63
103
|
throw Error("Cannot access `context.parserPath` in `createOnce`");
|
|
64
104
|
}
|
|
65
105
|
});
|
|
106
|
+
/**
|
|
107
|
+
* Call `createOnce` method of rule, and return `Context`, `Visitor`, and `beforeHook` (if any).
|
|
108
|
+
*
|
|
109
|
+
* @param rule - Rule with `createOnce` method
|
|
110
|
+
* @returns Object with `context`, `visitor`, and `beforeHook` properties
|
|
111
|
+
*/
|
|
66
112
|
function createContextAndVisitor(rule) {
|
|
67
113
|
let { createOnce } = rule;
|
|
68
114
|
if (createOnce == null) throw Error("Rules must define either a `create` or `createOnce` method");
|
|
69
115
|
if (typeof createOnce != "function") throw Error("Rule `createOnce` property must be a function");
|
|
70
116
|
let context = Object.create(FILE_CONTEXT, {
|
|
71
117
|
id: {
|
|
72
|
-
value:
|
|
118
|
+
value: null,
|
|
73
119
|
enumerable: !0,
|
|
74
120
|
configurable: !0
|
|
75
121
|
},
|
|
@@ -79,7 +125,9 @@ function createContextAndVisitor(rule) {
|
|
|
79
125
|
configurable: !0
|
|
80
126
|
},
|
|
81
127
|
report: {
|
|
82
|
-
value
|
|
128
|
+
value() {
|
|
129
|
+
throw Error("Cannot report errors in `createOnce`");
|
|
130
|
+
},
|
|
83
131
|
enumerable: !0,
|
|
84
132
|
configurable: !0
|
|
85
133
|
}
|
|
@@ -107,4 +155,5 @@ function createContextAndVisitor(rule) {
|
|
|
107
155
|
beforeHook
|
|
108
156
|
};
|
|
109
157
|
}
|
|
158
|
+
//#endregion
|
|
110
159
|
export { definePlugin, defineRule, eslintCompatPlugin };
|