JS: add DCE devmode. Fix mapping paths in source maps
See KT-20210, KT-21307
This commit is contained in:
@@ -120,8 +120,12 @@ class DeadCodeElimination(private val logConsumer: (DCELogLevel, String) -> Unit
|
||||
val sourceMapFile = File(file.outputPath + ".map")
|
||||
val textOutput = TextOutputImpl()
|
||||
val sourceMapBuilder = SourceMap3Builder(File(file.outputPath), textOutput, "")
|
||||
val sourcePathResolver = SourceFilePathResolver(mutableListOf(), File(file.outputPath).parentFile)
|
||||
val consumer = SourceMapBuilderConsumer(sourceMapBuilder, sourcePathResolver, true, true)
|
||||
|
||||
val inputFile = File(file.resource.name)
|
||||
val sourceBaseDir = if (inputFile.exists()) inputFile.parentFile else File(".")
|
||||
|
||||
val sourcePathResolver = SourceFilePathResolver(emptyList(), File(file.outputPath).parentFile)
|
||||
val consumer = SourceMapBuilderConsumer(sourceBaseDir, sourceMapBuilder, sourcePathResolver, true, true)
|
||||
block.accept(JsToStringGenerationVisitor(textOutput, consumer))
|
||||
val sourceMapContent = sourceMapBuilder.build()
|
||||
sourceMapBuilder.addLink()
|
||||
|
||||
@@ -21,13 +21,19 @@ import java.io.FileInputStream
|
||||
import java.io.InputStream
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
class InputResource(val name: String, val reader: () -> InputStream) {
|
||||
class InputResource(val name: String, val lastModified: () -> Long, val reader: () -> InputStream) {
|
||||
companion object {
|
||||
fun file(path: String): InputResource = InputResource(path) { FileInputStream(File(path)) }
|
||||
fun file(path: String): InputResource = InputResource(path, { File(path).lastModified() }) { FileInputStream(File(path)) }
|
||||
|
||||
fun zipFile(path: String, entryPath: String): InputResource = InputResource("$path!$entryPath") {
|
||||
val zipFile = ZipFile(path)
|
||||
zipFile.getInputStream(zipFile.getEntry(entryPath))
|
||||
fun zipFile(path: String, entryPath: String): InputResource =
|
||||
InputResource("$path!$entryPath", { getZipModificationTime(path, entryPath) }) {
|
||||
val zipFile = ZipFile(path)
|
||||
zipFile.getInputStream(zipFile.getEntry(entryPath))
|
||||
}
|
||||
|
||||
private fun getZipModificationTime(path: String, entryPath: String): Long {
|
||||
val result = ZipFile(path).getEntry(entryPath).time
|
||||
return if (result != -1L) result else File(path).lastModified()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user