@rxap/workspace-ts-morph 19.1.1-dev.0 → 19.1.1-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [19.1.1-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/workspace-ts-morph@19.1.1-dev.0...@rxap/workspace-ts-morph@19.1.1-dev.1) (2024-06-20)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rxap/workspace-ts-morph
|
|
9
|
+
|
|
6
10
|
## [19.1.1-dev.0](https://gitlab.com/rxap/packages/compare/@rxap/workspace-ts-morph@19.1.0...@rxap/workspace-ts-morph@19.1.1-dev.0) (2024-06-18)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @rxap/workspace-ts-morph
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "19.1.1-dev.
|
|
2
|
+
"version": "19.1.1-dev.1",
|
|
3
3
|
"name": "@rxap/workspace-ts-morph",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@rxap/ts-morph": "^1.4.0",
|
|
7
|
-
"@rxap/utilities": "^16.2.
|
|
8
|
-
"@rxap/workspace-utilities": "^19.
|
|
6
|
+
"@rxap/ts-morph": "^1.4.1-dev.0",
|
|
7
|
+
"@rxap/utilities": "^16.2.4-dev.0",
|
|
8
|
+
"@rxap/workspace-utilities": "^19.3.0-dev.0",
|
|
9
9
|
"ts-morph": "18.0.0",
|
|
10
10
|
"tslib": "2.6.2"
|
|
11
11
|
},
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"directory": "packages/workspace/ts-morph"
|
|
37
37
|
},
|
|
38
38
|
"type": "commonjs",
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "3fa5a96cac9ec03017cb91b15f918a0e66db9066",
|
|
40
40
|
"main": "./src/index.js"
|
|
41
41
|
}
|
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
import { TreeLike } from '@rxap/workspace-utilities';
|
|
2
2
|
import { Project } from 'ts-morph';
|
|
3
|
+
/**
|
|
4
|
+
* Applies transformations to TypeScript source files within a given project using the TsMorph library, and synchronizes these changes with a file tree structure.
|
|
5
|
+
*
|
|
6
|
+
* @param {TreeLike} tree - An abstraction representing the file tree to which the project files will be written.
|
|
7
|
+
* @param {Project} project - The TsMorph project instance containing the source files to be processed.
|
|
8
|
+
* @param {string} [basePath=''] - The base path in the file tree where the project files will be located. Defaults to an empty string, representing the root.
|
|
9
|
+
* @param {boolean} [organizeImports=true] - A flag indicating whether to organize imports within each source file. Defaults to true.
|
|
10
|
+
* @param {boolean} [fixMissingImports=false] - A flag indicating whether to automatically fix missing imports within each source file. Defaults to false.
|
|
11
|
+
*
|
|
12
|
+
* This function performs the following operations:
|
|
13
|
+
* 1. Optionally fixes missing imports and organizes imports in all source files of the project if the respective flags are set.
|
|
14
|
+
* 2. Iterates over each source file in the project:
|
|
15
|
+
* a. Constructs the full path for the file based on the provided `basePath`.
|
|
16
|
+
* b. Checks if the file already exists in the tree:
|
|
17
|
+
* i. If it exists, reads the current content and compares it with the new content from the source file.
|
|
18
|
+
* If they differ, the file in the tree is overwritten with the new content.
|
|
19
|
+
* ii. If it does not exist, creates a new file in the tree with the content from the source file.
|
|
20
|
+
*
|
|
21
|
+
* Note: This function utilizes the `TreeAdapter` to interact with the file tree, ensuring that file operations are abstracted and can handle different tree implementations.
|
|
22
|
+
*/
|
|
3
23
|
export declare function ApplyTsMorphProject(tree: TreeLike, project: Project, basePath?: string, organizeImports?: boolean, fixMissingImports?: boolean): void;
|
|
@@ -4,6 +4,22 @@ exports.ApplyTsMorphProject = void 0;
|
|
|
4
4
|
const ts_morph_1 = require("@rxap/ts-morph");
|
|
5
5
|
const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
+
/**
|
|
8
|
+
* Determines if two `SourceFile` objects are the same by comparing their leaf nodes.
|
|
9
|
+
*
|
|
10
|
+
* This function iteratively compares the text of each leaf node in both source files.
|
|
11
|
+
* Leaf nodes are the deepest nodes in the file's AST (Abstract Syntax Tree) that do not have children.
|
|
12
|
+
* The comparison stops as soon as a mismatch is found or all corresponding leaf nodes have been compared.
|
|
13
|
+
*
|
|
14
|
+
* @param {SourceFile} sourceFile1 - The first source file to compare.
|
|
15
|
+
* @param {SourceFile} sourceFile2 - The second source file to compare.
|
|
16
|
+
* @returns {boolean} - Returns `true` if all corresponding leaf nodes in both files have the same text, otherwise returns `false`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Assuming `sourceFile1` and `sourceFile2` are both parsed source files:
|
|
20
|
+
* const result = areSame(sourceFile1, sourceFile2);
|
|
21
|
+
* console.log(result); // Outputs: true if the files are the same, false otherwise.
|
|
22
|
+
*/
|
|
7
23
|
function areSame(sourceFile1, sourceFile2) {
|
|
8
24
|
const leafNodes1 = getLeafNodes(sourceFile1);
|
|
9
25
|
const leafNodes2 = getLeafNodes(sourceFile2);
|
|
@@ -36,6 +52,26 @@ function areSame(sourceFile1, sourceFile2) {
|
|
|
36
52
|
}
|
|
37
53
|
}
|
|
38
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Applies transformations to TypeScript source files within a given project using the TsMorph library, and synchronizes these changes with a file tree structure.
|
|
57
|
+
*
|
|
58
|
+
* @param {TreeLike} tree - An abstraction representing the file tree to which the project files will be written.
|
|
59
|
+
* @param {Project} project - The TsMorph project instance containing the source files to be processed.
|
|
60
|
+
* @param {string} [basePath=''] - The base path in the file tree where the project files will be located. Defaults to an empty string, representing the root.
|
|
61
|
+
* @param {boolean} [organizeImports=true] - A flag indicating whether to organize imports within each source file. Defaults to true.
|
|
62
|
+
* @param {boolean} [fixMissingImports=false] - A flag indicating whether to automatically fix missing imports within each source file. Defaults to false.
|
|
63
|
+
*
|
|
64
|
+
* This function performs the following operations:
|
|
65
|
+
* 1. Optionally fixes missing imports and organizes imports in all source files of the project if the respective flags are set.
|
|
66
|
+
* 2. Iterates over each source file in the project:
|
|
67
|
+
* a. Constructs the full path for the file based on the provided `basePath`.
|
|
68
|
+
* b. Checks if the file already exists in the tree:
|
|
69
|
+
* i. If it exists, reads the current content and compares it with the new content from the source file.
|
|
70
|
+
* If they differ, the file in the tree is overwritten with the new content.
|
|
71
|
+
* ii. If it does not exist, creates a new file in the tree with the content from the source file.
|
|
72
|
+
*
|
|
73
|
+
* Note: This function utilizes the `TreeAdapter` to interact with the file tree, ensuring that file operations are abstracted and can handle different tree implementations.
|
|
74
|
+
*/
|
|
39
75
|
function ApplyTsMorphProject(tree, project, basePath = '', organizeImports = true, fixMissingImports = false) {
|
|
40
76
|
if (organizeImports || fixMissingImports) {
|
|
41
77
|
project
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-ts-morph-project.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/apply-ts-morph-project.ts"],"names":[],"mappings":";;;AAAA,6CAA+C;AAC/C,mEAGmC;AACnC,+BAA4B;AAO5B,SAAS,OAAO,CAAC,WAAuB,EAAE,WAAuB;IAC/D,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAE7C,iDAAiD;IACjD,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAEhC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC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AU,CAAC,eAAe,EAAE,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,iCAAW,CAAC,IAAI,CAAC,CAAC;IAE1C,OAAO;SACJ,cAAc,EAAE;SAChB,OAAO,CAAC,UAAU,CAAC,EAAE;QAEpB,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,QAAQ,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QAE1D,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,MAAM,cAAc,GAAG,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACrE,MAAM,UAAU,GAAG,IAAA,wBAAa,GAAE,CAAC;YACnC,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;YAC5C,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;gBACjF,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QACzD,CAAC;IAEH,CAAC,CAAC,CAAC;AACP,CAAC;AAxCD,kDAwCC"}
|
|
@@ -7,6 +7,27 @@ const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const add_dir_1 = require("./add-dir");
|
|
9
9
|
const apply_ts_morph_project_1 = require("./apply-ts-morph-project");
|
|
10
|
+
/**
|
|
11
|
+
* Transforms TypeScript source files using the TsMorph library based on specified options and filters.
|
|
12
|
+
*
|
|
13
|
+
* @param tree - An abstract representation of the file system hierarchy.
|
|
14
|
+
* @param sourceRoot - The root directory where the source files are located.
|
|
15
|
+
* @param cb - A callback function that performs operations on the TsMorph project and its source files.
|
|
16
|
+
* @param options - Configuration options for the transformation process. Defaults to an empty object.
|
|
17
|
+
* @param projectOptions - Additional options to configure the TsMorph project. Defaults to an empty object.
|
|
18
|
+
* @param filePathFilter - Optional filter to specify which files should be included in the transformation. Can be a single string, an array of strings, or undefined.
|
|
19
|
+
*
|
|
20
|
+
* The function initializes a TsMorph project with the given `projectOptions`, and logs the transformation process.
|
|
21
|
+
* It handles file path filtering, ensuring only specified files are included based on `filePathFilter`.
|
|
22
|
+
* If `options.replace` is false, it adds directories and files to the project without replacing existing ones.
|
|
23
|
+
* The function throws errors for invalid configurations or when specified files do not exist and are required.
|
|
24
|
+
* Finally, it applies the transformations to the project and updates the file system tree.
|
|
25
|
+
*
|
|
26
|
+
* Errors:
|
|
27
|
+
* - Throws an error if `dirPath` ends with `fileName`.
|
|
28
|
+
* - Throws an error if a specified file does not exist and is not marked as optional when `replace` is false.
|
|
29
|
+
* - Throws an error if `filePathFilter` is not an array but multiple files are attempted to be processed.
|
|
30
|
+
*/
|
|
10
31
|
function TsMorphTransform(tree, sourceRoot, cb, options = {}, projectOptions = {}, filePathFilter) {
|
|
11
32
|
const { replace = false, filter = true, } = options;
|
|
12
33
|
let filePath = undefined;
|
|
@@ -72,16 +93,81 @@ function TsMorphTransform(tree, sourceRoot, cb, options = {}, projectOptions = {
|
|
|
72
93
|
(0, apply_ts_morph_project_1.ApplyTsMorphProject)(tree, project, sourceRoot, false);
|
|
73
94
|
}
|
|
74
95
|
exports.TsMorphTransform = TsMorphTransform;
|
|
96
|
+
/**
|
|
97
|
+
* Transforms a NestJS project using TypeScript morph transformations.
|
|
98
|
+
*
|
|
99
|
+
* This function applies a transformation to a NestJS project by utilizing the TsMorph library. It first constructs a base path for the project using the provided `tree` and `options`, then delegates the transformation process to the `TsMorphTransform` function.
|
|
100
|
+
*
|
|
101
|
+
* @param tree - The project's file structure represented as a `TreeLike` object, which abstracts the file system operations.
|
|
102
|
+
* @param options - An object of type `TsMorphNestProjectTransformOptions`, which includes settings and configurations for the transformation process.
|
|
103
|
+
* @param cb - A callback function of type `TsMorphTransformCallback` that defines how each file should be transformed using the TsMorph library.
|
|
104
|
+
* @param filePath - Optional. A specific file path or an array of file paths within the project to apply the transformation. If undefined, the transformation is applied to all applicable files within the project.
|
|
105
|
+
*/
|
|
75
106
|
function TsMorphNestProjectTransform(tree, options, cb, filePath) {
|
|
76
107
|
const basePath = (0, workspace_utilities_1.BuildNestBasePath)(tree, options);
|
|
77
108
|
return TsMorphTransform(tree, basePath, cb, options, options.projectOptions, filePath);
|
|
78
109
|
}
|
|
79
110
|
exports.TsMorphNestProjectTransform = TsMorphNestProjectTransform;
|
|
111
|
+
/**
|
|
112
|
+
* Transforms an Angular project using TypeScript morph transformations.
|
|
113
|
+
*
|
|
114
|
+
* This function applies a transformation callback to an Angular project's TypeScript files,
|
|
115
|
+
* potentially modifying their structure or contents based on the provided options. It leverages
|
|
116
|
+
* the TsMorph library to manipulate the project's source code files.
|
|
117
|
+
*
|
|
118
|
+
* @param tree - An abstraction representing the file structure of the project.
|
|
119
|
+
* @param options - Configuration options that are immutable, guiding the transformation process.
|
|
120
|
+
* @param cb - A callback function that defines how individual files or sets of files should be transformed.
|
|
121
|
+
* @param filePath - Optional. A specific file or array of files to target for transformation. If undefined,
|
|
122
|
+
* the transformation is applied to all relevant files in the project.
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* The `filePath` parameter allows for selective transformation, enabling focused modifications rather than
|
|
126
|
+
* a full-project sweep. This can be useful for large projects or when only certain files need to be updated.
|
|
127
|
+
*
|
|
128
|
+
* The transformation process is initialized by determining the base path of the Angular project using the
|
|
129
|
+
* `BuildAngularBasePath` function, which constructs the path based on the provided `tree` and `options`.
|
|
130
|
+
* This base path is then used to guide the TsMorph transformation process.
|
|
131
|
+
*/
|
|
80
132
|
function TsMorphAngularProjectTransform(tree, options, cb, filePath) {
|
|
81
133
|
const basePath = (0, workspace_utilities_1.BuildAngularBasePath)(tree, options);
|
|
82
134
|
return TsMorphTransform(tree, basePath, cb, options, options.projectOptions, filePath);
|
|
83
135
|
}
|
|
84
136
|
exports.TsMorphAngularProjectTransform = TsMorphAngularProjectTransform;
|
|
137
|
+
/**
|
|
138
|
+
* Transforms a project using the TsMorph library based on specified options and a callback function.
|
|
139
|
+
*
|
|
140
|
+
* This function serves as a wrapper around the `TsMorphTransform` function, specifically tailored to handle
|
|
141
|
+
* TypeScript project transformations. It utilizes the TsMorph library to apply transformations to files within
|
|
142
|
+
* a project structure.
|
|
143
|
+
*
|
|
144
|
+
* @param tree - The abstract representation of the file tree to which the transformation will be applied.
|
|
145
|
+
* @param options - An object containing options for the transformation, including project-specific settings.
|
|
146
|
+
* @param cb - A callback function that defines how individual files or sets of files should be transformed.
|
|
147
|
+
* This function is called for each file in the project that matches the criteria specified in `filePath`.
|
|
148
|
+
* @param filePath - Optional. A path or an array of paths specifying particular files or directories to transform.
|
|
149
|
+
* If undefined, the transformation is applied to all files in the project.
|
|
150
|
+
*
|
|
151
|
+
* @remarks
|
|
152
|
+
* The `options` object must include a `project` property that specifies the name of the project within the workspace.
|
|
153
|
+
* Additional project-specific options can be provided through `options.projectOptions`.
|
|
154
|
+
*
|
|
155
|
+
* The function first determines the root directory of the project by calling `GetProjectRoot` with the provided `tree`
|
|
156
|
+
* and `project` name from `options`. It then delegates the actual transformation process to `TsMorphTransform`,
|
|
157
|
+
* passing along the necessary parameters.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* TsMorphProjectTransform(tree, {
|
|
161
|
+
* project: 'my-app',
|
|
162
|
+
* projectOptions: { compilerOptions: { target: ts.ScriptTarget.ES5 } }
|
|
163
|
+
* }, (sourceFile) => {
|
|
164
|
+
* sourceFile.addImportDeclaration({
|
|
165
|
+
* moduleSpecifier: "lodash",
|
|
166
|
+
* namedImports: ["flatten"]
|
|
167
|
+
* });
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
85
171
|
function TsMorphProjectTransform(tree, options, cb, filePath) {
|
|
86
172
|
return TsMorphTransform(tree, (0, workspace_utilities_1.GetProjectRoot)(tree, options.project), cb, options, options.projectOptions, filePath);
|
|
87
173
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-morph-transform.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/ts-morph-transform.ts"],"names":[],"mappings":";;;AAAA,6CAA+C;AAC/C,+CAA8C;AAC9C,mEAMmC;AACnC,+BAA4B;AAM5B,uCAAmC;AACnC,qEAA+D;AAwC/D,SAAgB,gBAAgB,CAC9B,IAAc,EACd,UAAkB,EAClB,EAA4B,EAC5B,UAAmC,EAAE,EACrC,iBAA0C,EAAE,EAC5C,cAA8C;IAE9C,MAAM,EACJ,OAAO,GAAG,KAAK,EACf,MAAM,GAAG,IAAI,GACd,GAAG,OAAO,CAAC;IAEZ,IAAI,QAAQ,GAAyB,SAAS,CAAC;IAE/C,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YAClC,QAAQ,GAAG,cAAc,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,CAAE,cAAc,CAAE,CAAC;QAChC,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,IAAA,wBAAa,EAAC,cAAc,CAAC,CAAC;IAE9C,OAAO,CAAC,GAAG,CAAC,oCAAoC,UAAU,sBAAsB,IAAA,uBAAW,EAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjI,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,IAAA,gBAAM,EACJ,IAAI,EACJ,UAAU,EACV,OAAO,EACP,CAAC,QAAgB,EAAE,OAAe,EAAE,EAAE;YACpC,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAA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8B,CAC5C,IAAc,EACd,OAAwD,EACxD,EAA4B,EAC5B,QAAwC;IAExC,MAAM,QAAQ,GAAG,IAAA,0CAAoB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrD,OAAO,gBAAgB,CACrB,IAAI,EACJ,QAAQ,EACR,EAAS,EACT,OAAO,EACP,OAAO,CAAC,cAAc,EACtB,QAAe,CAChB,CAAC;AACJ,CAAC;AAfD,wEAeC;AAyBD,SAAgB,uBAAuB,CACrC,IAAc,EACd,OAAiD,EACjD,EAA4B,EAC5B,QAAwC;IAExC,OAAO,gBAAgB,CACrB,IAAI,EACJ,IAAA,oCAAc,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EACrC,EAAS,EACT,OAAO,EACP,OAAO,CAAC,cAAc,EACtB,QAAe,CAChB,CAAC;AACJ,CAAC;AAdD,0DAcC"}
|
|
1
|
+
{"version":3,"file":"ts-morph-transform.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/ts-morph-transform.ts"],"names":[],"mappings":";;;AAAA,6CAA+C;AAC/C,+CAA8C;AAC9C,mEAMmC;AACnC,+BAA4B;AAM5B,uCAAmC;AACnC,qEAA+D;AAwC/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,gBAAgB,CAC9B,IAAc,EACd,UAAkB,EAClB,EAA4B,EAC5B,UAAmC,EAAE,EACrC,iBAA0C,EAAE,EAC5C,cAA8C;IAE9C,MAAM,EACJ,OAAO,GAAG,KAAK,EACf,MAAM,GAAG,IAAI,GACd,GAAG,OAAO,CAAC;IAEZ,IAAI,QAAQ,GAAyB,SAAS,CAAC;IAE/C,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YAClC,QAAQ,GAAG,cAAc,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,CAAE,cAAc,CAAE,CAAC;QAChC,CAAC;IACH,CAAC;IA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