JS backend: removed adding '$' to label suffix
This commit is contained in:
@@ -49,14 +49,30 @@ public class JsFunctionScope(parent: JsScope, description: String) : JsScope(par
|
||||
topLabelScope?.findName(label)
|
||||
|
||||
private inner class LabelScope(parent: LabelScope?, val ident: String) : JsScope(parent, "Label scope for $ident", null) {
|
||||
val labelName = JsName(this@JsFunctionScope, parent?.getFreshIdent(ident) ?: ident)
|
||||
val labelName: JsName
|
||||
|
||||
{
|
||||
val freshIdent = when {
|
||||
ident in RESERVED_WORDS -> getFreshIdent(ident)
|
||||
parent != null -> parent.getFreshIdent(ident)
|
||||
else -> ident
|
||||
}
|
||||
|
||||
labelName = JsName(this@JsFunctionScope, freshIdent)
|
||||
}
|
||||
|
||||
override fun findOwnName(name: String): JsName? =
|
||||
if (name == ident) labelName else null
|
||||
|
||||
/**
|
||||
* Safe call is necessary, because hasOwnName can be called
|
||||
* in constructor before labelName is initialized (see KT-4394)
|
||||
*/
|
||||
[suppress("UNNECESSARY_SAFE_CALL")]
|
||||
override fun hasOwnName(name: String): Boolean =
|
||||
name == ident
|
||||
|| name == labelName.getIdent()
|
||||
name in RESERVED_WORDS
|
||||
|| name == ident
|
||||
|| name == labelName?.getIdent()
|
||||
|| getParent()?.hasOwnName(name) ?: false
|
||||
}
|
||||
|
||||
|
||||
@@ -364,7 +364,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
private static String getReferencedName(JetSimpleNameExpression expression) {
|
||||
return expression.getReferencedName()
|
||||
.replaceAll("^@", "")
|
||||
.replaceAll("(?:^`(.*)`$)", "$1") + "$";
|
||||
.replaceAll("(?:^`(.*)`$)", "$1");
|
||||
}
|
||||
|
||||
private static JsNameRef getTargetLabel(JetExpressionWithLabel expression, TranslationContext context) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=test1 name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test2 name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test1 name=loop count=1
|
||||
// CHECK_LABELS_COUNT: function=test2 name=loop count=1
|
||||
|
||||
fun test1() {
|
||||
var `loop$` = 0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_0 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop_0 count=1
|
||||
|
||||
fun test() {
|
||||
var i = 0
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_0 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_1 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop_0 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop_1 count=1
|
||||
|
||||
class State() {
|
||||
public var value: Int = 0
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_0 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_1 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop_0 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop_1 count=1
|
||||
|
||||
class State() {
|
||||
public var value: Int = 0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$ count=2
|
||||
// CHECK_LABELS_COUNT: function=test name=loop count=2
|
||||
|
||||
fun test() {
|
||||
var i = 0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: testInline
|
||||
// CHECK_LABELS_COUNT: function=testNoinline name=loop$ count=2
|
||||
// CHECK_LABELS_COUNT: function=testNoinline name=loop count=2
|
||||
|
||||
inline fun testInline(): Int {
|
||||
var c = 0
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: testLabelInline
|
||||
// CHECK_LABELS_COUNT: function=testLabel name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=testLabel name=loop$_0 count=2
|
||||
// CHECK_LABELS_COUNT: function=testLabel name=loop count=1
|
||||
// CHECK_LABELS_COUNT: function=testLabel name=loop_0 count=2
|
||||
|
||||
inline fun testLabelInline(): Int {
|
||||
var a = 0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=testBreak name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=testContinue name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=testBreak name=loop count=1
|
||||
// CHECK_LABELS_COUNT: function=testContinue name=loop count=1
|
||||
|
||||
fun testBreak() {
|
||||
var i = 0
|
||||
|
||||
@@ -2,8 +2,8 @@ package foo
|
||||
|
||||
// CHECK_NOT_CALLED: testBreak
|
||||
// CHECK_NOT_CALLED: testContinue
|
||||
// CHECK_LABELS_COUNT: function=testBreakNoinline name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=testContinueNoinline name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=testBreakNoinline name=loop count=1
|
||||
// CHECK_LABELS_COUNT: function=testContinueNoinline name=loop count=1
|
||||
|
||||
inline fun testBreak(): Int {
|
||||
var i = 0
|
||||
|
||||
Reference in New Issue
Block a user