Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$.utils.code.toSource is unnecessarily conservative about quoting property names #469

Open
cpcallen opened this issue Mar 24, 2021 · 3 comments
Labels
core Things related to the "core" part of the database enhancement Feature requests, major new features, etc. server Things related to the codecity server proper

Comments

@cpcallen
Copy link
Collaborator

cpcallen commented Mar 24, 2021

$.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).

@cpcallen cpcallen added enhancement Feature requests, major new features, etc. server Things related to the codecity server proper core Things related to the "core" part of the database labels Mar 24, 2021
@cpcallen
Copy link
Collaborator Author

No: I believe $.utils.code.quote is fine. The problem is that it is being called in certain cases where it does not need to be.

@cpcallen
Copy link
Collaborator Author

There is not presently any code in code.js that has this issue.

@cpcallen
Copy link
Collaborator Author

$.utils.code.isIdentifierName has been split out of $.utils.code.isIdentifier, and .toSource updated appropriately.

Unquoted numeric literals are not yet generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Things related to the "core" part of the database enhancement Feature requests, major new features, etc. server Things related to the codecity server proper
Projects
None yet
Development

No branches or pull requests

1 participant