org.scalajs.core

compiler

package compiler

Visibility
  1. Public
  2. All

Type Members

  1. trait Compat210Component extends AnyRef

    Hacks to have our source code compatible with 2.10 and 2.11.

    Hacks to have our source code compatible with 2.10 and 2.11. It exposes 2.11 API in a 2.10 compiler.

  2. abstract class ExplicitInnerJS extends PluginComponent with InfoTransform with TypingTransformers with PluginComponent210Compat

    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 in Outer to hold the JS class value for Inner. 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 the transformInfo also applies to classes defined in the current compilation unit, the tree traversal must not create the field symbols a second time when synthesizing the ValDef. Instead, it must reuse the same symbols that transformInfo will create.

    It seems the easiest way to do that is to run the entire transform "in the future", with exitingPhase(ExplicitInnerJS). This design is similar to how explicitouter works.

  3. abstract class ExplicitLocalJS extends PluginComponent with Transform with TypingTransformers with PluginComponent210Compat

    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* classes. traits and objects 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 of outer() to hold the JS class value for Local. 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 a classOf
    • 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 of Local, 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 the val Local$jsclass is instead declared as a var 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 of C:

    • If C is a statically accessible class, desugar to runtime.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 form path.D for some pair (path, D), and we desugar it to path.D$jsclass, using the field created by ExplicitInnerJS (it is an error if C is of the form Enclosing#D).
    • If C is a local JS class, desugar to C$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 into js.special.instanceof(x, js.constructorOf[C]).
    • new C(...args) desugars into withContextualJSClassValue(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 into withContextualJSClassValue(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 as withContextualJSClassValue(js.constructorOf[ParentClassOfO], new O.type()), so that the back-end receives a reified reference to the parent class of O. A similar treatment is applied on anonymous JS classes, which basically define something very similar to an object, although without its own JS class.

  4. abstract class GenJSCode extends PluginComponent with TypeKinds with JSEncoding with GenJSExports with GenJSFiles with PluginComponent210Compat

    Generate JavaScript code and output it to disk

  5. trait GenJSExports extends SubComponent

    Generation of exports for JavaScript

  6. trait GenJSFiles extends SubComponent

    Send JS ASTs to files

  7. trait JSDefinitions extends AnyRef

    Core definitions for Scala.js

  8. trait JSEncoding extends SubComponent

    Encoding of symbol names for JavaScript

    Encoding of symbol names for JavaScript

    Some issues that this encoding solves: * Overloading: encode the full signature in the JS name * Same scope for fields and methods of a class * Global access to classes and modules (by their full name)

  9. trait JSGlobalAddons extends JSDefinitions with Compat210Component

    Additions to Global meaningful for the JavaScript backend

  10. abstract class JSPrimitives extends AnyRef

    Extension of ScalaPrimitives for primitives only relevant to the JS backend

  11. trait PluginComponent210Compat extends Compat210Component

  12. abstract class PreTyperComponent extends PluginComponent with Transform with PluginComponent210Compat

    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 the typer in jsinterop 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
      ...
    }
  13. trait PrepJSExports extends AnyRef

    Prepare export generation

    Prepare export generation

    Helpers for transformation of @JSExport annotations

  14. abstract class PrepJSInterop extends PluginComponent with PrepJSExports with Transform with PluginComponent210Compat

    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.

  15. 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.

  16. class ScalaJSPlugin extends Plugin

    Main entry point for the Scala.js compiler plugin

  17. trait TypeKinds extends SubComponent

    Glue representation of types as seen from the IR but still with a reference to the Symbols.

Value Members

  1. object Compat210Component

  2. object JSTreeExtractors

    Useful extractors for JavaScript trees

  3. object PrepJSInterop

  4. object ScalaJSOptions

  5. package util

Ungrouped