JS: prohibit stable (public) names with non-identifier chars. Rewrite unstable (private) names with non-identifier chars. See KT-4160

This commit is contained in:
Alexey Andreev
2016-12-28 13:49:03 +03:00
parent 7f0166623d
commit 900adcf29b
14 changed files with 166 additions and 10 deletions
@@ -0,0 +1,34 @@
private fun `+`(a: Int, b: Int) = a + b
@JsName("minus")
fun `-`(a: Int, b: Int) = a - b
fun test1(): Int {
val ` x ` = 23
val `*` = 3
return `-`(` x `, `*`)
}
fun test2(`p 1`: Int, `.p 2`: Int) = `+`(`p 1`, `.p 2`)
fun test3(): String {
val `#` = "K"
class ` `(private val `::`: String) {
internal fun `@`() = `::` + `#`
}
return ` `("O").`@`()
}
fun test4(): String {
val `()` = "OK"
fun `[]`() = `()`
return `[]`()
}
fun box(): String {
if (test1() != 20) return "fail1"
if (test2(10, 13) != 23) return "fail2"
if (test3() != "OK") return "fail3"
if (test4() != "OK") return "fail4"
return "OK"
}
+2 -4
View File
@@ -8,8 +8,6 @@ public class JsTestsAsserter() : Asserter {
public override fun fail(message: String?): Nothing = failWithMessage(message)
}
@JsName("JsTests.assert")
public external fun assert(value: Boolean, message: String?): Unit = noImpl
public inline fun assert(value: Boolean, message: String?): Unit = js("JsTests").assert(value, message)
@JsName("JsTests.fail")
private external fun failWithMessage(message: String?): Nothing = noImpl
private inline fun failWithMessage(message: String?): Nothing = js("JsTests").fail(message)