@oxlint/plugins 1.51.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 +266 -247
- 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,43 +1049,10 @@ 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;
|
|
1091
1058
|
regex: undefined;
|
|
@@ -1131,213 +1098,9 @@ interface StringToken extends BaseToken {
|
|
|
1131
1098
|
interface TemplateToken extends BaseToken {
|
|
1132
1099
|
type: "Template";
|
|
1133
1100
|
}
|
|
1134
|
-
type TokenOrComment =
|
|
1135
|
-
/**
|
|
1136
|
-
* Get all tokens that are related to the given node.
|
|
1137
|
-
* @param node - The AST node.
|
|
1138
|
-
* @param countOptions? - Options object. If is a function, equivalent to `{ filter: fn }`.
|
|
1139
|
-
* @returns Array of `Token`s.
|
|
1140
|
-
*/
|
|
1141
|
-
/**
|
|
1142
|
-
* Get all tokens that are related to the given node.
|
|
1143
|
-
* @param node - The AST node.
|
|
1144
|
-
* @param beforeCount? - The number of tokens before the node to retrieve.
|
|
1145
|
-
* @param afterCount? - The number of tokens after the node to retrieve.
|
|
1146
|
-
* @returns Array of `Token`s.
|
|
1147
|
-
*/
|
|
1148
|
-
declare function getTokens(node: Node, countOptions?: CountOptions | number | FilterFn | null, afterCount?: number | null): TokenOrComment[];
|
|
1149
|
-
/**
|
|
1150
|
-
* Get the first token of the given node.
|
|
1151
|
-
* @param node - The AST node.
|
|
1152
|
-
* @param skipOptions? - Options object.
|
|
1153
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1154
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1155
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1156
|
-
*/
|
|
1157
|
-
declare function getFirstToken(node: Node, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1158
|
-
/**
|
|
1159
|
-
* Get the first tokens of the given node.
|
|
1160
|
-
* @param node - The AST node.
|
|
1161
|
-
* @param countOptions? - Options object.
|
|
1162
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1163
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1164
|
-
* @returns Array of `Token`s.
|
|
1165
|
-
*/
|
|
1166
|
-
declare function getFirstTokens(node: Node, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1167
|
-
/**
|
|
1168
|
-
* Get the last token of the given node.
|
|
1169
|
-
* @param node - The AST node.
|
|
1170
|
-
* @param skipOptions? - Options object.
|
|
1171
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1172
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1173
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1174
|
-
*/
|
|
1175
|
-
declare function getLastToken(node: Node, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1176
|
-
/**
|
|
1177
|
-
* Get the last tokens of the given node.
|
|
1178
|
-
* @param node - The AST node.
|
|
1179
|
-
* @param countOptions? - Options object.
|
|
1180
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1181
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1182
|
-
* @returns Array of `Token`s.
|
|
1183
|
-
*/
|
|
1184
|
-
declare function getLastTokens(node: Node, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1185
|
-
/**
|
|
1186
|
-
* Get the token that precedes a given node or token.
|
|
1187
|
-
* @param nodeOrToken - The AST node or token.
|
|
1188
|
-
* @param skipOptions? - Options object.
|
|
1189
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1190
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1191
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1192
|
-
*/
|
|
1193
|
-
declare function getTokenBefore(nodeOrToken: NodeOrToken, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1194
|
-
/**
|
|
1195
|
-
* Get the token that precedes a given node or token.
|
|
1196
|
-
*
|
|
1197
|
-
* @deprecated Use `sourceCode.getTokenBefore` with `includeComments: true` instead.
|
|
1198
|
-
*
|
|
1199
|
-
* @param nodeOrToken The AST node or token.
|
|
1200
|
-
* @param skip - Number of tokens to skip.
|
|
1201
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1202
|
-
*/
|
|
1203
|
-
declare function getTokenOrCommentBefore(nodeOrToken: NodeOrToken, skip?: number): TokenOrComment | null;
|
|
1204
|
-
/**
|
|
1205
|
-
* Get the tokens that precede a given node or token.
|
|
1206
|
-
* @param nodeOrToken - The AST node or token.
|
|
1207
|
-
* @param countOptions? - Options object.
|
|
1208
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1209
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1210
|
-
* @returns Array of `Token`s.
|
|
1211
|
-
*/
|
|
1212
|
-
declare function getTokensBefore(nodeOrToken: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1213
|
-
/**
|
|
1214
|
-
* Get the token that follows a given node or token.
|
|
1215
|
-
* @param nodeOrToken - The AST node or token.
|
|
1216
|
-
* @param skipOptions? - Options object.
|
|
1217
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1218
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1219
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1220
|
-
*/
|
|
1221
|
-
declare function getTokenAfter(nodeOrToken: NodeOrToken, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1222
|
-
/**
|
|
1223
|
-
* Get the token that follows a given node or token.
|
|
1224
|
-
*
|
|
1225
|
-
* @deprecated Use `sourceCode.getTokenAfter` with `includeComments: true` instead.
|
|
1226
|
-
*
|
|
1227
|
-
* @param nodeOrToken The AST node or token.
|
|
1228
|
-
* @param skip - Number of tokens to skip.
|
|
1229
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1230
|
-
*/
|
|
1231
|
-
declare function getTokenOrCommentAfter(nodeOrToken: NodeOrToken, skip?: number): TokenOrComment | null;
|
|
1232
|
-
/**
|
|
1233
|
-
* Get the tokens that follow a given node or token.
|
|
1234
|
-
* @param nodeOrToken - The AST node or token.
|
|
1235
|
-
* @param countOptions? - Options object.
|
|
1236
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1237
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1238
|
-
* @returns Array of `Token`s.
|
|
1239
|
-
*/
|
|
1240
|
-
declare function getTokensAfter(nodeOrToken: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1241
|
-
/**
|
|
1242
|
-
* Get all of the tokens between two non-overlapping nodes.
|
|
1243
|
-
* @param left - Node or token before the desired token range.
|
|
1244
|
-
* @param right - Node or token after the desired token range.
|
|
1245
|
-
* @param countOptions? - Options object. If is a function, equivalent to `{ filter: fn }`.
|
|
1246
|
-
* @returns Array of `Token`s between `left` and `right`.
|
|
1247
|
-
*/
|
|
1248
|
-
/**
|
|
1249
|
-
* Get all of the tokens between two non-overlapping nodes.
|
|
1250
|
-
* @param left - Node or token before the desired token range.
|
|
1251
|
-
* @param right - Node or token after the desired token range.
|
|
1252
|
-
* @param padding - Number of extra tokens on either side of center.
|
|
1253
|
-
* @returns Array of `Token`s between `left` and `right`.
|
|
1254
|
-
*/
|
|
1255
|
-
declare function getTokensBetween(left: NodeOrToken, right: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1256
|
-
/**
|
|
1257
|
-
* Get the first token between two non-overlapping nodes.
|
|
1258
|
-
* @param left - Node or token before the desired token range.
|
|
1259
|
-
* @param right - Node or token after the desired token range.
|
|
1260
|
-
* @param skipOptions? - Options object.
|
|
1261
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1262
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1263
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1264
|
-
*/
|
|
1265
|
-
declare function getFirstTokenBetween(left: NodeOrToken, right: NodeOrToken, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1266
|
-
/**
|
|
1267
|
-
* Get the first tokens between two non-overlapping nodes.
|
|
1268
|
-
* @param left - Node or token before the desired token range.
|
|
1269
|
-
* @param right - Node or token after the desired token range.
|
|
1270
|
-
* @param countOptions? - Options object.
|
|
1271
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1272
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1273
|
-
* @returns Array of `Token`s between `left` and `right`.
|
|
1274
|
-
*/
|
|
1275
|
-
declare function getFirstTokensBetween(left: NodeOrToken, right: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1276
|
-
/**
|
|
1277
|
-
* Get the last token between two non-overlapping nodes.
|
|
1278
|
-
* @param left - Node or token before the desired token range.
|
|
1279
|
-
* @param right - Node or token after the desired token range.
|
|
1280
|
-
* @param skipOptions? - Options object.
|
|
1281
|
-
* If is a number, equivalent to `{ skip: n }`.
|
|
1282
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1283
|
-
* @returns `Token`, or `null` if all were skipped.
|
|
1284
|
-
*/
|
|
1285
|
-
declare function getLastTokenBetween(left: NodeOrToken, right: NodeOrToken, skipOptions?: SkipOptions | number | FilterFn | null): TokenOrComment | null;
|
|
1286
|
-
/**
|
|
1287
|
-
* Get the last tokens between two non-overlapping nodes.
|
|
1288
|
-
* @param left - Node or token before the desired token range.
|
|
1289
|
-
* @param right - Node or token after the desired token range.
|
|
1290
|
-
* @param countOptions? - Options object.
|
|
1291
|
-
* If is a number, equivalent to `{ count: n }`.
|
|
1292
|
-
* If is a function, equivalent to `{ filter: fn }`.
|
|
1293
|
-
* @returns Array of `Token`s between `left` and `right`.
|
|
1294
|
-
*/
|
|
1295
|
-
declare function getLastTokensBetween(left: NodeOrToken, right: NodeOrToken, countOptions?: CountOptions | number | FilterFn | null): TokenOrComment[];
|
|
1296
|
-
/**
|
|
1297
|
-
* Get the token starting at the specified index.
|
|
1298
|
-
* @param index - Index of the start of the token's range.
|
|
1299
|
-
* @param rangeOptions - Options object.
|
|
1300
|
-
* @returns The token starting at index, or `null` if no such token.
|
|
1301
|
-
*/
|
|
1302
|
-
declare function getTokenByRangeStart(index: number, rangeOptions?: RangeOptions | null): TokenOrComment | null;
|
|
1303
|
-
/**
|
|
1304
|
-
* Determine if two nodes or tokens have at least one whitespace character between them.
|
|
1305
|
-
* Order does not matter.
|
|
1306
|
-
*
|
|
1307
|
-
* Returns `false` if the given nodes or tokens overlap.
|
|
1308
|
-
*
|
|
1309
|
-
* Checks for whitespace *between tokens*, not including whitespace *inside tokens*.
|
|
1310
|
-
* e.g. Returns `false` for `isSpaceBetween(x, y)` in `x+" "+y`.
|
|
1311
|
-
*
|
|
1312
|
-
* @param first - The first node or token to check between.
|
|
1313
|
-
* @param second - The second node or token to check between.
|
|
1314
|
-
* @returns `true` if there is a whitespace character between
|
|
1315
|
-
* any of the tokens found between the two given nodes or tokens.
|
|
1316
|
-
*/
|
|
1317
|
-
declare function isSpaceBetween(first: NodeOrToken, second: NodeOrToken): boolean;
|
|
1318
|
-
/**
|
|
1319
|
-
* Determine if two nodes or tokens have at least one whitespace character between them.
|
|
1320
|
-
* Order does not matter.
|
|
1321
|
-
*
|
|
1322
|
-
* Returns `false` if the given nodes or tokens overlap.
|
|
1323
|
-
*
|
|
1324
|
-
* Checks for whitespace *between tokens*, not including whitespace *inside tokens*.
|
|
1325
|
-
* e.g. Returns `false` for `isSpaceBetween(x, y)` in `x+" "+y`.
|
|
1326
|
-
*
|
|
1327
|
-
* Unlike `SourceCode#isSpaceBetween`, this function does return `true` if there is a `JSText` token between the two
|
|
1328
|
-
* input tokens, and it contains whitespace.
|
|
1329
|
-
* e.g. Returns `true` for `isSpaceBetweenTokens(x, slash)` in `<X>a b</X>`.
|
|
1330
|
-
*
|
|
1331
|
-
* @deprecated Use `sourceCode.isSpaceBetween` instead.
|
|
1332
|
-
*
|
|
1333
|
-
* @param first - The first node or token to check between.
|
|
1334
|
-
* @param second - The second node or token to check between.
|
|
1335
|
-
* @returns `true` if there is a whitespace character between
|
|
1336
|
-
* any of the tokens found between the two given nodes or tokens.
|
|
1337
|
-
*/
|
|
1338
|
-
declare function isSpaceBetweenTokens(first: NodeOrToken, second: NodeOrToken): boolean;
|
|
1101
|
+
type TokenOrComment = TokenType | Comment;
|
|
1339
1102
|
declare namespace types_d_exports {
|
|
1340
|
-
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 };
|
|
1341
1104
|
}
|
|
1342
1105
|
interface Program extends Span {
|
|
1343
1106
|
type: "Program";
|
|
@@ -1345,7 +1108,7 @@ interface Program extends Span {
|
|
|
1345
1108
|
sourceType: ModuleKind;
|
|
1346
1109
|
hashbang: Hashbang | null;
|
|
1347
1110
|
comments: Comment[];
|
|
1348
|
-
tokens:
|
|
1111
|
+
tokens: TokenType[];
|
|
1349
1112
|
parent: null;
|
|
1350
1113
|
}
|
|
1351
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;
|
|
@@ -2633,7 +2396,12 @@ type ModuleKind = "script" | "module" | "commonjs";
|
|
|
2633
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;
|
|
2634
2397
|
//#endregion
|
|
2635
2398
|
//#region src-js/generated/visitor.d.ts
|
|
2636
|
-
|
|
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 {
|
|
2637
2405
|
DebuggerStatement?: (node: DebuggerStatement) => void;
|
|
2638
2406
|
"DebuggerStatement:exit"?: (node: DebuggerStatement) => void;
|
|
2639
2407
|
EmptyStatement?: (node: EmptyStatement) => void;
|
|
@@ -2964,8 +2732,8 @@ interface VisitorObject {
|
|
|
2964
2732
|
"TSTypeReference:exit"?: (node: TSTypeReference) => void;
|
|
2965
2733
|
TSUnionType?: (node: TSUnionType) => void;
|
|
2966
2734
|
"TSUnionType:exit"?: (node: TSUnionType) => void;
|
|
2967
|
-
[key: string]: (node: Node$1) => void;
|
|
2968
2735
|
}
|
|
2736
|
+
type VisitorObject = { [K in keyof StrictVisitorObject]?: BivarianceHackHandler<Exclude<StrictVisitorObject[K], undefined>> | undefined } & Record<string, BivarianceHackHandler<(node: Node$1) => void> | undefined>;
|
|
2969
2737
|
//#endregion
|
|
2970
2738
|
//#region src-js/plugins/types.d.ts
|
|
2971
2739
|
type BeforeHook = () => boolean | void;
|
|
@@ -2975,7 +2743,7 @@ type VisitorWithHooks = VisitorObject & {
|
|
|
2975
2743
|
after?: AfterHook;
|
|
2976
2744
|
};
|
|
2977
2745
|
interface Node extends Span {}
|
|
2978
|
-
type NodeOrToken = Node |
|
|
2746
|
+
type NodeOrToken = Node | TokenType | Comment;
|
|
2979
2747
|
interface Comment extends Span {
|
|
2980
2748
|
type: "Line" | "Block" | "Shebang";
|
|
2981
2749
|
value: string;
|
|
@@ -3298,6 +3066,257 @@ declare function getScope(node: Node$1): Scope;
|
|
|
3298
3066
|
*/
|
|
3299
3067
|
declare function markVariableAsUsed(name: string, refNode: Node$1): boolean;
|
|
3300
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
|
|
3301
3320
|
//#region src-js/plugins/source_code.d.ts
|
|
3302
3321
|
declare const SOURCE_CODE: Readonly<{
|
|
3303
3322
|
/**
|
|
@@ -3342,7 +3361,7 @@ declare const SOURCE_CODE: Readonly<{
|
|
|
3342
3361
|
/**
|
|
3343
3362
|
* Array of all tokens and comments in the file, in source order.
|
|
3344
3363
|
*/
|
|
3345
|
-
readonly tokensAndComments: (
|
|
3364
|
+
readonly tokensAndComments: (TokenType | Comment)[];
|
|
3346
3365
|
/**
|
|
3347
3366
|
* Get the source code for the given node.
|
|
3348
3367
|
* @param node? - The AST node to get the text for.
|
|
@@ -3772,7 +3791,7 @@ interface RuleMeta {
|
|
|
3772
3791
|
* Type of fixes that the rule provides.
|
|
3773
3792
|
* Must be `'code'` or `'whitespace'` if the rule provides fixes.
|
|
3774
3793
|
*/
|
|
3775
|
-
fixable?: "code" | "whitespace";
|
|
3794
|
+
fixable?: "code" | "whitespace" | null | undefined;
|
|
3776
3795
|
/**
|
|
3777
3796
|
* Specifies whether rule can return suggestions.
|
|
3778
3797
|
* Must be `true` if the rule provides suggestions.
|
|
@@ -3963,4 +3982,4 @@ declare function defineRule(rule: Rule): Rule;
|
|
|
3963
3982
|
*/
|
|
3964
3983
|
declare function eslintCompatPlugin(plugin: Plugin): Plugin;
|
|
3965
3984
|
//#endregion
|
|
3966
|
-
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 };
|