Escaping object field names: possibly confusing underscore
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 10.3k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
Description
Consider this JavaScript object:
var node = {
type: "Identifier"
};
To create this object in Reason, we have to escape the type field by prefixing it with an underscore because type is a keyword:
let node = {
"_type": "Identifier"
};
I find this syntax to be quite confusing for the following reasons:
- The double quotes suggest that
_typeis the literal name of the property. To me, the underscore doesn't look like an escape character in this position. - The underscore is commonly used in JavaScript to denote a (pseudo-)private property.
- The underscore is a valid code point at the start of an identifier.
What are your thoughts on moving the underscore outside of the double quotes?
let node = {
_"type": "Identifier"
};
This way, it's clearer that the generated property name will be type (not _type).
Another approach worth exploring might be to choose another character for escaping. Either way, I'd suggest moving the escape character outside of the double quotes.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the issue's Reason and JavaScript object examples and the two proposed escaping syntaxes. Determine whether the language should change how keyword field names are escaped or use another escape character. Done means reaching and documenting a decided syntax direction; no files or tests are identified in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, ocaml
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100