From 71925297335acd3d358330a3e18d15aa5b6fc186 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 30 Jan 2017 19:24:42 +0300 Subject: [PATCH] JS: drop support of old library format --- .../cli/js/folderAsLib/LibraryExample.js | 44 +++++++ .../cli/js/folderAsLib/LibraryExample.meta.js | 1 + .../LibraryExample/library/sample/sample.kjsm | Bin 0 -> 432 bytes .../testData/cli/js/lib/LibraryExample.jar | Bin 0 -> 2967 bytes .../js/lib}/LibraryExample.kt | 0 compiler/testData/cli/js/lib/ReadMe.md | 5 + .../testData/cli/js/notValidLibraryDir.args | 2 +- .../testData/cli/js/notValidLibraryDir.out | 2 +- compiler/testData/cli/js/withFolderAsLib.args | 2 +- compiler/testData/cli/js/withLib.args | 2 +- .../build.log.expected | 11 -- .../simpleWithStdlibAndAnotherLib/build.xml | 17 --- .../jslib-example.jar | Bin 1778 -> 0 bytes .../root1/foo.kt | 14 --- .../build.log.expected | 11 -- .../build.xml | 17 --- .../jslib-example/META-INF/MANIFEST.MF | 9 -- .../jslib-example/ReadMe.md | 6 - .../jslib-example/jslib-example.js | 38 ------ .../root1/foo.kt | 14 --- .../jetbrains/kotlin/utils/LibraryUtils.kt | 20 +--- idea/src/META-INF/extensions/kotlin2js.xml | 1 - .../kotlin/jps/build/KotlinJpsBuildTest.kt | 11 +- .../jslib-example/META-INF/MANIFEST.MF | 1 - .../jslib-example/ReadMe.md | 2 +- .../jslib-example/jslib-example.js | 79 +++++++------ .../jslib-example/jslib-example.meta.js | 1 + .../jslib-example/library/sample/sample.kjsm | Bin 0 -> 432 bytes .../js/analyze/TopDownAnalyzerFacadeForJS.kt | 3 +- .../kotlin/js/analyze/suppressWarnings.kt | 10 -- .../jetbrains/kotlin/js/config/JsConfig.java | 22 +--- .../js/config/LibrarySourcesConfig.java | 111 ++++-------------- .../kotlin/js/inline/FunctionReader.kt | 10 +- .../kotlin/integration/AntTaskJsTest.java | 8 -- .../kotlin/js/facade/K2JSTranslator.java | 2 +- .../js/translate/utils/JsDescriptorUtils.java | 32 +---- resources/kotlinManifest.properties | 1 - 37 files changed, 143 insertions(+), 366 deletions(-) create mode 100644 compiler/testData/cli/js/folderAsLib/LibraryExample.js create mode 100644 compiler/testData/cli/js/folderAsLib/LibraryExample.meta.js create mode 100644 compiler/testData/cli/js/folderAsLib/LibraryExample/library/sample/sample.kjsm create mode 100644 compiler/testData/cli/js/lib/LibraryExample.jar rename compiler/testData/{integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example => cli/js/lib}/LibraryExample.kt (100%) create mode 100644 compiler/testData/cli/js/lib/ReadMe.md delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/build.log.expected delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/build.xml delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/root1/foo.kt delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/build.log.expected delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/build.xml delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/META-INF/MANIFEST.MF delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/ReadMe.md delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/jslib-example.js delete mode 100644 compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/root1/foo.kt create mode 100644 jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example.meta.js create mode 100644 jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example/library/sample/sample.kjsm diff --git a/compiler/testData/cli/js/folderAsLib/LibraryExample.js b/compiler/testData/cli/js/folderAsLib/LibraryExample.js new file mode 100644 index 00000000000..68154be1e35 --- /dev/null +++ b/compiler/testData/cli/js/folderAsLib/LibraryExample.js @@ -0,0 +1,44 @@ +if (typeof kotlin === 'undefined') { + throw new Error("Error loading module 'LibraryExample'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'LibraryExample'."); +} +var LibraryExample = function (_, Kotlin) { + 'use strict'; + function pairAdd(p) { + return p.first + p.second | 0; + } + function pairMul(p) { + return Kotlin.imul(p.first, p.second); + } + function IntHolder(value) { + this.value = value; + } + IntHolder.$metadata$ = { + kind: Kotlin.Kind.CLASS, + simpleName: 'IntHolder', + interfaces: [] + }; + IntHolder.prototype.component1 = function () { + return this.value; + }; + IntHolder.prototype.copy_za3lpa$ = function (value) { + return new IntHolder(value === void 0 ? this.value : value); + }; + IntHolder.prototype.toString = function () { + return 'IntHolder(value=' + Kotlin.toString(this.value) + ')'; + }; + IntHolder.prototype.hashCode = function () { + var result = 0; + result = result * 31 + Kotlin.hashCode(this.value) | 0; + return result; + }; + IntHolder.prototype.equals = function (other) { + return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value)))); + }; + var package$library = _.library || (_.library = {}); + var package$sample = package$library.sample || (package$library.sample = {}); + package$sample.pairAdd_1fzo63$ = pairAdd; + package$sample.pairMul_1fzo63$ = pairMul; + package$sample.IntHolder = IntHolder; + Kotlin.defineModule('LibraryExample', _); + return _; +}(typeof LibraryExample === 'undefined' ? {} : LibraryExample, kotlin); diff --git a/compiler/testData/cli/js/folderAsLib/LibraryExample.meta.js b/compiler/testData/cli/js/folderAsLib/LibraryExample.meta.js new file mode 100644 index 00000000000..5dd2ffc566e --- /dev/null +++ b/compiler/testData/cli/js/folderAsLib/LibraryExample.meta.js @@ -0,0 +1 @@ +// Kotlin.kotlin_module_metadata(1, "LibraryExample", "H4sIAAAAAAAAAJVW227TQBB1fF1Pb64LJTUgRBEgbiWkCIEESC19KJWQgIoPcJ1tsqmzG9ZO0v4Ar0h9QP2UfAGf0N+BcS5O0tRu6gfvaHdmzlzOjq2490FxFa94Rv4Nn0LXHsmnRHE9sMD49oOz2NVBdRTPPCNK11aSs4cwD+aRiEPGQWXChUQBdKI4hUQNffVcvIabqZol6WFIgxjUeuQ6I318Fxw1sVK7tjp0rtf9tg96K2ZhlvOXsJo6n6fHTSpZg/LYzzToBV3/2aLyBNQWy1J7BzdAE7IKWmczAK0iGqAFUeSuXowZ36qjJaZa19YS0yfgpCGZ0udVGmWh7MNGqgqBkAJT5TSazASA8VgyHrFgJvwNWBoP/bgm8yv9CBbSIJJEr1OSlgxnCakIRs90mkO3gQzbMX34AGCEmBXWxhi95gLRaPqSRYJn1vw5rKT6dkQRmgfZHXqBSacdakqBbYlZtvqFYMKE6ywnmAn3IwLkXaVeQayjmhRcRGB06EE1zG/wZY2L2tVZGvcebl00NWkbaTkTEycGRD0zqx4H+mrTHNgcq1AP3zhosbCSn/FTWJ4aOVnobyZSnMMGHwrZ8JEU+RjPwE0xCN5QKnn21NmC9asvej7ebw3+FMAK2YH0cXaZkd9ohhTszzzeFWGFylGZtvgJGG0/bFHQ8DhBbDQFR5BXoAeiidbIez+MwNoWIqQ+B0PENXRBan5U+yQqFEgs9pOpUwVzsFpNn8mtSgUKTdC/otzf+dIK3Y9jgZtJ4EUFdzSUNUdHOVnNwQqDdXGwLhcVb8e76yx5askou47jLbq6i3L/XSJdouCxm3Pcr/M6I79IUS2rJX2buKZjJBZ7tmMl6+5fbW/FISiqZYI8NfqbBdy0UTTLxJnz9GKhpO+ea2g03zs/L6C4gKKF4veBSwQ8JSpMDdpkdM7OygMpOhGVWYR5C2tjvhe4iNkhC/z+MMlFKSHKyNI4pHFQy7d4DIuTUyUrqERxmIAe0+PMOzXxSam3Mz8pd8BOGT199T9A8eLwQcbJCMk4y/Qp46AfmVsdIY+ovGbxWEivsFgDs/+fMh3/Dty79MdnbFzMkMbEJ8LnyIQeCzJK6g1U/wOSAB0W3QkAAA=="); diff --git a/compiler/testData/cli/js/folderAsLib/LibraryExample/library/sample/sample.kjsm b/compiler/testData/cli/js/folderAsLib/LibraryExample/library/sample/sample.kjsm new file mode 100644 index 0000000000000000000000000000000000000000..f53578c8ac0ac1a628c156f0bcb52b8f6bd937d9 GIT binary patch literal 432 zcmaKnK~BRk5JhdraV7&46E;yKHXHzj8~~}nB2+>`a01g-`F7!4Mx!HXZ7zVxoL9jbTV zySl+(+^jJCG;V1zpcrxL=dEvS(_f>U`gVoNek_e!V07!fv!=n&_cIy+Gqaf8`N|^n z{-y8g<_*=LQETdMTvf literal 0 HcmV?d00001 diff --git a/compiler/testData/cli/js/lib/LibraryExample.jar b/compiler/testData/cli/js/lib/LibraryExample.jar new file mode 100644 index 0000000000000000000000000000000000000000..8f4c227bcb97895ae6c27f9a0af5a84b0c30f962 GIT binary patch literal 2967 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 mx8nZ~yT7sj6>CCs0Q [[Temp]/out.js] - [unzip] Expanding: [TestData]/jslib-example.jar into [Temp] - -BUILD SUCCESSFUL -Total time: [time] - -Return code: 0 diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/build.xml b/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/build.xml deleted file mode 100644 index e6853081fc0..00000000000 --- a/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/build.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar b/compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar deleted file mode 100644 index 9e5f07c06b9a2384b91599c739bb416eeb43bc75..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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=k5) { - val p = Pair(10, 20) - val x = pairAdd(p) - ok = "OK" - println("x=$x") -} - -fun box(): String = ok diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/build.log.expected b/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/build.log.expected deleted file mode 100644 index f1a7a8e9413..00000000000 --- a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/build.log.expected +++ /dev/null @@ -1,11 +0,0 @@ -OUT: -Buildfile: [TestData]/build.xml - -build: -[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] - [copy] Copying 1 file to [Temp] - -BUILD SUCCESSFUL -Total time: [time] - -Return code: 0 diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/build.xml b/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/build.xml deleted file mode 100644 index 5c132935d2b..00000000000 --- a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/build.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/META-INF/MANIFEST.MF b/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/META-INF/MANIFEST.MF deleted file mode 100644 index 00281ee90c5..00000000000 --- a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/META-INF/MANIFEST.MF +++ /dev/null @@ -1,9 +0,0 @@ -Manifest-Version: 1.0 -Ant-Version: Apache Ant 1.9.1 -Created-By: 1.7.0_72-b14 (Oracle Corporation) -Built-By: JetBrains -Implementation-Vendor: JetBrains -Implementation-Version: snapshot -Specification-Title: Kotlin JavaScript Lib -Kotlin-JS-Module-Name: jslib-example - diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/ReadMe.md b/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/ReadMe.md deleted file mode 100644 index 714dece829f..00000000000 --- a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/ReadMe.md +++ /dev/null @@ -1,6 +0,0 @@ -# jslib-example - -Path to sources: compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example - -The archive compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar should be updated after -changing some files in source folder. 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 deleted file mode 100644 index 74647a38a35..00000000000 --- a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example/jslib-example.js +++ /dev/null @@ -1,38 +0,0 @@ -this['jslib-example'] = function (Kotlin) { - 'use strict'; - var _ = Kotlin.defineRootPackage(null, /** @lends _ */ { - library: Kotlin.definePackage(null, /** @lends _.library */ { - sample: Kotlin.definePackage(null, /** @lends _.library.sample */ { - pairAdd_bunuun$: function (p) { - return p.first + p.second; - }, - pairMul_bunuun$: function (p) { - return p.first * p.second; - }, - IntHolder: Kotlin.createClass(null, function (value) { - this.value = value; - }, /** @lends _.library.sample.IntHolder.prototype */ { - component1: function () { - return this.value; - }, - copy_za3lpa$: function (value) { - return new _.library.sample.IntHolder(value === void 0 ? this.value : value); - }, - toString: function () { - return 'IntHolder(value=' + Kotlin.toString(this.value) + ')'; - }, - hashCode: function () { - var result = 0; - result = result * 31 + Kotlin.hashCode(this.value) | 0; - return result; - }, - equals_za3rmp$: function (other) { - return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value)))); - } - }) - }) - }) - }); - Kotlin.defineModule('jslib-example', _); - return _; -}(kotlin); diff --git a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/root1/foo.kt b/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/root1/foo.kt deleted file mode 100644 index c6da571924b..00000000000 --- a/compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/root1/foo.kt +++ /dev/null @@ -1,14 +0,0 @@ -package foo - -import library.sample.* - -var ok = "FAIL" - -fun main(args: Array) { - val p = Pair(10, 20) - val x = pairAdd(p) - ok = "OK" - println("x=$x") -} - -fun box(): String = ok diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/LibraryUtils.kt b/compiler/util/src/org/jetbrains/kotlin/utils/LibraryUtils.kt index 22c63e3e6a3..d9b793cd25d 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/LibraryUtils.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/LibraryUtils.kt @@ -27,17 +27,13 @@ import java.util.jar.Manifest object LibraryUtils { private val LOG = Logger.getInstance(LibraryUtils::class.java) - val KOTLIN_JS_MODULE_NAME: String = "Kotlin-JS-Module-Name" private var TITLE_KOTLIN_JAVASCRIPT_STDLIB: String - private var TITLE_KOTLIN_JAVASCRIPT_LIB: String val META_INF = "META-INF/" private val MANIFEST_PATH = "${META_INF}MANIFEST.MF" - private val KOTLIN_JS_MODULE_ATTRIBUTE_NAME = Attributes.Name(KOTLIN_JS_MODULE_NAME) init { var jsStdLib = "" - var jsLib = "" val manifestProperties = LibraryUtils::class.java.getResourceAsStream("/kotlinManifest.properties") if (manifestProperties != null) { @@ -45,7 +41,6 @@ object LibraryUtils { val properties = Properties() properties.load(manifestProperties) jsStdLib = properties.getPropertyOrFail("manifest.impl.title.kotlin.javascript.stdlib") - jsLib = properties.getPropertyOrFail("manifest.spec.title.kotlin.javascript.lib") } catch (e: IOException) { LOG.error(e) @@ -57,27 +52,14 @@ object LibraryUtils { } TITLE_KOTLIN_JAVASCRIPT_STDLIB = jsStdLib - TITLE_KOTLIN_JAVASCRIPT_LIB = jsLib } @JvmStatic fun getJarFile(classesRoots: List, jarName: String): VirtualFile? { return classesRoots.firstOrNull { it.name == jarName } } - @JvmStatic fun getKotlinJsModuleName(library: File): String? { - return getManifestMainAttributesFromJarOrDirectory(library)?.getValue(KOTLIN_JS_MODULE_ATTRIBUTE_NAME) - } - - @JvmStatic fun isOldKotlinJavascriptLibrary(library: File): Boolean = - checkAttributeValue(library, TITLE_KOTLIN_JAVASCRIPT_LIB, Attributes.Name.SPECIFICATION_TITLE) && - getKotlinJsModuleName(library) != null - - @JvmStatic fun isKotlinJavascriptLibraryWithMetadata(library: File): Boolean = - KotlinJavascriptMetadataUtils.loadMetadata(library).isNotEmpty() - @Suppress("unused") // used in K2JSCompilerMojo - @JvmStatic fun isKotlinJavascriptLibrary(library: File): Boolean = - isOldKotlinJavascriptLibrary(library) || isKotlinJavascriptLibraryWithMetadata(library) + @JvmStatic fun isKotlinJavascriptLibrary(library: File): Boolean = KotlinJavascriptMetadataUtils.loadMetadata(library).isNotEmpty() @JvmStatic fun isKotlinJavascriptStdLibrary(library: File): Boolean { return checkAttributeValue(library, TITLE_KOTLIN_JAVASCRIPT_STDLIB, Attributes.Name.IMPLEMENTATION_TITLE) diff --git a/idea/src/META-INF/extensions/kotlin2js.xml b/idea/src/META-INF/extensions/kotlin2js.xml index e42e3fc04ba..99248642ec3 100644 --- a/idea/src/META-INF/extensions/kotlin2js.xml +++ b/idea/src/META-INF/extensions/kotlin2js.xml @@ -8,6 +8,5 @@ - diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index b065e8962a4..3fbf62c0c2c 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -98,8 +98,7 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { private val EXPECTED_JS_FILES_IN_OUTPUT_NO_COPY = hashSetOf( "$PROJECT_NAME.js", "$PROJECT_NAME.meta.js", - "$PROJECT_NAME/root-package.kjsm", - "$PROJECT_NAME/library/sample/sample.kjsm" + "$PROJECT_NAME/root-package.kjsm" ) private val EXPECTED_JS_FILES_IN_OUTPUT_WITH_ADDITIONAL_LIB_AND_DEFAULT_DIR = hashSetOf( "$PROJECT_NAME.js", @@ -107,13 +106,13 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { "lib/kotlin.js", "lib/kotlin.meta.js", "lib/jslib-example.js", + "lib/jslib-example.meta.js", "lib/file0.js", "lib/dir/file1.js", "lib/META-INF-ex/file2.js", "lib/res0.js", "lib/resdir/res1.js", - "$PROJECT_NAME/root-package.kjsm", - "$PROJECT_NAME/library/sample/sample.kjsm" + "$PROJECT_NAME/root-package.kjsm" ) private val EXPECTED_JS_FILES_IN_OUTPUT_WITH_ADDITIONAL_LIB_AND_CUSTOM_DIR = hashSetOf( "$PROJECT_NAME.js", @@ -121,13 +120,13 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { "custom/kotlin.js", "custom/kotlin.meta.js", "custom/jslib-example.js", + "custom/jslib-example.meta.js", "custom/file0.js", "custom/dir/file1.js", "custom/META-INF-ex/file2.js", "custom/res0.js", "custom/resdir/res1.js", - "$PROJECT_NAME/root-package.kjsm", - "$PROJECT_NAME/library/sample/sample.kjsm" + "$PROJECT_NAME/root-package.kjsm" ) private fun k2jsOutput(vararg moduleNames: String): Array { diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/META-INF/MANIFEST.MF b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/META-INF/MANIFEST.MF index 00281ee90c5..5d1ec1e9192 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/META-INF/MANIFEST.MF +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/META-INF/MANIFEST.MF @@ -5,5 +5,4 @@ Built-By: JetBrains Implementation-Vendor: JetBrains Implementation-Version: snapshot Specification-Title: Kotlin JavaScript Lib -Kotlin-JS-Module-Name: jslib-example diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/ReadMe.md b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/ReadMe.md index 6c269930b08..9e82278e756 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/ReadMe.md +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/ReadMe.md @@ -1,6 +1,6 @@ # jslib-example -Path to sources: compiler/integration-tests/testData/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example +Path to sources: `compiler/testData/cli/js/jslib` The archive compiler/integration-tests/testData/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar should be updated after changing some files in source folder. \ No newline at end of file diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example.js b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example.js index 8fb2ce81d48..68154be1e35 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example.js +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example.js @@ -1,37 +1,44 @@ -(function (Kotlin) { +if (typeof kotlin === 'undefined') { + throw new Error("Error loading module 'LibraryExample'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'LibraryExample'."); +} +var LibraryExample = function (_, Kotlin) { 'use strict'; - var _ = Kotlin.defineRootPackage(null, /** @lends _ */ { - library: Kotlin.definePackage(null, /** @lends _.library */ { - sample: Kotlin.definePackage(null, /** @lends _.library.sample */ { - pairAdd_bunuun$: function (p) { - return p.first + p.second; - }, - pairMul_bunuun$: function (p) { - return p.first * p.second; - }, - IntHolder: Kotlin.createClass(null, function (value) { - this.value = value; - }, /** @lends _.library.sample.IntHolder.prototype */ { - component1: function () { - return this.value; - }, - copy_za3lpa$: function (value) { - return new _.library.sample.IntHolder(value === void 0 ? this.value : value); - }, - toString: function () { - return 'IntHolder(value=' + Kotlin.toString(this.value) + ')'; - }, - hashCode: function () { - var result = 0; - result = result * 31 + Kotlin.hashCode(this.value) | 0; - return result; - }, - equals_za3rmp$: function (other) { - return this === other || (other !== null && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value))); - } - }) - }) - }) - }); - Kotlin.defineModule('jslib-example', _); -}(Kotlin)); + function pairAdd(p) { + return p.first + p.second | 0; + } + function pairMul(p) { + return Kotlin.imul(p.first, p.second); + } + function IntHolder(value) { + this.value = value; + } + IntHolder.$metadata$ = { + kind: Kotlin.Kind.CLASS, + simpleName: 'IntHolder', + interfaces: [] + }; + IntHolder.prototype.component1 = function () { + return this.value; + }; + IntHolder.prototype.copy_za3lpa$ = function (value) { + return new IntHolder(value === void 0 ? this.value : value); + }; + IntHolder.prototype.toString = function () { + return 'IntHolder(value=' + Kotlin.toString(this.value) + ')'; + }; + IntHolder.prototype.hashCode = function () { + var result = 0; + result = result * 31 + Kotlin.hashCode(this.value) | 0; + return result; + }; + IntHolder.prototype.equals = function (other) { + return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value)))); + }; + var package$library = _.library || (_.library = {}); + var package$sample = package$library.sample || (package$library.sample = {}); + package$sample.pairAdd_1fzo63$ = pairAdd; + package$sample.pairMul_1fzo63$ = pairMul; + package$sample.IntHolder = IntHolder; + Kotlin.defineModule('LibraryExample', _); + return _; +}(typeof LibraryExample === 'undefined' ? {} : LibraryExample, kotlin); diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example.meta.js b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example.meta.js new file mode 100644 index 00000000000..5dd2ffc566e --- /dev/null +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example.meta.js @@ -0,0 +1 @@ +// Kotlin.kotlin_module_metadata(1, "LibraryExample", "H4sIAAAAAAAAAJVW227TQBB1fF1Pb64LJTUgRBEgbiWkCIEESC19KJWQgIoPcJ1tsqmzG9ZO0v4Ar0h9QP2UfAGf0N+BcS5O0tRu6gfvaHdmzlzOjq2490FxFa94Rv4Nn0LXHsmnRHE9sMD49oOz2NVBdRTPPCNK11aSs4cwD+aRiEPGQWXChUQBdKI4hUQNffVcvIabqZol6WFIgxjUeuQ6I318Fxw1sVK7tjp0rtf9tg96K2ZhlvOXsJo6n6fHTSpZg/LYzzToBV3/2aLyBNQWy1J7BzdAE7IKWmczAK0iGqAFUeSuXowZ36qjJaZa19YS0yfgpCGZ0udVGmWh7MNGqgqBkAJT5TSazASA8VgyHrFgJvwNWBoP/bgm8yv9CBbSIJJEr1OSlgxnCakIRs90mkO3gQzbMX34AGCEmBXWxhi95gLRaPqSRYJn1vw5rKT6dkQRmgfZHXqBSacdakqBbYlZtvqFYMKE6ywnmAn3IwLkXaVeQayjmhRcRGB06EE1zG/wZY2L2tVZGvcebl00NWkbaTkTEycGRD0zqx4H+mrTHNgcq1AP3zhosbCSn/FTWJ4aOVnobyZSnMMGHwrZ8JEU+RjPwE0xCN5QKnn21NmC9asvej7ebw3+FMAK2YH0cXaZkd9ohhTszzzeFWGFylGZtvgJGG0/bFHQ8DhBbDQFR5BXoAeiidbIez+MwNoWIqQ+B0PENXRBan5U+yQqFEgs9pOpUwVzsFpNn8mtSgUKTdC/otzf+dIK3Y9jgZtJ4EUFdzSUNUdHOVnNwQqDdXGwLhcVb8e76yx5askou47jLbq6i3L/XSJdouCxm3Pcr/M6I79IUS2rJX2buKZjJBZ7tmMl6+5fbW/FISiqZYI8NfqbBdy0UTTLxJnz9GKhpO+ea2g03zs/L6C4gKKF4veBSwQ8JSpMDdpkdM7OygMpOhGVWYR5C2tjvhe4iNkhC/z+MMlFKSHKyNI4pHFQy7d4DIuTUyUrqERxmIAe0+PMOzXxSam3Mz8pd8BOGT199T9A8eLwQcbJCMk4y/Qp46AfmVsdIY+ovGbxWEivsFgDs/+fMh3/Dty79MdnbFzMkMbEJ8LnyIQeCzJK6g1U/wOSAB0W3QkAAA=="); diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example/library/sample/sample.kjsm b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/jslib-example/jslib-example/library/sample/sample.kjsm new file mode 100644 index 0000000000000000000000000000000000000000..f53578c8ac0ac1a628c156f0bcb52b8f6bd937d9 GIT binary patch literal 432 zcmaKnK~BRk5JhdraV7&46E;yKHXHzj8~~}nB2+>`a01g-`F7!4Mx!HXZ7zVxoL9jbTV zySl+(+^jJCG;V1zpcrxL=dEvS(_f>U`gVoNek_e!V07!fv!=n&_cIy+Gqaf8`N|^n z{-y8g<_*=LQETdMTvf literal 0 HcmV?d00001 diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/TopDownAnalyzerFacadeForJS.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/TopDownAnalyzerFacadeForJS.kt index 6087e633435..4acfa24a442 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/TopDownAnalyzerFacadeForJS.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/TopDownAnalyzerFacadeForJS.kt @@ -54,10 +54,9 @@ object TopDownAnalyzerFacadeForJS { moduleContext: ModuleContext, config: JsConfig ): JsAnalysisResult { - val allFiles = JsConfig.withJsLibAdded(files, config) val analyzerForJs = createTopDownAnalyzerForJs( moduleContext, trace, - FileBasedDeclarationProviderFactory(moduleContext.storageManager, allFiles), + FileBasedDeclarationProviderFactory(moduleContext.storageManager, files), config.configuration.get(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS, LanguageVersionSettingsImpl.DEFAULT) ) analyzerForJs.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, files) diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/suppressWarnings.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/suppressWarnings.kt index 6db3f86e5ef..fb35b0bfd07 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/suppressWarnings.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/suppressWarnings.kt @@ -20,11 +20,8 @@ import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters1 import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.js.PredefinedAnnotation.* -import org.jetbrains.kotlin.js.config.LibrarySourcesConfig import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils -import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtSimpleNameExpression import org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor import org.jetbrains.kotlin.resolve.diagnostics.FUNCTION_NO_BODY_ERRORS @@ -50,10 +47,3 @@ class SuppressUninitializedErrorsForNativeDeclarations : DiagnosticSuppressor { } } -class SuppressWarningsFromExternalModules : DiagnosticSuppressor { - override fun isSuppressed(diagnostic: Diagnostic): Boolean { - val file = diagnostic.psiFile - return diagnostic.severity == Severity.WARNING && - file is KtFile && file.getUserData(LibrarySourcesConfig.EXTERNAL_MODULE_NAME) != null - } -} 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 719c4ed8300..c589a24e162 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 @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.js.config; -import com.google.common.collect.Lists; import com.intellij.openapi.project.Project; import com.intellij.util.SmartList; import kotlin.collections.CollectionsKt; @@ -29,7 +28,6 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider; import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl; import org.jetbrains.kotlin.js.resolve.JsPlatform; import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.psi.KtFile; import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration; import org.jetbrains.kotlin.serialization.js.JsModuleDescriptor; import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil; @@ -39,7 +37,6 @@ import org.jetbrains.kotlin.utils.JsMetadataVersion; import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; @@ -50,7 +47,6 @@ public abstract class JsConfig { private final Project project; private final CompilerConfiguration configuration; private final LockBasedStorageManager storageManager = new LockBasedStorageManager(); - private final List sourceFilesFromLibraries = new SmartList(); @NotNull protected final List metadata = new SmartList(); @@ -92,7 +88,7 @@ public abstract class JsConfig { public abstract boolean checkLibFilesAndReportErrors(@NotNull Reporter report); - protected abstract void init(@NotNull List sourceFilesInLibraries, @NotNull List metadata); + protected abstract void init(@NotNull List metadata); @NotNull public List> getModuleDescriptors() { @@ -117,16 +113,10 @@ public abstract class JsConfig { return moduleDescriptors; } - @NotNull - private List getSourceFilesFromLibraries() { - init(); - return sourceFilesFromLibraries; - } - private void init() { if (initialized) return; - init(sourceFilesFromLibraries, metadata); + init(metadata); initialized = true; } @@ -153,12 +143,4 @@ public abstract class JsConfig { private static void setDependencies(ModuleDescriptorImpl module, List modules) { module.setDependencies(CollectionsKt.plus(modules, JsPlatform.INSTANCE.getBuiltIns().getBuiltInsModule())); } - - @NotNull - public static Collection withJsLibAdded(@NotNull Collection files, @NotNull JsConfig config) { - Collection allFiles = Lists.newArrayList(); - allFiles.addAll(files); - allFiles.addAll(config.getSourceFilesFromLibraries()); - return allFiles; - } } diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/config/LibrarySourcesConfig.java b/js/js.frontend/src/org/jetbrains/kotlin/js/config/LibrarySourcesConfig.java index 275fe45ad38..67863f338cd 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/config/LibrarySourcesConfig.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/config/LibrarySourcesConfig.java @@ -17,24 +17,20 @@ package org.jetbrains.kotlin.js.config; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.*; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; +import com.intellij.openapi.vfs.StandardFileSystems; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.util.PathUtil; import com.intellij.util.io.URLUtil; import kotlin.Unit; -import kotlin.jvm.functions.Function2; +import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.config.CompilerConfiguration; -import org.jetbrains.kotlin.idea.KotlinFileType; -import org.jetbrains.kotlin.psi.KtFile; import org.jetbrains.kotlin.utils.JsMetadataVersion; import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata; import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils; -import org.jetbrains.kotlin.utils.LibraryUtils; import java.io.File; import java.util.Collections; @@ -42,7 +38,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import static org.jetbrains.kotlin.utils.LibraryUtils.isOldKotlinJavascriptLibrary; import static org.jetbrains.kotlin.utils.PathUtil.getKotlinPathsForDistDirectory; public class LibrarySourcesConfig extends JsConfig { @@ -52,7 +47,6 @@ public class LibrarySourcesConfig extends JsConfig { public static final List JS_KOTLIN_TEST = Collections.singletonList(getKotlinPathsForDistDirectory().getJsKotlinTestJarPath().getAbsolutePath()); - public static final Key EXTERNAL_MODULE_NAME = Key.create("externalModule"); public static final String UNKNOWN_EXTERNAL_MODULE_NAME = ""; public LibrarySourcesConfig(@NotNull Project project, @NotNull CompilerConfiguration configuration) { @@ -65,11 +59,9 @@ public class LibrarySourcesConfig extends JsConfig { } @Override - protected void init(@NotNull final List sourceFilesInLibraries, @NotNull final List metadata) { + protected void init(@NotNull final List metadata) { if (getLibraries().isEmpty()) return; - final PsiManager psiManager = PsiManager.getInstance(getProject()); - JsConfig.Reporter report = new JsConfig.Reporter() { @Override public void error(@NotNull String message) { @@ -77,18 +69,12 @@ public class LibrarySourcesConfig extends JsConfig { } }; - Function2 action = new Function2() { + Function1 action = new Function1() { @Override - public Unit invoke(String moduleName, VirtualFile file) { - if (moduleName != null) { - JetFileCollector jetFileCollector = new JetFileCollector(sourceFilesInLibraries, moduleName, psiManager); - VfsUtilCore.visitChildrenRecursively(file, jetFileCollector); - } - else { - String libraryPath = PathUtil.getLocalPath(file); - assert libraryPath != null : "libraryPath for " + file + " should not be null"; - metadata.addAll(KotlinJavascriptMetadataUtils.loadMetadata(libraryPath)); - } + public Unit invoke(VirtualFile file) { + String libraryPath = PathUtil.getLocalPath(file); + assert libraryPath != null : "libraryPath for " + file + " should not be null"; + metadata.addAll(KotlinJavascriptMetadataUtils.loadMetadata(libraryPath)); return Unit.INSTANCE; } @@ -103,7 +89,7 @@ public class LibrarySourcesConfig extends JsConfig { return checkLibFilesAndReportErrors(report, null); } - private boolean checkLibFilesAndReportErrors(@NotNull JsConfig.Reporter report, @Nullable Function2 action) { + private boolean checkLibFilesAndReportErrors(@NotNull JsConfig.Reporter report, @Nullable Function1 action) { List libraries = getLibraries(); if (libraries.isEmpty()) { return false; @@ -135,73 +121,28 @@ public class LibrarySourcesConfig extends JsConfig { return true; } - String moduleName; - - if (isOldKotlinJavascriptLibrary(filePath)) { - moduleName = LibraryUtils.getKotlinJsModuleName(filePath); - if (!modules.add(moduleName)) { - report.warning("Module \"" + moduleName + "\" is defined in more, than one file"); - } + List metadataList = KotlinJavascriptMetadataUtils.loadMetadata(filePath); + if (metadataList.isEmpty()) { + report.warning("'" + path + "' is not a valid Kotlin Javascript library"); + continue; } - else { - List metadataList = KotlinJavascriptMetadataUtils.loadMetadata(filePath); - if (metadataList.isEmpty()) { - report.warning("'" + path + "' is not a valid Kotlin Javascript library"); - continue; - } - for (KotlinJavascriptMetadata metadata : metadataList) { - if (!metadata.getVersion().isCompatible()) { - report.error("File '" + path + "' was compiled with an incompatible version of Kotlin. " + - "The binary version of its metadata is " + metadata.getVersion() + - ", expected version is " + JsMetadataVersion.INSTANCE); - return true; - } - if (!modules.add(metadata.getModuleName())) { + for (KotlinJavascriptMetadata metadata : metadataList) { + if (!metadata.getVersion().isCompatible()) { + report.error("File '" + path + "' was compiled with an incompatible version of Kotlin. " + + "The binary version of its metadata is " + metadata.getVersion() + + ", expected version is " + JsMetadataVersion.INSTANCE); + return true; + } + if (!modules.add(metadata.getModuleName())) { report.warning("Module \"" + metadata.getModuleName() + "\" is defined in more, than one file"); - } - } - - moduleName = null; - } + }} if (action != null) { - action.invoke(moduleName, file); + action.invoke(file); } } return false; } - - private static KtFile getJetFileByVirtualFile(VirtualFile file, String moduleName, PsiManager psiManager) { - PsiFile psiFile = psiManager.findFile(file); - assert psiFile != null; - - setupPsiFile(psiFile, moduleName); - return (KtFile) psiFile; - } - - private static void setupPsiFile(PsiFile psiFile, String moduleName) { - psiFile.putUserData(EXTERNAL_MODULE_NAME, moduleName); - } - - private static class JetFileCollector extends VirtualFileVisitor { - private final List jetFiles; - private final String moduleName; - private final PsiManager psiManager; - - private JetFileCollector(List files, String name, PsiManager manager) { - moduleName = name; - psiManager = manager; - jetFiles = files; - } - - @Override - public boolean visitFile(@NotNull VirtualFile file) { - if (!file.isDirectory() && StringUtil.notNullize(file.getExtension()).equalsIgnoreCase(KotlinFileType.EXTENSION)) { - jetFiles.add(getJetFileByVirtualFile(file, moduleName, psiManager)); - } - return true; - } - } } diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt index eed02593bff..cf96d89d637 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.js.translate.context.Namer import org.jetbrains.kotlin.js.translate.context.TranslationContext import org.jetbrains.kotlin.js.translate.reference.CallExpressionTranslator import org.jetbrains.kotlin.js.translate.utils.JsAstUtils -import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils.getExternalModuleName +import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils.getModuleName import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension import org.jetbrains.kotlin.resolve.inline.InlineStrategy import org.jetbrains.kotlin.utils.JsLibraryUtils @@ -68,7 +68,7 @@ class FunctionReader(private val context: TranslationContext) { val config = context.config as LibrarySourcesConfig val libs = config.libraries.map { File(it) } - JsLibraryUtils.traverseJsLibraries(libs) { fileContent, path -> + JsLibraryUtils.traverseJsLibraries(libs) { fileContent, _ -> var current = 0 while (true) { @@ -113,9 +113,9 @@ class FunctionReader(private val context: TranslationContext) { } operator fun contains(descriptor: CallableDescriptor): Boolean { - val moduleName = getExternalModuleName(descriptor) + val moduleName = getModuleName(descriptor) val currentModuleName = context.config.moduleId - return currentModuleName != moduleName && moduleName != null && moduleName in moduleNameToInfo.keys() + return currentModuleName != moduleName && moduleName in moduleNameToInfo.keys() } operator fun get(descriptor: CallableDescriptor): JsFunction = functionCache.get(descriptor) @@ -123,7 +123,7 @@ class FunctionReader(private val context: TranslationContext) { private fun readFunction(descriptor: CallableDescriptor): JsFunction? { if (descriptor !in this) return null - val moduleName = getExternalModuleName(descriptor) + val moduleName = getModuleName(descriptor) for (info in moduleNameToInfo[moduleName]) { val function = readFunctionFromSource(descriptor, info) 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 734257fa687..89e7a8af8e1 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/integration/AntTaskJsTest.java @@ -104,14 +104,6 @@ public class AntTaskJsTest extends AbstractAntTaskTest { doJsAntTest(); } - public void testSimpleWithStdlibAndAnotherLib() throws Exception { - doJsAntTest("jslib-example.js"); - } - - public void testSimpleWithStdlibAndFolderAsAnotherLib() throws Exception { - doJsAntTest("jslib-example.js"); - } - public void testSimpleWithoutStdlibAndFolderAsAnotherLib() throws Exception { doJsAntTest("jslib-example.js"); } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/facade/K2JSTranslator.java b/js/js.translator/src/org/jetbrains/kotlin/js/facade/K2JSTranslator.java index 6b65486a71d..12db6706966 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/facade/K2JSTranslator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/facade/K2JSTranslator.java @@ -74,7 +74,7 @@ public final class K2JSTranslator { } BindingTrace bindingTrace = analysisResult.getBindingTrace(); - TopDownAnalyzerFacadeForJS.checkForErrors(JsConfig.withJsLibAdded(files, config), bindingTrace.getBindingContext()); + TopDownAnalyzerFacadeForJS.checkForErrors(files, bindingTrace.getBindingContext()); ModuleDescriptor moduleDescriptor = analysisResult.getModuleDescriptor(); Diagnostics diagnostics = bindingTrace.getBindingContext().getDiagnostics(); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsDescriptorUtils.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsDescriptorUtils.java index 2dffc92a900..987d660f8ef 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsDescriptorUtils.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsDescriptorUtils.java @@ -17,15 +17,12 @@ package org.jetbrains.kotlin.js.translate.utils; import com.intellij.openapi.util.Condition; -import com.intellij.psi.PsiElement; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.*; -import org.jetbrains.kotlin.js.config.LibrarySourcesConfig; import org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt; -import org.jetbrains.kotlin.js.translate.context.Namer; import org.jetbrains.kotlin.js.translate.context.TranslationContext; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.KtExpression; @@ -42,7 +39,6 @@ import java.util.List; import java.util.Set; import static org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.isNativeObject; -import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration; import static org.jetbrains.kotlin.resolve.DescriptorUtils.*; public final class JsDescriptorUtils { @@ -164,24 +160,9 @@ public final class JsDescriptorUtils { @NotNull public static String getModuleName(@NotNull DeclarationDescriptor descriptor) { - String externalModuleName = getExternalModuleName(descriptor); - if (externalModuleName != null) return externalModuleName; - - return getModuleNameFromDescriptorName(descriptor); - } - - @Nullable - public static String getExternalModuleName(@NotNull DeclarationDescriptor descriptor) { - if (KotlinBuiltIns.isBuiltIn(descriptor)) return Namer.KOTLIN_LOWER_NAME; - - PsiElement element = descriptorToDeclaration(descriptor); - if (element == null && descriptor instanceof PropertyAccessorDescriptor) { - element = descriptorToDeclaration(((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty()); - } - - if (element == null) return getModuleNameFromDescriptorName(descriptor); - - return element.getContainingFile().getUserData(LibrarySourcesConfig.EXTERNAL_MODULE_NAME); + ModuleDescriptor moduleDescriptor = DescriptorUtils.getContainingModule(findRealInlineDeclaration(descriptor)); + String moduleName = moduleDescriptor.getName().asString(); + return moduleName.substring(1, moduleName.length() - 1); } @NotNull @@ -210,13 +191,6 @@ public final class JsDescriptorUtils { return null; } - private static String getModuleNameFromDescriptorName(@NotNull DeclarationDescriptor descriptor) { - ModuleDescriptor moduleDescriptor = DescriptorUtils.getContainingModule(findRealInlineDeclaration(descriptor)); - String moduleName = moduleDescriptor.getName().asString(); - return moduleName.substring(1, moduleName.length() - 1); - } - - public static boolean isImmediateSubtypeOfError(@NotNull ClassDescriptor descriptor) { if (!isExceptionClass(descriptor)) return false; ClassDescriptor superClass = org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getSuperClassOrAny(descriptor); diff --git a/resources/kotlinManifest.properties b/resources/kotlinManifest.properties index 823e385dc69..43fa48034bf 100644 --- a/resources/kotlinManifest.properties +++ b/resources/kotlinManifest.properties @@ -21,7 +21,6 @@ manifest.impl.title.kotlin.jvm.reflect.sources=Kotlin Reflect Sources manifest.impl.title.kotlin.script.runtime.sources=Kotlin Script Runtime Sources manifest.impl.title.kotlin.javascript.stdlib=Kotlin JavaScript StdLib -manifest.spec.title.kotlin.javascript.lib=Kotlin JavaScript Lib manifest.impl.title.kotlin.preloader=Kotlin Preloader