@murky-web/typebuddy 2.0.0 → 3.0.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.
Files changed (45) hide show
  1. package/README.md +184 -72
  2. package/dist/collections.js +1 -2
  3. package/dist/empty.js +34 -13
  4. package/dist/guards.js +33 -9
  5. package/dist/ids.js +6 -6
  6. package/dist/oxlint.js +7 -7
  7. package/dist/parse.js +39 -15
  8. package/dist/result.js +9 -8
  9. package/dist/rules/async_rule.js +45 -28
  10. package/dist/rules/deliberate_throw.js +5 -6
  11. package/dist/rules/maybe_promise_rule.js +109 -47
  12. package/dist/rules/maybe_rule.js +7 -5
  13. package/dist/rules/nullable_rule.js +7 -5
  14. package/dist/rules/optional_rule.js +8 -4
  15. package/dist/rules/own_subtree.js +1 -2
  16. package/dist/rules/test_file.js +63 -0
  17. package/dist/rules/typebuddy_import.js +242 -35
  18. package/dist/rules/use_server.js +63 -0
  19. package/globals.d.ts +49 -44
  20. package/jsr.json +3 -2
  21. package/oxlint/index.ts +7 -5
  22. package/package.json +92 -91
  23. package/rules/async_rule.ts +87 -67
  24. package/rules/deliberate_throw.ts +11 -11
  25. package/rules/maybe_promise_rule.ts +229 -98
  26. package/rules/maybe_rule.ts +74 -47
  27. package/rules/nullable_rule.ts +78 -50
  28. package/rules/optional_rule.ts +80 -51
  29. package/rules/own_subtree.ts +33 -33
  30. package/rules/test_file.ts +114 -0
  31. package/rules/typebuddy_import.ts +479 -87
  32. package/rules/use_server.ts +117 -0
  33. package/src/empty.ts +57 -19
  34. package/src/guards.ts +96 -30
  35. package/src/ids.ts +10 -4
  36. package/src/index.ts +1 -18
  37. package/src/parse.ts +104 -25
  38. package/src/public_api.ts +22 -0
  39. package/src/result.ts +11 -9
  40. package/src/types/globals.ts +11 -11
  41. package/src/types/index.ts +21 -21
  42. package/src/types/json.ts +48 -11
  43. package/src/types/maybe_promise.ts +17 -12
  44. package/src/types/nullable.ts +2 -2
  45. package/src/types/optional.ts +6 -6
@@ -1,134 +1,526 @@
1
1
  type AstNode = {
2
- type: string;
3
- parent?: AstNode;
4
- [key: string]: unknown;
2
+ type: string;
3
+ parent?: AstNode;
4
+ [key: string]: unknown;
5
5
  };
6
6
 
7
7
  const PACKAGE_NAME = "@murky-web/typebuddy";
8
8
 
9
- function isNode(value: unknown): value is AstNode {
10
- return typeof value === "object" && value !== null && "type" in value;
11
- }
9
+ /**
10
+ * The entries that export `ok` and `err`. The result helpers live in their own
11
+ * entry so a caller that only needs them does not pull the guards along, and a
12
+ * file that imports them from there already has what the fix is about to add.
13
+ */
14
+ const RESULT_HELPER_SOURCES = new Set([PACKAGE_NAME, `${PACKAGE_NAME}/result`]);
15
+ const TYPE_SOURCES = new Set([PACKAGE_NAME]);
12
16
 
13
- function isIdentifierNamed(node: unknown, name: string): boolean {
14
- return isNode(node) && node.type === "Identifier" && node["name"] === name;
17
+ type ImportKind = "type" | "value";
18
+
19
+ /** What a rule needs from `context.getSourceCode()` to plan an import. */
20
+ type ImportSourceCode = {
21
+ getScope(node: unknown): unknown;
22
+ };
23
+
24
+ /**
25
+ * The outcome of looking for a name before a fix uses it:
26
+ *
27
+ * - `present`: the file already imports it from the package, nothing to add.
28
+ * - `global`: no import can be added here (a script file), so a type is written
29
+ * by its global name, as before.
30
+ * - `conflict`: the name is something else at that spot (a catch parameter, a
31
+ * local, another library's import), or it is a value in a place that cannot
32
+ * import. Using it would call or type the wrong thing, so the fix must not be
33
+ * offered.
34
+ * - `insert`: nothing of that name is in scope; add this edit. It is a new import
35
+ * line, or the name appended to an import of the package that is already
36
+ * there.
37
+ */
38
+ type ImportPlan =
39
+ | { readonly kind: "present" }
40
+ | { readonly kind: "global" }
41
+ | { readonly kind: "conflict" }
42
+ | {
43
+ readonly kind: "insert";
44
+ readonly range: [number, number];
45
+ readonly text: string;
46
+ };
47
+
48
+ function isNode(value: unknown): value is AstNode {
49
+ return typeof value === "object" && value !== null && "type" in value;
15
50
  }
16
51
 
17
52
  function isImportDeclaration(node: unknown): node is AstNode {
18
- return isNode(node) && node.type === "ImportDeclaration";
53
+ return isNode(node) && node.type === "ImportDeclaration";
19
54
  }
20
55
 
21
56
  function getStringLiteralValue(node: unknown): string | null {
22
- if (!isNode(node)) {
57
+ if (!isNode(node)) {
58
+ return null;
59
+ }
60
+
61
+ if (
62
+ (node.type === "Literal" || node.type === "StringLiteral") &&
63
+ typeof node["value"] === "string"
64
+ ) {
65
+ return node["value"];
66
+ }
67
+
23
68
  return null;
24
- }
69
+ }
25
70
 
26
- if (
27
- (node.type === "Literal" || node.type === "StringLiteral") &&
28
- typeof node["value"] === "string"
29
- ) {
30
- return node["value"];
31
- }
71
+ function getModuleExportName(node: unknown): string | null {
72
+ if (!isNode(node)) {
73
+ return null;
74
+ }
32
75
 
33
- return null;
76
+ if (node.type === "Identifier" && typeof node["name"] === "string") {
77
+ return node["name"];
78
+ }
79
+
80
+ return getStringLiteralValue(node);
34
81
  }
35
82
 
36
83
  function getProgram(node: unknown): AstNode | null {
37
- if (!isNode(node)) {
38
- return null;
39
- }
84
+ if (!isNode(node)) {
85
+ return null;
86
+ }
40
87
 
41
- let current: AstNode | undefined = node;
42
- while (current?.parent) {
43
- current = current.parent;
44
- }
88
+ let current: AstNode | undefined = node;
89
+ while (current?.parent) {
90
+ current = current.parent;
91
+ }
45
92
 
46
- return current?.type === "Program" ? current : null;
93
+ return current?.type === "Program" ? current : null;
47
94
  }
48
95
 
49
96
  function getProgramBody(program: AstNode): AstNode[] {
50
- if (!Array.isArray(program["body"])) {
97
+ if (!Array.isArray(program["body"])) {
98
+ return [];
99
+ }
100
+
101
+ return program["body"].filter(isNode);
102
+ }
103
+
104
+ /** `"use client"`, `"use cache"`, `"use strict"`: the directive prologue. */
105
+ function isDirective(statement: AstNode): boolean {
106
+ return (
107
+ statement.type === "ExpressionStatement" &&
108
+ typeof statement["directive"] === "string"
109
+ );
110
+ }
111
+
112
+ const MODULE_STATEMENTS = new Set([
113
+ "ExportAllDeclaration",
114
+ "ExportDefaultDeclaration",
115
+ "ExportNamedDeclaration",
116
+ "ImportDeclaration",
117
+ "TSExportAssignment",
118
+ ]);
119
+
120
+ function isModuleStatement(statement: AstNode): boolean {
121
+ if (MODULE_STATEMENTS.has(statement.type)) {
122
+ return true;
123
+ }
124
+
125
+ // `import fs = require("fs")` makes a file a module, `import a = b.c` is
126
+ // only an alias.
127
+ if (statement.type !== "TSImportEqualsDeclaration") {
128
+ return false;
129
+ }
130
+ const reference = statement["moduleReference"];
131
+ return isNode(reference) && reference.type === "TSExternalModuleReference";
132
+ }
133
+
134
+ /**
135
+ * Whether the file is a module. TypeScript decides this by its statements, not
136
+ * by the extension: a file without an `import` or `export` is a script, its
137
+ * top-level names are global, and adding an `import` would turn it into a
138
+ * module and take its globals away (`vite-env.d.ts` with `interface
139
+ * ImportMetaEnv`, `interface Window`, `declare var`).
140
+ */
141
+ function isModule(program: AstNode): boolean {
142
+ return getProgramBody(program).some(isModuleStatement);
143
+ }
144
+
145
+ /**
146
+ * Whether the file the node is in can take an import without changing what it
147
+ * is: it already is a module. A script file cannot, and `ok`/`err` have no
148
+ * global name to fall back on, so a rule that needs them there must not offer a
149
+ * fix.
150
+ *
151
+ * @param {unknown} node - Any node of the file.
152
+ * @returns {boolean} True when an import can be added to the file.
153
+ */
154
+ function canAddImport(node: unknown): boolean {
155
+ const program = getProgram(node);
156
+ return program !== null && isModule(program);
157
+ }
158
+
159
+ type ScopeLike = {
160
+ upper: ScopeLike | null;
161
+ set: Map<string, unknown>;
162
+ };
163
+
164
+ function isScopeLike(value: unknown): value is ScopeLike {
165
+ return (
166
+ typeof value === "object" &&
167
+ value !== null &&
168
+ "set" in value &&
169
+ value.set instanceof Map
170
+ );
171
+ }
172
+
173
+ function getUpperScope(scope: ScopeLike): ScopeLike | null {
174
+ const upper: unknown = scope.upper;
175
+ return isScopeLike(upper) ? upper : null;
176
+ }
177
+
178
+ /** The first binding of `name` visible from `node`, innermost scope first. */
179
+ function findBinding(
180
+ sourceCode: ImportSourceCode,
181
+ node: unknown,
182
+ name: string,
183
+ ): unknown {
184
+ const start: unknown = sourceCode.getScope(node);
185
+ let scope: ScopeLike | null = isScopeLike(start) ? start : null;
186
+
187
+ while (scope) {
188
+ const variable = scope.set.get(name);
189
+ if (variable !== undefined) {
190
+ return variable;
191
+ }
192
+ scope = getUpperScope(scope);
193
+ }
194
+
195
+ return undefined;
196
+ }
197
+
198
+ function getDefinitions(variable: unknown): unknown[] {
199
+ if (
200
+ typeof variable === "object" &&
201
+ variable !== null &&
202
+ "defs" in variable &&
203
+ Array.isArray(variable.defs)
204
+ ) {
205
+ return variable.defs;
206
+ }
207
+
51
208
  return [];
52
- }
209
+ }
53
210
 
54
- return program["body"].filter(isNode);
211
+ function sourcesFor(kind: ImportKind): ReadonlySet<string> {
212
+ return kind === "value" ? RESULT_HELPER_SOURCES : TYPE_SOURCES;
55
213
  }
56
214
 
57
- function importsHelper(program: AstNode, helperName: string): boolean {
58
- return getProgramBody(program).some((statement) => {
59
- if (!isImportDeclaration(statement)) {
60
- return false;
215
+ /**
216
+ * Whether one definition is `import { name } from "<package>"`, imported under
217
+ * its own name. A renamed import (`import { ok as okay }`), a default import
218
+ * and an import from another module are different bindings that happen to share
219
+ * the name. For a value, a type-only import does not count either: it has no
220
+ * runtime binding to call.
221
+ */
222
+ function isPackageImport(
223
+ definition: unknown,
224
+ name: string,
225
+ kind: ImportKind,
226
+ ): boolean {
227
+ if (
228
+ typeof definition !== "object" ||
229
+ definition === null ||
230
+ !("type" in definition) ||
231
+ definition.type !== "ImportBinding" ||
232
+ !("node" in definition) ||
233
+ !("parent" in definition)
234
+ ) {
235
+ return false;
61
236
  }
62
237
 
63
- if (getStringLiteralValue(statement["source"]) !== PACKAGE_NAME) {
64
- return false;
238
+ const specifier = definition.node;
239
+ const declaration = definition.parent;
240
+ if (
241
+ !isNode(specifier) ||
242
+ specifier.type !== "ImportSpecifier" ||
243
+ !isImportDeclaration(declaration)
244
+ ) {
245
+ return false;
65
246
  }
66
247
 
67
- // A type-only import brings no runtime binding, so it does not satisfy a
68
- // fix that is about to call the helper.
69
- if (statement["importKind"] === "type") {
70
- return false;
248
+ const source = getStringLiteralValue(declaration["source"]);
249
+ if (source === null || !sourcesFor(kind).has(source)) {
250
+ return false;
251
+ }
252
+ if (getModuleExportName(specifier["imported"]) !== name) {
253
+ return false;
254
+ }
255
+ if (kind === "value") {
256
+ return (
257
+ declaration["importKind"] !== "type" &&
258
+ specifier["importKind"] !== "type"
259
+ );
71
260
  }
72
261
 
73
- const specifiers = Array.isArray(statement["specifiers"])
74
- ? statement["specifiers"]
75
- : [];
262
+ return true;
263
+ }
76
264
 
77
- return specifiers.some((specifier) => {
78
- return (
79
- isNode(specifier) &&
80
- specifier.type === "ImportSpecifier" &&
81
- isIdentifierNamed(specifier["local"], helperName)
82
- );
83
- });
84
- });
265
+ function getSpecifiers(declaration: AstNode): AstNode[] {
266
+ return Array.isArray(declaration["specifiers"])
267
+ ? declaration["specifiers"].filter(isNode)
268
+ : [];
85
269
  }
86
270
 
271
+ type MergeTarget = {
272
+ /** Where the new specifier goes: right after the last named one. */
273
+ readonly at: number;
274
+ /**
275
+ * The specifier needs its own `type` modifier (a type joining a value
276
+ * import).
277
+ */
278
+ readonly inlineType: boolean;
279
+ };
280
+
87
281
  /**
88
- * Where and what to insert so `helperName` is imported from the package.
282
+ * The import of the package that the name can join, or `null` when there is
283
+ * none. A value joins `import { … }`. A type joins `import type { … }`, or else
284
+ * an `import { … }` of the package as `type Name` (an inline type specifier),
285
+ * so the file does not end up with two imports from one module. An import with
286
+ * a namespace specifier, or with no named specifier, is left alone.
287
+ */
288
+ function findMergeTarget(
289
+ imports: readonly AstNode[],
290
+ kind: ImportKind,
291
+ ): MergeTarget | null {
292
+ const sources = sourcesFor(kind);
293
+ let inlineTarget: MergeTarget | null = null;
294
+
295
+ for (const declaration of imports) {
296
+ const source = getStringLiteralValue(declaration["source"]);
297
+ const isTypeImport = declaration["importKind"] === "type";
298
+ if (source === null || !sources.has(source)) {
299
+ continue;
300
+ }
301
+ if (kind === "value" && isTypeImport) {
302
+ continue;
303
+ }
304
+
305
+ const specifiers = getSpecifiers(declaration);
306
+ if (
307
+ specifiers.some((specifier) => {
308
+ return specifier.type === "ImportNamespaceSpecifier";
309
+ })
310
+ ) {
311
+ continue;
312
+ }
313
+
314
+ const named = specifiers.filter((specifier) => {
315
+ return specifier.type === "ImportSpecifier";
316
+ });
317
+ const range = named.at(-1)?.["range"];
318
+ if (!Array.isArray(range) || typeof range[1] !== "number") {
319
+ continue;
320
+ }
321
+
322
+ if (kind === "value" || isTypeImport) {
323
+ return { at: range[1], inlineType: false };
324
+ }
325
+
326
+ inlineTarget ??= { at: range[1], inlineType: true };
327
+ }
328
+
329
+ return inlineTarget;
330
+ }
331
+
332
+ /**
333
+ * Where and what to insert so `name` is imported from the package, and whether
334
+ * it has to be at all.
89
335
  *
90
- * Both async rules add `ok`/`err` imports, and both used to carry their own
91
- * copy of this — including the same bug. Whether the import lands after an
92
- * existing one was inferred from the anchor's offset (`range[0] !== 0`), which
93
- * is only the same question in a file whose first statement starts at byte
94
- * zero. A leading comment moved the first statement off zero, the wrong branch
95
- * won, and the fix emitted a leading newline instead of a trailing one:
336
+ * The answer comes from the scope at the place the fix is about to use the
337
+ * name, not from the list of imports. A catch parameter called `err`, a local
338
+ * called `ok`, or an unrelated library's `Maybe` all make a name mean something
339
+ * else there, and adding an import for it would not change that.
96
340
  *
97
- * import { err } from "@murky-web/typebuddy";export async function load()
341
+ * Where the import goes: appended to an existing import of the same kind from
342
+ * the package; otherwise a new line after the last import; with no import,
343
+ * after the directive prologue (`"use client"` has to stay the first statement
344
+ * of the file or it stops being a directive); with neither, before the first
345
+ * statement.
98
346
  *
99
- * The list of imports answers it directly, so that is what decides now.
347
+ * A script file (no `import` or `export`) gets no import: that would turn it
348
+ * into a module and take its globals away. A type is then written by its global
349
+ * name, as it was before this rule added imports; a value, which has no global
350
+ * name, gets no fix. Inside a module, `declare global` and `declare module`
351
+ * blocks get the import like any other code: the file is a module already, and
352
+ * the global name would break a project that does not load the globals entry.
100
353
  *
101
- * @param {unknown} node - Any node in the file; the program is found from it.
102
- * @param {string} helperName - The named export to import, e.g. `"err"`.
103
- * @returns {{ range: [number, number]; text: string } | null} The zero-width
104
- * insertion to apply, or null when the helper is already imported or no
105
- * anchor carries a usable range.
354
+ * @param {ImportSourceCode} sourceCode - Source code of the file, for scopes.
355
+ * @param {unknown} node - The node the fix uses `name` at.
356
+ * @param {string} name - The named export to import, e.g. `"err"`.
357
+ * @param {ImportKind} kind - `"value"` for a helper that is called, `"type"`
358
+ * for a type that is only named.
359
+ * @returns {ImportPlan} Whether to insert, with the zero-width insertion to
360
+ * apply.
106
361
  */
107
- function getTypeBuddyImportInsertion(
108
- node: unknown,
109
- helperName: string,
110
- ): { range: [number, number]; text: string } | null {
111
- const program = getProgram(node);
112
- if (!program || importsHelper(program, helperName)) {
113
- return null;
114
- }
362
+ function planTypeBuddyImport(
363
+ sourceCode: ImportSourceCode,
364
+ node: unknown,
365
+ name: string,
366
+ kind: ImportKind,
367
+ ): ImportPlan {
368
+ const program = getProgram(node);
369
+ if (!program || !isNode(node)) {
370
+ return { kind: "conflict" };
371
+ }
115
372
 
116
- const body = getProgramBody(program);
117
- const imports = body.filter(isImportDeclaration);
118
- const anchor = imports.at(-1) ?? body[0] ?? program;
119
- const range = anchor["range"];
120
- if (!Array.isArray(range) || range.length < 2) {
121
- return null;
122
- }
373
+ const binding = findBinding(sourceCode, node, name);
374
+ if (binding !== undefined) {
375
+ const definitions = getDefinitions(binding);
376
+ const isOurs =
377
+ definitions.length > 0 &&
378
+ definitions.every((definition) => {
379
+ return isPackageImport(definition, name, kind);
380
+ });
381
+
382
+ return { kind: isOurs ? "present" : "conflict" };
383
+ }
384
+
385
+ if (!isModule(program)) {
386
+ return { kind: kind === "type" ? "global" : "conflict" };
387
+ }
388
+
389
+ const body = getProgramBody(program);
390
+ const imports = body.filter(isImportDeclaration);
391
+
392
+ const merge = findMergeTarget(imports, kind);
393
+ if (merge !== null) {
394
+ return {
395
+ kind: "insert",
396
+ range: [merge.at, merge.at],
397
+ text: `, ${merge.inlineType ? "type " : ""}${name}`,
398
+ };
399
+ }
123
400
 
124
- const statement = `import { ${helperName} } from "${PACKAGE_NAME}";`;
125
- if (imports.length > 0) {
126
- const end: number = range[1];
127
- return { range: [end, end], text: `\n${statement}` };
128
- }
401
+ const statement =
402
+ kind === "type"
403
+ ? `import type { ${name} } from "${PACKAGE_NAME}";`
404
+ : `import { ${name} } from "${PACKAGE_NAME}";`;
129
405
 
130
- const start: number = range[0];
131
- return { range: [start, start], text: `${statement}\n` };
406
+ const lastImport = imports.at(-1);
407
+ if (lastImport) {
408
+ const range = lastImport["range"];
409
+ if (!Array.isArray(range) || range.length < 2) {
410
+ return { kind: "conflict" };
411
+ }
412
+ const end: number = range[1];
413
+ return { kind: "insert", range: [end, end], text: `\n${statement}` };
414
+ }
415
+
416
+ const lastDirective = body.filter(isDirective).at(-1);
417
+ if (lastDirective) {
418
+ const range = lastDirective["range"];
419
+ if (!Array.isArray(range) || range.length < 2) {
420
+ return { kind: "conflict" };
421
+ }
422
+ const end: number = range[1];
423
+ return { kind: "insert", range: [end, end], text: `\n${statement}` };
424
+ }
425
+
426
+ const anchor = body[0] ?? program;
427
+ const range = anchor["range"];
428
+ if (!Array.isArray(range) || range.length < 2) {
429
+ return { kind: "conflict" };
430
+ }
431
+
432
+ const start: number = range[0];
433
+ return { kind: "insert", range: [start, start], text: `${statement}\n` };
434
+ }
435
+
436
+ /**
437
+ * Where the first non-directive statement of a body starts, for a fix that
438
+ * wraps the body. `"use cache"` and `"use server"` only count as directives at
439
+ * the very top of the body; wrapping them in a `try` turns them into expression
440
+ * statements that do nothing.
441
+ *
442
+ * @param {unknown} body - A block statement.
443
+ * @returns {number | null} The offset right after the directive prologue, or
444
+ * the offset right after the opening brace when there is none; null when the
445
+ * range is unusable.
446
+ */
447
+ function getBodyStartAfterDirectives(body: unknown): number | null {
448
+ if (!isNode(body) || !Array.isArray(body["range"])) {
449
+ return null;
450
+ }
451
+
452
+ const range: unknown[] = body["range"];
453
+ const opening = range[0];
454
+ if (typeof opening !== "number") {
455
+ return null;
456
+ }
457
+
458
+ const statements = Array.isArray(body["body"])
459
+ ? body["body"].filter(isNode)
460
+ : [];
461
+ const lastDirective = statements.filter(isDirective).at(-1);
462
+ if (lastDirective) {
463
+ const directiveRange: unknown = lastDirective["range"];
464
+ if (
465
+ Array.isArray(directiveRange) &&
466
+ typeof directiveRange[1] === "number"
467
+ ) {
468
+ return directiveRange[1];
469
+ }
470
+ return null;
471
+ }
472
+
473
+ return opening + 1;
474
+ }
475
+
476
+ type ImportFixer = {
477
+ insertTextBeforeRange(range: [number, number], text: string): unknown;
478
+ };
479
+
480
+ /**
481
+ * Turns import plans into the fixes a rule returns, for one file.
482
+ *
483
+ * `fixes` returns `null` when the name is something else at that spot (or a
484
+ * value cannot be imported there), and a rule then offers no fix at all: a fix
485
+ * that calls the caught `err` or a different library's `Maybe` is worse than
486
+ * none.
487
+ *
488
+ * Every fix that needs an import carries it itself. oxlint applies a fix as a
489
+ * whole or not at all, and drops a fix that overlaps one it applied earlier in
490
+ * the same pass; an import attached to only the first fix of a file would be
491
+ * lost with that fix while the later fixes, which no longer overlap, applied
492
+ * without it. The price is that fixes needing the same import share one
493
+ * insertion point, so one `--fix` pass applies one of them; the next pass finds
494
+ * the import present and applies the rest.
495
+ *
496
+ * @param {ImportSourceCode} sourceCode - Source code of the file, for scopes.
497
+ * @returns {{ fixes: Function }} The planner.
498
+ */
499
+ function createImportPlanner(sourceCode: ImportSourceCode) {
500
+ return {
501
+ fixes(
502
+ node: unknown,
503
+ fixer: ImportFixer,
504
+ name: string,
505
+ kind: ImportKind,
506
+ ): unknown[] | null {
507
+ const plan = planTypeBuddyImport(sourceCode, node, name, kind);
508
+ if (plan.kind === "conflict") {
509
+ return null;
510
+ }
511
+ if (plan.kind === "insert") {
512
+ return [fixer.insertTextBeforeRange(plan.range, plan.text)];
513
+ }
514
+
515
+ return [];
516
+ },
517
+ };
132
518
  }
133
519
 
134
- export { getTypeBuddyImportInsertion };
520
+ export {
521
+ canAddImport,
522
+ createImportPlanner,
523
+ getBodyStartAfterDirectives,
524
+ planTypeBuddyImport,
525
+ };
526
+ export type { ImportFixer, ImportKind, ImportPlan, ImportSourceCode };