[Wasm] Escaped quotes and added export in DCE in IR dumps
This commit is contained in:
committed by
Space Team
parent
d5c6dd5f5c
commit
3b52b452a3
+4
-4
@@ -328,14 +328,14 @@ private fun transformToJsonString(reachabilityInfos: List<ReachabilityInfo>): St
|
||||
return "[\n" + transformToStringBy(reachabilityInfos, ",\n") { sourceFqn, targetFqn, description, isTargetContagious ->
|
||||
"""
|
||||
| {
|
||||
| "source" : "$sourceFqn",
|
||||
| "target" : "$targetFqn",
|
||||
| "description" : "$description",
|
||||
| "source" : "${sourceFqn.removeQuotes()}",
|
||||
| "target" : "${targetFqn.removeQuotes()}",
|
||||
| "description" : "${description.removeQuotes()}",
|
||||
| "isTargetContagious" : $isTargetContagious
|
||||
| }""".trimMargin()
|
||||
} + "\n]"
|
||||
}
|
||||
|
||||
private fun transformToJsConstDeclaration(reachabilityInfos: List<ReachabilityInfo>): String {
|
||||
return "const kotlinReachabilityInfos = " + transformToJsonString(reachabilityInfos) + ";"
|
||||
return "export const kotlinReachabilityInfos = " + transformToJsonString(reachabilityInfos) + ";"
|
||||
}
|
||||
|
||||
@@ -45,7 +45,9 @@ fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List<IrModuleFragmen
|
||||
is IrFunction,
|
||||
is IrProperty,
|
||||
is IrField,
|
||||
is IrAnonymousInitializer -> {
|
||||
is IrAnonymousInitializer,
|
||||
is IrClass,
|
||||
-> {
|
||||
declarations.add(declaration)
|
||||
}
|
||||
}
|
||||
@@ -58,15 +60,33 @@ fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List<IrModuleFragmen
|
||||
val out = File(path)
|
||||
val (prefix, postfix, separator, indent) = when (out.extension) {
|
||||
"json" -> listOf("{\n", "\n}", ",\n", " ")
|
||||
"js" -> listOf("const kotlinDeclarationsSize = {\n", "\n};\n", ",\n", " ")
|
||||
"js" -> listOf("export const kotlinDeclarationsSize = {\n", "\n};\n", ",\n", " ")
|
||||
else -> listOf("", "", "\n", "")
|
||||
}
|
||||
|
||||
val value = declarations.joinToString(separator, prefix, postfix) {
|
||||
val fqn = it.fqNameForDceDump()
|
||||
val size = it.dumpKotlinLike().length
|
||||
"$indent\"$fqn\" : $size"
|
||||
}
|
||||
val value = declarations
|
||||
.groupBy({ it.fqNameForDceDump() }, { it })
|
||||
.map { (k, v) -> k to v.maxBy { it.dumpKotlinLike().length } }
|
||||
.joinToString(separator, prefix, postfix) { (fqn, element) ->
|
||||
val size = element.dumpKotlinLike().length
|
||||
val type = when (element) {
|
||||
is IrFunction -> "function"
|
||||
is IrProperty -> "property"
|
||||
is IrField -> "field"
|
||||
is IrAnonymousInitializer -> "anonymousInitializer"
|
||||
is IrClass -> "class"
|
||||
else -> "unknown"
|
||||
}
|
||||
"""$indent"${fqn.removeQuotes()}": {
|
||||
|$indent$indent"size": $size,
|
||||
|$indent$indent"type": "$type"
|
||||
|$indent}
|
||||
""".trimMargin()
|
||||
}
|
||||
|
||||
out.writeText(value)
|
||||
}
|
||||
|
||||
internal fun String.removeQuotes() = replace('"'.toString(), "")
|
||||
.replace("'", "")
|
||||
.replace("\\", "\\\\")
|
||||
|
||||
Reference in New Issue
Block a user