11
11
12
12
/** @typedef {import("@eslint/core").VisitTraversalStep } VisitTraversalStep */
13
13
/** @typedef {import("@eslint/core").CallTraversalStep } CallTraversalStep */
14
- /** @typedef {import("@eslint/core").TextSourceCode } TextSourceCode */
15
14
/** @typedef {import("@eslint/core").TraversalStep } TraversalStep */
16
15
/** @typedef {import("@eslint/core").SourceLocation } SourceLocation */
17
16
/** @typedef {import("@eslint/core").SourceLocationWithOffset } SourceLocationWithOffset */
18
17
/** @typedef {import("@eslint/core").SourceRange } SourceRange */
19
18
/** @typedef {import("@eslint/core").Directive } IDirective */
20
19
/** @typedef {import("@eslint/core").DirectiveType } DirectiveType */
20
+ /** @typedef {import("@eslint/core").SourceCodeBaseTypeOptions } SourceCodeBaseTypeOptions */
21
+ /**
22
+ * @typedef {import("@eslint/core").TextSourceCode<Options> } TextSourceCode<Options>
23
+ * @template {SourceCodeBaseTypeOptions} [Options=SourceCodeBaseTypeOptions]
24
+ */
21
25
22
26
//-----------------------------------------------------------------------------
23
27
// Helpers
@@ -212,7 +216,8 @@ export class Directive {
212
216
213
217
/**
214
218
* Source Code Base Object
215
- * @implements {TextSourceCode}
219
+ * @template {SourceCodeBaseTypeOptions & {SyntaxElementWithLoc: object}} [Options=SourceCodeBaseTypeOptions & {SyntaxElementWithLoc: object}]
220
+ * @implements {TextSourceCode<Options>}
216
221
*/
217
222
export class TextSourceCodeBase {
218
223
/**
@@ -223,7 +228,7 @@ export class TextSourceCodeBase {
223
228
224
229
/**
225
230
* The AST of the source code.
226
- * @type {object }
231
+ * @type {Options['RootNode'] }
227
232
*/
228
233
ast ;
229
234
@@ -237,7 +242,7 @@ export class TextSourceCodeBase {
237
242
* Creates a new instance.
238
243
* @param {Object } options The options for the instance.
239
244
* @param {string } options.text The source code text.
240
- * @param {object } options.ast The root AST node.
245
+ * @param {Options['RootNode'] } options.ast The root AST node.
241
246
* @param {RegExp } [options.lineEndingPattern] The pattern to match lineEndings in the source code.
242
247
*/
243
248
constructor ( { text, ast, lineEndingPattern = / \r ? \n / u } ) {
@@ -248,7 +253,7 @@ export class TextSourceCodeBase {
248
253
249
254
/**
250
255
* Returns the loc information for the given node or token.
251
- * @param {object } nodeOrToken The node or token to get the loc information for.
256
+ * @param {Options['SyntaxElementWithLoc'] } nodeOrToken The node or token to get the loc information for.
252
257
* @returns {SourceLocation } The loc information for the node or token.
253
258
*/
254
259
getLoc ( nodeOrToken ) {
@@ -267,7 +272,7 @@ export class TextSourceCodeBase {
267
272
268
273
/**
269
274
* Returns the range information for the given node or token.
270
- * @param {object } nodeOrToken The node or token to get the range information for.
275
+ * @param {Options['SyntaxElementWithLoc'] } nodeOrToken The node or token to get the range information for.
271
276
* @returns {SourceRange } The range information for the node or token.
272
277
*/
273
278
getRange ( nodeOrToken ) {
@@ -290,8 +295,8 @@ export class TextSourceCodeBase {
290
295
/* eslint-disable no-unused-vars -- Required to complete interface. */
291
296
/**
292
297
* Returns the parent of the given node.
293
- * @param {object } node The node to get the parent of.
294
- * @returns {object |undefined } The parent of the node.
298
+ * @param {Options['SyntaxElementWithLoc'] } node The node to get the parent of.
299
+ * @returns {Options['SyntaxElementWithLoc'] |undefined } The parent of the node.
295
300
*/
296
301
getParent ( node ) {
297
302
throw new Error ( "Not implemented." ) ;
@@ -300,8 +305,8 @@ export class TextSourceCodeBase {
300
305
301
306
/**
302
307
* Gets all the ancestors of a given node
303
- * @param {object } node The node
304
- * @returns {Array<object > } All the ancestor nodes in the AST, not including the provided node, starting
308
+ * @param {Options['SyntaxElementWithLoc'] } node The node
309
+ * @returns {Array<Options['SyntaxElementWithLoc'] > } All the ancestor nodes in the AST, not including the provided node, starting
305
310
* from the root node at index 0 and going inwards to the parent node.
306
311
* @throws {TypeError } When `node` is missing.
307
312
*/
@@ -325,7 +330,7 @@ export class TextSourceCodeBase {
325
330
326
331
/**
327
332
* Gets the source code for the given node.
328
- * @param {object } [node] The AST node to get the text for.
333
+ * @param {Options['SyntaxElementWithLoc'] } [node] The AST node to get the text for.
329
334
* @param {number } [beforeCount] The number of characters before the node to retrieve.
330
335
* @param {number } [afterCount] The number of characters after the node to retrieve.
331
336
* @returns {string } The text representing the AST node.
0 commit comments