Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use private fields #8506

Merged
merged 1 commit into from Jun 13, 2022
Merged

chore: use private fields #8506

merged 1 commit into from Jun 13, 2022

Conversation

jrandolf
Copy link
Contributor

@jrandolf jrandolf commented Jun 10, 2022

This PR changes all underscored fields/methods into private fields and underscores (and labels as internal) all cross-module, camelCase, internal fields/variables/methods.

@jrandolf jrandolf requested a review from OrKoN June 10, 2022 17:02
@jrandolf jrandolf force-pushed the private branch 5 times, most recently from 54844ad to 8e34383 Compare June 10, 2022 20:30
.eslintrc.js Show resolved Hide resolved
@smashah
Copy link

smashah commented Jun 22, 2022

I understand that this is js convention, however what other reasoning is there for this PR? Lots of dependent projects need to use HTTPRequest._client or Page._client.

@OrKoN
Copy link
Collaborator

OrKoN commented Jun 22, 2022

@smashah to maintain the project we want to clearly separate the public API from internals. In this case, dependent projects were using the undocumented internal API. Please file a issue for your use case and we will try to expose the API in a documented and sustainable way. Btw, the Page._client() is still there.

@smashah
Copy link

smashah commented Jun 22, 2022

Thanks for the explanation @OrKoN

I have submitted #8545 to resolve an urgent use case

@casey6
Copy link

casey6 commented Jul 5, 2022

I was a little disappointed to discover that this breaking change made it into a minor release (14.4.0) completely undocumented and missing from the release notes.

I have some simple code that proxies a Page instance, which now throws a type error Cannot read private member from an object whose class did not declare it. 😞

@jrandolf
Copy link
Contributor Author

jrandolf commented Jul 5, 2022

@casey6 This is not a breaking change unless you use internal code which is always subject to breaking changes. If there is public behavior that we amended, please submit an issue and we can try to accommodate. That being said, we do have some places unlabeled with @internal, so that also might have been the problem. If such is the case, we apologize.

@casey6
Copy link

casey6 commented Jul 5, 2022

I'm simply proxying the page instance, not using any internal code:

const proxiedPage = new Proxy(page, {
  get(page, property) {
    // intercept screenshot calls to override the path property
    if (property === 'screenshot') {
      return async (options = {}) => {
        const filename = options.path?.split('/').pop() ?? `${Date.now()}.png`

        return await page.screenshot({
          ...options,
          path: `/path/to/${filename}`
        })
      }
    }

    return page[property]
  }
})

@jrandolf
Copy link
Contributor Author

jrandolf commented Jul 5, 2022

Ah, I see... This is a well-known issue: tc39/proposal-class-fields#106. If I recall, there is a solution using inheritance.

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.

None yet

4 participants