JS: report error when js() produces empty AST
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
fun test() {
|
||||||
|
js(<!JSCODE_NO_JAVASCRIPT_PRODUCED!>""<!>)
|
||||||
|
js(<!JSCODE_NO_JAVASCRIPT_PRODUCED!>" "<!>)
|
||||||
|
js(<!JSCODE_NO_JAVASCRIPT_PRODUCED!>"""
|
||||||
|
"""<!>)
|
||||||
|
|
||||||
|
val empty = ""
|
||||||
|
js(<!JSCODE_NO_JAVASCRIPT_PRODUCED!>empty<!>)
|
||||||
|
|
||||||
|
val whitespace = " "
|
||||||
|
js(<!JSCODE_NO_JAVASCRIPT_PRODUCED!>whitespace<!>)
|
||||||
|
|
||||||
|
val multiline = """
|
||||||
|
"""
|
||||||
|
js(<!JSCODE_NO_JAVASCRIPT_PRODUCED!>multiline<!>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun test(): kotlin.Unit
|
||||||
+6
@@ -257,6 +257,12 @@ public class JetDiagnosticsTestWithJsStdLibGenerated extends AbstractJetDiagnost
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noJavaScriptProduced.kt")
|
||||||
|
public void testNoJavaScriptProduced() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode/noJavaScriptProduced.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("warning.kt")
|
@TestMetadata("warning.kt")
|
||||||
public void testWarning() throws Exception {
|
public void testWarning() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode/warning.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode/warning.kt");
|
||||||
|
|||||||
+1
@@ -38,6 +38,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by Delegates.lazy {
|
|||||||
put(ErrorsJs.REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED, "Callable references for builtin members are not supported yet: ''{0}''", RenderFirstLineOfElementText)
|
put(ErrorsJs.REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED, "Callable references for builtin members are not supported yet: ''{0}''", RenderFirstLineOfElementText)
|
||||||
put(ErrorsJs.NON_TOPLEVEL_CLASS_DECLARATION, "Non-toplevel {0} declarations not supported yet", Renderers.STRING)
|
put(ErrorsJs.NON_TOPLEVEL_CLASS_DECLARATION, "Non-toplevel {0} declarations not supported yet", Renderers.STRING)
|
||||||
put(ErrorsJs.SECONDARY_CONSTRUCTOR, "Secondary constructors not supported yet")
|
put(ErrorsJs.SECONDARY_CONSTRUCTOR, "Secondary constructors not supported yet")
|
||||||
|
put(ErrorsJs.JSCODE_NO_JAVASCRIPT_PRODUCED, "Argument must be non-empty JavaScript code")
|
||||||
put(ErrorsJs.INLINE_CALL_CYCLE, "The call is a part of inline cycle")
|
put(ErrorsJs.INLINE_CALL_CYCLE, "The call is a part of inline cycle")
|
||||||
|
|
||||||
this
|
this
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public interface ErrorsJs {
|
|||||||
DiagnosticFactory1<JetElement, JetElement> REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
|
DiagnosticFactory1<JetElement, JetElement> REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
|
||||||
DiagnosticFactory1<JetNamedDeclaration, String> NON_TOPLEVEL_CLASS_DECLARATION = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
DiagnosticFactory1<JetNamedDeclaration, String> NON_TOPLEVEL_CLASS_DECLARATION = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||||
DiagnosticFactory0<JetNamedDeclaration> SECONDARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
DiagnosticFactory0<JetNamedDeclaration> SECONDARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||||
|
DiagnosticFactory0<JetExpression> JSCODE_NO_JAVASCRIPT_PRODUCED = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||||
DiagnosticFactory0<PsiElement> INLINE_CALL_CYCLE = DiagnosticFactory0.create(ERROR, DEFAULT);
|
DiagnosticFactory0<PsiElement> INLINE_CALL_CYCLE = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat
|
|||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.types.JetType
|
||||||
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
|
import org.jetbrains.kotlin.js.parser.parse
|
||||||
import java.io.StringReader
|
import java.io.StringReader
|
||||||
|
|
||||||
import kotlin.platform.platformStatic
|
import kotlin.platform.platformStatic
|
||||||
@@ -81,18 +82,16 @@ public class JsCallChecker : CallChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val code = evaluationResult.getValue() as String
|
val code = evaluationResult.getValue() as String
|
||||||
val reader = StringReader(code)
|
|
||||||
val errorReporter = JsCodeErrorReporter(argument, code, context.trace)
|
val errorReporter = JsCodeErrorReporter(argument, code, context.trace)
|
||||||
Context.enter().setErrorReporter(errorReporter)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val ts = TokenStream(reader, "js", 0)
|
val statements = parse(code, errorReporter, insideFunction = true)
|
||||||
val parser = Parser(IRFactory(ts), /* insideFunction = */ true)
|
|
||||||
parser.parse(ts)
|
if (statements.size() == 0) {
|
||||||
|
context.trace.report(ErrorsJs.JSCODE_NO_JAVASCRIPT_PRODUCED.on(argument))
|
||||||
|
}
|
||||||
} catch (e: AbortParsingException) {
|
} catch (e: AbortParsingException) {
|
||||||
// ignore
|
// ignore
|
||||||
} finally {
|
|
||||||
Context.exit()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user