@@ -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)
@@ -1021,7 +1023,7 @@ class JSCodeGen()(implicit ctx: Context) {
1021
1023
1022
1024
/** Gen JS code for a primitive method call. */
1023
1025
private def genPrimitiveOp (tree : Apply , isStat : Boolean ): js.Tree = {
1024
- import scala .tools .nsc .backend .ScalaPrimitives ._
1026
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1025
1027
1026
1028
implicit val pos = tree.pos
1027
1029
@@ -1061,7 +1063,7 @@ class JSCodeGen()(implicit ctx: Context) {
1061
1063
1062
1064
/** Gen JS code for a simple unary operation. */
1063
1065
private def genSimpleUnaryOp (tree : Apply , arg : Tree , code : Int ): js.Tree = {
1064
- import scala .tools .nsc .backend .ScalaPrimitives ._
1066
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1065
1067
1066
1068
implicit val pos = tree.pos
1067
1069
@@ -1102,7 +1104,7 @@ class JSCodeGen()(implicit ctx: Context) {
1102
1104
1103
1105
/** Gen JS code for a simple binary operation. */
1104
1106
private def genSimpleBinaryOp (tree : Apply , lhs : Tree , rhs : Tree , code : Int ): js.Tree = {
1105
- import scala .tools .nsc .backend .ScalaPrimitives ._
1107
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1106
1108
import js .UnaryOp ._
1107
1109
1108
1110
/* Codes for operation types, in an object so that they can be 'final val'
@@ -1280,7 +1282,7 @@ class JSCodeGen()(implicit ctx: Context) {
1280
1282
private def genUniversalEqualityOp (lhs : Tree , rhs : Tree , code : Int )(
1281
1283
implicit pos : Position ): js.Tree = {
1282
1284
1283
- import scala .tools .nsc .backend .ScalaPrimitives ._
1285
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1284
1286
1285
1287
val genLhs = genExpr(lhs)
1286
1288
val genRhs = genExpr(rhs)
@@ -1409,7 +1411,7 @@ class JSCodeGen()(implicit ctx: Context) {
1409
1411
1410
1412
/** Gen JS code for an array operation (get, set or length) */
1411
1413
private def genArrayOp (tree : Tree , code : Int ): js.Tree = {
1412
- import scala .tools .nsc .backend .ScalaPrimitives ._
1414
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1413
1415
1414
1416
implicit val pos = tree.pos
1415
1417
@@ -1423,8 +1425,9 @@ class JSCodeGen()(implicit ctx: Context) {
1423
1425
case defn.ArrayOf (el) => el
1424
1426
case JavaArrayType (el) => el
1425
1427
case tpe =>
1426
- ctx.error(s " expected Array $tpe" )
1427
- ErrorType
1428
+ val msg = ex " expected Array $tpe"
1429
+ ctx.error(msg)
1430
+ ErrorType (msg)
1428
1431
}
1429
1432
1430
1433
def genSelect (): js.Tree =
@@ -1472,7 +1475,7 @@ class JSCodeGen()(implicit ctx: Context) {
1472
1475
1473
1476
/** Gen JS code for a coercion */
1474
1477
private def genCoercion (tree : Apply , receiver : Tree , code : Int ): js.Tree = {
1475
- import scala .tools .nsc .backend .ScalaPrimitives ._
1478
+ import scala .tools .nsc .backend .ScalaPrimitivesOps ._
1476
1479
1477
1480
implicit val pos = tree.pos
1478
1481
@@ -1881,7 +1884,7 @@ class JSCodeGen()(implicit ctx: Context) {
1881
1884
}.unzip
1882
1885
1883
1886
val formalParamNames = sym.info.paramNamess.flatten.drop(envSize)
1884
- val formalParamTypes = sym.info.paramTypess .flatten.drop(envSize)
1887
+ val formalParamTypes = sym.info.paramInfoss .flatten.drop(envSize)
1885
1888
val (formalParams, actualParams) = formalParamNames.zip(formalParamTypes).map {
1886
1889
case (name, tpe) =>
1887
1890
val formalParam = js.ParamDef (freshLocalIdent(name.toString),
@@ -2175,7 +2178,7 @@ class JSCodeGen()(implicit ctx: Context) {
2175
2178
implicit pos : Position ): List [js.Tree ] = {
2176
2179
2177
2180
def paramNamesAndTypes (implicit ctx : Context ): List [(Names .TermName , Type )] =
2178
- sym.info.paramNamess.flatten.zip(sym.info.paramTypess .flatten)
2181
+ sym.info.paramNamess.flatten.zip(sym.info.paramInfoss .flatten)
2179
2182
2180
2183
val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) { implicit ctx =>
2181
2184
for ((name, tpe) <- paramNamesAndTypes)
0 commit comments