@biomejs/runtime 0.0.0-stage → 2.6.2
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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/diagnostics.d.ts +3 -0
- package/js_ast.d.ts +4899 -0
- package/package.json +39 -3
- package/plugin.d.ts +318 -0
- package/plugin.js +3 -0
- package/semantic.d.ts +611 -0
- package/README.md +0 -3
package/semantic.d.ts
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyJsAstNode,
|
|
3
|
+
JsIdentifierAssignment,
|
|
4
|
+
JsIdentifierBinding,
|
|
5
|
+
JsReferenceIdentifier,
|
|
6
|
+
JsxReferenceIdentifier,
|
|
7
|
+
TsIdentifierBinding,
|
|
8
|
+
TsLiteralEnumMemberName,
|
|
9
|
+
TsTypeParameterName,
|
|
10
|
+
} from "./js_ast";
|
|
11
|
+
|
|
12
|
+
/** Identifier nodes that refer to a binding or an external name. */
|
|
13
|
+
export type AnyJsIdentifierReference =
|
|
14
|
+
| JsReferenceIdentifier
|
|
15
|
+
| JsIdentifierAssignment
|
|
16
|
+
| JsxReferenceIdentifier;
|
|
17
|
+
|
|
18
|
+
/** Identifier nodes that introduce bindings. */
|
|
19
|
+
export type AnyJsIdentifierBinding =
|
|
20
|
+
| JsIdentifierBinding
|
|
21
|
+
| TsIdentifierBinding
|
|
22
|
+
| TsTypeParameterName
|
|
23
|
+
| TsLiteralEnumMemberName;
|
|
24
|
+
|
|
25
|
+
/** The semantic classification of a binding's declaration. */
|
|
26
|
+
export type JsDeclarationKind =
|
|
27
|
+
/** Class binding, including named class expressions. */
|
|
28
|
+
| "class"
|
|
29
|
+
/** TypeScript enum declaration or member. */
|
|
30
|
+
| "enum"
|
|
31
|
+
/** Function declaration or overload signature. */
|
|
32
|
+
| "function"
|
|
33
|
+
/** Generic type parameter. */
|
|
34
|
+
| "generic"
|
|
35
|
+
/** Hoisted value, such as `var` or a named function expression. */
|
|
36
|
+
| "hoistedValue"
|
|
37
|
+
/** Import binding, including TypeScript `import =`. */
|
|
38
|
+
| "import"
|
|
39
|
+
/** Type-only import binding. */
|
|
40
|
+
| "importType"
|
|
41
|
+
/** TypeScript interface declaration. */
|
|
42
|
+
| "interface"
|
|
43
|
+
/** TypeScript module declaration. */
|
|
44
|
+
| "module"
|
|
45
|
+
/** TypeScript namespace declaration. */
|
|
46
|
+
| "namespace"
|
|
47
|
+
/** Type alias declaration. */
|
|
48
|
+
| "type"
|
|
49
|
+
/** Declaration not classified by the model. */
|
|
50
|
+
| "unknown"
|
|
51
|
+
/** Explicit resource-management binding. */
|
|
52
|
+
| "using"
|
|
53
|
+
/** Value binding, such as `let`, `const`, or a parameter. */
|
|
54
|
+
| "value";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A range in the analyzed source, measured in UTF-8 bytes.
|
|
58
|
+
* The range starts at `start` and stops before `end`.
|
|
59
|
+
* For example, `{ start: 2, end: 5 }` covers bytes 2, 3, and 4; byte 5 is not included.
|
|
60
|
+
*/
|
|
61
|
+
export interface TextRange {
|
|
62
|
+
/** Starting byte offset, included in the range. */
|
|
63
|
+
readonly start: number;
|
|
64
|
+
/** Byte offset immediately after the range. */
|
|
65
|
+
readonly end: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Bindings and references in one analyzed source snapshot.
|
|
70
|
+
* Access it through `context.model` in a rule using `semantic(...)`.
|
|
71
|
+
*
|
|
72
|
+
* Node arguments must belong to this model's source. Saved models and handles
|
|
73
|
+
* retain their original source; prepared code fixes do not update the model.
|
|
74
|
+
* Collection methods return fresh arrays whose contents can be inspected with
|
|
75
|
+
* normal JavaScript iteration and array methods.
|
|
76
|
+
*/
|
|
77
|
+
export interface SemanticModel {
|
|
78
|
+
/**
|
|
79
|
+
* Resolves an identifier use to the binding it refers to, respecting shadowing.
|
|
80
|
+
* Returns `undefined` for configured globals and unresolved references.
|
|
81
|
+
*
|
|
82
|
+
* In a rule querying `semantic("JS_REFERENCE_IDENTIFIER")`, highlight the
|
|
83
|
+
* declaration of the referenced name:
|
|
84
|
+
* ```ts
|
|
85
|
+
* const binding = context.model.binding(node);
|
|
86
|
+
* if (binding) {
|
|
87
|
+
* registerDiagnostic(binding.syntax(), "information", "Declared here.");
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
binding(reference: AnyJsIdentifierReference): Binding | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Looks up the binding introduced by a declaration's identifier node.
|
|
94
|
+
* Returns `undefined` when the model does not track that declaration.
|
|
95
|
+
*
|
|
96
|
+
* In a rule querying `semantic("JS_IDENTIFIER_BINDING")`, report how many
|
|
97
|
+
* references resolve to the declaration:
|
|
98
|
+
* ```ts
|
|
99
|
+
* const binding = context.model.asBinding(node);
|
|
100
|
+
* if (binding) {
|
|
101
|
+
* const count = binding.allReferences().length;
|
|
102
|
+
* registerDiagnostic(node, "information", `${count} references.`);
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
asBinding(node: AnyJsIdentifierBinding): Binding | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Returns all tracked bindings in the source, including nested scopes.
|
|
109
|
+
* Declarations with the same spelling can introduce separate bindings.
|
|
110
|
+
*
|
|
111
|
+
* In a semantic rule querying the root, highlight each declaration:
|
|
112
|
+
* ```ts
|
|
113
|
+
* for (const binding of context.model.allBindings()) {
|
|
114
|
+
* registerDiagnostic(binding.syntax(), "information", "Declaration.");
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
allBindings(): readonly Binding[];
|
|
119
|
+
/**
|
|
120
|
+
* Returns the bindings marked as exported by the model, with each binding
|
|
121
|
+
* appearing once even if it has multiple export sites. Order is unspecified.
|
|
122
|
+
* Re-exports that introduce no local binding are not included.
|
|
123
|
+
*
|
|
124
|
+
* In a semantic rule querying the root, highlight exported declarations:
|
|
125
|
+
* ```ts
|
|
126
|
+
* for (const binding of context.model.allExportedBindings()) {
|
|
127
|
+
* registerDiagnostic(binding.syntax(), "information", "Exported declaration.");
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
allExportedBindings(): readonly Binding[];
|
|
132
|
+
/**
|
|
133
|
+
* Returns whether the model tracks at least one exported binding.
|
|
134
|
+
* This is not a check for export syntax: an empty export, a re-export without
|
|
135
|
+
* a local binding, or an exported literal can leave this value `false`.
|
|
136
|
+
*
|
|
137
|
+
* In a semantic rule querying the root, check for exported bindings:
|
|
138
|
+
* ```ts
|
|
139
|
+
* if (context.model.hasExports()) {
|
|
140
|
+
* registerDiagnostic(node, "information", "This source exports bindings.");
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
hasExports(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Returns all scopes in this source, including the global scope and nested scopes.
|
|
147
|
+
*
|
|
148
|
+
* In a semantic rule querying the root, inspect each scope's declarations:
|
|
149
|
+
* ```ts
|
|
150
|
+
* for (const scope of context.model.scopes()) {
|
|
151
|
+
* for (const binding of scope.bindings()) {
|
|
152
|
+
* registerDiagnostic(binding.syntax(), "information", "Declared in this scope.");
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
scopes(): readonly Scope[];
|
|
158
|
+
/**
|
|
159
|
+
* Returns the outermost scope of this source, including for an empty file.
|
|
160
|
+
* This scope has no parent. It is distinct from the configured global names
|
|
161
|
+
* returned by `allGlobalReferences()`.
|
|
162
|
+
*
|
|
163
|
+
* In a semantic rule, inspect bindings in the outermost scope:
|
|
164
|
+
* ```ts
|
|
165
|
+
* const scope = context.model.globalScope();
|
|
166
|
+
* const names = scope.bindings().map(binding => binding.syntax().text);
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
globalScope(): Scope;
|
|
170
|
+
/**
|
|
171
|
+
* Returns the most specific scope containing the node's trimmed source range.
|
|
172
|
+
* Returns `undefined` for an empty node. Use `globalScope()` to obtain a scope
|
|
173
|
+
* for an empty file.
|
|
174
|
+
*
|
|
175
|
+
* In a semantic rule, inspect the scope surrounding the matched node:
|
|
176
|
+
* ```ts
|
|
177
|
+
* const scope = context.model.scope(node);
|
|
178
|
+
* if (scope) {
|
|
179
|
+
* registerDiagnostic(scope.syntax(), "information", "Containing scope.");
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
scope(node: AnyJsAstNode): Scope | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Returns the scope a declaration's identifier was hoisted to, if the model
|
|
186
|
+
* records one. This can differ from the scope containing its source text.
|
|
187
|
+
*
|
|
188
|
+
* In a rule querying `semantic("JS_IDENTIFIER_BINDING")`, inspect hoisting:
|
|
189
|
+
* ```ts
|
|
190
|
+
* const scope = context.model.scopeHoistedTo(node);
|
|
191
|
+
* if (scope) {
|
|
192
|
+
* registerDiagnostic(scope.syntax(), "information", "Declaration is hoisted here.");
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
scopeHoistedTo(node: AnyJsAstNode): Scope | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Returns references resolved to globals configured in the supplied model.
|
|
199
|
+
* Locally shadowed names resolve to local bindings instead.
|
|
200
|
+
*
|
|
201
|
+
* In a semantic rule querying the root, highlight uses of configured globals:
|
|
202
|
+
* ```ts
|
|
203
|
+
* for (const reference of context.model.allGlobalReferences()) {
|
|
204
|
+
* registerDiagnostic(reference.syntax(), "information", "Uses a global.");
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
allGlobalReferences(): readonly GlobalReference[];
|
|
209
|
+
/**
|
|
210
|
+
* Returns references that resolve to neither a local binding nor a global
|
|
211
|
+
* configured in the supplied model.
|
|
212
|
+
*
|
|
213
|
+
* In a semantic rule querying the root, highlight unresolved names:
|
|
214
|
+
* ```ts
|
|
215
|
+
* for (const reference of context.model.allUnresolvedReferences()) {
|
|
216
|
+
* registerDiagnostic(reference.syntax(), "warning", "Unresolved name.");
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
allUnresolvedReferences(): readonly UnresolvedReference[];
|
|
221
|
+
/**
|
|
222
|
+
* Returns whether an identifier use resolves to a configured global.
|
|
223
|
+
* Returns `false` for local bindings and unresolved references.
|
|
224
|
+
*
|
|
225
|
+
* In a rule querying `semantic("JS_REFERENCE_IDENTIFIER")`, distinguish
|
|
226
|
+
* configured globals from other identifier uses:
|
|
227
|
+
* ```ts
|
|
228
|
+
* if (context.model.isGlobalReference(node)) {
|
|
229
|
+
* registerDiagnostic(node, "information", "Uses a configured global.");
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
isGlobalReference(reference: AnyJsIdentifierReference): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Returns whether an identifier use has no local binding or configured global.
|
|
236
|
+
* A reference to a declaration later in the source can still resolve.
|
|
237
|
+
*
|
|
238
|
+
* In a rule querying `semantic("JS_REFERENCE_IDENTIFIER")`, report names the
|
|
239
|
+
* model cannot resolve:
|
|
240
|
+
* ```ts
|
|
241
|
+
* if (context.model.isUnresolvedReference(node)) {
|
|
242
|
+
* registerDiagnostic(node, "warning", "This name could not be resolved.");
|
|
243
|
+
* }
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
isUnresolvedReference(reference: AnyJsIdentifierReference): boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Returns whether a declaration is imported, or a reference resolves to an
|
|
249
|
+
* imported declaration. Returns `false` when a reference has no local binding.
|
|
250
|
+
*
|
|
251
|
+
* In a rule querying `semantic("JS_REFERENCE_IDENTIFIER")`, highlight uses
|
|
252
|
+
* of imported names:
|
|
253
|
+
* ```ts
|
|
254
|
+
* if (context.model.isImported(node)) {
|
|
255
|
+
* registerDiagnostic(node, "information", "Uses an imported binding.");
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
isImported(node: AnyJsIdentifierBinding | AnyJsIdentifierReference): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Returns whether a declaration is exported, or a reference resolves to an
|
|
262
|
+
* exported declaration. Returns `false` when a reference has no local binding.
|
|
263
|
+
*
|
|
264
|
+
* In a rule querying `semantic("JS_IDENTIFIER_BINDING")`, highlight exported
|
|
265
|
+
* declarations:
|
|
266
|
+
* ```ts
|
|
267
|
+
* if (context.model.isExported(node)) {
|
|
268
|
+
* registerDiagnostic(node, "information", "This binding is exported.");
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
isExported(node: AnyJsIdentifierBinding | AnyJsIdentifierReference): boolean;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* A declaration and the references that resolve to it.
|
|
277
|
+
* The examples use a `binding` obtained from `context.model.binding(...)`
|
|
278
|
+
* or `context.model.asBinding(...)`.
|
|
279
|
+
*/
|
|
280
|
+
export interface Binding {
|
|
281
|
+
/**
|
|
282
|
+
* Returns the model's declaration classification, such as `"function"`,
|
|
283
|
+
* `"importType"`, or `"hoistedValue"`. This describes how the binding was
|
|
284
|
+
* declared, rather than the syntax kind of its identifier node.
|
|
285
|
+
*
|
|
286
|
+
* Highlight hoisted value bindings:
|
|
287
|
+
* ```ts
|
|
288
|
+
* if (binding.declarationKind() === "hoistedValue") {
|
|
289
|
+
* registerDiagnostic(binding.syntax(), "information", "Hoisted value binding.");
|
|
290
|
+
* }
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
declarationKind(): JsDeclarationKind;
|
|
294
|
+
/**
|
|
295
|
+
* Returns the identifier nodes at this binding's tracked export sites.
|
|
296
|
+
* A directly exported declaration yields its identifier binding; an export
|
|
297
|
+
* specifier yields the local identifier reference, not its exported alias.
|
|
298
|
+
* Returns an empty array for a binding with no tracked export sites.
|
|
299
|
+
*
|
|
300
|
+
* Highlight the places that export this binding:
|
|
301
|
+
* ```ts
|
|
302
|
+
* for (const site of binding.exports()) {
|
|
303
|
+
* registerDiagnostic(site, "information", "Exported here.");
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
exports(): readonly (AnyJsIdentifierBinding | AnyJsIdentifierReference)[];
|
|
308
|
+
/**
|
|
309
|
+
* Returns the model's source ranges for this binding's export sites.
|
|
310
|
+
* Offsets count UTF-8 bytes, with an inclusive start and exclusive end;
|
|
311
|
+
* they are not JavaScript string indices. Returns an empty array when no
|
|
312
|
+
* export sites are tracked.
|
|
313
|
+
*
|
|
314
|
+
* Report the recorded byte offsets alongside the declaration:
|
|
315
|
+
* ```ts
|
|
316
|
+
* const locations = binding.exportRanges()
|
|
317
|
+
* .map(range => `${range.start}..${range.end}`)
|
|
318
|
+
* .join(", ");
|
|
319
|
+
* registerDiagnostic(binding.syntax(), "information", `Export byte ranges: ${locations}.`);
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
exportRanges(): readonly TextRange[];
|
|
323
|
+
/**
|
|
324
|
+
* Returns the identifier node introducing this binding, rather than the
|
|
325
|
+
* enclosing declaration statement. The node can be used in diagnostics and fixes.
|
|
326
|
+
*
|
|
327
|
+
* Highlight the declaration's name:
|
|
328
|
+
* ```ts
|
|
329
|
+
* const identifier = binding.syntax();
|
|
330
|
+
* registerDiagnostic(identifier, "information", `Declares ${identifier.text}.`);
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
syntax(): AnyJsIdentifierBinding;
|
|
334
|
+
/**
|
|
335
|
+
* Returns the scope containing the declaration's identifier in the source.
|
|
336
|
+
* For hoisted declarations, use `context.model.scopeHoistedTo(binding.syntax())`
|
|
337
|
+
* to inspect the destination scope instead.
|
|
338
|
+
*
|
|
339
|
+
* Inspect the declaration's surrounding scope:
|
|
340
|
+
* ```ts
|
|
341
|
+
* const scope = binding.scope();
|
|
342
|
+
* registerDiagnostic(scope.syntax(), "information", "Declaration appears here.");
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
scope(): Scope;
|
|
346
|
+
/**
|
|
347
|
+
* Returns all references that resolve to this binding, including reads and writes.
|
|
348
|
+
* References to a different binding with the same spelling are excluded.
|
|
349
|
+
*
|
|
350
|
+
* Highlight every reference to this declaration:
|
|
351
|
+
* ```ts
|
|
352
|
+
* for (const reference of binding.allReferences()) {
|
|
353
|
+
* registerDiagnostic(reference.syntax(), "information", "References this binding.");
|
|
354
|
+
* }
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
allReferences(): readonly Reference[];
|
|
358
|
+
/**
|
|
359
|
+
* Returns references classified as reads by the semantic model.
|
|
360
|
+
*
|
|
361
|
+
* Highlight the places that read this binding:
|
|
362
|
+
* ```ts
|
|
363
|
+
* for (const reference of binding.allReads()) {
|
|
364
|
+
* registerDiagnostic(reference.syntax(), "information", "Reads this binding.");
|
|
365
|
+
* }
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
allReads(): readonly Reference[];
|
|
369
|
+
/**
|
|
370
|
+
* Returns references classified as writes by the semantic model.
|
|
371
|
+
*
|
|
372
|
+
* Highlight the places that write to this binding:
|
|
373
|
+
* ```ts
|
|
374
|
+
* for (const reference of binding.allWrites()) {
|
|
375
|
+
* registerDiagnostic(reference.syntax(), "information", "Writes to this binding.");
|
|
376
|
+
* }
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
allWrites(): readonly Reference[];
|
|
380
|
+
/**
|
|
381
|
+
* Returns whether this binding has an import declaration kind in the model.
|
|
382
|
+
*
|
|
383
|
+
* Highlight an imported declaration:
|
|
384
|
+
* ```ts
|
|
385
|
+
* if (binding.isImported()) {
|
|
386
|
+
* registerDiagnostic(binding.syntax(), "information", "Imported binding.");
|
|
387
|
+
* }
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
isImported(): boolean;
|
|
391
|
+
/**
|
|
392
|
+
* Returns whether this binding is exported from the source.
|
|
393
|
+
*
|
|
394
|
+
* Highlight an exported declaration:
|
|
395
|
+
* ```ts
|
|
396
|
+
* if (binding.isExported()) {
|
|
397
|
+
* registerDiagnostic(binding.syntax(), "information", "Exported binding.");
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
isExported(): boolean;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* A reference resolved to a local binding.
|
|
406
|
+
* The examples use a `reference` obtained from a binding's reference arrays.
|
|
407
|
+
*/
|
|
408
|
+
export interface Reference {
|
|
409
|
+
/**
|
|
410
|
+
* Returns the identifier node at the reference site. The node can be used in
|
|
411
|
+
* diagnostics and fixes.
|
|
412
|
+
*
|
|
413
|
+
* Highlight the identifier use rather than its declaration:
|
|
414
|
+
* ```ts
|
|
415
|
+
* registerDiagnostic(reference.syntax(), "information", "Referenced here.");
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
syntax(): AnyJsIdentifierReference;
|
|
419
|
+
/**
|
|
420
|
+
* Returns the binding this reference resolves to.
|
|
421
|
+
*
|
|
422
|
+
* Follow a reference back to its declaration:
|
|
423
|
+
* ```ts
|
|
424
|
+
* const declaration = reference.binding();
|
|
425
|
+
* if (declaration) {
|
|
426
|
+
* registerDiagnostic(declaration.syntax(), "information", "Declared here.");
|
|
427
|
+
* }
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
binding(): Binding | undefined;
|
|
431
|
+
/**
|
|
432
|
+
* Returns the scope containing this identifier use, which can differ from the
|
|
433
|
+
* scope containing its declaration.
|
|
434
|
+
*
|
|
435
|
+
* Highlight the scope where the reference occurs:
|
|
436
|
+
* ```ts
|
|
437
|
+
* registerDiagnostic(reference.scope().syntax(), "information", "Reference scope.");
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
scope(): Scope;
|
|
441
|
+
/**
|
|
442
|
+
* Returns whether the model classifies this reference as a read.
|
|
443
|
+
*
|
|
444
|
+
* Report only read references while inspecting a binding's references:
|
|
445
|
+
* ```ts
|
|
446
|
+
* if (reference.isRead()) {
|
|
447
|
+
* registerDiagnostic(reference.syntax(), "information", "Read access.");
|
|
448
|
+
* }
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
isRead(): boolean;
|
|
452
|
+
/**
|
|
453
|
+
* Returns whether the model classifies this reference as a write.
|
|
454
|
+
*
|
|
455
|
+
* Report only write references while inspecting a binding's references:
|
|
456
|
+
* ```ts
|
|
457
|
+
* if (reference.isWrite()) {
|
|
458
|
+
* registerDiagnostic(reference.syntax(), "information", "Write access.");
|
|
459
|
+
* }
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
isWrite(): boolean;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* A lexical scope in one source snapshot. Obtain scopes through the semantic
|
|
467
|
+
* model, a binding, or a resolved reference. The examples use a `scope` returned
|
|
468
|
+
* by one of those APIs. Collection methods return fresh arrays.
|
|
469
|
+
*/
|
|
470
|
+
export interface Scope {
|
|
471
|
+
/**
|
|
472
|
+
* Returns the syntax node associated with this scope, such as a module,
|
|
473
|
+
* function, or block. The node can be used in diagnostics and fixes.
|
|
474
|
+
*
|
|
475
|
+
* Highlight the code that defines this scope:
|
|
476
|
+
* ```ts
|
|
477
|
+
* registerDiagnostic(scope.syntax(), "information", "Scope starts here.");
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
syntax(): AnyJsAstNode;
|
|
481
|
+
/**
|
|
482
|
+
* Returns whether this is the source's outermost scope.
|
|
483
|
+
*
|
|
484
|
+
* Inspect nested scopes only:
|
|
485
|
+
* ```ts
|
|
486
|
+
* if (!scope.isGlobalScope()) {
|
|
487
|
+
* registerDiagnostic(scope.syntax(), "information", "Nested scope.");
|
|
488
|
+
* }
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
isGlobalScope(): boolean;
|
|
492
|
+
/**
|
|
493
|
+
* Returns the immediately enclosing scope, or `undefined` for the global scope.
|
|
494
|
+
*
|
|
495
|
+
* Highlight the containing scope:
|
|
496
|
+
* ```ts
|
|
497
|
+
* const parent = scope.parent();
|
|
498
|
+
* if (parent) {
|
|
499
|
+
* registerDiagnostic(parent.syntax(), "information", "Parent scope.");
|
|
500
|
+
* }
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
parent(): Scope | undefined;
|
|
504
|
+
/**
|
|
505
|
+
* Returns this scope's immediate child scopes, without their descendants.
|
|
506
|
+
*
|
|
507
|
+
* Inspect each directly nested scope:
|
|
508
|
+
* ```ts
|
|
509
|
+
* for (const child of scope.children()) {
|
|
510
|
+
* registerDiagnostic(child.syntax(), "information", "Child scope.");
|
|
511
|
+
* }
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
children(): readonly Scope[];
|
|
515
|
+
/**
|
|
516
|
+
* Returns this scope followed by its parents, ending with the global scope.
|
|
517
|
+
* The first entry is the current scope itself.
|
|
518
|
+
*
|
|
519
|
+
* Search outward for the nearest binding named `value`:
|
|
520
|
+
* ```ts
|
|
521
|
+
* for (const ancestor of scope.ancestors()) {
|
|
522
|
+
* const binding = ancestor.getBinding("value");
|
|
523
|
+
* if (binding) {
|
|
524
|
+
* registerDiagnostic(binding.syntax(), "information", "Nearest declaration.");
|
|
525
|
+
* break;
|
|
526
|
+
* }
|
|
527
|
+
* }
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
ancestors(): readonly Scope[];
|
|
531
|
+
/**
|
|
532
|
+
* Returns bindings declared in or hoisted to this scope. Bindings belonging
|
|
533
|
+
* to parent or child scopes are excluded.
|
|
534
|
+
*
|
|
535
|
+
* List this scope's binding names:
|
|
536
|
+
* ```ts
|
|
537
|
+
* const names = scope.bindings().map(binding => binding.syntax().text);
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
bindings(): readonly Binding[];
|
|
541
|
+
/**
|
|
542
|
+
* Looks up a binding in this scope only; parent scopes are not searched.
|
|
543
|
+
* Returns `undefined` when the name is absent. Unicode escapes are decoded.
|
|
544
|
+
* When a TypeScript name has both type and value bindings, the value binding
|
|
545
|
+
* is preferred, falling back to the type binding if no value exists.
|
|
546
|
+
*
|
|
547
|
+
* Inspect a binding declared in this scope:
|
|
548
|
+
* ```ts
|
|
549
|
+
* const binding = scope.getBinding("value");
|
|
550
|
+
* if (binding) {
|
|
551
|
+
* registerDiagnostic(binding.syntax(), "information", "Local declaration.");
|
|
552
|
+
* }
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
getBinding(name: string): Binding | undefined;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* A reference resolved to a global configured in the supplied model.
|
|
560
|
+
* The examples use a `reference` from `context.model.allGlobalReferences()`.
|
|
561
|
+
*/
|
|
562
|
+
export interface GlobalReference {
|
|
563
|
+
/**
|
|
564
|
+
* Returns the identifier node that uses the configured global.
|
|
565
|
+
*
|
|
566
|
+
* Highlight the global's name at its use site:
|
|
567
|
+
* ```ts
|
|
568
|
+
* const identifier = reference.syntax();
|
|
569
|
+
* registerDiagnostic(identifier, "information", `Uses global ${identifier.text}.`);
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
syntax(): AnyJsIdentifierReference;
|
|
573
|
+
/**
|
|
574
|
+
* Returns whether the model classifies this global reference as a read.
|
|
575
|
+
*
|
|
576
|
+
* Highlight reads of configured globals:
|
|
577
|
+
* ```ts
|
|
578
|
+
* if (reference.isRead()) {
|
|
579
|
+
* registerDiagnostic(reference.syntax(), "information", "Reads a global.");
|
|
580
|
+
* }
|
|
581
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
isRead(): boolean;
|
|
584
|
+
/**
|
|
585
|
+
* Returns whether the model classifies this global reference as a write.
|
|
586
|
+
*
|
|
587
|
+
* Report assignments to configured globals:
|
|
588
|
+
* ```ts
|
|
589
|
+
* if (reference.isWrite()) {
|
|
590
|
+
* registerDiagnostic(reference.syntax(), "warning", "Writes to a global.");
|
|
591
|
+
* }
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
isWrite(): boolean;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** A reference without a local binding or configured global. */
|
|
598
|
+
export interface UnresolvedReference {
|
|
599
|
+
/**
|
|
600
|
+
* Returns the identifier node whose name could not be resolved.
|
|
601
|
+
*
|
|
602
|
+
* Highlight each unresolved name in a semantic rule:
|
|
603
|
+
* ```ts
|
|
604
|
+
* for (const reference of context.model.allUnresolvedReferences()) {
|
|
605
|
+
* const identifier = reference.syntax();
|
|
606
|
+
* registerDiagnostic(identifier, "warning", `Cannot resolve ${identifier.text}.`);
|
|
607
|
+
* }
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
syntax(): AnyJsIdentifierReference;
|
|
611
|
+
}
|
package/README.md
DELETED