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

Next.js 12.0.8 breaks "this" in TS classes #33283

Closed
VladimirMikulic opened this issue Jan 13, 2022 · 1 comment · Fixed by #33201
Closed

Next.js 12.0.8 breaks "this" in TS classes #33283

VladimirMikulic opened this issue Jan 13, 2022 · 1 comment · Fixed by #33201
Assignees
Labels
SWC Related to minification/transpilation in Next.js.

Comments

@VladimirMikulic
Copy link

Run next info (available from version 12.0.8 and up)

Operating System:
Platform: linux
Arch: x64
Version: #51~20.04.1-Ubuntu SMP Fri Jan 7 06:51:40 UTC 2022
Binaries:
Node: 16.13.2
npm: 8.0.0
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.0.8
react: 17.0.2
react-dom: 17.0.2

What version of Next.js are you using?

12.0.8

What version of Node.js are you using?

16.13.2

What browser are you using?

Chrome, Safari, Firefox

What operating system are you using?

Android, IOS, macOS, Windows, Linux

How are you deploying your application?

Vercel

Describe the Bug

After upgrading Next.js from 12.0.7 to 12.0.8, an important system broke at our company.
TypeScript code that had classes like the example below broke, because this became undefined.
(check out "To Reproduce" section)

Expected Behavior

I would expect this in a method to actually refer to the instance of the class and not be undefined.
(as also specified in TS docs)

This code has been in the codebase for quite a while and has survived major Next.js releases, until this minor one :)

To Reproduce

// example.ts
export default class Example {
  readonly status: string;

  constructor({ status }: { status: string }) {
    this.status = status;
  }

  public activate = async (data: string) => {
    // Some code...
    this.status // WHOOPS! Exception thrown - this undefined! (worked fine in 12.0.7)
  };
}
// index.ts
const example = new Example({ status: "GOOD" })
example.activate("some string");
@VladimirMikulic VladimirMikulic added the bug Issue was opened via the bug report template. label Jan 13, 2022
@ijjk ijjk added SWC Related to minification/transpilation in Next.js. kind: bug and removed bug Issue was opened via the bug report template. labels Jan 13, 2022
@kdy1 kdy1 self-assigned this Jan 13, 2022
kdy1 added a commit to swc-project/swc that referenced this issue Jan 14, 2022
swc_ecma_transforms_compat:
 - `async_to_generator`: Fix `this` in async class properties. (vercel/next.js#33283)
 - Add a test for #3228 (Closes #3228).
@kdy1 kdy1 mentioned this issue Jan 14, 2022
@kodiakhq kodiakhq bot closed this as completed in #33201 Jan 14, 2022
kodiakhq bot pushed a commit that referenced this issue Jan 14, 2022
This PR is a bit big because AST definitions are modified recently because previous AST defs were too error-prone.
It will prevent plugin authors from making some common mistakes.


 - Closes #33088
 - Closes #31084
 - Closes #33283
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 13, 2022
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
This PR is a bit big because AST definitions are modified recently because previous AST defs were too error-prone.
It will prevent plugin authors from making some common mistakes.


 - Closes vercel#33088
 - Closes vercel#31084
 - Closes vercel#33283
nevilm-lt pushed a commit to nevilm-lt/next.js that referenced this issue Apr 22, 2022
This PR is a bit big because AST definitions are modified recently because previous AST defs were too error-prone.
It will prevent plugin authors from making some common mistakes.


 - Closes vercel#33088
 - Closes vercel#31084
 - Closes vercel#33283
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants