Skip to content

fix: guard atob global reference in @stdlib/string/base/atob#13018

Draft
Planeshifter wants to merge 2 commits into
developfrom
philipp/ci-fix-atob-global-undefined-2026-06-21
Draft

fix: guard atob global reference in @stdlib/string/base/atob#13018
Planeshifter wants to merge 2 commits into
developfrom
philipp/ci-fix-atob-global-undefined-2026-06-21

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • Fixes ReferenceError: atob is not defined thrown during module load on Node.js v12 and v14.

On those versions, atob is not a global (added in Node.js v16.0.0). lib/node_modules/@stdlib/string/base/atob/lib/global.js previously exported the bare identifier atob at require-time, crashing before any feature detection could run. The fix wraps the reference in a typeof guard, which never throws for undeclared identifiers, and exports null on environments lacking native atob. The existing try/catch in main.js handles 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

Does this pull request have any related issues?

None.

Questions

Any questions for reviewers?

No.

Other

Any other information relevant?

No.

Checklist

AI Assistance

  • Yes
  • No

If yes, how:

  • Code generation
  • Test/benchmark generation
  • Documentation
  • Research and understanding

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

`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
@stdlib-bot

stdlib-bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/atob $\\color{green}217/217$
$\\color{green}+100.00\\%$
$\\color{red}11/12$
$\\color{green}+91.67\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}217/217$
$\\color{green}+100.00\\%$

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
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.

3 participants