it's possible in a compiler plugin to create a fie...
# compiler
z
it's possible in a compiler plugin to create a field with a name like
foo<bar
even though it won't be legal in the JVM (and fail later). Java has things like
Character.isJavaIdentifierPart()
, is there anything/reference we should have for targeting other platforms like JS for ensuring names are safely escaped?
e
isJavaIdentifier
is stricter than what the JVM will accept
as far as what Kotlin/JS will accept, that has changed https://youtrack.jetbrains.com/issue/KT-31799
z
that's a feature request and I was more looking for what the current allowances are as a reference for plugins generating declaration names
e
the feature was rolled out in 2.1
z
sure, but I am looking for a specific reference (code, list of characters, etc) of what characters are legal
z
I am specifically looking for what specific targets allow, not what the
Name
class allows
e
I dunno then. it seems to me that the compiler allows any valid Name through, and then might blow up later
z
right, that's my point and why I am asking if there's docs or references. This question was more for the compiler folks at JB
m
JVM is a lot more lenient compared to dex/Dalvik/ART
👍 1
(letter codepoints, 0-9 digits,
$
or `_`; cannot start with a digit)
e
pretty similar to Java source identifiers, but Kotlin/JS will handle identifiers outside of that range too (with
-XXLanguage:+JsAllowInvalidCharsIdentifiersEscaping
or by default in newer versions), so JS's own identifier restrictions don't necessarily apply
I'm not aware of any restrictions on native or wasm identifiers, unless you are trying to export those symbols for interop…
z
looks like the JS ones are a subset of what java allows so that's convenient
b
For JVM we have FirJvmInvalidAndDangerousCharactersChecker which uses FirJvmNamesChecker. This is driven by the JVM spec and a few additional characters that we have found to be dangerous. In the JS space, it's a little more complicated. The entry point is FirJsExportDeclarationChecker which uses
validateDeclarationOnConsumableName
to check against a couple special and reserved keywords and makes sure the sanitized name is the same as the original name. Sanitization is driven by the ES 5.1 spec: https://262.ecma-international.org/5.1/#sec-7.6. Native has FirNativeIdentifierChecker. Sadly, I haven't found anything which unifies all of these that compiler plugin could use.
🙇 1