$.utils.code.toSource is unnecessarily conservative about quoting property names
- Dominant language
- JavaScript
- Stars
- 198
- Forks
- 38
- PR merge metrics
- No merged PRs in 30d
Description
`$.utils.code.toSource({delete: 'foo'})` returns `{'delete': "foo"}`, but the single quotes around "delete" are not needed because although `delete` is a reserved word it is being used here as a property rather than variable name.
Similarly, `$.utils.code.toSource({4: 4})` returns `{'4': 4}` when `{4: 4}` is legal.
The `$.utils.code.quote` function is doing this but it perhaps needs to be forked into different versions for different contexts. (Note that you can also say `object.delete` but not `object.4`.)
Whatever changes are made here should be back to `server/code.js`.
Reference:
See https://262.ecma-international.org/5.1/#sec-11.1.5 (ES5.1) and/or https://tc39.es/ecma262/#sec-object-initializer (ES20xx) for the syntax of an _ObjectInitializer_; note that _PropertyName_ (ES5.1) / _LiteralPropertyName_ (ES20xx) can be any of **_IdentifierName_**, _StringLiteral_ or **_NumericLiteral_**, and that _IdentifierName_ is not the same as _Identifier_ (which does exclude _ReservedWord_).
Contributor guide
Assessment
This issue has not been assessed yet.