@codefast/cli 0.5.0-canary.5 → 1.0.0-canary.7
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/README.md +106 -480
- package/dist/arrange/analyze.js +25 -0
- package/dist/arrange/analyze.js.map +1 -0
- package/dist/arrange/cli-schema.js +29 -0
- package/dist/arrange/cli-schema.js.map +1 -0
- package/dist/arrange/command.js +170 -0
- package/dist/arrange/command.js.map +1 -0
- package/dist/arrange/domain/analyze-service.js +122 -0
- package/dist/arrange/domain/analyze-service.js.map +1 -0
- package/dist/arrange/domain/ast/ast-node.js +240 -0
- package/dist/arrange/domain/ast/ast-node.js.map +1 -0
- package/dist/arrange/domain/ast/collectors-cn.js +81 -0
- package/dist/arrange/domain/ast/collectors-cn.js.map +1 -0
- package/dist/arrange/domain/ast/collectors-jsx.js +24 -0
- package/dist/arrange/domain/ast/collectors-jsx.js.map +1 -0
- package/dist/arrange/domain/ast/collectors-tv.js +319 -0
- package/dist/arrange/domain/ast/collectors-tv.js.map +1 -0
- package/dist/arrange/domain/ast/helpers.js +151 -0
- package/dist/arrange/domain/ast/helpers.js.map +1 -0
- package/dist/arrange/domain/ast/simplify-targets.js +161 -0
- package/dist/arrange/domain/ast/simplify-targets.js.map +1 -0
- package/dist/arrange/domain/ast/targets.js +182 -0
- package/dist/arrange/domain/ast/targets.js.map +1 -0
- package/dist/arrange/domain/constants.js +225 -0
- package/dist/arrange/domain/constants.js.map +1 -0
- package/dist/arrange/domain/grouping-service.js +128 -0
- package/dist/arrange/domain/grouping-service.js.map +1 -0
- package/dist/arrange/domain/grouping.js +435 -0
- package/dist/arrange/domain/grouping.js.map +1 -0
- package/dist/arrange/domain/imports.js +160 -0
- package/dist/arrange/domain/imports.js.map +1 -0
- package/dist/arrange/domain/source-text-formatters.js +100 -0
- package/dist/arrange/domain/source-text-formatters.js.map +1 -0
- package/dist/arrange/domain/tailwind-token.js +50 -0
- package/dist/arrange/domain/tailwind-token.js.map +1 -0
- package/dist/arrange/domain/token-classifier.js +448 -0
- package/dist/arrange/domain/token-classifier.js.map +1 -0
- package/dist/arrange/domain/types.js +11 -0
- package/dist/arrange/domain/types.js.map +1 -0
- package/dist/arrange/output.js +120 -0
- package/dist/arrange/output.js.map +1 -0
- package/dist/arrange/process-file.js +44 -0
- package/dist/arrange/process-file.js.map +1 -0
- package/dist/arrange/resolve-target.js +33 -0
- package/dist/arrange/resolve-target.js.map +1 -0
- package/dist/arrange/scan-target.js +30 -0
- package/dist/arrange/scan-target.js.map +1 -0
- package/dist/arrange/simplify-process-file.js +29 -0
- package/dist/arrange/simplify-process-file.js.map +1 -0
- package/dist/arrange/simplify-sync.js +29 -0
- package/dist/arrange/simplify-sync.js.map +1 -0
- package/dist/arrange/source-parse.js +17 -0
- package/dist/arrange/source-parse.js.map +1 -0
- package/dist/arrange/suggest.js +14 -0
- package/dist/arrange/suggest.js.map +1 -0
- package/dist/arrange/sync.js +48 -0
- package/dist/arrange/sync.js.map +1 -0
- package/dist/arrange/typescript-ast-translator.js +455 -0
- package/dist/arrange/typescript-ast-translator.js.map +1 -0
- package/dist/arrange/workspace.js +31 -0
- package/dist/arrange/workspace.js.map +1 -0
- package/dist/audit/cli-schema.js +22 -0
- package/dist/audit/cli-schema.js.map +1 -0
- package/dist/audit/command.js +60 -0
- package/dist/audit/command.js.map +1 -0
- package/dist/audit/domain/audit-file.js +101 -0
- package/dist/audit/domain/audit-file.js.map +1 -0
- package/dist/audit/domain/mappings.js +103 -0
- package/dist/audit/domain/mappings.js.map +1 -0
- package/dist/audit/domain/tokenize.js +83 -0
- package/dist/audit/domain/tokenize.js.map +1 -0
- package/dist/audit/domain/types.js +2 -0
- package/dist/audit/domain/types.js.map +1 -0
- package/dist/audit/output.js +44 -0
- package/dist/audit/output.js.map +1 -0
- package/dist/audit/prepare.js +42 -0
- package/dist/audit/prepare.js.map +1 -0
- package/dist/audit/run.js +57 -0
- package/dist/audit/run.js.map +1 -0
- package/dist/{bin.mjs → bin.js} +2 -4
- package/dist/bin.js.map +1 -0
- package/dist/cli.js +45 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/cli/format-error.js +19 -0
- package/dist/core/cli/format-error.js.map +1 -0
- package/dist/core/cli/global-options.js +10 -0
- package/dist/core/cli/global-options.js.map +1 -0
- package/dist/core/cli/positional.js +9 -0
- package/dist/core/cli/positional.js.map +1 -0
- package/dist/core/cli/result-handle.js +69 -0
- package/dist/core/cli/result-handle.js.map +1 -0
- package/dist/core/config/loader.js +88 -0
- package/dist/core/config/loader.js.map +1 -0
- package/dist/core/config/schema.js +97 -0
- package/dist/core/config/schema.js.map +1 -0
- package/dist/core/config/warnings.js +12 -0
- package/dist/core/config/warnings.js.map +1 -0
- package/dist/core/config.js +18 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.js +58 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/exit-codes.js +15 -0
- package/dist/core/exit-codes.js.map +1 -0
- package/dist/core/filesystem/node.js +33 -0
- package/dist/core/filesystem/node.js.map +1 -0
- package/dist/core/filesystem/port.js +2 -0
- package/dist/core/filesystem/port.js.map +1 -0
- package/dist/core/glob.js +20 -0
- package/dist/core/glob.js.map +1 -0
- package/dist/core/logger.js +13 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/result.js +16 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/schema-parse.js +21 -0
- package/dist/core/schema-parse.js.map +1 -0
- package/dist/core/source-text-edit.js +62 -0
- package/dist/core/source-text-edit.js.map +1 -0
- package/dist/core/verbose-diagnostics.js +9 -0
- package/dist/core/verbose-diagnostics.js.map +1 -0
- package/dist/core/workspace/resolver.js +208 -0
- package/dist/core/workspace/resolver.js.map +1 -0
- package/dist/core/workspace/typescript-walk.js +41 -0
- package/dist/core/workspace/typescript-walk.js.map +1 -0
- package/dist/mirror/cli-result.js +20 -0
- package/dist/mirror/cli-result.js.map +1 -0
- package/dist/mirror/cli-schema.js +11 -0
- package/dist/mirror/cli-schema.js.map +1 -0
- package/dist/mirror/command.js +73 -0
- package/dist/mirror/command.js.map +1 -0
- package/dist/mirror/dist-filesystem-impl.js +53 -0
- package/dist/mirror/dist-filesystem-impl.js.map +1 -0
- package/dist/mirror/domain/constants.js +21 -0
- package/dist/mirror/domain/constants.js.map +1 -0
- package/dist/mirror/domain/dirent-guard.js +16 -0
- package/dist/mirror/domain/dirent-guard.js.map +1 -0
- package/dist/mirror/domain/dist-filesystem.js +2 -0
- package/dist/mirror/domain/dist-filesystem.js.map +1 -0
- package/dist/mirror/domain/errors.js +19 -0
- package/dist/mirror/domain/errors.js.map +1 -0
- package/dist/mirror/domain/exports.js +284 -0
- package/dist/mirror/domain/exports.js.map +1 -0
- package/dist/mirror/domain/package-display-name.js +10 -0
- package/dist/mirror/domain/package-display-name.js.map +1 -0
- package/dist/mirror/domain/path-normalizer.js +8 -0
- package/dist/mirror/domain/path-normalizer.js.map +1 -0
- package/dist/mirror/domain/types.js +2 -0
- package/dist/mirror/domain/types.js.map +1 -0
- package/dist/mirror/output.js +47 -0
- package/dist/mirror/output.js.map +1 -0
- package/dist/mirror/package-path.js +40 -0
- package/dist/mirror/package-path.js.map +1 -0
- package/dist/mirror/prepare.js +37 -0
- package/dist/mirror/prepare.js.map +1 -0
- package/dist/mirror/supplement-exports.js +157 -0
- package/dist/mirror/supplement-exports.js.map +1 -0
- package/dist/mirror/sync-reporter.js +125 -0
- package/dist/mirror/sync-reporter.js.map +1 -0
- package/dist/mirror/sync-types.js +2 -0
- package/dist/mirror/sync-types.js.map +1 -0
- package/dist/mirror/sync-workspace-package.js +117 -0
- package/dist/mirror/sync-workspace-package.js.map +1 -0
- package/dist/mirror/sync.js +90 -0
- package/dist/mirror/sync.js.map +1 -0
- package/dist/mirror/write-exports.js +145 -0
- package/dist/mirror/write-exports.js.map +1 -0
- package/dist/tag/cli-result.js +12 -0
- package/dist/tag/cli-result.js.map +1 -0
- package/dist/tag/cli-schema.js +13 -0
- package/dist/tag/cli-schema.js.map +1 -0
- package/dist/tag/command.js +69 -0
- package/dist/tag/command.js.map +1 -0
- package/dist/tag/domain/types.js +2 -0
- package/dist/tag/domain/types.js.map +1 -0
- package/dist/tag/output.js +101 -0
- package/dist/tag/output.js.map +1 -0
- package/dist/tag/prepare.js +30 -0
- package/dist/tag/prepare.js.map +1 -0
- package/dist/tag/resolve-target-path.js +14 -0
- package/dist/tag/resolve-target-path.js.map +1 -0
- package/dist/tag/since-writer.js +231 -0
- package/dist/tag/since-writer.js.map +1 -0
- package/dist/tag/sync.js +166 -0
- package/dist/tag/sync.js.map +1 -0
- package/dist/tag/target-candidates.js +79 -0
- package/dist/tag/target-candidates.js.map +1 -0
- package/dist/tag/target-runner.js +25 -0
- package/dist/tag/target-runner.js.map +1 -0
- package/dist/tag/version-resolver.js +28 -0
- package/dist/tag/version-resolver.js.map +1 -0
- package/package.json +27 -21
- package/dist/arrange/analyze.mjs +0 -24
- package/dist/arrange/cli-schema.mjs +0 -27
- package/dist/arrange/command.mjs +0 -130
- package/dist/arrange/domain/analyze-service.mjs +0 -102
- package/dist/arrange/domain/ast/ast-node.mjs +0 -215
- package/dist/arrange/domain/ast/collectors-cn.mjs +0 -64
- package/dist/arrange/domain/ast/collectors-jsx.mjs +0 -23
- package/dist/arrange/domain/ast/collectors-tv.mjs +0 -189
- package/dist/arrange/domain/ast/helpers.mjs +0 -108
- package/dist/arrange/domain/ast/simplify-targets.mjs +0 -109
- package/dist/arrange/domain/ast/targets.mjs +0 -134
- package/dist/arrange/domain/constants.mjs +0 -213
- package/dist/arrange/domain/grouping-service.mjs +0 -121
- package/dist/arrange/domain/grouping.mjs +0 -338
- package/dist/arrange/domain/imports.mjs +0 -107
- package/dist/arrange/domain/source-text-formatters.mjs +0 -88
- package/dist/arrange/domain/tailwind-token.mjs +0 -40
- package/dist/arrange/domain/token-classifier.mjs +0 -218
- package/dist/arrange/domain/types.mjs +0 -1
- package/dist/arrange/output.mjs +0 -87
- package/dist/arrange/process-file.mjs +0 -42
- package/dist/arrange/resolve-target.mjs +0 -24
- package/dist/arrange/scan-target.mjs +0 -29
- package/dist/arrange/simplify-process-file.mjs +0 -35
- package/dist/arrange/simplify-sync.mjs +0 -32
- package/dist/arrange/source-parse.mjs +0 -18
- package/dist/arrange/suggest.mjs +0 -15
- package/dist/arrange/sync.mjs +0 -51
- package/dist/arrange/typescript-ast-translator.mjs +0 -354
- package/dist/arrange/workspace.mjs +0 -31
- package/dist/cli.mjs +0 -34
- package/dist/core/cli/format-error.mjs +0 -15
- package/dist/core/cli/global-options.mjs +0 -10
- package/dist/core/cli/positional.mjs +0 -11
- package/dist/core/cli/result-handle.mjs +0 -51
- package/dist/core/config/loader.mjs +0 -79
- package/dist/core/config/schema.mjs +0 -60
- package/dist/core/config/warnings.mjs +0 -12
- package/dist/core/config.mjs +0 -19
- package/dist/core/errors.mjs +0 -35
- package/dist/core/exit-codes.mjs +0 -17
- package/dist/core/filesystem/node.mjs +0 -32
- package/dist/core/filesystem/port.mjs +0 -1
- package/dist/core/glob.mjs +0 -20
- package/dist/core/logger.mjs +0 -15
- package/dist/core/result.mjs +0 -21
- package/dist/core/schema-parse.mjs +0 -18
- package/dist/core/source-text-edit.mjs +0 -56
- package/dist/core/verbose-diagnostics.mjs +0 -11
- package/dist/core/workspace/resolver.mjs +0 -177
- package/dist/core/workspace/typescript-walk.mjs +0 -36
- package/dist/mirror/cli-result.mjs +0 -22
- package/dist/mirror/cli-schema.mjs +0 -13
- package/dist/mirror/command.mjs +0 -58
- package/dist/mirror/dist-filesystem-impl.mjs +0 -42
- package/dist/mirror/domain/constants.mjs +0 -31
- package/dist/mirror/domain/dirent-guard.mjs +0 -16
- package/dist/mirror/domain/dist-filesystem.mjs +0 -1
- package/dist/mirror/domain/errors.mjs +0 -21
- package/dist/mirror/domain/exports.mjs +0 -226
- package/dist/mirror/domain/package-display-name.mjs +0 -12
- package/dist/mirror/domain/path-normalizer.mjs +0 -10
- package/dist/mirror/domain/types.mjs +0 -1
- package/dist/mirror/output.mjs +0 -48
- package/dist/mirror/package-path.mjs +0 -32
- package/dist/mirror/prepare.mjs +0 -33
- package/dist/mirror/supplement-exports.mjs +0 -114
- package/dist/mirror/sync-reporter.mjs +0 -107
- package/dist/mirror/sync-types.mjs +0 -1
- package/dist/mirror/sync-workspace-package.mjs +0 -109
- package/dist/mirror/sync.mjs +0 -88
- package/dist/mirror/write-exports.mjs +0 -94
- package/dist/tag/cli-result.mjs +0 -11
- package/dist/tag/cli-schema.mjs +0 -15
- package/dist/tag/command.mjs +0 -56
- package/dist/tag/domain/types.mjs +0 -1
- package/dist/tag/output.mjs +0 -87
- package/dist/tag/prepare.mjs +0 -29
- package/dist/tag/resolve-target-path.mjs +0 -12
- package/dist/tag/since-writer.mjs +0 -131
- package/dist/tag/sync.mjs +0 -149
- package/dist/tag/target-candidates.mjs +0 -68
- package/dist/tag/target-runner.mjs +0 -26
- package/dist/tag/version-resolver.mjs +0 -25
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { forEachDomainChild, isDomainArrayLiteralExpression, isDomainCallExpression, isDomainJsxAttribute, isDomainJsxExpression, isDomainObjectLiteralExpression, isDomainPropertyAssignment, isDomainSpreadElement, isDomainTailwindClassLiteral } from "./ast-node.mjs";
|
|
2
|
-
import "../constants.mjs";
|
|
3
|
-
import { indentOfLineContaining } from "../../../core/source-text-edit.mjs";
|
|
4
|
-
import { buildKnownCnTvBindings, isCnOrTvIdentifier } from "./helpers.mjs";
|
|
5
|
-
import { escapeTsStringLiteralContent } from "../source-text-formatters.mjs";
|
|
6
|
-
//#region src/arrange/domain/ast/simplify-targets.ts
|
|
7
|
-
function toFlatString(text) {
|
|
8
|
-
return `"${escapeTsStringLiteralContent(text.trim())}"`;
|
|
9
|
-
}
|
|
10
|
-
function joinLiterals(args) {
|
|
11
|
-
return args.filter(isDomainTailwindClassLiteral).map((lit) => lit.text).join(" ");
|
|
12
|
-
}
|
|
13
|
-
function isAllStaticLiterals(args) {
|
|
14
|
-
return args.length > 0 && args.every(isDomainTailwindClassLiteral);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* For a cn() call that has both static and dynamic args:
|
|
18
|
-
* - Merge ALL static string literals (regardless of position) into one string.
|
|
19
|
-
* - Place the merged string first.
|
|
20
|
-
* - Append all dynamic args in their original relative order.
|
|
21
|
-
*
|
|
22
|
-
* Returns `null` when nothing changes (0 statics, or already 1 static at arg[0]).
|
|
23
|
-
*/
|
|
24
|
-
function buildMixedCnReplacement(call, sourceText) {
|
|
25
|
-
const args = [...call.arguments];
|
|
26
|
-
if (args.length === 0) return null;
|
|
27
|
-
const staticTexts = [];
|
|
28
|
-
const dynamicSrcs = [];
|
|
29
|
-
for (const arg of args) if (isDomainTailwindClassLiteral(arg)) staticTexts.push(arg.text);
|
|
30
|
-
else dynamicSrcs.push(sourceText.slice(arg.pos, arg.end));
|
|
31
|
-
if (staticTexts.length === 0) return null;
|
|
32
|
-
const firstArg = args[0];
|
|
33
|
-
if (staticTexts.length === 1 && firstArg !== void 0 && isDomainTailwindClassLiteral(firstArg)) return null;
|
|
34
|
-
const flatStatic = staticTexts.join(" ").trim();
|
|
35
|
-
const baseIndent = indentOfLineContaining(sourceText, call.pos);
|
|
36
|
-
const argIndent = `${baseIndent} `;
|
|
37
|
-
return `cn(\n${[`${argIndent}"${escapeTsStringLiteralContent(flatStatic)}",`, ...dynamicSrcs.map((src) => `${argIndent}${src},`)].join("\n")}\n${baseIndent})`;
|
|
38
|
-
}
|
|
39
|
-
function collectTvArrayEdits(obj, results, depth) {
|
|
40
|
-
if (depth > 12) return;
|
|
41
|
-
for (const prop of obj.properties) {
|
|
42
|
-
if (!isDomainPropertyAssignment(prop)) continue;
|
|
43
|
-
const init = prop.initializer;
|
|
44
|
-
if (isDomainArrayLiteralExpression(init)) {
|
|
45
|
-
const elements = [...init.elements];
|
|
46
|
-
if (!elements.some(isDomainSpreadElement) && elements.length > 0 && isAllStaticLiterals(elements)) results.push({
|
|
47
|
-
start: init.pos,
|
|
48
|
-
end: init.end,
|
|
49
|
-
replacement: toFlatString(joinLiterals(elements)),
|
|
50
|
-
label: "tv-array"
|
|
51
|
-
});
|
|
52
|
-
} else if (isDomainObjectLiteralExpression(init)) collectTvArrayEdits(init, results, depth + 1);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Collect all simplify edits for a source file:
|
|
57
|
-
* - Arrays of pure string literals inside tv() slots → flat string
|
|
58
|
-
* - cn() calls whose every argument is a static string literal → flat string (unwrap cn)
|
|
59
|
-
* - cn() calls with mixed static + dynamic args → merge adjacent statics into one string
|
|
60
|
-
* - JSX className={cn(...all-static...)} → className="flat string"
|
|
61
|
-
*
|
|
62
|
-
* @since 0.3.16-canary.0
|
|
63
|
-
*/
|
|
64
|
-
function collectSimplifyTargets(sourceFile) {
|
|
65
|
-
const sourceText = sourceFile.text;
|
|
66
|
-
const results = [];
|
|
67
|
-
const knownBindings = buildKnownCnTvBindings(sourceFile);
|
|
68
|
-
const seenCnPos = /* @__PURE__ */ new Set();
|
|
69
|
-
const visitNode = (node) => {
|
|
70
|
-
if (isDomainCallExpression(node)) {
|
|
71
|
-
if (isCnOrTvIdentifier(node.expression, "tv", knownBindings)) {
|
|
72
|
-
const arg0 = node.arguments[0];
|
|
73
|
-
if (arg0 && isDomainObjectLiteralExpression(arg0)) collectTvArrayEdits(arg0, results, 0);
|
|
74
|
-
} else if (isCnOrTvIdentifier(node.expression, "cn", knownBindings) && !seenCnPos.has(node.pos)) {
|
|
75
|
-
seenCnPos.add(node.pos);
|
|
76
|
-
const args = [...node.arguments];
|
|
77
|
-
if (isAllStaticLiterals(args)) {
|
|
78
|
-
const flat = joinLiterals(args);
|
|
79
|
-
const parent = node.parent;
|
|
80
|
-
if (parent && isDomainJsxExpression(parent) && parent.parent && isDomainJsxAttribute(parent.parent)) results.push({
|
|
81
|
-
start: parent.pos,
|
|
82
|
-
end: parent.end,
|
|
83
|
-
replacement: toFlatString(flat),
|
|
84
|
-
label: "jsx-cn"
|
|
85
|
-
});
|
|
86
|
-
else results.push({
|
|
87
|
-
start: node.pos,
|
|
88
|
-
end: node.end,
|
|
89
|
-
replacement: toFlatString(flat),
|
|
90
|
-
label: "cn-static"
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
const replacement = buildMixedCnReplacement(node, sourceText);
|
|
94
|
-
if (replacement !== null) results.push({
|
|
95
|
-
start: node.pos,
|
|
96
|
-
end: node.end,
|
|
97
|
-
replacement,
|
|
98
|
-
label: "cn-merge"
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
forEachDomainChild(node, visitNode);
|
|
104
|
-
};
|
|
105
|
-
for (const stmt of sourceFile.statements) visitNode(stmt);
|
|
106
|
-
return results;
|
|
107
|
-
}
|
|
108
|
-
//#endregion
|
|
109
|
-
export { collectSimplifyTargets };
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { forEachDomainChild, isDomainArrayLiteralExpression, isDomainJsxAttribute, isDomainPropertyAssignment, isDomainTailwindClassLiteral } from "./ast-node.mjs";
|
|
2
|
-
import "../constants.mjs";
|
|
3
|
-
import { isUnsafeLiteralForCnStyleApplySplit } from "./collectors-cn.mjs";
|
|
4
|
-
import { jsxClassNameStaticLiteral } from "./collectors-jsx.mjs";
|
|
5
|
-
import { endAfterOptionalCommaFollowingInSource, indentOfLineContaining, textPrefixFromLineStartToPosition } from "../../../core/source-text-edit.mjs";
|
|
6
|
-
import { tokenizeClassString } from "../tailwind-token.mjs";
|
|
7
|
-
import { collectGroupableStringNodes, slotClassString } from "./collectors-tv.mjs";
|
|
8
|
-
import { escapeTsStringLiteralContent, formatArray, formatArrayElementsAsSiblingLines, formatJsxCnAttributeValue } from "../source-text-formatters.mjs";
|
|
9
|
-
import { areCnTailwindPartitionsEquivalent, suggestCnGroups, summarizeGroupBucketLabels } from "../grouping.mjs";
|
|
10
|
-
//#region src/arrange/domain/ast/targets.ts
|
|
11
|
-
/**
|
|
12
|
-
* @since 0.3.16-canary.0
|
|
13
|
-
*/
|
|
14
|
-
function targetReplaceStart(target) {
|
|
15
|
-
if (target.kind === "cnArg") return target.item.cnCall ? target.item.cnCall.pos : target.item.primaryClassLiteral.pos;
|
|
16
|
-
return target.valueNode.pos;
|
|
17
|
-
}
|
|
18
|
-
function collectLongJsxClassNameTargets(sourceFile) {
|
|
19
|
-
const results = [];
|
|
20
|
-
const visitTypeScriptSubtree = (tsNode) => {
|
|
21
|
-
if (isDomainJsxAttribute(tsNode)) {
|
|
22
|
-
const parsed = jsxClassNameStaticLiteral(tsNode);
|
|
23
|
-
if (parsed && tokenizeClassString(parsed.lit.text).length >= 2) results.push({
|
|
24
|
-
kind: "jsxClassName",
|
|
25
|
-
sf: sourceFile,
|
|
26
|
-
lit: parsed.lit,
|
|
27
|
-
valueNode: parsed.valueNode
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
forEachDomainChild(tsNode, visitTypeScriptSubtree);
|
|
31
|
-
};
|
|
32
|
-
for (const stmt of sourceFile.statements) visitTypeScriptSubtree(stmt);
|
|
33
|
-
return results;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @since 0.3.16-canary.0
|
|
37
|
-
*/
|
|
38
|
-
function collectGroupTargets(sourceFile, filePath) {
|
|
39
|
-
const cnPart = collectGroupableStringNodes(sourceFile).map((stringNode) => ({
|
|
40
|
-
kind: "cnArg",
|
|
41
|
-
item: stringNode
|
|
42
|
-
}));
|
|
43
|
-
if (!filePath.endsWith(".tsx")) return cnPart;
|
|
44
|
-
return [...cnPart, ...collectLongJsxClassNameTargets(sourceFile)];
|
|
45
|
-
}
|
|
46
|
-
function formatCnCallReplacement(stringNode, sourceText, withClassName) {
|
|
47
|
-
const call = stringNode.cnCall;
|
|
48
|
-
if (call === void 0) throw new Error("formatCnCallReplacement requires a cn() call on the string node");
|
|
49
|
-
const baseIndent = indentOfLineContaining(sourceText, call.pos);
|
|
50
|
-
const argIndent = `${baseIndent} `;
|
|
51
|
-
const dynamicArgTexts = [];
|
|
52
|
-
for (const arg of call.arguments) if (!(isDomainTailwindClassLiteral(arg) && !isUnsafeLiteralForCnStyleApplySplit(arg))) dynamicArgTexts.push(sourceText.slice(arg.pos, arg.end));
|
|
53
|
-
const pool = slotClassString(stringNode);
|
|
54
|
-
const groups = pool.trim() ? suggestCnGroups(pool) : [];
|
|
55
|
-
const allArgs = [];
|
|
56
|
-
if (groups.length > 1) for (const group of groups) allArgs.push(`${argIndent}"${escapeTsStringLiteralContent(group)}"`);
|
|
57
|
-
else if (groups.length === 1) {
|
|
58
|
-
const onlyGroup = groups[0];
|
|
59
|
-
if (onlyGroup === void 0) throw new Error("invariant: single cn group missing");
|
|
60
|
-
allArgs.push(`${argIndent}"${escapeTsStringLiteralContent(onlyGroup)}"`);
|
|
61
|
-
}
|
|
62
|
-
for (const dynamicArgumentSource of dynamicArgTexts) allArgs.push(`${argIndent}${dynamicArgumentSource}`);
|
|
63
|
-
if (withClassName) allArgs.push(`${argIndent}className`);
|
|
64
|
-
const commaAfterLastArg = allArgs.length > 1;
|
|
65
|
-
return `cn(\n${allArgs.map((argLine, lineIndex) => lineIndex < allArgs.length - 1 || commaAfterLastArg ? `${argLine},` : argLine).join("\n")}\n${baseIndent})`;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @since 0.3.16-canary.0
|
|
69
|
-
*/
|
|
70
|
-
function planGroupEditForTarget(target, textAfterUnwrap, withClassName) {
|
|
71
|
-
if (target.kind === "jsxClassName") {
|
|
72
|
-
const groups = suggestCnGroups(target.lit.text);
|
|
73
|
-
if (groups.length <= 1) return;
|
|
74
|
-
const start = target.valueNode.pos;
|
|
75
|
-
return {
|
|
76
|
-
start,
|
|
77
|
-
end: target.valueNode.end,
|
|
78
|
-
replacement: formatJsxCnAttributeValue(groups, textAfterUnwrap, start),
|
|
79
|
-
bucketSummary: summarizeGroupBucketLabels(groups),
|
|
80
|
-
jsxCn: true,
|
|
81
|
-
lineSf: target.sf,
|
|
82
|
-
reportNode: target.lit,
|
|
83
|
-
label: "JSX className"
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
const groups = suggestCnGroups(slotClassString(target.item));
|
|
87
|
-
if (groups.length <= 1) return;
|
|
88
|
-
if (areCnTailwindPartitionsEquivalent(target.item.nodes.map((classLiteral) => classLiteral.text), groups)) return;
|
|
89
|
-
if (!target.item.cnCall) {
|
|
90
|
-
const anchorClassLiteral = target.item.primaryClassLiteral;
|
|
91
|
-
const parentNode = anchorClassLiteral.parent;
|
|
92
|
-
const parentArray = target.item.nodes.length > 1 && parentNode !== null && isDomainArrayLiteralExpression(parentNode) ? parentNode : null;
|
|
93
|
-
const bareStringProperty = !parentArray && parentNode !== null && isDomainPropertyAssignment(parentNode);
|
|
94
|
-
if (parentArray || bareStringProperty) {
|
|
95
|
-
const start = parentArray ? parentArray.pos : anchorClassLiteral.pos;
|
|
96
|
-
const end = parentArray ? parentArray.end : anchorClassLiteral.end;
|
|
97
|
-
const baseIndent = indentOfLineContaining(textAfterUnwrap, start);
|
|
98
|
-
return {
|
|
99
|
-
start,
|
|
100
|
-
end,
|
|
101
|
-
replacement: formatArray(groups).split("\n").map((line, lineIndex) => lineIndex === 0 ? line : `${baseIndent}${line}`).join("\n"),
|
|
102
|
-
bucketSummary: summarizeGroupBucketLabels(groups),
|
|
103
|
-
jsxCn: false,
|
|
104
|
-
lineSf: target.item.sf,
|
|
105
|
-
reportNode: anchorClassLiteral,
|
|
106
|
-
label: target.item.isTvContext ? "tv" : "cn"
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
const start = anchorClassLiteral.pos;
|
|
110
|
-
return {
|
|
111
|
-
start,
|
|
112
|
-
end: endAfterOptionalCommaFollowingInSource(textAfterUnwrap, anchorClassLiteral.end),
|
|
113
|
-
replacement: formatArrayElementsAsSiblingLines(groups, textPrefixFromLineStartToPosition(textAfterUnwrap, start)),
|
|
114
|
-
bucketSummary: summarizeGroupBucketLabels(groups),
|
|
115
|
-
jsxCn: false,
|
|
116
|
-
lineSf: target.item.sf,
|
|
117
|
-
reportNode: anchorClassLiteral,
|
|
118
|
-
label: target.item.isTvContext ? "tv" : "cn"
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
const call = target.item.cnCall;
|
|
122
|
-
return {
|
|
123
|
-
start: call.pos,
|
|
124
|
-
end: call.end,
|
|
125
|
-
replacement: formatCnCallReplacement(target.item, textAfterUnwrap, withClassName),
|
|
126
|
-
bucketSummary: summarizeGroupBucketLabels(groups),
|
|
127
|
-
jsxCn: false,
|
|
128
|
-
lineSf: target.item.sf,
|
|
129
|
-
reportNode: target.item.primaryClassLiteral,
|
|
130
|
-
label: target.item.isTvContext ? "tv" : "cn"
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
//#endregion
|
|
134
|
-
export { collectGroupTargets, planGroupEditForTarget, targetReplaceStart };
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
//#region src/arrange/domain/constants.ts
|
|
2
|
-
/**
|
|
3
|
-
* Analyze report: long literal threshold (token count).
|
|
4
|
-
*
|
|
5
|
-
* @since 0.3.16-canary.0
|
|
6
|
-
*/
|
|
7
|
-
const LONG_STRING_TOKEN_THRESHOLD = 18;
|
|
8
|
-
/**
|
|
9
|
-
* Minimum token count for a string to be considered a candidate for grouping
|
|
10
|
-
* in the apply/preview pipeline. Intentionally much lower than
|
|
11
|
-
* {@link LONG_STRING_TOKEN_THRESHOLD} (analyze only).
|
|
12
|
-
*
|
|
13
|
-
* @since 0.3.16-canary.0
|
|
14
|
-
*/
|
|
15
|
-
const APPLY_MIN_TOKENS = 2;
|
|
16
|
-
/**
|
|
17
|
-
* Minimum tokens a group must have to stand alone before singleton-merging.
|
|
18
|
-
* Set to 2 so single-token groups are not collapsed into unrelated buckets by the merger.
|
|
19
|
-
*
|
|
20
|
-
* @since 0.3.16-canary.0
|
|
21
|
-
*/
|
|
22
|
-
const MIN_GROUP_TOKENS = 2;
|
|
23
|
-
/**
|
|
24
|
-
* Dynamic max groups clamp: base bound.
|
|
25
|
-
*
|
|
26
|
-
* @since 0.3.16-canary.0
|
|
27
|
-
*/
|
|
28
|
-
const MAX_GROUPS_BASE = 4;
|
|
29
|
-
/**
|
|
30
|
-
* Dynamic max groups clamp: upper cap.
|
|
31
|
-
*
|
|
32
|
-
* @since 0.3.16-canary.0
|
|
33
|
-
*/
|
|
34
|
-
const MAX_GROUPS_CAP = 24;
|
|
35
|
-
/**
|
|
36
|
-
* Extra slots so a few state / aria groups do not force `capGroups` to merge
|
|
37
|
-
* unrelated buckets (e.g. `bg-border` + `outline-hidden`).
|
|
38
|
-
*
|
|
39
|
-
* @since 0.3.16-canary.0
|
|
40
|
-
*/
|
|
41
|
-
const MAX_GROUPS_HEADROOM = 2;
|
|
42
|
-
/**
|
|
43
|
-
* Maximum findings printed per category in the analyze report.
|
|
44
|
-
*
|
|
45
|
-
* @since 0.3.16-canary.0
|
|
46
|
-
*/
|
|
47
|
-
const MAX_REPORT_LINES = 40;
|
|
48
|
-
/**
|
|
49
|
-
* Maximum recursion depth when traversing `tv()` object literals.
|
|
50
|
-
*
|
|
51
|
-
* @since 0.3.16-canary.0
|
|
52
|
-
*/
|
|
53
|
-
const MAX_OBJECT_DEPTH = 12;
|
|
54
|
-
/**
|
|
55
|
-
* Maximum depth when peeling conditional / parens / arrays inside `cn(...)` args.
|
|
56
|
-
*
|
|
57
|
-
* @since 0.3.16-canary.0
|
|
58
|
-
*/
|
|
59
|
-
const MAX_CLASS_EXPR_DEPTH = 12;
|
|
60
|
-
/**
|
|
61
|
-
* Maximum variant-stripping passes in {@link stripVariants}.
|
|
62
|
-
* Real-world Tailwind stacks rarely exceed 4–5 segments (e.g. `@md/sidebar:group-hover:dark:focus-visible:`);
|
|
63
|
-
* 12 is a conservative safety cap that prevents runaway loops on malformed input.
|
|
64
|
-
*
|
|
65
|
-
* @since 0.3.16-canary.0
|
|
66
|
-
*/
|
|
67
|
-
const MAX_STRIP_VARIANT_PASSES = 12;
|
|
68
|
-
/**
|
|
69
|
-
* Passed when optional `knownBindings` is missing — size 0 disables matching
|
|
70
|
-
* for `cn` / `tv` identifier resolution.
|
|
71
|
-
*
|
|
72
|
-
* @since 0.3.16-canary.0
|
|
73
|
-
*/
|
|
74
|
-
const EMPTY_CN_TV_BINDINGS = /* @__PURE__ */ new Set();
|
|
75
|
-
/**
|
|
76
|
-
* Bucket sort order — **render pipeline** (lower → earlier in `cn()` output).
|
|
77
|
-
*
|
|
78
|
-
* Matches README: Existence → Position → Layout → Sizing → Spacing → Shape → Background
|
|
79
|
-
* → Shadow → Typography → Composite → Motion → Starting → Behavior → State → Selector,
|
|
80
|
-
* then `other` and `arbitrary` as sort tails for unknown utilities and arbitrary properties.
|
|
81
|
-
*
|
|
82
|
-
* @since 0.3.16-canary.0
|
|
83
|
-
*/
|
|
84
|
-
const BUCKET_ORDER = {
|
|
85
|
-
existence: 0,
|
|
86
|
-
position: 1,
|
|
87
|
-
layout: 2,
|
|
88
|
-
sizing: 3,
|
|
89
|
-
spacing: 4,
|
|
90
|
-
shape: 5,
|
|
91
|
-
background: 6,
|
|
92
|
-
shadow: 7,
|
|
93
|
-
typography: 8,
|
|
94
|
-
composite: 9,
|
|
95
|
-
motion: 10,
|
|
96
|
-
starting: 11,
|
|
97
|
-
behavior: 12,
|
|
98
|
-
state: 13,
|
|
99
|
-
selector: 14,
|
|
100
|
-
other: 15,
|
|
101
|
-
arbitrary: 16
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Compatible bucket **pairs** — two adjacent tokens whose buckets appear in the same
|
|
105
|
-
* `Set` may stay in one `cn()` string chunk. Compatibility is **not transitive**: there is
|
|
106
|
-
* no `{position, sizing}` pair, so `fixed inset-0` and `overflow-auto` become **separate**
|
|
107
|
-
* literals unless **layout** tokens sit between them in sorted order; then
|
|
108
|
-
* `position↔layout` and `layout↔sizing` each justify one hop and the whole “box in flow”
|
|
109
|
-
* (place + tracks + scrollport) stays in one chunk — co-located because they jointly define
|
|
110
|
-
* stacking and scroll behavior for the same surface.
|
|
111
|
-
*
|
|
112
|
-
* @since 0.3.16-canary.0
|
|
113
|
-
*/
|
|
114
|
-
const COMPATIBLE_BUCKET_SETS = [
|
|
115
|
-
/* @__PURE__ */ new Set(["existence", "position"]),
|
|
116
|
-
/* @__PURE__ */ new Set(["existence", "layout"]),
|
|
117
|
-
/* @__PURE__ */ new Set(["position", "layout"]),
|
|
118
|
-
/* @__PURE__ */ new Set(["layout", "sizing"]),
|
|
119
|
-
/* @__PURE__ */ new Set(["shape", "shadow"]),
|
|
120
|
-
/* @__PURE__ */ new Set(["background", "shadow"]),
|
|
121
|
-
/* @__PURE__ */ new Set(["background", "typography"]),
|
|
122
|
-
/* @__PURE__ */ new Set(["layout", "typography"]),
|
|
123
|
-
/* @__PURE__ */ new Set(["sizing", "typography"]),
|
|
124
|
-
/* @__PURE__ */ new Set(["motion", "behavior"]),
|
|
125
|
-
/* @__PURE__ */ new Set(["motion", "starting"]),
|
|
126
|
-
/* @__PURE__ */ new Set(["composite", "motion"]),
|
|
127
|
-
/* @__PURE__ */ new Set(["sizing", "composite"]),
|
|
128
|
-
/* @__PURE__ */ new Set(["sizing", "spacing"])
|
|
129
|
-
];
|
|
130
|
-
/**
|
|
131
|
-
* Responsive / variant prefix — Tailwind v4 aware.
|
|
132
|
-
*
|
|
133
|
-
* v3: sm: md: … — v4: @sm:, @min-[600px]:, @[480px]:, named @md/sidebar:,
|
|
134
|
-
* viewport md/sidebar:, min-[100px]: / max-[100px]:, …
|
|
135
|
-
*
|
|
136
|
-
* @since 0.3.16-canary.0
|
|
137
|
-
*/
|
|
138
|
-
const RESPONSIVE_PREFIX = /^(?:@(?:min|max)-\[[^\]]+\]:|@\[[^\]]+\]:|@(?:[a-z0-9]+(?:-[a-z0-9]+)*)(?:\/[a-z][a-z0-9-]*)?:|(?:max-|min-)?(?:sm|md|lg|xl|2xl|3xl)(?:\/[a-z][a-z0-9-]*)?:|(?:max-|min-)\[[^\]]+\]:)/;
|
|
139
|
-
/**
|
|
140
|
-
* State variant stems — hoisted to module scope (not recreated per call).
|
|
141
|
-
*
|
|
142
|
-
* @since 0.3.16-canary.0
|
|
143
|
-
*/
|
|
144
|
-
const STATE_PREFIXES = /* @__PURE__ */ new Set([
|
|
145
|
-
"hover",
|
|
146
|
-
"focus",
|
|
147
|
-
"focus-within",
|
|
148
|
-
"focus-visible",
|
|
149
|
-
"active",
|
|
150
|
-
"visited",
|
|
151
|
-
"link",
|
|
152
|
-
"any-link",
|
|
153
|
-
"disabled",
|
|
154
|
-
"enabled",
|
|
155
|
-
"checked",
|
|
156
|
-
"indeterminate",
|
|
157
|
-
"required",
|
|
158
|
-
"optional",
|
|
159
|
-
"valid",
|
|
160
|
-
"invalid",
|
|
161
|
-
"in-range",
|
|
162
|
-
"out-of-range",
|
|
163
|
-
"read-only",
|
|
164
|
-
"read-write",
|
|
165
|
-
"placeholder-shown",
|
|
166
|
-
"default",
|
|
167
|
-
"autofill",
|
|
168
|
-
"open",
|
|
169
|
-
"closed",
|
|
170
|
-
"first",
|
|
171
|
-
"last",
|
|
172
|
-
"only",
|
|
173
|
-
"odd",
|
|
174
|
-
"even",
|
|
175
|
-
"first-of-type",
|
|
176
|
-
"last-of-type",
|
|
177
|
-
"only-of-type",
|
|
178
|
-
"first-child",
|
|
179
|
-
"last-child",
|
|
180
|
-
"only-child",
|
|
181
|
-
"empty",
|
|
182
|
-
"target",
|
|
183
|
-
"group",
|
|
184
|
-
"peer",
|
|
185
|
-
"aria",
|
|
186
|
-
"data",
|
|
187
|
-
"dark",
|
|
188
|
-
"light",
|
|
189
|
-
"supports",
|
|
190
|
-
"motion-reduce",
|
|
191
|
-
"motion-safe",
|
|
192
|
-
"print",
|
|
193
|
-
"screen",
|
|
194
|
-
"ltr",
|
|
195
|
-
"rtl",
|
|
196
|
-
"not",
|
|
197
|
-
"has",
|
|
198
|
-
"in",
|
|
199
|
-
"nth",
|
|
200
|
-
"file",
|
|
201
|
-
"selection",
|
|
202
|
-
"marker",
|
|
203
|
-
"placeholder",
|
|
204
|
-
"before",
|
|
205
|
-
"after",
|
|
206
|
-
"first-line",
|
|
207
|
-
"first-letter",
|
|
208
|
-
"backdrop",
|
|
209
|
-
"details-content",
|
|
210
|
-
"popover-open"
|
|
211
|
-
]);
|
|
212
|
-
//#endregion
|
|
213
|
-
export { APPLY_MIN_TOKENS, BUCKET_ORDER, COMPATIBLE_BUCKET_SETS, EMPTY_CN_TV_BINDINGS, LONG_STRING_TOKEN_THRESHOLD, MAX_CLASS_EXPR_DEPTH, MAX_GROUPS_BASE, MAX_GROUPS_CAP, MAX_GROUPS_HEADROOM, MAX_OBJECT_DEPTH, MAX_REPORT_LINES, MAX_STRIP_VARIANT_PASSES, MIN_GROUP_TOKENS, RESPONSIVE_PREFIX, STATE_PREFIXES };
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { applyEditsDescending } from "../../core/source-text-edit.mjs";
|
|
2
|
-
import { buildKnownCnTvBindings, unwrapCnInsideTvCallReplacement } from "./ast/helpers.mjs";
|
|
3
|
-
import { listAllCnCallsInsideTvInSourceFile } from "./ast/collectors-tv.mjs";
|
|
4
|
-
import { collectGroupTargets, planGroupEditForTarget, targetReplaceStart } from "./ast/targets.mjs";
|
|
5
|
-
//#region src/arrange/domain/grouping-service.ts
|
|
6
|
-
function toUnwrapPlans(cnInTvCalls, sourceText) {
|
|
7
|
-
return cnInTvCalls.map((call) => {
|
|
8
|
-
const replacement = unwrapCnInsideTvCallReplacement(call, sourceText);
|
|
9
|
-
if (replacement === void 0) return;
|
|
10
|
-
return {
|
|
11
|
-
start: call.pos,
|
|
12
|
-
end: call.end,
|
|
13
|
-
replacement,
|
|
14
|
-
call
|
|
15
|
-
};
|
|
16
|
-
}).filter((plan) => plan !== void 0);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @since 0.3.16-canary.0
|
|
20
|
-
*/
|
|
21
|
-
function buildGroupFileUnwrapState(domainSfInitial, sourceText) {
|
|
22
|
-
const cnInTvCalls = listAllCnCallsInsideTvInSourceFile(domainSfInitial, buildKnownCnTvBindings(domainSfInitial));
|
|
23
|
-
const unwrapPlans = toUnwrapPlans(cnInTvCalls, sourceText);
|
|
24
|
-
const unwrapReplacementByCall = new Map(unwrapPlans.map((unwrapPlan) => [unwrapPlan.call, unwrapPlan.replacement]));
|
|
25
|
-
const unwrapEdits = unwrapPlans.filter((unwrapPlan) => sourceText.slice(unwrapPlan.start, unwrapPlan.end) !== unwrapPlan.replacement);
|
|
26
|
-
return {
|
|
27
|
-
cnInTvCalls,
|
|
28
|
-
unwrapReplacementByCall,
|
|
29
|
-
unwrapEdits,
|
|
30
|
-
textAfterUnwrap: unwrapEdits.length > 0 ? applyEditsDescending(sourceText, [...unwrapEdits]) : sourceText,
|
|
31
|
-
cnInTvNoReplacement: cnInTvCalls.length - unwrapPlans.length
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* `domainSfGrouped` must be a parse of `unwrap.textAfterUnwrap` (same `text` as source).
|
|
36
|
-
* Returns `null` when there is no cn-in-tv and no grouping targets.
|
|
37
|
-
*
|
|
38
|
-
* @since 0.3.16-canary.0
|
|
39
|
-
*/
|
|
40
|
-
function tryBuildGroupFileWorkPlan(input) {
|
|
41
|
-
const { filePath, sourceText, domainSfInitial, domainSfGrouped, withClassName, unwrap } = input;
|
|
42
|
-
if (domainSfGrouped.text !== unwrap.textAfterUnwrap) throw new Error("Domain invariant: domainSfGrouped.text must match unwrap phase textAfterUnwrap");
|
|
43
|
-
const groupTargets = collectGroupTargets(domainSfGrouped, filePath);
|
|
44
|
-
if (unwrap.cnInTvCalls.length === 0 && groupTargets.length === 0) return null;
|
|
45
|
-
const sortedTargets = [...groupTargets].toSorted((leftTarget, rightTarget) => targetReplaceStart(rightTarget) - targetReplaceStart(leftTarget));
|
|
46
|
-
const plannedGroupEdits = [];
|
|
47
|
-
for (const groupTarget of sortedTargets) {
|
|
48
|
-
const plan = planGroupEditForTarget(groupTarget, unwrap.textAfterUnwrap, withClassName);
|
|
49
|
-
if (plan === void 0) continue;
|
|
50
|
-
if (unwrap.textAfterUnwrap.slice(plan.start, plan.end) === plan.replacement) continue;
|
|
51
|
-
plannedGroupEdits.push(plan);
|
|
52
|
-
}
|
|
53
|
-
const editSitesCount = unwrap.unwrapEdits.length + plannedGroupEdits.length;
|
|
54
|
-
const reportTotal = editSitesCount + unwrap.cnInTvNoReplacement;
|
|
55
|
-
return {
|
|
56
|
-
filePath,
|
|
57
|
-
sourceText,
|
|
58
|
-
textAfterUnwrap: unwrap.textAfterUnwrap,
|
|
59
|
-
domainSfForLineNumbers: domainSfInitial,
|
|
60
|
-
domainSfGrouped,
|
|
61
|
-
cnInTvCalls: unwrap.cnInTvCalls,
|
|
62
|
-
unwrapReplacementByCall: unwrap.unwrapReplacementByCall,
|
|
63
|
-
unwrapEdits: unwrap.unwrapEdits,
|
|
64
|
-
plannedGroupEdits,
|
|
65
|
-
cnInTvNoReplacement: unwrap.cnInTvNoReplacement,
|
|
66
|
-
reportTotal,
|
|
67
|
-
editSitesCount
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* @since 0.3.16-canary.0
|
|
72
|
-
*/
|
|
73
|
-
function groupFileDryRunNoEdits(filePath) {
|
|
74
|
-
return {
|
|
75
|
-
filePath,
|
|
76
|
-
totalFound: 0,
|
|
77
|
-
changed: 0
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @since 0.3.16-canary.0
|
|
82
|
-
*/
|
|
83
|
-
function groupFilePreviewTotals(work) {
|
|
84
|
-
return {
|
|
85
|
-
filePath: work.filePath,
|
|
86
|
-
totalFound: work.reportTotal,
|
|
87
|
-
changed: 0
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* @since 0.3.16-canary.0
|
|
92
|
-
*/
|
|
93
|
-
function mergeGroupFileBodyText(work) {
|
|
94
|
-
const groupEdits = work.plannedGroupEdits.map((plannedEdit) => ({
|
|
95
|
-
start: plannedEdit.start,
|
|
96
|
-
end: plannedEdit.end,
|
|
97
|
-
replacement: plannedEdit.replacement,
|
|
98
|
-
jsxCn: plannedEdit.jsxCn
|
|
99
|
-
}));
|
|
100
|
-
return groupEdits.length > 0 ? applyEditsDescending(work.textAfterUnwrap, groupEdits) : work.textAfterUnwrap;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* @since 0.3.16-canary.0
|
|
104
|
-
*/
|
|
105
|
-
function groupFileEditsTouchJsxCn(work) {
|
|
106
|
-
return work.plannedGroupEdits.some((plannedEdit) => plannedEdit.jsxCn);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* @since 0.3.16-canary.0
|
|
110
|
-
*/
|
|
111
|
-
function countPersistedGroupFileEdits(work) {
|
|
112
|
-
return work.unwrapEdits.length + work.plannedGroupEdits.length;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* @since 0.3.16-canary.0
|
|
116
|
-
*/
|
|
117
|
-
function groupFileWorkHasNothingToReport(work) {
|
|
118
|
-
return work.editSitesCount === 0 && work.cnInTvNoReplacement === 0;
|
|
119
|
-
}
|
|
120
|
-
//#endregion
|
|
121
|
-
export { buildGroupFileUnwrapState, countPersistedGroupFileEdits, groupFileDryRunNoEdits, groupFileEditsTouchJsxCn, groupFilePreviewTotals, groupFileWorkHasNothingToReport, mergeGroupFileBodyText, tryBuildGroupFileWorkPlan };
|