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

Why are there long underscores before the names in the output code? #344

Open
lissettecarlr opened this issue Feb 25, 2025 · 3 comments
Open

Comments

@lissettecarlr
Copy link

Input a segment:

{feed:l,reset:o}

output a segment:

feed: ________________________________________________________________handleTextInput,
reset: initializeInputState,

Image

@0xdevalias
Copy link
Contributor

0xdevalias commented Feb 26, 2025

I would suspect that there were a lot of name clashes, and this safe rename code is what's doing it:

const renamed = await visitor(smallestScopeNode.name, surroundingCode);
if (renamed !== smallestScopeNode.name) {
let safeRenamed = toIdentifier(renamed);
while (
renames.has(safeRenamed) ||
smallestScope.scope.hasBinding(safeRenamed)
) {
safeRenamed = `_${safeRenamed}`;
}
renames.add(safeRenamed);
smallestScope.scope.rename(smallestScopeNode.name, safeRenamed);
}

Some past discussion related to this feature here as well:

Instead of just prefixing with _ each time there is a clash, it might be better to generate some kind of suffix like foo$1, foo$2, etc; which has also been mentioned in the past:

And some other related issues/PRs:

Also.. off the top of my head.. since we're tracking renames against the entire program, rather than just per scope, it means that if there is a similarly named variable anywhere in the program, it will be disallowed, and thus get an extra _ prefix.

const renames = new Set<string>();

While this can obviously make it easier to not have to think about scope rules/shadowing while quickly skimming through a file, in cases like this, it clearly makes things worse. This issue is tangentially related to that area of the code:

@lissettecarlr
Copy link
Author

Thank you for your reply.
I checked the source code and indeed found numerous variables with the same character names. The main issue is that the single-page code is too long, causing the underscores to stack up infinitely.

@0xdevalias
Copy link
Contributor

It might be worth leaving this issue open as a reminder that we could improve this based on some of the notes above.

@lissettecarlr lissettecarlr reopened this Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants