test(minifier): extend legal-comment coverage for #19750 and #19748#21951
Merged
Dunqing merged 3 commits intooxc-project:fix/minifier-preserve-legal-comments-on-inlinefrom Apr 30, 2026
Conversation
…ect#19750 Pins three DCE-orphan scenarios beyond the omnibus `preserve_legal_comment_when_dce_removes_anchor` test: * `/* @license */` standalone (no `!`) — the only legal-comment marker the omnibus test doesn't already pin. * Multi-declarator pruning: `b` removed, then `a` inlined, leaving no declarator. Pins that the legal comment orphans the same as the single-declarator case. * Nested orphan in a surviving function whose own outer anchor is also DCE'd — pins that the inner orphan flushes at the inner block's next surviving statement, not at the outer scope.
…moval The codegen-side fix in 6d697da (`print_legal_orphans_before` flushing at every statement boundary) also resolves the legal-comment subset of issue oxc-project#19748: a legal comment anchored to a removed program-level or inner-function `"use strict"` directive is rescued at the next surviving statement instead of being silently dropped. Pin two cases — top-of-file banner above a removed program-level directive (both `//!` and `/*!` forms), and an inner-function legal comment when the redundant inner `"use strict"` is dropped under a strict outer scope. Documents (in a comment) that the non-legal subset of oxc-project#19748 is *not* covered: `print_legal_orphans_before` is gated on `Comment::is_legal()` by design, and closing the regular-comment case would need a separate `Normalize`-side comment remap.
32d8855 to
2ca3a6b
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
After the refactor of oxc-project#21575's omnibus `preserve_legal_comment_when_dce_removes_anchor`, two of the additional tests in this branch became mechanism-redundant: * `preserve_legal_comment_when_dce_removes_one_of_multiple_declarators` exercised the multi-declarator AST-mutation path, but the codegen-side orphan flush is identical to the single-declarator case the parent already pins. * `preserve_legal_comments_when_dce_removes_anchors_at_multiple_levels` asserted the inner orphan stays scoped when both inner and outer anchors are removed. The parent already pins the per-scope flush keeping the inner orphan inside the function with one orphan; adding an outer orphan exercises the same mechanism. The remaining three tests (`/* @license */` standalone, and the two `"use strict"`-removal tests for the legal-comment subset of oxc-project#19748) each cover behaviour the parent omnibus doesn't reach.
5f0dcb8
into
oxc-project:fix/minifier-preserve-legal-comments-on-inline
35 checks passed
Dunqing
pushed a commit
that referenced
this pull request
Apr 30, 2026
…21951) What --- Three tests on top of #21575: In `dead_code_elimination.rs`: - `/* @license */` standalone — the only legal-comment marker the omnibus `preserve_legal_comment_when_dce_removes_anchor` doesn't pin. In `normalize.rs`, covering the legal-comment subset of #19748 that #21575 also closes: - Banner above a removed program-level `"use strict"`. - Inner-function `"use strict"` removal preserving its inner legal comment. The placement quirk for the legal-comment subset of #19748 is pinned separately in #21943.
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.
What
Three tests on top of #21575:
In
dead_code_elimination.rs:/* @license */standalone — the only legal-comment marker the omnibuspreserve_legal_comment_when_dce_removes_anchordoesn't pin.In
normalize.rs, covering the legal-comment subset of #19748 that #21575 also closes:"use strict"."use strict"removal preserving its inner legal comment.The placement quirk for the legal-comment subset of #19748 is pinned separately in #21943.