@ai-dev-tools/test-copilot-core 1.0.19
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 +6 -0
- package/azure-pipelines.yml +51 -0
- package/out/cli/commands/appInsightTelemetry.d.ts +7 -0
- package/out/cli/commands/appInsightTelemetry.d.ts.map +1 -0
- package/out/cli/commands/appInsightTelemetry.js +76 -0
- package/out/cli/commands/appInsightTelemetry.js.map +1 -0
- package/out/cli/commands/cliConfig.d.ts +4 -0
- package/out/cli/commands/cliConfig.d.ts.map +1 -0
- package/out/cli/commands/cliConfig.js +68 -0
- package/out/cli/commands/cliConfig.js.map +1 -0
- package/out/cli/commands/prompt.d.ts +6 -0
- package/out/cli/commands/prompt.d.ts.map +1 -0
- package/out/cli/commands/prompt.js +29 -0
- package/out/cli/commands/prompt.js.map +1 -0
- package/out/cli/commands/ut.d.ts +14 -0
- package/out/cli/commands/ut.d.ts.map +1 -0
- package/out/cli/commands/ut.js +72 -0
- package/out/cli/commands/ut.js.map +1 -0
- package/out/cli/commands/utPipeCmdWrapper.d.ts +18 -0
- package/out/cli/commands/utPipeCmdWrapper.d.ts.map +1 -0
- package/out/cli/commands/utPipeCmdWrapper.js +37 -0
- package/out/cli/commands/utPipeCmdWrapper.js.map +1 -0
- package/out/cli/config/index.d.ts +15 -0
- package/out/cli/config/index.d.ts.map +1 -0
- package/out/cli/config/index.js +10 -0
- package/out/cli/config/index.js.map +1 -0
- package/out/cli/index.d.ts +3 -0
- package/out/cli/index.d.ts.map +1 -0
- package/out/cli/index.js +169 -0
- package/out/cli/index.js.map +1 -0
- package/out/cli/type.d.ts +11 -0
- package/out/cli/type.d.ts.map +1 -0
- package/out/cli/type.js +3 -0
- package/out/cli/type.js.map +1 -0
- package/out/cli/utils/ds.d.ts +3 -0
- package/out/cli/utils/ds.d.ts.map +1 -0
- package/out/cli/utils/ds.js +50 -0
- package/out/cli/utils/ds.js.map +1 -0
- package/out/cli/utils/gpt.d.ts +3 -0
- package/out/cli/utils/gpt.d.ts.map +1 -0
- package/out/cli/utils/gpt.js +63 -0
- package/out/cli/utils/gpt.js.map +1 -0
- package/out/core/analyze/cjs.d.ts +61 -0
- package/out/core/analyze/cjs.d.ts.map +1 -0
- package/out/core/analyze/cjs.js +358 -0
- package/out/core/analyze/cjs.js.map +1 -0
- package/out/core/analyze/class.d.ts +4 -0
- package/out/core/analyze/class.d.ts.map +1 -0
- package/out/core/analyze/class.js +32 -0
- package/out/core/analyze/class.js.map +1 -0
- package/out/core/analyze/declares.d.ts +7 -0
- package/out/core/analyze/declares.d.ts.map +1 -0
- package/out/core/analyze/declares.js +316 -0
- package/out/core/analyze/declares.js.map +1 -0
- package/out/core/analyze/deps.d.ts +8 -0
- package/out/core/analyze/deps.d.ts.map +1 -0
- package/out/core/analyze/deps.js +210 -0
- package/out/core/analyze/deps.js.map +1 -0
- package/out/core/analyze/functionComponent.d.ts +4 -0
- package/out/core/analyze/functionComponent.d.ts.map +1 -0
- package/out/core/analyze/functionComponent.js +77 -0
- package/out/core/analyze/functionComponent.js.map +1 -0
- package/out/core/analyze/functions.d.ts +4 -0
- package/out/core/analyze/functions.d.ts.map +1 -0
- package/out/core/analyze/functions.js +46 -0
- package/out/core/analyze/functions.js.map +1 -0
- package/out/core/analyze/index.d.ts +16 -0
- package/out/core/analyze/index.d.ts.map +1 -0
- package/out/core/analyze/index.js +149 -0
- package/out/core/analyze/index.js.map +1 -0
- package/out/core/analyze/index.type.d.ts +69 -0
- package/out/core/analyze/index.type.d.ts.map +1 -0
- package/out/core/analyze/index.type.js +14 -0
- package/out/core/analyze/index.type.js.map +1 -0
- package/out/core/analyze/utils/global.d.ts +2 -0
- package/out/core/analyze/utils/global.d.ts.map +1 -0
- package/out/core/analyze/utils/global.js +84 -0
- package/out/core/analyze/utils/global.js.map +1 -0
- package/out/core/analyzev2/declare/class.d.ts +4 -0
- package/out/core/analyzev2/declare/class.d.ts.map +1 -0
- package/out/core/analyzev2/declare/class.js +24 -0
- package/out/core/analyzev2/declare/class.js.map +1 -0
- package/out/core/analyzev2/declare/funcLike.d.ts +8 -0
- package/out/core/analyzev2/declare/funcLike.d.ts.map +1 -0
- package/out/core/analyzev2/declare/funcLike.js +71 -0
- package/out/core/analyzev2/declare/funcLike.js.map +1 -0
- package/out/core/analyzev2/declare/variable.d.ts +3 -0
- package/out/core/analyzev2/declare/variable.d.ts.map +1 -0
- package/out/core/analyzev2/declare/variable.js +15 -0
- package/out/core/analyzev2/declare/variable.js.map +1 -0
- package/out/core/analyzev2/file.d.ts +19 -0
- package/out/core/analyzev2/file.d.ts.map +1 -0
- package/out/core/analyzev2/file.js +449 -0
- package/out/core/analyzev2/file.js.map +1 -0
- package/out/core/analyzev2/index.d.ts +5 -0
- package/out/core/analyzev2/index.d.ts.map +1 -0
- package/out/core/analyzev2/index.js +30 -0
- package/out/core/analyzev2/index.js.map +1 -0
- package/out/core/analyzev2/type.d.ts +35 -0
- package/out/core/analyzev2/type.d.ts.map +1 -0
- package/out/core/analyzev2/type.js +3 -0
- package/out/core/analyzev2/type.js.map +1 -0
- package/out/core/config/index.d.ts +25 -0
- package/out/core/config/index.d.ts.map +1 -0
- package/out/core/config/index.js +14 -0
- package/out/core/config/index.js.map +1 -0
- package/out/core/constants.d.ts +9 -0
- package/out/core/constants.d.ts.map +1 -0
- package/out/core/constants.js +12 -0
- package/out/core/constants.js.map +1 -0
- package/out/core/features/common/base.d.ts +20 -0
- package/out/core/features/common/base.d.ts.map +1 -0
- package/out/core/features/common/base.js +77 -0
- package/out/core/features/common/base.js.map +1 -0
- package/out/core/features/common/types.d.ts +16 -0
- package/out/core/features/common/types.d.ts.map +1 -0
- package/out/core/features/common/types.js +12 -0
- package/out/core/features/common/types.js.map +1 -0
- package/out/core/features/generateFile.d.ts +31 -0
- package/out/core/features/generateFile.d.ts.map +1 -0
- package/out/core/features/generateFile.js +148 -0
- package/out/core/features/generateFile.js.map +1 -0
- package/out/core/features/generateSingle.d.ts +28 -0
- package/out/core/features/generateSingle.d.ts.map +1 -0
- package/out/core/features/generateSingle.js +149 -0
- package/out/core/features/generateSingle.js.map +1 -0
- package/out/core/features/index.d.ts +9 -0
- package/out/core/features/index.d.ts.map +1 -0
- package/out/core/features/index.js +16 -0
- package/out/core/features/index.js.map +1 -0
- package/out/core/features/lintFix.d.ts +2 -0
- package/out/core/features/lintFix.d.ts.map +1 -0
- package/out/core/features/lintFix.js +33 -0
- package/out/core/features/lintFix.js.map +1 -0
- package/out/core/features/mergeUTFile.d.ts +19 -0
- package/out/core/features/mergeUTFile.d.ts.map +1 -0
- package/out/core/features/mergeUTFile.js +63 -0
- package/out/core/features/mergeUTFile.js.map +1 -0
- package/out/core/features/removeFailedCases.d.ts +23 -0
- package/out/core/features/removeFailedCases.d.ts.map +1 -0
- package/out/core/features/removeFailedCases.js +81 -0
- package/out/core/features/removeFailedCases.js.map +1 -0
- package/out/core/features/updateSpec.d.ts +20 -0
- package/out/core/features/updateSpec.d.ts.map +1 -0
- package/out/core/features/updateSpec.js +98 -0
- package/out/core/features/updateSpec.js.map +1 -0
- package/out/core/features/validFix.d.ts +29 -0
- package/out/core/features/validFix.d.ts.map +1 -0
- package/out/core/features/validFix.js +219 -0
- package/out/core/features/validFix.js.map +1 -0
- package/out/core/generate/UTGen.d.ts +79 -0
- package/out/core/generate/UTGen.d.ts.map +1 -0
- package/out/core/generate/UTGen.js +795 -0
- package/out/core/generate/UTGen.js.map +1 -0
- package/out/core/llm/index.d.ts +9 -0
- package/out/core/llm/index.d.ts.map +1 -0
- package/out/core/llm/index.js +39 -0
- package/out/core/llm/index.js.map +1 -0
- package/out/core/llm/prompts/config.d.ts +6 -0
- package/out/core/llm/prompts/config.d.ts.map +1 -0
- package/out/core/llm/prompts/config.js +239 -0
- package/out/core/llm/prompts/config.js.map +1 -0
- package/out/core/llm/prompts/templates/common.d.ts +3 -0
- package/out/core/llm/prompts/templates/common.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/common.js +27 -0
- package/out/core/llm/prompts/templates/common.js.map +1 -0
- package/out/core/llm/prompts/templates/fixCase.d.ts +4 -0
- package/out/core/llm/prompts/templates/fixCase.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/fixCase.js +46 -0
- package/out/core/llm/prompts/templates/fixCase.js.map +1 -0
- package/out/core/llm/prompts/templates/fixLint.d.ts +3 -0
- package/out/core/llm/prompts/templates/fixLint.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/fixLint.js +22 -0
- package/out/core/llm/prompts/templates/fixLint.js.map +1 -0
- package/out/core/llm/prompts/templates/genClassMemberUT.d.ts +5 -0
- package/out/core/llm/prompts/templates/genClassMemberUT.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/genClassMemberUT.js +115 -0
- package/out/core/llm/prompts/templates/genClassMemberUT.js.map +1 -0
- package/out/core/llm/prompts/templates/genFuncUT.d.ts +4 -0
- package/out/core/llm/prompts/templates/genFuncUT.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/genFuncUT.js +64 -0
- package/out/core/llm/prompts/templates/genFuncUT.js.map +1 -0
- package/out/core/llm/prompts/templates/mergeUT.d.ts +4 -0
- package/out/core/llm/prompts/templates/mergeUT.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/mergeUT.js +106 -0
- package/out/core/llm/prompts/templates/mergeUT.js.map +1 -0
- package/out/core/llm/prompts/templates/msnStudio.d.ts +3 -0
- package/out/core/llm/prompts/templates/msnStudio.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/msnStudio.js +36 -0
- package/out/core/llm/prompts/templates/msnStudio.js.map +1 -0
- package/out/core/llm/prompts/templates/snapshotUT.d.ts +4 -0
- package/out/core/llm/prompts/templates/snapshotUT.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/snapshotUT.js +68 -0
- package/out/core/llm/prompts/templates/snapshotUT.js.map +1 -0
- package/out/core/llm/prompts/templates/updateSpecBlock.d.ts +3 -0
- package/out/core/llm/prompts/templates/updateSpecBlock.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/updateSpecBlock.js +38 -0
- package/out/core/llm/prompts/templates/updateSpecBlock.js.map +1 -0
- package/out/core/llm/prompts/templates/updateSpecFile.d.ts +3 -0
- package/out/core/llm/prompts/templates/updateSpecFile.d.ts.map +1 -0
- package/out/core/llm/prompts/templates/updateSpecFile.js +30 -0
- package/out/core/llm/prompts/templates/updateSpecFile.js.map +1 -0
- package/out/core/llm/types.d.ts +80 -0
- package/out/core/llm/types.d.ts.map +1 -0
- package/out/core/llm/types.js +5 -0
- package/out/core/llm/types.js.map +1 -0
- package/out/core/quality/validateMockedTest.d.ts +3 -0
- package/out/core/quality/validateMockedTest.d.ts.map +1 -0
- package/out/core/quality/validateMockedTest.js +211 -0
- package/out/core/quality/validateMockedTest.js.map +1 -0
- package/out/core/utils/checkTestIgnore.d.ts +4 -0
- package/out/core/utils/checkTestIgnore.d.ts.map +1 -0
- package/out/core/utils/checkTestIgnore.js +52 -0
- package/out/core/utils/checkTestIgnore.js.map +1 -0
- package/out/core/utils/common.d.ts +4 -0
- package/out/core/utils/common.d.ts.map +1 -0
- package/out/core/utils/common.js +34 -0
- package/out/core/utils/common.js.map +1 -0
- package/out/core/utils/console.d.ts +8 -0
- package/out/core/utils/console.d.ts.map +1 -0
- package/out/core/utils/console.js +24 -0
- package/out/core/utils/console.js.map +1 -0
- package/out/core/utils/deps.d.ts +3 -0
- package/out/core/utils/deps.d.ts.map +1 -0
- package/out/core/utils/deps.js +58 -0
- package/out/core/utils/deps.js.map +1 -0
- package/out/core/utils/eslintRuleHandler.d.ts +3 -0
- package/out/core/utils/eslintRuleHandler.d.ts.map +1 -0
- package/out/core/utils/eslintRuleHandler.js +98 -0
- package/out/core/utils/eslintRuleHandler.js.map +1 -0
- package/out/core/utils/file.d.ts +18 -0
- package/out/core/utils/file.d.ts.map +1 -0
- package/out/core/utils/file.js +142 -0
- package/out/core/utils/file.js.map +1 -0
- package/out/core/utils/lint.d.ts +9 -0
- package/out/core/utils/lint.d.ts.map +1 -0
- package/out/core/utils/lint.js +95 -0
- package/out/core/utils/lint.js.map +1 -0
- package/out/core/utils/lru.d.ts +12 -0
- package/out/core/utils/lru.d.ts.map +1 -0
- package/out/core/utils/lru.js +47 -0
- package/out/core/utils/lru.js.map +1 -0
- package/out/core/utils/move.d.ts +12 -0
- package/out/core/utils/move.d.ts.map +1 -0
- package/out/core/utils/move.js +93 -0
- package/out/core/utils/move.js.map +1 -0
- package/out/core/utils/msnStudio.d.ts +13 -0
- package/out/core/utils/msnStudio.d.ts.map +1 -0
- package/out/core/utils/msnStudio.js +150 -0
- package/out/core/utils/msnStudio.js.map +1 -0
- package/out/core/utils/parseCustomizedCmd.d.ts +2 -0
- package/out/core/utils/parseCustomizedCmd.d.ts.map +1 -0
- package/out/core/utils/parseCustomizedCmd.js +32 -0
- package/out/core/utils/parseCustomizedCmd.js.map +1 -0
- package/out/core/utils/specBlock.d.ts +20 -0
- package/out/core/utils/specBlock.d.ts.map +1 -0
- package/out/core/utils/specBlock.js +231 -0
- package/out/core/utils/specBlock.js.map +1 -0
- package/out/core/utils/system.d.ts +13 -0
- package/out/core/utils/system.d.ts.map +1 -0
- package/out/core/utils/system.js +86 -0
- package/out/core/utils/system.js.map +1 -0
- package/out/core/utils/telemetry.d.ts +9 -0
- package/out/core/utils/telemetry.d.ts.map +1 -0
- package/out/core/utils/telemetry.js +32 -0
- package/out/core/utils/telemetry.js.map +1 -0
- package/out/core/utils/tsMorph.d.ts +13 -0
- package/out/core/utils/tsMorph.d.ts.map +1 -0
- package/out/core/utils/tsMorph.js +76 -0
- package/out/core/utils/tsMorph.js.map +1 -0
- package/out/core/valid/customizedLint.d.ts +2 -0
- package/out/core/valid/customizedLint.d.ts.map +1 -0
- package/out/core/valid/customizedLint.js +64 -0
- package/out/core/valid/customizedLint.js.map +1 -0
- package/out/core/valid/customizedTest.d.ts +3 -0
- package/out/core/valid/customizedTest.d.ts.map +1 -0
- package/out/core/valid/customizedTest.js +58 -0
- package/out/core/valid/customizedTest.js.map +1 -0
- package/out/core/valid/extractVitestConfig.d.ts +5 -0
- package/out/core/valid/extractVitestConfig.d.ts.map +1 -0
- package/out/core/valid/extractVitestConfig.js +97 -0
- package/out/core/valid/extractVitestConfig.js.map +1 -0
- package/out/core/valid/getViteConfig.d.ts +2 -0
- package/out/core/valid/getViteConfig.d.ts.map +1 -0
- package/out/core/valid/getViteConfig.js +65 -0
- package/out/core/valid/getViteConfig.js.map +1 -0
- package/out/core/valid/index.d.ts +15 -0
- package/out/core/valid/index.d.ts.map +1 -0
- package/out/core/valid/index.js +99 -0
- package/out/core/valid/index.js.map +1 -0
- package/out/core/valid/jest.d.ts +4 -0
- package/out/core/valid/jest.d.ts.map +1 -0
- package/out/core/valid/jest.js +121 -0
- package/out/core/valid/jest.js.map +1 -0
- package/out/core/valid/mock.d.ts +2 -0
- package/out/core/valid/mock.d.ts.map +1 -0
- package/out/core/valid/mock.js +149 -0
- package/out/core/valid/mock.js.map +1 -0
- package/out/core/valid/remove.d.ts +5 -0
- package/out/core/valid/remove.d.ts.map +1 -0
- package/out/core/valid/remove.js +109 -0
- package/out/core/valid/remove.js.map +1 -0
- package/out/core/valid/tag.d.ts +3 -0
- package/out/core/valid/tag.d.ts.map +1 -0
- package/out/core/valid/tag.js +91 -0
- package/out/core/valid/tag.js.map +1 -0
- package/out/core/valid/type.d.ts +83 -0
- package/out/core/valid/type.d.ts.map +1 -0
- package/out/core/valid/type.js +3 -0
- package/out/core/valid/type.js.map +1 -0
- package/out/core/valid/vitest.d.ts +3 -0
- package/out/core/valid/vitest.d.ts.map +1 -0
- package/out/core/valid/vitest.js +82 -0
- package/out/core/valid/vitest.js.map +1 -0
- package/out/index.d.ts +20 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +60 -0
- package/out/index.js.map +1 -0
- package/out/setup.d.ts +11 -0
- package/out/setup.d.ts.map +1 -0
- package/out/setup.js +14 -0
- package/out/setup.js.map +1 -0
- package/out/types.d.ts +23 -0
- package/out/types.d.ts.map +1 -0
- package/out/types.js +3 -0
- package/out/types.js.map +1 -0
- package/package.json +39 -0
- package/package_devops.json +42 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonJSAnalyzer = void 0;
|
|
4
|
+
exports.maybeCjs = maybeCjs;
|
|
5
|
+
exports.analyzeCommonJSFile = analyzeCommonJSFile;
|
|
6
|
+
const ts_morph_1 = require("ts-morph");
|
|
7
|
+
const index_type_1 = require("./index.type");
|
|
8
|
+
const tsMorph_1 = require("../utils/tsMorph");
|
|
9
|
+
const declares_1 = require("./declares");
|
|
10
|
+
const localPackageRegex = /^(\.|@)/;
|
|
11
|
+
function maybeCjs(fileName, fileContent) {
|
|
12
|
+
if (fileName.endsWith(".cjs")) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (!/\.jsx?$/.test(fileName)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return fileContent.includes("module.exports")
|
|
19
|
+
|| fileContent.includes("exports.");
|
|
20
|
+
}
|
|
21
|
+
class CommonJSAnalyzer {
|
|
22
|
+
#imports = {};
|
|
23
|
+
#classes = [];
|
|
24
|
+
#functions = [];
|
|
25
|
+
#variables = [];
|
|
26
|
+
#results = [];
|
|
27
|
+
/**
|
|
28
|
+
* Analyzes a CommonJS file to extract imports and exports
|
|
29
|
+
*/
|
|
30
|
+
analyzeFile(filePath) {
|
|
31
|
+
const { sourceFile } = (0, tsMorph_1.getProject)(filePath, {
|
|
32
|
+
projectOptions: {
|
|
33
|
+
compilerOptions: {
|
|
34
|
+
allowJs: true,
|
|
35
|
+
checkJs: true,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (!sourceFile) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
this.#classes = sourceFile.getClasses();
|
|
43
|
+
this.#functions = sourceFile.getFunctions();
|
|
44
|
+
this.#variables = sourceFile.getVariableDeclarations().filter((decl) => {
|
|
45
|
+
const init = decl.getInitializer();
|
|
46
|
+
if (!init) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
// Check if it's a function expression or arrow function
|
|
50
|
+
if (init.isKind(ts_morph_1.SyntaxKind.FunctionExpression)
|
|
51
|
+
|| init.isKind(ts_morph_1.SyntaxKind.FunctionDeclaration)
|
|
52
|
+
|| init.isKind(ts_morph_1.SyntaxKind.ArrowFunction)
|
|
53
|
+
|| init.isKind(ts_morph_1.SyntaxKind.ClassExpression)
|
|
54
|
+
|| init.isKind(ts_morph_1.SyntaxKind.ClassDeclaration)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
// TODO: Check for HOC
|
|
58
|
+
// if (init.isKind(SyntaxKind.CallExpression)) {
|
|
59
|
+
// }
|
|
60
|
+
return false;
|
|
61
|
+
});
|
|
62
|
+
// Reset results for each analysis
|
|
63
|
+
this.#results = [];
|
|
64
|
+
this.analyzeRequireImports(sourceFile);
|
|
65
|
+
const exports = this.analyzeExports(sourceFile);
|
|
66
|
+
return exports.map(el => ({
|
|
67
|
+
...el,
|
|
68
|
+
isCommonJS: true,
|
|
69
|
+
importDeclares: this.#imports,
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Analyzes require() imports in a CommonJS file
|
|
74
|
+
*/
|
|
75
|
+
analyzeRequireImports(sourceFile) {
|
|
76
|
+
sourceFile.getVariableStatements().forEach((stmt) => {
|
|
77
|
+
stmt.getDeclarations().forEach((decl) => {
|
|
78
|
+
const requireInfo = this.extractRequireInfo(decl);
|
|
79
|
+
if (!requireInfo) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const { moduleName, nameIdentifier } = requireInfo;
|
|
83
|
+
if (!this.#imports[moduleName]) {
|
|
84
|
+
this.#imports[moduleName] = [];
|
|
85
|
+
}
|
|
86
|
+
this.processRequireDeclaration(nameIdentifier, decl, this.#imports[moduleName]);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Extracts require() call information from a variable declaration
|
|
92
|
+
*/
|
|
93
|
+
extractRequireInfo(decl) {
|
|
94
|
+
const init = decl.getInitializer();
|
|
95
|
+
if (!init || !init.isKind(ts_morph_1.SyntaxKind.CallExpression) || !init.getText().startsWith("require(")) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const moduleNameArg = init.getArguments()?.[0];
|
|
99
|
+
if (!moduleNameArg || !moduleNameArg.isKind(ts_morph_1.SyntaxKind.StringLiteral)) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const moduleName = moduleNameArg.getLiteralValue();
|
|
103
|
+
if (!moduleName || !localPackageRegex.test(moduleName)) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
moduleName,
|
|
108
|
+
nameIdentifier: decl.getNameNode()
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Processes a require declaration and adds it to the imports array
|
|
113
|
+
*/
|
|
114
|
+
processRequireDeclaration(nameIdentifier, decl, imports) {
|
|
115
|
+
if (nameIdentifier.isKind(ts_morph_1.SyntaxKind.Identifier)) {
|
|
116
|
+
// Simple case: const foo = require(...)
|
|
117
|
+
const typeNode = decl.getTypeNode();
|
|
118
|
+
const typeText = typeNode ? typeNode.getText() : decl.getType().getText();
|
|
119
|
+
if (typeText) {
|
|
120
|
+
imports.push({
|
|
121
|
+
name: decl.getName(),
|
|
122
|
+
declare: typeText,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (nameIdentifier.isKind(ts_morph_1.SyntaxKind.ObjectBindingPattern)) {
|
|
127
|
+
// Destructuring case: const { foo, bar } = require(...)
|
|
128
|
+
nameIdentifier.getElements().forEach((element) => {
|
|
129
|
+
if (!element.isKind(ts_morph_1.SyntaxKind.BindingElement)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const name = element.getName();
|
|
133
|
+
const typeText = element.getType()?.getText();
|
|
134
|
+
if (typeText) {
|
|
135
|
+
imports.push({
|
|
136
|
+
name,
|
|
137
|
+
declare: typeText,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Analyzes exports and module.exports in a CommonJS file
|
|
145
|
+
*/
|
|
146
|
+
analyzeExports(sourceFile) {
|
|
147
|
+
sourceFile.getStatements().forEach((stmt) => {
|
|
148
|
+
if (!stmt.isKind(ts_morph_1.SyntaxKind.ExpressionStatement)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const expr = stmt.asKind(ts_morph_1.SyntaxKind.ExpressionStatement).getExpression();
|
|
152
|
+
if (!expr.isKind(ts_morph_1.SyntaxKind.BinaryExpression)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const leftText = expr.getLeft().getText();
|
|
156
|
+
const right = expr.getRight();
|
|
157
|
+
this.processExportStatement(leftText, right);
|
|
158
|
+
});
|
|
159
|
+
return this.#results;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Processes a single export statement
|
|
163
|
+
*/
|
|
164
|
+
processExportStatement(leftText, right) {
|
|
165
|
+
// (module.)exports.xxx = ...
|
|
166
|
+
const exportsMatch = leftText.match(/^(?:module\.)?exports\.(\w+)$/);
|
|
167
|
+
if (exportsMatch) {
|
|
168
|
+
const name = exportsMatch[1];
|
|
169
|
+
this.processNamedExport(name, right);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// module.exports = ...
|
|
173
|
+
if (leftText === "module.exports") {
|
|
174
|
+
this.processModuleExport(right);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Processes a named export (exports.xxx = ...)
|
|
179
|
+
*/
|
|
180
|
+
processNamedExport(name, right) {
|
|
181
|
+
if (right.isKind(ts_morph_1.SyntaxKind.FunctionExpression) || right.isKind(ts_morph_1.SyntaxKind.FunctionDeclaration) || right.isKind(ts_morph_1.SyntaxKind.ArrowFunction)) {
|
|
182
|
+
this.extractFunction(right, name);
|
|
183
|
+
}
|
|
184
|
+
else if (right.isKind(ts_morph_1.SyntaxKind.ClassExpression) || right.isKind(ts_morph_1.SyntaxKind.ClassDeclaration)) {
|
|
185
|
+
this.extractClass(right, name);
|
|
186
|
+
}
|
|
187
|
+
else if (right.isKind(ts_morph_1.SyntaxKind.Identifier)) {
|
|
188
|
+
// If it's an identifier, we need to find the declaration
|
|
189
|
+
const decl = this.findByName(right.getText());
|
|
190
|
+
this.checkNode(decl, name);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Processes module.exports assignment
|
|
195
|
+
*/
|
|
196
|
+
processModuleExport(right) {
|
|
197
|
+
if (right.isKind(ts_morph_1.SyntaxKind.FunctionExpression) || right.isKind(ts_morph_1.SyntaxKind.FunctionDeclaration) || right.isKind(ts_morph_1.SyntaxKind.ArrowFunction)) {
|
|
198
|
+
this.extractFunction(right);
|
|
199
|
+
}
|
|
200
|
+
else if (right.isKind(ts_morph_1.SyntaxKind.ClassExpression)) {
|
|
201
|
+
this.extractClass(right);
|
|
202
|
+
}
|
|
203
|
+
else if (right.isKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)) {
|
|
204
|
+
this.processObjectLiteralExport(right);
|
|
205
|
+
}
|
|
206
|
+
else if (right.isKind(ts_morph_1.SyntaxKind.Identifier)) {
|
|
207
|
+
this.checkNode(this.findByName(right.getText()), "default", true);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Processes object literal exports (module.exports = { ... })
|
|
212
|
+
*/
|
|
213
|
+
processObjectLiteralExport(right) {
|
|
214
|
+
for (const prop of right.getProperties()) {
|
|
215
|
+
if (prop.isKind(ts_morph_1.SyntaxKind.PropertyAssignment)) {
|
|
216
|
+
this.processPropertyAssignment(prop);
|
|
217
|
+
}
|
|
218
|
+
else if (prop.isKind(ts_morph_1.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
219
|
+
this.processShorthandProperty(prop);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Processes property assignment in object literal export
|
|
225
|
+
*/
|
|
226
|
+
processPropertyAssignment(prop) {
|
|
227
|
+
const name = prop.getName();
|
|
228
|
+
const value = prop.getInitializer();
|
|
229
|
+
if (!value) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (value.isKind(ts_morph_1.SyntaxKind.Identifier)) {
|
|
233
|
+
const varName = value.getText();
|
|
234
|
+
const decl = this.findByName(varName);
|
|
235
|
+
this.checkNode(decl, name);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
this.checkNode(value, name);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Processes shorthand property in object literal export
|
|
243
|
+
*/
|
|
244
|
+
processShorthandProperty(prop) {
|
|
245
|
+
const name = prop.getName();
|
|
246
|
+
// Shorthand properties refer to variables or functions in the same scope
|
|
247
|
+
// Cannot directly extract code, so we look for the declaration
|
|
248
|
+
let decl = this.findByName(name);
|
|
249
|
+
this.checkNode(decl, name);
|
|
250
|
+
}
|
|
251
|
+
checkNode(node, name, isDefaultExport = false) {
|
|
252
|
+
if (!node) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
let decl = node;
|
|
256
|
+
if (decl.isKind(ts_morph_1.SyntaxKind.VariableDeclaration) && decl.hasInitializer()) {
|
|
257
|
+
decl = decl.getInitializer();
|
|
258
|
+
}
|
|
259
|
+
if (decl.isKind(ts_morph_1.SyntaxKind.FunctionDeclaration) ||
|
|
260
|
+
decl.isKind(ts_morph_1.SyntaxKind.FunctionExpression) ||
|
|
261
|
+
decl.isKind(ts_morph_1.SyntaxKind.ArrowFunction)) {
|
|
262
|
+
this.extractFunction(decl, name, isDefaultExport);
|
|
263
|
+
}
|
|
264
|
+
else if (decl.isKind(ts_morph_1.SyntaxKind.ClassDeclaration) || decl.isKind(ts_morph_1.SyntaxKind.ClassExpression)) {
|
|
265
|
+
this.extractClass(decl, name, isDefaultExport);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
extractFunction(funcNode, name, isDefaultExport = false) {
|
|
269
|
+
let nodeName = name;
|
|
270
|
+
if (!name && funcNode.isKind(ts_morph_1.SyntaxKind.FunctionDeclaration)) {
|
|
271
|
+
nodeName = funcNode.getName?.() || "default";
|
|
272
|
+
}
|
|
273
|
+
else if (!funcNode.isKind(ts_morph_1.SyntaxKind.FunctionDeclaration)) {
|
|
274
|
+
nodeName = nodeName || "default";
|
|
275
|
+
}
|
|
276
|
+
const linesRange = this.extractRange(funcNode);
|
|
277
|
+
this.#results.push({
|
|
278
|
+
type: index_type_1.CodeType.Function,
|
|
279
|
+
name: nodeName,
|
|
280
|
+
code: funcNode.getText(),
|
|
281
|
+
linesRange,
|
|
282
|
+
isDefaultExport
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
extractClass(classNode, name, isDefaultExport = false) {
|
|
286
|
+
const classFunctions = this.extractClassFunctions(classNode);
|
|
287
|
+
const linesRange = this.extractRange(classNode);
|
|
288
|
+
let nodeName = name;
|
|
289
|
+
if (!name) {
|
|
290
|
+
name = classNode.getName?.() || "default";
|
|
291
|
+
}
|
|
292
|
+
const classStructure = (0, declares_1.getClassStructure)(classNode, {
|
|
293
|
+
scanFunc: true,
|
|
294
|
+
skipDependencies: true
|
|
295
|
+
});
|
|
296
|
+
this.#results.push({
|
|
297
|
+
type: index_type_1.CodeType.Class,
|
|
298
|
+
name: nodeName,
|
|
299
|
+
code: (0, declares_1.getClassDeclaration)(classStructure),
|
|
300
|
+
classFunctions,
|
|
301
|
+
linesRange,
|
|
302
|
+
isDefaultExport
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Extracts class functions from a class expression
|
|
307
|
+
*/
|
|
308
|
+
extractClassFunctions(classExpression) {
|
|
309
|
+
const classFunctions = [];
|
|
310
|
+
for (const m of classExpression.getMembers()) {
|
|
311
|
+
this.addClassFunction(classFunctions, m);
|
|
312
|
+
}
|
|
313
|
+
return classFunctions;
|
|
314
|
+
}
|
|
315
|
+
extractRange(node) {
|
|
316
|
+
return [
|
|
317
|
+
node.getStartLineNumber(),
|
|
318
|
+
node.getEndLineNumber(),
|
|
319
|
+
];
|
|
320
|
+
}
|
|
321
|
+
addClassFunction(funcs, m) {
|
|
322
|
+
if (m.isKind(ts_morph_1.SyntaxKind.ClassStaticBlockDeclaration)) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
let name = '';
|
|
326
|
+
if (m.isKind(ts_morph_1.SyntaxKind.Constructor)) {
|
|
327
|
+
name = 'constructor';
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
name = m.getName?.() ?? "unknown";
|
|
331
|
+
}
|
|
332
|
+
funcs.push({
|
|
333
|
+
name,
|
|
334
|
+
body: m.getText(),
|
|
335
|
+
isStatic: m.hasModifier(ts_morph_1.SyntaxKind.StaticKeyword),
|
|
336
|
+
isProp: m.isKind(ts_morph_1.SyntaxKind.PropertyDeclaration),
|
|
337
|
+
scope: name,
|
|
338
|
+
linesRange: this.extractRange(m),
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
findByName(name) {
|
|
342
|
+
return this.#classes.find(c => c.getName() === name)
|
|
343
|
+
|| this.#functions.find(f => f.getName() === name)
|
|
344
|
+
|| this.#variables.find(v => v.getName() === name);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
exports.CommonJSAnalyzer = CommonJSAnalyzer;
|
|
348
|
+
function analyzeCommonJSFile(filePath) {
|
|
349
|
+
try {
|
|
350
|
+
const analyzer = new CommonJSAnalyzer();
|
|
351
|
+
return analyzer.analyzeFile(filePath);
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
console.error(`Error analyzing CommonJS file ${filePath}:`, error);
|
|
355
|
+
return [];
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
//# sourceMappingURL=cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cjs.js","sourceRoot":"","sources":["../../../src/core/analyze/cjs.ts"],"names":[],"mappings":";;;AAOA,4BAUC;AAyWD,kDAQC;AAlYD,uCAA6R;AAC7R,6CAAgF;AAChF,8CAA8C;AAC9C,yCAAoE;AAEpE,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAEpC,SAAgB,QAAQ,CAAC,QAAgB,EAAE,WAAmB;IAC1D,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,WAAW,CAAC,QAAQ,CAAC,gBAAgB,CAAC;WACtC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAClC;AACT,CAAC;AAED,MAAa,gBAAgB;IACzB,QAAQ,GAA8B,EAAE,CAAC;IAEzC,QAAQ,GAAuB,EAAE,CAAC;IAClC,UAAU,GAA0B,EAAE,CAAC;IACvC,UAAU,GAA0B,EAAE,CAAC;IAEvC,QAAQ,GAAqB,EAAE,CAAC;IAChC;;OAEG;IACI,WAAW,CAAC,QAAgB;QAC/B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,oBAAU,EAAC,QAAQ,EAAE;YACxC,cAAc,EAAE;gBACZ,eAAe,EAAE;oBACb,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE,IAAI;iBAChB;aACJ;SACJ,CAAC,CAAC;QACH,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO,EA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IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC;eAC/C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC,CAAC;IAC3D,CAAC;CAEJ;AArWD,4CAqWC;AAED,SAAgB,mBAAmB,CAAC,QAAgB;IAChD,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACxC,OAAO,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,iCAAiC,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;QACnE,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../../src/core/analyze/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,IAAI,EAAc,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAY,cAAc,EAAE,MAAM,cAAc,CAAC;AAIlE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,QAAQ,GAAG,SAAS,CAuB5G"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractClass = extractClass;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const index_type_1 = require("./index.type");
|
|
6
|
+
const declares_1 = require("./declares");
|
|
7
|
+
const deps_1 = require("./deps");
|
|
8
|
+
function extractClass(name, declaration, options) {
|
|
9
|
+
const kind = declaration.getKind();
|
|
10
|
+
if (kind !== ts_morph_1.SyntaxKind.ClassDeclaration) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const classDeclaration = declaration;
|
|
14
|
+
const structure = (0, declares_1.getClassStructure)(classDeclaration, {
|
|
15
|
+
...options,
|
|
16
|
+
scanFunc: true,
|
|
17
|
+
});
|
|
18
|
+
if (!structure) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const declareString = (0, declares_1.getClassDeclaration)(structure);
|
|
22
|
+
const res = {
|
|
23
|
+
type: index_type_1.CodeType.Class,
|
|
24
|
+
name: name,
|
|
25
|
+
body: `declare ${declareString}`,
|
|
26
|
+
classFunctions: structure.functions,
|
|
27
|
+
externalIdentifiers: options?.skipDependencies ? undefined : (0, deps_1.searchExternalIdentifiers)(declaration, options),
|
|
28
|
+
linesRange: [declaration.getStartLineNumber(), declaration.getEndLineNumber()]
|
|
29
|
+
};
|
|
30
|
+
return res;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class.js","sourceRoot":"","sources":["../../../src/core/analyze/class.ts"],"names":[],"mappings":";;AAKA,oCAuBC;AA5BD,uCAA8D;AAC9D,6CAAkE;AAClE,yCAAoE;AACpE,iCAAmD;AAEnD,SAAgB,YAAY,CAAC,IAAY,EAAE,WAAiB,EAAE,OAAwB;IAClF,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC;IACnC,IAAI,IAAI,KAAK,qBAAU,CAAC,gBAAgB,EAAE,CAAC;QACvC,OAAO;IACX,CAAC;IACD,MAAM,gBAAgB,GAAG,WAA+B,CAAC;IACzD,MAAM,SAAS,GAAG,IAAA,4BAAiB,EAAC,gBAAgB,EAAE;QAClD,GAAG,OAAO;QACV,QAAQ,EAAE,IAAI;KACjB,CAAC,CAAC;IACH,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,OAAO;IACX,CAAC;IACD,MAAM,aAAa,GAAG,IAAA,8BAAmB,EAAC,SAAS,CAAC,CAAC;IACrD,MAAM,GAAG,GAAa;QAClB,IAAI,EAAE,qBAAQ,CAAC,KAAK;QACpB,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,WAAW,aAAa,EAAE;QAChC,cAAc,EAAE,SAAS,CAAC,SAAS;QACnC,mBAAmB,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,gCAAyB,EAAC,WAAW,EAAE,OAAO,CAAC;QAC5G,UAAU,EAAE,CAAC,WAAW,CAAC,kBAAkB,EAAE,EAAE,WAAW,CAAC,gBAAgB,EAAE,CAAC;KACjF,CAAC;IACF,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ClassDeclaration, ImportDeclaration, SourceFile } from "ts-morph";
|
|
2
|
+
import { ClassStructure, DependData, ExtractOptions } from "./index.type";
|
|
3
|
+
export declare function getImportDeclarations(imports: ImportDeclaration[]): Record<string, DependData>;
|
|
4
|
+
export declare function getLocalDeclarations(sourceFile: SourceFile): Record<string, DependData>;
|
|
5
|
+
export declare function getClassDeclaration(structure: ClassStructure | undefined): string;
|
|
6
|
+
export declare function getClassStructure(classDeclaration: ClassDeclaration, options?: ExtractOptions): ClassStructure | undefined;
|
|
7
|
+
//# sourceMappingURL=declares.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declares.d.ts","sourceRoot":"","sources":["../../../src/core/analyze/declares.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA8F,iBAAiB,EAA8F,UAAU,EAAkF,MAAM,UAAU,CAAC;AACnV,OAAO,EAAiB,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGzF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAiB9F;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAyBvF;AAkJD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,cAAc,GAAG,SAAS,UAMxE;AAgCD,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,GAAG,SAAS,CA8D1H"}
|