Skip to content
Permalink
Browse files

[[FIX]] Validate lone arrow function parameter

Previously, the identifier parsing logic returned early for a lone arrow
function parameter in order to avoid incorrectly extending the
environment record in which the associated arrow function was defined.
This unintentionally circumvented logic which enforced restrictions on
identifier names.

Refactor the parsing logic to enforce the restriction in all cases, but
only alter the environment record when the identifier is not a lone
arrow function parameter.
  • Loading branch information...
jugglinmike authored and rwaldron committed Aug 18, 2019
1 parent 691dbdc commit 38285cd78346ff0194e5b080af565f3143476255
Showing with 3 additions and 8 deletions.
  1. +3 −5 src/jshint.js
  2. +0 −3 tests/test262/expectations.txt
@@ -2239,7 +2239,6 @@ var JSHINT = (function() {

nud: function(context) {
var v = this.value;

// If this identifier is the lone parameter to a shorthand "fat arrow"
// function definition, i.e.
//
@@ -2248,15 +2247,14 @@ var JSHINT = (function() {
// ...it should not be considered as a variable in the current scope. It
// will be added to the scope of the new function when the next token is
// parsed, so it can be safely ignored for now.
if (state.tokens.next.id === "=>") {
return this;
}
var isLoneArrowParam = state.tokens.next.id !== "=>";

if (isReserved(context, this)) {
warning("W024", this, v);
} else if (!state.funct["(comparray)"].check(v)) {
} else if (isLoneArrowParam && !state.funct["(comparray)"].check(v)) {
state.funct["(scope)"].block.use(v, state.tokens.curr);
}

return this;
},

@@ -267,9 +267,6 @@ test/language/expressions/arrow-function/scope-param-rest-elem-var-close.js(defa
test/language/expressions/arrow-function/scope-param-rest-elem-var-open.js(default)
test/language/expressions/arrow-function/syntax/arrowparameters-bindingidentifier-yield.js(default)
test/language/expressions/arrow-function/syntax/arrowparameters-cover-formalparameters-yield.js(default)
test/language/expressions/arrow-function/syntax/early-errors/arrowparameters-bindingidentifier-identifier-futurereservedword.js(default)
test/language/expressions/arrow-function/syntax/early-errors/arrowparameters-bindingidentifier-identifier-futurereservedword.js(strict mode)
test/language/expressions/arrow-function/syntax/early-errors/arrowparameters-bindingidentifier-identifier-strict-futurereservedword.js(strict mode)
test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-invalid-parenless-parameters-expression-body.js(default)
test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-invalid-parenless-parameters-expression-body.js(strict mode)
test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-invalid-parenless-parameters.js(default)

0 comments on commit 38285cd

Please sign in to comment.
You can’t perform that action at this time.