simplify the output file argument

This commit is contained in:
Erik Krogh Kristensen
2020-02-20 10:57:33 +01:00
parent a5fdcb67f9
commit 558beb7255

View File

@@ -172,14 +172,28 @@ module UselsesCatCandidates {
|
(if root.asExpr() instanceof TemplateLiteral then quote = "`" else quote = "\"") and
root.getFirstLeaf().getStringValue().prefix(cat.length()) = cat and
// Remove an initial ""+ (e.g. in `""+file`)
exists(string rawConcat | rawConcat = quote + printed.suffix(cat.length()).trim() |
if rawConcat.prefix(3) = "\"\"+" then result = rawConcat.suffix(3) else result = rawConcat
result = getSimplifiedStringConcat(rawConcat)
)
)
)
}
/**
* Gets a simplified and equivalent string concatenation for a given string concatenation `str`
*/
bindingset[str]
private string getSimplifiedStringConcat(string str) {
// Remove an initial ""+ (e.g. in `""+file`)
if str.prefix(3) = "\"\"+" then
result = str.suffix(3)
// prettify `${newpath}` to just newpath
else if str.prefix(3) = "`${" and str.suffix(str.length() - 2) = "}`" and not str.suffix(3).matches("%{%") then
result = str.prefix(str.length() - 2).suffix(3)
else
result = str
}
/**
* A call to child_process.exec that might be a useless call to cat.
*/