-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help debuggers by not emitting loop bodies in new functions/classes? #61111
Comments
Which emit are you referring to (i.e. what's the input code that's causing this)? |
Again quoting the devtools discussion, TS source: private hideRadiosAndSetDiff() {
const root = unwrap(this.modal).find('.historiccode');
const items = root.find('li:not(.template)');
let foundbase = false;
let foundcomp = false;
for (const elem of items) { // breakpoint 1
const li = $(elem); // breakpoint 2
const dt = li.data('dt');
const base = li.find('.base');
const comp = li.find('.comp');
let baseShouldBeVisible = true;
let compShouldBeVisible = true;
if (comp.prop('checked')) {
foundcomp = true;
baseShouldBeVisible = false;
const itemRight = this.currentList.find(item => item.dt === dt);
if (itemRight) {
unwrap(this.rhs).update(itemRight);
}
} else if (base.prop('checked')) {
foundbase = true;
const itemLeft = this.currentList.find(item => item.dt === dt);
if (itemLeft) {
unwrap(this.lhs).update(itemLeft);
}
}
if (foundbase && foundcomp) {
compShouldBeVisible = false;
} else if (!foundbase && !foundcomp) {
baseShouldBeVisible = false;
}
if (compShouldBeVisible) {
comp.css('visibility', '');
} else {
comp.css('visibility', 'hidden');
}
if (baseShouldBeVisible) {
base.css('visibility', '');
} else {
base.css('visibility', 'hidden');
}
}
} Uglified transpiled JS: e.prototype.hideRadiosAndSetDiff = function() {
var e, t, i = (0,
l.unwrap)(this.modal).find(".historiccode").find("li:not(.template)"), r = !1, s = !1, a = function(e) {
var t = (0,
n.default)(e) // breakpoint 2
, i = t.data("dt")
, o = t.find(".base")
, a = t.find(".comp")
, c = !0
, d = !0;
if (a.prop("checked")) {
s = !0,
c = !1;
var p = u.currentList.find((function(e) {
return e.dt === i
}
));
p && (0,
l.unwrap)(u.rhs).update(p)
} else if (o.prop("checked")) {
r = !0;
var g = u.currentList.find((function(e) {
return e.dt === i
}
));
g && (0,
l.unwrap)(u.lhs).update(g)
}
r && s ? d = !1 : r || s || (c = !1),
d ? a.css("visibility", "") : a.css("visibility", "hidden"),
c ? o.css("visibility", "") : o.css("visibility", "hidden")
}, u = this;
try {
for (var c = o.__values(i), d = c.next(); !d.done; d = c.next()) { // breakpoint 1
a(d.value)
}
} catch (t) {
e = {
error: t
}
} finally {
try {
d && !d.done && (t = c.return) && t.call(c)
} finally {
if (e)
throw e.error
}
}
} |
The function body here is necessary to get the correct A really good alternative is to target ES6+, which virtually every runtime (and certainly any runtime running on a dev machine) supports |
Thank you for the suggestion, but I actually see zero diff in JS when changing tsconfig to
|
That's a configuration error on your side then (of whatever tooling you use besides TypeScript). |
π Search Terms
debugging debugger watch scope
β Viability Checklist
β Suggestion
Here is a typical situation while debugging TS code:
(in this case with chrome devtools).
A variable whose scope is larger than a certain loop (in this case even class scope
this
) is properly tracked through transpiling, but once breaking inside the loop - it appears to the debugger asundefined
.In this recent discussion in chromium issues, DevTools dev said that
This is actually a recurring complaint among debugger users: https://issues.chromium.org/issues/387132016, https://issues.chromium.org/issues/380459170
Are this extra-scopes really necessary? Can't the transpiler do its work within the original function?
If indeed necessary, perhaps source-maps can be somehow enriched to account for them?
Figuring this out would be of great value to all thos doing TS debugging out there.
π Motivating Example
Copying the repro steps from the devtools issue (captured in the gif above):
But this is an extremely common pain when debugging TS. No doubt you've experienced it yourselves if you ever debugged anything TS.
π» Use Cases
Debugging
Unable to debug within loops
printf-debugging
The text was updated successfully, but these errors were encountered: