diff --git a/src/test/mochitest/browser_dbg-sourcemaps2.js b/src/test/mochitest/browser_dbg-sourcemaps2.js index b048ea5c21..c5260bf2a1 100644 --- a/src/test/mochitest/browser_dbg-sourcemaps2.js +++ b/src/test/mochitest/browser_dbg-sourcemaps2.js @@ -1,11 +1,17 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ + +function assertBpInGutter(dbg, lineNumber) { + const el = findElement(dbg, "breakpoint"); + const bpLineNumber = +el.querySelector(".CodeMirror-linenumber").innerText; + is(bpLineNumber, lineNumber); +} + // Tests loading sourcemapped sources, setting breakpoints, and // stepping in them. // This source map does not have source contents, so it's fetched separately - add_task(async function() { // NOTE: the CORS call makes the test run times inconsistent requestLongerTimeout(2); @@ -28,6 +34,7 @@ add_task(async function() { "Breakpoint has correct line" ); + assertBpInGutter(dbg, 4); invokeInTab("logMessage"); await waitForPaused(dbg); diff --git a/src/workers/parser/frameworks.js b/src/workers/parser/frameworks.js index c4be51057e..c0f69b9de4 100644 --- a/src/workers/parser/frameworks.js +++ b/src/workers/parser/frameworks.js @@ -11,19 +11,11 @@ export function isReactComponent(source) { } function importsReact(imports) { - let result = false; - - imports.some(importObj => { - if (importObj.source === "react") { - importObj.specifiers.some(specifier => { - if (specifier.local.name === "React") { - result = true; - } - }); - } - }); - - return result; + return imports.some( + importObj => + importObj.source === "react" && + importObj.specifiers.some(specifier => specifier === "React") + ); } function extendsComponent(classes) { diff --git a/src/workers/parser/getSymbols.js b/src/workers/parser/getSymbols.js index 8c51bfdbb7..5eca654607 100644 --- a/src/workers/parser/getSymbols.js +++ b/src/workers/parser/getSymbols.js @@ -80,6 +80,14 @@ function getComments(ast) { })); } +function getSpecifiers(specifiers) { + if (!specifiers) { + return null; + } + + return specifiers.map(specifier => specifier.local && specifier.local.name); +} + function extractSymbols(source: Source) { const functions = []; const variables = []; @@ -118,7 +126,7 @@ function extractSymbols(source: Source) { imports.push({ source: path.node.source.value, location: path.node.loc, - specifiers: path.node.specifiers + specifiers: getSpecifiers(path.node.specifiers) }); } diff --git a/src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap b/src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap index 1a0c450af9..775d786a67 100644 --- a/src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap +++ b/src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap @@ -191,7 +191,7 @@ variables: [(82, 35), (82, 43)] newColor callExpressions: -[(7, 4), (7, 9)] undefined +[(7, 4), (7, 9)] [(34, 18), (34, 29)] createClass [(42, 12), (42, 23)] createClass [(50, 16), (50, 27)] createClass @@ -231,10 +231,10 @@ objectProperties: [(53, 2), (53, 8)] render comments: -[(1, 0), (3, 3)] undefined -[(22, 0), (24, 3)] undefined -[(58, 0), (60, 3)] undefined -[(81, 0), (81, 34)] undefined +[(1, 0), (3, 3)] +[(22, 0), (24, 3)] +[(58, 0), (60, 3)] +[(81, 0), (81, 34)] identifiers: [(5, 6), (5, 11)] Punny Punny @@ -391,15 +391,15 @@ variables: [(19, 6), (19, 45)] res4 [(19, 17), (19, 21)] a [(19, 29), (19, 41)] b -[(22, 6), (22, 35)] undefined +[(22, 6), (22, 35)] [(22, 8), (22, 9)] b [(22, 11), (22, 16)] resty -[(23, 6), (23, 35)] undefined -[(25, 16), (25, 24)] undefined +[(23, 6), (23, 35)] +[(25, 16), (25, 24)] [(25, 18), (25, 19)] a [(25, 21), (25, 22)] b [(26, 4), (26, 32)] pars -[(26, 20), (26, 28)] undefined +[(26, 20), (26, 28)] [(26, 22), (26, 23)] a [(26, 25), (26, 26)] b [(27, 6), (27, 43)] evil @@ -454,22 +454,22 @@ objectProperties: [(26, 25), (26, 26)] b b comments: -[(1, 29), (1, 44)] undefined -[(2, 35), (2, 68)] undefined -[(4, 0), (4, 22)] undefined -[(5, 51), (5, 67)] undefined -[(11, 0), (11, 14)] undefined -[(12, 35), (12, 54)] undefined -[(13, 31), (13, 46)] undefined -[(15, 0), (15, 9)] undefined -[(16, 34), (16, 50)] undefined -[(17, 32), (17, 50)] undefined -[(18, 47), (18, 65)] undefined -[(19, 47), (19, 66)] undefined -[(21, 0), (21, 16)] undefined -[(22, 37), (22, 46)] undefined -[(25, 29), (25, 38)] undefined -[(27, 45), (27, 70)] undefined +[(1, 29), (1, 44)] +[(2, 35), (2, 68)] +[(4, 0), (4, 22)] +[(5, 51), (5, 67)] +[(11, 0), (11, 14)] +[(12, 35), (12, 54)] +[(13, 31), (13, 46)] +[(15, 0), (15, 9)] +[(16, 34), (16, 50)] +[(17, 32), (17, 50)] +[(18, 47), (18, 65)] +[(19, 47), (19, 66)] +[(21, 0), (21, 16)] +[(22, 37), (22, 46)] +[(25, 29), (25, 38)] +[(27, 45), (27, 70)] identifiers: [(1, 6), (1, 27)] obj obj @@ -524,14 +524,14 @@ identifiers: [(19, 36), (19, 37)] c c [(19, 38), (19, 39)] v v [(19, 40), (19, 41)] d d -[(22, 6), (22, 35)] undefined +[(22, 6), (22, 35)] [(22, 8), (22, 9)] b b [(22, 8), (22, 9)] b b [(22, 11), (22, 16)] resty resty [(22, 11), (22, 16)] resty resty [(22, 21), (22, 28)] compute compute [(22, 29), (22, 34)] stuff stuff -[(23, 6), (23, 35)] undefined +[(23, 6), (23, 35)] [(23, 7), (23, 8)] a a [(23, 13), (23, 17)] rest rest [(23, 21), (23, 28)] compute compute @@ -578,12 +578,12 @@ variables: [(37, 9), (37, 36)] greeting callExpressions: -[(36, 3), (39, 3)] undefined +[(36, 3), (39, 3)] [(37, 20), (37, 28)] sayHello memberExpressions: [(23, 18), (23, 29)] [(23, 10), (23, 29)] name.undefined.toUpperCase toUpperCase -[(23, 15), (23, 16)] [(23, 10), (23, 17)] name. undefined +[(23, 15), (23, 16)] [(23, 10), (23, 17)] name. [(23, 39), (23, 48)] [(23, 34), (23, 48)] name.substring substring [(28, 4), (28, 8)] [(25, 19), (28, 8)] join [(27, 4), (27, 7)] [(25, 19), (27, 7)] map @@ -654,7 +654,7 @@ variables: [(23, 6), (31, 1)] obj callExpressions: -[(19, 1), (21, 1)] undefined +[(19, 1), (21, 1)] memberExpressions: @@ -712,8 +712,8 @@ objectProperties: comments: -[(3, 4), (3, 21)] undefined -[(7, 2), (7, 24)] undefined +[(3, 4), (3, 21)] +[(7, 2), (7, 24)] identifiers: [(1, 9), (1, 13)] math math @@ -829,7 +829,7 @@ classes: [(3, 0), (3, 39)] PrimaryPanes imports: -[(1, 0), (1, 41)] undefined" +[(1, 0), (1, 41)] React, Component" `; exports[`Parser.getSymbols var 1`] = ` diff --git a/src/workers/parser/utils/formatSymbols.js b/src/workers/parser/utils/formatSymbols.js index 83fdc131ef..e85b587f6f 100644 --- a/src/workers/parser/utils/formatSymbols.js +++ b/src/workers/parser/utils/formatSymbols.js @@ -23,7 +23,10 @@ export function formatSymbols(source: Source) { const expression = symbol.expression || ""; const klass = symbol.klass || ""; - return `${loc} ${exprLoc} ${expression} ${symbol.name}${params} ${klass}`.trim(); // eslint-disable-line max-len + const name = symbol.name || ""; + const names = symbol.specifiers ? symbol.specifiers.join(", ") : ""; + + return `${loc} ${exprLoc} ${expression} ${name}${params} ${klass} ${names}`.trim(); // eslint-disable-line max-len } return Object.keys(symbols)