-
Notifications
You must be signed in to change notification settings - Fork 2k
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
allow use of JS (non-coffee) keywords as identifiers #1452
Comments
I like this, though compiling to something like |
@alpha123: the problem with those solutions is that any alternative identifier that we use takes the place of some other identifier. So, in other words, what would |
@michaelficarra: The ECMAScript spec (3rd edition anyway) says the $ character is intended for use in generated code. Obviously some popular libraries ignored this, so theoretically you could have clashes, but putting it at the end reduces those greatly and is good for interoperability with JS. Let's say you have something like Oh, and I just discovered that Unicode escapes break Google Closure somewhat, which compiles |
But when given the option between reduced clashes (unacceptable) and no clashes (perfect), we'd obviously want to go with no clashes. On your second point, we would still have pretty output in all compilations that are allowed today. We would be adding the ability to use these JS keywords as identifiers and the only negative is that they don't compile to a pretty-looking name. I can live with that, and so can somebody using these identifiers. I will file a bug with closure compiler. We should hold off on this feature until that bug is fixed. edit: Filed bug #493. |
We could instead/additionally use some crazy unicode character that you can see as one character in every viewer - for example, the first character of "coffeescript" in a circle - no programmer would ever put something like that in his code, right?
or
|
@thejh: That's not a valid identifier, you'd actually have to use the escape sequence for it. Nice idea, but it wouldn't work. |
I'm afraid this one is a
And then, when you try to use my library from JavaScript:
Reserved words should not be used as identifiers. |
@jashkenas: bad example? $;node > var Twitter = { function: function(){ console.log('works'); } }; > Twitter.function() works > I don't see the compatibility problem. |
Safari:
... does not work. |
As usual, we don't give a damn about what ES5 says here -- what matters is what runs in browsers, including IE6 and IE7, even. |
I don't have a way to test IE right now, but the spec hasn't changed with this regard since ES3, back in 1999. So it's very possible (likely?) that those older browsers support unicode escape sequences in identifiers. Can you provide an example of any browser that doesn't support them? Re-opening, since this was closed without a (related) explanation. Feel free to close it again if browser support is found to be lacking or there's some reason this practice should be disallowed. |
OK, © doesn't work, but, for example, delta (Δ) seems to work at least in v8 (although I didn't read the spec). |
IE6 doesn't seem to support them: var va\u0072 = 'it works!'; document.write(va\u0072); gives an error on l. 1 col. 5: Expected identifier Edit: even IE9 throws exactly the same error |
It breaks API compatibility with JavaScript: JS cannot reference a variable, or call a function, by the same name that CoffeeScript identifies it with. You would never want to write a library that took advantage of this feature. |
@thejh: What the heck, that actually works. Tested in FF5, Opera 11.11, Chrome 14, IE9, and IE9 in IE7 compatibility mode. Dunno if it truly works in older IE versions though, IE compatibility mode tends not to work so well when it comes to JS. |
By way of unicode escape sequences in identifier names. See section 7.6 for the identifier requirements.
So the coffeescript
var = 7
can becomevar va\u0072 = 7
. This will alow the use of the following currently reserved words as identifiers:case
default
function
var
void
with
const
let
enum
export
import
native
We may, however, want to keep some of these reserved for later use by coffeescript (probably
void
, maybeconst
ordefault
).The text was updated successfully, but these errors were encountered: