@@ -185,7 +185,7 @@ class JSCodeGen()(implicit ctx: Context) {
185
185
import dotty .tools .io ._
186
186
187
187
val outputDirectory : AbstractFile = // TODO Support virtual files
188
- new PlainDirectory (new Directory ( new java.io. File ( ctx.settings.d .value)) )
188
+ new PlainDirectory (ctx.settings.outputDir .value)
189
189
190
190
val pathParts = sym.fullName.toString.split(" [./]" )
191
191
val dir = (outputDirectory /: pathParts.init)(_.subdirectoryNamed(_))
@@ -285,9 +285,9 @@ class JSCodeGen()(implicit ctx: Context) {
285
285
js.ModuleExportDef (" hello.world" ),
286
286
js.MethodDef (static = false , js.StringLiteral (" main" ),
287
287
Nil , jstpe.AnyType ,
288
- js.Block (List (
288
+ Some ( js.Block (List (
289
289
js.Apply (js.This ()(jstpe.ClassType (classIdent.name)), js.Ident (" main__V" ), Nil )(jstpe.NoType ),
290
- js.Undefined ())))(
290
+ js.Undefined ())))) (
291
291
OptimizerHints .empty, None ))
292
292
} else {
293
293
/*
@@ -339,17 +339,22 @@ class JSCodeGen()(implicit ctx: Context) {
339
339
implicit val pos = sym.pos
340
340
341
341
val classIdent = encodeClassFullNameIdent(sym)
342
+ val kind = {
343
+ if (sym.is(Trait )) ClassKind .AbstractJSType
344
+ else if (sym.is(ModuleClass )) ClassKind .NativeJSModuleClass
345
+ else ClassKind .NativeJSClass
346
+ }
342
347
val superClass =
343
348
if (sym.is(Trait )) None
344
349
else Some (encodeClassFullNameIdent(sym.superClass))
345
- val jsName =
346
- if (sym.is(Trait ) || sym.is( ModuleClass ) ) None
347
- else Some (fullJSNameOf(sym))
350
+ val jsNativeLoadSpec =
351
+ if (sym.is(Trait )) None
352
+ else Some (js. JSNativeLoadSpec . Global ( fullJSNameOf(sym).split( '.' ).toList ))
348
353
349
- js.ClassDef (classIdent, ClassKind . RawJSType ,
354
+ js.ClassDef (classIdent, kind ,
350
355
superClass,
351
356
genClassInterfaces(sym),
352
- jsName ,
357
+ jsNativeLoadSpec ,
353
358
Nil )(
354
359
OptimizerHints .empty)
355
360
}
@@ -404,10 +409,7 @@ class JSCodeGen()(implicit ctx: Context) {
404
409
" genClassFields called with a ClassDef other than the current one" )
405
410
406
411
// Non-method term members are fields
407
- (for {
408
- f <- classSym.info.decls
409
- if ! f.is(Method ) && f.isTerm
410
- } yield {
412
+ classSym.info.decls.filter(f => ! f.is(Method ) && f.isTerm).map({ f =>
411
413
implicit val pos = f.pos
412
414
413
415
val name =
@@ -451,7 +453,7 @@ class JSCodeGen()(implicit ctx: Context) {
451
453
}
452
454
}*/
453
455
454
- js.FieldDef (name, irTpe, f.is(Mutable ))
456
+ js.FieldDef (static = false , name, irTpe, f.is(Mutable ))
455
457
}).toList
456
458
}
457
459
@@ -510,7 +512,7 @@ class JSCodeGen()(implicit ctx: Context) {
510
512
None
511
513
} else*/ if (sym.is(Deferred )) {
512
514
Some (js.MethodDef (static = false , methodName,
513
- jsParams, toIRType(patchedResultType(sym)), js. EmptyTree )(
515
+ jsParams, toIRType(patchedResultType(sym)), None )(
514
516
OptimizerHints .empty, None ))
515
517
} else /* if (isJSNativeCtorDefaultParam(sym)) {
516
518
None
@@ -549,7 +551,7 @@ class JSCodeGen()(implicit ctx: Context) {
549
551
} else*/ if (sym.isConstructor) {
550
552
js.MethodDef (static = false , methodName,
551
553
jsParams, jstpe.NoType ,
552
- genStat(rhs))(optimizerHints, None )
554
+ Some ( genStat(rhs) ))(optimizerHints, None )
553
555
} else {
554
556
val resultIRType = toIRType(patchedResultType(sym))
555
557
genMethodDef(static = false , methodName,
@@ -576,7 +578,7 @@ class JSCodeGen()(implicit ctx: Context) {
576
578
tree : Tree , optimizerHints : OptimizerHints ): js.MethodDef = {
577
579
implicit val pos = tree.pos
578
580
579
- ctx.debuglog(" genMethod " + methodName.name )
581
+ ctx.debuglog(" genMethod " + methodName.encodedName )
580
582
ctx.debuglog(" " )
581
583
582
584
val jsParams = for (param <- paramsSyms) yield {
@@ -590,7 +592,7 @@ class JSCodeGen()(implicit ctx: Context) {
590
592
else genExpr(tree)
591
593
592
594
// if (!isScalaJSDefinedJSClass(currentClassSym)) {
593
- js.MethodDef (static, methodName, jsParams, resultIRType, genBody())(
595
+ js.MethodDef (static, methodName, jsParams, resultIRType, Some ( genBody() ))(
594
596
optimizerHints, None )
595
597
/* } else {
596
598
assert(!static, tree.pos)
@@ -1006,7 +1008,7 @@ class JSCodeGen()(implicit ctx: Context) {
1006
1008
1007
1009
/** Gen JS code for a primitive method call. */
1008
1010
private def genPrimitiveOp (tree : Apply , isStat : Boolean ): js.Tree = {
1009
- import scala .tools .nsc .backend .ScalaPrimitives ._
1011
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1010
1012
1011
1013
implicit val pos = tree.pos
1012
1014
@@ -1046,7 +1048,7 @@ class JSCodeGen()(implicit ctx: Context) {
1046
1048
1047
1049
/** Gen JS code for a simple unary operation. */
1048
1050
private def genSimpleUnaryOp (tree : Apply , arg : Tree , code : Int ): js.Tree = {
1049
- import scala .tools .nsc .backend .ScalaPrimitives ._
1051
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1050
1052
1051
1053
implicit val pos = tree.pos
1052
1054
@@ -1087,7 +1089,7 @@ class JSCodeGen()(implicit ctx: Context) {
1087
1089
1088
1090
/** Gen JS code for a simple binary operation. */
1089
1091
private def genSimpleBinaryOp (tree : Apply , lhs : Tree , rhs : Tree , code : Int ): js.Tree = {
1090
- import scala .tools .nsc .backend .ScalaPrimitives ._
1092
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1091
1093
import js .UnaryOp ._
1092
1094
1093
1095
/* Codes for operation types, in an object so that they can be 'final val'
@@ -1265,7 +1267,7 @@ class JSCodeGen()(implicit ctx: Context) {
1265
1267
private def genUniversalEqualityOp (lhs : Tree , rhs : Tree , code : Int )(
1266
1268
implicit pos : Position ): js.Tree = {
1267
1269
1268
- import scala .tools .nsc .backend .ScalaPrimitives ._
1270
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1269
1271
1270
1272
val genLhs = genExpr(lhs)
1271
1273
val genRhs = genExpr(rhs)
@@ -1394,7 +1396,7 @@ class JSCodeGen()(implicit ctx: Context) {
1394
1396
1395
1397
/** Gen JS code for an array operation (get, set or length) */
1396
1398
private def genArrayOp (tree : Tree , code : Int ): js.Tree = {
1397
- import scala .tools .nsc .backend .ScalaPrimitives ._
1399
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1398
1400
1399
1401
implicit val pos = tree.pos
1400
1402
@@ -1408,8 +1410,9 @@ class JSCodeGen()(implicit ctx: Context) {
1408
1410
case defn.ArrayOf (el) => el
1409
1411
case JavaArrayType (el) => el
1410
1412
case tpe =>
1411
- ctx.error(s " expected Array $tpe" )
1412
- ErrorType
1413
+ val msg = ex " expected Array $tpe"
1414
+ ctx.error(msg)
1415
+ ErrorType (msg)
1413
1416
}
1414
1417
1415
1418
def genSelect (): js.Tree =
@@ -1457,7 +1460,7 @@ class JSCodeGen()(implicit ctx: Context) {
1457
1460
1458
1461
/** Gen JS code for a coercion */
1459
1462
private def genCoercion (tree : Apply , receiver : Tree , code : Int ): js.Tree = {
1460
- import scala .tools .nsc .backend .ScalaPrimitives ._
1463
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1461
1464
1462
1465
implicit val pos = tree.pos
1463
1466
@@ -1866,7 +1869,7 @@ class JSCodeGen()(implicit ctx: Context) {
1866
1869
}.unzip
1867
1870
1868
1871
val formalParamNames = sym.info.paramNamess.flatten.drop(envSize)
1869
- val formalParamTypes = sym.info.paramTypess .flatten.drop(envSize)
1872
+ val formalParamTypes = sym.info.paramInfoss .flatten.drop(envSize)
1870
1873
val (formalParams, actualParams) = formalParamNames.zip(formalParamTypes).map {
1871
1874
case (name, tpe) =>
1872
1875
val formalParam = js.ParamDef (freshLocalIdent(name.toString),
@@ -2160,7 +2163,7 @@ class JSCodeGen()(implicit ctx: Context) {
2160
2163
implicit pos : Position ): List [js.Tree ] = {
2161
2164
2162
2165
def paramNamesAndTypes (implicit ctx : Context ): List [(Names .TermName , Type )] =
2163
- sym.info.paramNamess.flatten.zip(sym.info.paramTypess .flatten)
2166
+ sym.info.paramNamess.flatten.zip(sym.info.paramInfoss .flatten)
2164
2167
2165
2168
val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) { implicit ctx =>
2166
2169
for ((name, tpe) <- paramNamesAndTypes)
0 commit comments