fix(playwright): add retainLines to preserve source line numbers#39257
Closed
omarshibli wants to merge 2 commits intomicrosoft:mainfrom
Closed
fix(playwright): add retainLines to preserve source line numbers#39257omarshibli wants to merge 2 commits intomicrosoft:mainfrom
omarshibli wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Without retainLines, babel expands destructured parameters across
multiple lines causing cumulative line drift in compiled output:
Source line 7: test('first', async ({ foo, bar, baz }) => {
Source line 10: test('second', async ({ foo, bar, baz }) => {
Source line 13: test('third', async ({ foo, bar, baz }) => {
Compiled without retainLines:
Line 9: test('first', async ({ (+2 drift)
Line 16: test('second', async ({ (+6 drift)
Line 23: test('third', async ({ (+10 drift)
This breaks the Playwright Inspector (PWDEBUG=1) which uses compiled
line numbers from captureRawStack() to highlight lines in the source
file via metadata.location in the Recorder.
Author
|
I've made previous attempt to fix it here #39217 but got it rejected, i've revisited the tests and fix the issues raised in the previous PR. |
Member
|
As per #39217 (comment), please start with filing a bug report. Thank you. |
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
Babel's
compact: falseexpands destructured parameters across multiple lines in the compiled output, causing cumulative line drift:Each destructured pattern with N parameters expands from 1 line to N+2 lines. The drift grows with each pattern, compounding across the file.
Why source maps alone don't cover this
While
sourceMapSupportcorrectly resolves line numbers in the test report path (wrapFunctionWithLocation→sourceMapSupport.wrapCallSite), the Playwright Inspector (PWDEBUG=1) uses a different code path:captureRawStack()capturesError.stack→parseStackFrame()extracts line numbersmetadata.locationto the serverRecorder._updateUserSources()usesmetadata.location.linedirectly to highlight lines in the source fileAdditionally,
retainLines: truemakes the source map trivially correct (1:1 line mapping), eliminating any potential for source map inaccuracies with complex transformations.Fix
One-line change: add
retainLines: trueto babel transform options. This tells babel to keep statements on their original lines, preserving line number alignment between source and compiled output.Test
The test calls
babelTransform()directly and verifies thattest()calls with destructured TypeScript parameters remain on their original source lines (7, 10, 13) in the compiled output. This test fails withoutretainLines: true(lines shift to 9, 16, 23).Related Issues