Skip to content

es/module: Export of __proto__ is lost during transpilation due to object property handling #10419

@magic-akari

Description

@magic-akari

Describe the bug

A property definition of the form __proto__: value or "__proto__": value does not create a property with the name __proto__. Instead, if the provided value is an object or null, it points the [[Prototype]] of the created object to that value. (If the value is not an object or null, the object is not changed.)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#prototype_setter

Input code

export const __proto__ = 1;
export const another = 2;

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
    },
    "target": "es2024"
  },
  "module": {
    "type": "commonjs"
  },
  "isModule": true
}

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.11.24&code=H4sIAAAAAAAAA0utKMgvKlFIzs8rLlGIjy8oyi%2FJj49XsFUwtOZKRZZLzMsvyUgtAsoYWQMAbei9ajUAAAA%3D&config=H4sIAAAAAAAAA0WMSwqAMAxE9z1FydqFiCvv4CFKDWKxtiQpWMS7W%2F%2BrzJt5ZFNag2MLnd5KLBANMdLHpeG8iFlLA2i9YUtTFKiudb8PiKER5VK4qZsW1LOBD0Oa8X8vOZ4ENngfFse%2FOXH%2FukIJ1X4AjE9B8pwAAAA%3D

SWC Info output

No response

Expected behavior

The __proto__ name should be exported as a named binding.

Actual behavior

_export(exports, {
    __proto__: function() {
        return __proto__;
    },
    another: function() {
        return another;
    }
});

__proto__ is recognized as the prototype setter and is not exported.

Version

1.11.24

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions