Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

[WIP] Symbols#3229

Merged
jasonLaster merged 15 commits into
firefox-devtools:masterfrom
jasonLaster:symbols
Jun 28, 2017
Merged

[WIP] Symbols#3229
jasonLaster merged 15 commits into
firefox-devtools:masterfrom
jasonLaster:symbols

Conversation

@jasonLaster
Copy link
Copy Markdown
Contributor

@jasonLaster jasonLaster commented Jun 26, 2017

Summary of Changes

I want to find all of the expressions in a file, this will let us anticipate what a user might want to preview or where a breakpoint might be added.

const obj = { a: { b: 2 } }; // e.g. obj.a.b
const foo = obj2.c.secondProperty; // e.g. foo.obj2.c.secondProperty

// computed properties
const com = { [a]: { b: "c" }, [b]: 3 }; // e.g. com[a].b

// assignments
obj.foo = { a: { b: "c" }, b: 3 }; // e.g. obj.foo.a.b
com = { a: { b: "c" }, b: 3 }; // e.g. com.a.b

// arrays
const res = [{ a: 2 }, { b: 3 }]; // e.g. res[1].b
const res2 = {a: [{b: 2}]}  // e.g. res.a[0].b
const res3 = [[{a:3}],[{b:3}]] // e.g. res[1][0].b

// destructuring
const { a, rest } = compute(stuff); // e.g. a
const [a, ...rest] = compute(stuff);

function params({ a, b }) {} // e.g. a
var pars = function({ a, b }) {};

const evil = obj2.doEvil().c.secondProperty; // e.g. obj2.doEvil or ""

Test Plan

Lots of tests, lots and lots of them

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 27, 2017

Codecov Report

Merging #3229 into master will increase coverage by 1.18%.
The diff coverage is 95.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3229      +/-   ##
==========================================
+ Coverage   47.71%   48.89%   +1.18%     
==========================================
  Files          98       98              
  Lines        4068     4174     +106     
  Branches      836      874      +38     
==========================================
+ Hits         1941     2041     +100     
- Misses       2127     2133       +6
Impacted Files Coverage Δ
src/utils/parser/getSymbols.js 96.15% <95.32%> (-3.85%) ⬇️
src/utils/parser/utils/helpers.js 94.11% <0%> (-2.95%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04703bc...3672fa2. Read the comment docs.

Copy link
Copy Markdown
Contributor

@codehag codehag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments!


symbols.identifiers.push({
name: path.node.name,
expression: path.node.name,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can

const { loc, name } = path.node;

at the top of this block

}

if (t.isVariableDeclarator(path)) {
const node = path.node.id;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit confusing, why is the node === path.node.id? could this be a mistake?

Comment thread src/utils/parser/getSymbols.js Outdated
return symbols;
}

function addProperty(name, expression, path, prevPath) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to extendExpression

Comment thread src/utils/parser/getSymbols.js Outdated
function getObjectExpression(path, prevPath, expression = "") {
const name = path.node.key.name;

expression = addProperty(name, expression, path, prevPath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to
const extendedExpression = extendExpression( ... )

Comment thread src/utils/parser/getSymbols.js Outdated

expression = addProperty(name, expression, path, prevPath);

prevPath = path;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to
const nextPrevPath = path;

Comment thread src/utils/parser/getSymbols.js Outdated
return getExpression(path, prevPath, expression);
}

function getExpression(path, prevPath, expression = "") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be renamed to getExpressionName since it returns a string representation, and not the expression itself

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snippit might be better

return name;
}

if (computed || array) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we need this block, since it is doing the same thing as lines 160 - 164, and if it is computed -- we have an early return at line 150

Comment thread src/utils/parser/getSymbols.js Outdated
expression = addProperty(index, expression, path, prevPath);

prevPath = path;
path = path.parentPath && path.parentPath.parentPath;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for lines 202 204, 205 -- avoid renaming arguments

}

if (t.isVariableDeclarator(path)) {
const node = path.node.id;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, a bit confused about why id is an node? would expect it to be a string...

Comment thread src/utils/parser/getSymbols.js Outdated
}

const name = node.name;
const prop = addProperty(name, expression, path, prevPath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can directly return this

@jasonLaster jasonLaster merged commit 2e74914 into firefox-devtools:master Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants