Skip to content

Commit

Permalink
[[CHORE]] Simplify internal function
Browse files Browse the repository at this point in the history
In so-called "object short notation," an IdentifierName is interpreted
as both a LiteralPropertyName and an IdentifierReference. The second is
a more restrictive goal than the first, so it is not necessary to apply
the LiteralPropertyName validation rules. Removing that validation logic
allows for an otherwise-unused parameter of the internal `propertyName`
function to be removed.
  • Loading branch information
jugglinmike committed Sep 19, 2020
1 parent ca59769 commit 3f6f61c
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/jshint.js
Expand Up @@ -3446,24 +3446,19 @@ var JSHINT = (function() {
*
* @param {number} context - the parsing context; see `prod-params.js` for
* more information
* @param {boolean} [preserve] - `true` if the token should not be consumed
*
* @returns {string|undefined} - the value of the identifier, if present
*/
function propertyName(context, preserve) {
var id = optionalidentifier(context, true, preserve);
function propertyName(context) {
var id = optionalidentifier(context, true);

if (!id) {
if (state.tokens.next.id === "(string)") {
id = state.tokens.next.value;
if (!preserve) {
advance();
}
advance();
} else if (state.tokens.next.id === "(number)") {
id = state.tokens.next.value.toString();
if (!preserve) {
advance();
}
advance();
}
}

Expand Down Expand Up @@ -3992,10 +3987,9 @@ var JSHINT = (function() {
if (!state.inES6()) {
warning("W104", state.tokens.next, "object short notation", "6");
}
i = propertyName(context, true);
saveProperty(props, i, state.tokens.next);

expression(context, 10);
t = expression(context, 10);
i = t.value;
saveProperty(props, i, t);

} else if (peek().id !== ":" && (nextVal === "get" || nextVal === "set")) {
advance(nextVal);
Expand Down

0 comments on commit 3f6f61c

Please sign in to comment.