diff --git a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt index af2234d71bd..c377ab3d976 100644 --- a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt +++ b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt @@ -27,6 +27,7 @@ class Kotlin2JsTask : KotlinCompilerBaseTask() { var outputPostfix: File? = null var sourceMap: Boolean = false var metaInfo: Boolean = false + var moduleKind: String = "plain" /** * {@link K2JsArgumentConstants.CALL} (default) if need generate a main function call (main function will be auto detected) @@ -73,5 +74,7 @@ class Kotlin2JsTask : KotlinCompilerBaseTask() { if (noStdlib) args.add("-no-stdlib") if (sourceMap) args.add("-source-map") if (metaInfo) args.add("-meta-info") + + args += listOf("-module-kind", moduleKind) } } diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar b/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar index 9ab9caad358..9e5f07c06b9 100644 Binary files a/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar and b/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar differ diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/jslib-example.js b/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/jslib-example.js index 8fb2ce81d48..74647a38a35 100644 --- a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/jslib-example.js +++ b/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/jslib-example.js @@ -1,4 +1,4 @@ -(function (Kotlin) { +this['jslib-example'] = function (Kotlin) { 'use strict'; var _ = Kotlin.defineRootPackage(null, /** @lends _ */ { library: Kotlin.definePackage(null, /** @lends _.library */ { @@ -27,11 +27,12 @@ return result; }, equals_za3rmp$: function (other) { - return this === other || (other !== null && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value))); + return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value)))); } }) }) }) }); Kotlin.defineModule('jslib-example', _); -}(Kotlin)); + return _; +}(kotlin); diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/amd.js b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/amd.js new file mode 100644 index 00000000000..4eff8adf66b --- /dev/null +++ b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/amd.js @@ -0,0 +1,15 @@ +(function(global) { + var modules = {}; + modules.kotlin = kotlin; + + function define(name, dependencies, body) { + var resolvedDependencies = []; + for (var i = 0; i < dependencies.length; ++i) { + resolvedDependencies[i] = modules[dependencies[i]]; + } + modules[name] = body.apply(body, resolvedDependencies); + } + define.amd = {}; + + global.define = define; +})(this); \ No newline at end of file diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/build.log.expected b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/build.log.expected new file mode 100644 index 00000000000..3dc293a7e9d --- /dev/null +++ b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/build.log.expected @@ -0,0 +1,14 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [mkdir] Created dir: [Temp]/lib +[kotlin2js] Compiling [[TestData]/jslib-example] => [[Temp]/lib/jslib-example.js] +[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] + [copy] Copying 2 files to [Temp] + [copy] Copying 1 file to [Temp] + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/build.xml b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/build.xml new file mode 100644 index 00000000000..4effa950e3d --- /dev/null +++ b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/build.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/jslib-example/LibraryExample.kt b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/jslib-example/LibraryExample.kt new file mode 100644 index 00000000000..f77e26551f9 --- /dev/null +++ b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/jslib-example/LibraryExample.kt @@ -0,0 +1,9 @@ +package library.sample + +import kotlin.js.Date + +public class ClassA() { + val value: Int = 100 +} + +public fun Date.extFun(): Int = 100 \ No newline at end of file diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/root1/foo.kt b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/root1/foo.kt new file mode 100644 index 00000000000..743fab365aa --- /dev/null +++ b/compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/root1/foo.kt @@ -0,0 +1,17 @@ +package foo + +import library.sample.* +import kotlin.js.Date + +var ok = "FAIL" + +fun main(args: Array) { + val x = ClassA().value + if (x == 100) { + ok = "OK" + } + val date = Date() + println(date.extFun()) +} + +fun box(): String = ok diff --git a/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java b/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java index 4b36b901c82..73d00da2936 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java @@ -120,6 +120,10 @@ public class AntTaskJsTest extends AbstractAntTaskTest { doJsAntTest("jslib-example.js"); } + public void testSimpleWithStdlibAndJsFileAsAnotherLibModuleKind() throws Exception { + doJsAntTest("amd.js", "jslib-example.js"); + } + public void testSimpleWithStdlibAndTwoJsFilesAsLibraries() throws Exception { doJsAntTest("jslib-example1.js", "jslib-example2.js"); }