package nscplugin
- Alphabetic
- Public
- All
Type Members
-
trait
CompatComponent extends AnyRef
Hacks to have our source code compatible with the compiler internals of all the versions of Scala that we support.
Hacks to have our source code compatible with the compiler internals of all the versions of Scala that we support.
In general, it tries to provide the newer APIs on top of older APIs.
-
abstract
class
ExplicitInnerJS[G <: Global with Singleton] extends PluginComponent with InfoTransform with TypingTransformers with CompatComponent
Makes the references to inner JS class values explicit.
Makes the references to inner JS class values explicit.
Roughly, for every inner JS class of the form:
class Outer { class Inner extends ParentJSClass }
this phase creates a field
Inner$jsclass
inOuter
to hold the JS class value forInner
. The rhs of that field is a call to a magic method, used to retain information that the back-end will need.class Outer { <synthetic> val Inner$jsclass: AnyRef = createJSClass(classOf[Inner], js.constructorOf[ParentJSClass]) class Inner extends ParentJSClass }
These fields will be read by code generated in
ExplicitLocalJS
.Note that this field must also be added to outer classes and traits coming from separate compilation, therefore this phase is an
InfoTransform
. Since thetransformInfo
also applies to classes defined in the current compilation unit, the tree traversal must not create the field symbols a second time when synthesizing theValDef
. Instead, it must reuse the same symbols thattransformInfo
will create.It seems the easiest way to do that is to run the entire
transform
"in the future", withexitingPhase(ExplicitInnerJS)
. This design is similar to howexplicitouter
works. -
abstract
class
ExplicitLocalJS[G <: Global with Singleton] extends PluginComponent with Transform with TypingTransformers with CompatComponent
Makes the references to local JS classes explicit and desugars calls to
js.constructorOf
.Makes the references to local JS classes explicit and desugars calls to
js.constructorOf
.It also makes explicit all references to inner JS classes, using the pointers created by
ExplicitInnerJS
, and otherwise makes sure the back-end will receive all the information it needs to translate inner- and local JS classes and objects.Note that in this comment, by "class" we mean *only*
class
es.trait
s andobject
s are not implied.Similarly to how
ExplicitInnerJS
creates explicit fields in the enclosing templates of inner JS classes to hold the JS class values, this phase creates local vals for local JS classes in the enclosing statement list.For every local JS class of the form:
def outer() = { class Local extends ParentJSClass }
this phase creates a local
val Local$jslass
in the body ofouter()
to hold the JS class value forLocal
. The rhs of that val is a call to a magic method, used to retain information that the back-end will need:- A reified reference to
class Local
, in the form of aclassOf
- An explicit reference to the super JS class value, i.e., the desugaring
of
js.constructorOf[ParentJSClass]
- An array of fake
new
expressions for all overloaded constructors.
The latter will be augmented by
lambdalift
with the appropriate actual parameters for the captures ofLocal
, which will be needed by the back-end. In code, this looks like:def outer() = { class Local extends ParentJSClass val Local$jsclass: AnyRef = createLocalJSClass( classOf[Local], js.constructorOf[ParentJSClass], Array[AnyRef](new Local(), ...)) }
Since we need to insert fake
new Inner()
s, this scheme does not work for abstract local classes. We therefore reject them as implementation restriction.If the body of
Local
references itself, then theval Local$jsclass
is instead declared as avar
to work around the cyclic dependency:def outer() = { var Local$jsclass: AnyRef = null class Local extends ParentJSClass { ... } Local$jsclass = createLocalJSClass(...) }
In addition to the above,
ExplicitLocalJS
transforms all *call sites* of local JS classes *and* inner JS classes, so that they refer to the synthesized local vals and fields.The primary transformation is the desugaring of
js.constructorOf[C]
, which depends on the nature ofC
:- If
C
is a statically accessible class, desugar toruntime.constructorOf(classOf[C])
so that the reified symbol survives erasure and reaches the back-end. - If
C
is an inner JS class, it must be of the formpath.D
for some pair (path
,D
), and we desugar it topath.D$jsclass
, using the field created byExplicitInnerJS
(it is an error ifC
is of the formEnclosing#D
). - If
C
is a local JS class, desugar toC$jsclass
, using the local val created by this phase.
The other transformations build on top of the desugaring of
js.constructorOf[C]
, and apply only to inner JS classes and local JS classes (not for statically accessible classes):x.isInstanceOf[C]
desugars intojs.special.instanceof(x, js.constructorOf[C])
.new C(...args)
desugars intowithContextualJSClassValue(js.constructorOf[C], new C(...args))
, so that the back-end receives a reified reference to the JS class value.- In the same spirit, for
D extends C
,D.super.m(...args)
desugars intowithContextualJSClassValue(js.constructorOf[C], D.super.m(...args))
.
Finally, for inner- and local JS *objects*, their (only) instantiation point of the form
new O.type()
is rewritten aswithContextualJSClassValue(js.constructorOf[ParentClassOfO], new O.type())
, so that the back-end receives a reified reference to the parent class ofO
. A similar treatment is applied on anonymous JS classes, which basically define something very similar to anobject
, although without its own JS class. - A reified reference to
-
abstract
class
GenJSCode[G <: Global with Singleton] extends PluginComponent with TypeConversions[G] with JSEncoding[G] with GenJSExports[G] with GenJSFiles[G] with CompatComponent
Generate JavaScript code and output it to disk
-
trait
GenJSExports[G <: Global with Singleton] extends SubComponent
Generation of exports for JavaScript
-
trait
GenJSFiles[G <: Global with Singleton] extends SubComponent
Send JS ASTs to files
-
trait
JSDefinitions extends AnyRef
Core definitions for Scala.js
-
trait
JSEncoding[G <: Global with Singleton] extends SubComponent
Encoding of symbol names for the IR.
-
trait
JSGlobalAddons extends JSDefinitions with CompatComponent
Additions to Global meaningful for the JavaScript backend
-
abstract
class
JSPrimitives extends AnyRef
Extension of ScalaPrimitives for primitives only relevant to the JS backend
-
abstract
class
PreTyperComponent extends PluginComponent with Transform with CompatComponent
This
jspretyper
phase prepares a fix for issue SI-9487 in the case of anonymous classes that extend js.Any.This
jspretyper
phase prepares a fix for issue SI-9487 in the case of anonymous classes that extend js.Any.During
typer
, due to a bug (SI-9487), Scalac transfroms some public method definitions of a quite specific syntactic form of anonymous classes into private methods. This affects both methods and field accessors. This phase identifies any anonymous class and adds a@WasPublicBeforeTyper
annotation on its public methods and fields. After thetyper
injsinterop
the anonymous classes are fixed if they extend js.Any using the annotations as reference.As an example:
class $anon extends ... { val foo = ??? var bar = ??? def baz = ??? private val foo2 = ??? private var bar2 = ??? private def baz2 = ??? }
Would become:
class $anon extends ... { @WasPublicBeforeTyper val foo = ??? @WasPublicBeforeTyper var bar = ??? @WasPublicBeforeTyper def baz = ??? private val foo2 = ??? private var bar2 = ??? private def baz2 = ??? }
And after
typer
(if has SI-9487) will be:class $anon extends ... { @WasPublicBeforeTyper private[this] var foo = ??? private <stable> <accessor> def foo = ??? // Needs fix @WasPublicBeforeTyper private[this] var bar = ??? private <accessor> def bar = ??? // Needs fix private <accessor> def bar_=(...) = ??? // Needs fix @WasPublicBeforeTyper private def baz = ??? // Needs fix ... }
-
trait
PrepJSExports[G <: Global with Singleton] extends AnyRef
Prepare export generation
Prepare export generation
Helpers for transformation of @JSExport annotations
-
abstract
class
PrepJSInterop[G <: Global with Singleton] extends PluginComponent with PrepJSExports[G] with Transform with CompatComponent
Prepares classes extending js.Any for JavaScript interop
Prepares classes extending js.Any for JavaScript interop
This phase does: - Sanity checks for js.Any hierarchy - Annotate subclasses of js.Any to be treated specially - Rewrite calls to scala.Enumeration.Value (include name string) - Create JSExport methods: Dummy methods that are propagated through the whole compiler chain to mark exports. This allows exports to have the same semantics than methods.
-
trait
ScalaJSOptions extends AnyRef
This trait allows to query all options to the ScalaJS plugin
This trait allows to query all options to the ScalaJS plugin
Also see the help text in ScalaJSPlugin for information about particular options.
-
class
ScalaJSPlugin extends Plugin
Main entry point for the Scala.js compiler plugin
-
trait
TypeConversions[G <: Global with Singleton] extends SubComponent
Conversions from scalac
Type
s to the IRType
s andTypeRef
s.
Value Members
- object CompatComponent
- object PrepJSInterop
- object ScalaJSOptions