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

Incorrect ES5 transpilation for try/catch + super #55646

Closed
nevedaren opened this issue Sep 6, 2023 · 3 comments Β· Fixed by #56130
Closed

Incorrect ES5 transpilation for try/catch + super #55646

nevedaren opened this issue Sep 6, 2023 · 3 comments Β· Fixed by #56130
Assignees
Labels
Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript Fix Available A PR has been opened for this issue

Comments

@nevedaren
Copy link

nevedaren commented Sep 6, 2023

πŸ”Ž Search Terms

ES5, this alias

πŸ•— Version & Regression Information

  • This changed between versions 5.1.6 and 5.2.2

⏯ Playground Link

https://www.typescriptlang.org/play?target=1&ts=5.2.2#code/IYIwzgLgTsDGEAJYBthjAgYge2wg3gFAJLYB2kUArvNlABRgAW2VyAJgCpNTYDuALgQhcyAKbAyASgLESCAJYAzBIxZsuPfjKLz5ELXwRkxRgKJReDAOQAFcWjEIoY6AE9rUgNxySAXwQxZDAnXT1SCmxxADpkbABzemsAeQBpTx89Pzls7MIUNAwAIWAoQIAPCDEydgwcPDDYckoaCDp6HV8Ed1lwhDAqAAcxBmgqMW8ugNhgCFgmVTEhKjIAazJ+aV7wpsiYuMTrCyshawQAakWENARjuilogFsxdGB4iczwgHov51coNxdEgDYYMJTAYIfKY5Qh5ExGEoMbxAA

πŸ’» Code

// @target: es5
// @showEmit: true

abstract class Foo {
  constructor(shouldThrow: boolean) {
    if (shouldThrow) {
      throw new Error('Please retry');
    } else {
      console.log('OK');
    }
  }
}

class Bar extends Foo {
  constructor() {
    try {
      super(true);
    } catch (e: unknown) {
      console.log('Error: ' + (e as Error).message);
      // retry
      super(false);
    }
  }
}

new Bar();

Target: ES5

πŸ™ Actual behavior

_this is not defined 

πŸ™‚ Expected behavior

No error

Additional information about the issue

In TS5.2.2 output var _this = this; has been removed, but _this is still being used.

@fatcerberus
Copy link

fatcerberus commented Sep 6, 2023

Probably related to as #55637, as both involve a use of this (though indirectly, in this case) in a class constructor which broke in 5.2.

edit: Just realized you posted that other issue too πŸ˜†

@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript labels Sep 7, 2023
@typescript-bot
Copy link
Collaborator

The change between v5.1.6 and v5.2.2 occurred at f9cf821.

@andrewbranch
Copy link
Member

Same bisect result, so probably the same thing as #55637

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants