Skip to content

Incorrect ES5 transpilation for try/catch + superΒ #55646

@nevedaren

Description

@nevedaren

πŸ”Ž 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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions