Skip to content

Optional chaining with function call is compiled incorrectly #2063

@chuanqisun

Description

@chuanqisun

Describe the bug
In the compiled output, instead of calling the function, the function body is returned.

In the screenshot:
Upper left: source code
Bottom left: swc cli compiler output
Upper right: running source directly in browser, output is correct
Bottom right: running compiled code directly in browser, output is wrong

image

Input code

const myVar = {
  target: {
    value: "ABC"
  }
}

console.log(myVar.target.value.toLowerCase?.());

Config

No config. Running CLI from command line without any flags.

npx swc example.ts

Expected behavior
The console log should output abc

Version
The version of @swc/core: "1.2.76"

Additional context

Thank you for maintaining this project. The speed is insane.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions