Prohibit illegal identifiers in packages in JS BE
See KT-18032
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
package <!INVALID_CHARACTERS!>`//`<!>
|
||||
|
||||
class A
|
||||
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
package `//` {
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -491,6 +491,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("illegalPackageName.kt")
|
||||
public void testIllegalPackageName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jsNameAndOverridden.kt")
|
||||
public void testJsNameAndOverridden() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameAndOverridden.kt");
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.container.useImpl
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.*
|
||||
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
|
||||
import org.jetbrains.kotlin.resolve.IdentifierChecker
|
||||
import org.jetbrains.kotlin.resolve.OverloadFilter
|
||||
import org.jetbrains.kotlin.resolve.OverridesBackwardCompatibilityHelper
|
||||
import org.jetbrains.kotlin.resolve.PlatformConfigurator
|
||||
@@ -50,7 +49,7 @@ object JsPlatformConfigurator : PlatformConfigurator(
|
||||
additionalTypeCheckers = listOf(),
|
||||
additionalClassifierUsageCheckers = listOf(),
|
||||
additionalAnnotationCheckers = listOf(),
|
||||
identifierChecker = IdentifierChecker.DEFAULT,
|
||||
identifierChecker = JsIdentifierChecker,
|
||||
overloadFilter = OverloadFilter.DEFAULT,
|
||||
platformToKotlinClassMap = PlatformToKotlinClassMap.EMPTY,
|
||||
delegationFilter = DelegationFilter.DEFAULT,
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.js.naming.NameSuggestion
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.IdentifierChecker
|
||||
|
||||
object JsIdentifierChecker : IdentifierChecker {
|
||||
override fun checkIdentifier(identifier: PsiElement?, diagnosticHolder: DiagnosticSink) {
|
||||
if (identifier == null) return
|
||||
|
||||
val hasIllegalChars = identifier.text.split('.').any { NameSuggestion.sanitizeName(it) != it }
|
||||
if (hasIllegalChars) {
|
||||
diagnosticHolder.report(Errors.INVALID_CHARACTERS.on(identifier, "contains illegal characters"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun checkDeclaration(declaration: KtDeclaration, diagnosticHolder: DiagnosticSink) {}
|
||||
}
|
||||
Reference in New Issue
Block a user