-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JS Plain Objects] Remove dispatchReceiver from JsPlainObject invoke …
…operator by marking it with @JsNoDispatchReceiver ^KT-68904 Fixed ^KT-70078 Fixed ^KT-72598 Fixed
- Loading branch information
Showing
12 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../org/jetbrains/kotlin/ir/backend/js/lower/NoDispatchReceiverAnnotationApplyingLowering.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.ir.backend.js.lower | ||
|
||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass | ||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration | ||
import org.jetbrains.kotlin.ir.declarations.IrParameterKind | ||
import org.jetbrains.kotlin.ir.expressions.IrBody | ||
import org.jetbrains.kotlin.ir.expressions.IrCall | ||
import org.jetbrains.kotlin.ir.expressions.IrExpression | ||
import org.jetbrains.kotlin.ir.util.hasAnnotation | ||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid | ||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid | ||
import org.jetbrains.kotlin.name.JsStandardClassIds | ||
|
||
object NoDispatchReceiverAnnotationApplyingLowering : BodyLoweringPass { | ||
override fun lower(irBody: IrBody, container: IrDeclaration) { | ||
irBody.transformChildrenVoid(object : IrElementTransformerVoid() { | ||
override fun visitCall(expression: IrCall): IrExpression { | ||
val callee = expression.symbol.owner | ||
if (callee.hasAnnotation(JsStandardClassIds.Annotations.JsNoDispatchReceiver)) { | ||
expression.removeDispatchReceiver() | ||
callee.parameters = callee.parameters.filter { it.kind != IrParameterKind.DispatchReceiver } | ||
} | ||
return super.visitCall(expression) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
plugins/js-plain-objects/compiler-plugin/testData/box/jsQualifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// MODULE: lib | ||
// FILE: lib.kt | ||
@file:JsQualifier("foo.bar.baz") | ||
package foo | ||
|
||
import kotlinx.js.JsPlainObject | ||
|
||
@JsPlainObject | ||
external interface User { | ||
var name: String | ||
val age: Int | ||
} | ||
|
||
// MODULE: main(lib) | ||
// FILE: main.kt | ||
import foo.User | ||
|
||
fun box(): String { | ||
val user = User(name = "Name", age = 10) | ||
|
||
if (user.name != "Name") return "Fail: problem with `name` property" | ||
if (user.age != 10) return "Fail: problem with `age` property" | ||
|
||
val json = js("JSON.stringify(user)") | ||
if (json != "{\"age\":10,\"name\":\"Name\"}") return "Fail: got the next json: $json" | ||
|
||
return "OK" | ||
} |
23 changes: 23 additions & 0 deletions
23
plugins/js-plain-objects/compiler-plugin/testData/box/nested.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package foo | ||
|
||
import kotlinx.js.JsPlainObject | ||
|
||
external class Parent { | ||
@JsPlainObject | ||
interface User { | ||
var name: String | ||
val age: Int | ||
} | ||
} | ||
|
||
fun box(): String { | ||
val user = Parent.User(name = "Name", age = 10) | ||
|
||
if (user.name != "Name") return "Fail: problem with `name` property" | ||
if (user.age != 10) return "Fail: problem with `age` property" | ||
|
||
val json = js("JSON.stringify(user)") | ||
if (json != "{\"age\":10,\"name\":\"Name\"}") return "Fail: got the next json: $json" | ||
|
||
return "OK" | ||
} |
1 change: 0 additions & 1 deletion
1
plugins/js-plain-objects/compiler-plugin/testData/box/suspendFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// IGNORE_BACKEND: JS_IR | ||
// ISSUE: KT-70078 | ||
|
||
import kotlinx.js.JsPlainObject | ||
|
12 changes: 12 additions & 0 deletions
12
...n/tests-gen/org/jetbrains/kotlinx/jspo/runners/FirJsPlainObjectsIrJsBoxTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.