microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.02k stars 12.49k forks source link

Typescript does not emit names in sourcemap. This breaks this -> _this hover when debugging #14688

Closed nojvek closed 6 years ago

nojvek commented 7 years ago

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx) v2.2.1 Code

// A *self-contained* demonstration of the problem follows...
const test = (inp: string[]) => {
    console.log(this);
    for (let str of inp) {
        console.log(str);
    }
}

test(['1', '2', '3', '4'])

output:

var _this = this;
var test = function (inp) {
    console.log(_this);
    for (var _i = 0, inp_1 = inp; _i < inp_1.length; _i++) {
        var str = inp_1[_i];
        console.log(str);
    }
};
test(['1', '2', '3', '4']);
//# sourceMappingURL=blah.js.map

Sourcemap:

{"version":3,"file":"blah.js","sourceRoot":"","sources":["blah.ts"],"names":[],
"mappings":"AAAA,iBAO0B;AAP1B,IAAM,IAAI,GAAG,UAAC,GAAa;IACvB,OAAO,CAAC,GAAG,CAAC,KAAI,CAAC,CAAC;IAClB,GAAG,CAAC,CAAY,UAAG,EAAH,WAAG,EAAH,iBAAG,EAAH,IAAG;QAAd,IAAI,GAAG,YAAA;QACR,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KACpB;AACL,CAAC,CAAA;AAED,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA"}

Expected behavior: names:[] should be filled with the transpiled names. This breaks debuggers that try to show values when hovering over the variable name. In many cases this in scope refer to _this or _this1 or _this12.

See https://github.com/Microsoft/vscode/issues/12066#issuecomment-287036761

Having names would aid VSCode in giving a better experience for debugging transpiled typescript output

Actual behavior:

names is always empty.

JasonKleban commented 6 years ago

Can this be put on the roadmap?

mhegazy commented 6 years ago

this is a duplicate of https://github.com/Microsoft/TypeScript/issues/9627

typescript-bot commented 6 years ago

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.