fix(babel): add retainLines to preserve source line numbers#39217
Closed
omarshibli wants to merge 1 commit intomicrosoft:mainfrom
Closed
fix(babel): add retainLines to preserve source line numbers#39217omarshibli wants to merge 1 commit intomicrosoft:mainfrom
omarshibli wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Without `retainLines: true`, babel expands destructured parameters
across multiple lines in the compiled output (e.g. `async ({ page }) =>`
becomes three lines). This causes the Playwright Inspector (PWDEBUG=1)
to highlight wrong source lines, as the compiled line numbers no longer
match the original source. The offset grows with each destructured
parameter pattern, making debugging increasingly inaccurate.
Fixes microsoft#19944, fixes microsoft#26727
Author
|
@microsoft-github-policy-service agree |
Member
|
The tests are already green without the implementation change, and the referenced issues are also marked as fixed before this PR. If you experience a bug, please report it in a bug report first. |
Author
|
hey @Skn0tt , thanks for the input. but i do experience issues with debugging in chrome, the debugger isn't in sync with the source code. and i tried this fix locally fix yarn patch and it did fix my issue. |
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.
Problem
The Playwright Inspector (
PWDEBUG=1) highlights wrong source lines when debugging TypeScript tests that use destructured parameters.Root cause: Playwright's babel transform does not set
retainLines: true. Without it, babel'scompact: falsemode expands destructured parameters across multiple lines in the compiled output:Each destructured pattern with N parameters expands from 1 line to N+2 lines. The Playwright Inspector uses compiled line numbers against the original source file without properly resolving through source maps, causing a cumulative line offset that grows with each destructured parameter pattern. For tests with multiple fixtures, the reported line can be off by 5-10+ lines.
Fix
Add
retainLines: trueto babel transform options inbabelBundleImpl.ts. This tells babel to preserve the original line numbers in the compiled output by keeping statements on their original lines, eliminating the line drift entirely.Testing
Added two test cases to
tests/playwright-test/babel.spec.ts:Line numbers in test report — Verifies that three tests using
async ({ foo, bar, baz }) =>destructured parameters report correct spec line numbers (8, 11, 14) instead of inflated values (~8, ~14, ~20).Error location in test report — Verifies that a failing assertion inside a test with
async ({ foo, bar }) =>reports the correct error line (11) instead of an inflated value.All existing babel tests continue to pass (10/10).
Related Issues
Fixes #19944
Fixes #26727