Skip to content

fix(core): drop a leading byte order mark before parsing - #858

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/issue-846
Oct 17, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/issue-846

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Closes #846

Problem

A file that starts with a byte order mark followed by a shebang failed to load under oxc-node with Invalid Character '!', while plain Node.js runs it. The oxc parser follows the spec: a hashbang is recognised only at the very start of the source, and a BOM counts as whitespace. Hosts strip the mark first: Node.js's CommonJS loader uses stripBOM, its ES module loader decodes with TextDecoder, and oxc's own linter and formatter strip it as well. oxc-node passed it through.

Fix

strip_bom drops one leading U+FEFF wherever oxc-node parses a file:

  • oxc_transform, which serves the load hook, the require() hook and the public transform API;
  • the parse that decides whether an ambiguous .js/.ts file runs as an ES module;
  • the .cts module-syntax check.

Code frames and source-map positions are computed against the stripped text. Node counts line and column numbers the same way, so a stack trace through a file with a BOM matches the same file without one.

Tests

  • A Rust unit test checks that the parser rejects BOM + #! and accepts it once the mark is stripped (with the hashbang recognised). It also checks that only one mark is dropped.
  • bom.spec.ts covers ES module entries (.ts, .mts, .js, .mjs), CommonJS entries (.ts, .cts), a .ts file loaded with require(), a BOM without a shebang, and stack-trace lines matching the BOM-less file. 6 of these fail without the change.

πŸ€– Generated with Claude Code

A hashbang is only one at the very start of the source, and the parser
takes a BOM for whitespace, so a file saved with a BOM before its `#!`
failed with `Invalid Character '!'`. Node.js drops the mark before
compiling, in its CommonJS loader (stripBOM) and its ES module loader
(TextDecoder), as do oxc's linter and formatter. Strip one leading U+FEFF
wherever oxc-node parses a file: the transform behind the load hook, the
require() hook and the public API, and the parse that decides whether an
ambiguous file runs as an ES module.

Closes #846

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
πŸ“ Code Review βœ… Completed 2026-10-17T04:05:54.493124Z 62fe057 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with πŸ‘€ while any review is running, comments if it has suggestions, and reacts with πŸ‘ once all reviews finish with no findings.

@Brooooooklyn
Brooooooklyn merged commit 440c31f into main Oct 17, 2026
67 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/issue-846 branch October 17, 2026 04:18
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.

A byte order mark before a shebang makes the file fail to parse

1 participant