Trees
Type members
Classlikes
Apply an instance method with dynamic dispatch (the default).
Apply an instance method with dynamic dispatch (the default).
Apply a static method via dynamic import.
Apply a static method via dynamic import.
Apply a static method.
Apply a static method.
Apply an instance method with static dispatch (e.g., super calls).
Apply an instance method with static dispatch (e.g., super calls).
Binary operation (always preserves pureness).
Binary operation (always preserves pureness).
- Companion:
- object
- Companion:
- object
Closure with explicit captures.
Closure with explicit captures.
- Value parameters:
- arrow
If
true
, the closure is an Arrow Function (=>
), which does not have anthis
parameter, and cannot be constructed (called withnew
). Iffalse
, it is a regular Function (function
).
Creates a JavaScript class value.
Creates a JavaScript class value.
- Value parameters:
- captureValues
Actual values for the captured parameters (in the
ClassDef
'sjsClassCaptures.get
)- className
Reference to the
ClassDef
for the class definition, which must havejsClassCaptures.nonEmpty
Base class for all nodes in the IR.
Base class for all nodes in the IR.
Usually, one of the direct subclasses of IRNode
should be used instead.
Binary operation (always preserves pureness).
Binary operation (always preserves pureness).
Operations which do not preserve pureness are not allowed in this tree. These are notably +=, -=, *=, /= and %=
- Companion:
- object
delete qualifier[item]
delete qualifier[item]
JavaScript dynamic import of the form import(arg)
.
JavaScript dynamic import of the form import(arg)
.
This form is its own node, rather than using something like
JSFunctionApply(JSImport())
because import
is not a first-class term in JavaScript.
ImportCall
is a dedicated syntactic form that cannot be
dissociated.
JavaScript meta-property import.meta
.
JavaScript meta-property import.meta
.
This form is its own node, rather than using something like
JSSelect(JSImport(), StringLiteral("meta"))
because import
is not a first-class term in JavaScript. import.meta
is a dedicated syntactic form that cannot be dissociated.
Loading specification for a native JS class or object.
Loading specification for a native JS class or object.
- Companion:
- object
JavaScript meta-property new.target
.
JavaScript meta-property new.target
.
This form is its own node, rather than using something like
JSSelect(JSNew(), StringLiteral("target"))
because new
is not a first-class term in JavaScript. new.target
is a dedicated syntactic form that cannot be dissociated.
...items
, the "spread" operator of ECMAScript 6.
...items
, the "spread" operator of ECMAScript 6.
- Value parameters:
- items
An Array whose items will be spread (not an arbitrary iterable)
Super constructor call in the constructor of a non-native JS class.
Super constructor call in the constructor of a non-native JS class.
Exactly one such node must appear in the constructor of a
non-native JS class, at the top-level (possibly as a direct child
of a top-level Block
). Any other use of this node is invalid.
Statements before this node, as well as the args
, cannot contain any
This()
node. Statements after this node can use This()
.
After the execution of this node, it is guaranteed that all fields declared in the current class have been created and initialized. Up to that point, accessing any field declared in this class (e.g., through an overridden method called from the super constructor) is undefined behavior.
All in all, the shape of a constructor is therefore:
{
statementsNotUsingThis();
JSSuperConstructorCall(...argsNotUsingThis);
statementsThatMayUseThis()
}
which currently translates to something of the following shape:
{
statementsNotUsingThis();
super(...argsNotUsingThis);
this.privateField1 = 0;
this["publicField2"] = false;
statementsThatMayUseThis()
}
Calls a method inherited from the given superClass
on receiver
.
Calls a method inherited from the given superClass
on receiver
.
Intuitively, this corresponds to
superClass.prototype[method].call(receiver, ...args)
but retains more structure at the IR level than using an explicit encoding of the above expression.
Given the non-native JS classes
class Bar extends js.Object
class Foo extends Bar
The node
JSSuperBrackerCall(LoadJSConstructor(ClassName("Bar")), receiver, method, args)
which is printed as
super(constructorOf[Bar])::receiver[method](...args)
has the following semantics:
Bar.prototype[method].call(receiver, ...args)
If this happens to be located in an instance method of Foo
, and
receiver
happens to be This()
, this is equivalent to the ES6
statement
super[method](...args)
Selects a property inherited from the given superClass
on receiver
.
Selects a property inherited from the given superClass
on receiver
.
Given the non-native JS classes
class Bar extends js.Object
class Foo extends Bar
The node
JSSuperBrackerSelect(LoadJSConstructor(ClassName("Bar")), qualifier, item)
which is printed as
super(constructorOf[Bar])::qualifier[item]
has the semantics of an ES6 super reference
super[item]
as if it were in an instance method of Foo
with qualifier
as the
this
value.
Unary operation (always preserves pureness).
Unary operation (always preserves pureness).
Operations which do not preserve pureness are not allowed in this tree. These are notably ++ and --
- Companion:
- object
Marker for literals. Literals are always pure.
Marker for literals. Literals are always pure.
Loads the constructor of a JS class (native or not).
Loads the constructor of a JS class (native or not).
className
must represent a non-trait JS class (native or not).
This is used typically to instantiate a JS class, and most importantly if it is a non-native JS class. Given the class
class Foo(x: Int) extends js.Object
The instantiation new Foo(1)
would be represented as
JSNew(LoadJSConstructor(ClassName("Foo")), List(IntLiteral(1)))
This node is also useful to encode o.isInstanceOf[Foo]
:
JSBinaryOp(instanceof, o, LoadJSConstructor(ClassName("Foo")))
If Foo
is non-native, the presence of this node makes it instantiable,
and therefore reachable.
A break-free switch (without fallthrough behavior).
A break-free switch (without fallthrough behavior).
Unlike a JavaScript switch, it can be used in expression position.
It supports alternatives explicitly (hence the List[MatchableLiteral]
in cases), whereas in a switch one would use the fallthrough behavior to
implement alternatives.
(This is not a pattern matching construct like in Scala.)
The selector must be either an int
(IntType
) or a java.lang.String
.
The cases can be any MatchableLiteral
, even if they do not make sense
for the type of the selecter (they simply will never match).
Because +0.0 === -0.0
in JavaScript, and because those semantics are
used in a JS switch
, we have to prevent the selector from ever being
-0.0
. Otherwise, it would be matched by a case IntLiteral(0)
. At the
same time, we must allow at least int
and java.lang.String
to support
all switchable match
es from Scala. Since the latter two have no common
super type that does not allow -0.0
, we really have to special-case
those two types.
This is also why we restrict MatchableLiteral
s to IntLiteral
,
StringLiteral
and Null
. Allowing more cases would only make IR
checking more complicated, without bringing any added value.
Any member of a ClassDef
.
Any member of a ClassDef
.
Partitioned into AnyFieldDef
, MethodDef
and JSMethodPropDef
.
Export for a top-level object.
Export for a top-level object.
This exports the singleton instance of the containing module class. The instance is initialized during ES module instantiation.
A transient node for custom purposes.
A transient node for custom purposes.
A transient node is never a valid input to the Serializers nor to the linker, but can be used in a transient state for internal purposes.
- Value parameters:
- value
The payload of the transient node, without any specified meaning.
- Companion:
- object
Node for a statement or expression in the IR.
Node for a statement or expression in the IR.
A hash of a tree (usually a MethodDef).
A hash of a tree (usually a MethodDef).
Contains a SHA-1 hash.
Either a Tree
or a JSSpread
.
Either a Tree
or a JSSpread
.
This is the type of actual arguments to JS applications.
Unary operation (always preserves pureness).
Unary operation (always preserves pureness).
- Companion:
- object