--- a/devtools/client/debugger/new/parser-worker.js
+++ b/devtools/client/debugger/new/parser-worker.js
@@ -21185,37 +21185,46 @@ function getFirstExpression(ast) {
if (statements.length == 0) {
return null;
}
return statements[0].expression;
}
function mapOriginalExpression(expression, mappings) {
+ let didReplace = false;
const ast = (0, _ast.parseScript)(expression);
t.traverse(ast, (node, ancestors) => {
const parent = ancestors[ancestors.length - 1];
if (!parent) {
return;
}
const parentNode = parent.node;
if (t.isIdentifier(node) && t.isReferenced(node, parentNode)) {
if (mappings.hasOwnProperty(node.name)) {
const mapping = mappings[node.name];
- if (mapping) {
+ if (mapping && mapping !== node.name) {
const mappingNode = getFirstExpression((0, _ast.parseScript)(mapping));
replaceNode(ancestors, mappingNode);
+
+ didReplace = true;
}
}
}
});
- return (0, _generator2.default)(ast, { concise: true }).code;
+ if (!didReplace) {
+ // Avoid the extra code generation work and also avoid potentially
+ // reformatting the user's code unnecessarily.
+ return expression;
+ }
+
+ return (0, _generator2.default)(ast).code;
}
/***/ }),
/***/ 398:
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {var root = __webpack_require__(8);
--- a/devtools/client/debugger/new/test/mochitest/browser_dbg-babel-preview.js
+++ b/devtools/client/debugger/new/test/mochitest/browser_dbg-babel-preview.js
@@ -80,42 +80,42 @@ add_task(async function() {
await pushPref("devtools.debugger.features.map-scopes", true);
const dbg = await initDebugger("doc-babel.html");
await breakpointPreviews(dbg, "for-of", { line: 5, column: 4 }, [
{
line: 5,
column: 7,
- expression: "doThing;",
+ expression: "doThing",
result: "doThing(arg)",
},
{
line: 5,
column: 12,
- expression: "x;",
+ expression: "x",
result: "1",
},
{
line: 8,
column: 16,
- expression: "doThing;",
+ expression: "doThing",
result: "doThing(arg)",
},
]);
await breakpointPreviews(dbg, "shadowed-vars", { line: 18, column: 6 }, [
// These aren't what the user would expect, but we test them anyway since
// they reflect what this actually returns. These shadowed bindings read
// the binding closest to the current frame's scope even though their
// actual value is different.
{
line: 2,
column: 9,
- expression: "aVar;",
+ expression: "aVar",
result: '"var3"',
},
{
line: 3,
column: 9,
expression: "_aLet2;",
result: '"let3"',
},
@@ -123,17 +123,17 @@ add_task(async function() {
line: 4,
column: 11,
expression: "_aConst2;",
result: '"const3"',
},
{
line: 10,
column: 11,
- expression: "aVar;",
+ expression: "aVar",
result: '"var3"',
},
{
line: 11,
column: 11,
expression: "_aLet2;",
result: '"let3"',
},
@@ -143,17 +143,17 @@ add_task(async function() {
expression: "_aConst2;",
result: '"const3"',
},
// These actually result in the values the user would expect.
{
line: 14,
column: 13,
- expression: "aVar;",
+ expression: "aVar",
result: '"var3"',
},
{
line: 15,
column: 13,
expression: "_aLet2;",
result: '"let3"',
},
@@ -188,17 +188,17 @@ add_task(async function() {
line: 25,
column: 16,
expression: "_mod4.original;",
result: '"an-original"',
},
{
line: 26,
column: 16,
- expression: "aNamespace;",
+ expression: "aNamespace",
fields: [
['aNamed', 'a-named'],
['default', 'a-default'],
],
},
{
line: 31,
column: 20,
@@ -221,16 +221,16 @@ add_task(async function() {
line: 34,
column: 20,
expression: "_mod9.original;",
result: '"an-original2"',
},
{
line: 35,
column: 20,
- expression: "aNamespace2;",
+ expression: "aNamespace2",
fields: [
['aNamed', 'a-named2'],
['default', 'a-default2'],
],
},
]);
});