Skip to content

@rollup/plugin-typescript Doesn't properly transform syntax if .js files are being bundled #1896

@jbhammon

Description

@jbhammon

Expected Behavior

With target: "ES2018", the TypeScript plugin should transform:

  • obj.prop?.nested(obj.prop == null ? void 0 : obj.prop.nested)
  • obj.timeout ??= valueobj.timeout = obj.timeout ?? value

Actual Behavior

When using @rollup/plugin-typescript with target: "ES2018", optional chaining (?.) and nullish coalescing assignment (??=) operators are not being transformed to ES2018-compatible syntax, even though these features were introduced in ES2020.

The optional chaining and nullish coalescing operators remain unchanged in the output, making the code incompatible with ES2018 environments.

This appears to be the case when .js files are involved in bundling. The attached example starts with a JavaScript file, but it's not clear to me if this issue will appear if you start bundling from a .ts file that imports something from a .js file as well.

Additional Information

I included a README in the StackBlitz reproduction with a few more details.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions