Skip to content

Exported mutable variable in namespace with setter function does not mutate value #5259

@abrenneke

Description

@abrenneke

Describe the bug

If an export from a namespace is mutable, and a function in the namespace mutates the value, the exported value is not mutated.

Input code

namespace A {
    export let a = 5;

    export function setA(value: number) {
        a = value;
    }
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.2.218&code=H4sIAAAAAAAAA8tLzE0tLkhMTlVwVKjmUgCC1IqC%2FKIShZzUEoVEBVsFU2suZOG00rzkksz8PIXi1BJHjbLEnNJUK4W80tyk1CJNqAEgANIJlrQGC9Vy1QIA8jab8GkAAAA%3D&config=H4sIAAAAAAAAA0WNSwrDMAxE76J1tt3kDj2ESZXg4B8aBWqM7165OGQnzedNoxMbrY2KE7CMCzWp%2B9JKWgtjE1%2BUFlKYtLsA7vY4OVgtwniZF3IGT3eh6JPf6yBtORZh4LFcOsKd7AaK%2BXMNof3HDGiVmNMJ6g9olj3eM61ycf8BnwbyVboAAAA%3D

Expected behavior

tsc output correctly mutates the value:

"use strict";
var A;
(function (A) {
    A.a = 5;
    function setA(value) {
        A.a = value;
    }
    A.setA = setA;
})(A || (A = {}));

Actual behavior

Mutates the variable internal to the namespace but not the exported value from the namespace.

"use strict";
var A;
(function(A) {
    var setA = function setA(value) {
        a = value;
    };
    var a = A.a = 5;
    A.setA = setA;
})(A || (A = {}));

Version

1.2.218

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions