diff --git a/compiler/testData/cli/js/jsHelp.out b/compiler/testData/cli/js/jsHelp.out index 84d2aecbc73..e64d0dfa8fa 100644 --- a/compiler/testData/cli/js/jsHelp.out +++ b/compiler/testData/cli/js/jsHelp.out @@ -7,6 +7,7 @@ where possible options include: -meta-info Generate metadata -kjsm Generate kjsm-files (for creating libraries) -target Generate JS files for specific ECMA version (only ECMA 5 is supported) + -module-kind Kind of a module generated by compiler. Supported values are: plain (by default), amd, commonjs, umd. -main {call,noCall} Whether a main function should be called; default 'call' (main function will be auto detected) -output-prefix Path to file which will be added to the beginning of output file -output-postfix Path to file which will be added to the end of output file @@ -17,5 +18,4 @@ where possible options include: -help (-h) Print a synopsis of standard options -X Print a synopsis of advanced options -P plugin::= - Pass an option to a plugin -OK \ No newline at end of file + Pass an option to a plugin \ No newline at end of file diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/config/JsConfig.java b/js/js.frontend/src/org/jetbrains/kotlin/js/config/JsConfig.java index a1f02e50730..d52bbdb640e 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/config/JsConfig.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/config/JsConfig.java @@ -83,7 +83,7 @@ public abstract class JsConfig { @NotNull public ModuleKind getModuleKind() { - return configuration.getNotNull(JSConfigurationKeys.MODULE_KIND); + return configuration.get(JSConfigurationKeys.MODULE_KIND, ModuleKind.PLAIN); } public abstract boolean checkLibFilesAndReportErrors(@NotNull Function1 report); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/rhino/RhinoUtils.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/rhino/RhinoUtils.java index aceb796f3a6..ea8ce836eb3 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/rhino/RhinoUtils.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/rhino/RhinoUtils.java @@ -193,6 +193,7 @@ public final class RhinoUtils { private static ScriptableObject initScope(@NotNull EcmaVersion version, @NotNull Context context, @NotNull List jsLibraries) { ScriptableObject scope = context.initStandardObjects(); try { + context.evaluateString(scope, "var Kotlin = {};", ".", 1, null); runFileWithRhino(getKotlinLibFile(version), context, scope); runFileWithRhino(TEST_DATA_DIR_PATH + "kotlin_lib.js", context, scope); runFileWithRhino(TEST_DATA_DIR_PATH + "maps.js", context, scope); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java index 7cc3be2bc3c..dbcd6976df2 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java @@ -41,7 +41,10 @@ import org.jetbrains.kotlin.resolve.BindingTrace; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import static org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.*; import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.pureFqn; @@ -542,6 +545,13 @@ public final class StaticContext { JsNameRef result = getQualifierForParentPackage(((PackageFragmentDescriptor) containingDescriptor).getFqName()); + // TODO: remove this dirty hack + if (descriptor instanceof ClassDescriptor && DescriptorUtils.isTopLevelDeclaration(descriptor)) { + if (DescriptorUtils.getFqNameFromTopLevelClass(descriptor).toString().equals("Annotation")) { + return result; + } + } + String moduleName = getExternalModuleName(descriptor); if (moduleName == null) { return result; diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/general/Translation.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/general/Translation.java index 61421168975..6c84fa91cce 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/general/Translation.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/general/Translation.java @@ -217,7 +217,6 @@ public final class Translation { TranslationContext context = TranslationContext.rootContext(staticContext, rootFunction); statements.addAll(PackageDeclarationTranslator.translateFiles(files, context)); defineModule(context, statements, config.getModuleId()); - statements.add(new JsReturn(program.getRootScope().declareName(Namer.getRootPackageName()).makeRef())); mayBeGenerateTests(files, config, rootBlock, context); @@ -241,6 +240,8 @@ public final class Translation { } } + statements.add(new JsReturn(program.getRootScope().declareName(Namer.getRootPackageName()).makeRef())); + JsBlock block = program.getGlobalBlock(); block.getStatements().addAll(wrapIfNecessary(config.getModuleId(), rootFunction, importedModuleList, program, config.getModuleKind())); @@ -362,7 +363,7 @@ public final class Translation { statement = invocation.makeStmt(); } else { - statement = JsAstUtils.newVar(program.getScope().declareName(moduleId), function); + statement = JsAstUtils.newVar(program.getScope().declareName(moduleId), invocation); } return Collections.singletonList(statement);