/
JSImport.scala
92 lines (84 loc) · 2.78 KB
/
JSImport.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Scala.js (https://www.scala-js.org/)
*
* Copyright EPFL.
*
* Licensed under Apache License 2.0
* (https://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/
package scala.scalajs.js.annotation
/** Marks the annotated class or object as imported from another JS module.
*
* Intuitively, this corresponds to ECMAScript import directives. See the
* documentation of the various constructors.
*
* `@JSImport` is not compatible with the `jsDependencies` mechanism offered
* by the Scala.js sbt plugin. You are responsible for resolving and/or
* bundling the JavaScript modules that you are importing using other
* mechanisms.
*/
class JSImport private () extends scala.annotation.StaticAnnotation {
/** Named import of a member of the module.
*
* Intuitively, this corresponds to the following ECMAScript import
* directive:
* {{{
* import { <name> as AnnotatedClassOrObject } from <module>
* }}}
*
* To import the default export of a module, use `JSImport.Default` as
* `name`.
*/
def this(module: String, name: String) = this()
/** Namespace import (import the module itself).
*
* The second parameter should be the singleton `JSImport.Namespace`.
*
* Intuitively, this corresponds to
* {{{
* import * as AnnotatedObject from <module>
* }}}
*/
def this(module: String, name: JSImport.Namespace.type) = this()
/** Named import of a member of the module, with a fallback on a global
* variable.
*
* When linking with module support, this is equivalent to
* `@JSImport(module, name)`.
*
* When linking without module support, this is equivalent to
* `@JSGlobal(globalFallback)`.
*/
def this(module: String, name: String, globalFallback: String) = this()
/** Namespace import (import the module itself), with a fallback on a global
* variable.
*
* When linking with module support, this is equivalent to
* `@JSImport(module, name)`.
*
* When linking without module support, this is equivalent to
* `@JSGlobal(globalFallback)`.
*/
def this(module: String, name: JSImport.Namespace.type,
globalFallback: String) = this()
}
object JSImport {
/** Use as the `name` of a `JSImport` to use the default import.
*
* The actual value of this constant, the string `"default"`, is not
* arbitrary. It is the name under which a default export is registered in
* the ECMAScript 2015 specification.
*/
final val Default = "default"
/** Use as the `name` of a `JSImport` to use a namespace import.
*
* Intuitively, it corresponds to `*` in an ECMAScript import:
* {{{
* import * as AnnotatedObject from <module>
* }}}
*/
object Namespace
}