JS: prohibit illegal chars on dynamic call site
See KT-19540
This commit is contained in:
+17
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.js.naming.NameSuggestion
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
@@ -62,6 +63,15 @@ object JsDynamicCallChecker : CallChecker {
|
||||
context.trace.report(ErrorsJs.WRONG_OPERATION_WITH_DYNAMIC.on(element.parent, "destructuring declaration"))
|
||||
}
|
||||
}
|
||||
|
||||
is KtSimpleNameExpression -> checkIdentifier(element.getReferencedName(), element, context)
|
||||
|
||||
is KtCallExpression -> {
|
||||
val calleePsi = element.calleeExpression
|
||||
if (calleePsi is KtSimpleNameExpression) {
|
||||
checkIdentifier(calleePsi.getReferencedName(), calleePsi, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (argument in resolvedCall.call.valueArguments) {
|
||||
@@ -71,6 +81,13 @@ object JsDynamicCallChecker : CallChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkIdentifier(name: String?, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
if (name == null) return
|
||||
if (NameSuggestion.sanitizeName(name) != name) {
|
||||
context.trace.report(ErrorsJs.NAME_CONTAINS_ILLEGAL_CHARS.on(reportOn))
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkSpreadOperator(resolvedCall: ResolvedCall<*>, context: CallCheckerContext) {
|
||||
for (arg in resolvedCall.call.valueArguments) {
|
||||
val argExpression = arg.getArgumentExpression() ?: continue
|
||||
|
||||
Reference in New Issue
Block a user