fix: guard atob global reference in @stdlib/string/base/atob#13018
Draft
Planeshifter wants to merge 2 commits into
Draft
fix: guard atob global reference in @stdlib/string/base/atob#13018Planeshifter wants to merge 2 commits into
atob global reference in @stdlib/string/base/atob#13018Planeshifter wants to merge 2 commits into
Conversation
`global.js` exported the bare `atob` identifier at module evaluation
time (`module.exports = atob`). On Node.js v12 and v14, `atob` is
not a global — it was added in Node.js v16.0.0 — so loading the
module threw `ReferenceError: atob is not defined`. Because `index.js`
eagerly requires `./main.js` before calling `hasAtobSupport()`, the
polyfill branch was structurally unreachable: the process crashed
during the require phase.
Replace the bare reference with a typeof guard:
var main = ( typeof atob === 'function' ) ? atob : null;
This mirrors the pattern already used in
`@stdlib/assert/has-atob-support/lib/atob.js`. On Node.js v12/v14,
`global.js` now exports `null`; `main.js`'s existing try/catch
absorbs the null-call TypeError and returns null. On v16+, the
native `atob` is exported unchanged, restoring prior behavior.
Ref: https://github.com/stdlib-js/stdlib/actions/runs/27901198731
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
…@stdlib/string/base/atob` The `atob` global is intentionally referenced inside a `typeof` guard to detect its availability. The eslint rule `n/no-unsupported-features/node-builtins` does not understand that this is a feature-detection pattern rather than an unsupported usage, so suppress it inline. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116goNvkDr7ZQ7w5vpvseiw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
ReferenceError: atob is not definedthrown during module load on Node.js v12 and v14.On those versions,
atobis not a global (added in Node.js v16.0.0).lib/node_modules/@stdlib/string/base/atob/lib/global.jspreviously exported the bare identifieratobat require-time, crashing before any feature detection could run. The fix wraps the reference in atypeofguard, which never throws for undeclared identifiers, and exportsnullon environments lacking nativeatob. The existing try/catch inmain.jshandles the null case correctly. Pattern matches@stdlib/assert/has-atob-support/lib/atob.js.Failing CI runs (develop, 2026-06-21): https://github.com/stdlib-js/stdlib/actions/runs/27901198731
Related Issues
None.
Questions
No.
Other
No.
Checklist
AI Assistance
If yes, how:
Disclosure
This PR was prepared with the assistance of Claude (claude-sonnet-4-6). Root cause identification, fix implementation, and three-reviewer validation were AI-assisted. The fix was verified against existing codebase patterns in
@stdlib/assert/has-atob-support/lib/atob.js.@stdlib-js/reviewers
Generated by Claude Code