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

The use of reserved words as variable or function declaration identifiers is allowed in ES5 mode #744

Closed
jamesallardice opened this Issue Nov 21, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@jamesallardice
Copy link
Contributor

jamesallardice commented Nov 21, 2012

The use of a reserved word as a function or variable identifier, or as a function argument identifier, always throws a syntax error (regardless of the ECMAScript version). For example:

var default = 10; // Syntax error
function new () {} // Syntax error
function x(class) {} // Syntax error

In ECMAScript 5, the use of reserved words is permitted when they appear as the identifier for an object property:

var x = {
    default: 10 // No problem in ES5, syntax error in <ES5
};

JSHint (and JSLint) allow the use of reserved words as any type of identifier when the es5 option is set to true.

It appears that JSLint originally intended to handle this situation (an argument is passed to optional_identifier when the identifier belongs to an object property - this is the only situation in which this argument is passed in, but the argument is never actually used). JSHint has changed the meaning of this argument (it signifies that the identifier belongs to a function argument), but still passes it through for object property identifiers (but this doesn't actually cause an issue).

To handle this without too much change, the simplest solution may be to add a 2nd argument to optionalidentifier which will represent object property identifiers, and keep the 1st argument for function argument identifiers.

jamesallardice added a commit to jamesallardice/jshint that referenced this issue Nov 21, 2012

Disallows the use of reserved words as variable or function declarati…
…on identifiers. Currently, no warning is given for such use of reserved words when the es5 option is set to true. See issue jshint#744 for more details.
@valueof

This comment has been minimized.

Copy link
Member

valueof commented Dec 5, 2012

Fixed, thanks.

@valueof valueof closed this Dec 5, 2012

jugglinmike added a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014

Disallows the use of reserved words as variable or function declarati…
…on identifiers. Currently, no warning is given for such use of reserved words when the es5 option is set to true. See issue jshint#744 for more details.

danielctull pushed a commit to danielctull-forks/jshint that referenced this issue Jan 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment