Skip to content

Getters/Setters with Object.defineProperty #7

@artfiedler

Description

@artfiedler

Bug report

Input code

// This will be an internal class determined by entry point
export class testProperties {
    private _salad: number = 0;
    public dressing: number = 0;
    public get salad(): number { return this._salad; }
    public set salad(val: number) { this._salad = val; }
}

var test = new testProperties();
test.salad = 0;
test.dressing = 0;
var totalSalad = test.salad + 1;
var totalDressing = test.dressing + 0;

Expected output

(function(exports){
exports.testProperties = void 0;
    var testProperties = (function () {
        function testProperties() {
            this._private__salad = 0;
            this._internal_dressing = 0;
        }
        Object.defineProperty(testProperties.prototype, "_internal_salad", {
            get: function () { return this._private__salad; },
            set: function (val) { this._private__salad = val; },
            enumerable: false,
            configurable: true
        });
        return testProperties;
    }());
    exports.testProperties = testProperties;
    var test = new testProperties();
    test._internal_salad = 0;
    test._internal_dressing = 0;
    var totalSalad = test._internal_salad + 1;
    var totalDressing = test._internal_dressing + 0;
})(output);

Actual output

(function(exports){
exports.testProperties = void 0;
    var testProperties = (function () {
        function testProperties() {
            this._private__salad = 0;
            this._internal_dressing = 0;
        }
        Object.defineProperty(testProperties.prototype, "salad", {
            get: function () { return this._private__salad; },
            set: function (val) { this._private__salad = val; },
            enumerable: false,
            configurable: true
        });
        return testProperties;
    }());
    exports.testProperties = testProperties;
    var test = new testProperties();
    test._internal_salad = 0;
    test._internal_dressing = 0;
    var totalSalad = test._internal_salad + 1;
    var totalDressing = test._internal_dressing + 0;
})(output);

Additional context
The "salad" argument of Object.defineProperty was not renamed to "_internal_salad"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions