Repository navigation
fix(core): drop a leading byte order mark before parsing - #858
Merged
Merged
Conversation
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>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
βΉοΈ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with π while any review is running, comments if it has suggestions, and reacts with π once all reviews finish with no findings. |
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.
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 usesstripBOM, its ES module loader decodes withTextDecoder, and oxc's own linter and formatter strip it as well. oxc-node passed it through.Fix
strip_bomdrops one leading U+FEFF wherever oxc-node parses a file:oxc_transform, which serves the load hook, therequire()hook and the publictransformAPI;.js/.tsfile runs as an ES module;.ctsmodule-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
#!and accepts it once the mark is stripped (with the hashbang recognised). It also checks that only one mark is dropped.bom.spec.tscovers ES module entries (.ts,.mts,.js,.mjs), CommonJS entries (.ts,.cts), a.tsfile loaded withrequire(), 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