jshint/jshint — Issue #301: Unicode characters in identifier names
Author: alawatthe
Created: 2011-10-09 12:43:52+00:00
State: open

With jsHint it is currently not possible to use identifiers which do not match the RegExp /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/ (see [line 753](https://github.com/jshint/jshint/blob/master/jshint.js#L753)).
In the following code each line would fail in jsHint.

π = 3.1415;
josé = 42;
Ж = "test";

But ECMA-Script also allows every character in one of the [Unicode categories](http://www.fileformat.info/info/unicode/category/index.htm) “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)” in identifier names. (see http://es5.github.com/#x7.6).

Therefor I think we should allow these characters, too.

There are some possibilities to accomplish this task. These three I found so far:

#### a long RegExp or a list
As there are approx. 15000 valid chars, the RegExp/list would be very long.

#### try and catch
An other way is trying to assign a value to the variable.
If it works, the variable name should be valid, if it throws an error the variable name should be wrong. The only problem is IE, as it allows chars like ☺ as variable names, which is wrong (see [http://stackoverflow.com/questions/7451524/why-arent-and-valid-javascript-variable-names](http://stackoverflow.com/questions/7451524/why-arent-and-valid-javascript-variable-names)).

#### upperCase !== lowerCase trick
Mihai Bazon [found a trick](http://mihai.bazon.net/blog/javascript-unicode-letters-in-regexps) to identify Unicode letters. He used this trick because of a bug in Firefox which is fixed now.
The chars in the categories Lu, Ll, Lt and Lm have an .toUpperCase() version that differs from the .toLowerCase() version. We could use it like this

function isUnicodeLetter(char) {
return char.toUpperCase() !== char.toLowerCase();
}

The problem is, that not every valid char satisfies this (example: ↂ).

#### What are the others doing?

* jsLint fails to parse it exactly like jsHint
* Narcissus is trying and catching (see [https://github.com/mozilla/narcissus/blob/master/lib/jslex.js#L86](https://github.com/mozilla/narcissus/blob/master/lib/jslex.js#L86)
* Traceur is using a list [http://code.google.com/p/traceur-compiler/source/browse/branches/v0.10/src/syntax/Scanner.js#114](http://code.google.com/p/traceur-compiler/source/browse/branches/v0.10/src/syntax/Scanner.js#114)
* the parse-js port from Uglify-Js is using a RegExp [https://github.com/mishoo/UglifyJS/blob/master/lib/parse-js.js#L204](https://github.com/mishoo/UglifyJS/blob/master/lib/parse-js.js#L204)

I think we should use the long RegExp. Shall I write a pull request?

What do you think?
alawatthe/alex