@ryuugg/stanza 0.3.3 → 0.4.1

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 +15 -13
  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
package/src/compiled.ts DELETED
@@ -1,9 +0,0 @@
1
- import { embedCompiledDeserializers } from "./languages/javascript/embedded.ts";
2
-
3
- export async function start(addon: string): Promise<void> {
4
- // Must precede any oxc-parser import (its loader cannot find the binding in a compiled binary), hence the dynamic import.
5
- process.env.NAPI_RS_NATIVE_LIBRARY_PATH = addon;
6
- embedCompiledDeserializers();
7
- const { start } = await import("./start.ts");
8
- process.exitCode = await start(process.argv.slice(2));
9
- }
package/src/depth.ts DELETED
@@ -1,372 +0,0 @@
1
- // Worker threads get a far smaller native stack than main and oxc's parser recurses, so a deep file aborts the whole process in a worker; these sit at an eighth of the crash depths measured in a worker.
2
- export const FRAME_LIMIT = 300;
3
- export const TOKEN_LIMIT = 1400;
4
-
5
- const NEWLINE = 10;
6
- const RETURN = 13;
7
-
8
- const DOUBLE = 34;
9
- const SINGLE = 39;
10
- const BACKTICK = 96;
11
- const DOLLAR = 36;
12
- const BACKSLASH = 92;
13
-
14
- const OPEN_PAREN = 40;
15
- const OPEN_BRACKET = 91;
16
- const OPEN_BRACE = 123;
17
-
18
- const CLOSE_PAREN = 41;
19
- const CLOSE_BRACKET = 93;
20
- const CLOSE_BRACE = 125;
21
-
22
- const SLASH = 47;
23
- const STAR = 42;
24
- const LESS = 60;
25
- const GREATER = 62;
26
-
27
- const COMMA = 44;
28
- const SEMICOLON = 59;
29
-
30
- const enum Frame {
31
- Bracket,
32
- Interpolation,
33
- Element,
34
- }
35
-
36
- const enum Last {
37
- Start,
38
- Name,
39
- Keyword,
40
- Literal,
41
- Close,
42
- Paren,
43
- Punctuator,
44
- }
45
-
46
- const REGEX_AFTER = [
47
- "return",
48
- "typeof",
49
- "instanceof",
50
- "in",
51
- "of",
52
- "new",
53
- "delete",
54
- "void",
55
- "throw",
56
- "case",
57
- "do",
58
- "else",
59
- "yield",
60
- "await",
61
- ];
62
-
63
- const KEYWORDS = new Set([
64
- ...REGEX_AFTER,
65
- "keyof",
66
- "readonly",
67
- "infer",
68
- "unique",
69
- "async",
70
- "export",
71
- "declare",
72
- "abstract",
73
- "static",
74
- "public",
75
- "private",
76
- "protected",
77
- "override",
78
- "get",
79
- "set",
80
- "accessor",
81
- "let",
82
- "const",
83
- "var",
84
- "function",
85
- "class",
86
- "interface",
87
- "type",
88
- "enum",
89
- "namespace",
90
- "module",
91
- "import",
92
- "from",
93
- "default",
94
- "extends",
95
- "implements",
96
- "as",
97
- "satisfies",
98
- "is",
99
- "asserts",
100
- "if",
101
- "for",
102
- "while",
103
- "with",
104
- "switch",
105
- "try",
106
- "catch",
107
- "finally",
108
- ]);
109
-
110
- const CONTINUES = new Set([
111
- "else",
112
- "catch",
113
- "finally",
114
- "while",
115
- "instanceof",
116
- "in",
117
- "of",
118
- "as",
119
- "satisfies",
120
- "extends",
121
- "implements",
122
- ]);
123
-
124
- interface Scan {
125
- text: string;
126
- frames: Frame[];
127
- segments: number[];
128
- tokens: number;
129
- }
130
-
131
- function isWord(code: number): boolean {
132
- return (
133
- (code >= 97 && code <= 122) ||
134
- (code >= 65 && code <= 90) ||
135
- (code >= 48 && code <= 57) ||
136
- code === 95 ||
137
- code === DOLLAR ||
138
- code > 127
139
- );
140
- }
141
-
142
- function isBlank(code: number): boolean {
143
- return (
144
- code === 32 || code === 9 || code === 11 || code === 12 || code === 0xa0 || code === 0xfeff
145
- );
146
- }
147
-
148
- function isLineEnd(code: number): boolean {
149
- return code === NEWLINE || code === RETURN;
150
- }
151
-
152
- function quotedEnd(text: string, start: number, quote: number): number {
153
- for (let index = start + 1; index < text.length; index++) {
154
- const code = text.charCodeAt(index);
155
- if (code === quote) return index + 1;
156
- if (code === BACKSLASH) index++;
157
- else if (isLineEnd(code)) return -1;
158
- }
159
-
160
- return -1;
161
- }
162
-
163
- function regexEnd(text: string, start: number): number {
164
- let inClass = false;
165
- for (let index = start + 1; index < text.length; index++) {
166
- const code = text.charCodeAt(index);
167
- if (code === BACKSLASH) index++;
168
- else if (isLineEnd(code)) return -1;
169
- else if (code === OPEN_BRACKET) inClass = true;
170
- else if (code === CLOSE_BRACKET) inClass = false;
171
- else if (code === SLASH && !inClass) {
172
- let end = index + 1;
173
- while (end < text.length && isWord(text.charCodeAt(end))) end++;
174
- return end;
175
- }
176
- }
177
-
178
- return -1;
179
- }
180
-
181
- function count(scan: Scan): boolean {
182
- scan.segments[scan.segments.length - 1]!++;
183
- scan.tokens++;
184
-
185
- const nested = (scan.frames.length - 1) * TOKEN_LIMIT;
186
- return nested + scan.tokens * FRAME_LIMIT > FRAME_LIMIT * TOKEN_LIMIT;
187
- }
188
-
189
- function reset(scan: Scan): void {
190
- scan.tokens -= scan.segments[scan.segments.length - 1]!;
191
- scan.segments[scan.segments.length - 1] = 0;
192
- }
193
-
194
- function push(scan: Scan, frame: Frame): void {
195
- scan.frames.push(frame);
196
- scan.segments.push(0);
197
- }
198
-
199
- function pop(scan: Scan): void {
200
- scan.tokens -= scan.segments.pop()!;
201
- scan.frames.pop();
202
- }
203
-
204
- function top(scan: Scan): Frame {
205
- return scan.frames[scan.frames.length - 1]!;
206
- }
207
-
208
- function closeElement(scan: Scan): void {
209
- pop(scan);
210
- if (top(scan) === Frame.Element) reset(scan);
211
- }
212
-
213
- function templateEnd(scan: Scan, start: number): number {
214
- const { text } = scan;
215
- for (let index = start; index < text.length; index++) {
216
- const code = text.charCodeAt(index);
217
- if (code === BACKSLASH) index++;
218
- else if (code === BACKTICK) return index + 1;
219
- else if (code === DOLLAR && text.charCodeAt(index + 1) === OPEN_BRACE) {
220
- push(scan, Frame.Interpolation);
221
- return -(index + 2);
222
- }
223
- }
224
-
225
- return text.length;
226
- }
227
-
228
- export function deepRisk(text: string, jsx: boolean): boolean {
229
- const scan: Scan = { text, frames: [Frame.Bracket], segments: [0], tokens: 0 };
230
-
231
- let last = Last.Start;
232
- let lineBreak = false;
233
- let index = 0;
234
- while (index < text.length) {
235
- const code = text.charCodeAt(index);
236
- if (isBlank(code)) {
237
- index++;
238
- continue;
239
- }
240
-
241
- if (isLineEnd(code)) {
242
- lineBreak ||= last === Last.Name || last === Last.Literal || last === Last.Close;
243
- index++;
244
- continue;
245
- }
246
-
247
- const next = text.charCodeAt(index + 1);
248
- if (code === SLASH && next === SLASH) {
249
- while (index < text.length && !isLineEnd(text.charCodeAt(index))) index++;
250
- continue;
251
- }
252
-
253
- const commentEnd = code === SLASH && next === STAR ? text.indexOf("*/", index + 2) : -1;
254
- if (commentEnd >= 0) {
255
- index = commentEnd + 2;
256
- continue;
257
- }
258
-
259
- if (isWord(code)) {
260
- const start = index;
261
- while (index < text.length && isWord(text.charCodeAt(index))) index++;
262
-
263
- const word = index - start <= 10 ? text.slice(start, index) : "";
264
- if (lineBreak && !CONTINUES.has(word)) reset(scan);
265
-
266
- lineBreak = false;
267
- last = KEYWORDS.has(word) ? Last.Keyword : Last.Name;
268
- if (count(scan)) return true;
269
- continue;
270
- }
271
-
272
- lineBreak = false;
273
-
274
- if (code === SINGLE || code === DOUBLE) {
275
- const end = quotedEnd(text, index, code);
276
- index = end < 0 ? index + 1 : end;
277
- last = end < 0 ? Last.Punctuator : Last.Literal;
278
- if (count(scan)) return true;
279
- continue;
280
- }
281
-
282
- if (code === BACKTICK) {
283
- const end = templateEnd(scan, index + 1);
284
- index = Math.abs(end);
285
- last = end < 0 ? Last.Punctuator : Last.Literal;
286
- if (count(scan)) return true;
287
- continue;
288
- }
289
-
290
- const divides =
291
- last === Last.Name || last === Last.Literal || last === Last.Close || last === Last.Paren;
292
-
293
- const regex = code === SLASH && !divides ? regexEnd(text, index) : -1;
294
- if (regex >= 0) {
295
- index = regex;
296
- last = Last.Literal;
297
- if (count(scan)) return true;
298
- continue;
299
- }
300
-
301
- index++;
302
-
303
- if (code === SEMICOLON || code === COMMA) {
304
- reset(scan);
305
- last = Last.Punctuator;
306
- continue;
307
- }
308
-
309
- if (code === OPEN_PAREN || code === OPEN_BRACKET || code === OPEN_BRACE) {
310
- if (count(scan)) return true;
311
-
312
- push(scan, Frame.Bracket);
313
- last = Last.Punctuator;
314
- continue;
315
- }
316
-
317
- if (code === CLOSE_PAREN || code === CLOSE_BRACKET || code === CLOSE_BRACE) {
318
- while (scan.frames.length > 1 && top(scan) === Frame.Element) pop(scan);
319
-
320
- if (code === CLOSE_BRACE && scan.frames.length > 1 && top(scan) === Frame.Interpolation) {
321
- pop(scan);
322
-
323
- const end = templateEnd(scan, index);
324
- index = Math.abs(end);
325
- last = end < 0 ? Last.Punctuator : Last.Literal;
326
- continue;
327
- }
328
-
329
- if (scan.frames.length > 1) pop(scan);
330
-
331
- last = code === CLOSE_PAREN ? Last.Paren : Last.Close;
332
- if (count(scan)) return true;
333
- continue;
334
- }
335
-
336
- if (jsx && code === LESS && next === SLASH) {
337
- if (top(scan) === Frame.Element) closeElement(scan);
338
-
339
- last = Last.Punctuator;
340
- if (count(scan)) return true;
341
- continue;
342
- }
343
-
344
- const opensElement =
345
- top(scan) === Frame.Element ||
346
- last === Last.Start ||
347
- last === Last.Punctuator ||
348
- last === Last.Keyword;
349
-
350
- if (jsx && code === LESS && opensElement && (isWord(next) || next === GREATER)) {
351
- if (count(scan)) return true;
352
-
353
- push(scan, Frame.Element);
354
- last = Last.Punctuator;
355
- continue;
356
- }
357
-
358
- if (jsx && code === SLASH && next === GREATER && top(scan) === Frame.Element) {
359
- index++;
360
- closeElement(scan);
361
- }
362
-
363
- last = Last.Punctuator;
364
- if (count(scan)) return true;
365
- }
366
-
367
- return false;
368
- }
369
-
370
- export function tooDeep(path: string, text: string): boolean {
371
- return deepRisk(text, !/\.[cm]?ts$/.test(path));
372
- }
@@ -1,77 +0,0 @@
1
- import { existsSync, readdirSync, realpathSync } from "node:fs";
2
- import { basename, dirname, join } from "node:path";
3
-
4
- type Listing = { names: Set<string>; folded: Set<string> } | null;
5
-
6
- const maps: Map<unknown, unknown>[] = [];
7
- export function invocationMap<K, V>(): Map<K, V> {
8
- const map = new Map<K, V>();
9
- maps.push(map);
10
- return map;
11
- }
12
-
13
- export function beginInvocation(): void {
14
- for (const map of maps) map.clear();
15
- }
16
-
17
- const realDirectories = invocationMap<string, string>();
18
- const listings = invocationMap<string, Listing>();
19
- const existence = invocationMap<string, boolean>();
20
- const realPaths = invocationMap<string, string>();
21
-
22
- export function realDirectory(dir: string): string {
23
- const cached = realDirectories.get(dir);
24
- if (cached !== undefined) return cached;
25
-
26
- const parent = dirname(dir);
27
- const real = existsSync(dir)
28
- ? realpathSync(dir)
29
- : parent === dir
30
- ? dir
31
- : join(realDirectory(parent), basename(dir));
32
-
33
- realDirectories.set(dir, real);
34
- realDirectories.set(real, real);
35
- return real;
36
- }
37
-
38
- function listing(dir: string): Listing {
39
- const cached = listings.get(dir);
40
- if (cached !== undefined) return cached;
41
-
42
- let result: Listing;
43
- try {
44
- const names = readdirSync(dir);
45
- result = { names: new Set(names), folded: new Set(names.map((name) => name.toLowerCase())) };
46
- } catch {
47
- result = null;
48
- }
49
-
50
- listings.set(dir, result);
51
- return result;
52
- }
53
-
54
- export function holds(dir: string, name: string): boolean {
55
- const path = join(dir, name);
56
- const cached = existence.get(path);
57
- if (cached !== undefined) return cached;
58
-
59
- const entries = listing(dir);
60
- const exists = (entries === null || entries.folded.has(name.toLowerCase())) && existsSync(path);
61
-
62
- existence.set(path, exists);
63
- return exists;
64
- }
65
-
66
- export function listed(dir: string, name: string): boolean {
67
- return listing(dir)?.names.has(name) ?? false;
68
- }
69
-
70
- export function realPath(path: string): string {
71
- const cached = realPaths.get(path);
72
- if (cached !== undefined) return cached;
73
-
74
- const real = realpathSync(path);
75
- realPaths.set(path, real);
76
- return real;
77
- }
@@ -1,62 +0,0 @@
1
- import { blankLines, commentIndex, lineAt } from "./doc.ts";
2
- import { ignored } from "./directives.ts";
3
- import type { Doc, Item, Stmt } from "./model.ts";
4
-
5
- function fallthroughEnd<Node>(
6
- doc: Doc,
7
- item: Item<Node>,
8
- next: Item<Node> | undefined,
9
- end: number,
10
- ): number {
11
- if (!item.caseBody || next?.kind !== "case") return end;
12
-
13
- const index = commentIndex(doc, end);
14
- const comment = doc.comments[index];
15
- if (!comment || (doc.comments[index + 1]?.start ?? Infinity) < next.start) return end;
16
-
17
- const directlyBetween =
18
- lineAt(doc, comment.start) === lineAt(doc, end - 1) + 1 &&
19
- lineAt(doc, comment.end - 1) + 1 === lineAt(doc, next.start);
20
-
21
- return directlyBetween && /^(falls through|fallthrough)/i.test(comment.value.trimStart())
22
- ? comment.end
23
- : end;
24
- }
25
-
26
- export function attach<Node>(
27
- doc: Doc,
28
- items: Item<Node>[],
29
- opener: number,
30
- limit: number,
31
- ): Stmt<Node>[] {
32
- let previousEnd = opener;
33
- return items.map((item, itemIndex) => {
34
- const itemStartLine = lineAt(doc, item.start);
35
- const itemEndLine = lineAt(doc, item.end - 1);
36
- const leading = doc.comments[commentIndex(doc, previousEnd)];
37
- const leadLine =
38
- leading && leading.end <= item.start ? lineAt(doc, leading.start) : itemStartLine;
39
-
40
- const detached =
41
- leadLine !== itemStartLine && blankLines(doc, leadLine - 1, itemStartLine).length > 0;
42
-
43
- let end = item.end;
44
- for (let index = commentIndex(doc, item.end); index < doc.comments.length; index++) {
45
- const comment = doc.comments[index]!;
46
- if (comment.start >= limit || lineAt(doc, comment.start) !== itemEndLine) break;
47
- end = Math.max(end, comment.end);
48
- }
49
-
50
- if (item.kind === "case") end = fallthroughEnd(doc, item, items[itemIndex + 1], end);
51
-
52
- previousEnd = end;
53
- return {
54
- ...item,
55
- frozen: ignored(doc, item.start),
56
- startLine: detached ? itemStartLine : leadLine,
57
- endLine: lineAt(doc, end - 1),
58
- multiline: itemStartLine !== itemEndLine,
59
- detached,
60
- };
61
- });
62
- }
@@ -1,157 +0,0 @@
1
- import { commentIndex, lineAt } from "./doc.ts";
2
- import type { Comment, Doc, StatementList } from "./model.ts";
3
-
4
- export type Region = { start: number; end: number };
5
-
6
- type Directive = "ignore" | "off" | "on";
7
-
8
- function directive(comment: Comment): Directive | null {
9
- const value = comment.type === "Block" ? comment.value.replace(/^[\s*]*/, "") : comment.value;
10
- const match = /^stanza-(ignore|off|on)(?![\p{ID_Continue}-])/u.exec(value.trim());
11
- return match ? (match[1] as Directive) : null;
12
- }
13
-
14
- function directlyAbove(doc: Doc, comment: Comment, top: number): boolean {
15
- const between = doc.text.slice(comment.end, top);
16
- const lineStart = doc.lineStarts[lineAt(doc, comment.start) - 1]!;
17
- return (
18
- /^[^\S\n]*\n[^\S\n]*$/.test(between) && /^\s*$/.test(doc.text.slice(lineStart, comment.start))
19
- );
20
- }
21
-
22
- export function ignored(doc: Doc, start: number): boolean {
23
- let top = start;
24
- for (let index = commentIndex(doc, start) - 1; index >= 0; index--) {
25
- const comment = doc.comments[index]!;
26
- if (!directlyAbove(doc, comment, top)) return false;
27
- if (directive(comment) === "ignore") return true;
28
-
29
- top = comment.start;
30
- }
31
-
32
- return false;
33
- }
34
-
35
- function enclosing(doc: Doc, containers: Region[], comment: Comment): Region {
36
- let block: Region = { start: 0, end: doc.text.length };
37
- for (const container of containers)
38
- if (
39
- container.start < comment.start &&
40
- comment.end <= container.end &&
41
- (container.start > block.start ||
42
- (container.start === block.start && container.end < block.end))
43
- )
44
- block = container;
45
-
46
- return block;
47
- }
48
-
49
- function nests(sorted: Region[]): boolean {
50
- const open: Region[] = [];
51
- for (const container of sorted) {
52
- while (open.length > 0 && open.at(-1)!.end <= container.start) open.pop();
53
- if (open.length > 0 && container.end > open.at(-1)!.end) return false;
54
- open.push(container);
55
- }
56
-
57
- return true;
58
- }
59
-
60
- function enclosingAll(doc: Doc, containers: Region[], marks: Comment[]): Region[] {
61
- const sorted = containers.toSorted(
62
- (left, right) => left.start - right.start || right.end - left.end,
63
- );
64
-
65
- if (!nests(sorted)) return marks.map((comment) => enclosing(doc, containers, comment));
66
-
67
- const whole: Region = { start: 0, end: doc.text.length };
68
- const open: Region[] = [];
69
-
70
- let next = 0;
71
- return marks.map((comment) => {
72
- for (; next < sorted.length && sorted[next]!.start < comment.start; next++) {
73
- while (open.length > 0 && open.at(-1)!.end <= sorted[next]!.start) open.pop();
74
- open.push(sorted[next]!);
75
- }
76
-
77
- while (open.length > 0 && open.at(-1)!.end < comment.end) open.pop();
78
- return open.at(-1) ?? whole;
79
- });
80
- }
81
-
82
- export function marks(doc: Doc): Comment[] {
83
- return doc.comments.filter(
84
- (comment) => directive(comment) === "off" || directive(comment) === "on",
85
- );
86
- }
87
-
88
- export function regions(doc: Doc, marks: Comment[], containers: Region[]): Region[] {
89
- if (marks.length === 0) return [];
90
-
91
- const ranges = enclosingAll(doc, containers, marks);
92
- const open = new Map<string, Region & { depth: number }>();
93
- const result: Region[] = [];
94
- for (const [index, comment] of marks.entries()) {
95
- const range = ranges[index]!;
96
- const key = `${range.start}:${range.end}`;
97
- const current = open.get(key);
98
- if (directive(comment) === "off") {
99
- if (current) current.depth++;
100
- else open.set(key, { start: comment.start, end: range.end, depth: 1 });
101
-
102
- continue;
103
- }
104
-
105
- if (!current) continue;
106
-
107
- current.depth--;
108
- if (current.depth > 0) continue;
109
-
110
- result.push({ start: current.start, end: comment.start });
111
- open.delete(key);
112
- }
113
-
114
- for (const { start, end } of open.values()) result.push({ start, end });
115
-
116
- result.sort((left, right) => left.start - right.start);
117
-
118
- const merged: Region[] = [];
119
- for (const region of result) {
120
- const previous = merged.at(-1);
121
- if (previous && region.start <= previous.end) previous.end = Math.max(previous.end, region.end);
122
- else merged.push(region);
123
- }
124
-
125
- return merged;
126
- }
127
-
128
- export function within(regions: Region[], offset: number): boolean {
129
- let low = 0;
130
- let high = regions.length;
131
- while (low < high) {
132
- const middle = Math.floor((low + high) / 2);
133
- if (regions[middle]!.start <= offset) low = middle + 1;
134
- else high = middle;
135
- }
136
-
137
- const region = regions[low - 1];
138
- return region !== undefined && offset < region.end;
139
- }
140
-
141
- export function freeze(
142
- doc: Doc,
143
- marked: Comment[],
144
- lists: StatementList[],
145
- containers: Region[],
146
- ): { lists: StatementList[]; frozen: Region[] } {
147
- if (marked.length === 0) return { lists, frozen: [] };
148
-
149
- const frozen = regions(doc, marked, containers);
150
- for (const list of lists)
151
- for (const stmt of list.stmts) if (within(frozen, stmt.start)) stmt.frozen = true;
152
-
153
- return {
154
- lists: lists.filter((list) => list.kind === "module" || !within(frozen, list.start)),
155
- frozen,
156
- };
157
- }