Repository navigation
bundler: warn about direct eval in ES modules, with one guard for weird-code warnings #46890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
robobun
wants to merge
1
commit into
main
Choose a base branch
from
robobun/9dadacfe/direct-eval-warning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+353
−44
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Users who bundle a minified ES module that calls eval outside node_modules now get a stderr line of the whole minified source plus one space per column, per eval call. The new warning in warn_direct_eval at src/js_parser/p.rs:1043 carries a range on the source line, and the printer at src/ast/lib.rs:1052-1065 echoes the full line text and then pads to the column. Fix: make the warning safe on long lines before it ships, either by landing the printer cap the PR description names (#41658) first or by truncating lineText and the padding in write_format around a window of the column, so every range warning on a minified line stays bounded. The description calls this an ordering dependency, but nothing in this diff enforces it. [also at: src/js_parser/p.rs:1044 - Users who bundle a minified ES module that lives outside node_modules (a vendored .min.js, or the output of a first
bun build --minifyfed into a second build or--compile) now get a ~120-byte window of the line echoed to stderr once per direct eval, plus one space per column, where the base branch printed nothing.]Why this was flagged
A project bundles a prebuilt, minified ESM file that is not under node_modules (for example a vendored lib.min.mjs, or a bundle output from
bun build --minifyre-bundled). The file hasexportorimportand a directeval(call at column N on a one-line source. visit_expr.rs:1924 now calls warn_direct_eval for every such call, and p.rs:1043 attaches a range on that line. Log printing at src/ast/lib.rs:1052-1065 writes the full line text and thenwrite_n_bytes(to, b' ', line_offset_for_second_line), so stderr gets roughly N bytes of source plus N spaces per eval call, with no cap in this diff. On the base branch this file produces no warning so none of this is printed. The author's note says #41658 must merge first, but this checkout has no such cap, so merging in the other order ships the cost.Verification: normal — acknowledged in diff: the bound is accurate for the padding, and nothing in this PR's own commits caps it. Trigger:
bun build(CLI, logLevel >= warn) of a bundled ES module not under node_modules whose source is one long line with a directeval(call.write_n_bytes(to, b' ', line_offset_for_second_line)(lib.rs:1065) then writes that many spaces.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct. It is the second bullet of Downsides.
The cost comes from the log printer and not from this warning.
Location::init_or_null_implcuts the excerpt to about 120 bytes but keeps the column of the whole line, andData::write_formatpads the caret to that column. It also keeps the whole line when the position is in its last 80 bytes. Each located diagnostic on a long line pays this on main. #41658 and #43313 are the fixes. Both need a rebase, and I asked for that.I did not add a bound in this diff:
warn_direct_evalfixes one diagnostic and leaves the printer as it is.To make the order a property of the PR and not only a sentence in its body, this PR is now a draft. It leaves draft when #41658 is merged. I leave this thread open until then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction to my reply above: this PR waits for #43313 too, not only for #41658. #41658 bounds the caret padding. #43313 bounds the excerpt when the position is in the last 80 bytes of the line.
Measured on main with a warning that exists today (a read of a setter-only private name) on a 200 KB line: 200,268 B of stderr in the middle of the line, 400,196 B at its end.
Both PRs are rebased and mergeable now. This PR stays a draft until both are merged.