[K/JS] Throw error when a module contains file with the same name and package (ignoring case)

This commit is contained in:
Artem Kobzar
2023-07-07 13:50:04 +00:00
committed by Space Team
parent 0e6930e7ef
commit 7c7aa98875
9 changed files with 94 additions and 4 deletions
@@ -15,9 +15,24 @@ import org.jetbrains.kotlin.ir.declarations.path
private const val EXPORTER_FILE_POSTFIX = ".export"
class ModuleFragmentToExternalName(private val jsOutputNamesMapping: Map<IrModuleFragment, String>) {
private val externalNameToItsFile = hashMapOf<String, IrFile>()
fun getExternalNameFor(file: IrFile, granularity: JsGenerationGranularity): String {
assert(granularity == JsGenerationGranularity.PER_FILE) { "This method should be used only for PER_FILE granularity" }
return file.module.getJsOutputName().getExternalModuleNameForPerFile(file)
return file.module.getJsOutputName().getExternalModuleNameForPerFile(file).also {
val alreadyReservedBy = externalNameToItsFile.putIfAbsent(it.lowercase(), file)
if (alreadyReservedBy != null && alreadyReservedBy != file) {
error(
"""
|There are two files in module '${file.module.name}' that have the similar package and file names.
| - Package "${file.packageFqName.asString()}" and path "${file.path}"
| - Package "${alreadyReservedBy.packageFqName.asString()}" and path "${alreadyReservedBy.path}"
|Note, that if the difference is only in letter cases, it also could lead to a clash of the compiled artifacts
""".trimMargin()
)
}
}
}
fun getExternalNameForExporterFile(file: IrFile, granularity: JsGenerationGranularity): String {