feat: add WARNING on usage top-level exportable declarations with non-consumable identifiers.

This commit is contained in:
Artem Kobzar
2022-05-04 11:22:57 +00:00
committed by Space
parent 0ea9c1fbce
commit a2b40acc98
9 changed files with 170 additions and 22 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.js.backend.ast
import org.jetbrains.kotlin.js.common.RESERVED_KEYWORDS
import java.util.*
class JsObjectScope(parent: JsScope, description: String) : JsScope(parent, description)
@@ -70,23 +71,7 @@ open class JsDeclarationScope(parent: JsScope, description: String, useParentSco
}
companion object {
val RESERVED_WORDS: Set<String> = setOf(
// keywords
"await", "break", "case", "catch", "continue", "debugger", "default", "delete", "do", "else", "finally", "for", "function", "if",
"in", "instanceof", "new", "return", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with",
// future reserved words
"class", "const", "enum", "export", "extends", "import", "super",
// as future reserved words in strict mode
"implements", "interface", "let", "package", "private", "protected", "public", "static", "yield",
// additional reserved words
"null", "true", "false",
// disallowed as variable names in strict mode
"eval", "arguments",
val RESERVED_WORDS: Set<String> = RESERVED_KEYWORDS + setOf(
// global identifiers usually declared in a typical JS interpreter
"NaN", "isNaN", "Infinity", "undefined",
"Error", "Object", "Math", "String", "Number", "Boolean", "Date", "Array", "RegExp", "JSON",
@@ -49,4 +49,22 @@ fun String.isValidES5Identifier(): Boolean {
if (!get(idx).isES5IdentifierPart()) return false
}
return true
}
}
val RESERVED_KEYWORDS: Set<String> = setOf(
// keywords
"await", "break", "case", "catch", "continue", "debugger", "default", "delete", "do", "else", "finally", "for", "function", "if",
"in", "instanceof", "new", "return", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with",
// future reserved words
"class", "const", "enum", "export", "extends", "import", "super",
// as future reserved words in strict mode
"implements", "interface", "let", "package", "private", "protected", "public", "static", "yield",
// additional reserved words
"null", "true", "false",
// disallowed as variable names in strict mode
"eval", "arguments",
)