Skip to content

fix: add isClassPrivateMethod() to esm-transformer - #300

Closed
nytamin wants to merge 1 commit into
yao-pkg:mainfrom
nytamin:fix/class-private-method
Closed

nytamin wants to merge 1 commit into
yao-pkg:mainfrom
nytamin:fix/class-private-method

Conversation

@nytamin

@nytamin nytamin commented Sep 7, 2026

Copy link
Copy Markdown

Bug fix

This PR adds the check isClassPrivateMethod() to the detectESMFeatures topLevelAwait checks, to exclude private-hashtag-methods from bein considered top-level.

Background

I found a bug where I got the message path/to/file.js has both top-level await and export statements..., even though I had reduced the file in question to be simply:

export class MyClass {
  async #myMethod() {
    await Promise.resolve()
  }
}

Adding parent.isClassPrivateMethod() to the checks fixed the issue for me locally.

To fix a bug where an await in a hastag-private-method resulting in the error message "..has both top-level await and export statements"
@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.23%. Comparing base (30924f0) to head (04c2924).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #300   +/-   ##
=======================================
  Coverage   87.23%   87.23%           
=======================================
  Files          23       23           
  Lines        7929     7931    +2     
  Branches     1214     1215    +1     
=======================================
+ Hits         6917     6919    +2     
  Misses       1005     1005           
  Partials        7        7           
Files with missing lines Coverage Δ
lib/esm-transformer.ts 88.07% <100.00%> (+0.05%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@robertsLando
robertsLando enabled auto-merge (squash) September 28, 2026 13:23
@robertsLando

Copy link
Copy Markdown
Member

Thanks @nytamin for finding and reporting this! Closing as a duplicate of #307, which fixes the same bug by using Babel's parent.isFunction() alias. That alias covers ClassPrivateMethod plus every other function-like node, so no other function kind can slip through later. #307 also adds a unit test for this case.

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.

2 participants