JS: prohibit illegal chars on dynamic call site
See KT-19540
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
public final fun `foo-bar`(): dynamic
|
||||||
|
public final var `ba-z`: dynamic
|
||||||
|
public final fun <get-ba-z>(): dynamic
|
||||||
|
public final fun <set-ba-z>(/*0*/ <set-?>: dynamic): kotlin.Unit
|
||||||
@@ -17,4 +17,9 @@ private class <!NAME_CONTAINS_ILLEGAL_CHARS!>` .private class `<!> {
|
|||||||
|
|
||||||
val x: Int
|
val x: Int
|
||||||
<!NAME_CONTAINS_ILLEGAL_CHARS!>@JsName(".")
|
<!NAME_CONTAINS_ILLEGAL_CHARS!>@JsName(".")
|
||||||
get()<!> = TODO("")
|
get()<!> = TODO("")
|
||||||
|
|
||||||
|
fun box(x: dynamic) {
|
||||||
|
x.<!NAME_CONTAINS_ILLEGAL_CHARS!>`foo-bar`<!>()
|
||||||
|
x.<!NAME_CONTAINS_ILLEGAL_CHARS!>`ba-z`<!>
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ private fun ` .private `(): kotlin.String
|
|||||||
@kotlin.js.JsName(name = "validName") private fun ` .private with @JsName `(): kotlin.String
|
@kotlin.js.JsName(name = "validName") private fun ` .private with @JsName `(): kotlin.String
|
||||||
public fun ` .public `(): kotlin.String
|
public fun ` .public `(): kotlin.String
|
||||||
@kotlin.js.JsName(name = " ___ ") private fun bar(): kotlin.String
|
@kotlin.js.JsName(name = " ___ ") private fun bar(): kotlin.String
|
||||||
|
public fun box(/*0*/ x: dynamic): kotlin.Unit
|
||||||
@kotlin.js.JsName(name = " __ ") public fun foo(): kotlin.String
|
@kotlin.js.JsName(name = " __ ") public fun foo(): kotlin.String
|
||||||
|
|
||||||
private final class ` .private class ` {
|
private final class ` .private class ` {
|
||||||
|
|||||||
+17
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.js.resolve.diagnostics
|
package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.js.naming.NameSuggestion
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
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"))
|
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) {
|
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) {
|
private fun checkSpreadOperator(resolvedCall: ResolvedCall<*>, context: CallCheckerContext) {
|
||||||
for (arg in resolvedCall.call.valueArguments) {
|
for (arg in resolvedCall.call.valueArguments) {
|
||||||
val argExpression = arg.getArgumentExpression() ?: continue
|
val argExpression = arg.getArgumentExpression() ?: continue
|
||||||
|
|||||||
Reference in New Issue
Block a user