[Wasm] Support JsModule and JsQualifier

This commit is contained in:
Svyatoslav Kuzmich
2023-01-10 21:49:51 +01:00
committed by Space Team
parent 75d3ae4466
commit d14d4c8510
18 changed files with 669 additions and 31 deletions
@@ -37,4 +37,65 @@ public actual annotation class JsExport {
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER
)
public actual annotation class JsName(actual val name: String)
public actual annotation class JsName(actual val name: String)
/**
* Denotes an `external` declaration that must be imported from JavaScript module.
*
* The annotation can be used on top-level external declarations (classes, properties, functions) and files.
* In case of file (which can't be `external`) the following rule applies: all the declarations in
* the file must be `external`. By applying `@JsModule(...)` on a file you tell the compiler to import a JavaScript object
* that contain all the declarations from the file.
*
* Example:
*
* ``` kotlin
* @JsModule("jquery")
* external abstract class JQuery() {
* // some declarations here
* }
*
* @JsModule("jquery")
* external fun JQuery(element: Element): JQuery
* ```
*
* @property import name of a module to import declaration from.
* It is not interpreted by the Kotlin compiler, it's passed as is directly to the target module system.
*/
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION, AnnotationTarget.FILE)
public annotation class JsModule(val import: String)
/**
* Adds prefix to `external` declarations in a source file.
*
* JavaScript does not have concept of packages (namespaces). They are usually emulated by nested objects.
* The compiler turns references to `external` declarations either to plain unprefixed names
* or to plain imports.
* However, if a JavaScript library provides its declarations in packages, you won't be satisfied with this.
* You can tell the compiler to generate additional prefix before references to `external` declarations using the `@JsQualifier(...)`
* annotation.
*
* Note that a file marked with the `@JsQualifier(...)` annotation can't contain non-`external` declarations.
*
* Example:
*
* ```
* @file:JsQualifier("my.jsPackageName")
* package some.kotlinPackage
*
* external fun foo(x: Int)
*
* external fun bar(): String
* ```
*
* @property value the qualifier to add to the declarations in the generated code.
* It must be a sequence of valid JavaScript identifiers separated by the `.` character.
* Examples of valid qualifiers are: `foo`, `bar.Baz`, `_.$0.f`.
*
* @see JsModule
*/
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.FILE)
public annotation class JsQualifier(val value: String)