Closed chenyan-dfinity closed 3 years ago
At some point I think @rossberg suggested allowing quoted strings for field names. We could extend this to this problem, i.e. type "record" = nat
.
Or maybe it is less pressing here because type aliases do not matter for compatibility (unlike field names), so maybe appending …_
is fine.
We may not even have to remove the suffix, as round-tripping of type names is not required. But we could, of course. No strong opinion yet.
Doesn't seem worthwhile to go out of our way to allow arbitrary identifier names. If you wanted to map them back to other languages that would likely be trouble anyway. I think restricting to common identifier syntax and escaping with an underscore is fine.
In Motoko, we can define
type record = Nat;
, then this gets translated totype record = nat;
in IDL. This cannot be parsed in the IDL compiler, asrecord
is a keyword in IDL, but not in Motoko.The same problem happens for IDL -> JS, we can define
type const = nat;
in IDL, then the generated JS binding cannot be parsed, becauseconst
is a keyword in JS, not in IDL.I think we need an escape mechanism for translating identifiers: append
_
in the identifier if it is a keyword in the target language; remove_
suffix when importing if the identifier is a keyword in the source language.