• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const fs = require("fs");
2const path = require("path");
3
4const fourslashCasesNameArray = [
5    "addMemberNotInNodeModulesDeclarationFile.ts",
6    "codeFixAddMissingFunctionDeclaration16.ts",
7    "codeFixCannotFindModule_all.ts",
8    "codeFixCannotFindModule_suggestion_falsePositive.ts",
9    "codeFixCannotFindModule_suggestion_js.ts",
10    "codeFixCannotFindModule_suggestion.ts",
11    "codeFixCannotFindModule.ts",
12    "codeFixGenerateDefinitions.ts",
13    "completionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved.ts",
14    "completionForStringLiteralNonrelativeImport1.ts",
15    "completionForStringLiteralNonrelativeImport2.ts",
16    "completionForStringLiteralNonrelativeImport3.ts",
17    "completionForStringLiteralNonrelativeImport4.ts",
18    "completionForStringLiteralNonrelativeImport7.ts",
19    "completionForStringLiteralNonrelativeImport10.ts",
20    "completionForStringLiteralNonrelativeImport11.ts",
21    "completionForStringLiteralNonrelativeImport13.ts",
22    "completionForStringLiteralNonrelativeImportTypings3.ts",
23    "completionInJsDocQualifiedNames.ts",
24    "completionListForExportEquals.ts",
25    "completionListForExportEquals2.ts",
26    "completionListInImportClause05.ts",
27    "completionsImport_compilerOptionsModule.ts",
28    "completionsImport_default_symbolName.ts",
29    "completionsImport_defaultFalsePositive.ts",
30    "completionsImport_exportEqualsNamespace_noDuplicate.ts",
31    "completionsImport_filteredByInvalidPackageJson_direct.ts",
32    "completionsImport_filteredByPackageJson_@typesImplicit.ts",
33    "completionsImport_filteredByPackageJson_@typesOnly.ts",
34    "completionsImport_filteredByPackageJson_ambient.ts",
35    "completionsImport_filteredByPackageJson_direct.ts",
36    "completionsImport_filteredByPackageJson_nested.ts",
37    "completionsImport_filteredByPackageJson_peerDependencies.ts",
38    "completionsImport_filteredByPackageJson_reexport.ts",
39    "completionsImport_filteredByPackageJson_reexport2.ts",
40    "completionsImport_filteredByPackageJson_reexport3.ts",
41    "completionsImport_filteredByPackageJson_reexport4.ts",
42    "completionsImport_notFromUnrelatedNodeModules.ts",
43    "completionsImport_umdModules1_globalAccess.ts",
44    "completionsImport_umdModules2_moduleExports.ts",
45    "completionsImport_umdModules3_script.ts",
46    "completionsPathsJsonModule.ts",
47    "completionsPaths.ts",
48    "completionsPaths_fromTypings.ts",
49    "completionsPaths_importType.ts",
50    "documentHighlights_moduleImport_filesToSearch.ts",
51    "documentHighlights_moduleImport_filesToSearchWithInvalidFile.ts",
52    "duplicatePackageServices_fileChanges.ts",
53    "exportEqualNamespaceClassESModuleInterop.ts",
54    "findAllReferencesTripleSlash.ts",
55    "getEditsForFileRename_ambientModule.ts",
56    "getEditsForFileRename_directory_noUpdateNodeModulesImport.ts",
57    "getEditsForFileRename_nodeModuleDirectoryCase.ts",
58    "getEditsForFileRename_symlink.ts",
59    "goToDefinition_untypedModule.ts",
60    "importFixesGlobalTypingsCache.ts",
61    "importFixesWithPackageJsonInSideAnotherPackage.ts",
62    "importJsNodeModule1.ts",
63    "importJsNodeModule2.ts",
64    "importJsNodeModule3.ts",
65    "importJsNodeModule4.ts",
66    "importNameCodeFixExistingImport5.ts",
67    "importNameCodeFixExistingImport6.ts",
68    "importNameCodeFixNewImportFromAtTypes.ts",
69    "importNameCodeFixNewImportFromAtTypesScopedPackage.ts",
70    "importNameCodeFixNewImportIndex_notForClassicResolution.ts",
71    "importNameCodeFixNewImportNodeModules0.ts",
72    "importNameCodeFixNewImportNodeModules1.ts",
73    "importNameCodeFixNewImportNodeModules2.ts",
74    "importNameCodeFixNewImportNodeModules3.ts",
75    "importNameCodeFixNewImportNodeModules4.ts",
76    "importNameCodeFixNewImportNodeModules5.ts",
77    "importNameCodeFixNewImportNodeModules6.ts",
78    "importNameCodeFixNewImportNodeModules7.ts",
79    "importNameCodeFixNewImportNodeModules8.ts",
80    "importNameCodeFix_avoidRelativeNodeModules.ts",
81    "importNameCodeFix_getCanonicalFileName.ts",
82    "importNameCodeFix_symlink.ts",
83    "importNameCodeFix_symlink_own_package.ts",
84    "importNameCodeFix_symlink_own_package_2.ts",
85    "importNameCodeFix_types_classic.ts",
86    "importNameCodeFixOptionalImport1.ts",
87    "importNameCodeFixUMDGlobalReact0.ts",
88    "importNameCodeFixUMDGlobalReact1.ts",
89    "importTypesDeclarationDiagnosticsNoServerError.ts",
90    "moduleReexportedIntoGlobalQuickInfo.ts",
91    "noImportCompletionsInOtherJavaScriptFile.ts"
92];
93
94const compilerCasesNameArray = [
95    "declarationEmitForGlobalishSpecifierSymlink.ts",
96    "declarationEmitForGlobalishSpecifierSymlink2.ts",
97    "declarationEmitHasTypesRefOnNamespaceUse.ts",
98    "declarationEmitReexportedSymlinkReference.ts",
99    "declarationEmitReexportedSymlinkReference2.ts",
100    "declarationEmitReexportedSymlinkReference3.ts",
101    "declarationEmitSymlinkPaths.ts",
102    "declarationEmitUnnessesaryTypeReferenceNotAdded.ts",
103    "declarationEmitWithInvalidPackageJsonTypings.ts",
104    "duplicatePackage_globalMerge.ts",
105    "duplicatePackage.ts",
106    "duplicatePackage_packageIdIncludesSubModule.ts",
107    "duplicatePackage_referenceTypes.ts",
108    "duplicatePackage_relativeImportWithinPackage.ts",
109    "duplicatePackage_relativeImportWithinPackage_scoped.ts",
110    "duplicatePackage_subModule.ts",
111    "duplicatePackage_withErrors.ts",
112    "moduleLocalImportNotIncorrectlyRedirected.ts",
113    "moduleResolutionPackageIdWithRelativeAndAbsolutePath.ts",
114    "moduleResolutionWithExtensions_unexpected.ts",
115    "moduleResolutionWithExtensions_unexpected2.ts",
116    "moduleResolution_packageJson_notAtPackageRoot.ts",
117    "moduleResolution_packageJson_notAtPackageRoot_fakeScopedPackage.ts",
118    "moduleResolution_packageJson_scopedPackage.ts",
119    "moduleResolution_packageJson_yesAtPackageRoot.ts",
120    "moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.ts",
121    "moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.ts",
122    "symbolLinkDeclarationEmitModuleNamesImportRef.ts"
123];
124
125const thisFilePath = __dirname;
126function GenOHFourslashTestCases() {
127    const ohFourslashCasesDir = path.join(thisFilePath, "../tests/cases/fourslash/oh");
128    if (!fs.existsSync(ohFourslashCasesDir)) {
129        fs.mkdirSync(ohFourslashCasesDir);
130    }
131    for (const caseName of fourslashCasesNameArray) {
132        const fourslashCasesNamePath = path.join(thisFilePath, "../tests/cases/fourslash", caseName);
133
134        const ohFourslashCasesName = caseName.replace(/NodeModules/g, "OHModules").replace(/PackageJson/g, "OHPackageJson5");
135        const ohFourslashCasesNamePath = path.join(ohFourslashCasesDir, ohFourslashCasesName);
136
137        const fileContent = fs.readFileSync(fourslashCasesNamePath).toString();
138        let ohfileContent = fileContent.replace(/node_modules/g, "oh_modules").replace(/package.json/g, "oh-package.json5");
139        if (caseName === "completionForStringLiteralNonrelativeImport7.ts" || caseName === "completionForStringLiteralNonrelativeImport11.ts") {
140            ohfileContent = ohfileContent.replace("fourslash/modules", "fourslash/oh/modules")
141        }
142        fs.writeFileSync(ohFourslashCasesNamePath, ohfileContent);
143    }
144}
145
146function GenOHCompilerTestCases() {
147    const ohCompilerCasesDir = path.join(thisFilePath, "../tests/cases/compiler-oh");
148    const baselineDir = path.join(thisFilePath, "../tests/baselines/reference");
149    const baselineTypes = [".js", ".symbols", ".types", ".errors.txt", ".trace.json"];
150    if (!fs.existsSync(ohCompilerCasesDir)) {
151        fs.mkdirSync(ohCompilerCasesDir);
152    }
153
154    for (const caseName of compilerCasesNameArray) {
155        const compilerCasesNamePath = path.join(thisFilePath, "../tests/cases/compiler", caseName);
156        let ohCompilerCasesName = "";
157        if (RegExp(/NodeModules|PackageJson/g).test(caseName)) {
158            ohCompilerCasesName = caseName.replace(/NodeModules/g, "OHModules").replace(/PackageJson/g, "OHPackageJson5");
159        }
160        else {
161            ohCompilerCasesName = caseName.replace(".ts", "_isohpm.ts");
162        }
163        const ohCompilerCasesNamePath = path.join(ohCompilerCasesDir, ohCompilerCasesName);
164        const fileContent = fs.readFileSync(compilerCasesNamePath).toString();
165        let ohfileContent = "";
166        if (fileContent.startsWith("// @filename")) {
167            ohfileContent = "// @packageManagerType: ohpm\r\n" + fileContent.replace(/node_modules/g, "oh_modules").replace(/package.json/g, "oh-package.json5");
168        } else {
169            ohfileContent = "// @packageManagerType: ohpm\n" + fileContent.replace(/node_modules/g, "oh_modules").replace(/package.json/g, "oh-package.json5");
170        }
171        fs.writeFileSync(ohCompilerCasesNamePath, ohfileContent);
172
173        const baselineCaseNamePath = path.join(baselineDir, caseName);
174        for (const type of baselineTypes) {
175            const baselineNamePath = baselineCaseNamePath.replace(".ts", type);
176            if (!fs.existsSync(baselineNamePath)) {
177                continue;
178            }
179            const content = fs.readFileSync(baselineNamePath).toString();
180            let ohContent = content.replace(/node_modules/g, "oh_modules").replace(/package.json/g, "oh-package.json5").replace(caseName, ohCompilerCasesName);
181            if (type == ".js") {
182                ohContent = ohContent.replace("tests/cases/compiler", "tests/cases/compiler-oh");
183            }
184            const ohBaselineNamePath = path.join(baselineDir, ohCompilerCasesName).replace(".ts", type);
185            fs.writeFileSync(ohBaselineNamePath, ohContent);
186        }
187    }
188}
189
190function main() {
191    GenOHFourslashTestCases();
192    GenOHCompilerTestCases();
193}
194
195main()