KT-3008: remove unused code that handles anonymous modules, since there's no way to declare them via configuration
This commit is contained in:
@@ -160,7 +160,7 @@ class FunctionReader(private val context: TranslationContext) {
|
||||
|
||||
private fun getRootPackage(): JsExpression {
|
||||
val rootName = context.program().rootScope.declareName(Namer.getRootPackageName())
|
||||
return JsAstUtils.fqnWithoutSideEffects(rootName, null)
|
||||
return JsAstUtils.pureFqn(rootName, null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.js.test.WithModuleKind
|
||||
import org.jetbrains.kotlin.serialization.js.ModuleKind
|
||||
|
||||
class MultiModuleWrappersTest() : MultipleModulesTranslationTest("multiModuleWrappers/") {
|
||||
private var overridenTestName = ""
|
||||
private var overriddenTestName = ""
|
||||
|
||||
@WithModuleKind(ModuleKind.AMD) fun testAmd() {
|
||||
runTest("simple")
|
||||
@@ -56,11 +56,11 @@ class MultiModuleWrappersTest() : MultipleModulesTranslationTest("multiModuleWra
|
||||
}
|
||||
|
||||
fun runTest(name: String) {
|
||||
overridenTestName = name
|
||||
overriddenTestName = name
|
||||
doTest("${pathToTestDir()}/cases/$name")
|
||||
}
|
||||
|
||||
override fun getTestName(lowercaseFirstLetter: Boolean) = overridenTestName
|
||||
override fun getTestName(lowercaseFirstLetter: Boolean) = overriddenTestName
|
||||
|
||||
override fun getOutputPath() = "${super.getOutputPath()}/${moduleKind.name.toLowerCase()}/"
|
||||
}
|
||||
|
||||
@@ -546,20 +546,7 @@ public final class StaticContext {
|
||||
JsNameRef result = getQualifierForParentPackage(((PackageFragmentDescriptor) containingDescriptor).getFqName());
|
||||
|
||||
JsExpression moduleExpression = getModuleExpressionFor(descriptor);
|
||||
if (moduleExpression == null) return result;
|
||||
|
||||
if (LibrarySourcesConfig.UNKNOWN_EXTERNAL_MODULE_NAME.equals(moduleName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JsName moduleId = moduleName.equals(Namer.KOTLIN_LOWER_NAME) ? rootScope.declareName(Namer.KOTLIN_NAME) :
|
||||
importedModules.get(moduleName);
|
||||
if (moduleId == null) {
|
||||
moduleId = rootScope.declareFreshName(Namer.LOCAL_MODULE_PREFIX + Namer.suggestedModuleName(moduleName));
|
||||
importedModules.put(moduleName, moduleId);
|
||||
}
|
||||
|
||||
return JsAstUtils.replaceRootReference(result, JsAstUtils.pureFqn(moduleId, null));
|
||||
return moduleExpression != null ? JsAstUtils.replaceRootReference(result, moduleExpression) : result;
|
||||
}
|
||||
};
|
||||
Rule<JsExpression> constructorOrCompanionObjectHasTheSameQualifierAsTheClass = new Rule<JsExpression>() {
|
||||
@@ -667,7 +654,7 @@ public final class StaticContext {
|
||||
importedModules.put(moduleName, moduleId);
|
||||
}
|
||||
|
||||
return JsAstUtils.fqnWithoutSideEffects(moduleId, null);
|
||||
return JsAstUtils.pureFqn(moduleId, null);
|
||||
}
|
||||
|
||||
private static JsExpression applySideEffects(JsExpression expression, DeclarationDescriptor descriptor) {
|
||||
|
||||
+16
-30
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.serialization.js.ModuleKind
|
||||
|
||||
object ModuleWrapperTranslation {
|
||||
@JvmStatic fun wrapIfNecessary(
|
||||
moduleId: String?, function: JsExpression, importedModules: List<String>,
|
||||
moduleId: String, function: JsExpression, importedModules: List<String>,
|
||||
program: JsProgram, kind: ModuleKind
|
||||
): List<JsStatement> {
|
||||
return when (kind) {
|
||||
@@ -35,7 +35,7 @@ object ModuleWrapperTranslation {
|
||||
}
|
||||
|
||||
private fun wrapUmd(
|
||||
moduleId: String?, function: JsExpression,
|
||||
moduleId: String, function: JsExpression,
|
||||
importedModules: List<String>, program: JsProgram
|
||||
): List<JsStatement> {
|
||||
val scope = program.scope
|
||||
@@ -57,18 +57,13 @@ object ModuleWrapperTranslation {
|
||||
val commonJsBody = JsBlock(wrapCommonJs(factoryName.makeRef(), importedModules, program))
|
||||
val plainInvocation = makePlainInvocation(factoryName.makeRef(), importedModules, program)
|
||||
|
||||
val plainExpr: JsExpression = if (moduleId != null) {
|
||||
val lhs: JsExpression = if (Namer.requiresEscaping(moduleId)) {
|
||||
JsArrayAccess(rootName.makeRef(), program.getStringLiteral(moduleId))
|
||||
}
|
||||
else {
|
||||
JsNameRef(scope.declareName(moduleId), rootName.makeRef())
|
||||
}
|
||||
JsAstUtils.assignment(lhs, plainInvocation)
|
||||
val lhs: JsExpression = if (Namer.requiresEscaping(moduleId)) {
|
||||
JsArrayAccess(rootName.makeRef(), program.getStringLiteral(moduleId))
|
||||
}
|
||||
else {
|
||||
plainInvocation
|
||||
JsNameRef(scope.declareName(moduleId), rootName.makeRef())
|
||||
}
|
||||
val plainExpr = JsAstUtils.assignment(lhs, plainInvocation)
|
||||
|
||||
val selector = JsAstUtils.newJsIf(amdTest, amdBody, JsAstUtils.newJsIf(commonJsTest, commonJsBody, plainExpr.makeStmt()))
|
||||
adapterBody.statements += selector
|
||||
@@ -77,20 +72,16 @@ object ModuleWrapperTranslation {
|
||||
}
|
||||
|
||||
private fun wrapAmd(
|
||||
moduleId: String?,function: JsExpression,
|
||||
moduleId: String,function: JsExpression,
|
||||
importedModules: List<String>, program: JsProgram
|
||||
): List<JsStatement> {
|
||||
val scope = program.scope
|
||||
val defineName = scope.declareName("define")
|
||||
val invocationArgs = mutableListOf<JsExpression>()
|
||||
|
||||
if (moduleId != null) {
|
||||
invocationArgs += program.getStringLiteral(moduleId)
|
||||
}
|
||||
|
||||
val moduleNameList = importedModules.map { program.getStringLiteral(it) }
|
||||
invocationArgs += JsArrayLiteral(moduleNameList)
|
||||
invocationArgs += function
|
||||
val invocationArgs = listOf(
|
||||
program.getStringLiteral(moduleId),
|
||||
JsArrayLiteral(importedModules.map { program.getStringLiteral(it) }),
|
||||
function
|
||||
)
|
||||
|
||||
val invocation = JsInvocation(defineName.makeRef(), invocationArgs)
|
||||
return listOf(invocation.makeStmt())
|
||||
@@ -108,21 +99,16 @@ object ModuleWrapperTranslation {
|
||||
}
|
||||
|
||||
private fun wrapPlain(
|
||||
moduleId: String?, function: JsExpression,
|
||||
moduleId: String, function: JsExpression,
|
||||
importedModules: List<String>, program: JsProgram
|
||||
): List<JsStatement> {
|
||||
val invocation = makePlainInvocation(function, importedModules, program)
|
||||
|
||||
val statement = if (moduleId == null) {
|
||||
invocation.makeStmt()
|
||||
val statement = if (Namer.requiresEscaping(moduleId)) {
|
||||
JsAstUtils.assignment(makePlainModuleRef(moduleId, program), invocation).makeStmt()
|
||||
}
|
||||
else {
|
||||
if (Namer.requiresEscaping(moduleId)) {
|
||||
JsAstUtils.assignment(makePlainModuleRef(moduleId, program), invocation).makeStmt()
|
||||
}
|
||||
else {
|
||||
JsAstUtils.newVar(program.rootScope.declareName(moduleId), invocation)
|
||||
}
|
||||
JsAstUtils.newVar(program.rootScope.declareName(moduleId), invocation)
|
||||
}
|
||||
|
||||
return listOf(statement)
|
||||
|
||||
Reference in New Issue
Block a user