JS: drop support of old library format
This commit is contained in:
@@ -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);
|
||||||
@@ -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==");
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
|||||||
|
# jslib
|
||||||
|
|
||||||
|
Path to sources: `compiler/testData/cli/js/jslib`
|
||||||
|
|
||||||
|
`folderAsLib/LibraryExample.js`, `folderAsLib/LibraryExample.meta.js` and `LibraryExample.jar` should be updated after changing some files in source folder.
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
$TESTDATA_DIR$/withLib.kt
|
$TESTDATA_DIR$/withLib.kt
|
||||||
-libraries
|
-libraries
|
||||||
compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib
|
compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLib
|
||||||
-output
|
-output
|
||||||
$TEMP_DIR$/out.js
|
$TEMP_DIR$/out.js
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
warning: 'compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib' is not a valid Kotlin Javascript library
|
warning: 'compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLib' is not a valid Kotlin Javascript library
|
||||||
compiler/testData/cli/js/withLib.kt:2:8: error: unresolved reference: library
|
compiler/testData/cli/js/withLib.kt:2:8: error: unresolved reference: library
|
||||||
import library.sample.*
|
import library.sample.*
|
||||||
^
|
^
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
$TESTDATA_DIR$/withLib.kt
|
$TESTDATA_DIR$/withLib.kt
|
||||||
-libraries
|
-libraries
|
||||||
compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example
|
$TESTDATA_DIR$/folderAsLib
|
||||||
-output
|
-output
|
||||||
$TEMP_DIR$/out.js
|
$TEMP_DIR$/out.js
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
$TESTDATA_DIR$/withLib.kt
|
$TESTDATA_DIR$/withLib.kt
|
||||||
-libraries
|
-libraries
|
||||||
compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar
|
$TESTDATA_DIR$/lib/LibraryExample.jar
|
||||||
-output
|
-output
|
||||||
$TEMP_DIR$/out.js
|
$TEMP_DIR$/out.js
|
||||||
|
|||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
OUT:
|
|
||||||
Buildfile: [TestData]/build.xml
|
|
||||||
|
|
||||||
build:
|
|
||||||
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
|
|
||||||
[unzip] Expanding: [TestData]/jslib-example.jar into [Temp]
|
|
||||||
|
|
||||||
BUILD SUCCESSFUL
|
|
||||||
Total time: [time]
|
|
||||||
|
|
||||||
Return code: 0
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<project name="Ant Task Test" default="build">
|
|
||||||
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
|
||||||
<property name="library.path" value="${test.data}/jslib-example.jar"/>
|
|
||||||
<target name="build">
|
|
||||||
<kotlin2js src="${test.data}/root1" output="${temp}/out.js" main="call">
|
|
||||||
<libraries>
|
|
||||||
<pathelement path="${library.path}"/>
|
|
||||||
</libraries>
|
|
||||||
</kotlin2js>
|
|
||||||
<unzip src="${library.path}" dest="${temp}">
|
|
||||||
<patternset>
|
|
||||||
<include name="*.js"/>
|
|
||||||
<exclude name="META-INF/**"/>
|
|
||||||
</patternset>
|
|
||||||
</unzip>
|
|
||||||
</target>
|
|
||||||
</project>
|
|
||||||
BIN
Binary file not shown.
-14
@@ -1,14 +0,0 @@
|
|||||||
package foo
|
|
||||||
|
|
||||||
import library.sample.*
|
|
||||||
|
|
||||||
var ok = "FAIL"
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
val p = Pair(10, 20)
|
|
||||||
val x = pairAdd(p)
|
|
||||||
ok = "OK"
|
|
||||||
println("x=$x")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String = ok
|
|
||||||
Vendored
-11
@@ -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
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
<project name="Ant Task Test" default="build">
|
|
||||||
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
|
||||||
<property name="library.path" value="${test.data}/jslib-example"/>
|
|
||||||
<target name="build">
|
|
||||||
<kotlin2js src="${test.data}/root1" output="${temp}/out.js" main="call">
|
|
||||||
<libraries>
|
|
||||||
<pathelement path="${library.path}"/>
|
|
||||||
</libraries>
|
|
||||||
</kotlin2js>
|
|
||||||
<copy todir="${temp}">
|
|
||||||
<fileset dir="${library.path}">
|
|
||||||
<include name="**/*.js"/>
|
|
||||||
<exclude name="META-INF/**"/>
|
|
||||||
</fileset>
|
|
||||||
</copy>
|
|
||||||
</target>
|
|
||||||
</project>
|
|
||||||
-9
@@ -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
|
|
||||||
|
|
||||||
Vendored
-6
@@ -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.
|
|
||||||
-38
@@ -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);
|
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
package foo
|
|
||||||
|
|
||||||
import library.sample.*
|
|
||||||
|
|
||||||
var ok = "FAIL"
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
val p = Pair(10, 20)
|
|
||||||
val x = pairAdd(p)
|
|
||||||
ok = "OK"
|
|
||||||
println("x=$x")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String = ok
|
|
||||||
@@ -27,17 +27,13 @@ import java.util.jar.Manifest
|
|||||||
object LibraryUtils {
|
object LibraryUtils {
|
||||||
private val LOG = Logger.getInstance(LibraryUtils::class.java)
|
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_STDLIB: String
|
||||||
private var TITLE_KOTLIN_JAVASCRIPT_LIB: String
|
|
||||||
|
|
||||||
val META_INF = "META-INF/"
|
val META_INF = "META-INF/"
|
||||||
private val MANIFEST_PATH = "${META_INF}MANIFEST.MF"
|
private val MANIFEST_PATH = "${META_INF}MANIFEST.MF"
|
||||||
private val KOTLIN_JS_MODULE_ATTRIBUTE_NAME = Attributes.Name(KOTLIN_JS_MODULE_NAME)
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
var jsStdLib = ""
|
var jsStdLib = ""
|
||||||
var jsLib = ""
|
|
||||||
|
|
||||||
val manifestProperties = LibraryUtils::class.java.getResourceAsStream("/kotlinManifest.properties")
|
val manifestProperties = LibraryUtils::class.java.getResourceAsStream("/kotlinManifest.properties")
|
||||||
if (manifestProperties != null) {
|
if (manifestProperties != null) {
|
||||||
@@ -45,7 +41,6 @@ object LibraryUtils {
|
|||||||
val properties = Properties()
|
val properties = Properties()
|
||||||
properties.load(manifestProperties)
|
properties.load(manifestProperties)
|
||||||
jsStdLib = properties.getPropertyOrFail("manifest.impl.title.kotlin.javascript.stdlib")
|
jsStdLib = properties.getPropertyOrFail("manifest.impl.title.kotlin.javascript.stdlib")
|
||||||
jsLib = properties.getPropertyOrFail("manifest.spec.title.kotlin.javascript.lib")
|
|
||||||
}
|
}
|
||||||
catch (e: IOException) {
|
catch (e: IOException) {
|
||||||
LOG.error(e)
|
LOG.error(e)
|
||||||
@@ -57,27 +52,14 @@ object LibraryUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TITLE_KOTLIN_JAVASCRIPT_STDLIB = jsStdLib
|
TITLE_KOTLIN_JAVASCRIPT_STDLIB = jsStdLib
|
||||||
TITLE_KOTLIN_JAVASCRIPT_LIB = jsLib
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic fun getJarFile(classesRoots: List<VirtualFile>, jarName: String): VirtualFile? {
|
@JvmStatic fun getJarFile(classesRoots: List<VirtualFile>, jarName: String): VirtualFile? {
|
||||||
return classesRoots.firstOrNull { it.name == jarName }
|
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
|
@Suppress("unused") // used in K2JSCompilerMojo
|
||||||
@JvmStatic fun isKotlinJavascriptLibrary(library: File): Boolean =
|
@JvmStatic fun isKotlinJavascriptLibrary(library: File): Boolean = KotlinJavascriptMetadataUtils.loadMetadata(library).isNotEmpty()
|
||||||
isOldKotlinJavascriptLibrary(library) || isKotlinJavascriptLibraryWithMetadata(library)
|
|
||||||
|
|
||||||
@JvmStatic fun isKotlinJavascriptStdLibrary(library: File): Boolean {
|
@JvmStatic fun isKotlinJavascriptStdLibrary(library: File): Boolean {
|
||||||
return checkAttributeValue(library, TITLE_KOTLIN_JAVASCRIPT_STDLIB, Attributes.Name.IMPLEMENTATION_TITLE)
|
return checkAttributeValue(library, TITLE_KOTLIN_JAVASCRIPT_STDLIB, Attributes.Name.IMPLEMENTATION_TITLE)
|
||||||
|
|||||||
@@ -8,6 +8,5 @@
|
|||||||
<suppressStringProvider implementation="org.jetbrains.kotlin.js.analyze.SuppressUnusedParameterForJsNative"/>
|
<suppressStringProvider implementation="org.jetbrains.kotlin.js.analyze.SuppressUnusedParameterForJsNative"/>
|
||||||
<suppressStringProvider implementation="org.jetbrains.kotlin.js.analyze.SuppressNoBodyErrorsForNativeDeclarations"/>
|
<suppressStringProvider implementation="org.jetbrains.kotlin.js.analyze.SuppressNoBodyErrorsForNativeDeclarations"/>
|
||||||
<diagnosticSuppressor implementation="org.jetbrains.kotlin.js.analyze.SuppressUninitializedErrorsForNativeDeclarations"/>
|
<diagnosticSuppressor implementation="org.jetbrains.kotlin.js.analyze.SuppressUninitializedErrorsForNativeDeclarations"/>
|
||||||
<diagnosticSuppressor implementation="org.jetbrains.kotlin.js.analyze.SuppressWarningsFromExternalModules"/>
|
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
private val EXPECTED_JS_FILES_IN_OUTPUT_NO_COPY = hashSetOf(
|
private val EXPECTED_JS_FILES_IN_OUTPUT_NO_COPY = hashSetOf(
|
||||||
"$PROJECT_NAME.js",
|
"$PROJECT_NAME.js",
|
||||||
"$PROJECT_NAME.meta.js",
|
"$PROJECT_NAME.meta.js",
|
||||||
"$PROJECT_NAME/root-package.kjsm",
|
"$PROJECT_NAME/root-package.kjsm"
|
||||||
"$PROJECT_NAME/library/sample/sample.kjsm"
|
|
||||||
)
|
)
|
||||||
private val EXPECTED_JS_FILES_IN_OUTPUT_WITH_ADDITIONAL_LIB_AND_DEFAULT_DIR = hashSetOf(
|
private val EXPECTED_JS_FILES_IN_OUTPUT_WITH_ADDITIONAL_LIB_AND_DEFAULT_DIR = hashSetOf(
|
||||||
"$PROJECT_NAME.js",
|
"$PROJECT_NAME.js",
|
||||||
@@ -107,13 +106,13 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
"lib/kotlin.js",
|
"lib/kotlin.js",
|
||||||
"lib/kotlin.meta.js",
|
"lib/kotlin.meta.js",
|
||||||
"lib/jslib-example.js",
|
"lib/jslib-example.js",
|
||||||
|
"lib/jslib-example.meta.js",
|
||||||
"lib/file0.js",
|
"lib/file0.js",
|
||||||
"lib/dir/file1.js",
|
"lib/dir/file1.js",
|
||||||
"lib/META-INF-ex/file2.js",
|
"lib/META-INF-ex/file2.js",
|
||||||
"lib/res0.js",
|
"lib/res0.js",
|
||||||
"lib/resdir/res1.js",
|
"lib/resdir/res1.js",
|
||||||
"$PROJECT_NAME/root-package.kjsm",
|
"$PROJECT_NAME/root-package.kjsm"
|
||||||
"$PROJECT_NAME/library/sample/sample.kjsm"
|
|
||||||
)
|
)
|
||||||
private val EXPECTED_JS_FILES_IN_OUTPUT_WITH_ADDITIONAL_LIB_AND_CUSTOM_DIR = hashSetOf(
|
private val EXPECTED_JS_FILES_IN_OUTPUT_WITH_ADDITIONAL_LIB_AND_CUSTOM_DIR = hashSetOf(
|
||||||
"$PROJECT_NAME.js",
|
"$PROJECT_NAME.js",
|
||||||
@@ -121,13 +120,13 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
"custom/kotlin.js",
|
"custom/kotlin.js",
|
||||||
"custom/kotlin.meta.js",
|
"custom/kotlin.meta.js",
|
||||||
"custom/jslib-example.js",
|
"custom/jslib-example.js",
|
||||||
|
"custom/jslib-example.meta.js",
|
||||||
"custom/file0.js",
|
"custom/file0.js",
|
||||||
"custom/dir/file1.js",
|
"custom/dir/file1.js",
|
||||||
"custom/META-INF-ex/file2.js",
|
"custom/META-INF-ex/file2.js",
|
||||||
"custom/res0.js",
|
"custom/res0.js",
|
||||||
"custom/resdir/res1.js",
|
"custom/resdir/res1.js",
|
||||||
"$PROJECT_NAME/root-package.kjsm",
|
"$PROJECT_NAME/root-package.kjsm"
|
||||||
"$PROJECT_NAME/library/sample/sample.kjsm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun k2jsOutput(vararg moduleNames: String): Array<String> {
|
private fun k2jsOutput(vararg moduleNames: String): Array<String> {
|
||||||
|
|||||||
-1
@@ -5,5 +5,4 @@ Built-By: JetBrains
|
|||||||
Implementation-Vendor: JetBrains
|
Implementation-Vendor: JetBrains
|
||||||
Implementation-Version: snapshot
|
Implementation-Version: snapshot
|
||||||
Specification-Title: Kotlin JavaScript Lib
|
Specification-Title: Kotlin JavaScript Lib
|
||||||
Kotlin-JS-Module-Name: jslib-example
|
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
# jslib-example
|
# 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
|
The archive compiler/integration-tests/testData/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar should be updated after
|
||||||
changing some files in source folder.
|
changing some files in source folder.
|
||||||
+43
-36
@@ -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';
|
'use strict';
|
||||||
var _ = Kotlin.defineRootPackage(null, /** @lends _ */ {
|
function pairAdd(p) {
|
||||||
library: Kotlin.definePackage(null, /** @lends _.library */ {
|
return p.first + p.second | 0;
|
||||||
sample: Kotlin.definePackage(null, /** @lends _.library.sample */ {
|
}
|
||||||
pairAdd_bunuun$: function (p) {
|
function pairMul(p) {
|
||||||
return p.first + p.second;
|
return Kotlin.imul(p.first, p.second);
|
||||||
},
|
}
|
||||||
pairMul_bunuun$: function (p) {
|
function IntHolder(value) {
|
||||||
return p.first * p.second;
|
this.value = value;
|
||||||
},
|
}
|
||||||
IntHolder: Kotlin.createClass(null, function (value) {
|
IntHolder.$metadata$ = {
|
||||||
this.value = value;
|
kind: Kotlin.Kind.CLASS,
|
||||||
}, /** @lends _.library.sample.IntHolder.prototype */ {
|
simpleName: 'IntHolder',
|
||||||
component1: function () {
|
interfaces: []
|
||||||
return this.value;
|
};
|
||||||
},
|
IntHolder.prototype.component1 = function () {
|
||||||
copy_za3lpa$: function (value) {
|
return this.value;
|
||||||
return new _.library.sample.IntHolder(value === void 0 ? this.value : value);
|
};
|
||||||
},
|
IntHolder.prototype.copy_za3lpa$ = function (value) {
|
||||||
toString: function () {
|
return new IntHolder(value === void 0 ? this.value : value);
|
||||||
return 'IntHolder(value=' + Kotlin.toString(this.value) + ')';
|
};
|
||||||
},
|
IntHolder.prototype.toString = function () {
|
||||||
hashCode: function () {
|
return 'IntHolder(value=' + Kotlin.toString(this.value) + ')';
|
||||||
var result = 0;
|
};
|
||||||
result = result * 31 + Kotlin.hashCode(this.value) | 0;
|
IntHolder.prototype.hashCode = function () {
|
||||||
return result;
|
var result = 0;
|
||||||
},
|
result = result * 31 + Kotlin.hashCode(this.value) | 0;
|
||||||
equals_za3rmp$: function (other) {
|
return result;
|
||||||
return this === other || (other !== null && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value)));
|
};
|
||||||
}
|
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 = {});
|
||||||
Kotlin.defineModule('jslib-example', _);
|
package$sample.pairAdd_1fzo63$ = pairAdd;
|
||||||
}(Kotlin));
|
package$sample.pairMul_1fzo63$ = pairMul;
|
||||||
|
package$sample.IntHolder = IntHolder;
|
||||||
|
Kotlin.defineModule('LibraryExample', _);
|
||||||
|
return _;
|
||||||
|
}(typeof LibraryExample === 'undefined' ? {} : LibraryExample, kotlin);
|
||||||
|
|||||||
+1
@@ -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==");
|
||||||
BIN
Binary file not shown.
@@ -54,10 +54,9 @@ object TopDownAnalyzerFacadeForJS {
|
|||||||
moduleContext: ModuleContext,
|
moduleContext: ModuleContext,
|
||||||
config: JsConfig
|
config: JsConfig
|
||||||
): JsAnalysisResult {
|
): JsAnalysisResult {
|
||||||
val allFiles = JsConfig.withJsLibAdded(files, config)
|
|
||||||
val analyzerForJs = createTopDownAnalyzerForJs(
|
val analyzerForJs = createTopDownAnalyzerForJs(
|
||||||
moduleContext, trace,
|
moduleContext, trace,
|
||||||
FileBasedDeclarationProviderFactory(moduleContext.storageManager, allFiles),
|
FileBasedDeclarationProviderFactory(moduleContext.storageManager, files),
|
||||||
config.configuration.get(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS, LanguageVersionSettingsImpl.DEFAULT)
|
config.configuration.get(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS, LanguageVersionSettingsImpl.DEFAULT)
|
||||||
)
|
)
|
||||||
analyzerForJs.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, files)
|
analyzerForJs.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, files)
|
||||||
|
|||||||
@@ -20,11 +20,8 @@ import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
|||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters1
|
import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters1
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.diagnostics.Severity
|
|
||||||
import org.jetbrains.kotlin.js.PredefinedAnnotation.*
|
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.js.translate.utils.AnnotationsUtils
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
|
||||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||||
import org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor
|
import org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor
|
||||||
import org.jetbrains.kotlin.resolve.diagnostics.FUNCTION_NO_BODY_ERRORS
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.js.config;
|
package org.jetbrains.kotlin.js.config;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.util.SmartList;
|
import com.intellij.util.SmartList;
|
||||||
import kotlin.collections.CollectionsKt;
|
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.descriptors.impl.ModuleDescriptorImpl;
|
||||||
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
|
||||||
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration;
|
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration;
|
||||||
import org.jetbrains.kotlin.serialization.js.JsModuleDescriptor;
|
import org.jetbrains.kotlin.serialization.js.JsModuleDescriptor;
|
||||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil;
|
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil;
|
||||||
@@ -39,7 +37,6 @@ import org.jetbrains.kotlin.utils.JsMetadataVersion;
|
|||||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata;
|
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -50,7 +47,6 @@ public abstract class JsConfig {
|
|||||||
private final Project project;
|
private final Project project;
|
||||||
private final CompilerConfiguration configuration;
|
private final CompilerConfiguration configuration;
|
||||||
private final LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
private final LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||||
private final List<KtFile> sourceFilesFromLibraries = new SmartList<KtFile>();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected final List<KotlinJavascriptMetadata> metadata = new SmartList<KotlinJavascriptMetadata>();
|
protected final List<KotlinJavascriptMetadata> metadata = new SmartList<KotlinJavascriptMetadata>();
|
||||||
@@ -92,7 +88,7 @@ public abstract class JsConfig {
|
|||||||
|
|
||||||
public abstract boolean checkLibFilesAndReportErrors(@NotNull Reporter report);
|
public abstract boolean checkLibFilesAndReportErrors(@NotNull Reporter report);
|
||||||
|
|
||||||
protected abstract void init(@NotNull List<KtFile> sourceFilesInLibraries, @NotNull List<KotlinJavascriptMetadata> metadata);
|
protected abstract void init(@NotNull List<KotlinJavascriptMetadata> metadata);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<JsModuleDescriptor<ModuleDescriptorImpl>> getModuleDescriptors() {
|
public List<JsModuleDescriptor<ModuleDescriptorImpl>> getModuleDescriptors() {
|
||||||
@@ -117,16 +113,10 @@ public abstract class JsConfig {
|
|||||||
return moduleDescriptors;
|
return moduleDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private List<KtFile> getSourceFilesFromLibraries() {
|
|
||||||
init();
|
|
||||||
return sourceFilesFromLibraries;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
if (initialized) return;
|
if (initialized) return;
|
||||||
|
|
||||||
init(sourceFilesFromLibraries, metadata);
|
init(metadata);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,12 +143,4 @@ public abstract class JsConfig {
|
|||||||
private static void setDependencies(ModuleDescriptorImpl module, List<ModuleDescriptorImpl> modules) {
|
private static void setDependencies(ModuleDescriptorImpl module, List<ModuleDescriptorImpl> modules) {
|
||||||
module.setDependencies(CollectionsKt.plus(modules, JsPlatform.INSTANCE.getBuiltIns().getBuiltInsModule()));
|
module.setDependencies(CollectionsKt.plus(modules, JsPlatform.INSTANCE.getBuiltIns().getBuiltInsModule()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static Collection<KtFile> withJsLibAdded(@NotNull Collection<KtFile> files, @NotNull JsConfig config) {
|
|
||||||
Collection<KtFile> allFiles = Lists.newArrayList();
|
|
||||||
allFiles.addAll(files);
|
|
||||||
allFiles.addAll(config.getSourceFilesFromLibraries());
|
|
||||||
return allFiles;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,24 +17,20 @@
|
|||||||
package org.jetbrains.kotlin.js.config;
|
package org.jetbrains.kotlin.js.config;
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Key;
|
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.openapi.vfs.*;
|
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||||
import com.intellij.psi.PsiManager;
|
|
||||||
import com.intellij.util.PathUtil;
|
import com.intellij.util.PathUtil;
|
||||||
import com.intellij.util.io.URLUtil;
|
import com.intellij.util.io.URLUtil;
|
||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
import kotlin.jvm.functions.Function2;
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
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.JsMetadataVersion;
|
||||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata;
|
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata;
|
||||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils;
|
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils;
|
||||||
import org.jetbrains.kotlin.utils.LibraryUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -42,7 +38,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.utils.LibraryUtils.isOldKotlinJavascriptLibrary;
|
|
||||||
import static org.jetbrains.kotlin.utils.PathUtil.getKotlinPathsForDistDirectory;
|
import static org.jetbrains.kotlin.utils.PathUtil.getKotlinPathsForDistDirectory;
|
||||||
|
|
||||||
public class LibrarySourcesConfig extends JsConfig {
|
public class LibrarySourcesConfig extends JsConfig {
|
||||||
@@ -52,7 +47,6 @@ public class LibrarySourcesConfig extends JsConfig {
|
|||||||
public static final List<String> JS_KOTLIN_TEST =
|
public static final List<String> JS_KOTLIN_TEST =
|
||||||
Collections.singletonList(getKotlinPathsForDistDirectory().getJsKotlinTestJarPath().getAbsolutePath());
|
Collections.singletonList(getKotlinPathsForDistDirectory().getJsKotlinTestJarPath().getAbsolutePath());
|
||||||
|
|
||||||
public static final Key<String> EXTERNAL_MODULE_NAME = Key.create("externalModule");
|
|
||||||
public static final String UNKNOWN_EXTERNAL_MODULE_NAME = "<unknown>";
|
public static final String UNKNOWN_EXTERNAL_MODULE_NAME = "<unknown>";
|
||||||
|
|
||||||
public LibrarySourcesConfig(@NotNull Project project, @NotNull CompilerConfiguration configuration) {
|
public LibrarySourcesConfig(@NotNull Project project, @NotNull CompilerConfiguration configuration) {
|
||||||
@@ -65,11 +59,9 @@ public class LibrarySourcesConfig extends JsConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init(@NotNull final List<KtFile> sourceFilesInLibraries, @NotNull final List<KotlinJavascriptMetadata> metadata) {
|
protected void init(@NotNull final List<KotlinJavascriptMetadata> metadata) {
|
||||||
if (getLibraries().isEmpty()) return;
|
if (getLibraries().isEmpty()) return;
|
||||||
|
|
||||||
final PsiManager psiManager = PsiManager.getInstance(getProject());
|
|
||||||
|
|
||||||
JsConfig.Reporter report = new JsConfig.Reporter() {
|
JsConfig.Reporter report = new JsConfig.Reporter() {
|
||||||
@Override
|
@Override
|
||||||
public void error(@NotNull String message) {
|
public void error(@NotNull String message) {
|
||||||
@@ -77,18 +69,12 @@ public class LibrarySourcesConfig extends JsConfig {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Function2<String, VirtualFile, Unit> action = new Function2<String, VirtualFile, Unit>() {
|
Function1<VirtualFile, Unit> action = new Function1<VirtualFile, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(String moduleName, VirtualFile file) {
|
public Unit invoke(VirtualFile file) {
|
||||||
if (moduleName != null) {
|
String libraryPath = PathUtil.getLocalPath(file);
|
||||||
JetFileCollector jetFileCollector = new JetFileCollector(sourceFilesInLibraries, moduleName, psiManager);
|
assert libraryPath != null : "libraryPath for " + file + " should not be null";
|
||||||
VfsUtilCore.visitChildrenRecursively(file, jetFileCollector);
|
metadata.addAll(KotlinJavascriptMetadataUtils.loadMetadata(libraryPath));
|
||||||
}
|
|
||||||
else {
|
|
||||||
String libraryPath = PathUtil.getLocalPath(file);
|
|
||||||
assert libraryPath != null : "libraryPath for " + file + " should not be null";
|
|
||||||
metadata.addAll(KotlinJavascriptMetadataUtils.loadMetadata(libraryPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
}
|
}
|
||||||
@@ -103,7 +89,7 @@ public class LibrarySourcesConfig extends JsConfig {
|
|||||||
return checkLibFilesAndReportErrors(report, null);
|
return checkLibFilesAndReportErrors(report, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkLibFilesAndReportErrors(@NotNull JsConfig.Reporter report, @Nullable Function2<String, VirtualFile, Unit> action) {
|
private boolean checkLibFilesAndReportErrors(@NotNull JsConfig.Reporter report, @Nullable Function1<VirtualFile, Unit> action) {
|
||||||
List<String> libraries = getLibraries();
|
List<String> libraries = getLibraries();
|
||||||
if (libraries.isEmpty()) {
|
if (libraries.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -135,73 +121,28 @@ public class LibrarySourcesConfig extends JsConfig {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String moduleName;
|
List<KotlinJavascriptMetadata> metadataList = KotlinJavascriptMetadataUtils.loadMetadata(filePath);
|
||||||
|
if (metadataList.isEmpty()) {
|
||||||
if (isOldKotlinJavascriptLibrary(filePath)) {
|
report.warning("'" + path + "' is not a valid Kotlin Javascript library");
|
||||||
moduleName = LibraryUtils.getKotlinJsModuleName(filePath);
|
continue;
|
||||||
if (!modules.add(moduleName)) {
|
|
||||||
report.warning("Module \"" + moduleName + "\" is defined in more, than one file");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
List<KotlinJavascriptMetadata> metadataList = KotlinJavascriptMetadataUtils.loadMetadata(filePath);
|
|
||||||
if (metadataList.isEmpty()) {
|
|
||||||
report.warning("'" + path + "' is not a valid Kotlin Javascript library");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (KotlinJavascriptMetadata metadata : metadataList) {
|
for (KotlinJavascriptMetadata metadata : metadataList) {
|
||||||
if (!metadata.getVersion().isCompatible()) {
|
if (!metadata.getVersion().isCompatible()) {
|
||||||
report.error("File '" + path + "' was compiled with an incompatible version of Kotlin. " +
|
report.error("File '" + path + "' was compiled with an incompatible version of Kotlin. " +
|
||||||
"The binary version of its metadata is " + metadata.getVersion() +
|
"The binary version of its metadata is " + metadata.getVersion() +
|
||||||
", expected version is " + JsMetadataVersion.INSTANCE);
|
", expected version is " + JsMetadataVersion.INSTANCE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!modules.add(metadata.getModuleName())) {
|
if (!modules.add(metadata.getModuleName())) {
|
||||||
report.warning("Module \"" + metadata.getModuleName() + "\" is defined in more, than one file");
|
report.warning("Module \"" + metadata.getModuleName() + "\" is defined in more, than one file");
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
|
|
||||||
moduleName = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
action.invoke(moduleName, file);
|
action.invoke(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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<KtFile> jetFiles;
|
|
||||||
private final String moduleName;
|
|
||||||
private final PsiManager psiManager;
|
|
||||||
|
|
||||||
private JetFileCollector(List<KtFile> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.context.TranslationContext
|
||||||
import org.jetbrains.kotlin.js.translate.reference.CallExpressionTranslator
|
import org.jetbrains.kotlin.js.translate.reference.CallExpressionTranslator
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
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.descriptorUtil.isExtension
|
||||||
import org.jetbrains.kotlin.resolve.inline.InlineStrategy
|
import org.jetbrains.kotlin.resolve.inline.InlineStrategy
|
||||||
import org.jetbrains.kotlin.utils.JsLibraryUtils
|
import org.jetbrains.kotlin.utils.JsLibraryUtils
|
||||||
@@ -68,7 +68,7 @@ class FunctionReader(private val context: TranslationContext) {
|
|||||||
val config = context.config as LibrarySourcesConfig
|
val config = context.config as LibrarySourcesConfig
|
||||||
val libs = config.libraries.map { File(it) }
|
val libs = config.libraries.map { File(it) }
|
||||||
|
|
||||||
JsLibraryUtils.traverseJsLibraries(libs) { fileContent, path ->
|
JsLibraryUtils.traverseJsLibraries(libs) { fileContent, _ ->
|
||||||
var current = 0
|
var current = 0
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -113,9 +113,9 @@ class FunctionReader(private val context: TranslationContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator fun contains(descriptor: CallableDescriptor): Boolean {
|
operator fun contains(descriptor: CallableDescriptor): Boolean {
|
||||||
val moduleName = getExternalModuleName(descriptor)
|
val moduleName = getModuleName(descriptor)
|
||||||
val currentModuleName = context.config.moduleId
|
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)
|
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? {
|
private fun readFunction(descriptor: CallableDescriptor): JsFunction? {
|
||||||
if (descriptor !in this) return null
|
if (descriptor !in this) return null
|
||||||
|
|
||||||
val moduleName = getExternalModuleName(descriptor)
|
val moduleName = getModuleName(descriptor)
|
||||||
|
|
||||||
for (info in moduleNameToInfo[moduleName]) {
|
for (info in moduleNameToInfo[moduleName]) {
|
||||||
val function = readFunctionFromSource(descriptor, info)
|
val function = readFunctionFromSource(descriptor, info)
|
||||||
|
|||||||
@@ -104,14 +104,6 @@ public class AntTaskJsTest extends AbstractAntTaskTest {
|
|||||||
doJsAntTest();
|
doJsAntTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleWithStdlibAndAnotherLib() throws Exception {
|
|
||||||
doJsAntTest("jslib-example.js");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleWithStdlibAndFolderAsAnotherLib() throws Exception {
|
|
||||||
doJsAntTest("jslib-example.js");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleWithoutStdlibAndFolderAsAnotherLib() throws Exception {
|
public void testSimpleWithoutStdlibAndFolderAsAnotherLib() throws Exception {
|
||||||
doJsAntTest("jslib-example.js");
|
doJsAntTest("jslib-example.js");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public final class K2JSTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BindingTrace bindingTrace = analysisResult.getBindingTrace();
|
BindingTrace bindingTrace = analysisResult.getBindingTrace();
|
||||||
TopDownAnalyzerFacadeForJS.checkForErrors(JsConfig.withJsLibAdded(files, config), bindingTrace.getBindingContext());
|
TopDownAnalyzerFacadeForJS.checkForErrors(files, bindingTrace.getBindingContext());
|
||||||
ModuleDescriptor moduleDescriptor = analysisResult.getModuleDescriptor();
|
ModuleDescriptor moduleDescriptor = analysisResult.getModuleDescriptor();
|
||||||
Diagnostics diagnostics = bindingTrace.getBindingContext().getDiagnostics();
|
Diagnostics diagnostics = bindingTrace.getBindingContext().getDiagnostics();
|
||||||
|
|
||||||
|
|||||||
+3
-29
@@ -17,15 +17,12 @@
|
|||||||
package org.jetbrains.kotlin.js.translate.utils;
|
package org.jetbrains.kotlin.js.translate.utils;
|
||||||
|
|
||||||
import com.intellij.openapi.util.Condition;
|
import com.intellij.openapi.util.Condition;
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.js.config.LibrarySourcesConfig;
|
|
||||||
import org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt;
|
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.js.translate.context.TranslationContext;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.KtExpression;
|
import org.jetbrains.kotlin.psi.KtExpression;
|
||||||
@@ -42,7 +39,6 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.isNativeObject;
|
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.*;
|
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
||||||
|
|
||||||
public final class JsDescriptorUtils {
|
public final class JsDescriptorUtils {
|
||||||
@@ -164,24 +160,9 @@ public final class JsDescriptorUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getModuleName(@NotNull DeclarationDescriptor descriptor) {
|
public static String getModuleName(@NotNull DeclarationDescriptor descriptor) {
|
||||||
String externalModuleName = getExternalModuleName(descriptor);
|
ModuleDescriptor moduleDescriptor = DescriptorUtils.getContainingModule(findRealInlineDeclaration(descriptor));
|
||||||
if (externalModuleName != null) return externalModuleName;
|
String moduleName = moduleDescriptor.getName().asString();
|
||||||
|
return moduleName.substring(1, moduleName.length() - 1);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -210,13 +191,6 @@ public final class JsDescriptorUtils {
|
|||||||
return null;
|
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) {
|
public static boolean isImmediateSubtypeOfError(@NotNull ClassDescriptor descriptor) {
|
||||||
if (!isExceptionClass(descriptor)) return false;
|
if (!isExceptionClass(descriptor)) return false;
|
||||||
ClassDescriptor superClass = org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getSuperClassOrAny(descriptor);
|
ClassDescriptor superClass = org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getSuperClassOrAny(descriptor);
|
||||||
|
|||||||
@@ -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.script.runtime.sources=Kotlin Script Runtime Sources
|
||||||
|
|
||||||
manifest.impl.title.kotlin.javascript.stdlib=Kotlin JavaScript StdLib
|
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
|
manifest.impl.title.kotlin.preloader=Kotlin Preloader
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user