Skip to content

Commit baa6b44

Browse files
committed
Deprecate CharSequence.size in JS
#KT-18267 Fixed
1 parent f10ea03 commit baa6b44

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

js/js.libraries/src/core/string.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public inline fun String.match(regex: String): Array<String>? = asDynamic().matc
3535
//native public fun String.trim(): String
3636
//TODO: String.replace to implement effective trimLeading and trimTrailing
3737

38+
@Deprecated("Use length property instead.", ReplaceWith("length"), level = DeprecationLevel.WARNING) // TODO: ERROR in 1.2
3839
@kotlin.internal.InlineOnly
39-
public inline val CharSequence.size: Int get() = asDynamic().length
40+
public inline val CharSequence.size: Int get() = length
4041

4142
@kotlin.internal.InlineOnly
4243
internal inline fun String.nativeReplace(pattern: RegExp, replacement: String): String = asDynamic().replace(pattern, replacement)

js/js.translator/testData/box/expression/misc/KT-5058.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fun test():Any {
77
if (true) {
88
when {
99
false -> "1"
10-
((a as? String)?.size ?: 0 > 0) -> a
10+
((a as? String)?.length ?: 0 > 0) -> a
1111
else -> "2"
1212
}
1313
}

js/js.translator/testData/box/expression/stringClass/extensionMethods.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ fun assertEquals(expected: Any, actual: Any, s: CharSequence, whatTested: String
2222
}
2323

2424
fun testString(s: String, expectedSize: Int, indexOfB: Int) {
25-
assertEquals(expectedSize, s.size, s, "size")
2625
assertEquals(expectedSize, s.length, s, "length")
2726
assertEquals(expectedSize == 0, s.isEmpty(), s, "isEmpty()")
2827
assertEquals(expectedSize != 0, s.startsWith(startsWithParam), s, "startsWith(\"$startsWithParam\")")
@@ -35,7 +34,6 @@ fun testString(s: String, expectedSize: Int, indexOfB: Int) {
3534
}
3635

3736
fun testCharSequence(s: CharSequence, expectedSize: Int) {
38-
assertEquals(expectedSize, s.size, s, "size")
3937
assertEquals(expectedSize, s.length, s, "length")
4038
assertEquals(expectedSize == 0, s.isEmpty(), s, "isEmpty()")
4139
}

js/js.translator/testData/box/inheritance/overrideAnyMethods.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ inline fun String.charCodeAt(i: Int): Int = asDynamic().charCodeAt(i)
77
fun String.myHashCode(): Int {
88
var hash = 0
99

10-
for (i in 0..size - 1) {
10+
for (i in 0..length - 1) {
1111
hash = 31 * hash + charCodeAt(i)
1212
}
1313

0 commit comments

Comments
 (0)