diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeString.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeString.kt new file mode 100644 index 00000000000..95348a463c9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeString.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL + +fun testSimpleString() { + js("var a = 123;") +} + +fun testSimpleStringPlus() { + js("var a" + "=" + "123;") +} + +fun testSimpleStringConcat() { + js("var a${"="}123;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithCompanionVal.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithCompanionVal.fir.kt new file mode 100644 index 00000000000..693b289e448 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithCompanionVal.fir.kt @@ -0,0 +1,96 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently + +// MODULE: lib1 +// FILE: A.kt +class ClassFromOtherModule { + companion object { + val valFromOtherModuleCompanion = "valFromOtherModuleCompanion" + } +} + +// FILE: B.kt +class ClassFromOtherModule2 { + companion object { + val valFromOtherModuleCompanion2 = ClassFromOtherModule.valFromOtherModuleCompanion + "2" + } +} + +// MODULE: main(lib1) +// FILE: A.kt +class ClassFromOtherFile { + companion object { + val valFromOtherFileCompanion = "valFromOtherFileCompanion" + } +} + +// FILE: B.kt +class ClassFromOtherFile2 { + companion object { + val valFromOtherFileCompanion2 = ClassFromOtherFile.valFromOtherFileCompanion + "2" + } +} + +// FILE: Main.kt +class ClassFromThisFile { + companion object { + val valFromThisFileCompanion = "valFromThisFileCompanion" + + fun testCompanionFromThisCompanion() { + js("var ${valFromThisFileCompanion} = 1;") + js("var " + valFromThisFileCompanion + " = 1;") + } + } + + fun testCompanionFromThis() { + js("var ${valFromThisFileCompanion} = 1;") + js("var " + valFromThisFileCompanion + " = 1;") + } +} + +class ClassFromThisFile2 { + companion object { + val valFromThisFileCompanion2 = ClassFromThisFile.valFromThisFileCompanion + "2" + + fun testCompanionFromThisCompanion() { + js("var ${valFromThisFileCompanion2} = 1;") + js("var " + valFromThisFileCompanion2 + " = 1;") + } + } + + fun testCompanionFromThis() { + js("var ${valFromThisFileCompanion2} = 1;") + js("var " + valFromThisFileCompanion2 + " = 1;") + } +} + +fun testCompanionValFromOtherModule() { + js("var ${ClassFromOtherModule.valFromOtherModuleCompanion} = 1;") + js("var " + ClassFromOtherModule.valFromOtherModuleCompanion + " = 1;") +} + +fun testCompanionValFromOtherModule2() { + js("var ${ClassFromOtherModule2.valFromOtherModuleCompanion2} = 1;") + js("var " + ClassFromOtherModule2.valFromOtherModuleCompanion2 + " = 1;") +} + + +fun testCompanionValFromOtherFile() { + js("var ${ClassFromOtherFile.valFromOtherFileCompanion} = 1;") + js("var " + ClassFromOtherFile.valFromOtherFileCompanion + " = 1;") +} + +fun testCompanionValFromOtherFile2() { + js("var ${ClassFromOtherFile2.valFromOtherFileCompanion2} = 1;") + js("var " + ClassFromOtherFile2.valFromOtherFileCompanion2 + " = 1;") +} + +fun testCompanionValFromThisFile() { + js("var ${ClassFromThisFile.valFromThisFileCompanion} = 1;") + js("var " + ClassFromThisFile.valFromThisFileCompanion + " = 1;") +} + +fun testCompanionValFromThisFile2() { + js("var ${ClassFromThisFile2.valFromThisFileCompanion2} = 1;") + js("var " + ClassFromThisFile2.valFromThisFileCompanion2 + " = 1;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithCompanionVal.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithCompanionVal.kt new file mode 100644 index 00000000000..e84838e1bbc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithCompanionVal.kt @@ -0,0 +1,96 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently + +// MODULE: lib1 +// FILE: A.kt +class ClassFromOtherModule { + companion object { + val valFromOtherModuleCompanion = "valFromOtherModuleCompanion" + } +} + +// FILE: B.kt +class ClassFromOtherModule2 { + companion object { + val valFromOtherModuleCompanion2 = ClassFromOtherModule.valFromOtherModuleCompanion + "2" + } +} + +// MODULE: main(lib1) +// FILE: A.kt +class ClassFromOtherFile { + companion object { + val valFromOtherFileCompanion = "valFromOtherFileCompanion" + } +} + +// FILE: B.kt +class ClassFromOtherFile2 { + companion object { + val valFromOtherFileCompanion2 = ClassFromOtherFile.valFromOtherFileCompanion + "2" + } +} + +// FILE: Main.kt +class ClassFromThisFile { + companion object { + val valFromThisFileCompanion = "valFromThisFileCompanion" + + fun testCompanionFromThisCompanion() { + js("var ${valFromThisFileCompanion} = 1;") + js("var " + valFromThisFileCompanion + " = 1;") + } + } + + fun testCompanionFromThis() { + js("var ${valFromThisFileCompanion} = 1;") + js("var " + valFromThisFileCompanion + " = 1;") + } +} + +class ClassFromThisFile2 { + companion object { + val valFromThisFileCompanion2 = ClassFromThisFile.valFromThisFileCompanion + "2" + + fun testCompanionFromThisCompanion() { + js("var ${valFromThisFileCompanion2} = 1;") + js("var " + valFromThisFileCompanion2 + " = 1;") + } + } + + fun testCompanionFromThis() { + js("var ${valFromThisFileCompanion2} = 1;") + js("var " + valFromThisFileCompanion2 + " = 1;") + } +} + +fun testCompanionValFromOtherModule() { + js("var ${ClassFromOtherModule.valFromOtherModuleCompanion} = 1;") + js("var " + ClassFromOtherModule.valFromOtherModuleCompanion + " = 1;") +} + +fun testCompanionValFromOtherModule2() { + js("var ${ClassFromOtherModule2.valFromOtherModuleCompanion2} = 1;") + js("var " + ClassFromOtherModule2.valFromOtherModuleCompanion2 + " = 1;") +} + + +fun testCompanionValFromOtherFile() { + js("var ${ClassFromOtherFile.valFromOtherFileCompanion} = 1;") + js("var " + ClassFromOtherFile.valFromOtherFileCompanion + " = 1;") +} + +fun testCompanionValFromOtherFile2() { + js("var ${ClassFromOtherFile2.valFromOtherFileCompanion2} = 1;") + js("var " + ClassFromOtherFile2.valFromOtherFileCompanion2 + " = 1;") +} + +fun testCompanionValFromThisFile() { + js("var ${ClassFromThisFile.valFromThisFileCompanion} = 1;") + js("var " + ClassFromThisFile.valFromThisFileCompanion + " = 1;") +} + +fun testCompanionValFromThisFile2() { + js("var ${ClassFromThisFile2.valFromThisFileCompanion2} = 1;") + js("var " + ClassFromThisFile2.valFromThisFileCompanion2 + " = 1;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithConstVal.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithConstVal.kt new file mode 100644 index 00000000000..e8d9f566202 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithConstVal.kt @@ -0,0 +1,76 @@ +// FIR_IDENTICAL +// MODULE: lib1 +// FILE: A.kt +const val constFromOtherModule = "constFromOtherModule" + +class ClassFromOtherModule { + companion object { + const val constFromOtherModuleCompanion = "constFromOtherModuleCompanion" + } +} + +// MODULE: main(lib1) +// FILE: A.kt +const val constFromOtherFile = "constFromOtherFile" + +class ClassFromOtherFile { + companion object { + const val constFromOtherFileCompanion = "constFromOtherFileCompanion" + } +} + +// FILE: Main.kt +const val constFromThisFile = "constFromThisFile" + +open class ClassFromThisFile { + companion object { + const val constFromThisFileCompanion = "constFromThisFileCompanion" + + fun testCompanionFromThisCompanion() { + js("var ${constFromThisFileCompanion} = 1;") + js("var " + constFromThisFileCompanion + " = 1;") + } + } + + fun testCompanionFromThis() { + js("var ${constFromThisFileCompanion} = 1;") + js("var " + constFromThisFileCompanion + " = 1;") + } +} + +class Class: ClassFromThisFile() { + fun testCompanionFromParent() { + js("var ${constFromThisFileCompanion} = 1;") + js("var " + constFromThisFileCompanion + " = 1;") + } +} + +fun testConstFromOtherModule() { + js("var $constFromOtherModule = 1;") + js("var " + constFromOtherModule + " = 1;") +} + +fun testCompanionConstFromOtherModule() { + js("var ${ClassFromOtherModule.constFromOtherModuleCompanion} = 1;") + js("var " + ClassFromOtherModule.constFromOtherModuleCompanion + " = 1;") +} + +fun testConstFromOtherFile() { + js("var $constFromOtherFile = 1;") + js("var " + constFromOtherFile + " = 1;") +} + +fun testCompanionConstFromOtherFile() { + js("var ${ClassFromOtherFile.constFromOtherFileCompanion} = 1;") + js("var " + ClassFromOtherFile.constFromOtherFileCompanion + " = 1;") +} + +fun testConstFromThisFile() { + js("var $constFromThisFile = 1;") + js("var " + constFromThisFile + " = 1;") +} + +fun testCompanionConstFromThisFile() { + js("var ${ClassFromThisFile.constFromThisFileCompanion} = 1;") + js("var " + ClassFromThisFile.constFromThisFileCompanion + " = 1;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithFunCall.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithFunCall.fir.kt new file mode 100644 index 00000000000..06c7fd9ebf8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithFunCall.fir.kt @@ -0,0 +1,39 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently +// ERROR_POLICY: SEMANTIC +@file:Suppress("NOTHING_TO_INLINE") + +fun function1() = "function1" + +inline fun inlineFunction1() = "inlineFunction1" + +class Class { + fun method1() = "method1" + inline fun inlineMethod1() = "method1" + + fun testMethodFromThis() { + js("var a = '${method1()}' + '" + method1() + "';") + } + + fun testInlineMethodFromThis() { + js("var a = '${inlineMethod1()}' + '" + inlineMethod1() + "';") + } +} + +fun testFunction() { + js("var a = '${function1()}' + '" + function1() + "';") +} + +fun testInlineFunction() { + js("var a = '${inlineFunction1()}' + '" + inlineFunction1() + "';") +} + +fun testMethod() { + val c = Class() + js("var a = '${c.method1()}' + '" + c.method1() + "';") +} + +fun testInlineMethod() { + val c = Class() + js("var a = '${c.inlineMethod1()}' + '" + c.inlineMethod1() + "';") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithFunCall.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithFunCall.kt new file mode 100644 index 00000000000..f1b87fdd7af --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithFunCall.kt @@ -0,0 +1,39 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently +// ERROR_POLICY: SEMANTIC +@file:Suppress("NOTHING_TO_INLINE") + +fun function1() = "function1" + +inline fun inlineFunction1() = "inlineFunction1" + +class Class { + fun method1() = "method1" + inline fun inlineMethod1() = "method1" + + fun testMethodFromThis() { + js("var a = '${method1()}' + '" + method1() + "';") + } + + fun testInlineMethodFromThis() { + js("var a = '${inlineMethod1()}' + '" + inlineMethod1() + "';") + } +} + +fun testFunction() { + js("var a = '${function1()}' + '" + function1() + "';") +} + +fun testInlineFunction() { + js("var a = '${inlineFunction1()}' + '" + inlineFunction1() + "';") +} + +fun testMethod() { + val c = Class() + js("var a = '${c.method1()}' + '" + c.method1() + "';") +} + +fun testInlineMethod() { + val c = Class() + js("var a = '${c.inlineMethod1()}' + '" + c.inlineMethod1() + "';") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithIntrinConstCall.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithIntrinConstCall.fir.kt new file mode 100644 index 00000000000..aa42998854d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithIntrinConstCall.fir.kt @@ -0,0 +1,122 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently +// ERROR_POLICY: SEMANTIC + +@file:Suppress( + "DEPRECATED_IDENTITY_EQUALS", + "SENSELESS_COMPARISON" +) + +fun testTrimMargin() { + js(""" + | var x = 1; + """.trimMargin()) +} + +fun testTrimIndent() { + js(""" + var x = 1; + """.trimIndent()) +} + +const val ONE = 1 +const val UONE = 1U +const val HALF = 0.5 +const val TRUE = true +const val STR = "str" +const val CHAR = 'C' + +fun testStringSize() { + js("var a = ${STR.length};") +} + +fun testSimpleStringConcat() { + js("{ var a = '${'b'}'; }") + js("{ var a = ${123}; }") + js("{ var a = ${123U}; }") + js("{ var a = ${123L}; }") + js("{ var a = ${123UL}; }") + js("{ var a = ${1.23}; }") + js("{ var a = ${1.23f}; }") + js("{ var a = ${true}; }") + js("{ var a = ${false}; }") + js("{ var a = ${null}; }") + + js("{ var a = ${ONE}; }") + js("{ var a = ${UONE}; }") + js("{ var a = ${HALF}; }") + js("{ var a = ${TRUE}; }") + js("{ var a = '${STR}'; }") + js("{ var a = '${CHAR}'; }") +} + +fun testArithmeticOperations() { + js("{ var a = ${1 + 2}; }") + js("{ var a = ${1 - 2}; }") + js("{ var a = ${1 * 2}; }") + js("{ var a = ${1 / 2}; }") + js("{ var a = ${1 % 2}; }") + js("{ var a = ${1.1 + 2.1}; }") + js("{ var a = ${1.1 - 2.1}; }") + js("{ var a = ${1.1 * 2.1}; }") + js("{ var a = ${1.1 / 2.1}; }") + + js("{ var a = ${ONE + 2}; }") + js("{ var a = ${HALF + 2.1}; }") + + js("{ var a = '${"foo" + "bar"}'; }") + js("{ var a = '${"foo" + 'c'}'; }") + js("{ var a = '${'c' + "foo"}'; }") + + js("{ var a = ${STR + STR}; }") + js("{ var a = ${STR + CHAR}; }") + js("{ var a = ${CHAR + STR}; }") +} + +fun testLogicOperations() { + js("{ var a = ${!true}; }") + js("{ var a = ${true or false}; }") + js("{ var a = ${true || false}; }") + js("{ var a = ${true and false}; }") + js("{ var a = ${true && false}; }") + + js("{ var a = ${TRUE && false}; }") + js("{ var a = ${TRUE or false}; }") +} + +fun testEq() { + js("{ var a = ${1 == 1}; }") + js("{ var a = ${1U == 1U}; }") + js("{ var a = ${UONE == 1U}; }") + js("{ var a = ${"FOO" == STR}; }") + js("{ var a = ${TRUE == null}; }") + js("{ var a = ${STR == null}; }") + + js("{ var a = ${1 != 1}; }") + js("{ var a = ${1U != 1U}; }") + js("{ var a = ${UONE != 1U}; }") + js("{ var a = ${"FOO" != STR}; }") + js("{ var a = ${TRUE != null}; }") + js("{ var a = ${STR != null}; }") + + js("{ var a = ${1 === 1}; }") + js("{ var a = ${TRUE === false}; }") + js("{ var a = ${CHAR === 's'}; }") + + js("{ var a = ${1 !== 1}; }") + js("{ var a = ${TRUE !== false}; }") + js("{ var a = ${CHAR !== 's'}; }") +} + +fun testCmp() { + js("{ var a = ${1 < 1}; }") + js("{ var a = ${1 <= 1}; }") + js("{ var a = ${1 > 1}; }") + js("{ var a = ${1 >= 1}; }") + + js("{ var a = ${"fo=" < "bar"}; }") + js("{ var a = ${'a' > 'c'}; }") + + js("{ var a = ${ONE > 1}; }") + js("{ var a = ${STR <= "1"}; }") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithIntrinConstCall.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithIntrinConstCall.kt new file mode 100644 index 00000000000..6378ca680d9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithIntrinConstCall.kt @@ -0,0 +1,122 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently +// ERROR_POLICY: SEMANTIC + +@file:Suppress( + "DEPRECATED_IDENTITY_EQUALS", + "SENSELESS_COMPARISON" +) + +fun testTrimMargin() { + js(""" + | var x = 1; + """.trimMargin()) +} + +fun testTrimIndent() { + js(""" + var x = 1; + """.trimIndent()) +} + +const val ONE = 1 +const val UONE = 1U +const val HALF = 0.5 +const val TRUE = true +const val STR = "str" +const val CHAR = 'C' + +fun testStringSize() { + js("var a = ${STR.length};") +} + +fun testSimpleStringConcat() { + js("{ var a = '${'b'}'; }") + js("{ var a = ${123}; }") + js("{ var a = ${123U}; }") + js("{ var a = ${123L}; }") + js("{ var a = ${123UL}; }") + js("{ var a = ${1.23}; }") + js("{ var a = ${1.23f}; }") + js("{ var a = ${true}; }") + js("{ var a = ${false}; }") + js("{ var a = ${null}; }") + + js("{ var a = ${ONE}; }") + js("{ var a = ${UONE}; }") + js("{ var a = ${HALF}; }") + js("{ var a = ${TRUE}; }") + js("{ var a = '${STR}'; }") + js("{ var a = '${CHAR}'; }") +} + +fun testArithmeticOperations() { + js("{ var a = ${1 + 2}; }") + js("{ var a = ${1 - 2}; }") + js("{ var a = ${1 * 2}; }") + js("{ var a = ${1 / 2}; }") + js("{ var a = ${1 % 2}; }") + js("{ var a = ${1.1 + 2.1}; }") + js("{ var a = ${1.1 - 2.1}; }") + js("{ var a = ${1.1 * 2.1}; }") + js("{ var a = ${1.1 / 2.1}; }") + + js("{ var a = ${ONE + 2}; }") + js("{ var a = ${HALF + 2.1}; }") + + js("{ var a = '${"foo" + "bar"}'; }") + js("{ var a = '${"foo" + 'c'}'; }") + js("{ var a = '${'c' + "foo"}'; }") + + js("{ var a = ${STR + STR}; }") + js("{ var a = ${STR + CHAR}; }") + js("{ var a = ${CHAR + STR}; }") +} + +fun testLogicOperations() { + js("{ var a = ${!true}; }") + js("{ var a = ${true or false}; }") + js("{ var a = ${true || false}; }") + js("{ var a = ${true and false}; }") + js("{ var a = ${true && false}; }") + + js("{ var a = ${TRUE && false}; }") + js("{ var a = ${TRUE or false}; }") +} + +fun testEq() { + js("{ var a = ${1 == 1}; }") + js("{ var a = ${1U == 1U}; }") + js("{ var a = ${UONE == 1U}; }") + js("{ var a = ${"FOO" == STR}; }") + js("{ var a = ${TRUE == null}; }") + js("{ var a = ${STR == null}; }") + + js("{ var a = ${1 != 1}; }") + js("{ var a = ${1U != 1U}; }") + js("{ var a = ${UONE != 1U}; }") + js("{ var a = ${"FOO" != STR}; }") + js("{ var a = ${TRUE != null}; }") + js("{ var a = ${STR != null}; }") + + js("{ var a = ${1 === 1}; }") + js("{ var a = ${TRUE === false}; }") + js("{ var a = ${CHAR === 's'}; }") + + js("{ var a = ${1 !== 1}; }") + js("{ var a = ${TRUE !== false}; }") + js("{ var a = ${CHAR !== 's'}; }") +} + +fun testCmp() { + js("{ var a = ${1 < 1}; }") + js("{ var a = ${1 <= 1}; }") + js("{ var a = ${1 > 1}; }") + js("{ var a = ${1 >= 1}; }") + + js("{ var a = ${"fo=" < "bar"}; }") + js("{ var a = ${'a' > 'c'}; }") + + js("{ var a = ${ONE > 1}; }") + js("{ var a = ${STR <= "1"}; }") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithTopLevelVal.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithTopLevelVal.fir.kt new file mode 100644 index 00000000000..7be21c339ec --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithTopLevelVal.fir.kt @@ -0,0 +1,58 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently +// ERROR_POLICY: SEMANTIC + +// MODULE: lib1 +// FILE: A.kt +val valFromOtherModule = "valFromOtherModule" + +// FILE: B.kt +val valFromOtherModule2 = valFromOtherModule + "2" + +// MODULE: main(lib1) +// FILE: A.kt +val valFromOtherFile = "valFromOtherFile" + +// FILE: B.kt +val valFromOtherFile2 = valFromOtherFile + "2" + +// FILE: Main.kt +val valFromThisFile = "valFromThisFile" +val valFromThisFile2 = valFromThisFile + "2" + +val valWithGetter: String get() = "valWithGetter" + +fun testValFromOtherModule() { + js("var ${valFromOtherModule} = 1;") + js("var " + valFromOtherModule + " = 1;") +} + +fun testValFromOtherModule2() { + js("var ${valFromOtherModule2} = 1;") + js("var " + valFromOtherModule2 + " = 1;") +} + +fun testValFromOtherFile() { + js("var ${valFromOtherFile} = 1;") + js("var " + valFromOtherFile + " = 1;") +} + +fun testValFromOtherFile2() { + js("var ${valFromOtherFile2} = 1;") + js("var " + valFromOtherFile2 + " = 1;") +} + +fun testValFromThisFile() { + js("var ${valFromThisFile} = 1;") + js("var " + valFromThisFile + " = 1;") +} + +fun testValFromThisFile2() { + js("var ${valFromThisFile2} = 1;") + js("var " + valFromThisFile2 + " = 1;") +} + +fun testValWithGetter() { + js("var ${valWithGetter} = 1;") + js("var " + valWithGetter + " = 1;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithTopLevelVal.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithTopLevelVal.kt new file mode 100644 index 00000000000..41325196ecf --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithTopLevelVal.kt @@ -0,0 +1,58 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently +// ERROR_POLICY: SEMANTIC + +// MODULE: lib1 +// FILE: A.kt +val valFromOtherModule = "valFromOtherModule" + +// FILE: B.kt +val valFromOtherModule2 = valFromOtherModule + "2" + +// MODULE: main(lib1) +// FILE: A.kt +val valFromOtherFile = "valFromOtherFile" + +// FILE: B.kt +val valFromOtherFile2 = valFromOtherFile + "2" + +// FILE: Main.kt +val valFromThisFile = "valFromThisFile" +val valFromThisFile2 = valFromThisFile + "2" + +val valWithGetter: String get() = "valWithGetter" + +fun testValFromOtherModule() { + js("var ${valFromOtherModule} = 1;") + js("var " + valFromOtherModule + " = 1;") +} + +fun testValFromOtherModule2() { + js("var ${valFromOtherModule2} = 1;") + js("var " + valFromOtherModule2 + " = 1;") +} + +fun testValFromOtherFile() { + js("var ${valFromOtherFile} = 1;") + js("var " + valFromOtherFile + " = 1;") +} + +fun testValFromOtherFile2() { + js("var ${valFromOtherFile2} = 1;") + js("var " + valFromOtherFile2 + " = 1;") +} + +fun testValFromThisFile() { + js("var ${valFromThisFile} = 1;") + js("var " + valFromThisFile + " = 1;") +} + +fun testValFromThisFile2() { + js("var ${valFromThisFile2} = 1;") + js("var " + valFromThisFile2 + " = 1;") +} + +fun testValWithGetter() { + js("var ${valWithGetter} = 1;") + js("var " + valWithGetter + " = 1;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithVal.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithVal.fir.kt new file mode 100644 index 00000000000..cf257ced34b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithVal.fir.kt @@ -0,0 +1,63 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently +// ERROR_POLICY: SEMANTIC + +fun testValFromThisFunction() { + val valFromThisFunction = "valFromThisFunction" + val valFromThisFunction2 = valFromThisFunction + "2" + + js("var ${valFromThisFunction} = 1;") + js("var " + valFromThisFunction + " = 1;") + + js("var ${valFromThisFunction2} = 1;") + js("var " + valFromThisFunction2 + " = 1;") +} + +fun testVarFromThisFunction() { + var varFromThisFunction = "varFromThisFunction" + var varFromThisFunction2 = varFromThisFunction + "2" + + js("var ${varFromThisFunction} = 1;") + js("var " + varFromThisFunction + " = 1;") + + js("var ${varFromThisFunction2} = 1;") + js("var " + varFromThisFunction2 + " = 1;") +} + +fun testValFromParam(valFromParam: String) { + js("var ${valFromParam} = 1;") + js("var " + valFromParam + " = 1;") +} + +class Class { + val valFromClass = "valFromClass" + + val valWithGetter: String get() = "valWithGetter" + + fun testValFromThis() { + js("var ${valFromClass} = 1;") + js("var " + valFromClass + " = 1;") + } + + fun testValWithGetterThis() { + js("var ${valWithGetter} = 1;") + js("var " + valWithGetter + " = 1;") + } +} + +fun testValFromClassObject() { + val c = Class() + js("var ${c.valFromClass} = 1;") + js("var " + c.valFromClass + " = 1;") + + js("var ${c.valWithGetter} = 1;") + js("var " + c.valWithGetter + " = 1;") +} + +fun testValFromObject() { + val o = object { + val valFromObject = "valFromClass" + } + js("var ${o.valFromObject} = 1;") + js("var " + o.valFromObject + " = 1;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithVal.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithVal.kt new file mode 100644 index 00000000000..ae4b578a6c7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithVal.kt @@ -0,0 +1,63 @@ +// FIR_DIFFERENCE +// The difference is okay: K1 and K2 report a bit differently +// ERROR_POLICY: SEMANTIC + +fun testValFromThisFunction() { + val valFromThisFunction = "valFromThisFunction" + val valFromThisFunction2 = valFromThisFunction + "2" + + js("var ${valFromThisFunction} = 1;") + js("var " + valFromThisFunction + " = 1;") + + js("var ${valFromThisFunction2} = 1;") + js("var " + valFromThisFunction2 + " = 1;") +} + +fun testVarFromThisFunction() { + var varFromThisFunction = "varFromThisFunction" + var varFromThisFunction2 = varFromThisFunction + "2" + + js("var ${varFromThisFunction} = 1;") + js("var " + varFromThisFunction + " = 1;") + + js("var ${varFromThisFunction2} = 1;") + js("var " + varFromThisFunction2 + " = 1;") +} + +fun testValFromParam(valFromParam: String) { + js("var ${valFromParam} = 1;") + js("var " + valFromParam + " = 1;") +} + +class Class { + val valFromClass = "valFromClass" + + val valWithGetter: String get() = "valWithGetter" + + fun testValFromThis() { + js("var ${valFromClass} = 1;") + js("var " + valFromClass + " = 1;") + } + + fun testValWithGetterThis() { + js("var ${valWithGetter} = 1;") + js("var " + valWithGetter + " = 1;") + } +} + +fun testValFromClassObject() { + val c = Class() + js("var ${c.valFromClass} = 1;") + js("var " + c.valFromClass + " = 1;") + + js("var ${c.valWithGetter} = 1;") + js("var " + c.valWithGetter + " = 1;") +} + +fun testValFromObject() { + val o = object { + val valFromObject = "valFromClass" + } + js("var ${o.valFromObject} = 1;") + js("var " + o.valFromObject + " = 1;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptEmpty.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptEmpty.kt new file mode 100644 index 00000000000..bbdc9c16352 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptEmpty.kt @@ -0,0 +1,19 @@ +// FIR_IDENTICAL +// ERROR_POLICY: SEMANTIC + +fun testEmptyString() { + js("") +} + +const val SPACE = " " + +fun testStringWithSpaces() { + js("\n \n$SPACE \t" + " ") +} + +fun testComment() { + js(""" + // just a comment + $SPACE + """) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptError.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptError.kt new file mode 100644 index 00000000000..2d8300a4ebb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptError.kt @@ -0,0 +1,8 @@ +// FIR_IDENTICAL +// ERROR_POLICY: SEMANTIC + +const val VALUE = 123 + +fun testJavaScriptError() { + js("var = $VALUE;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptWarning.kt b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptWarning.kt new file mode 100644 index 00000000000..69a77c434cc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptWarning.kt @@ -0,0 +1,7 @@ +// FIR_IDENTICAL + +const val VALUE = 888 + +fun testJavaScriptWarning() { + js("var a = 0$VALUE;") +} diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java index 7f9086e591f..6cdbdb1b7bb 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java @@ -7104,6 +7104,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest { runTest("js/js.translator/testData/box/jsCode/comments.kt"); } + @Test + @TestMetadata("compileTimeString.kt") + public void testCompileTimeString() throws Exception { + runTest("js/js.translator/testData/box/jsCode/compileTimeString.kt"); + } + @Test @TestMetadata("constantExpression.kt") public void testConstantExpression() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java index f95b1af4b88..f9ebea9dfcf 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java @@ -7210,6 +7210,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest { runTest("js/js.translator/testData/box/jsCode/comments.kt"); } + @Test + @TestMetadata("compileTimeString.kt") + public void testCompileTimeString() throws Exception { + runTest("js/js.translator/testData/box/jsCode/compileTimeString.kt"); + } + @Test @TestMetadata("constantExpression.kt") public void testConstantExpression() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsOldFrontendDiagnosticsWithBackendTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsOldFrontendDiagnosticsWithBackendTestGenerated.java index b023efceca2..6114f6c168c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsOldFrontendDiagnosticsWithBackendTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsOldFrontendDiagnosticsWithBackendTestGenerated.java @@ -144,6 +144,48 @@ public class FirPsiJsOldFrontendDiagnosticsWithBackendTestGenerated extends Abst runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/badAssignment.kt"); } + @Test + @TestMetadata("compileTimeString.kt") + public void testCompileTimeString() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeString.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithCompanionVal.kt") + public void testCompileTimeStringWithCompanionVal() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithCompanionVal.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithConstVal.kt") + public void testCompileTimeStringWithConstVal() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithConstVal.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithFunCall.kt") + public void testCompileTimeStringWithFunCall() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithFunCall.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithIntrinConstCall.kt") + public void testCompileTimeStringWithIntrinConstCall() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithIntrinConstCall.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithTopLevelVal.kt") + public void testCompileTimeStringWithTopLevelVal() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithTopLevelVal.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithVal.kt") + public void testCompileTimeStringWithVal() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithVal.kt"); + } + @Test @TestMetadata("deleteOperation.kt") public void testDeleteOperation() throws Exception { @@ -156,6 +198,24 @@ public class FirPsiJsOldFrontendDiagnosticsWithBackendTestGenerated extends Abst runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/error.kt"); } + @Test + @TestMetadata("javaScriptEmpty.kt") + public void testJavaScriptEmpty() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptEmpty.kt"); + } + + @Test + @TestMetadata("javaScriptError.kt") + public void testJavaScriptError() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptError.kt"); + } + + @Test + @TestMetadata("javaScriptWarning.kt") + public void testJavaScriptWarning() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptWarning.kt"); + } + @Test @TestMetadata("noJavaScriptProduced.kt") public void testNoJavaScriptProduced() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/DiagnosticsWithJsStdLibAndBackendTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/DiagnosticsWithJsStdLibAndBackendTestGenerated.java index 64f44a2dc5a..a163f9b1ebe 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/DiagnosticsWithJsStdLibAndBackendTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/DiagnosticsWithJsStdLibAndBackendTestGenerated.java @@ -144,6 +144,48 @@ public class DiagnosticsWithJsStdLibAndBackendTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/badAssignment.kt"); } + @Test + @TestMetadata("compileTimeString.kt") + public void testCompileTimeString() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeString.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithCompanionVal.kt") + public void testCompileTimeStringWithCompanionVal() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithCompanionVal.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithConstVal.kt") + public void testCompileTimeStringWithConstVal() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithConstVal.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithFunCall.kt") + public void testCompileTimeStringWithFunCall() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithFunCall.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithIntrinConstCall.kt") + public void testCompileTimeStringWithIntrinConstCall() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithIntrinConstCall.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithTopLevelVal.kt") + public void testCompileTimeStringWithTopLevelVal() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithTopLevelVal.kt"); + } + + @Test + @TestMetadata("compileTimeStringWithVal.kt") + public void testCompileTimeStringWithVal() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/compileTimeStringWithVal.kt"); + } + @Test @TestMetadata("deleteOperation.kt") public void testDeleteOperation() throws Exception { @@ -156,6 +198,24 @@ public class DiagnosticsWithJsStdLibAndBackendTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/error.kt"); } + @Test + @TestMetadata("javaScriptEmpty.kt") + public void testJavaScriptEmpty() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptEmpty.kt"); + } + + @Test + @TestMetadata("javaScriptError.kt") + public void testJavaScriptError() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptError.kt"); + } + + @Test + @TestMetadata("javaScriptWarning.kt") + public void testJavaScriptWarning() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLibAndBackendCompilation/jsCode/javaScriptWarning.kt"); + } + @Test @TestMetadata("noJavaScriptProduced.kt") public void testNoJavaScriptProduced() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java index 6174d78bebb..b7f9e9ea02e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java @@ -7210,6 +7210,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test { runTest("js/js.translator/testData/box/jsCode/comments.kt"); } + @Test + @TestMetadata("compileTimeString.kt") + public void testCompileTimeString() throws Exception { + runTest("js/js.translator/testData/box/jsCode/compileTimeString.kt"); + } + @Test @TestMetadata("constantExpression.kt") public void testConstantExpression() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java index dc2a78e2a39..a6255394032 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java @@ -7104,6 +7104,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/jsCode/comments.kt"); } + @Test + @TestMetadata("compileTimeString.kt") + public void testCompileTimeString() throws Exception { + runTest("js/js.translator/testData/box/jsCode/compileTimeString.kt"); + } + @Test @TestMetadata("constantExpression.kt") public void testConstantExpression() throws Exception { diff --git a/js/js.translator/testData/box/jsCode/compileTimeString.kt b/js/js.translator/testData/box/jsCode/compileTimeString.kt new file mode 100644 index 00000000000..9d2e6f71514 --- /dev/null +++ b/js/js.translator/testData/box/jsCode/compileTimeString.kt @@ -0,0 +1,200 @@ +// WITH_STDLIB + +// MODULE: lib1 +// FILE: f.kt +const val LIB_INT = 1 +const val LIB_STR = "LIB_STR" +const val LIB_CHAR = '1' +const val LIB_UINT = 1U +const val LIB_ULINT = 1UL +const val LIB_DOUBLE = 0.1 +const val LIB_FLOAT = 0.1f + +open class LIB_Class { + companion object { + const val STR = "LIB_ClassSTR" + } +} + +// MODULE: main(lib1) +// FILE: main.kt + +const val INT = 2 +const val STR = "STR" +const val CHAR = '2' +const val UINT = 2U +const val ULINT = 2UL +const val DOUBLE = 0.2 +const val FLOAT = 0.2f + +open class Class { + companion object { + const val STR = "ClassSTR" + } + + fun testClassCompanion(): String { + js(""" + function testClassCompanionInnerBox() { + if ('$STR' != 'ClassSTR') { return "Not OK Class.STR"; } + return "OK"; + } + """) + return js("testClassCompanionInnerBox()") as String + } +} + +class Child : Class() { + fun testParentCompanion(): String { + js(""" + function testParentCompanionInnerBox() { + if ('$STR' != 'ClassSTR') { return "Not OK Class.STR"; } + return "OK"; + } + """) + return js("testParentCompanionInnerBox()") as String + } +} + +fun testConstantInlining(): String { + js(""" + function testConstantInliningInnerBox() { + if ($INT != 2) { return "Not OK INT"; } + if ('$STR' != 'STR') { return "Not OK STR"; } + if ('$CHAR' != '2') { return "Not OK CHAR"; } + if ($UINT != '2') { return "Not OK UINT"; } + if ($ULINT != '2') { return "Not OK ULINT"; } + if ($DOUBLE > 0.21) { return "Not OK DOUBLE"; } + if ($FLOAT > 0.21) { return "Not OK FLOAT"; } + if ('${Class.STR}' != 'ClassSTR') { return "Not OK Class.STR"; } + + return "OK"; + } + """) + return js("testConstantInliningInnerBox()") as String +} + +fun testConstantInliningFromOtherLib(): String { + js(""" + function testConstantInliningFromOtherLibInnerBox() { + if ($LIB_INT != 1) { return "Not OK LIB_INT"; } + if ('$LIB_STR' != 'LIB_STR') { return "Not OK LIB_STR"; } + if ('$LIB_CHAR' != '1') { return "Not OK LIB_CHAR"; } + if ($LIB_UINT != '1') { return "Not OK LIB_UINT"; } + if ($LIB_ULINT != '1') { return "Not OK LIB_ULINT"; } + if ($LIB_DOUBLE > 0.11) { return "Not OK LIB_DOUBLE"; } + if ($LIB_FLOAT > 0.11) { return "Not OK LIB_FLOAT"; } + if ('${LIB_Class.STR}' != 'LIB_ClassSTR') { return "Not OK LIB_Class.STR"; } + + return "OK"; + } + """) + return js("testConstantInliningFromOtherLibInnerBox()") as String +} + +fun testConstEvaluation(): String { + js(""" + function testConstEvaluationInnerBox() { + if (${INT != 2}) { return "Not OK INT"; } + if (${CHAR != '2'}) { return "Not OK CHAR"; } + if (${STR != "STR"}) { return "Not OK STR"; } + if (${STR.length} != 3) { return "Not OK STR.length"; } + if (${Class.STR != "ClassSTR"}) { return "Not OK Class.STR"; } + if (${Class.STR.length} != 8) { return "Not OK Class.STR.length"; } + + if (${LIB_INT != 1}) { return "Not OK LIB_INT"; } + if (${LIB_CHAR != '1'}) { return "Not OK LIB_CHAR"; } + if (${LIB_STR != "LIB_STR"}) { return "Not OK LIB_STR"; } + if (${LIB_STR.length} != 7) { return "Not OK LIB_STR.length"; } + if (${LIB_Class.STR != "LIB_ClassSTR"}) { return "Not OK LIB_Class.STR"; } + if (${LIB_Class.STR.length} != 12) { return "Not OK LIB_Class.STR.length"; } + + if (${(INT != 2 || CHAR != '2') && (STR == "STR")}) { return "Not OK Boolean operations"; } + + if (${INT + 2 / INT - 3 * INT} != -3) { return "Not OK INT arithmetic operations"; } + if (${LIB_INT + 2 / LIB_INT - 3 * LIB_INT} != 0) { return "Not OK LIB_INT arithmetic operations"; } + + if ('${STR + " " + LIB_Class.STR}' != 'STR LIB_ClassSTR') { return "Not OK STR plus"; } + + return "OK"; + } + """) + return js("testConstEvaluationInnerBox()") as String +} + +inline fun jsInInlineFunction() { + js(""" + function jsInInlineFunctionInnerBox() { + if ($INT != 2) { return "Not OK INT"; } + if ($LIB_INT != 1) { return "Not OK LIB_INT"; } + if ('${Class.STR}' != 'ClassSTR') { return "Not OK Class.STR"; } + if ('${LIB_Class.STR}' != 'LIB_ClassSTR') { return "Not OK LIB_Class.STR"; } + + return "OK"; + } + """) +} + +fun testJsInInlineFunction(): String { + jsInInlineFunction() + return js("jsInInlineFunctionInnerBox()") as String +} + +fun testCaptureVariables(param1: String = "parameter"): String { + val STR1 = "local variable" + + js(""" + function testCaptureVariablesInnerBox() { + if (param$LIB_INT != 'parameter') { return "Not OK parameter"; } + if ($STR$LIB_INT != 'local variable') { return "Not OK local variable"; } + + return "OK"; + } + """) + return js("testCaptureVariablesInnerBox()") as String +} + +inline fun jsInInlineFunctionCaptureVariables(param1: String = "parameter") { + val STR1 = "local variable" + + js(""" + function jsInInlineFunctionCaptureVariablesInnerBox() { + if (param$LIB_INT != 'parameter') { return "Not OK parameter"; } + if ($STR$LIB_INT != 'local variable') { return "Not OK local variable"; } + + return "OK"; + } + """) +} + +fun testCaptureVariablesInlineFunction(): String { + jsInInlineFunctionCaptureVariables() + return js("jsInInlineFunctionCaptureVariablesInnerBox()") as String +} + +fun box(): String { + var r = Class().testClassCompanion() + if (r != "OK") { return "Fail Class.testClassCompanion: $r" } + + r = Child().testParentCompanion() + if (r != "OK") { return "Fail Class.testParentCompanion: $r" } + + r = testConstantInlining() + if (r != "OK") { return "Fail testConstantInlining: $r" } + + r = testConstantInliningFromOtherLib() + if (r != "OK") { return "Fail testConstantInliningFromOtherLib: $r" } + + r = testConstEvaluation() + if (r != "OK") { return "Fail testConstEvaluation: $r" } + + r = testJsInInlineFunction() + if (r != "OK") { return "Fail testJsInInlineFunction: $r" } + + r = testCaptureVariables() + if (r != "OK") { return "Fail testCaptureVariables: $r" } + + r = testCaptureVariablesInlineFunction() + if (r != "OK") { return "Fail testCaptureVariablesInlineFunction: $r" } + + return "OK" +}