@ryuugg/stanza 0.3.3 → 0.4.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 (59) hide show
  1. package/README.md +7 -5
  2. package/package.json +19 -11
  3. package/src/launcher +102 -8
  4. package/src/cli.ts +0 -684
  5. package/src/compile/darwin-arm64.ts +0 -3
  6. package/src/compile/darwin-x64.ts +0 -3
  7. package/src/compile/linux-arm64-musl.ts +0 -3
  8. package/src/compile/linux-arm64.ts +0 -3
  9. package/src/compile/linux-x64-musl.ts +0 -3
  10. package/src/compile/linux-x64.ts +0 -3
  11. package/src/compiled.ts +0 -9
  12. package/src/depth.ts +0 -372
  13. package/src/directories.ts +0 -77
  14. package/src/engine/attach.ts +0 -62
  15. package/src/engine/directives.ts +0 -157
  16. package/src/engine/doc.ts +0 -93
  17. package/src/engine/edits.ts +0 -79
  18. package/src/engine/explain.ts +0 -337
  19. package/src/engine/gaps.ts +0 -361
  20. package/src/engine/hunks.ts +0 -319
  21. package/src/engine/index.ts +0 -273
  22. package/src/engine/model.ts +0 -103
  23. package/src/engine/rules.ts +0 -104
  24. package/src/engine/types.ts +0 -38
  25. package/src/files.ts +0 -1186
  26. package/src/format.ts +0 -159
  27. package/src/gitignore.ts +0 -280
  28. package/src/hook.ts +0 -380
  29. package/src/languages/index.ts +0 -34
  30. package/src/languages/javascript/ast.ts +0 -261
  31. package/src/languages/javascript/braces.ts +0 -374
  32. package/src/languages/javascript/config/biome.ts +0 -112
  33. package/src/languages/javascript/config/eslint.ts +0 -128
  34. package/src/languages/javascript/config/evaluate.ts +0 -278
  35. package/src/languages/javascript/config/find.ts +0 -105
  36. package/src/languages/javascript/config/glob.ts +0 -149
  37. package/src/languages/javascript/config/index.ts +0 -48
  38. package/src/languages/javascript/config/layers.ts +0 -468
  39. package/src/languages/javascript/config/module.ts +0 -327
  40. package/src/languages/javascript/config/oxlint.ts +0 -170
  41. package/src/languages/javascript/config/width.ts +0 -723
  42. package/src/languages/javascript/deserializers.ts +0 -17
  43. package/src/languages/javascript/embedded.ts +0 -7
  44. package/src/languages/javascript/entry.ts +0 -42
  45. package/src/languages/javascript/facts.ts +0 -294
  46. package/src/languages/javascript/index.ts +0 -20
  47. package/src/languages/javascript/lists.ts +0 -64
  48. package/src/languages/javascript/oracle.ts +0 -191
  49. package/src/languages/javascript/oxc-raw.d.ts +0 -31
  50. package/src/languages/javascript/parse.ts +0 -131
  51. package/src/languages/javascript/raw.ts +0 -95
  52. package/src/languages/javascript/scan.ts +0 -68
  53. package/src/languages/language.ts +0 -109
  54. package/src/native-file.d.ts +0 -4
  55. package/src/pool.ts +0 -473
  56. package/src/start.ts +0 -49
  57. package/src/step.ts +0 -113
  58. package/src/usage.ts +0 -35
  59. package/src/worker.ts +0 -5
@@ -1,17 +0,0 @@
1
- import { dirname, join } from "node:path";
2
-
3
- export interface DeserializerFiles {
4
- js: string;
5
- ts: string;
6
- }
7
-
8
- let embedded: DeserializerFiles | undefined;
9
- export function embedDeserializers(files: DeserializerFiles): void {
10
- embedded = files;
11
- }
12
-
13
- export function deserializerFiles(): DeserializerFiles {
14
- if (embedded) return embedded;
15
- const generated = join(dirname(require.resolve("oxc-parser")), "generated", "deserialize");
16
- return { js: join(generated, "js.js"), ts: join(generated, "ts.js") };
17
- }
@@ -1,7 +0,0 @@
1
- import js from "oxc-parser/src-js/generated/deserialize/js.js" with { type: "file" };
2
- import ts from "oxc-parser/src-js/generated/deserialize/ts.js" with { type: "file" };
3
- import { embedDeserializers } from "./deserializers.ts";
4
-
5
- export function embedCompiledDeserializers(): void {
6
- embedDeserializers({ js, ts });
7
- }
@@ -1,42 +0,0 @@
1
- import type { Entry } from "../language.ts";
2
-
3
- const extensions = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
4
- const generatedSuffixes = [
5
- ...extensions.map((extension) => `.gen${extension}`),
6
- ...extensions
7
- .filter((extension) => extension.endsWith("js"))
8
- .map((extension) => `.min${extension}`),
9
- ];
10
-
11
- const directories = new Set([
12
- "node_modules",
13
- "dist",
14
- "build",
15
- ".git",
16
- ".next",
17
- "out",
18
- "coverage",
19
- "migrations",
20
- "drizzle",
21
- ]);
22
-
23
- function generatedName(name: string): boolean {
24
- return name.includes(".generated.") || generatedSuffixes.some((suffix) => name.endsWith(suffix));
25
- }
26
-
27
- function skipsName(name: string, keepGenerated: boolean): boolean {
28
- return (
29
- name.endsWith(".d.ts") ||
30
- name.endsWith(".d.mts") ||
31
- name.endsWith(".d.cts") ||
32
- (!keepGenerated && generatedName(name))
33
- );
34
- }
35
-
36
- export const entry: Entry = {
37
- id: "javascript",
38
- extensions,
39
- directories,
40
- skipsName,
41
- load: () => (require("./index.ts") as typeof import("./index.ts")).language,
42
- };
@@ -1,294 +0,0 @@
1
- import type { Node, Statement, SwitchCase } from "oxc-parser";
2
- import { boundNames, children, declared, jsxElementPath, references } from "./ast.ts";
3
- import { lineAt, source } from "../../engine/doc.ts";
4
- import type { Binding, Doc, Item, Kind, Path } from "../../engine/model.ts";
5
- import type { Layout } from "../language.ts";
6
-
7
- const KINDS: Record<string, Kind> = {
8
- VariableDeclaration: "declaration",
9
- IfStatement: "if",
10
- ForStatement: "loop",
11
- ForInStatement: "loop",
12
- ForOfStatement: "loop",
13
- WhileStatement: "loop",
14
- DoWhileStatement: "loop",
15
- SwitchStatement: "switch",
16
- SwitchCase: "case",
17
- TryStatement: "try",
18
- FunctionDeclaration: "function",
19
- ReturnStatement: "return",
20
- ThrowStatement: "throw",
21
- BreakStatement: "break",
22
- ContinueStatement: "continue",
23
- };
24
-
25
- const WORDS: Record<string, string> = {
26
- IfStatement: "if",
27
- ReturnStatement: "return",
28
- SwitchStatement: "switch",
29
- ForStatement: "for",
30
- ForInStatement: "for",
31
- ForOfStatement: "for",
32
- WhileStatement: "while",
33
- DoWhileStatement: "do",
34
- TryStatement: "try",
35
- FunctionDeclaration: "function",
36
- };
37
-
38
- const JUMPS: Record<string, string> = {
39
- ReturnStatement: "return",
40
- ThrowStatement: "throw",
41
- ContinueStatement: "continue",
42
- BreakStatement: "break",
43
- };
44
-
45
- function exported(node: Statement | SwitchCase): Statement | SwitchCase {
46
- if (node.type === "ExportNamedDeclaration" && node.declaration) return node.declaration;
47
- if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "FunctionDeclaration")
48
- return node.declaration;
49
-
50
- return node;
51
- }
52
-
53
- function kindOf(node: Statement | SwitchCase): Kind {
54
- if (
55
- node.type === "ImportDeclaration" ||
56
- node.type === "ExportAllDeclaration" ||
57
- (node.type === "ExportNamedDeclaration" && node.source)
58
- )
59
- return "import";
60
-
61
- if (node.type === "ExpressionStatement")
62
- return node.expression.type === "AssignmentExpression" ? "assignment" : "expression";
63
-
64
- return KINDS[node.type] ?? "other";
65
- }
66
-
67
- function unwrapPath(node: Node): Node {
68
- let current = node;
69
- while (
70
- current.type === "ChainExpression" ||
71
- current.type === "TSNonNullExpression" ||
72
- current.type === "TSAsExpression" ||
73
- current.type === "TSSatisfiesExpression" ||
74
- current.type === "TSTypeAssertion" ||
75
- current.type === "ParenthesizedExpression"
76
- )
77
- current = current.expression;
78
-
79
- return current;
80
- }
81
-
82
- type Member = Node & { type: "MemberExpression" };
83
-
84
- function spine(outer: Member): { members: Member[]; base: Node } {
85
- const members = [outer];
86
-
87
- let base = unwrapPath(outer.object);
88
- while (base.type === "MemberExpression") {
89
- members.push(base);
90
- base = unwrapPath(base.object);
91
- }
92
-
93
- return { members, base };
94
- }
95
-
96
- function memberSegment(doc: Doc, member: Member): string {
97
- const { computed, property } = member;
98
- if (computed) return `[${source(doc, property)}]`;
99
- if (property.type === "PrivateIdentifier") return `#${property.name}`;
100
- return property.name;
101
- }
102
-
103
- function headName(base: Node): string | undefined {
104
- if (base.type === "Identifier") return base.name;
105
- if (base.type === "ThisExpression") return "this";
106
- if (base.type === "Super") return "super";
107
- return undefined;
108
- }
109
-
110
- function memberPath(doc: Doc, outer: Member): Path | undefined {
111
- const { members, base } = spine(outer);
112
- const head = headName(base);
113
- if (head === undefined) return undefined;
114
-
115
- return [head, ...members.map((member) => memberSegment(doc, member)).reverse()];
116
- }
117
-
118
- function spineReads(doc: Doc, members: Member[], base: Node, path: Path): boolean {
119
- const first = members.length - (path.length - 1);
120
- if (first < 0 || headName(base) !== path[0]) return false;
121
-
122
- return members
123
- .slice(first)
124
- .every((member, index) => memberSegment(doc, member) === path[path.length - 1 - index]);
125
- }
126
-
127
- function readsPath(doc: Doc, root: Node, path: Path): boolean {
128
- const stack = [root];
129
- while (stack.length > 0) {
130
- const node = stack.pop()!;
131
- if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") continue;
132
- if (node.type === "FunctionDeclaration" && node !== root) continue;
133
- if (path[0] !== "this" && path[0] !== "super" && declared(node).includes(path[0])) {
134
- if (node.type === "SwitchStatement") stack.push(node.discriminant);
135
- continue;
136
- }
137
-
138
- if (node.type === "JSXOpeningElement") {
139
- const elementPath = jsxElementPath(node.name);
140
- if (
141
- elementPath &&
142
- elementPath.length >= path.length &&
143
- path.every((segment, index) => elementPath[index] === segment)
144
- )
145
- return true;
146
- }
147
-
148
- if (node.type !== "MemberExpression") {
149
- for (const [, child] of children(node).toReversed()) stack.push(child);
150
- continue;
151
- }
152
-
153
- const { members, base } = spine(node);
154
- if (spineReads(doc, members, base, path)) return true;
155
-
156
- stack.push(base);
157
- for (const member of members) if (member.computed) stack.push(member.property);
158
- }
159
-
160
- return false;
161
- }
162
-
163
- function guardOf(node: Statement | SwitchCase): { jump: string | null } | null {
164
- if (node.type !== "IfStatement" || node.alternate) return null;
165
-
166
- const { consequent } = node;
167
- if (consequent.type !== "BlockStatement") return { jump: JUMPS[consequent.type] ?? null };
168
- if (consequent.body.length !== 1) return null;
169
-
170
- return { jump: JUMPS[consequent.body[0]!.type] ?? null };
171
- }
172
-
173
- function bindsOf(doc: Doc, node: Statement | SwitchCase): Binding | null {
174
- if (node.type === "VariableDeclaration") return boundNames(node);
175
- if (node.type !== "ExpressionStatement" || node.expression.type !== "AssignmentExpression")
176
- return null;
177
-
178
- const target = node.expression.left;
179
- const member = unwrapPath(target);
180
- return member.type === "MemberExpression"
181
- ? (memberPath(doc, member) ?? null)
182
- : boundNames(target);
183
- }
184
-
185
- function joinedText(doc: Doc, node: Node): string | null {
186
- if (lineAt(doc, node.start) === lineAt(doc, node.end - 1)) return source(doc, node).trim();
187
-
188
- const body =
189
- node.type === "IfStatement" && !node.alternate
190
- ? node.consequent
191
- : node.type === "ForStatement" ||
192
- node.type === "ForInStatement" ||
193
- node.type === "ForOfStatement" ||
194
- node.type === "WhileStatement"
195
- ? node.body
196
- : null;
197
-
198
- if (!body || body.type === "BlockStatement") return null;
199
-
200
- const header = doc.text.slice(node.start, body.start);
201
- const lines = header.split(/\r?\n/);
202
- if (lines.length > 2 || (lines.length === 2 && lines[1]!.trim() !== "")) return null;
203
-
204
- let before = body.start;
205
- while (before > node.start && /\s/.test(doc.text[before - 1]!)) before--;
206
-
207
- if (doc.comments.some((comment) => comment.end === before && comment.start >= node.start))
208
- return null;
209
-
210
- const joined = joinedText(doc, body);
211
- return joined === null
212
- ? null
213
- : `${lines[0]!.trimEnd()}${body.type === "EmptyStatement" ? "" : " "}${joined}`;
214
- }
215
-
216
- function joinedColumns(doc: Doc, node: Node, width: Layout): number | null {
217
- if (lineAt(doc, node.start) === lineAt(doc, node.end - 1)) return null;
218
-
219
- const joined = joinedText(doc, node);
220
- if (joined === null) return null;
221
-
222
- const lineStart = doc.lineStarts[lineAt(doc, node.start) - 1]!;
223
- const prefix = doc.text.slice(lineStart, node.start);
224
-
225
- let columns = 0;
226
- for (const char of prefix + joined)
227
- columns += char === "\t" ? width.tab - (columns % width.tab) : Bun.stringWidth(char);
228
-
229
- return columns;
230
- }
231
-
232
- function operation(doc: Doc, node: Node): string | null {
233
- if (node.type !== "ExpressionStatement") return null;
234
-
235
- const expression = node.expression;
236
- if (expression.type === "CallExpression") return `call:${source(doc, expression.callee)}`;
237
- if (expression.type === "AssignmentExpression") return `assign:${source(doc, expression.left)}`;
238
-
239
- return null;
240
- }
241
-
242
- function repeatsOperation(doc: Doc, root: Node, expected: string): boolean {
243
- const stack = [root];
244
- while (stack.length > 0) {
245
- const node = stack.pop()!;
246
- if (
247
- node.type === "FunctionExpression" ||
248
- node.type === "ArrowFunctionExpression" ||
249
- node.type === "FunctionDeclaration"
250
- )
251
- continue;
252
-
253
- if (node.type === "ExpressionStatement") {
254
- if (operation(doc, node) === expected) return true;
255
- continue;
256
- }
257
-
258
- for (const [, child] of children(node).toReversed()) stack.push(child);
259
- }
260
-
261
- return false;
262
- }
263
-
264
- export function facts(
265
- doc: Doc,
266
- node: Statement | SwitchCase,
267
- width: Layout,
268
- ): Item<Statement | SwitchCase> {
269
- const inner = exported(node);
270
- const finalizer = node.type === "TryStatement" ? node.finalizer : null;
271
- const joined = joinedColumns(doc, node, width);
272
- return {
273
- node,
274
- start: node.start,
275
- end: node.end,
276
- kind: kindOf(inner),
277
- word: WORDS[inner.type] ?? null,
278
- binds: bindsOf(doc, inner),
279
- declaration:
280
- inner.type === "VariableDeclaration"
281
- ? { keyword: inner.kind, letLike: inner.kind === "let" }
282
- : null,
283
- guard: guardOf(node),
284
- compact:
285
- lineAt(doc, node.start) === lineAt(doc, node.end - 1) ||
286
- (joined !== null && joined <= width.columns),
287
- joined,
288
- caseBody: node.type === "SwitchCase" && node.consequent.length > 0,
289
- operation: operation(doc, node),
290
- references: (names) => references(inner, names),
291
- readsPath: (path) => readsPath(doc, inner, path),
292
- finallyRepeats: (expected) => finalizer !== null && repeatsOperation(doc, finalizer, expected),
293
- };
294
- }
@@ -1,20 +0,0 @@
1
- import type { Language } from "../language.ts";
2
- import { braceDecisions, bracesSetting } from "./config/index.ts";
3
- import { formatterWidth } from "./config/width.ts";
4
- import { parse, rejection } from "./parse.ts";
5
- import { scan } from "./scan.ts";
6
-
7
- export const language: Language = {
8
- parse(path, text) {
9
- const parsed = parse(path, text);
10
- const error = parsed.errors[0];
11
- return {
12
- comments: parsed.comments,
13
- error: error ? { start: error.labels[0]?.start ?? 0, message: error.message } : undefined,
14
- rejection: (text) => rejection(text, parsed),
15
- scan: (doc, width) => scan(doc, parsed.program, width),
16
- };
17
- },
18
- config: { setting: bracesSetting, decisions: braceDecisions, width: formatterWidth },
19
- oracle: () => (require("./oracle.ts") as typeof import("./oracle.ts")).oracle,
20
- };
@@ -1,64 +0,0 @@
1
- import type { Node, Statement, SwitchCase } from "oxc-parser";
2
- import { attach } from "../../engine/attach.ts";
3
- import { lineAt, nextToken } from "../../engine/doc.ts";
4
- import { facts } from "./facts.ts";
5
- import type { Doc, StatementList } from "../../engine/model.ts";
6
- import type { Layout } from "../language.ts";
7
-
8
- export type List = StatementList<Statement | SwitchCase>;
9
-
10
- export function listAt(doc: Doc, node: Node, width: Layout): List | undefined {
11
- if (node.type === "Program")
12
- return {
13
- kind: "module",
14
- start: node.start,
15
- end: node.end,
16
- openLine: null,
17
- closeLine: null,
18
- stmts: attach(
19
- doc,
20
- node.body.map((stmt) => facts(doc, stmt, width)),
21
- node.start,
22
- node.end,
23
- ),
24
- };
25
-
26
- if (node.type === "BlockStatement" || node.type === "StaticBlock") {
27
- const start =
28
- node.type === "StaticBlock" ? nextToken(doc, node.start + "static".length) : node.start;
29
-
30
- return {
31
- kind: "block",
32
- start,
33
- end: node.end,
34
- openLine: lineAt(doc, start),
35
- closeLine: lineAt(doc, node.end - 1),
36
- stmts: attach(
37
- doc,
38
- node.body.map((stmt) => facts(doc, stmt, width)),
39
- start + 1,
40
- node.end - 1,
41
- ),
42
- };
43
- }
44
-
45
- if (node.type === "SwitchStatement" || node.type === "SwitchCase") {
46
- const nodes = node.type === "SwitchStatement" ? node.cases : node.consequent;
47
- const opener =
48
- node.type === "SwitchCase" ? (node.test?.end ?? node.start) : node.discriminant.end;
49
-
50
- return {
51
- kind: node.type === "SwitchStatement" ? "switch" : "block",
52
- start: node.start,
53
- end: node.end,
54
- openLine: null,
55
- closeLine: null,
56
- stmts: attach(
57
- doc,
58
- nodes.map((stmt) => facts(doc, stmt, width)),
59
- opener,
60
- node.end,
61
- ),
62
- };
63
- }
64
- }
@@ -1,191 +0,0 @@
1
- import type { BlockStatement, Node } from "oxc-parser";
2
- import type { Comment } from "../../engine/model.ts";
3
- import type { Region } from "../../engine/directives.ts";
4
- import type { Oracle, OracleStatement } from "../language.ts";
5
- import { children, walk } from "./ast.ts";
6
- import { controlledBlocks } from "./braces.ts";
7
- import { parse, type Parsed } from "./parse.ts";
8
-
9
- const POSITION_KEYS = new Set(["start", "end", "range", "loc"]);
10
-
11
- type Range = { start: number; end: number };
12
- type Statement = { node: Node; parent: Node | null };
13
-
14
- const ENCLOSING = new Set([
15
- "BlockStatement",
16
- "StaticBlock",
17
- "SwitchStatement",
18
- "SwitchCase",
19
- "ClassBody",
20
- "TSModuleBlock",
21
- ]);
22
-
23
- const INTERIORS = new Set(["BlockStatement", "StaticBlock", "ClassBody", "TSModuleBlock"]);
24
-
25
- const STATEMENT_ARRAYS = new Set([
26
- "Program:body",
27
- "BlockStatement:body",
28
- "StaticBlock:body",
29
- "SwitchStatement:cases",
30
- "SwitchCase:consequent",
31
- "TSModuleBlock:body",
32
- ]);
33
-
34
- function shape(parsed: Parsed, blocks: BlockStatement[]): string | undefined {
35
- if (parsed.errors.length > 0) return undefined;
36
-
37
- const flattened = new Set(blocks.filter((block) => block.body.length === 1));
38
- return JSON.stringify(parsed.program, (key, value) => {
39
- if (POSITION_KEYS.has(key)) return undefined;
40
- if (typeof value === "bigint") return `${value}n`;
41
- return flattened.has(value) ? value.body[0] : value;
42
- });
43
- }
44
-
45
- function container(program: Node, comment: Comment): Region {
46
- let enclosing: Node = program;
47
- walk(program, (node) => {
48
- if (ENCLOSING.has(node.type) && node.start < comment.start && comment.end <= node.end)
49
- if (node.end - node.start < enclosing.end - enclosing.start) enclosing = node;
50
- });
51
-
52
- return { start: enclosing.start, end: enclosing.end };
53
- }
54
-
55
- function controlledRanges(node: Node): Range[] {
56
- const ranges: Range[] = [];
57
- function body(child: Node): void {
58
- ranges.push(
59
- child.type === "BlockStatement"
60
- ? { start: child.start + 1, end: child.end - 1 }
61
- : { start: child.start, end: child.end },
62
- );
63
- }
64
-
65
- function chain(current: Node): void {
66
- switch (current.type) {
67
- case "LabeledStatement":
68
- chain(current.body);
69
- break;
70
-
71
- case "IfStatement":
72
- body(current.consequent);
73
-
74
- if (current.alternate?.type === "IfStatement") chain(current.alternate);
75
- else if (current.alternate) body(current.alternate);
76
-
77
- break;
78
-
79
- case "ForStatement":
80
- case "ForInStatement":
81
- case "ForOfStatement":
82
- case "WhileStatement":
83
- case "DoWhileStatement":
84
- case "WithStatement":
85
- body(current.body);
86
- }
87
- }
88
-
89
- chain(node);
90
- return ranges;
91
- }
92
-
93
- function statementSkeleton(text: string, statement: Statement): string {
94
- const ranges = controlledRanges(statement.node);
95
-
96
- walk(statement.node, (node) => {
97
- if (ranges.some((range) => range.start <= node.start && node.end <= range.end)) return;
98
- if (INTERIORS.has(node.type)) ranges.push({ start: node.start + 1, end: node.end - 1 });
99
- else if (node.type === "SwitchStatement")
100
- ranges.push({ start: node.discriminant.end, end: node.end - 1 });
101
- });
102
-
103
- const outermost = ranges
104
- .sort((left, right) => left.start - right.start || right.end - left.end)
105
- .filter(
106
- (range, index, all) =>
107
- !all.slice(0, index).some((prior) => prior.start <= range.start && range.end <= prior.end),
108
- );
109
-
110
- let cursor = statement.node.start;
111
- let result = "";
112
- for (const range of outermost) {
113
- result += text.slice(cursor, range.start) + "\0";
114
- cursor = range.end;
115
- }
116
-
117
- return result + text.slice(cursor, statement.node.end);
118
- }
119
-
120
- function edgeAbove(parent: Node): number | undefined {
121
- if (parent.type === "BlockStatement" || parent.type === "StaticBlock") return parent.start;
122
- if (parent.type === "SwitchStatement") return parent.discriminant.end;
123
- }
124
-
125
- function edgeBelow(parent: Node): number | undefined {
126
- if (["BlockStatement", "StaticBlock", "SwitchStatement"].includes(parent.type)) return parent.end;
127
- }
128
-
129
- function gaps(text: string, statement: Statement): [string | undefined, string | undefined] {
130
- if (!statement.parent) return [undefined, undefined];
131
-
132
- const entry = children(statement.parent).find(([, child]) => child === statement.node);
133
- if (!entry || !STATEMENT_ARRAYS.has(`${statement.parent.type}:${entry[0]}`))
134
- return [undefined, undefined];
135
-
136
- const siblings = children(statement.parent)
137
- .filter(([key]) => key === entry[0])
138
- .map(([, child]) => child);
139
-
140
- const index = siblings.indexOf(statement.node);
141
- const previous = siblings[index - 1];
142
- const next = siblings[index + 1];
143
-
144
- const above = previous?.end ?? edgeAbove(statement.parent);
145
- const below = next?.start ?? edgeBelow(statement.parent);
146
- return [
147
- above === undefined ? undefined : text.slice(above, statement.node.start),
148
- below === undefined ? undefined : text.slice(statement.node.end, below),
149
- ];
150
- }
151
-
152
- function statementAfter(program: Node, text: string, offset: number): OracleStatement | undefined {
153
- let next: Statement | undefined;
154
- walk(program, (node, parent) => {
155
- if (
156
- node.start < offset ||
157
- (node.type !== "SwitchCase" && !/(Statement|Declaration)$/.test(node.type))
158
- )
159
- return;
160
-
161
- if (!next || node.start < next.node.start) next = { node, parent };
162
- });
163
-
164
- if (!next) return undefined;
165
-
166
- const statement = next;
167
- return {
168
- start: statement.node.start,
169
- clause: statement.node.type === "SwitchCase",
170
- skeleton: () => statementSkeleton(text, statement),
171
- gaps: () => gaps(text, statement),
172
- };
173
- }
174
-
175
- export const oracle: Oracle = {
176
- side(path, text) {
177
- const parsed = parse(path, text);
178
- const blocks = [...controlledBlocks(parsed.program).keys()];
179
- return {
180
- comments: parsed.comments,
181
- blocks: blocks.map((block) => ({
182
- start: block.start,
183
- end: block.end,
184
- single: block.body.length === 1,
185
- })),
186
- shape: () => shape(parsed, blocks),
187
- container: (comment) => container(parsed.program, comment),
188
- statementAfter: (offset) => statementAfter(parsed.program, text, offset),
189
- };
190
- },
191
- };
@@ -1,31 +0,0 @@
1
- declare module "oxc-parser/src-js/bindings.js" {
2
- import type { ParserOptions } from "oxc-parser";
3
-
4
- export function getBufferOffset(buffer: Uint8Array): number;
5
- export function rawTransferSupported(): boolean;
6
- export function parseRawSync(
7
- path: string,
8
- block: Uint8Array,
9
- sourceStartPos: number,
10
- sourceByteLen: number,
11
- options: ParserOptions,
12
- ): void;
13
- }
14
-
15
- declare module "oxc-parser/src-js/generated/constants.js" {
16
- export const ACTIVE_SIZE: number;
17
- export const BLOCK_ALIGN: number;
18
- export const BLOCK_SIZE: number;
19
- export const BUFFER_SIZE: number;
20
- export const IS_TS_FLAG_POS: number;
21
- }
22
-
23
- declare module "oxc-parser/src-js/generated/deserialize/js.js" {
24
- const path: string;
25
- export default path;
26
- }
27
-
28
- declare module "oxc-parser/src-js/generated/deserialize/ts.js" {
29
- const path: string;
30
- export default path;
31
- }