-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Scala.js: Implement the PrepJSInterop phase, minus exports handling. #9725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ final class JSDefinitions()(using Context) { | |
def JSPackage_constructorOf(using Context) = JSPackage_constructorOfR.symbol | ||
@threadUnsafe lazy val JSPackage_nativeR = ScalaJSJSPackageClass.requiredMethodRef("native") | ||
def JSPackage_native(using Context) = JSPackage_nativeR.symbol | ||
@threadUnsafe lazy val JSPackage_undefinedR = ScalaJSJSPackageClass.requiredMethodRef("undefined") | ||
def JSPackage_undefined(using Context) = JSPackage_undefinedR.symbol | ||
|
||
@threadUnsafe lazy val JSNativeAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.native") | ||
def JSNativeAnnot(using Context) = JSNativeAnnotType.symbol.asClass | ||
|
@@ -50,6 +52,11 @@ final class JSDefinitions()(using Context) { | |
@threadUnsafe lazy val PseudoUnionType: TypeRef = requiredClassRef("scala.scalajs.js.|") | ||
def PseudoUnionClass(using Context) = PseudoUnionType.symbol.asClass | ||
|
||
@threadUnsafe lazy val PseudoUnionModuleRef = requiredModuleRef("scala.scalajs.js.|") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need to special case this? I thought dotty supports union types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dotty supports union types, but it can also interoperate with Scala 2 libraries. And in particular with the pseudo Also note that we cannot "reinterpret" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The same is true for Scala 2 intersection types versus Dotty &, I have a wip branch which erases those differently, so we could extend that mechanism to handle unions too if needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean we could reinterpret There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that should be doable. |
||
def PseudoUnionModule(using Context) = PseudoUnionModuleRef.symbol | ||
@threadUnsafe lazy val PseudoUnion_fromTypeConstructorR = PseudoUnionModule.requiredMethodRef("fromTypeConstructor") | ||
def PseudoUnion_fromTypeConstructor(using Context) = PseudoUnion_fromTypeConstructorR.symbol | ||
|
||
@threadUnsafe lazy val JSArrayType: TypeRef = requiredClassRef("scala.scalajs.js.Array") | ||
def JSArrayClass(using Context) = JSArrayType.symbol.asClass | ||
|
||
|
@@ -63,6 +70,10 @@ final class JSDefinitions()(using Context) { | |
@threadUnsafe lazy val JavaScriptExceptionType: TypeRef = requiredClassRef("scala.scalajs.js.JavaScriptException") | ||
def JavaScriptExceptionClass(using Context) = JavaScriptExceptionType.symbol.asClass | ||
|
||
@threadUnsafe lazy val JSGlobalAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSGlobal") | ||
def JSGlobalAnnot(using Context) = JSGlobalAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSImportAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSImport") | ||
def JSImportAnnot(using Context) = JSImportAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSGlobalScopeAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSGlobalScope") | ||
def JSGlobalScopeAnnot(using Context) = JSGlobalScopeAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSNameAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSName") | ||
|
@@ -73,21 +84,24 @@ final class JSDefinitions()(using Context) { | |
def JSBracketAccessAnnot(using Context) = JSBracketAccessAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSBracketCallAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSBracketCall") | ||
def JSBracketCallAnnot(using Context) = JSBracketCallAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSExportTopLevelAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSExportTopLevel") | ||
def JSExportTopLevelAnnot(using Context) = JSExportTopLevelAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSExportAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSExport") | ||
def JSExportAnnot(using Context) = JSExportAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSExportDescendentObjectsAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSExportDescendentObjects") | ||
def JSExportDescendentObjectsAnnot(using Context) = JSExportDescendentObjectsAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSExportDescendentClassesAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSExportDescendentClasses") | ||
def JSExportDescendentClassesAnnot(using Context) = JSExportDescendentClassesAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSExportStaticAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSExportStatic") | ||
def JSExportStaticAnnot(using Context) = JSExportStaticAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSExportAllAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSExportAll") | ||
def JSExportAllAnnot(using Context) = JSExportAllAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSExportNamedAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSExportNamed") | ||
def JSExportNamedAnnot(using Context) = JSExportNamedAnnotType.symbol.asClass | ||
@threadUnsafe lazy val RawJSTypeAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.RawJSType") | ||
def RawJSTypeAnnot(using Context) = RawJSTypeAnnotType.symbol.asClass | ||
@threadUnsafe lazy val ExposedJSMemberAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.ExposedJSMember") | ||
@threadUnsafe lazy val JSTypeAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.internal.JSType") | ||
def JSTypeAnnot(using Context) = JSTypeAnnotType.symbol.asClass | ||
@threadUnsafe lazy val JSOptionalAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.internal.JSOptional") | ||
def JSOptionalAnnot(using Context) = JSOptionalAnnotType.symbol.asClass | ||
@threadUnsafe lazy val ExposedJSMemberAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.internal.ExposedJSMember") | ||
def ExposedJSMemberAnnot(using Context) = ExposedJSMemberAnnotType.symbol.asClass | ||
|
||
@threadUnsafe lazy val JSImportNamespaceModuleRef = requiredModuleRef("scala.scalajs.js.annotation.JSImport.Namespace") | ||
def JSImportNamespaceModule(using Context) = JSImportNamespaceModuleRef.symbol | ||
|
||
@threadUnsafe lazy val JSAnyModuleRef = requiredModuleRef("scala.scalajs.js.Any") | ||
def JSAnyModule(using Context) = JSAnyModuleRef.symbol | ||
@threadUnsafe lazy val JSAny_fromFunctionR = (0 to 22).map(n => JSAnyModule.requiredMethodRef("fromFunction" + n)).toArray | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems odd that the distinction of receiver types needs to be made here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also done in scala-js/scala-js:
https://github.com/scala-js/scala-js/blob/730931a3a11b351ea850a5c6107cfbd332c52a9b/compiler/src/main/scala/org/scalajs/nscplugin/GenJSCode.scala#L6171-L6188
That is necessary because the owner
SomeObject
referred to in an@JSName(SomeObject.aSymbolVal)
can be a Scala object, a native JS object or a non-native JS object.