@codefast/cli 0.5.0-canary.5 → 0.5.0-canary.6
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 +25 -20
- 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,215 +0,0 @@
|
|
|
1
|
-
//#region src/arrange/domain/ast/ast-node.ts
|
|
2
|
-
/**
|
|
3
|
-
* Pure-domain AST shapes for arrange analysis. No TypeScript compiler types.
|
|
4
|
-
* Positions mirror `getStart(sourceFile)` / `getEnd()` semantics from translation.
|
|
5
|
-
*
|
|
6
|
-
* @since 0.3.16-canary.0
|
|
7
|
-
*/
|
|
8
|
-
let DomainSyntaxKind = /* @__PURE__ */ function(DomainSyntaxKind) {
|
|
9
|
-
DomainSyntaxKind[DomainSyntaxKind["Unknown"] = 1] = "Unknown";
|
|
10
|
-
DomainSyntaxKind[DomainSyntaxKind["Identifier"] = 2] = "Identifier";
|
|
11
|
-
DomainSyntaxKind[DomainSyntaxKind["StringLiteral"] = 3] = "StringLiteral";
|
|
12
|
-
DomainSyntaxKind[DomainSyntaxKind["NoSubstitutionTemplateLiteral"] = 4] = "NoSubstitutionTemplateLiteral";
|
|
13
|
-
DomainSyntaxKind[DomainSyntaxKind["ImportDeclaration"] = 5] = "ImportDeclaration";
|
|
14
|
-
DomainSyntaxKind[DomainSyntaxKind["ImportClause"] = 6] = "ImportClause";
|
|
15
|
-
DomainSyntaxKind[DomainSyntaxKind["NamedImports"] = 7] = "NamedImports";
|
|
16
|
-
DomainSyntaxKind[DomainSyntaxKind["NamespaceImport"] = 8] = "NamespaceImport";
|
|
17
|
-
DomainSyntaxKind[DomainSyntaxKind["ImportSpecifier"] = 9] = "ImportSpecifier";
|
|
18
|
-
DomainSyntaxKind[DomainSyntaxKind["CallExpression"] = 10] = "CallExpression";
|
|
19
|
-
DomainSyntaxKind[DomainSyntaxKind["PropertyAccessExpression"] = 11] = "PropertyAccessExpression";
|
|
20
|
-
DomainSyntaxKind[DomainSyntaxKind["ObjectLiteralExpression"] = 12] = "ObjectLiteralExpression";
|
|
21
|
-
DomainSyntaxKind[DomainSyntaxKind["PropertyAssignment"] = 13] = "PropertyAssignment";
|
|
22
|
-
DomainSyntaxKind[DomainSyntaxKind["ArrayLiteralExpression"] = 14] = "ArrayLiteralExpression";
|
|
23
|
-
DomainSyntaxKind[DomainSyntaxKind["SpreadElement"] = 15] = "SpreadElement";
|
|
24
|
-
DomainSyntaxKind[DomainSyntaxKind["ParenthesizedExpression"] = 16] = "ParenthesizedExpression";
|
|
25
|
-
DomainSyntaxKind[DomainSyntaxKind["AsExpression"] = 17] = "AsExpression";
|
|
26
|
-
DomainSyntaxKind[DomainSyntaxKind["SatisfiesExpression"] = 18] = "SatisfiesExpression";
|
|
27
|
-
DomainSyntaxKind[DomainSyntaxKind["NonNullExpression"] = 19] = "NonNullExpression";
|
|
28
|
-
DomainSyntaxKind[DomainSyntaxKind["ConditionalExpression"] = 20] = "ConditionalExpression";
|
|
29
|
-
DomainSyntaxKind[DomainSyntaxKind["BinaryExpression"] = 21] = "BinaryExpression";
|
|
30
|
-
DomainSyntaxKind[DomainSyntaxKind["ExpressionStatement"] = 22] = "ExpressionStatement";
|
|
31
|
-
DomainSyntaxKind[DomainSyntaxKind["JsxAttribute"] = 23] = "JsxAttribute";
|
|
32
|
-
DomainSyntaxKind[DomainSyntaxKind["JsxExpression"] = 24] = "JsxExpression";
|
|
33
|
-
return DomainSyntaxKind;
|
|
34
|
-
}({});
|
|
35
|
-
/**
|
|
36
|
-
* @since 0.3.16-canary.0
|
|
37
|
-
*/
|
|
38
|
-
let DomainBinaryOperator = /* @__PURE__ */ function(DomainBinaryOperator) {
|
|
39
|
-
DomainBinaryOperator[DomainBinaryOperator["Plus"] = 0] = "Plus";
|
|
40
|
-
DomainBinaryOperator[DomainBinaryOperator["Other"] = 1] = "Other";
|
|
41
|
-
return DomainBinaryOperator;
|
|
42
|
-
}({});
|
|
43
|
-
/**
|
|
44
|
-
* @since 0.3.16-canary.0
|
|
45
|
-
*/
|
|
46
|
-
function isDomainIdentifier(node) {
|
|
47
|
-
return node.kind === 2;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* @since 0.3.16-canary.0
|
|
51
|
-
*/
|
|
52
|
-
function isDomainStringLiteral(node) {
|
|
53
|
-
return node.kind === 3;
|
|
54
|
-
}
|
|
55
|
-
function isDomainNoSubstitutionTemplateLiteral(node) {
|
|
56
|
-
return node.kind === 4;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @since 0.3.16-canary.0
|
|
60
|
-
*/
|
|
61
|
-
function isDomainTailwindClassLiteral(node) {
|
|
62
|
-
return isDomainStringLiteral(node) || isDomainNoSubstitutionTemplateLiteral(node);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* @since 0.3.16-canary.0
|
|
66
|
-
*/
|
|
67
|
-
function isDomainImportDeclaration(node) {
|
|
68
|
-
return node.kind === 5;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* @since 0.3.16-canary.0
|
|
72
|
-
*/
|
|
73
|
-
function isDomainNamedImports(node) {
|
|
74
|
-
return node.kind === 7;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @since 0.3.16-canary.0
|
|
78
|
-
*/
|
|
79
|
-
function isDomainNamespaceImport(node) {
|
|
80
|
-
return node.kind === 8;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* @since 0.3.16-canary.0
|
|
84
|
-
*/
|
|
85
|
-
function isDomainCallExpression(node) {
|
|
86
|
-
return node.kind === 10;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* @since 0.3.16-canary.0
|
|
90
|
-
*/
|
|
91
|
-
function isDomainObjectLiteralExpression(node) {
|
|
92
|
-
return node.kind === 12;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @since 0.3.16-canary.0
|
|
96
|
-
*/
|
|
97
|
-
function isDomainPropertyAssignment(node) {
|
|
98
|
-
return node.kind === 13;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @since 0.3.16-canary.0
|
|
102
|
-
*/
|
|
103
|
-
function isDomainArrayLiteralExpression(node) {
|
|
104
|
-
return node.kind === 14;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* @since 0.3.16-canary.0
|
|
108
|
-
*/
|
|
109
|
-
function isDomainSpreadElement(node) {
|
|
110
|
-
return node.kind === 15;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* @since 0.3.16-canary.0
|
|
114
|
-
*/
|
|
115
|
-
function isDomainPropertyAccessExpression(node) {
|
|
116
|
-
return node.kind === 11;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* @since 0.3.16-canary.0
|
|
120
|
-
*/
|
|
121
|
-
function isDomainJsxAttribute(node) {
|
|
122
|
-
return node.kind === 23;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* @since 0.3.16-canary.0
|
|
126
|
-
*/
|
|
127
|
-
function isDomainJsxExpression(node) {
|
|
128
|
-
return node.kind === 24;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* @since 0.3.16-canary.0
|
|
132
|
-
*/
|
|
133
|
-
function forEachDomainChild(node, visit) {
|
|
134
|
-
switch (node.kind) {
|
|
135
|
-
case 1:
|
|
136
|
-
for (const child of node.children) visit(child);
|
|
137
|
-
return;
|
|
138
|
-
case 5:
|
|
139
|
-
if (node.importClause) visit(node.importClause);
|
|
140
|
-
visit(node.moduleSpecifier);
|
|
141
|
-
return;
|
|
142
|
-
case 6:
|
|
143
|
-
if (node.name) visit(node.name);
|
|
144
|
-
if (node.namedBindings) visit(node.namedBindings);
|
|
145
|
-
return;
|
|
146
|
-
case 7:
|
|
147
|
-
for (const element of node.elements) visit(element);
|
|
148
|
-
return;
|
|
149
|
-
case 8:
|
|
150
|
-
visit(node.name);
|
|
151
|
-
return;
|
|
152
|
-
case 9:
|
|
153
|
-
if (node.propertyName) visit(node.propertyName);
|
|
154
|
-
visit(node.name);
|
|
155
|
-
return;
|
|
156
|
-
case 10:
|
|
157
|
-
visit(node.expression);
|
|
158
|
-
for (const arg of node.arguments) visit(arg);
|
|
159
|
-
return;
|
|
160
|
-
case 11:
|
|
161
|
-
visit(node.expression);
|
|
162
|
-
visit(node.name);
|
|
163
|
-
return;
|
|
164
|
-
case 12:
|
|
165
|
-
for (const prop of node.properties) visit(prop);
|
|
166
|
-
return;
|
|
167
|
-
case 13:
|
|
168
|
-
visit(node.name);
|
|
169
|
-
visit(node.initializer);
|
|
170
|
-
return;
|
|
171
|
-
case 14:
|
|
172
|
-
for (const element of node.elements) visit(element);
|
|
173
|
-
return;
|
|
174
|
-
case 15:
|
|
175
|
-
visit(node.expression);
|
|
176
|
-
return;
|
|
177
|
-
case 16:
|
|
178
|
-
case 17:
|
|
179
|
-
case 18:
|
|
180
|
-
case 19:
|
|
181
|
-
visit(node.expression);
|
|
182
|
-
return;
|
|
183
|
-
case 20:
|
|
184
|
-
visit(node.condition);
|
|
185
|
-
visit(node.whenTrue);
|
|
186
|
-
visit(node.whenFalse);
|
|
187
|
-
return;
|
|
188
|
-
case 21:
|
|
189
|
-
visit(node.left);
|
|
190
|
-
visit(node.right);
|
|
191
|
-
return;
|
|
192
|
-
case 22:
|
|
193
|
-
visit(node.expression);
|
|
194
|
-
return;
|
|
195
|
-
case 23:
|
|
196
|
-
visit(node.name);
|
|
197
|
-
if (node.initializer) visit(node.initializer);
|
|
198
|
-
return;
|
|
199
|
-
case 24:
|
|
200
|
-
if (node.expression) visit(node.expression);
|
|
201
|
-
return;
|
|
202
|
-
default: return;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* @since 0.3.16-canary.0
|
|
207
|
-
*/
|
|
208
|
-
function lineOfSourcePosition(sourceText, pos) {
|
|
209
|
-
const boundedPos = Math.max(0, Math.min(pos, sourceText.length));
|
|
210
|
-
let line = 1;
|
|
211
|
-
for (let i = 0; i < boundedPos; i++) if (sourceText.charCodeAt(i) === 10) line++;
|
|
212
|
-
return line;
|
|
213
|
-
}
|
|
214
|
-
//#endregion
|
|
215
|
-
export { DomainBinaryOperator, DomainSyntaxKind, forEachDomainChild, isDomainArrayLiteralExpression, isDomainCallExpression, isDomainIdentifier, isDomainImportDeclaration, isDomainJsxAttribute, isDomainJsxExpression, isDomainNamedImports, isDomainNamespaceImport, isDomainObjectLiteralExpression, isDomainPropertyAccessExpression, isDomainPropertyAssignment, isDomainSpreadElement, isDomainStringLiteral, isDomainTailwindClassLiteral, lineOfSourcePosition };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { isDomainArrayLiteralExpression, isDomainTailwindClassLiteral } from "./ast-node.mjs";
|
|
2
|
-
import "../constants.mjs";
|
|
3
|
-
//#region src/arrange/domain/ast/collectors-cn.ts
|
|
4
|
-
/**
|
|
5
|
-
* @since 0.3.16-canary.0
|
|
6
|
-
*/
|
|
7
|
-
function forEachStringLiteralInClassExpression(expr, sink, depth = 0, options) {
|
|
8
|
-
if (depth > 12) return;
|
|
9
|
-
if (isDomainTailwindClassLiteral(expr)) {
|
|
10
|
-
sink(expr);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (expr.kind === 16) {
|
|
14
|
-
forEachStringLiteralInClassExpression(expr.expression, sink, depth + 1, options);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (expr.kind === 17 || expr.kind === 18) {
|
|
18
|
-
forEachStringLiteralInClassExpression(expr.expression, sink, depth + 1, options);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (expr.kind === 19) {
|
|
22
|
-
forEachStringLiteralInClassExpression(expr.expression, sink, depth + 1, options);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (expr.kind === 20) {
|
|
26
|
-
if (options?.descendIntoConditional === false) return;
|
|
27
|
-
forEachStringLiteralInClassExpression(expr.whenTrue, sink, depth + 1, options);
|
|
28
|
-
forEachStringLiteralInClassExpression(expr.whenFalse, sink, depth + 1, options);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (expr.kind === 21 && expr.operator === 0) {
|
|
32
|
-
forEachStringLiteralInClassExpression(expr.left, sink, depth + 1, options);
|
|
33
|
-
forEachStringLiteralInClassExpression(expr.right, sink, depth + 1, options);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (isDomainArrayLiteralExpression(expr)) for (const arrayElement of expr.elements) {
|
|
37
|
-
if (arrayElement.kind === 15) continue;
|
|
38
|
-
forEachStringLiteralInClassExpression(arrayElement, sink, depth + 1, options);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @since 0.3.16-canary.0
|
|
43
|
-
*/
|
|
44
|
-
function isUnsafeLiteralForCnStyleApplySplit(classLiteral) {
|
|
45
|
-
return classLiteral.parent !== null && isDomainArrayLiteralExpression(classLiteral.parent);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @since 0.3.16-canary.0
|
|
49
|
-
*/
|
|
50
|
-
const CN_APPLY_LITERAL_WALK_OPTS = { descendIntoConditional: false };
|
|
51
|
-
/**
|
|
52
|
-
* @since 0.3.16-canary.0
|
|
53
|
-
*/
|
|
54
|
-
function collectUnconditionalTailwindLiteralsFromCnArguments(args) {
|
|
55
|
-
const staticLits = [];
|
|
56
|
-
for (const arg of args) if (isDomainTailwindClassLiteral(arg)) {
|
|
57
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(arg)) staticLits.push(arg);
|
|
58
|
-
} else forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
59
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(lit)) staticLits.push(lit);
|
|
60
|
-
}, 0, CN_APPLY_LITERAL_WALK_OPTS);
|
|
61
|
-
return staticLits;
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
|
-
export { CN_APPLY_LITERAL_WALK_OPTS, collectUnconditionalTailwindLiteralsFromCnArguments, forEachStringLiteralInClassExpression, isUnsafeLiteralForCnStyleApplySplit };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isDomainIdentifier, isDomainJsxExpression, isDomainTailwindClassLiteral } from "./ast-node.mjs";
|
|
2
|
-
//#region src/arrange/domain/ast/collectors-jsx.ts
|
|
3
|
-
/**
|
|
4
|
-
* @since 0.3.16-canary.0
|
|
5
|
-
*/
|
|
6
|
-
function jsxClassNameStaticLiteral(jsxClassNameAttribute) {
|
|
7
|
-
if (!isDomainIdentifier(jsxClassNameAttribute.name) || jsxClassNameAttribute.name.text !== "className") return;
|
|
8
|
-
const init = jsxClassNameAttribute.initializer;
|
|
9
|
-
if (!init) return;
|
|
10
|
-
if (isDomainTailwindClassLiteral(init)) return {
|
|
11
|
-
lit: init,
|
|
12
|
-
valueNode: init
|
|
13
|
-
};
|
|
14
|
-
if (isDomainJsxExpression(init) && init.expression) {
|
|
15
|
-
const jsxExpressionBody = init.expression;
|
|
16
|
-
if (isDomainTailwindClassLiteral(jsxExpressionBody)) return {
|
|
17
|
-
lit: jsxExpressionBody,
|
|
18
|
-
valueNode: init
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
export { jsxClassNameStaticLiteral };
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { forEachDomainChild, isDomainArrayLiteralExpression, isDomainCallExpression, isDomainObjectLiteralExpression, isDomainPropertyAssignment, isDomainSpreadElement, isDomainTailwindClassLiteral } from "./ast-node.mjs";
|
|
2
|
-
import "../constants.mjs";
|
|
3
|
-
import { CN_APPLY_LITERAL_WALK_OPTS, collectUnconditionalTailwindLiteralsFromCnArguments, forEachStringLiteralInClassExpression, isUnsafeLiteralForCnStyleApplySplit } from "./collectors-cn.mjs";
|
|
4
|
-
import { buildKnownCnTvBindings, isCnOrTvIdentifier, propertyAssignmentNameText } from "./helpers.mjs";
|
|
5
|
-
import { tokenizeClassString } from "../tailwind-token.mjs";
|
|
6
|
-
//#region src/arrange/domain/ast/collectors-tv.ts
|
|
7
|
-
/**
|
|
8
|
-
* @since 0.3.16-canary.0
|
|
9
|
-
*/
|
|
10
|
-
function traverseTvObject(sourceFile, obj, visitor, depth = 0, knownBindings) {
|
|
11
|
-
if (depth > 12) return;
|
|
12
|
-
for (const prop of obj.properties) {
|
|
13
|
-
if (!isDomainPropertyAssignment(prop)) continue;
|
|
14
|
-
const init = prop.initializer;
|
|
15
|
-
if (isDomainTailwindClassLiteral(init)) visitor(init, sourceFile, void 0);
|
|
16
|
-
else if (isDomainArrayLiteralExpression(init)) for (const arrayElement of init.elements) {
|
|
17
|
-
if (isDomainSpreadElement(arrayElement)) continue;
|
|
18
|
-
if (isDomainTailwindClassLiteral(arrayElement)) visitor(arrayElement, sourceFile, void 0);
|
|
19
|
-
else if (isDomainCallExpression(arrayElement) && isCnOrTvIdentifier(arrayElement.expression, "cn", knownBindings)) for (const arg of arrayElement.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
20
|
-
visitor(lit, sourceFile, arrayElement);
|
|
21
|
-
});
|
|
22
|
-
else if (isDomainObjectLiteralExpression(arrayElement)) for (const objectProperty of arrayElement.properties) {
|
|
23
|
-
if (!isDomainPropertyAssignment(objectProperty)) continue;
|
|
24
|
-
const propName = propertyAssignmentNameText(objectProperty);
|
|
25
|
-
if (propName !== "className" && propName !== "class") continue;
|
|
26
|
-
const innerInit = objectProperty.initializer;
|
|
27
|
-
if (isDomainTailwindClassLiteral(innerInit)) visitor(innerInit, sourceFile, void 0);
|
|
28
|
-
else if (isDomainArrayLiteralExpression(innerInit)) for (const nestedArrayElement of innerInit.elements) {
|
|
29
|
-
if (isDomainSpreadElement(nestedArrayElement)) continue;
|
|
30
|
-
if (isDomainTailwindClassLiteral(nestedArrayElement)) visitor(nestedArrayElement, sourceFile, void 0);
|
|
31
|
-
}
|
|
32
|
-
else if (isDomainCallExpression(innerInit) && isCnOrTvIdentifier(innerInit.expression, "cn", knownBindings)) for (const arg of innerInit.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
33
|
-
visitor(lit, sourceFile, innerInit);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else if (isDomainObjectLiteralExpression(init)) traverseTvObject(sourceFile, init, visitor, depth + 1, knownBindings);
|
|
38
|
-
else if (isDomainCallExpression(init) && isCnOrTvIdentifier(init.expression, "cn", knownBindings)) for (const arg of init.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
39
|
-
visitor(lit, sourceFile, init);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @since 0.3.16-canary.0
|
|
45
|
-
*/
|
|
46
|
-
function collectCnCallsInsideTv(sourceFile, obj, knownBindings, depth = 0) {
|
|
47
|
-
if (depth > 12) return [];
|
|
48
|
-
const calls = [];
|
|
49
|
-
for (const prop of obj.properties) {
|
|
50
|
-
if (!isDomainPropertyAssignment(prop)) continue;
|
|
51
|
-
const init = prop.initializer;
|
|
52
|
-
if (isDomainArrayLiteralExpression(init)) for (const arrayElement of init.elements) {
|
|
53
|
-
if (isDomainSpreadElement(arrayElement)) continue;
|
|
54
|
-
if (isDomainCallExpression(arrayElement) && isCnOrTvIdentifier(arrayElement.expression, "cn", knownBindings)) calls.push(arrayElement);
|
|
55
|
-
else if (isDomainObjectLiteralExpression(arrayElement)) for (const objectProperty of arrayElement.properties) {
|
|
56
|
-
if (!isDomainPropertyAssignment(objectProperty)) continue;
|
|
57
|
-
const propName = propertyAssignmentNameText(objectProperty);
|
|
58
|
-
if (propName !== "className" && propName !== "class") continue;
|
|
59
|
-
const innerInit = objectProperty.initializer;
|
|
60
|
-
if (isDomainCallExpression(innerInit) && isCnOrTvIdentifier(innerInit.expression, "cn", knownBindings)) calls.push(innerInit);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else if (isDomainObjectLiteralExpression(init)) calls.push(...collectCnCallsInsideTv(sourceFile, init, knownBindings, depth + 1));
|
|
64
|
-
else if (isDomainCallExpression(init) && isCnOrTvIdentifier(init.expression, "cn", knownBindings)) calls.push(init);
|
|
65
|
-
}
|
|
66
|
-
return calls;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @since 0.3.16-canary.0
|
|
70
|
-
*/
|
|
71
|
-
function listAllCnCallsInsideTvInSourceFile(sourceFile, knownBindings) {
|
|
72
|
-
const calls = [];
|
|
73
|
-
const visitSubtree = (tsNode) => {
|
|
74
|
-
if (isDomainCallExpression(tsNode) && isCnOrTvIdentifier(tsNode.expression, "tv", knownBindings)) {
|
|
75
|
-
const arg0 = tsNode.arguments[0];
|
|
76
|
-
if (arg0 && isDomainObjectLiteralExpression(arg0)) calls.push(...collectCnCallsInsideTv(sourceFile, arg0, knownBindings, 0));
|
|
77
|
-
}
|
|
78
|
-
forEachDomainChild(tsNode, visitSubtree);
|
|
79
|
-
};
|
|
80
|
-
for (const stmt of sourceFile.statements) visitSubtree(stmt);
|
|
81
|
-
return calls;
|
|
82
|
-
}
|
|
83
|
-
function makeStringNode(nodes, sourceFile, isTvContext, cnCall) {
|
|
84
|
-
return {
|
|
85
|
-
nodes,
|
|
86
|
-
sf: sourceFile,
|
|
87
|
-
isTvContext,
|
|
88
|
-
cnCall,
|
|
89
|
-
get primaryClassLiteral() {
|
|
90
|
-
const first = this.nodes[0];
|
|
91
|
-
if (first === void 0) throw new Error("invariant: StringNode requires at least one class literal");
|
|
92
|
-
return first;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* @since 0.3.16-canary.0
|
|
98
|
-
*/
|
|
99
|
-
function slotClassString(stringNode) {
|
|
100
|
-
return stringNode.nodes.map((literal) => literal.text).join(" ");
|
|
101
|
-
}
|
|
102
|
-
function emitTvSlot(lits, sourceFile, cnCall, results, seenNodePos) {
|
|
103
|
-
if (lits.length === 0) return;
|
|
104
|
-
const firstLit = lits[0];
|
|
105
|
-
if (firstLit === void 0) return;
|
|
106
|
-
const firstPos = firstLit.pos;
|
|
107
|
-
if (seenNodePos.has(firstPos)) return;
|
|
108
|
-
seenNodePos.add(firstPos);
|
|
109
|
-
if (lits.reduce((accumulatedTokenCount, literal) => accumulatedTokenCount + tokenizeClassString(literal.text).length, 0) < 2) return;
|
|
110
|
-
results.push(makeStringNode(lits, sourceFile, true, cnCall));
|
|
111
|
-
}
|
|
112
|
-
function collectTvSlots(sourceFile, obj, knownBindings, results, seenNodePos, depth = 0) {
|
|
113
|
-
if (depth > 12) return;
|
|
114
|
-
for (const prop of obj.properties) {
|
|
115
|
-
if (!isDomainPropertyAssignment(prop)) continue;
|
|
116
|
-
const init = prop.initializer;
|
|
117
|
-
if (isDomainTailwindClassLiteral(init)) emitTvSlot([init], sourceFile, void 0, results, seenNodePos);
|
|
118
|
-
else if (isDomainArrayLiteralExpression(init)) {
|
|
119
|
-
const arrayPos = init.pos;
|
|
120
|
-
if (seenNodePos.has(arrayPos)) continue;
|
|
121
|
-
seenNodePos.add(arrayPos);
|
|
122
|
-
const staticLits = [];
|
|
123
|
-
for (const arrayElement of init.elements) {
|
|
124
|
-
if (isDomainSpreadElement(arrayElement)) continue;
|
|
125
|
-
if (isDomainTailwindClassLiteral(arrayElement)) staticLits.push(arrayElement);
|
|
126
|
-
else if (isDomainCallExpression(arrayElement) && isCnOrTvIdentifier(arrayElement.expression, "cn", knownBindings)) for (const arg of arrayElement.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
127
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(lit)) staticLits.push(lit);
|
|
128
|
-
}, 0, CN_APPLY_LITERAL_WALK_OPTS);
|
|
129
|
-
else if (isDomainObjectLiteralExpression(arrayElement)) for (const objectProperty of arrayElement.properties) {
|
|
130
|
-
if (!isDomainPropertyAssignment(objectProperty)) continue;
|
|
131
|
-
const propName = propertyAssignmentNameText(objectProperty);
|
|
132
|
-
if (propName !== "className" && propName !== "class") continue;
|
|
133
|
-
const innerInit = objectProperty.initializer;
|
|
134
|
-
if (isDomainTailwindClassLiteral(innerInit)) emitTvSlot([innerInit], sourceFile, void 0, results, seenNodePos);
|
|
135
|
-
else if (isDomainArrayLiteralExpression(innerInit)) {
|
|
136
|
-
const innerLits = [];
|
|
137
|
-
for (const nestedArrayElement of innerInit.elements) if (!isDomainSpreadElement(nestedArrayElement) && isDomainTailwindClassLiteral(nestedArrayElement)) innerLits.push(nestedArrayElement);
|
|
138
|
-
emitTvSlot(innerLits, sourceFile, void 0, results, seenNodePos);
|
|
139
|
-
} else if (isDomainCallExpression(innerInit) && isCnOrTvIdentifier(innerInit.expression, "cn", knownBindings)) {
|
|
140
|
-
const cnLits = [];
|
|
141
|
-
for (const arg of innerInit.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
142
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(lit)) cnLits.push(lit);
|
|
143
|
-
}, 0, CN_APPLY_LITERAL_WALK_OPTS);
|
|
144
|
-
emitTvSlot(cnLits, sourceFile, innerInit, results, seenNodePos);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (staticLits.length > 0) emitTvSlot(staticLits, sourceFile, void 0, results, seenNodePos);
|
|
149
|
-
} else if (isDomainObjectLiteralExpression(init)) collectTvSlots(sourceFile, init, knownBindings, results, seenNodePos, depth + 1);
|
|
150
|
-
else if (isDomainCallExpression(init) && isCnOrTvIdentifier(init.expression, "cn", knownBindings)) {
|
|
151
|
-
const cnLits = [];
|
|
152
|
-
for (const arg of init.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
153
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(lit)) cnLits.push(lit);
|
|
154
|
-
}, 0, CN_APPLY_LITERAL_WALK_OPTS);
|
|
155
|
-
emitTvSlot(cnLits, sourceFile, init, results, seenNodePos);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @since 0.3.16-canary.0
|
|
161
|
-
*/
|
|
162
|
-
function collectGroupableStringNodes(sourceFile) {
|
|
163
|
-
const results = [];
|
|
164
|
-
const seenNodePos = /* @__PURE__ */ new Set();
|
|
165
|
-
const knownBindings = buildKnownCnTvBindings(sourceFile);
|
|
166
|
-
const visitTypeScriptSubtree = (tsNode) => {
|
|
167
|
-
if (isDomainCallExpression(tsNode)) {
|
|
168
|
-
if (isCnOrTvIdentifier(tsNode.expression, "cn", knownBindings)) {
|
|
169
|
-
const callPos = tsNode.pos;
|
|
170
|
-
if (seenNodePos.has(callPos)) {
|
|
171
|
-
forEachDomainChild(tsNode, visitTypeScriptSubtree);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
seenNodePos.add(callPos);
|
|
175
|
-
const staticLits = collectUnconditionalTailwindLiteralsFromCnArguments(tsNode.arguments);
|
|
176
|
-
const totalTokens = staticLits.reduce((accumulatedTokenCount, literal) => accumulatedTokenCount + tokenizeClassString(literal.text).length, 0);
|
|
177
|
-
if (staticLits.length > 0 && totalTokens >= 2) results.push(makeStringNode(staticLits, sourceFile, false, tsNode));
|
|
178
|
-
} else if (isCnOrTvIdentifier(tsNode.expression, "tv", knownBindings)) {
|
|
179
|
-
const arg0 = tsNode.arguments[0];
|
|
180
|
-
if (arg0 && isDomainObjectLiteralExpression(arg0)) collectTvSlots(sourceFile, arg0, knownBindings, results, seenNodePos);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
forEachDomainChild(tsNode, visitTypeScriptSubtree);
|
|
184
|
-
};
|
|
185
|
-
for (const stmt of sourceFile.statements) visitTypeScriptSubtree(stmt);
|
|
186
|
-
return results;
|
|
187
|
-
}
|
|
188
|
-
//#endregion
|
|
189
|
-
export { collectCnCallsInsideTv, collectGroupableStringNodes, listAllCnCallsInsideTvInSourceFile, slotClassString, traverseTvObject };
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { isDomainIdentifier, isDomainImportDeclaration, isDomainNamedImports, isDomainNamespaceImport, isDomainPropertyAccessExpression, isDomainStringLiteral, lineOfSourcePosition } from "./ast-node.mjs";
|
|
2
|
-
import { EMPTY_CN_TV_BINDINGS } from "../constants.mjs";
|
|
3
|
-
import { applyEditsDescending, indentOfLineContaining } from "../../../core/source-text-edit.mjs";
|
|
4
|
-
//#region src/arrange/domain/ast/helpers.ts
|
|
5
|
-
/**
|
|
6
|
-
* Known module specifiers that export `cn` / `tv`.
|
|
7
|
-
*/
|
|
8
|
-
const KNOWN_CN_TV_MODULES = /* @__PURE__ */ new Set([
|
|
9
|
-
"@codefast/tailwind-variants",
|
|
10
|
-
"clsx",
|
|
11
|
-
"class-variance-authority",
|
|
12
|
-
"tailwind-variants",
|
|
13
|
-
"#lib/utils",
|
|
14
|
-
"~/lib/utils",
|
|
15
|
-
"@/lib/utils"
|
|
16
|
-
]);
|
|
17
|
-
/**
|
|
18
|
-
* True for typical utils re-exports: `./utils`, `@/lib/utils`, `…/utils/…`,
|
|
19
|
-
* or a dedicated `cn.ts` / `cn.tsx` module.
|
|
20
|
-
*/
|
|
21
|
-
function moduleLooksLikeCnTvReexport(moduleSpecifier) {
|
|
22
|
-
const norm = moduleSpecifier.replace(/\\/g, "/");
|
|
23
|
-
if (/(?:^|[./])utils(?:\/|$)/.test(norm)) return true;
|
|
24
|
-
if (/\/utils\//.test(norm) || norm.endsWith("/utils")) return true;
|
|
25
|
-
if (/(?:^|\/)cn\.tsx?$/.test(norm)) return true;
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Build a set of local binding names that are imported from a known cn/tv
|
|
30
|
-
* module in `sourceFile`.
|
|
31
|
-
*
|
|
32
|
-
* @since 0.3.16-canary.0
|
|
33
|
-
*/
|
|
34
|
-
function buildKnownCnTvBindings(sourceFile) {
|
|
35
|
-
const bindings = /* @__PURE__ */ new Set();
|
|
36
|
-
for (const stmt of sourceFile.statements) {
|
|
37
|
-
if (!isDomainImportDeclaration(stmt) || !stmt.importClause) continue;
|
|
38
|
-
if (stmt.importClause.isTypeOnly) continue;
|
|
39
|
-
const spec = stmt.moduleSpecifier;
|
|
40
|
-
if (!isDomainStringLiteral(spec)) continue;
|
|
41
|
-
const moduleSpecifierText = spec.text;
|
|
42
|
-
if (!KNOWN_CN_TV_MODULES.has(moduleSpecifierText) && !moduleLooksLikeCnTvReexport(moduleSpecifierText)) continue;
|
|
43
|
-
const clause = stmt.importClause;
|
|
44
|
-
if (clause.name) bindings.add(clause.name.text);
|
|
45
|
-
const { namedBindings } = clause;
|
|
46
|
-
if (!namedBindings) continue;
|
|
47
|
-
if (isDomainNamedImports(namedBindings)) {
|
|
48
|
-
for (const namedImport of namedBindings.elements) bindings.add(namedImport.name.text);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (isDomainNamespaceImport(namedBindings)) bindings.add(namedBindings.name.text);
|
|
52
|
-
}
|
|
53
|
-
return bindings;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Returns true when `expr` is an identifier whose name matches `name` AND
|
|
57
|
-
* that name is listed in `knownBindings` from a recognized import.
|
|
58
|
-
*
|
|
59
|
-
* @since 0.3.16-canary.0
|
|
60
|
-
*/
|
|
61
|
-
function isCnOrTvIdentifier(expr, name, knownBindings = EMPTY_CN_TV_BINDINGS) {
|
|
62
|
-
if (knownBindings.size === 0) return false;
|
|
63
|
-
if (isDomainIdentifier(expr) && expr.text === name) return knownBindings.has(expr.text);
|
|
64
|
-
if (isDomainPropertyAccessExpression(expr) && expr.name.text === name) return isDomainIdentifier(expr.expression) && knownBindings.has(expr.expression.text);
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @since 0.3.16-canary.0
|
|
69
|
-
*/
|
|
70
|
-
function propertyAssignmentNameText(prop) {
|
|
71
|
-
if (isDomainIdentifier(prop.name)) return prop.name.text;
|
|
72
|
-
if (isDomainStringLiteral(prop.name)) return prop.name.text;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* @since 0.3.16-canary.0
|
|
76
|
-
*/
|
|
77
|
-
function lineOf(sourceFile, node) {
|
|
78
|
-
return lineOfSourcePosition(sourceFile.text, node.pos);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Replace `cn(...)` nested in `tv({...})` with a plain string (one arg) or a string
|
|
82
|
-
* array (multiple args). Returns undefined when there are zero arguments.
|
|
83
|
-
*
|
|
84
|
-
* @since 0.3.16-canary.0
|
|
85
|
-
*/
|
|
86
|
-
function unwrapCnInsideTvCallReplacement(call, sourceText) {
|
|
87
|
-
const args = call.arguments;
|
|
88
|
-
if (args.length === 0) return;
|
|
89
|
-
const baseIndent = indentOfLineContaining(sourceText, call.pos);
|
|
90
|
-
const innerIndent = `${baseIndent} `;
|
|
91
|
-
if (args.length === 1) {
|
|
92
|
-
const firstArg = args[0];
|
|
93
|
-
if (firstArg === void 0) return;
|
|
94
|
-
return sourceText.slice(firstArg.pos, firstArg.end);
|
|
95
|
-
}
|
|
96
|
-
const lines = ["["];
|
|
97
|
-
for (let i = 0; i < args.length; i++) {
|
|
98
|
-
const arg = args[i];
|
|
99
|
-
if (arg === void 0) throw new Error("invariant: unwrapCnInsideTvCall argument missing");
|
|
100
|
-
const piece = sourceText.slice(arg.pos, arg.end);
|
|
101
|
-
const comma = i < args.length - 1 || args.length > 1 ? "," : "";
|
|
102
|
-
lines.push(`${innerIndent}${piece}${comma}`);
|
|
103
|
-
}
|
|
104
|
-
lines.push(`${baseIndent}]`);
|
|
105
|
-
return lines.join("\n");
|
|
106
|
-
}
|
|
107
|
-
//#endregion
|
|
108
|
-
export { applyEditsDescending, buildKnownCnTvBindings, isCnOrTvIdentifier, lineOf, propertyAssignmentNameText, unwrapCnInsideTvCallReplacement };
|