-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Generated function argument names conflict with inlined JS #452
Comments
That would increase the size of the generate JS a lot since there are more variables generated from Mint code then from inlined code. I usually prefix the inlined variables with The proper solution to this would be something which Crystal has: https://crystal-lang.org/reference/syntax_and_semantics/macros/fresh_variables.html Something like this:
and would generate this (next available variable name): const AH = new(class extends _M {
b(n, m, o) {
return ((() => {
for (let p = 0; p < m.length; p++) {
console.log(m[p])
}
})());
}
}); Implementation wise all occurrences of a variable ( |
Another situation resulted in arguments generated as Thanks for the explanation. I can add a warning to the docs to avoid single letter variable names. |
I'd vote for autoprefixed variable names (interpolated ones). Otherwise it's gonna be tricky as hell to debug such issues, and fresh variables doesn't seem to give any advantage over autoprefixing, and OTOH they introduce another concept needed to be learned. |
I don't understand what you mean by that. |
I meant that the variable names should be prefixed to avoid clashing with already defined (usually single-lettered) variables. |
If we prefix every variable that the compiler produces it will significantly increase the size of the compiled code. Fresh variables are the proper way of fixing it, since they will take up a variable name slot.
I think it needs to be documented properly - both fresh variables and manual prefixing - and we will be fine. |
hmm, I still don't see this as a solution, since, theoretically every interpolated variable name within the inline JS body could clash with already defined ones, so in order to be safe you'd need to always use fresh variables, and if that's the case why not do this automatically and always be sure we're not colliding. Even using a |
The generated function arguments
m
,n
,o
can conflict with the actual JS values (particularlyn
which is not uncommon as a variable name), causing weird errors.Given a module:
This generates:
The
n
defined in the JavaScript code is shadowing then
defined as the minified argument name.It seems like these generated arguments should be ones that cannot conflict, perhaps with an index/uuid like
n9208
, or__0__
,__1__
, etc..The text was updated successfully, but these errors were encountered: