Skip to content

Gh 41788 incorrect output for esprivate with nested class in esnext - #42663

Merged
Nathan Shively-Sanders (sandersn) merged 7 commits into
microsoft:masterfrom
bloomberg:GH-41788-incorrect-output-for-esprivate-with-nested-class-in-esnext
Apr 7, 2021
Merged

Gh 41788 incorrect output for esprivate with nested class in esnext#42663
Nathan Shively-Sanders (sandersn) merged 7 commits into
microsoft:masterfrom
bloomberg:GH-41788-incorrect-output-for-esprivate-with-nested-class-in-esnext

Conversation

@dragomirtitian

Copy link
Copy Markdown
Contributor

Fixes#41788

Fixed as described in comment

  1. If target:esnext,then useDefineForClassFields: true will now be the default.
  2. If target:esnext, useDefineForClassFields: true we emit correct code so no further action is needed (ex)
  3. If target:esnext, useDefineForClassFields: false and we encounter a usage of a #private field in a static member we emit an error like "You can't do this, change useDefineForClassFields: true, or target an earlier version of ES."

@typescript-botTypeScript Bot (typescript-bot) added the For Milestone Bug PRs that fix a bug with a specific milestone label Feb 5, 2021
@dragomirtitian
Titian Cernicova-Dragomir (dragomirtitian) marked this pull request as ready for review February 5, 2021 16:11
Comment threadsrc/compiler/diagnosticMessages.json Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's missing a check that the property is static.

Comment threadsrc/compiler/diagnosticMessages.json Outdated
Comment threadsrc/compiler/checker.ts
Comment threadsrc/compiler/checker.ts Outdated
@dragomirtitian

Copy link
Copy Markdown
ContributorAuthor

Nathan Shively-Sanders (@sandersn) Thank you for the review. I fixed the issues. Let me know if there are any others changes I should make.

@sandersn

Copy link
Copy Markdown
Member

Titian Cernicova-Dragomir (@dragomirtitian) Sorry for the delay on this. I tried merging from master but there are some changes in the emit that were so complex that I couldn't tell whether they were correct. Can you take a look? I'll merge after that.

@ExE-Boss

Copy link
Copy Markdown
Contributor

This also fixed #34787

Haoqun Jiang (haoqunjiang) added a commit to haoqunjiang/vite that referenced this pull request Jul 14, 2021
Since TypeScript 4.3, `target: "esnext"` indicates that
`useDefineForClassFields: true` as the new default.
See <microsoft/TypeScript#42663>
So I'm explicitly adding this field to the tsconfigs to avoid any
confusions.
Note that `lit-element` projects must use
`useDefineForClassFields: false` because of <https://github.com/lit/lit-element/issues/1030>
Vue projects must use `useDefineForClassFields: true` so as to support
class style `prop` definition in `vue-class-component`:
<vuejs/vue-class-component#465>
Popular React state management library MobX requires it to be `true`:
<https://mobx.js.org/installation.html#use-spec-compliant-transpilation-for-class-properties>
Other frameworks seem to have no particular opinion on this.
So I turned it on in all templates except for the `lit-element` one.
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone BugPRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Incorrect output for #private with nested class in ESNext

5 participants

@dragomirtitian@sandersn@ExE-Boss@DanielRosenwasser@typescript-bot