Skip to content

Commit

Permalink
[[FIX]] Validate lone arrow function parameter
Browse files Browse the repository at this point in the history
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 21, 2019
1 parent 691dbdc commit 38285cd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/jshint.js
Expand Up @@ -2239,7 +2239,6 @@ var JSHINT = (function() {


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

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


if (isReserved(context, this)) { if (isReserved(context, this)) {
warning("W024", this, v); 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); state.funct["(scope)"].block.use(v, state.tokens.curr);
} }

return this; return this;
}, },


Expand Down
3 changes: 0 additions & 3 deletions tests/test262/expectations.txt
Expand Up @@ -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/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-bindingidentifier-yield.js(default)
test/language/expressions/arrow-function/syntax/arrowparameters-cover-formalparameters-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(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-expression-body.js(strict mode)
test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-invalid-parenless-parameters.js(default) test/language/expressions/arrow-function/syntax/early-errors/asi-restriction-invalid-parenless-parameters.js(default)
Expand Down

0 comments on commit 38285cd

Please sign in to comment.