diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.kt new file mode 100644 index 00000000000..6e85ce4f119 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.kt @@ -0,0 +1,3 @@ +package `//` + +class A \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.txt b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.txt new file mode 100644 index 00000000000..ea87874d14d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.txt @@ -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 + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java index adacf791770..fb704ee1007 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java @@ -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"); diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt index aa3665a9734..52ab5af16cf 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.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, diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsIdentifierChecker.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsIdentifierChecker.kt new file mode 100644 index 00000000000..e6539eacadc --- /dev/null +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsIdentifierChecker.kt @@ -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) {} +}