KJS: fix inlining from modules with non valid identifier name
This commit is contained in:
@@ -46,7 +46,7 @@ import java.io.File
|
|||||||
private val JS_IDENTIFIER_START = "\\p{Lu}\\p{Ll}\\p{Lt}\\p{Lm}\\p{Lo}\\p{Nl}\\\$_"
|
private val JS_IDENTIFIER_START = "\\p{Lu}\\p{Ll}\\p{Lt}\\p{Lm}\\p{Lo}\\p{Nl}\\\$_"
|
||||||
private val JS_IDENTIFIER_PART = "$JS_IDENTIFIER_START\\p{Pc}\\p{Mc}\\p{Mn}\\d"
|
private val JS_IDENTIFIER_PART = "$JS_IDENTIFIER_START\\p{Pc}\\p{Mc}\\p{Mn}\\d"
|
||||||
private val JS_IDENTIFIER="[$JS_IDENTIFIER_START][$JS_IDENTIFIER_PART]*"
|
private val JS_IDENTIFIER="[$JS_IDENTIFIER_START][$JS_IDENTIFIER_PART]*"
|
||||||
private val DEFINE_MODULE_PATTERN = ("($JS_IDENTIFIER)\\.defineModule\\(\\s*(['\"])(\\w+)\\2\\s*,\\s*(\\w+)\\s*\\)").toRegex().toPattern()
|
private val DEFINE_MODULE_PATTERN = ("($JS_IDENTIFIER)\\.defineModule\\(\\s*(['\"])([^'\"]+)\\2\\s*,\\s*(\\w+)\\s*\\)").toRegex().toPattern()
|
||||||
private val DEFINE_MODULE_FIND_PATTERN = ".defineModule("
|
private val DEFINE_MODULE_FIND_PATTERN = ".defineModule("
|
||||||
|
|
||||||
class FunctionReader(private val context: TranslationContext) {
|
class FunctionReader(private val context: TranslationContext) {
|
||||||
@@ -87,7 +87,7 @@ class FunctionReader(private val context: TranslationContext) {
|
|||||||
val moduleName = preciseMatcher.group(3)
|
val moduleName = preciseMatcher.group(3)
|
||||||
val moduleVariable = preciseMatcher.group(4)
|
val moduleVariable = preciseMatcher.group(4)
|
||||||
val kotlinVariable = preciseMatcher.group(1)
|
val kotlinVariable = preciseMatcher.group(1)
|
||||||
assert(moduleName !in moduleJsDefinition) { "Module is defined in more, than one file" }
|
assert(moduleName !in moduleJsDefinition) { "Module \"$moduleName\" is defined in more, than one file" }
|
||||||
moduleJsDefinition[moduleName] = fileContent
|
moduleJsDefinition[moduleName] = fileContent
|
||||||
moduleRootVariable[moduleName] = moduleVariable
|
moduleRootVariable[moduleName] = moduleVariable
|
||||||
moduleKotlinVariable[moduleName] = kotlinVariable
|
moduleKotlinVariable[moduleName] = kotlinVariable
|
||||||
|
|||||||
@@ -5485,6 +5485,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/multiModuleWrappers/common_js"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/multiModuleWrappers/common_js"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineFromModuleWithNonIdentifierName.kt")
|
||||||
|
public void testInlineFromModuleWithNonIdentifierName() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/multiModuleWrappers/common_js/inlineFromModuleWithNonIdentifierName.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("moduleWithNonIdentifierName.kt")
|
@TestMetadata("moduleWithNonIdentifierName.kt")
|
||||||
public void testModuleWithNonIdentifierName() throws Exception {
|
public void testModuleWithNonIdentifierName() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/multiModuleWrappers/common_js/moduleWithNonIdentifierName.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/multiModuleWrappers/common_js/moduleWithNonIdentifierName.kt");
|
||||||
@@ -5506,6 +5512,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/multiModuleWrappers/plain"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/multiModuleWrappers/plain"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineFromModuleWithNonIdentifierName.kt")
|
||||||
|
public void testInlineFromModuleWithNonIdentifierName() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/multiModuleWrappers/plain/inlineFromModuleWithNonIdentifierName.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("moduleWithNonIdentifierName.kt")
|
@TestMetadata("moduleWithNonIdentifierName.kt")
|
||||||
public void testModuleWithNonIdentifierName() throws Exception {
|
public void testModuleWithNonIdentifierName() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/multiModuleWrappers/plain/moduleWithNonIdentifierName.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/multiModuleWrappers/plain/moduleWithNonIdentifierName.kt");
|
||||||
|
|||||||
js/js.translator/testData/box/multiModuleWrappers/common_js/inlineFromModuleWithNonIdentifierName.kt
Vendored
+23
@@ -0,0 +1,23 @@
|
|||||||
|
// MODULE: #my-libr@ry
|
||||||
|
// FILE: bar.kt
|
||||||
|
// MODULE_KIND: COMMON_JS
|
||||||
|
// PROPERTY_NOT_WRITTEN_TO: baz
|
||||||
|
// PROPERTY_NOT_WRITTEN_TO: boo_287e2$
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
|
||||||
|
inline fun foo() = "foo"
|
||||||
|
@kotlin.internal.InlineOnly
|
||||||
|
inline fun baz() = "baz"
|
||||||
|
inline fun <reified T> boo() = "boo"
|
||||||
|
|
||||||
|
// MODULE: main(#my-libr@ry)
|
||||||
|
// FILE: box.kt
|
||||||
|
// MODULE_KIND: COMMON_JS
|
||||||
|
// CHECK_CONTAINS_NO_CALLS: box except=assertEquals
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
assertEquals("foo", foo())
|
||||||
|
assertEquals("baz", baz())
|
||||||
|
assertEquals("boo", boo<Int>())
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Vendored
+23
@@ -0,0 +1,23 @@
|
|||||||
|
// MODULE: #my-libr@ry
|
||||||
|
// FILE: bar.kt
|
||||||
|
// MODULE_KIND: PLAIN
|
||||||
|
// PROPERTY_NOT_WRITTEN_TO: baz
|
||||||
|
// PROPERTY_NOT_WRITTEN_TO: boo_287e2$
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
|
||||||
|
inline fun foo() = "foo"
|
||||||
|
@kotlin.internal.InlineOnly
|
||||||
|
inline fun baz() = "baz"
|
||||||
|
inline fun <reified T> boo() = "boo"
|
||||||
|
|
||||||
|
// MODULE: main(#my-libr@ry)
|
||||||
|
// FILE: box.kt
|
||||||
|
// MODULE_KIND: PLAIN
|
||||||
|
// CHECK_CONTAINS_NO_CALLS: box except=assertEquals
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
assertEquals("foo", foo())
|
||||||
|
assertEquals("baz", baz())
|
||||||
|
assertEquals("boo", boo<Int>())
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user