Skip to content

fix(babel): add retainLines to preserve source line numbers#39217

Closed
omarshibli wants to merge 1 commit intomicrosoft:mainfrom
omarshibli:fix/babel-retain-lines
Closed

fix(babel): add retainLines to preserve source line numbers#39217
omarshibli wants to merge 1 commit intomicrosoft:mainfrom
omarshibli:fix/babel-retain-lines

Conversation

@omarshibli
Copy link

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's compact: false mode expands destructured parameters across multiple lines in the compiled output:

// Source (1 line):
test('my test', async ({ page }) => {

// Compiled without retainLines (3 lines):
test('my test', async ({
  page
}) => {

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: true to babel transform options in babelBundleImpl.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:

  1. 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).

  2. 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

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
@omarshibli
Copy link
Author

@microsoft-github-policy-service agree

@Skn0tt
Copy link
Member

Skn0tt commented Feb 11, 2026

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.

@Skn0tt Skn0tt closed this Feb 11, 2026
@omarshibli
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong line numbers in playwright inspector with cucumber.js [BUG] Playwright inspector highlights the wrong line of code (with cucumber.js)

2 participants

Comments