Add undefined handling in constant insertion

This commit is contained in:
Iaroslav Postovalov 2020-12-22 13:11:12 +07:00
parent d657f40e3f
commit 46ac73d2c1
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7

View File

@ -40,9 +40,10 @@ internal class ESTreeBuilder<T>(val bodyCallback: ESTreeBuilder<T>.() -> BaseExp
private val keys = mutableListOf<String>() private val keys = mutableListOf<String>()
fun constant(value: Any?) = when { fun constant(value: Any?) = when {
value == null || jsTypeOf(value) == "number" || jsTypeOf(value) == "string" || jsTypeOf(value) == "boolean" -> { value == null || jsTypeOf(value) == "number" || jsTypeOf(value) == "string" || jsTypeOf(value) == "boolean" ->
SimpleLiteral(value) SimpleLiteral(value)
}
jsType(value) == "undefined" -> Identifier("undefined")
else -> { else -> {
val idx = if (value in constants) constants.indexOf(value) else constants.also { it += value }.lastIndex val idx = if (value in constants) constants.indexOf(value) else constants.also { it += value }.lastIndex