pickier 0.1.34 → 0.1.35
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/dist/bin/cli.js +276 -32
- package/dist/src/index.js +275 -31
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -48,6 +48,37 @@ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
|
48
48
|
var __require = import.meta.require;
|
|
49
49
|
|
|
50
50
|
// src/format.ts
|
|
51
|
+
function isHangingControlLine(code) {
|
|
52
|
+
const m = RE_CONTROL_OPEN.exec(code);
|
|
53
|
+
if (!m)
|
|
54
|
+
return /^(?:else|do)\s*$/.test(code);
|
|
55
|
+
let depth = 0;
|
|
56
|
+
let inStr = null;
|
|
57
|
+
for (let i = m[0].length - 1;i < code.length; i++) {
|
|
58
|
+
const ch = code[i];
|
|
59
|
+
if (inStr) {
|
|
60
|
+
if (ch === "\\") {
|
|
61
|
+
i++;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ch === inStr)
|
|
65
|
+
inStr = null;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
69
|
+
inStr = ch;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (ch === "(") {
|
|
73
|
+
depth++;
|
|
74
|
+
} else if (ch === ")") {
|
|
75
|
+
depth--;
|
|
76
|
+
if (depth === 0)
|
|
77
|
+
return code.slice(i + 1).trim().length === 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
51
82
|
function getFileExt(filePath) {
|
|
52
83
|
const idx = filePath.lastIndexOf(".");
|
|
53
84
|
return idx >= 0 ? filePath.slice(idx) : "";
|
|
@@ -198,6 +229,25 @@ function fixQuotesLine(line, preferred) {
|
|
|
198
229
|
while (i < line.length) {
|
|
199
230
|
const ch = line[i];
|
|
200
231
|
if (inString === 0) {
|
|
232
|
+
if (ch === "/") {
|
|
233
|
+
const nxt = line[i + 1];
|
|
234
|
+
if (nxt === "/")
|
|
235
|
+
break;
|
|
236
|
+
if (nxt === "*") {
|
|
237
|
+
const end = line.indexOf("*/", i + 2);
|
|
238
|
+
i = end === -1 ? line.length : end + 2;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (isRegexStart(line, i)) {
|
|
242
|
+
const end = scanRegexEnd(line, i);
|
|
243
|
+
if (end !== -1) {
|
|
244
|
+
i = end;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
i++;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
201
251
|
if (ch === '"') {
|
|
202
252
|
inString = 2;
|
|
203
253
|
stringStart = i;
|
|
@@ -265,6 +315,8 @@ function normalizeSpacingLine(line) {
|
|
|
265
315
|
const c = line[firstNonSpace];
|
|
266
316
|
if (c === "/" && (line[firstNonSpace + 1] === "/" || line[firstNonSpace + 1] === "*"))
|
|
267
317
|
return line;
|
|
318
|
+
if (c === "*")
|
|
319
|
+
return line;
|
|
268
320
|
}
|
|
269
321
|
let hasSpacingChar = false;
|
|
270
322
|
for (let j = firstNonSpace;j < line.length; j++) {
|
|
@@ -377,6 +429,49 @@ function advanceTemplateState(line, stack) {
|
|
|
377
429
|
}
|
|
378
430
|
return -1;
|
|
379
431
|
}
|
|
432
|
+
function blockCommentStateAfter(line, startsIn) {
|
|
433
|
+
let inBlock = startsIn;
|
|
434
|
+
let inStr = null;
|
|
435
|
+
let i = 0;
|
|
436
|
+
while (i < line.length) {
|
|
437
|
+
const ch = line[i];
|
|
438
|
+
if (inBlock) {
|
|
439
|
+
if (ch === "*" && line[i + 1] === "/") {
|
|
440
|
+
inBlock = false;
|
|
441
|
+
i += 2;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
i++;
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (inStr) {
|
|
448
|
+
if (ch === "\\") {
|
|
449
|
+
i += 2;
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
if (ch === inStr)
|
|
453
|
+
inStr = null;
|
|
454
|
+
i++;
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
458
|
+
inStr = ch;
|
|
459
|
+
i++;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (ch === "/") {
|
|
463
|
+
if (line[i + 1] === "/")
|
|
464
|
+
break;
|
|
465
|
+
if (line[i + 1] === "*") {
|
|
466
|
+
inBlock = true;
|
|
467
|
+
i += 2;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
i++;
|
|
472
|
+
}
|
|
473
|
+
return inBlock;
|
|
474
|
+
}
|
|
380
475
|
function processCodeLinesFused(content, cfg) {
|
|
381
476
|
const lines = content.split(`
|
|
382
477
|
`);
|
|
@@ -385,9 +480,16 @@ function processCodeLinesFused(content, cfg) {
|
|
|
385
480
|
const preferred = cfg.format.quotes;
|
|
386
481
|
const doSemiRemoval = cfg.format.semi === true;
|
|
387
482
|
let indentLevel = 0;
|
|
483
|
+
let hangDepth = 0;
|
|
484
|
+
let inBlockComment = false;
|
|
388
485
|
const tmplStack = [];
|
|
389
486
|
for (let idx = 0;idx < len; idx++) {
|
|
390
487
|
let line = lines[idx];
|
|
488
|
+
if (inBlockComment) {
|
|
489
|
+
inBlockComment = blockCommentStateAfter(line, true);
|
|
490
|
+
result[idx] = line;
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
391
493
|
const protectedLine = inTemplateText(tmplStack);
|
|
392
494
|
let splitIdx = -1;
|
|
393
495
|
if (tmplStack.length > 0 || line.indexOf("`") !== -1)
|
|
@@ -396,6 +498,8 @@ function processCodeLinesFused(content, cfg) {
|
|
|
396
498
|
result[idx] = line;
|
|
397
499
|
continue;
|
|
398
500
|
}
|
|
501
|
+
if (splitIdx < 0 && tmplStack.length === 0)
|
|
502
|
+
inBlockComment = blockCommentStateAfter(line, false);
|
|
399
503
|
let tmplTail = "";
|
|
400
504
|
let prefixEndedWithSpace = false;
|
|
401
505
|
if (splitIdx >= 0) {
|
|
@@ -419,9 +523,15 @@ function processCodeLinesFused(content, cfg) {
|
|
|
419
523
|
const trimmed = line.slice(wsEnd).trimEnd();
|
|
420
524
|
if (RE_CLOSING_BRACE.test(trimmed))
|
|
421
525
|
indentLevel = Math.max(0, indentLevel - 1);
|
|
422
|
-
|
|
423
|
-
|
|
526
|
+
const continuationBump = RE_CONTINUATION_LINE.test(trimmed) ? 1 : 0;
|
|
527
|
+
line = makeIndent(indentLevel + hangDepth + continuationBump, cfg) + trimmed;
|
|
528
|
+
if (RE_OPENING_BRACE.test(trimmed)) {
|
|
424
529
|
indentLevel += 1;
|
|
530
|
+
hangDepth = 0;
|
|
531
|
+
} else if (!trimmed.startsWith("//") && !trimmed.startsWith("*") && !trimmed.startsWith("/*")) {
|
|
532
|
+
const code = trimmed.replace(RE_TRAILING_LINE_COMMENT, "");
|
|
533
|
+
hangDepth = isHangingControlLine(code) ? hangDepth + 1 : 0;
|
|
534
|
+
}
|
|
425
535
|
line = normalizeSpacingLine(line);
|
|
426
536
|
if (doSemiRemoval) {
|
|
427
537
|
if (!RE_FOR_LOOP.test(line)) {
|
|
@@ -653,8 +763,48 @@ function skipTemplate(input, start) {
|
|
|
653
763
|
}
|
|
654
764
|
return i;
|
|
655
765
|
}
|
|
766
|
+
function isRegexStart(input, slashIdx) {
|
|
767
|
+
let j = slashIdx - 1;
|
|
768
|
+
while (j >= 0 && (input[j] === " " || input[j] === "\t"))
|
|
769
|
+
j--;
|
|
770
|
+
if (j < 0)
|
|
771
|
+
return true;
|
|
772
|
+
const prev = input[j];
|
|
773
|
+
if ("(,=:[!&|?;{}<>+-*%^~".includes(prev))
|
|
774
|
+
return true;
|
|
775
|
+
if (/[\w$]/.test(prev)) {
|
|
776
|
+
let k = j;
|
|
777
|
+
while (k >= 0 && /[\w$]/.test(input[k]))
|
|
778
|
+
k--;
|
|
779
|
+
return REGEX_PRECEDING_KEYWORDS.has(input.slice(k + 1, j + 1));
|
|
780
|
+
}
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
function scanRegexEnd(input, start) {
|
|
784
|
+
let i = start + 1;
|
|
785
|
+
let inClass = false;
|
|
786
|
+
while (i < input.length) {
|
|
787
|
+
const c = input[i];
|
|
788
|
+
if (c === "\\") {
|
|
789
|
+
i += 2;
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
if (c === "[") {
|
|
793
|
+
inClass = true;
|
|
794
|
+
} else if (c === "]") {
|
|
795
|
+
inClass = false;
|
|
796
|
+
} else if (c === "/" && !inClass) {
|
|
797
|
+
i++;
|
|
798
|
+
while (i < input.length && /[a-z]/i.test(input[i]))
|
|
799
|
+
i++;
|
|
800
|
+
return i;
|
|
801
|
+
}
|
|
802
|
+
i++;
|
|
803
|
+
}
|
|
804
|
+
return -1;
|
|
805
|
+
}
|
|
656
806
|
function maskStrings(input) {
|
|
657
|
-
if (!input.includes("'") && !input.includes('"') && !input.includes("`"))
|
|
807
|
+
if (!input.includes("'") && !input.includes('"') && !input.includes("`") && !input.includes("/"))
|
|
658
808
|
return { text: input, strings: [] };
|
|
659
809
|
const strings = [];
|
|
660
810
|
const parts = [];
|
|
@@ -662,6 +812,42 @@ function maskStrings(input) {
|
|
|
662
812
|
let segStart = 0;
|
|
663
813
|
while (i < input.length) {
|
|
664
814
|
const ch = input[i];
|
|
815
|
+
if (ch === "/") {
|
|
816
|
+
const next = input[i + 1];
|
|
817
|
+
if (next === "/") {
|
|
818
|
+
if (i > segStart)
|
|
819
|
+
parts.push(input.slice(segStart, i));
|
|
820
|
+
strings.push(input.slice(i));
|
|
821
|
+
parts.push(`@@S${strings.length - 1}@@`);
|
|
822
|
+
segStart = input.length;
|
|
823
|
+
break;
|
|
824
|
+
}
|
|
825
|
+
if (next === "*") {
|
|
826
|
+
const end = input.indexOf("*/", i + 2);
|
|
827
|
+
const stop = end === -1 ? input.length : end + 2;
|
|
828
|
+
if (i > segStart)
|
|
829
|
+
parts.push(input.slice(segStart, i));
|
|
830
|
+
strings.push(input.slice(i, stop));
|
|
831
|
+
parts.push(`@@S${strings.length - 1}@@`);
|
|
832
|
+
i = stop;
|
|
833
|
+
segStart = i;
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
if (isRegexStart(input, i)) {
|
|
837
|
+
const end = scanRegexEnd(input, i);
|
|
838
|
+
if (end !== -1) {
|
|
839
|
+
if (i > segStart)
|
|
840
|
+
parts.push(input.slice(segStart, i));
|
|
841
|
+
strings.push(input.slice(i, end));
|
|
842
|
+
parts.push(`@@S${strings.length - 1}@@`);
|
|
843
|
+
i = end;
|
|
844
|
+
segStart = i;
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
i++;
|
|
849
|
+
continue;
|
|
850
|
+
}
|
|
665
851
|
if (ch === "'" || ch === '"' || ch === "`") {
|
|
666
852
|
if (i > segStart)
|
|
667
853
|
parts.push(input.slice(segStart, i));
|
|
@@ -717,24 +903,65 @@ function formatImports(source) {
|
|
|
717
903
|
const lines = source.split(`
|
|
718
904
|
`);
|
|
719
905
|
const imports = [];
|
|
906
|
+
const preamble = [];
|
|
907
|
+
const interleaved = [];
|
|
720
908
|
let idx = 0;
|
|
909
|
+
let lastEnd = 0;
|
|
910
|
+
let pendingStart = -1;
|
|
911
|
+
let sawImport = false;
|
|
721
912
|
while (idx < lines.length) {
|
|
722
913
|
const line = lines[idx];
|
|
723
|
-
if (RE_BLANK_LINE.test(line)
|
|
914
|
+
if (RE_BLANK_LINE.test(line)) {
|
|
724
915
|
idx++;
|
|
725
916
|
continue;
|
|
726
917
|
}
|
|
918
|
+
if (RE_LINE_COMMENT.test(line) || RE_BLOCK_COMMENT.test(line)) {
|
|
919
|
+
const start = idx;
|
|
920
|
+
if (RE_BLOCK_COMMENT.test(line)) {
|
|
921
|
+
while (idx < lines.length && !lines[idx].includes("*/"))
|
|
922
|
+
idx++;
|
|
923
|
+
idx++;
|
|
924
|
+
} else {
|
|
925
|
+
idx++;
|
|
926
|
+
}
|
|
927
|
+
if (!sawImport) {
|
|
928
|
+
for (let k = start;k < idx && k < lines.length; k++)
|
|
929
|
+
preamble.push(lines[k]);
|
|
930
|
+
lastEnd = idx;
|
|
931
|
+
} else if (pendingStart < 0) {
|
|
932
|
+
pendingStart = start;
|
|
933
|
+
}
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
727
936
|
if (!RE_IMPORT_STMT.test(line))
|
|
728
937
|
break;
|
|
729
|
-
|
|
938
|
+
let stmt = line.trim();
|
|
939
|
+
let stmtEnd = idx + 1;
|
|
940
|
+
while (!RE_IMPORT_COMPLETE.test(stmt) && stmtEnd < lines.length && stmtEnd - idx < 50) {
|
|
941
|
+
stmt += ` ${lines[stmtEnd].trim()}`;
|
|
942
|
+
stmtEnd++;
|
|
943
|
+
}
|
|
944
|
+
if (!RE_IMPORT_COMPLETE.test(stmt))
|
|
945
|
+
return source;
|
|
730
946
|
const parsed = parseImportStatement(stmt);
|
|
731
|
-
if (parsed)
|
|
732
|
-
|
|
733
|
-
|
|
947
|
+
if (!parsed)
|
|
948
|
+
return source;
|
|
949
|
+
if (pendingStart >= 0) {
|
|
950
|
+
for (let k = pendingStart;k < idx; k++) {
|
|
951
|
+
if (!RE_BLANK_LINE.test(lines[k]))
|
|
952
|
+
interleaved.push(lines[k]);
|
|
953
|
+
}
|
|
954
|
+
pendingStart = -1;
|
|
955
|
+
}
|
|
956
|
+
imports.push(parsed);
|
|
957
|
+
idx = stmtEnd;
|
|
958
|
+
lastEnd = idx;
|
|
959
|
+
sawImport = true;
|
|
734
960
|
}
|
|
735
961
|
if (imports.length === 0)
|
|
736
962
|
return source;
|
|
737
|
-
const
|
|
963
|
+
const restStart = pendingStart >= 0 ? pendingStart : lastEnd;
|
|
964
|
+
const rest = lines.slice(restStart).join(`
|
|
738
965
|
`);
|
|
739
966
|
const usedIdentifiers = collectIdentifierSet(rest);
|
|
740
967
|
const used = (name) => usedIdentifiers.has(name);
|
|
@@ -855,17 +1082,29 @@ function formatImports(source) {
|
|
|
855
1082
|
}
|
|
856
1083
|
return a.source.localeCompare(b.source);
|
|
857
1084
|
});
|
|
1085
|
+
const head = preamble.length > 0 ? `${preamble.join(`
|
|
1086
|
+
`)}
|
|
1087
|
+
` : "";
|
|
858
1088
|
if (entries.length === 0) {
|
|
859
|
-
|
|
1089
|
+
const restClean2 = rest.replace(/^\n+/, "");
|
|
1090
|
+
const kept = [...interleaved];
|
|
1091
|
+
if (head || kept.length > 0)
|
|
1092
|
+
return `${head}${kept.length > 0 ? `${kept.join(`
|
|
1093
|
+
`)}
|
|
1094
|
+
` : ""}${restClean2}`;
|
|
1095
|
+
return restClean2;
|
|
860
1096
|
}
|
|
861
1097
|
const rendered = entries.map(renderImport).join(`
|
|
862
1098
|
`);
|
|
863
|
-
const
|
|
864
|
-
`
|
|
1099
|
+
const mid = interleaved.length > 0 ? `
|
|
1100
|
+
${interleaved.join(`
|
|
1101
|
+
`)}` : "";
|
|
1102
|
+
const restClean = rest.replace(/^\n+/, "");
|
|
1103
|
+
const sep = restClean.length > 0 ? `
|
|
865
1104
|
|
|
866
1105
|
` : `
|
|
867
1106
|
`;
|
|
868
|
-
return `${rendered}${sep}${
|
|
1107
|
+
return `${head}${rendered}${mid}${sep}${restClean}`;
|
|
869
1108
|
}
|
|
870
1109
|
function renderImport(imp) {
|
|
871
1110
|
if (imp.kind === "side-effect")
|
|
@@ -1168,39 +1407,44 @@ function sortTsconfigContent(text) {
|
|
|
1168
1407
|
}
|
|
1169
1408
|
return JSON.stringify(outTop, null, 2);
|
|
1170
1409
|
}
|
|
1171
|
-
var CODE_EXTS, JSON_EXTS, YAML_EXTS, SHELL_EXTS, SHELL_SHEBANG_RE, RE_CLOSING_BRACE, RE_OPENING_BRACE, RE_FOR_LOOP, RE_EMPTY_SEMI, RE_DUP_SEMI, RE_SPACE_BEFORE_BRACE, RE_SPACE_AFTER_BRACE_KW, RE_COMMA_SPACE, RE_EQUALS_SPACE, RE_PLUS_OP, RE_MINUS_OP, RE_STAR_OP, RE_SLASH_OP, RE_SEMI_SPACE, RE_LT_OP, RE_GT_OP, RE_MULTI_SPACE, RE_BLANK_LINE, RE_LINE_COMMENT, RE_BLOCK_COMMENT, RE_IMPORT_STMT, RE_PACKAGE_JSON, RE_TSCONFIG_JSON, RE_TRAILING_WS, RE_LEADING_BLANKS, SPACING_CHARS;
|
|
1410
|
+
var CODE_EXTS, JSON_EXTS, YAML_EXTS, SHELL_EXTS, SHELL_SHEBANG_RE, RE_CLOSING_BRACE, RE_OPENING_BRACE, RE_TRAILING_LINE_COMMENT, RE_CONTROL_OPEN, RE_CONTINUATION_LINE, RE_FOR_LOOP, RE_EMPTY_SEMI, RE_DUP_SEMI, RE_SPACE_BEFORE_BRACE, RE_SPACE_AFTER_BRACE_KW, RE_COMMA_SPACE, RE_EQUALS_SPACE, RE_PLUS_OP, RE_MINUS_OP, RE_STAR_OP, RE_SLASH_OP, RE_SEMI_SPACE, RE_LT_OP, RE_GT_OP, RE_MULTI_SPACE, RE_BLANK_LINE, RE_LINE_COMMENT, RE_BLOCK_COMMENT, RE_IMPORT_STMT, RE_IMPORT_COMPLETE, RE_PACKAGE_JSON, RE_TSCONFIG_JSON, RE_TRAILING_WS, RE_LEADING_BLANKS, SPACING_CHARS, REGEX_PRECEDING_KEYWORDS;
|
|
1172
1411
|
var init_format = __esm(() => {
|
|
1173
1412
|
CODE_EXTS = new Set([".ts", ".js"]);
|
|
1174
1413
|
JSON_EXTS = new Set([".json", ".jsonc"]);
|
|
1175
1414
|
YAML_EXTS = new Set([".yaml", ".yml"]);
|
|
1176
1415
|
SHELL_EXTS = new Set([".sh", ".bash", ".zsh", ".ksh", ".dash"]);
|
|
1177
1416
|
SHELL_SHEBANG_RE = /^#!\s*(?:\/usr\/bin\/env\s+)?(?:ba|z|k|da)?sh\b/;
|
|
1178
|
-
RE_CLOSING_BRACE =
|
|
1179
|
-
RE_OPENING_BRACE =
|
|
1417
|
+
RE_CLOSING_BRACE = /^[}\])]/;
|
|
1418
|
+
RE_OPENING_BRACE = /[{[(]\s*$/;
|
|
1419
|
+
RE_TRAILING_LINE_COMMENT = /\s*\/\/.*$/;
|
|
1420
|
+
RE_CONTROL_OPEN = /^(?:if|else\s+if|for|while)\s*\(/;
|
|
1421
|
+
RE_CONTINUATION_LINE = /^(?:\.[\w$[]|\?[\s.:]|:\s|&&|\|\|)/;
|
|
1180
1422
|
RE_FOR_LOOP = /^\s*for\s*\(/;
|
|
1181
1423
|
RE_EMPTY_SEMI = new RegExp("^\\s*" + ";" + "\\s*$");
|
|
1182
1424
|
RE_DUP_SEMI = new RegExp(";" + "{2,}\\s*$");
|
|
1183
|
-
RE_SPACE_BEFORE_BRACE = /(\
|
|
1425
|
+
RE_SPACE_BEFORE_BRACE = /([\w)])\{/g;
|
|
1184
1426
|
RE_SPACE_AFTER_BRACE_KW = /\{(return|if|for|while|switch|const|let|var|function)\b/g;
|
|
1185
1427
|
RE_COMMA_SPACE = /,(\S)/g;
|
|
1186
|
-
RE_EQUALS_SPACE = /(?<![
|
|
1428
|
+
RE_EQUALS_SPACE = /(?<![=!<>+\-*/%&|^?])=(?![=><])/g;
|
|
1187
1429
|
RE_PLUS_OP = /(\w)\+(\w)/g;
|
|
1188
1430
|
RE_MINUS_OP = /(\w)-(\w)/g;
|
|
1189
1431
|
RE_STAR_OP = /(\w)\*(\w)/g;
|
|
1190
1432
|
RE_SLASH_OP = /(\w)\/(\w)/g;
|
|
1191
|
-
RE_SEMI_SPACE = new RegExp(";" + "([^\\s" + ";" + "])", "g");
|
|
1192
|
-
RE_LT_OP = /([\w\]
|
|
1193
|
-
RE_GT_OP = /(\
|
|
1433
|
+
RE_SEMI_SPACE = new RegExp("(?<=\\S);" + "([^\\s" + ";" + "])", "g");
|
|
1434
|
+
RE_LT_OP = /([\w)\]])<(\d)/g;
|
|
1435
|
+
RE_GT_OP = /([\w)\]])>(\d)/g;
|
|
1194
1436
|
RE_MULTI_SPACE = /\s{2,}/g;
|
|
1195
1437
|
RE_BLANK_LINE = /^\s*$/;
|
|
1196
1438
|
RE_LINE_COMMENT = /^\s*\/\//;
|
|
1197
1439
|
RE_BLOCK_COMMENT = /^\s*\/\*/;
|
|
1198
1440
|
RE_IMPORT_STMT = /^\s*import\b/;
|
|
1441
|
+
RE_IMPORT_COMPLETE = /\bfrom\s*['"][^'"]+['"]|^\s*import\s+['"][^'"]+['"]/;
|
|
1199
1442
|
RE_PACKAGE_JSON = /package\.json$/i;
|
|
1200
1443
|
RE_TSCONFIG_JSON = /[jt]sconfig(?:\..+)?\.json$/i;
|
|
1201
1444
|
RE_TRAILING_WS = /[ \t]+$/;
|
|
1202
1445
|
RE_LEADING_BLANKS = /^\n+/;
|
|
1203
1446
|
SPACING_CHARS = new Set(["{", ",", "=", "+", "-", "*", "/", ";", "<", ">"]);
|
|
1447
|
+
REGEX_PRECEDING_KEYWORDS = new Set(["return", "typeof", "instanceof", "in", "of", "new", "delete", "void", "do", "else", "case", "yield", "await"]);
|
|
1204
1448
|
});
|
|
1205
1449
|
|
|
1206
1450
|
// ../../node_modules/bunfig/dist/index.js
|
|
@@ -20767,7 +21011,7 @@ var init_no_unused_vars = __esm(() => {
|
|
|
20767
21011
|
let tInBlockComment = false;
|
|
20768
21012
|
let tEscaped = false;
|
|
20769
21013
|
let prevSig = "";
|
|
20770
|
-
const
|
|
21014
|
+
const isRegexStart2 = () => {
|
|
20771
21015
|
if (prevSig === "")
|
|
20772
21016
|
return true;
|
|
20773
21017
|
if ("=([{,;!&|?:+-*/%^~<>".includes(prevSig))
|
|
@@ -20869,7 +21113,7 @@ var init_no_unused_vars = __esm(() => {
|
|
|
20869
21113
|
else
|
|
20870
21114
|
tmplStack.pop();
|
|
20871
21115
|
prevSig = "}";
|
|
20872
|
-
} else if (ch === "/" &&
|
|
21116
|
+
} else if (ch === "/" && isRegexStart2()) {
|
|
20873
21117
|
tInRegex = true;
|
|
20874
21118
|
} else if (!/\s/.test(ch)) {
|
|
20875
21119
|
prevSig = ch;
|
|
@@ -20885,7 +21129,7 @@ var init_no_unused_vars = __esm(() => {
|
|
|
20885
21129
|
} else if (ch === '"') {
|
|
20886
21130
|
tInDouble = true;
|
|
20887
21131
|
prevSig = '"';
|
|
20888
|
-
} else if (ch === "/" &&
|
|
21132
|
+
} else if (ch === "/" && isRegexStart2()) {
|
|
20889
21133
|
tInRegex = true;
|
|
20890
21134
|
} else if (!/\s/.test(ch)) {
|
|
20891
21135
|
prevSig = ch;
|
|
@@ -22084,7 +22328,7 @@ function computeLineStartsInTemplate(text) {
|
|
|
22084
22328
|
let inBlockComment = false;
|
|
22085
22329
|
let escaped = false;
|
|
22086
22330
|
let prevSig = "";
|
|
22087
|
-
const
|
|
22331
|
+
const isRegexStart2 = () => {
|
|
22088
22332
|
if (prevSig === "")
|
|
22089
22333
|
return true;
|
|
22090
22334
|
return "=([{,;!&|?:+-*/%^~<>".includes(prevSig);
|
|
@@ -22184,7 +22428,7 @@ function computeLineStartsInTemplate(text) {
|
|
|
22184
22428
|
else
|
|
22185
22429
|
tmplStack.pop();
|
|
22186
22430
|
prevSig = "}";
|
|
22187
|
-
} else if (ch === "/" &&
|
|
22431
|
+
} else if (ch === "/" && isRegexStart2())
|
|
22188
22432
|
inRegex = true;
|
|
22189
22433
|
else if (!/\s/.test(ch))
|
|
22190
22434
|
prevSig = ch;
|
|
@@ -22199,7 +22443,7 @@ function computeLineStartsInTemplate(text) {
|
|
|
22199
22443
|
} else if (ch === '"') {
|
|
22200
22444
|
inDouble = true;
|
|
22201
22445
|
prevSig = '"';
|
|
22202
|
-
} else if (ch === "/" &&
|
|
22446
|
+
} else if (ch === "/" && isRegexStart2())
|
|
22203
22447
|
inRegex = true;
|
|
22204
22448
|
else if (!/\s/.test(ch))
|
|
22205
22449
|
prevSig = ch;
|
|
@@ -32845,7 +33089,7 @@ function findMatching(text, start, open, close) {
|
|
|
32845
33089
|
}
|
|
32846
33090
|
return i;
|
|
32847
33091
|
};
|
|
32848
|
-
const
|
|
33092
|
+
const isRegexStart2 = (i) => {
|
|
32849
33093
|
let j = i - 1;
|
|
32850
33094
|
while (j >= 0 && isWhitespace(text[j])) {
|
|
32851
33095
|
j--;
|
|
@@ -32901,7 +33145,7 @@ function findMatching(text, start, open, close) {
|
|
|
32901
33145
|
i = skipBlockComment(i) - 1;
|
|
32902
33146
|
continue;
|
|
32903
33147
|
}
|
|
32904
|
-
if (ch === "/" &&
|
|
33148
|
+
if (ch === "/" && isRegexStart2(i)) {
|
|
32905
33149
|
i = skipRegex(i) - 1;
|
|
32906
33150
|
continue;
|
|
32907
33151
|
}
|
|
@@ -38678,7 +38922,7 @@ function stripRegexLiterals(line) {
|
|
|
38678
38922
|
}
|
|
38679
38923
|
return result;
|
|
38680
38924
|
}
|
|
38681
|
-
function
|
|
38925
|
+
function isRegexStart2(lastSignificant, line, idx) {
|
|
38682
38926
|
if (lastSignificant === "")
|
|
38683
38927
|
return true;
|
|
38684
38928
|
const regexAfter = "([{,:;!?&|=<>~^+*%-";
|
|
@@ -39101,7 +39345,7 @@ function scanContentOptimized(filePath, content, cfg, suppress, commentLines) {
|
|
|
39101
39345
|
prev = ch;
|
|
39102
39346
|
continue;
|
|
39103
39347
|
}
|
|
39104
|
-
if (ch === "/" && ln[k + 1] !== "/" && ln[k + 1] !== "*" &&
|
|
39348
|
+
if (ch === "/" && ln[k + 1] !== "/" && ln[k + 1] !== "*" && isRegexStart2(lastSig, ln, k)) {
|
|
39105
39349
|
inRegex = true;
|
|
39106
39350
|
inRegexClass = false;
|
|
39107
39351
|
prev = ch;
|
|
@@ -43690,7 +43934,7 @@ var require_package = __commonJS((exports, module) => {
|
|
|
43690
43934
|
module.exports = {
|
|
43691
43935
|
name: "pickier",
|
|
43692
43936
|
type: "module",
|
|
43693
|
-
version: "0.1.
|
|
43937
|
+
version: "0.1.35",
|
|
43694
43938
|
description: "Format, lint and more in a fraction of seconds.",
|
|
43695
43939
|
author: "Chris Breuer <chris@stacksjs.org>",
|
|
43696
43940
|
license: "MIT",
|
package/dist/src/index.js
CHANGED
|
@@ -8882,6 +8882,37 @@ var init_config = __esm(() => {
|
|
|
8882
8882
|
});
|
|
8883
8883
|
|
|
8884
8884
|
// src/format.ts
|
|
8885
|
+
function isHangingControlLine(code) {
|
|
8886
|
+
const m = RE_CONTROL_OPEN.exec(code);
|
|
8887
|
+
if (!m)
|
|
8888
|
+
return /^(?:else|do)\s*$/.test(code);
|
|
8889
|
+
let depth = 0;
|
|
8890
|
+
let inStr = null;
|
|
8891
|
+
for (let i = m[0].length - 1;i < code.length; i++) {
|
|
8892
|
+
const ch = code[i];
|
|
8893
|
+
if (inStr) {
|
|
8894
|
+
if (ch === "\\") {
|
|
8895
|
+
i++;
|
|
8896
|
+
continue;
|
|
8897
|
+
}
|
|
8898
|
+
if (ch === inStr)
|
|
8899
|
+
inStr = null;
|
|
8900
|
+
continue;
|
|
8901
|
+
}
|
|
8902
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
8903
|
+
inStr = ch;
|
|
8904
|
+
continue;
|
|
8905
|
+
}
|
|
8906
|
+
if (ch === "(") {
|
|
8907
|
+
depth++;
|
|
8908
|
+
} else if (ch === ")") {
|
|
8909
|
+
depth--;
|
|
8910
|
+
if (depth === 0)
|
|
8911
|
+
return code.slice(i + 1).trim().length === 0;
|
|
8912
|
+
}
|
|
8913
|
+
}
|
|
8914
|
+
return false;
|
|
8915
|
+
}
|
|
8885
8916
|
function getFileExt(filePath) {
|
|
8886
8917
|
const idx = filePath.lastIndexOf(".");
|
|
8887
8918
|
return idx >= 0 ? filePath.slice(idx) : "";
|
|
@@ -9032,6 +9063,25 @@ function fixQuotesLine(line, preferred) {
|
|
|
9032
9063
|
while (i < line.length) {
|
|
9033
9064
|
const ch = line[i];
|
|
9034
9065
|
if (inString === 0) {
|
|
9066
|
+
if (ch === "/") {
|
|
9067
|
+
const nxt = line[i + 1];
|
|
9068
|
+
if (nxt === "/")
|
|
9069
|
+
break;
|
|
9070
|
+
if (nxt === "*") {
|
|
9071
|
+
const end = line.indexOf("*/", i + 2);
|
|
9072
|
+
i = end === -1 ? line.length : end + 2;
|
|
9073
|
+
continue;
|
|
9074
|
+
}
|
|
9075
|
+
if (isRegexStart(line, i)) {
|
|
9076
|
+
const end = scanRegexEnd(line, i);
|
|
9077
|
+
if (end !== -1) {
|
|
9078
|
+
i = end;
|
|
9079
|
+
continue;
|
|
9080
|
+
}
|
|
9081
|
+
}
|
|
9082
|
+
i++;
|
|
9083
|
+
continue;
|
|
9084
|
+
}
|
|
9035
9085
|
if (ch === '"') {
|
|
9036
9086
|
inString = 2;
|
|
9037
9087
|
stringStart = i;
|
|
@@ -9099,6 +9149,8 @@ function normalizeSpacingLine(line) {
|
|
|
9099
9149
|
const c = line[firstNonSpace];
|
|
9100
9150
|
if (c === "/" && (line[firstNonSpace + 1] === "/" || line[firstNonSpace + 1] === "*"))
|
|
9101
9151
|
return line;
|
|
9152
|
+
if (c === "*")
|
|
9153
|
+
return line;
|
|
9102
9154
|
}
|
|
9103
9155
|
let hasSpacingChar = false;
|
|
9104
9156
|
for (let j = firstNonSpace;j < line.length; j++) {
|
|
@@ -9211,6 +9263,49 @@ function advanceTemplateState(line, stack) {
|
|
|
9211
9263
|
}
|
|
9212
9264
|
return -1;
|
|
9213
9265
|
}
|
|
9266
|
+
function blockCommentStateAfter(line, startsIn) {
|
|
9267
|
+
let inBlock = startsIn;
|
|
9268
|
+
let inStr = null;
|
|
9269
|
+
let i = 0;
|
|
9270
|
+
while (i < line.length) {
|
|
9271
|
+
const ch = line[i];
|
|
9272
|
+
if (inBlock) {
|
|
9273
|
+
if (ch === "*" && line[i + 1] === "/") {
|
|
9274
|
+
inBlock = false;
|
|
9275
|
+
i += 2;
|
|
9276
|
+
continue;
|
|
9277
|
+
}
|
|
9278
|
+
i++;
|
|
9279
|
+
continue;
|
|
9280
|
+
}
|
|
9281
|
+
if (inStr) {
|
|
9282
|
+
if (ch === "\\") {
|
|
9283
|
+
i += 2;
|
|
9284
|
+
continue;
|
|
9285
|
+
}
|
|
9286
|
+
if (ch === inStr)
|
|
9287
|
+
inStr = null;
|
|
9288
|
+
i++;
|
|
9289
|
+
continue;
|
|
9290
|
+
}
|
|
9291
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
9292
|
+
inStr = ch;
|
|
9293
|
+
i++;
|
|
9294
|
+
continue;
|
|
9295
|
+
}
|
|
9296
|
+
if (ch === "/") {
|
|
9297
|
+
if (line[i + 1] === "/")
|
|
9298
|
+
break;
|
|
9299
|
+
if (line[i + 1] === "*") {
|
|
9300
|
+
inBlock = true;
|
|
9301
|
+
i += 2;
|
|
9302
|
+
continue;
|
|
9303
|
+
}
|
|
9304
|
+
}
|
|
9305
|
+
i++;
|
|
9306
|
+
}
|
|
9307
|
+
return inBlock;
|
|
9308
|
+
}
|
|
9214
9309
|
function processCodeLinesFused(content, cfg) {
|
|
9215
9310
|
const lines = content.split(`
|
|
9216
9311
|
`);
|
|
@@ -9219,9 +9314,16 @@ function processCodeLinesFused(content, cfg) {
|
|
|
9219
9314
|
const preferred = cfg.format.quotes;
|
|
9220
9315
|
const doSemiRemoval = cfg.format.semi === true;
|
|
9221
9316
|
let indentLevel = 0;
|
|
9317
|
+
let hangDepth = 0;
|
|
9318
|
+
let inBlockComment = false;
|
|
9222
9319
|
const tmplStack = [];
|
|
9223
9320
|
for (let idx = 0;idx < len; idx++) {
|
|
9224
9321
|
let line = lines[idx];
|
|
9322
|
+
if (inBlockComment) {
|
|
9323
|
+
inBlockComment = blockCommentStateAfter(line, true);
|
|
9324
|
+
result[idx] = line;
|
|
9325
|
+
continue;
|
|
9326
|
+
}
|
|
9225
9327
|
const protectedLine = inTemplateText(tmplStack);
|
|
9226
9328
|
let splitIdx = -1;
|
|
9227
9329
|
if (tmplStack.length > 0 || line.indexOf("`") !== -1)
|
|
@@ -9230,6 +9332,8 @@ function processCodeLinesFused(content, cfg) {
|
|
|
9230
9332
|
result[idx] = line;
|
|
9231
9333
|
continue;
|
|
9232
9334
|
}
|
|
9335
|
+
if (splitIdx < 0 && tmplStack.length === 0)
|
|
9336
|
+
inBlockComment = blockCommentStateAfter(line, false);
|
|
9233
9337
|
let tmplTail = "";
|
|
9234
9338
|
let prefixEndedWithSpace = false;
|
|
9235
9339
|
if (splitIdx >= 0) {
|
|
@@ -9253,9 +9357,15 @@ function processCodeLinesFused(content, cfg) {
|
|
|
9253
9357
|
const trimmed = line.slice(wsEnd).trimEnd();
|
|
9254
9358
|
if (RE_CLOSING_BRACE.test(trimmed))
|
|
9255
9359
|
indentLevel = Math.max(0, indentLevel - 1);
|
|
9256
|
-
|
|
9257
|
-
|
|
9360
|
+
const continuationBump = RE_CONTINUATION_LINE.test(trimmed) ? 1 : 0;
|
|
9361
|
+
line = makeIndent(indentLevel + hangDepth + continuationBump, cfg) + trimmed;
|
|
9362
|
+
if (RE_OPENING_BRACE.test(trimmed)) {
|
|
9258
9363
|
indentLevel += 1;
|
|
9364
|
+
hangDepth = 0;
|
|
9365
|
+
} else if (!trimmed.startsWith("//") && !trimmed.startsWith("*") && !trimmed.startsWith("/*")) {
|
|
9366
|
+
const code = trimmed.replace(RE_TRAILING_LINE_COMMENT, "");
|
|
9367
|
+
hangDepth = isHangingControlLine(code) ? hangDepth + 1 : 0;
|
|
9368
|
+
}
|
|
9259
9369
|
line = normalizeSpacingLine(line);
|
|
9260
9370
|
if (doSemiRemoval) {
|
|
9261
9371
|
if (!RE_FOR_LOOP.test(line)) {
|
|
@@ -9487,8 +9597,48 @@ function skipTemplate(input, start) {
|
|
|
9487
9597
|
}
|
|
9488
9598
|
return i;
|
|
9489
9599
|
}
|
|
9600
|
+
function isRegexStart(input, slashIdx) {
|
|
9601
|
+
let j = slashIdx - 1;
|
|
9602
|
+
while (j >= 0 && (input[j] === " " || input[j] === "\t"))
|
|
9603
|
+
j--;
|
|
9604
|
+
if (j < 0)
|
|
9605
|
+
return true;
|
|
9606
|
+
const prev = input[j];
|
|
9607
|
+
if ("(,=:[!&|?;{}<>+-*%^~".includes(prev))
|
|
9608
|
+
return true;
|
|
9609
|
+
if (/[\w$]/.test(prev)) {
|
|
9610
|
+
let k = j;
|
|
9611
|
+
while (k >= 0 && /[\w$]/.test(input[k]))
|
|
9612
|
+
k--;
|
|
9613
|
+
return REGEX_PRECEDING_KEYWORDS.has(input.slice(k + 1, j + 1));
|
|
9614
|
+
}
|
|
9615
|
+
return false;
|
|
9616
|
+
}
|
|
9617
|
+
function scanRegexEnd(input, start) {
|
|
9618
|
+
let i = start + 1;
|
|
9619
|
+
let inClass = false;
|
|
9620
|
+
while (i < input.length) {
|
|
9621
|
+
const c = input[i];
|
|
9622
|
+
if (c === "\\") {
|
|
9623
|
+
i += 2;
|
|
9624
|
+
continue;
|
|
9625
|
+
}
|
|
9626
|
+
if (c === "[") {
|
|
9627
|
+
inClass = true;
|
|
9628
|
+
} else if (c === "]") {
|
|
9629
|
+
inClass = false;
|
|
9630
|
+
} else if (c === "/" && !inClass) {
|
|
9631
|
+
i++;
|
|
9632
|
+
while (i < input.length && /[a-z]/i.test(input[i]))
|
|
9633
|
+
i++;
|
|
9634
|
+
return i;
|
|
9635
|
+
}
|
|
9636
|
+
i++;
|
|
9637
|
+
}
|
|
9638
|
+
return -1;
|
|
9639
|
+
}
|
|
9490
9640
|
function maskStrings(input) {
|
|
9491
|
-
if (!input.includes("'") && !input.includes('"') && !input.includes("`"))
|
|
9641
|
+
if (!input.includes("'") && !input.includes('"') && !input.includes("`") && !input.includes("/"))
|
|
9492
9642
|
return { text: input, strings: [] };
|
|
9493
9643
|
const strings = [];
|
|
9494
9644
|
const parts = [];
|
|
@@ -9496,6 +9646,42 @@ function maskStrings(input) {
|
|
|
9496
9646
|
let segStart = 0;
|
|
9497
9647
|
while (i < input.length) {
|
|
9498
9648
|
const ch = input[i];
|
|
9649
|
+
if (ch === "/") {
|
|
9650
|
+
const next = input[i + 1];
|
|
9651
|
+
if (next === "/") {
|
|
9652
|
+
if (i > segStart)
|
|
9653
|
+
parts.push(input.slice(segStart, i));
|
|
9654
|
+
strings.push(input.slice(i));
|
|
9655
|
+
parts.push(`@@S${strings.length - 1}@@`);
|
|
9656
|
+
segStart = input.length;
|
|
9657
|
+
break;
|
|
9658
|
+
}
|
|
9659
|
+
if (next === "*") {
|
|
9660
|
+
const end = input.indexOf("*/", i + 2);
|
|
9661
|
+
const stop = end === -1 ? input.length : end + 2;
|
|
9662
|
+
if (i > segStart)
|
|
9663
|
+
parts.push(input.slice(segStart, i));
|
|
9664
|
+
strings.push(input.slice(i, stop));
|
|
9665
|
+
parts.push(`@@S${strings.length - 1}@@`);
|
|
9666
|
+
i = stop;
|
|
9667
|
+
segStart = i;
|
|
9668
|
+
continue;
|
|
9669
|
+
}
|
|
9670
|
+
if (isRegexStart(input, i)) {
|
|
9671
|
+
const end = scanRegexEnd(input, i);
|
|
9672
|
+
if (end !== -1) {
|
|
9673
|
+
if (i > segStart)
|
|
9674
|
+
parts.push(input.slice(segStart, i));
|
|
9675
|
+
strings.push(input.slice(i, end));
|
|
9676
|
+
parts.push(`@@S${strings.length - 1}@@`);
|
|
9677
|
+
i = end;
|
|
9678
|
+
segStart = i;
|
|
9679
|
+
continue;
|
|
9680
|
+
}
|
|
9681
|
+
}
|
|
9682
|
+
i++;
|
|
9683
|
+
continue;
|
|
9684
|
+
}
|
|
9499
9685
|
if (ch === "'" || ch === '"' || ch === "`") {
|
|
9500
9686
|
if (i > segStart)
|
|
9501
9687
|
parts.push(input.slice(segStart, i));
|
|
@@ -9551,24 +9737,65 @@ function formatImports(source) {
|
|
|
9551
9737
|
const lines = source.split(`
|
|
9552
9738
|
`);
|
|
9553
9739
|
const imports = [];
|
|
9740
|
+
const preamble = [];
|
|
9741
|
+
const interleaved = [];
|
|
9554
9742
|
let idx = 0;
|
|
9743
|
+
let lastEnd = 0;
|
|
9744
|
+
let pendingStart = -1;
|
|
9745
|
+
let sawImport = false;
|
|
9555
9746
|
while (idx < lines.length) {
|
|
9556
9747
|
const line = lines[idx];
|
|
9557
|
-
if (RE_BLANK_LINE.test(line)
|
|
9748
|
+
if (RE_BLANK_LINE.test(line)) {
|
|
9558
9749
|
idx++;
|
|
9559
9750
|
continue;
|
|
9560
9751
|
}
|
|
9752
|
+
if (RE_LINE_COMMENT.test(line) || RE_BLOCK_COMMENT.test(line)) {
|
|
9753
|
+
const start = idx;
|
|
9754
|
+
if (RE_BLOCK_COMMENT.test(line)) {
|
|
9755
|
+
while (idx < lines.length && !lines[idx].includes("*/"))
|
|
9756
|
+
idx++;
|
|
9757
|
+
idx++;
|
|
9758
|
+
} else {
|
|
9759
|
+
idx++;
|
|
9760
|
+
}
|
|
9761
|
+
if (!sawImport) {
|
|
9762
|
+
for (let k = start;k < idx && k < lines.length; k++)
|
|
9763
|
+
preamble.push(lines[k]);
|
|
9764
|
+
lastEnd = idx;
|
|
9765
|
+
} else if (pendingStart < 0) {
|
|
9766
|
+
pendingStart = start;
|
|
9767
|
+
}
|
|
9768
|
+
continue;
|
|
9769
|
+
}
|
|
9561
9770
|
if (!RE_IMPORT_STMT.test(line))
|
|
9562
9771
|
break;
|
|
9563
|
-
|
|
9772
|
+
let stmt = line.trim();
|
|
9773
|
+
let stmtEnd = idx + 1;
|
|
9774
|
+
while (!RE_IMPORT_COMPLETE.test(stmt) && stmtEnd < lines.length && stmtEnd - idx < 50) {
|
|
9775
|
+
stmt += ` ${lines[stmtEnd].trim()}`;
|
|
9776
|
+
stmtEnd++;
|
|
9777
|
+
}
|
|
9778
|
+
if (!RE_IMPORT_COMPLETE.test(stmt))
|
|
9779
|
+
return source;
|
|
9564
9780
|
const parsed = parseImportStatement(stmt);
|
|
9565
|
-
if (parsed)
|
|
9566
|
-
|
|
9567
|
-
|
|
9781
|
+
if (!parsed)
|
|
9782
|
+
return source;
|
|
9783
|
+
if (pendingStart >= 0) {
|
|
9784
|
+
for (let k = pendingStart;k < idx; k++) {
|
|
9785
|
+
if (!RE_BLANK_LINE.test(lines[k]))
|
|
9786
|
+
interleaved.push(lines[k]);
|
|
9787
|
+
}
|
|
9788
|
+
pendingStart = -1;
|
|
9789
|
+
}
|
|
9790
|
+
imports.push(parsed);
|
|
9791
|
+
idx = stmtEnd;
|
|
9792
|
+
lastEnd = idx;
|
|
9793
|
+
sawImport = true;
|
|
9568
9794
|
}
|
|
9569
9795
|
if (imports.length === 0)
|
|
9570
9796
|
return source;
|
|
9571
|
-
const
|
|
9797
|
+
const restStart = pendingStart >= 0 ? pendingStart : lastEnd;
|
|
9798
|
+
const rest = lines.slice(restStart).join(`
|
|
9572
9799
|
`);
|
|
9573
9800
|
const usedIdentifiers = collectIdentifierSet(rest);
|
|
9574
9801
|
const used = (name) => usedIdentifiers.has(name);
|
|
@@ -9689,17 +9916,29 @@ function formatImports(source) {
|
|
|
9689
9916
|
}
|
|
9690
9917
|
return a.source.localeCompare(b.source);
|
|
9691
9918
|
});
|
|
9919
|
+
const head = preamble.length > 0 ? `${preamble.join(`
|
|
9920
|
+
`)}
|
|
9921
|
+
` : "";
|
|
9692
9922
|
if (entries.length === 0) {
|
|
9693
|
-
|
|
9923
|
+
const restClean2 = rest.replace(/^\n+/, "");
|
|
9924
|
+
const kept = [...interleaved];
|
|
9925
|
+
if (head || kept.length > 0)
|
|
9926
|
+
return `${head}${kept.length > 0 ? `${kept.join(`
|
|
9927
|
+
`)}
|
|
9928
|
+
` : ""}${restClean2}`;
|
|
9929
|
+
return restClean2;
|
|
9694
9930
|
}
|
|
9695
9931
|
const rendered = entries.map(renderImport).join(`
|
|
9696
9932
|
`);
|
|
9697
|
-
const
|
|
9698
|
-
`
|
|
9933
|
+
const mid = interleaved.length > 0 ? `
|
|
9934
|
+
${interleaved.join(`
|
|
9935
|
+
`)}` : "";
|
|
9936
|
+
const restClean = rest.replace(/^\n+/, "");
|
|
9937
|
+
const sep = restClean.length > 0 ? `
|
|
9699
9938
|
|
|
9700
9939
|
` : `
|
|
9701
9940
|
`;
|
|
9702
|
-
return `${rendered}${sep}${
|
|
9941
|
+
return `${head}${rendered}${mid}${sep}${restClean}`;
|
|
9703
9942
|
}
|
|
9704
9943
|
function renderImport(imp) {
|
|
9705
9944
|
if (imp.kind === "side-effect")
|
|
@@ -10002,39 +10241,44 @@ function sortTsconfigContent(text) {
|
|
|
10002
10241
|
}
|
|
10003
10242
|
return JSON.stringify(outTop, null, 2);
|
|
10004
10243
|
}
|
|
10005
|
-
var CODE_EXTS, JSON_EXTS, YAML_EXTS, SHELL_EXTS, SHELL_SHEBANG_RE, RE_CLOSING_BRACE, RE_OPENING_BRACE, RE_FOR_LOOP, RE_EMPTY_SEMI, RE_DUP_SEMI, RE_SPACE_BEFORE_BRACE, RE_SPACE_AFTER_BRACE_KW, RE_COMMA_SPACE, RE_EQUALS_SPACE, RE_PLUS_OP, RE_MINUS_OP, RE_STAR_OP, RE_SLASH_OP, RE_SEMI_SPACE, RE_LT_OP, RE_GT_OP, RE_MULTI_SPACE, RE_BLANK_LINE, RE_LINE_COMMENT, RE_BLOCK_COMMENT, RE_IMPORT_STMT, RE_PACKAGE_JSON, RE_TSCONFIG_JSON, RE_TRAILING_WS, RE_LEADING_BLANKS, SPACING_CHARS;
|
|
10244
|
+
var CODE_EXTS, JSON_EXTS, YAML_EXTS, SHELL_EXTS, SHELL_SHEBANG_RE, RE_CLOSING_BRACE, RE_OPENING_BRACE, RE_TRAILING_LINE_COMMENT, RE_CONTROL_OPEN, RE_CONTINUATION_LINE, RE_FOR_LOOP, RE_EMPTY_SEMI, RE_DUP_SEMI, RE_SPACE_BEFORE_BRACE, RE_SPACE_AFTER_BRACE_KW, RE_COMMA_SPACE, RE_EQUALS_SPACE, RE_PLUS_OP, RE_MINUS_OP, RE_STAR_OP, RE_SLASH_OP, RE_SEMI_SPACE, RE_LT_OP, RE_GT_OP, RE_MULTI_SPACE, RE_BLANK_LINE, RE_LINE_COMMENT, RE_BLOCK_COMMENT, RE_IMPORT_STMT, RE_IMPORT_COMPLETE, RE_PACKAGE_JSON, RE_TSCONFIG_JSON, RE_TRAILING_WS, RE_LEADING_BLANKS, SPACING_CHARS, REGEX_PRECEDING_KEYWORDS;
|
|
10006
10245
|
var init_format = __esm(() => {
|
|
10007
10246
|
CODE_EXTS = new Set([".ts", ".js"]);
|
|
10008
10247
|
JSON_EXTS = new Set([".json", ".jsonc"]);
|
|
10009
10248
|
YAML_EXTS = new Set([".yaml", ".yml"]);
|
|
10010
10249
|
SHELL_EXTS = new Set([".sh", ".bash", ".zsh", ".ksh", ".dash"]);
|
|
10011
10250
|
SHELL_SHEBANG_RE = /^#!\s*(?:\/usr\/bin\/env\s+)?(?:ba|z|k|da)?sh\b/;
|
|
10012
|
-
RE_CLOSING_BRACE =
|
|
10013
|
-
RE_OPENING_BRACE =
|
|
10251
|
+
RE_CLOSING_BRACE = /^[}\])]/;
|
|
10252
|
+
RE_OPENING_BRACE = /[{[(]\s*$/;
|
|
10253
|
+
RE_TRAILING_LINE_COMMENT = /\s*\/\/.*$/;
|
|
10254
|
+
RE_CONTROL_OPEN = /^(?:if|else\s+if|for|while)\s*\(/;
|
|
10255
|
+
RE_CONTINUATION_LINE = /^(?:\.[\w$[]|\?[\s.:]|:\s|&&|\|\|)/;
|
|
10014
10256
|
RE_FOR_LOOP = /^\s*for\s*\(/;
|
|
10015
10257
|
RE_EMPTY_SEMI = new RegExp("^\\s*" + ";" + "\\s*$");
|
|
10016
10258
|
RE_DUP_SEMI = new RegExp(";" + "{2,}\\s*$");
|
|
10017
|
-
RE_SPACE_BEFORE_BRACE = /(\
|
|
10259
|
+
RE_SPACE_BEFORE_BRACE = /([\w)])\{/g;
|
|
10018
10260
|
RE_SPACE_AFTER_BRACE_KW = /\{(return|if|for|while|switch|const|let|var|function)\b/g;
|
|
10019
10261
|
RE_COMMA_SPACE = /,(\S)/g;
|
|
10020
|
-
RE_EQUALS_SPACE = /(?<![
|
|
10262
|
+
RE_EQUALS_SPACE = /(?<![=!<>+\-*/%&|^?])=(?![=><])/g;
|
|
10021
10263
|
RE_PLUS_OP = /(\w)\+(\w)/g;
|
|
10022
10264
|
RE_MINUS_OP = /(\w)-(\w)/g;
|
|
10023
10265
|
RE_STAR_OP = /(\w)\*(\w)/g;
|
|
10024
10266
|
RE_SLASH_OP = /(\w)\/(\w)/g;
|
|
10025
|
-
RE_SEMI_SPACE = new RegExp(";" + "([^\\s" + ";" + "])", "g");
|
|
10026
|
-
RE_LT_OP = /([\w\]
|
|
10027
|
-
RE_GT_OP = /(\
|
|
10267
|
+
RE_SEMI_SPACE = new RegExp("(?<=\\S);" + "([^\\s" + ";" + "])", "g");
|
|
10268
|
+
RE_LT_OP = /([\w)\]])<(\d)/g;
|
|
10269
|
+
RE_GT_OP = /([\w)\]])>(\d)/g;
|
|
10028
10270
|
RE_MULTI_SPACE = /\s{2,}/g;
|
|
10029
10271
|
RE_BLANK_LINE = /^\s*$/;
|
|
10030
10272
|
RE_LINE_COMMENT = /^\s*\/\//;
|
|
10031
10273
|
RE_BLOCK_COMMENT = /^\s*\/\*/;
|
|
10032
10274
|
RE_IMPORT_STMT = /^\s*import\b/;
|
|
10275
|
+
RE_IMPORT_COMPLETE = /\bfrom\s*['"][^'"]+['"]|^\s*import\s+['"][^'"]+['"]/;
|
|
10033
10276
|
RE_PACKAGE_JSON = /package\.json$/i;
|
|
10034
10277
|
RE_TSCONFIG_JSON = /[jt]sconfig(?:\..+)?\.json$/i;
|
|
10035
10278
|
RE_TRAILING_WS = /[ \t]+$/;
|
|
10036
10279
|
RE_LEADING_BLANKS = /^\n+/;
|
|
10037
10280
|
SPACING_CHARS = new Set(["{", ",", "=", "+", "-", "*", "/", ";", "<", ">"]);
|
|
10281
|
+
REGEX_PRECEDING_KEYWORDS = new Set(["return", "typeof", "instanceof", "in", "of", "new", "delete", "void", "do", "else", "case", "yield", "await"]);
|
|
10038
10282
|
});
|
|
10039
10283
|
|
|
10040
10284
|
// ../../node_modules/@stacksjs/clarity/dist/src/index.js
|
|
@@ -20365,7 +20609,7 @@ var init_no_unused_vars = __esm(() => {
|
|
|
20365
20609
|
let tInBlockComment = false;
|
|
20366
20610
|
let tEscaped = false;
|
|
20367
20611
|
let prevSig = "";
|
|
20368
|
-
const
|
|
20612
|
+
const isRegexStart2 = () => {
|
|
20369
20613
|
if (prevSig === "")
|
|
20370
20614
|
return true;
|
|
20371
20615
|
if ("=([{,;!&|?:+-*/%^~<>".includes(prevSig))
|
|
@@ -20467,7 +20711,7 @@ var init_no_unused_vars = __esm(() => {
|
|
|
20467
20711
|
else
|
|
20468
20712
|
tmplStack.pop();
|
|
20469
20713
|
prevSig = "}";
|
|
20470
|
-
} else if (ch === "/" &&
|
|
20714
|
+
} else if (ch === "/" && isRegexStart2()) {
|
|
20471
20715
|
tInRegex = true;
|
|
20472
20716
|
} else if (!/\s/.test(ch)) {
|
|
20473
20717
|
prevSig = ch;
|
|
@@ -20483,7 +20727,7 @@ var init_no_unused_vars = __esm(() => {
|
|
|
20483
20727
|
} else if (ch === '"') {
|
|
20484
20728
|
tInDouble = true;
|
|
20485
20729
|
prevSig = '"';
|
|
20486
|
-
} else if (ch === "/" &&
|
|
20730
|
+
} else if (ch === "/" && isRegexStart2()) {
|
|
20487
20731
|
tInRegex = true;
|
|
20488
20732
|
} else if (!/\s/.test(ch)) {
|
|
20489
20733
|
prevSig = ch;
|
|
@@ -21682,7 +21926,7 @@ function computeLineStartsInTemplate(text) {
|
|
|
21682
21926
|
let inBlockComment = false;
|
|
21683
21927
|
let escaped = false;
|
|
21684
21928
|
let prevSig = "";
|
|
21685
|
-
const
|
|
21929
|
+
const isRegexStart2 = () => {
|
|
21686
21930
|
if (prevSig === "")
|
|
21687
21931
|
return true;
|
|
21688
21932
|
return "=([{,;!&|?:+-*/%^~<>".includes(prevSig);
|
|
@@ -21782,7 +22026,7 @@ function computeLineStartsInTemplate(text) {
|
|
|
21782
22026
|
else
|
|
21783
22027
|
tmplStack.pop();
|
|
21784
22028
|
prevSig = "}";
|
|
21785
|
-
} else if (ch === "/" &&
|
|
22029
|
+
} else if (ch === "/" && isRegexStart2())
|
|
21786
22030
|
inRegex = true;
|
|
21787
22031
|
else if (!/\s/.test(ch))
|
|
21788
22032
|
prevSig = ch;
|
|
@@ -21797,7 +22041,7 @@ function computeLineStartsInTemplate(text) {
|
|
|
21797
22041
|
} else if (ch === '"') {
|
|
21798
22042
|
inDouble = true;
|
|
21799
22043
|
prevSig = '"';
|
|
21800
|
-
} else if (ch === "/" &&
|
|
22044
|
+
} else if (ch === "/" && isRegexStart2())
|
|
21801
22045
|
inRegex = true;
|
|
21802
22046
|
else if (!/\s/.test(ch))
|
|
21803
22047
|
prevSig = ch;
|
|
@@ -32443,7 +32687,7 @@ function findMatching(text, start, open, close) {
|
|
|
32443
32687
|
}
|
|
32444
32688
|
return i;
|
|
32445
32689
|
};
|
|
32446
|
-
const
|
|
32690
|
+
const isRegexStart2 = (i) => {
|
|
32447
32691
|
let j = i - 1;
|
|
32448
32692
|
while (j >= 0 && isWhitespace(text[j])) {
|
|
32449
32693
|
j--;
|
|
@@ -32499,7 +32743,7 @@ function findMatching(text, start, open, close) {
|
|
|
32499
32743
|
i = skipBlockComment(i) - 1;
|
|
32500
32744
|
continue;
|
|
32501
32745
|
}
|
|
32502
|
-
if (ch === "/" &&
|
|
32746
|
+
if (ch === "/" && isRegexStart2(i)) {
|
|
32503
32747
|
i = skipRegex(i) - 1;
|
|
32504
32748
|
continue;
|
|
32505
32749
|
}
|
|
@@ -38677,7 +38921,7 @@ function stripRegexLiterals(line) {
|
|
|
38677
38921
|
}
|
|
38678
38922
|
return result;
|
|
38679
38923
|
}
|
|
38680
|
-
function
|
|
38924
|
+
function isRegexStart2(lastSignificant, line, idx) {
|
|
38681
38925
|
if (lastSignificant === "")
|
|
38682
38926
|
return true;
|
|
38683
38927
|
const regexAfter = "([{,:;!?&|=<>~^+*%-";
|
|
@@ -39100,7 +39344,7 @@ function scanContentOptimized(filePath, content, cfg, suppress, commentLines) {
|
|
|
39100
39344
|
prev = ch;
|
|
39101
39345
|
continue;
|
|
39102
39346
|
}
|
|
39103
|
-
if (ch === "/" && ln[k + 1] !== "/" && ln[k + 1] !== "*" &&
|
|
39347
|
+
if (ch === "/" && ln[k + 1] !== "/" && ln[k + 1] !== "*" && isRegexStart2(lastSig, ln, k)) {
|
|
39104
39348
|
inRegex = true;
|
|
39105
39349
|
inRegexClass = false;
|
|
39106
39350
|
prev = ch;
|