Skip to content

fix(transform): strip TypeScript declare class fields before class-features plugins run#41624

Merged
dgozman merged 2 commits into
microsoft:mainfrom
Git-Raini:fix-38586
Jul 7, 2026
Merged

fix(transform): strip TypeScript declare class fields before class-features plugins run#41624
dgozman merged 2 commits into
microsoft:mainfrom
Git-Raini:fix-38586

Conversation

@Git-Raini

Copy link
Copy Markdown
Contributor

Fixes #38586

  • babelBundle applies TypeScript stripping via a preset, and Babel always runs plain plugins before presets regardless of list order, so class-features plugins (decorators, class-properties) saw declare class fields before TypeScript stripping removed them, throwing a SyntaxError
  • Reordering the preset directly would fix this but breaks constructor-parameter-property vs class-field-initializer injection ordering (issue [regression] 1.32 beta POMs don't work #21794), so instead added a small dedicated pre-pass plugin that strips declare-flagged class fields before the class-features plugins run

…atures plugins run

Babel merges plugins and presets into a single traversal, always running
plain plugins before presets regardless of list order. Our TypeScript
stripping is applied via @babel/preset-typescript (a preset), so the
class-features plugins (decorators/class-properties/private-methods) ran
before it and choked on not-yet-stripped `declare` class fields.

Reordering @babel/preset-typescript into the plugins list fixes that crash,
but breaks the relative ordering between TypeScript constructor-parameter-
property assignments and class field initializers (a real regression caught
by the existing "should be able to access |this| inside class properties"
test), since both rely on unshifting into the constructor and the insertion
order flips.

Instead, add a small dedicated plugin that only strips `declare` class
fields, and run it before the class-features plugins, leaving the rest of
the pipeline (and its ordering) unchanged.

Fixes: microsoft#38586
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Cover the declare-vs-initializer field ordering (issue microsoft#21794) so the
test guards against a preset-reordering regression, and simplify the
explanatory comment in babelBundle.

Fixes: microsoft#38586
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [chromium] › mcp/annotate.spec.ts:110 › should abort annotation when last screenshot is removed @mcp-macos-latest-chromium

7708 passed, 1235 skipped


Merge workflow run.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

7 flaky ⚠️ [chromium-library] › library/chromium/chromium.spec.ts:211 › should intercept service worker requests (main and within) `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/video.spec.ts:275 › screencast › should capture navigation `@chromium-ubuntu-22.04-node20`
⚠️ [chromium-library] › library/inspector/recorder-api.spec.ts:120 › should type `@chromium-ubuntu-22.04-node22`
⚠️ [firefox-library] › library/heap.spec.ts:223 › should not leak workers `@firefox-ubuntu-22.04-node20`
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:118 › should collapse repeated console messages for test `@ubuntu-latest-node22`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:189 › should show snapshots for steps `@windows-latest-node22`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:827 › should update state on subsequent run `@windows-latest-node22`

49497 passed, 1164 skipped


Merge workflow run.

@dgozman dgozman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for the PR!

@dgozman dgozman merged commit c4c1b66 into microsoft:main Jul 7, 2026
47 of 48 checks passed
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.

[Bug]: Cannot run TypeScript files with "declare"

2 participants