Skip to content
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

Invalid JS produced when more than 26 variables are auto-generated #155

Closed
hen-x opened this issue Feb 16, 2010 · 1 comment
Closed

Invalid JS produced when more than 26 variables are auto-generated #155

hen-x opened this issue Feb 16, 2010 · 1 comment

Comments

@hen-x
Copy link

hen-x commented Feb 16, 2010

Input:

x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y
x for x in y

Output:

var __a, __b, __c, __d, __e, __f, __g, __h, __i, __j, __k, __l, __m, __n, __o, __p, __q, __r, __s, __t, __u, __v, __w, __x, __y, __z, __{, __|, __}, __~, __�, __�, x;
__a = y;
for (__b = 0; __b < __a.length; __b++) {
  x = __a[__b];
  x;
}

//----SNIP----

__} = y;
for (__~ = 0; __~ < __}.length; __~++) {
  x = __}[__~];
  x;
}

It looks like the names of auto-generated JS variables (eg. __a) are not currently restricted to alphanumeric characters, or checked for legality. When more than 26 such variables are emitted in a single scope, after __z has already been used, the compiler seems to continue up the ascii chart, using variable names like __{, __|, and __}, which are not syntactically valid.

A better option would switching to longer names after __z, and emitting __aa, __ab, ... __zy, _zz.

@jashkenas
Copy link
Owner

Thanks for reporting this -- I was just using Prototype.js' succ() without thinking about it. On the latest master, bin/node_coffee will now generate shorter numeric ids instead of bothering with alphabetic ones:

_1, _2, _3 ...

Closing the ticket.

protez pushed a commit to protez/coffee-script that referenced this issue Jul 28, 2015
protez pushed a commit to protez/coffee-script that referenced this issue Jul 28, 2015
protez pushed a commit to protez/coffee-script that referenced this issue Jul 28, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants