JS: Add EndsWith::Range

This commit is contained in:
Asger F
2019-02-15 16:48:15 +00:00
parent 2ccfd73be5
commit ab0ed66266

View File

@@ -343,16 +343,20 @@ module StringOps {
/**
* An expression that is equivalent to `A.endsWith(B)` or `!A.endsWith(B)`.
*/
abstract class EndsWith extends DataFlow::Node {
class EndsWith extends DataFlow::Node {
EndsWith::Range range;
EndsWith() { this = range }
/**
* Gets the `A` in `A.startsWith(B)`.
*/
abstract DataFlow::Node getBaseString();
DataFlow::Node getBaseString() { result = range.getBaseString() }
/**
* Gets the `B` in `A.startsWith(B)`.
*/
abstract DataFlow::Node getSubstring();
DataFlow::Node getSubstring() { result = range.getSubstring() }
/**
* Gets the polarity if the check.
@@ -360,37 +364,62 @@ module StringOps {
* If the polarity is `false` the check returns `true` if the string does not end
* with the given substring.
*/
boolean getPolarity() { result = true }
boolean getPolarity() { result = range.getPolarity() }
}
/**
* A call of form `A.endsWith(B)`.
*/
private class EndsWith_Native extends EndsWith, DataFlow::MethodCallNode {
EndsWith_Native() {
getMethodName() = "endsWith" and
getNumArgument() = 1
module EndsWith {
/**
* An expression that is equivalent to `A.endsWith(B)` or `!A.endsWith(B)`.
*/
abstract class Range extends DataFlow::Node {
/**
* Gets the `A` in `A.startsWith(B)`.
*/
abstract DataFlow::Node getBaseString();
/**
* Gets the `B` in `A.startsWith(B)`.
*/
abstract DataFlow::Node getSubstring();
/**
* Gets the polarity if the check.
*
* If the polarity is `false` the check returns `true` if the string does not end
* with the given substring.
*/
boolean getPolarity() { result = true }
}
override DataFlow::Node getBaseString() { result = getReceiver() }
/**
* A call of form `A.endsWith(B)`.
*/
private class EndsWith_Native extends Range, DataFlow::MethodCallNode {
EndsWith_Native() {
getMethodName() = "endsWith" and
getNumArgument() = 1
}
override DataFlow::Node getSubstring() { result = getArgument(0) }
}
override DataFlow::Node getBaseString() { result = getReceiver() }
/**
* A call of form `_.endsWith(A, B)` or `ramda.endsWith(A, B)`.
*/
private class EndsWith_Library extends StartsWith, DataFlow::CallNode {
EndsWith_Library() {
getNumArgument() = 2 and
exists(DataFlow::SourceNode callee | this = callee.getACall() |
callee = LodashUnderscore::member("endsWith") or
callee = DataFlow::moduleMember("ramda", "endsWith")
)
override DataFlow::Node getSubstring() { result = getArgument(0) }
}
override DataFlow::Node getBaseString() { result = getArgument(0) }
/**
* A call of form `_.endsWith(A, B)` or `ramda.endsWith(A, B)`.
*/
private class EndsWith_Library extends StartsWith, DataFlow::CallNode {
EndsWith_Library() {
getNumArgument() = 2 and
exists(DataFlow::SourceNode callee | this = callee.getACall() |
callee = LodashUnderscore::member("endsWith") or
callee = DataFlow::moduleMember("ramda", "endsWith")
)
}
override DataFlow::Node getSubstring() { result = getArgument(1) }
override DataFlow::Node getBaseString() { result = getArgument(0) }
override DataFlow::Node getSubstring() { result = getArgument(1) }
}
}
}