JS: optimize JSON parser

This commit is contained in:
Anton Bannykh
2019-04-12 13:00:19 +03:00
parent 675f930566
commit 56915d1c07
8 changed files with 52 additions and 35 deletions
@@ -122,7 +122,7 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
private fun mapSourcePaths(inputFile: File, targetFile: File): Boolean {
val json = try {
InputStreamReader(FileInputStream(inputFile), "UTF-8").use { parseJson(it) }
parseJson(inputFile)
} catch (e: JsonSyntaxException) {
return false
}
@@ -52,7 +52,7 @@ private fun mergeStdlibParts(outputFile: File, wrapperFile: File, baseDir: File,
val sourceMapFile = File(file.parent, file.name + ".map")
if (sourceMapFile.exists()) {
val sourceMapParse = sourceMapFile.reader().use { SourceMapParser.parse(it) }
val sourceMapParse = SourceMapParser.parse(sourceMapFile)
when (sourceMapParse) {
is SourceMapError -> {
System.err.println("Error parsing source map file $sourceMapFile: ${sourceMapParse.message}")
@@ -82,7 +82,7 @@ private fun mergeStdlibParts(outputFile: File, wrapperFile: File, baseDir: File,
outputFile.writeText(programText + "\n//# sourceMappingURL=${sourceMapFile.name}\n")
val sourceMapJson = StringReader(sourceMapContent).use { parseJson(it) }
val sourceMapJson = parseJson(sourceMapContent)
val sources = (sourceMapJson as JsonObject).properties["sources"] as JsonArray
sourceMapJson.properties["sourcesContent"] = JsonArray(*sources.elements.map { sourcePath ->