diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/js/dce/K2JSDce.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/js/dce/K2JSDce.kt index 420017f4259..cad5d078f86 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/js/dce/K2JSDce.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/js/dce/K2JSDce.kt @@ -38,8 +38,7 @@ class K2JSDce : CLITool() { val files = collectInputFiles(baseDir, arg, messageCollector) if (files != null) { files - } - else { + } else { hasErrors = true emptyList() } @@ -56,8 +55,9 @@ class K2JSDce : CLITool() { for (file in files) { existingFiles[file.outputPath]?.let { messageCollector.report( - CompilerMessageSeverity.ERROR, - "duplicate target file will be created for '${file.resource.name}' and '${it.resource.name}'") + CompilerMessageSeverity.ERROR, + "duplicate target file will be created for '${file.resource.name}' and '${it.resource.name}'" + ) return ExitCode.COMPILATION_ERROR } existingFiles[file.outputPath] = file @@ -69,8 +69,7 @@ class K2JSDce : CLITool() { return if (!arguments.devMode) { performDce(files, arguments, messageCollector) - } - else { + } else { copyFiles(files) ExitCode.OK } @@ -95,8 +94,10 @@ class K2JSDce : CLITool() { val reachabilitySeverity = if (arguments.printReachabilityInfo) CompilerMessageSeverity.INFO else CompilerMessageSeverity.LOGGING messageCollector.report(reachabilitySeverity, "") for (node in nodes.extractRoots()) { - printTree(node, { messageCollector.report(reachabilitySeverity, it) }, - printNestedMembers = false, showLocations = true) + printTree( + node, { messageCollector.report(reachabilitySeverity, it) }, + printNestedMembers = false, showLocations = true + ) } return ExitCode.OK @@ -123,14 +124,13 @@ class K2JSDce : CLITool() { FileOutputStream(targetFile).use { output -> input.copyTo(output) } - } + } } private fun mapSourcePaths(inputFile: File, targetFile: File): Boolean { val json = try { InputStreamReader(FileInputStream(inputFile), "UTF-8").use { parseJson(it) } - } - catch (e: JsonSyntaxException) { + } catch (e: JsonSyntaxException) { return false } @@ -145,12 +145,10 @@ class K2JSDce : CLITool() { if (result != null) { if (File(targetFile.parentFile, result).exists()) { result - } - else { + } else { it } - } - else { + } else { it } } @@ -180,8 +178,10 @@ class K2JSDce : CLITool() { collectInputFilesFromZip(baseDir, fileName) } else -> { - messageCollector.report(CompilerMessageSeverity.ERROR, - "invalid file name '$fileName'; must end either with '.js', '.zip' or '.jar'") + messageCollector.report( + CompilerMessageSeverity.ERROR, + "invalid file name '$fileName'; must end either with '.js', '.zip' or '.jar'" + ) null } } @@ -197,41 +197,47 @@ class K2JSDce : CLITool() { val moduleName = getModuleNameFromPath(path) val pathToSourceMapCandidate = "$path.map" val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null - return InputFile(InputResource.file(path), pathToSourceMap?.let { InputResource.file(it) }, - File(baseDir, "$moduleName.js").absolutePath, moduleName) + return InputFile( + InputResource.file(path), pathToSourceMap?.let { InputResource.file(it) }, + File(baseDir, "$moduleName.js").absolutePath, moduleName + ) } private fun collectInputFilesFromZip(baseDir: File, path: String): List { return ZipFile(path).use { zipFile -> zipFile.entries().asSequence() - .filter { !it.isDirectory } - .filter { it.name.endsWith(".js") } - .filter { zipFile.getEntry(it.name.metaJs()) != null } - .distinctBy { it.name } - .map { entry -> - val moduleName = getModuleNameFromPath(entry.name) - val pathToSourceMapCandidate = "${entry.name}.map" - val pathToSourceMap = if (zipFile.getEntry(pathToSourceMapCandidate) != null) pathToSourceMapCandidate else null - InputFile(InputResource.zipFile(path, entry.name), pathToSourceMap?.let { InputResource.zipFile(path, it) }, - File(baseDir, "$moduleName.js").absolutePath, moduleName) - } - .toList() + .filter { !it.isDirectory } + .filter { it.name.endsWith(".js") } + .filter { zipFile.getEntry(it.name.metaJs()) != null } + .distinctBy { it.name } + .map { entry -> + val moduleName = getModuleNameFromPath(entry.name) + val pathToSourceMapCandidate = "${entry.name}.map" + val pathToSourceMap = if (zipFile.getEntry(pathToSourceMapCandidate) != null) pathToSourceMapCandidate else null + InputFile( + InputResource.zipFile(path, entry.name), pathToSourceMap?.let { InputResource.zipFile(path, it) }, + File(baseDir, "$moduleName.js").absolutePath, moduleName + ) + } + .toList() } } private fun collectInputFilesFromDirectory(baseDir: File, path: String): List { return File(path).walkTopDown().asSequence() - .filter { !it.isDirectory } - .filter { it.name.endsWith(".js") } - .filter { File(it.path.metaJs()).exists() } - .map { entry -> - val moduleName = getModuleNameFromPath(entry.name) - val pathToSourceMapCandidate = "${entry.path}.map" - val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null - InputFile(InputResource.file(entry.path), pathToSourceMap?.let { InputResource.file(it) }, - File(baseDir, "$moduleName.js").absolutePath, moduleName) - } - .toList() + .filter { !it.isDirectory } + .filter { it.name.endsWith(".js") } + .filter { File(it.path.metaJs()).exists() } + .map { entry -> + val moduleName = getModuleNameFromPath(entry.name) + val pathToSourceMapCandidate = "${entry.path}.map" + val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null + InputFile( + InputResource.file(entry.path), pathToSourceMap?.let { InputResource.file(it) }, + File(baseDir, "$moduleName.js").absolutePath, moduleName + ) + } + .toList() } private fun String.metaJs() = removeSuffix(".js") + ".meta.js"