Skip to content

fix: Account for invalid identifiers#198

Merged
AbhiPrasad merged 4 commits intonodejs:mainfrom
getsentry:abhi-invalid-identifiers
Jun 12, 2025
Merged

fix: Account for invalid identifiers#198
AbhiPrasad merged 4 commits intonodejs:mainfrom
getsentry:abhi-invalid-identifiers

Conversation

@AbhiPrasad
Copy link
Copy Markdown
Member

Node 16 and above allows you to use interesting string identifiers like "module.exports" and "unsigned short" as valid export names.

ref https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

image

This PR accounts for that by updating our shim variable name logic, and adjusting how we do getters and setters so that we don't break when encoutering these "invalid" identifiers.

supercedes #115
resolves #94

If you can, please give this a test locally. I tried it myself on some test apps and worked fine.

@AbhiPrasad AbhiPrasad self-assigned this Jun 11, 2025
hook.js Outdated
} else {
const variableName = `$${n.replace(/[^a-zA-Z0-9_]/g, '_')}`
const objectKey = JSON.stringify(n)
const reExportedName = n === 'default' ? n : objectKey
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default has to be special-cased here, not sure if anything else applies.

@AbhiPrasad
Copy link
Copy Markdown
Member Author

Hmm there are more edge cases I'm missing - drafting this while I figure it out.

@AbhiPrasad AbhiPrasad marked this pull request as draft June 11, 2025 19:11
@AbhiPrasad AbhiPrasad marked this pull request as ready for review June 11, 2025 20:28
@AbhiPrasad
Copy link
Copy Markdown
Member Author

added a version check - this is ready to review now!

Copy link
Copy Markdown
Contributor

@timfish timfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!

@AbhiPrasad AbhiPrasad merged commit 2cc8207 into nodejs:main Jun 12, 2025
51 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-invalid-identifiers branch June 12, 2025 13:17
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

Successfully merging this pull request may close these issues.

Doesn't handle exports with invalid identifiers

3 participants