Reproduce debugger.html PR 5822 in mc draft
authorLogan Smyth <loganfsmyth@gmail.com>
Thu, 29 Mar 2018 15:59:20 -0700
changeset 775095 a5452b72cfcfd8f0e82b721dde508525b13fc655
parent 775094 7c6d4d42aef40f506e33b27933f90ab1f8a4f655
child 775096 aa8d758e2f61b92833b6a39ce36cdbdc79a59de0
push id104598
push userbmo:loganfsmyth@gmail.com
push dateFri, 30 Mar 2018 00:08:52 +0000
milestone61.0a1
Reproduce debugger.html PR 5822 in mc
devtools/client/debugger/new/panel.js
devtools/client/debugger/new/parser-worker.js
devtools/client/debugger/new/test/mochitest/browser_dbg-babel-preview.js
--- a/devtools/client/debugger/new/panel.js
+++ b/devtools/client/debugger/new/panel.js
@@ -111,16 +111,20 @@ DebuggerPanel.prototype = {
 
     frames.forEach(frame => {
       frame.actor = frame.id;
     });
 
     return { frames, selected };
   },
 
+  getMappedExpression(expression) {
+    return this._actions.getMappedExpression(expression);
+  },
+
   isPaused() {
     return this._selectors.isPaused(this._getState());
   },
 
   selectSource(url, line) {
     this._actions.selectSourceURL(url, { location: { line } });
   },
 
--- 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'],
       ],
     },
   ]);
 });