diff --git a/src/actions/tests/__snapshots__/ast.spec.js.snap b/src/actions/tests/__snapshots__/ast.spec.js.snap index 1858a5a0ac..0811bd93e1 100644 --- a/src/actions/tests/__snapshots__/ast.spec.js.snap +++ b/src/actions/tests/__snapshots__/ast.spec.js.snap @@ -188,6 +188,7 @@ Object { ], }, ], + "hasJsx": false, "identifiers": Array [ Object { "expression": "base", diff --git a/src/workers/parser/getSymbols.js b/src/workers/parser/getSymbols.js index 89ac650577..77b5717cf8 100644 --- a/src/workers/parser/getSymbols.js +++ b/src/workers/parser/getSymbols.js @@ -12,6 +12,7 @@ import getFunctionName from "./utils/getFunctionName"; import type { Source } from "debugger-html"; import type { NodePath, Node, Location as BabelLocation } from "babel-traverse"; + let symbolDeclarations = new Map(); export type SymbolDeclaration = {| @@ -104,6 +105,7 @@ function extractSymbols(source: Source) { const identifiers = []; const classes = []; const imports = []; + let hasJsx = false; const ast = traverseAst(source, { enter(path: NodePath) { @@ -121,6 +123,10 @@ function extractSymbols(source: Source) { }); } + if (t.isJSXElement(path)) { + hasJsx = true; + } + if (t.isClassDeclaration(path)) { classes.push({ name: path.node.id.name, @@ -218,7 +224,8 @@ function extractSymbols(source: Source) { comments, identifiers, classes, - imports + imports, + hasJsx }; } diff --git a/src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap b/src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap index cc05021b60..744daec238 100644 --- a/src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap +++ b/src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap @@ -77,7 +77,9 @@ classes: [(23, 0), (31, 1)] Ultra imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols call sites 1`] = ` @@ -115,7 +117,9 @@ classes: imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols class 1`] = ` @@ -164,7 +168,9 @@ classes: [(15, 0), (15, 14)] Test2 imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols component 1`] = ` @@ -325,7 +331,9 @@ classes: [(5, 0), (20, 1)] Punny imports: -" + + +hasJsx: true" `; exports[`Parser.getSymbols es6 1`] = ` @@ -357,7 +365,9 @@ classes: imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols expression 1`] = ` @@ -563,7 +573,9 @@ classes: imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols finds symbols in an html file 1`] = ` @@ -640,7 +652,9 @@ classes: imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols flow 1`] = ` @@ -673,7 +687,9 @@ classes: [(1, 0), (5, 1)] App imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols func 1`] = ` @@ -722,7 +738,41 @@ classes: imports: -" + + +hasJsx: false" +`; + +exports[`Parser.getSymbols jsx 1`] = ` +"functions: + + +variables: +[(1, 6), (1, 45)] jsxElement + +callExpressions: + + +memberExpressions: + + +objectProperties: + + +comments: + + +identifiers: +[(1, 6), (1, 45)] jsxElement jsxElement +[(1, 6), (1, 16)] jsxElement jsxElement + +classes: + + +imports: + + +hasJsx: true" `; exports[`Parser.getSymbols math 1`] = ` @@ -776,7 +826,9 @@ classes: imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols proto 1`] = ` @@ -834,7 +886,9 @@ classes: imports: -" + + +hasJsx: false" `; exports[`Parser.getSymbols react component 1`] = ` @@ -867,7 +921,9 @@ classes: [(3, 0), (3, 39)] PrimaryPanes imports: -[(1, 0), (1, 41)] React, Component" +[(1, 0), (1, 41)] React, Component + +hasJsx: false" `; exports[`Parser.getSymbols var 1`] = ` @@ -909,5 +965,7 @@ classes: imports: -" + + +hasJsx: false" `; diff --git a/src/workers/parser/tests/fixtures/jsx.js b/src/workers/parser/tests/fixtures/jsx.js new file mode 100644 index 0000000000..f67ed71707 --- /dev/null +++ b/src/workers/parser/tests/fixtures/jsx.js @@ -0,0 +1 @@ +const jsxElement =