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

[Flow] src/utils/function.js #5904

Merged
merged 1 commit into from
Apr 24, 2018

Conversation

atwalg2
Copy link
Contributor

@atwalg2 atwalg2 commented Apr 10, 2018

Fixes Issue: #5120

SymbolDeclarations? or should I just put Object?

line: number,
source: any,
symbols: SymbolDeclarations
): string | null {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks good.

I think we need to import SymbolDeclarations and perhaps replace any with any

Copy link
Contributor Author

Choose a reason for hiding this comment

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

replace any with any?

Copy link
Contributor

Choose a reason for hiding this comment

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

oops, i meant Source

@atwalg2
Copy link
Contributor Author

atwalg2 commented Apr 12, 2018

ok so issue is here:

export function findFunctionText(
  line: number,
  source: any,
  symbols: SymbolDeclarations
): string | null {
  const func = findClosestFunction(symbols, {
    line,
    column: Infinity
  });
  if (!func) {
    return null;
  }

the second arguemnt of findClosestFunction is a location type.. i.e

export type Location = {
  sourceId: SourceId,
  line: number,
  column: ?number,
  sourceUrl?: string
};

simple solution is to make sourceId an optional property. Thoughts?

src/types.js Outdated
@@ -54,7 +54,7 @@ export type ActorId = string;
* @static
*/
export type Location = {
sourceId: SourceId,
sourceId?: SourceId,
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, this shouldnt be optional, the param for the reducer should be

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is still a problem if I change this back and edit the reducer param.
In ast.js, location is declared multiple times and if sourceId is a required param then it should be included.. seperated... or made optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

});
} else {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

small suggestion here. I think i'd prefer putting the guard statement in findClosestFunction. We prefer safer calls than checks before the calls

diff --git a/src/utils/ast.js b/src/utils/ast.js
index 56c30f3..6464345 100644
--- a/src/utils/ast.js
+++ b/src/utils/ast.js
@@ -104,17 +104,25 @@ function findClosestofSymbol(declarations: any[], location: Location) {
 }
 
 export function findClosestFunction(
-  symbols: SymbolDeclarations,
+  symbols: ?SymbolDeclarations,
   location: Location
 ) {
+  if (!symbols) {
+    return null;
+  }
+
   const { functions } = symbols;
   return findClosestofSymbol(functions, location);
 }
 
 export function findClosestClass(
-  symbols: SymbolDeclarations,
+  symbols: ?SymbolDeclarations,
   location: Location
 ) {
+  if (!symbols) {
+    return null;
+  }
+
   const { classes } = symbols;
   return findClosestofSymbol(classes, location);
 }

export function getSymbols(
state: OuterState,
source: Source
): ?SymbolDeclarations {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's important that this is Symbols and not SymbolDeclarations look at the definition above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @jasonLaster were you referring to only this case or the other ones as well. I may have read this wrong initially.. I just realized you may have meant only this case and not the others .. oops. Please clarify this for me I can make a quick fix

@jasonLaster jasonLaster changed the title [Flow] src/utils/function.js - add type defs for flow [Flow] src/utils/function.js Apr 13, 2018
Copy link
Contributor

@AnshulMalik AnshulMalik left a comment

Choose a reason for hiding this comment

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

Nice! And a rebase always helps.

const middle = lines.slice(start.line, end.line - 1);
const functionText = [firstLine, ...middle, lastLine].join("\n");
const indentedFunctionText = correctIndentation(functionText);
const lines: string[] = source.text.split("\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need these types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No we don't. I just put them in their to try and improve the file coverage, which most likely wouldn't affect it.

src/utils/ast.js Outdated
if (
!(symbols.memberExpressions && symbols.identifiers && symbols.identifiers)
) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This means both memberExpressions and identifiers should be present for this to return results. Is this what we want?

src/utils/ast.js Outdated
if (
!(symbols.memberExpressions && symbols.identifiers && symbols.identifiers)
) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

!(symbols.memberExpressions && symbols.identifiers && symbols.identifiers)

could we just do !symbols

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well no because as per type def for Symbols it can be either SymbolDeclaration | {| loading: true |}. So we have to account for the other case. Really it seems like we are only dealing with SymbolDeclarations here. What do you think?

const lastLine: string = lines[end.line - 1].slice(0, end.column);
const middle: string[] = lines.slice(start.line, end.line - 1);
const functionText: string = [firstLine, ...middle, lastLine].join("\n");
const indentedFunctionText: string = correctIndentation(functionText);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need these for it to pass? they should be inferred...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh ok I can get rid of these. They are def unnecessary.

src/utils/ast.js Outdated
if (
!(symbols.memberExpressions && symbols.identifiers && symbols.identifiers)
) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

so symbols.identifiers && symbols.identifiers is unneccessary right?

could we do !symbols.loading && symbols

const { line, column } = tokenPos;
if (symbols.loading) {
return null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasonLaster hey Jason so I think having if(symbols.loading) return null make sense in this case. What do you think?

Copy link
Contributor

@jasonLaster jasonLaster Apr 20, 2018

Choose a reason for hiding this comment

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

yes. that definitely works

@jasonLaster jasonLaster merged commit 6b2ac3a into firefox-devtools:master Apr 24, 2018
jasonLaster added a commit to jasonLaster/debugger.html that referenced this pull request Apr 25, 2018
jasonLaster pushed a commit that referenced this pull request Apr 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants