-
Notifications
You must be signed in to change notification settings - Fork 761
Conversation
src/utils/function.js
Outdated
line: number, | ||
source: any, | ||
symbols: SymbolDeclarations | ||
): string | null { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace any with any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, i meant Source
ok so issue is here:
the second arguemnt of findClosestFunction is a location type.. i.e
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/utils/function.js
Outdated
}); | ||
} else { | ||
return null; | ||
} |
There was a problem hiding this comment.
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);
}
src/reducers/ast.js
Outdated
export function getSymbols( | ||
state: OuterState, | ||
source: Source | ||
): ?SymbolDeclarations { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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.
src/utils/function.js
Outdated
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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
src/utils/function.js
Outdated
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); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. that definitely works
94fd973
to
a0d51ed
Compare
a0d51ed
to
1ec3aa3
Compare
This reverts commit 6b2ac3a.
Fixes Issue: #5120
SymbolDeclarations? or should I just put Object?