From 713a7efcdff52c6bd6f0a01d3cd185844a2648d2 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 25 Apr 2016 15:19:49 +0300 Subject: [PATCH] KT-3008 Add support of module kind to Ant task. Repair Ant JS tests --- .../org/jetbrains/kotlin/ant/Kotlin2JsTask.kt | 3 +++ .../jslib-example.jar | Bin 1498 -> 1778 bytes .../jslib-example/jslib-example.js | 7 +++--- .../amd.js | 15 ++++++++++++ .../build.log.expected | 14 +++++++++++ .../build.xml | 23 ++++++++++++++++++ .../jslib-example/LibraryExample.kt | 9 +++++++ .../root1/foo.kt | 17 +++++++++++++ .../kotlin/integration/AntTaskJsTest.java | 4 +++ 9 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/amd.js create mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/build.log.expected create mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/build.xml create mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/jslib-example/LibraryExample.kt create mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/root1/foo.kt 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 9ab9caad358789fe738d0534695a599d4b63319a..9e5f07c06b9a2384b91599c739bb416eeb43bc75 100644 GIT binary patch literal 1778 zcmWIWW@h1H0D(JQjvinJl;C8LVeoYgan$wnbJGtE;bdU8&srb0`lM`lX$3a}Bg+eB z1_m$@05n1bsEGq?#AYVN+I>Kt5F-PF2(l5rj((nQuE8OCzHV^SR6b*vR(o!D-ys75 z)(iJ0{XeKG(#PTCxbUxB=D6>pO<~dTk8T}*KCgIP?%u2`-(NUhO#3KT zKY8l{iN6h&SK6lTddTxgKjw0q>W6YB0m;?{TXMW)pMLu#((TP()GKQ`-!4-imzQTHE}pS>KH>&$n0` z@a>y-r^{nrRj`Bh>EJ5_#l~Vt9v+JearECzwhjN?#n7(V0$j*TIwX3 z&?P_3t3_{oV*R(MdC}(+^Q7)?we_{R;`b(Nii^AU`i`i(AGrKO^WHCWNnNq+?%osp zAwMhaJs!R)64;W?&yxH9dBHiWw#8l_mn(*Bt(}}L_@(!?=qcgj2frR|OxXRkpd$JC zt;xLU=>prA_g$B}yhwRpg~M-?omZ{R&rMtL{=55^b!F3p*z4-q3jZTd8xO@knfNIkL&k2hmyHhu&-d~|E2)O>9lXM_z`*!Y*sjUkV zY;Vp@QO`*`e8$CQU*H-RY5ouQf9EqV7Jawv%YjV2D<c5JTlR+3g^_2bK^d?{%fyoyv^D@VV5>ebGa3zebxA7=k5YaL0FsdoF?}Z3swffp!Ek+x7vOl<7SYO6G&EM|J``^FC5upO| zw#aSGAGd*CC}w3~5CD23t2ie!NjDYh>#X9bA-D5{4Fzi7hw}to-CHlPZSAjV8d@v# z6+*Tyk{7Ui?fK}@jbqcD6n>V=tlzww?`)Ud+UxTyr_bE@xm9>;YLLUf(5Q1RjP>Uj zjM4>quCCd3^T_}G0=&jEoP>h|V+ayuaO`=C_S=>*}a?UYVIo@2*&!#B`--?GlH?^}qXqS=T=GJGG?zj`8l}!Lx7X z*B2cY_00OwwNWhW!Fk5Fm0#?>zEfRXz`FhKte)AkMAStie?D2?6!EWp|C^4ISwB~H z##$eEB3u5@f3uSH$vsMGrRth|hVS1mb9=nw>)pMxWL9?lE(|<$wp9H^!#s{#|GEX| zm~yC3eZ=p+YmS<|V0y7+FpzR6SkkBs%5L=t zyRhdtgnDUUg2c#w$l9@GK!o-qK<)7C2-oHf&FJVU9-*&`2{Zi%c(byBRImb}A<*2( HEFc~LRe-G@ 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"); }